- More cleanup
- Added kupos entity and sprites (body, bow) - Finally understood my code
This commit is contained in:
35
data/scripts/entities/kupo.lua
Normal file
35
data/scripts/entities/kupo.lua
Normal file
@@ -0,0 +1,35 @@
|
||||
Kupo = Entity:New(x,y)
|
||||
|
||||
function Kupo:New(x,y)
|
||||
local o = Entity:New(x,y)
|
||||
|
||||
o.pos = {x = x, y = y}
|
||||
o.speed = 20
|
||||
o.range = 1000
|
||||
|
||||
setmetatable(o, self)
|
||||
self.__index = self
|
||||
|
||||
return o
|
||||
end
|
||||
|
||||
function Kupo:DoInput()
|
||||
|
||||
end
|
||||
|
||||
function Kupo:HandleAnimation()
|
||||
-- flip sprite to look in the direction is moving
|
||||
if self.vel.x ~= 0 then self.flip.x = math.sign(self.vel.x) end
|
||||
self:LoadAnimation(animation.kupo.body)
|
||||
end
|
||||
|
||||
function Kupo:DoPhysics()
|
||||
|
||||
-- horizontal collisions
|
||||
if not isThereAnyCollisionAt(self.pos.x + self.vel.x, self.pos.y) then
|
||||
self.pos.x = self.pos.x + self.vel.x
|
||||
end
|
||||
if not isThereAnyCollisionAt(self.pos.x, self.pos.y + self.vel.y) then
|
||||
self.pos.y = self.pos.y + self.vel.y
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user