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
|
end
|
||||||
|
|
||||||
function Player:update(dt)
|
function Player:update(dt)
|
||||||
local dx, dy = 0, 0
|
self.xsp, self.ysp = 0, 0
|
||||||
if self.keys["up"].isDown then
|
if self.keys["up"].isDown then
|
||||||
dy = -120 * dt
|
self.ysp = -120 * dt
|
||||||
end
|
end
|
||||||
if self.keys["down"].isDown then
|
if self.keys["down"].isDown then
|
||||||
dy = 120 * dt
|
self.ysp = 120 * dt
|
||||||
end
|
end
|
||||||
if self.keys["left"].isDown then
|
if self.keys["left"].isDown then
|
||||||
dx = -120 * dt
|
self.xsp = -120 * dt
|
||||||
end
|
end
|
||||||
if self.keys["right"].isDown then
|
if self.keys["right"].isDown then
|
||||||
dx = 120 * dt
|
self.xsp = 120 * dt
|
||||||
end
|
end
|
||||||
|
|
||||||
self:move(self.x + dx, self.y + dy)
|
Player.super.update(self, dt)
|
||||||
end
|
end
|
||||||
|
|
||||||
return Player
|
return Player
|
||||||
|
|
|
@ -48,6 +48,9 @@ function Actor2D:initPhysics(x, y, w, h)
|
||||||
self.y = y or 0
|
self.y = y or 0
|
||||||
self.w = w or 0
|
self.w = w or 0
|
||||||
self.h = h or 0
|
self.h = h or 0
|
||||||
|
|
||||||
|
self.xsp = 0
|
||||||
|
self.ysp = 0
|
||||||
end
|
end
|
||||||
|
|
||||||
function Actor2D:register()
|
function Actor2D:register()
|
||||||
|
@ -69,12 +72,17 @@ end
|
||||||
-- Theses functions are activated every steps
|
-- Theses functions are activated every steps
|
||||||
|
|
||||||
function Actor2D:update(dt)
|
function Actor2D:update(dt)
|
||||||
-- here will be update actions
|
|
||||||
|
self:autoMove()
|
||||||
end
|
end
|
||||||
|
|
||||||
-- MOVEMENT FUNCTIONS
|
-- MOVEMENT FUNCTIONS
|
||||||
-- Basic functions from the movement.
|
-- Basic functions from the movement.
|
||||||
|
|
||||||
|
function Actor2D:autoMove()
|
||||||
|
self:move(self.x + self.xsp, self.y + self.ysp)
|
||||||
|
end
|
||||||
|
|
||||||
function Actor2D:move(newx, newy)
|
function Actor2D:move(newx, newy)
|
||||||
self.world:moveActor(self, newx, newy)
|
self.world:moveActor(self, newx, newy)
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue