sonic-radiance/sonic-radiance.love/scenes/overworld/actors/player.lua

48 lines
1.1 KiB
Lua
Raw Normal View History

local cwd = (...):gsub('%.player$', '') .. "."
local Parent = require(cwd .. "parent")
local Player = Parent:extend()
function Player:new(world, x, y, id)
Player.super.new(self, world, "player", x, y, 16, 16, true)
2020-08-01 18:54:12 +02:00
self.charset:addTexture("perso")
end
2020-08-01 18:54:12 +02:00
function Player:isMoving()
return ((math.abs(self.ysp) > 0.01) or (math.abs(self.xsp) > 0.01))
end
function Player:updateStart(dt)
self.xfrc, self.yfrc = 480*3, 480*3
if self.keys["up"].isDown then
self.ysp = -120
2020-08-01 18:54:12 +02:00
self.charDir = "up"
end
if self.keys["down"].isDown then
self.ysp = 120
2020-08-01 18:54:12 +02:00
self.charDir = "down"
end
if self.keys["left"].isDown then
self.xsp = -120
2020-08-01 18:54:12 +02:00
self.charDir = "left"
end
if self.keys["right"].isDown then
self.xsp = 120
2020-08-01 18:54:12 +02:00
self.charDir = "right"
end
end
function Player:draw()
2020-08-01 18:54:12 +02:00
if (self:isMoving()) then
self.charset:draw("perso", 1, self.charDir, self.x, self.y)
else
self.charset:drawStanding("perso", 1, self.charDir, self.x, self.y)
end
end
function Player:drawHUD(id)
love.graphics.print(id .. " test", 4, 4)
end
return Player