2020-08-01 16:57:12 +02:00
|
|
|
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")
|
2020-08-03 08:59:04 +02:00
|
|
|
self.active = game.characters:getActiveCharacterData()
|
2020-08-01 18:54:12 +02:00
|
|
|
end
|
2020-08-01 16:57:12 +02:00
|
|
|
|
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))
|
2020-08-01 16:57:12 +02:00
|
|
|
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"
|
2020-08-01 16:57:12 +02:00
|
|
|
end
|
|
|
|
if self.keys["down"].isDown then
|
|
|
|
self.ysp = 120
|
2020-08-01 18:54:12 +02:00
|
|
|
self.charDir = "down"
|
2020-08-01 16:57:12 +02:00
|
|
|
end
|
|
|
|
if self.keys["left"].isDown then
|
|
|
|
self.xsp = -120
|
2020-08-01 18:54:12 +02:00
|
|
|
self.charDir = "left"
|
2020-08-01 16:57:12 +02:00
|
|
|
end
|
|
|
|
if self.keys["right"].isDown then
|
|
|
|
self.xsp = 120
|
2020-08-01 18:54:12 +02:00
|
|
|
self.charDir = "right"
|
2020-08-01 16:57:12 +02:00
|
|
|
end
|
2020-08-03 08:59:04 +02:00
|
|
|
|
|
|
|
if self.keys["select"].isPressed then
|
|
|
|
game.characters:setActiveCharacter()
|
|
|
|
self.active = game.characters:getActiveCharacterData()
|
|
|
|
end
|
2020-08-01 16:57:12 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
function Player:draw()
|
2020-08-01 18:54:12 +02:00
|
|
|
if (self:isMoving()) then
|
2020-08-03 08:59:04 +02:00
|
|
|
self.charset:draw(self.active.data.charset, self.active.data.charId, self.charDir, self.x, self.y)
|
2020-08-01 18:54:12 +02:00
|
|
|
else
|
2020-08-03 08:59:04 +02:00
|
|
|
self.charset:drawStanding(self.active.data.charset, self.active.data.charId, self.charDir, self.x, self.y)
|
2020-08-01 18:54:12 +02:00
|
|
|
end
|
2020-08-01 16:57:12 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
function Player:drawHUD(id)
|
2020-08-02 15:56:36 +02:00
|
|
|
local border = 8
|
|
|
|
self.assets.images["guiRing"]:draw(border, border)
|
|
|
|
local ringString = utils.math.numberToString(game.loot.rings, 3)
|
|
|
|
self.assets.fonts["hudnbrs"]:print(ringString, border + 14, border + 1)
|
|
|
|
--love.graphics.print(id .. " test", 4, 4)
|
2020-08-01 16:57:12 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
return Player
|