137 lines
3.6 KiB
Lua
137 lines
3.6 KiB
Lua
local cwd = (...):gsub('%.player$', '') .. "."
|
|
local Parent = require(cwd .. "parent")
|
|
local Player = Parent:extend()
|
|
|
|
local Emblem = require "game.modules.gui.emblem"
|
|
|
|
local TweenManager = require "game.modules.tweenmanager"
|
|
|
|
function Player:new(world, x, y, id)
|
|
Player.super.new(self, world, "player", x, y, 16, 16, true)
|
|
self.active = game.characters:getActiveCharacterData()
|
|
|
|
self.emblems = {}
|
|
for i, name in ipairs(game.characters.team) do
|
|
game.characters:loadSprite(self.assets, name)
|
|
self.emblems[i] = Emblem(game.characters.list[name], self.scene)
|
|
end
|
|
|
|
self.activeVisible = game.characters.active
|
|
self.canChangeActive = true
|
|
|
|
self.tweens = TweenManager(self)
|
|
self.lastCollision = -1
|
|
self.haveCollided = false
|
|
|
|
self:updateCurrentCharset()
|
|
end
|
|
|
|
function Player:updateStart(dt)
|
|
self.xfrc, self.yfrc = 480*3, 480*3
|
|
|
|
if self.keys["up"].isDown then
|
|
self.ysp = -120
|
|
self.charDir = "up"
|
|
end
|
|
if self.keys["down"].isDown then
|
|
self.ysp = 120
|
|
self.charDir = "down"
|
|
end
|
|
if self.keys["left"].isDown then
|
|
self.xsp = -120
|
|
self.charDir = "left"
|
|
end
|
|
if self.keys["right"].isDown then
|
|
self.xsp = 120
|
|
self.charDir = "right"
|
|
end
|
|
|
|
if self.keys["select"].isPressed and self.canChangeActive then
|
|
game.characters:setActiveCharacter()
|
|
self.canChangeActive = false
|
|
self.tweens:newTimer(0.3, "changeCharacter")
|
|
self.tweens:newTween(0, 0.3, {activeVisible = self.activeVisible + 1}, "inQuad")
|
|
end
|
|
|
|
self.tweens:update(dt)
|
|
|
|
self.world:getTileTypeAtPoint(self.x, self.y)
|
|
|
|
if (self.haveCollided == false) then
|
|
self.lastCollision = nil
|
|
end
|
|
self.haveCollided = false
|
|
end
|
|
|
|
function Player:updateCurrentCharset()
|
|
self:setCharset(self.active.data.charset, self.active.data.charId)
|
|
end
|
|
|
|
function Player:collisionResponse(col)
|
|
local hitbox = col.other
|
|
local other = col.other.owner
|
|
if (not other.isDestroyed) then
|
|
if (hitbox.type == "gizmo") then
|
|
if (other.needButton) then
|
|
if (self.keys["A"].isPressed) then
|
|
other:doAction()
|
|
self.haveCollided = true
|
|
self.lastCollision = other.creationID
|
|
end
|
|
else
|
|
if (self.lastCollision ~= other.creationID) then
|
|
other:doAction()
|
|
end
|
|
self.haveCollided = true
|
|
self.lastCollision = other.creationID
|
|
end
|
|
end
|
|
if (hitbox.type == "btnInput" and other.needButton) then
|
|
if (self.keys["A"].isPressed and (self:faceRightDirection(other))) then
|
|
other:doAction()
|
|
self.haveCollided = true
|
|
self.lastCollision = other.creationID
|
|
end
|
|
end
|
|
end
|
|
end
|
|
|
|
function Player:faceRightDirection(other)
|
|
if (self.charDir == "up") then
|
|
return (self.y >= other.y + other.h)
|
|
end
|
|
if (self.charDir == "down") then
|
|
return (self.y + self.h <= other.y)
|
|
end
|
|
if (self.charDir == "left") then
|
|
return (self.x >= other.x + other.w)
|
|
end
|
|
if (self.charDir == "right") then
|
|
return (self.x + self.w <= other.x)
|
|
end
|
|
end
|
|
|
|
function Player:timerResponse(response)
|
|
if (response == "changeCharacter") then
|
|
self.canChangeActive = true
|
|
self.activeVisible = game.characters.active
|
|
self.active = game.characters:getActiveCharacterData()
|
|
self:updateCurrentCharset()
|
|
end
|
|
end
|
|
|
|
function Player:drawHUD(id)
|
|
--love.graphics.print(id .. " test", 4, 4)
|
|
self:drawEmblems(self.scene:getEmblemsPosition(), 24)
|
|
end
|
|
|
|
function Player:drawEmblems(x, y)
|
|
for i,emblem in ipairs(self.emblems) do
|
|
local angle = ((i-self.activeVisible) * (360/#self.emblems)) - 90
|
|
local rad = math.rad(angle)
|
|
local emblemX, emblemY = utils.math.lengthdir(18, rad)
|
|
emblem:draw(x + emblemX, y + emblemY)
|
|
end
|
|
end
|
|
|
|
return Player
|