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

28 lines
565 B
Lua
Raw Normal View History

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
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