1lakito = class:new() 2 3function lakito:init(x, y) 4 --PHYSICS STUFF 5 self.starty = y 6 self.x = x-1+2/16 7 self.y = y-12/16 8 self.speedx = 0 --! 9 self.speedy = 0 10 self.width = 12/16 11 self.height = 12/16 12 self.static = false 13 self.active = true 14 15 self.mask = { true, 16 true, false, false, true, true, 17 true, true, true, true, true, 18 true, false, true, true, true, 19 true, true, true, true, true, 20 true, true, true, true, true, 21 true, true, true, true, true} 22 23 self.gravity = 0 24 self.portalable = false 25 self.passive = false 26 self.category = 21 27 28 --IMAGE STUFF 29 self.drawable = false 30 31 self.direction = "left" 32 33 self.rotation = 0 34 35 self.timer = 0 36end 37 38function lakito:update(dt) 39 if self.shot then 40 self.speedy = self.speedy + shotgravity*dt 41 42 self.x = self.x+self.speedx*dt 43 self.y = self.y+self.speedy*dt 44 45 if self.passive == false then 46 self.timer = self.timer + dt 47 if self.timer > lakitorespawn then 48 self.y = self.starty - 12/16 49 self.x = splitxscroll[#splitxscroll] + width 50 self.timer = 0 51 self.shot = false 52 self.active = true 53 self.gravity = 0 54 self.speedy = 0 55 self.speedx = 0 56 end 57 end 58 59 elseif self.passive then 60 self.speedx = -lakitopassivespeed 61 else 62 local count = 0 63 for i, v in pairs(objects["goomba"]) do 64 if v.t == "spikeyfall" or v.t == "spikey" then 65 count = count + 1 66 end 67 end 68 69 self.timer = self.timer + dt 70 if count < 3 then 71 if self.timer > lakitothrowtime then 72 table.insert(objects["goomba"], goomba:new(self.x+6/16, self.y, "spikeyfall")) 73 self.timer = 0 74 end 75 end 76 77 --movement 78 --get nearest player (relative to that player's position in 1 second) 79 local nearestplayer = 1 80 local nearestplayerx = objects["player"][1].x + objects["player"][1].speedx * lakitodistancetime 81 for i = 2, players do 82 local v = objects["player"][i] 83 if math.abs(self.x - (v.x + v.speedx*lakitodistancetime)) < nearestplayerx and not v.dead then 84 nearestplayer = i 85 nearestplayerx = v.x + v.speedx*lakitodistancetime 86 end 87 end 88 89 local distance = math.abs(self.x - nearestplayerx) 90 91 --check if too far in wrong direciton 92 if self.direction == "left" and self.x < nearestplayerx-lakitospace then 93 self.direction = "right" 94 elseif self.direction == "right" and self.x > nearestplayerx+lakitospace then 95 self.direction = "left" 96 end 97 98 if self.direction == "right" then 99 self.speedx = math.max(2, round((distance-3)*2)) 100 else 101 self.speedx = -2 102 end 103 end 104 105 --check if switch to passive 106 if lakitoend then 107 self.passive = true 108 end 109end 110 111function lakito:draw() 112 local horscale = scale 113 if self.direction == "left" then 114 horscale = -scale 115 end 116 117 local verscale = scale 118 if self.shot then 119 verscale = -scale 120 end 121 122 local quad = 1 123 if self.timer > lakitothrowtime-lakitohidetime then 124 quad = 2 125 end 126 127 love.graphics.drawq(lakitoimg, lakitoquad[quad], math.floor((self.x-xscroll-2/16+.5)*16*scale), (self.y-0.5+1/16)*16*scale, 0, horscale, verscale, 8, 12) 128end 129 130function lakito:stomp() 131 self:shotted() 132 self.speedy = 0 133end 134 135function lakito:shotted() --fireball, star, turtle 136 playsound(shotsound) 137 self.shot = true 138 self.speedy = -shotjumpforce 139 self.direction = dir or "right" 140 self.active = false 141 self.gravity = shotgravity 142 self.speedx = 0 143 self.timer = 0 144end 145 146function lakito:rightcollide(a, b) 147 if a == "goomba" and b.t == "spikeyfall" then 148 self:shotted() 149 addpoints(firepoints["lakito"], self.x, self.y) 150 end 151 return false 152end 153 154function lakito:leftcollide(a, b) 155 if a == "goomba" and b.t == "spikeyfall" then 156 self:shotted() 157 addpoints(firepoints["lakito"], self.x, self.y) 158 end 159 return false 160end 161 162function lakito:ceilcollide(a, b) 163 if a == "goomba" and b.t == "spikeyfall" then 164 self:shotted() 165 addpoints(firepoints["lakito"], self.x, self.y) 166 end 167 return false 168end 169 170function lakito:floorcollide(a, b) 171 if a == "goomba" and b.t == "spikeyfall" then 172 self:shotted() 173 addpoints(firepoints["lakito"], self.x, self.y) 174 end 175 return false 176end