modules/world: add speed variables
This commit is contained in:
parent
f61cb21d58
commit
193e9b6fbf
2 changed files with 15 additions and 7 deletions
|
@ -7,21 +7,21 @@ function Player:new(world, x, y)
|
|||
end
|
||||
|
||||
function Player:update(dt)
|
||||
local dx, dy = 0, 0
|
||||
self.xsp, self.ysp = 0, 0
|
||||
if self.keys["up"].isDown then
|
||||
dy = -120 * dt
|
||||
self.ysp = -120 * dt
|
||||
end
|
||||
if self.keys["down"].isDown then
|
||||
dy = 120 * dt
|
||||
self.ysp = 120 * dt
|
||||
end
|
||||
if self.keys["left"].isDown then
|
||||
dx = -120 * dt
|
||||
self.xsp = -120 * dt
|
||||
end
|
||||
if self.keys["right"].isDown then
|
||||
dx = 120 * dt
|
||||
self.xsp = 120 * dt
|
||||
end
|
||||
|
||||
self:move(self.x + dx, self.y + dy)
|
||||
Player.super.update(self, dt)
|
||||
end
|
||||
|
||||
return Player
|
||||
|
|
|
@ -48,6 +48,9 @@ function Actor2D:initPhysics(x, y, w, h)
|
|||
self.y = y or 0
|
||||
self.w = w or 0
|
||||
self.h = h or 0
|
||||
|
||||
self.xsp = 0
|
||||
self.ysp = 0
|
||||
end
|
||||
|
||||
function Actor2D:register()
|
||||
|
@ -69,12 +72,17 @@ end
|
|||
-- Theses functions are activated every steps
|
||||
|
||||
function Actor2D:update(dt)
|
||||
-- here will be update actions
|
||||
|
||||
self:autoMove()
|
||||
end
|
||||
|
||||
-- MOVEMENT FUNCTIONS
|
||||
-- Basic functions from the movement.
|
||||
|
||||
function Actor2D:autoMove()
|
||||
self:move(self.x + self.xsp, self.y + self.ysp)
|
||||
end
|
||||
|
||||
function Actor2D:move(newx, newy)
|
||||
self.world:moveActor(self, newx, newy)
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue