2020-08-01 16:57:12 +02:00
|
|
|
local cwd = (...):gsub('%.player$', '') .. "."
|
|
|
|
local Parent = require(cwd .. "parent")
|
|
|
|
local Player = Parent:extend()
|
|
|
|
|
2020-08-03 10:28:18 +02:00
|
|
|
local Emblem = require "game.modules.gui.emblem"
|
|
|
|
|
|
|
|
local TweenManager = require "game.modules.tweenmanager"
|
|
|
|
|
2020-08-01 16:57:12 +02:00
|
|
|
function Player:new(world, x, y, id)
|
|
|
|
Player.super.new(self, world, "player", x, y, 16, 16, true)
|
2020-08-03 08:59:04 +02:00
|
|
|
self.active = game.characters:getActiveCharacterData()
|
2020-08-03 10:28:18 +02:00
|
|
|
|
|
|
|
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)
|
2021-03-20 17:23:14 +01:00
|
|
|
self.lastCollision = -1
|
|
|
|
self.haveCollided = false
|
2020-08-01 16:57:12 +02:00
|
|
|
|
2021-03-23 21:59:33 +01:00
|
|
|
self.previousMap = 0
|
|
|
|
|
2021-03-21 16:19:28 +01:00
|
|
|
self:updateCurrentCharset()
|
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
|
|
|
|
2020-08-03 10:28:18 +02:00
|
|
|
if self.keys["select"].isPressed and self.canChangeActive then
|
2020-08-03 08:59:04 +02:00
|
|
|
game.characters:setActiveCharacter()
|
2020-08-03 10:28:18 +02:00
|
|
|
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)
|
2021-03-14 18:21:44 +01:00
|
|
|
|
|
|
|
self.world:getTileTypeAtPoint(self.x, self.y)
|
2021-03-20 17:23:14 +01:00
|
|
|
|
|
|
|
if (self.haveCollided == false) then
|
|
|
|
self.lastCollision = nil
|
|
|
|
end
|
|
|
|
self.haveCollided = false
|
2021-03-23 21:59:33 +01:00
|
|
|
|
|
|
|
local currentMap = self.world.map:getMapAtPoint(self.x, self.y)
|
|
|
|
if (currentMap ~= nil) then
|
|
|
|
if (self.previousMap ~= currentMap.id) then
|
|
|
|
self.previousMap = currentMap.id
|
|
|
|
self.scene:updateCurrentMap(currentMap)
|
|
|
|
end
|
|
|
|
end
|
2021-03-20 17:23:14 +01:00
|
|
|
end
|
|
|
|
|
2021-03-21 16:19:28 +01:00
|
|
|
function Player:updateCurrentCharset()
|
|
|
|
self:setCharset(self.active.data.charset, self.active.data.charId)
|
|
|
|
end
|
|
|
|
|
2021-03-20 17:23:14 +01:00
|
|
|
function Player:collisionResponse(col)
|
2021-03-21 16:32:29 +01:00
|
|
|
local hitbox = col.other
|
|
|
|
local other = col.other.owner
|
|
|
|
if (not other.isDestroyed) then
|
|
|
|
if (hitbox.type == "gizmo") then
|
|
|
|
if (other.needButton) then
|
2021-03-20 17:23:14 +01:00
|
|
|
if (self.keys["A"].isPressed) then
|
2021-03-21 16:32:29 +01:00
|
|
|
other:doAction()
|
2021-03-20 17:23:14 +01:00
|
|
|
self.haveCollided = true
|
2021-03-21 16:32:29 +01:00
|
|
|
self.lastCollision = other.creationID
|
2021-03-20 17:23:14 +01:00
|
|
|
end
|
|
|
|
else
|
2021-03-21 16:32:29 +01:00
|
|
|
if (self.lastCollision ~= other.creationID) then
|
|
|
|
other:doAction()
|
2021-03-20 17:23:14 +01:00
|
|
|
end
|
|
|
|
self.haveCollided = true
|
2021-03-21 16:32:29 +01:00
|
|
|
self.lastCollision = other.creationID
|
2021-03-20 17:23:14 +01:00
|
|
|
end
|
|
|
|
end
|
2021-03-21 16:32:29 +01:00
|
|
|
if (hitbox.type == "btnInput" and other.needButton) then
|
|
|
|
if (self.keys["A"].isPressed and (self:faceRightDirection(other))) then
|
|
|
|
other:doAction()
|
2021-03-20 17:23:14 +01:00
|
|
|
self.haveCollided = true
|
2021-03-21 16:32:29 +01:00
|
|
|
self.lastCollision = other.creationID
|
2021-03-20 17:23:14 +01:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2020-08-03 10:28:18 +02:00
|
|
|
end
|
|
|
|
|
2021-03-21 16:30:46 +01:00
|
|
|
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
|
|
|
|
|
2020-08-03 10:28:18 +02:00
|
|
|
function Player:timerResponse(response)
|
|
|
|
if (response == "changeCharacter") then
|
|
|
|
self.canChangeActive = true
|
|
|
|
self.activeVisible = game.characters.active
|
2020-08-03 08:59:04 +02:00
|
|
|
self.active = game.characters:getActiveCharacterData()
|
2021-03-21 16:19:28 +01:00
|
|
|
self:updateCurrentCharset()
|
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
|
|
|
--love.graphics.print(id .. " test", 4, 4)
|
2020-08-20 15:39:02 +02:00
|
|
|
self:drawEmblems(self.scene:getEmblemsPosition(), 24)
|
2020-08-03 10:28:18 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
function Player:drawEmblems(x, y)
|
2021-03-21 16:19:28 +01:00
|
|
|
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
|
2020-08-01 16:57:12 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
return Player
|