From 193e9b6fbf13615e3095c84f1bb74b6f0c2f93c6 Mon Sep 17 00:00:00 2001 From: Kazhnuz Date: Sat, 13 Apr 2019 09:40:14 +0200 Subject: [PATCH] modules/world: add speed variables --- examples/gameplay/moveplayer/actors/player.lua | 12 ++++++------ gamecore/modules/world/actors/actor2D.lua | 10 +++++++++- 2 files changed, 15 insertions(+), 7 deletions(-) diff --git a/examples/gameplay/moveplayer/actors/player.lua b/examples/gameplay/moveplayer/actors/player.lua index caf51e7..debbd8d 100644 --- a/examples/gameplay/moveplayer/actors/player.lua +++ b/examples/gameplay/moveplayer/actors/player.lua @@ -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 diff --git a/gamecore/modules/world/actors/actor2D.lua b/gamecore/modules/world/actors/actor2D.lua index 1e9d6dc..469bec1 100644 --- a/gamecore/modules/world/actors/actor2D.lua +++ b/gamecore/modules/world/actors/actor2D.lua @@ -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