epervier-old/examples/gameplay/moveplayer/actors/player.lua

27 lines
572 B
Lua

local cwd = (...):gsub('%.player$', '') .. "."
local Parent = require(cwd .. "parent")
local Player = Parent:extend()
function Player:new(world, x, y)
Player.super.new(self, world, "player", x, y, 16, 16)
end
function Player:update(dt)
local dx, dy = 0, 0
if self.keys["up"].isPressed then
dy = -120 * dt
end
if self.keys["down"].isPressed then
dy = 120 * dt
end
if self.keys["left"].isPressed then
dx = -120 * dt
end
if self.keys["right"].isPressed then
dx = 120 * dt
end
self:move(self.x + dx, self.y + dy)
end
return Player