2019-07-26 19:39:32 +02:00
|
|
|
local cwd = (...):gsub('%.player$', '') .. "."
|
|
|
|
local Parent = require(cwd .. "parent")
|
|
|
|
local Player = Parent:extend()
|
|
|
|
|
2020-08-03 09:44:25 +02:00
|
|
|
local Emblem = require "game.modules.gui.emblem"
|
|
|
|
|
2019-07-26 19:39:32 +02:00
|
|
|
function Player:new(world, x, y, z, id)
|
2019-07-27 21:02:33 +02:00
|
|
|
Player.super.new(self, world, "player", x, y, 0, 16, 12, 24, true)
|
2019-07-27 23:52:15 +02:00
|
|
|
self:setGravity(480*2)
|
2019-07-26 19:39:32 +02:00
|
|
|
|
2020-08-16 10:52:00 +02:00
|
|
|
self:init()
|
|
|
|
|
|
|
|
self.action = "normal"
|
|
|
|
|
|
|
|
self.rings = 0
|
|
|
|
self.score = 0
|
|
|
|
end
|
|
|
|
|
|
|
|
function Player:init()
|
2020-08-02 23:47:42 +02:00
|
|
|
self.charName = game.characters:getActiveCharacter()
|
2020-08-03 09:44:25 +02:00
|
|
|
self.assets:addSprite(self.charName, "datas/gamedata/characters/" .. self.charName .. "/sprites")
|
|
|
|
self:setSprite(self.charName, 8, 10)
|
2019-07-26 19:39:32 +02:00
|
|
|
self:cloneSprite()
|
2019-07-27 15:50:59 +02:00
|
|
|
|
2020-08-03 09:44:25 +02:00
|
|
|
self.emblem = Emblem(game.characters:getActiveCharacterData(), self.scene)
|
2020-08-16 10:52:00 +02:00
|
|
|
self.guiborder = game.gui.newBorder(424, 20, 6)
|
2019-07-26 19:39:32 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
function Player:updateStart(dt)
|
|
|
|
self.xfrc, self.yfrc = 480*3, 480*3
|
|
|
|
|
2020-08-16 10:52:00 +02:00
|
|
|
self:basicMovements()
|
|
|
|
|
2020-08-16 11:03:06 +02:00
|
|
|
if self.keys["A"].isPressed and (self.onGround) then
|
2020-08-16 10:52:00 +02:00
|
|
|
self.zsp = 280*1.33
|
|
|
|
end
|
|
|
|
|
|
|
|
if self.keys["B"].isPressed and (self.onGround) then
|
|
|
|
-- Nothing for the moment
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
function Player:basicMovements()
|
|
|
|
|
2019-10-13 17:49:44 +02:00
|
|
|
if self.keys["up"].isDown then
|
2019-07-27 23:52:15 +02:00
|
|
|
self.ysp = -160
|
2019-07-26 19:39:32 +02:00
|
|
|
end
|
2019-10-13 17:49:44 +02:00
|
|
|
if self.keys["down"].isDown then
|
2019-07-27 23:52:15 +02:00
|
|
|
self.ysp = 160
|
2019-07-26 19:39:32 +02:00
|
|
|
end
|
2020-08-16 10:52:00 +02:00
|
|
|
if (self.world.autorun == true) then
|
|
|
|
self.xsp = 160
|
|
|
|
else
|
|
|
|
if self.keys["left"].isDown then
|
|
|
|
self.xsp = -160
|
|
|
|
end
|
|
|
|
if self.keys["right"].isDown then
|
|
|
|
self.xsp = 160
|
|
|
|
end
|
2019-07-26 19:39:32 +02:00
|
|
|
end
|
|
|
|
|
2020-08-16 10:52:00 +02:00
|
|
|
end
|
2019-08-01 08:45:13 +02:00
|
|
|
|
2020-08-16 10:52:00 +02:00
|
|
|
function Player:collisionResponse(collision)
|
|
|
|
if collision.other.type == "collectible" then
|
|
|
|
collision.other.owner:getPicked(self)
|
2019-08-01 08:45:13 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
function Player:animationEnded(name)
|
2019-10-13 17:49:44 +02:00
|
|
|
|
2019-07-26 19:39:32 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
function Player:updateEnd(dt)
|
|
|
|
self:setAnimation()
|
|
|
|
end
|
|
|
|
|
|
|
|
function Player:setAnimation()
|
|
|
|
local gsp = utils.math.pointDistance(0, 0, self.xsp, self.ysp)
|
|
|
|
self:setCustomSpeed(math.abs(gsp) / 12)
|
|
|
|
self:setDirection(self.xsp)
|
2019-08-01 08:45:13 +02:00
|
|
|
if (self.action == "punching") then
|
|
|
|
--the animation system is already active
|
2019-07-26 19:39:32 +02:00
|
|
|
else
|
|
|
|
if (self.onGround) then
|
|
|
|
if (math.abs(self.xsp) > 0) or (math.abs(self.ysp) > 0) then
|
|
|
|
self:changeAnimation("walk", false)
|
|
|
|
else
|
|
|
|
self:changeAnimation("idle", false)
|
|
|
|
end
|
|
|
|
else
|
2019-07-27 23:45:52 +02:00
|
|
|
if (self.zsp) > 0 then
|
|
|
|
self:changeAnimation("jump", false)
|
|
|
|
else
|
|
|
|
self:changeAnimation("fall", false)
|
|
|
|
end
|
2019-07-26 19:39:32 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
function Player:setDirection(direction)
|
|
|
|
direction = direction or 0
|
|
|
|
if direction ~= 0 then
|
|
|
|
direction = utils.math.sign(direction)
|
|
|
|
self.direction = direction
|
|
|
|
self:setSpriteScallingX(direction)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2019-07-27 13:56:14 +02:00
|
|
|
function Player:getViewCenter()
|
|
|
|
local x, y = Player.super.getViewCenter(self)
|
|
|
|
return x, y-16
|
|
|
|
end
|
|
|
|
|
2019-07-26 19:39:32 +02:00
|
|
|
function Player:draw()
|
|
|
|
Player.super.draw(self)
|
|
|
|
end
|
|
|
|
|
|
|
|
function Player:drawHUD(id)
|
2020-08-03 09:44:25 +02:00
|
|
|
love.graphics.draw(self.guiborder, 0, 20, 0, 1, -1)
|
|
|
|
self.emblem:draw(424 - 40, 12)
|
2019-07-26 19:39:32 +02:00
|
|
|
end
|
|
|
|
|
2020-08-16 10:52:00 +02:00
|
|
|
function Player:setRing(value, isRelative)
|
|
|
|
if (isRelative == false) then
|
|
|
|
self.rings = 0
|
|
|
|
end
|
|
|
|
self.rings = self.rings + value
|
|
|
|
end
|
|
|
|
|
|
|
|
function Player:setScore(value, isRelative)
|
|
|
|
if (isRelative == false) then
|
|
|
|
self.score = 0
|
|
|
|
end
|
|
|
|
self.score = self.score + value
|
|
|
|
end
|
|
|
|
|
2019-07-26 19:39:32 +02:00
|
|
|
return Player
|