1rocketlauncher = class:new() 2 3function rocketlauncher:init(x, y) 4 self.x = x 5 self.y = y 6 self.id = id 7 self:randomtime() 8 self.timer = self.time-0.5 9 self.autodelete = true 10end 11 12function rocketlauncher:update(dt) 13 self.timer = self.timer + dt 14 if self.timer > self.time and self.x > splitxscroll[1] and self.x < splitxscroll[1]+width+2 then 15 if self:fire() then 16 self.timer = 0 17 self:randomtime() 18 end 19 end 20end 21 22function rocketlauncher:fire() 23 if #objects["bulletbill"] >= maximumbulletbills then 24 return false 25 end 26 27 --get nearest player 28 local pl = 1 29 for i = 2, players do 30 if math.abs(objects["player"][i].x + 14/16 - self.x) < math.abs(objects["player"][pl].x + 14/16 - self.x) then 31 pl = i 32 end 33 end 34 35 if objects["player"][pl].x + 14/16 > self.x + bulletbillrange then 36 table.insert(objects["bulletbill"], bulletbill:new(self.x, self.y, "right")) 37 return true 38 elseif objects["player"][pl].x + 14/16 < self.x - bulletbillrange then 39 table.insert(objects["bulletbill"], bulletbill:new(self.x, self.y, "left")) 40 return true 41 end 42end 43 44function rocketlauncher:randomtime() 45 local rand = math.random(bulletbilltimemin*10, bulletbilltimemax*10)/10 46 self.time = rand 47end 48 49---------------------- 50bulletbill = class:new() 51function bulletbill:init(x, y, dir) 52 self.startx = x-14/16 53 --PHYSICS STUFF 54 self.x = self.startx 55 self.y = y-14/16 56 self.speedy = 0 57 if dir == "left" then 58 self.speedx = -bulletbillspeed 59 self.customscissor = {self.x-18/16, self.y-2/16, 1, 1} 60 else 61 self.speedx = bulletbillspeed 62 self.customscissor = {self.x+14/16, self.y-2/16, 1, 1} 63 end 64 self.width = 12/16 65 self.height = 12/16 66 self.static = false 67 self.active = true 68 self.gravity = 0 69 self.rotation = 0 70 self.autodelete = true 71 self.timer = 0 72 73 --IMAGE STUFF 74 self.drawable = true 75 self.quad = bulletbillquad[spriteset] 76 self.offsetX = 6 77 self.offsetY = 2 78 self.quadcenterX = 8 79 self.quadcenterY = 8 80 self.graphic = bulletbillimg 81 82 self.category = 11 83 self.animationdirection = dir 84 85 self.mask = { true, 86 true, false, false, false, true, 87 true, true, true, true, true, 88 true, false, true, true, true, 89 true, true, true, true, true, 90 true, true, true, true, true, 91 true, true, true, true, true} 92 93 self.shot = false 94 95 playsound(bulletbillsound) 96end 97 98function bulletbill:update(dt) 99 if self.x < self.startx - 1 or self.x > self.startx + 1 then 100 self.customscissor = nil 101 end 102 103 if self.shot then 104 self.speedy = self.speedy + shotgravity*dt 105 106 self.x = self.x+self.speedx*dt 107 self.y = self.y+self.speedy*dt 108 109 --check if goomba offscreen 110 if self.y > 18 then 111 return true 112 else 113 return false 114 end 115 else 116 self.timer = self.timer + dt 117 if self.timer >= bulletbilllifetime then 118 return true 119 end 120 121 if self.rotation ~= 0 then 122 if math.abs(math.abs(self.rotation)-math.pi/2) < 0.1 then 123 self.rotation = -math.pi/2 124 else 125 self.rotation = 0 126 end 127 end 128 129 if self.speedx < 0 then 130 self.animationdirection = "left" 131 elseif self.speedx > 0 then 132 self.animationdirection = "right" 133 elseif self.speedy < 0 then 134 self.animationdirection = "right" 135 elseif self.speedy > 0 then 136 self.animationdirection = "left" 137 end 138 end 139end 140 141function bulletbill:stomp(dir) --fireball, star, turtle 142 self.shot = true 143 self.speedy = 0 144 self.direction = dir or "right" 145 self.active = false 146 self.gravity = shotgravity 147 if self.direction == "left" then 148 self.speedx = -shotspeedx 149 else 150 self.speedx = shotspeedx 151 end 152end 153 154function bulletbill:shotted(dir) 155 self:stomp(dir) 156end 157 158function bulletbill:rightcollide(a, b) 159 self:globalcollide(a, b) 160 return false 161end 162 163function bulletbill:leftcollide(a, b) 164 self:globalcollide(a, b) 165 return false 166end 167 168function bulletbill:ceilcollide(a, b) 169 self:globalcollide(a, b) 170 if a == "player" or a == "box" then 171 self:stomp() 172 end 173 return false 174end 175 176function bulletbill:floorcollide(a, b) 177 self:globalcollide(a, b) 178 return false 179end 180 181function bulletbill:globalcollide(a, b) 182 if self.killstuff then 183 if a == "goomba" or a == "koopa" then 184 b:shotted("left") 185 return true 186 end 187 else 188 return true 189 end 190end 191 192function bulletbill:portaled() 193 self.killstuff = true 194end