2021-04-10 14:43:30 +02:00
|
|
|
local Parent = require "scenes.overworld.actors.parent"
|
2020-08-01 16:57:12 +02:00
|
|
|
local Player = Parent:extend()
|
|
|
|
|
2021-05-05 11:41:25 +02:00
|
|
|
local TweenManager = require "birb.classes.time"
|
2021-04-10 17:14:41 +02:00
|
|
|
local Team = require "scenes.overworld.actors.player.team"
|
|
|
|
local Interactions = require "scenes.overworld.actors.player.interactions"
|
|
|
|
local Actions = require "scenes.overworld.actors.player.actions"
|
|
|
|
local Charset = require "scenes.overworld.actors.player.charset"
|
|
|
|
local Map = require "scenes.overworld.actors.player.map"
|
2021-04-18 18:23:52 +02:00
|
|
|
local Health = require "scenes.overworld.actors.player.health"
|
2020-08-03 10:28:18 +02:00
|
|
|
|
2021-04-10 17:14:41 +02:00
|
|
|
Player:implement(Team)
|
|
|
|
Player:implement(Interactions)
|
|
|
|
Player:implement(Actions)
|
|
|
|
Player:implement(Charset)
|
|
|
|
Player:implement(Map)
|
2021-04-18 18:23:52 +02:00
|
|
|
Player:implement(Health)
|
2020-08-03 10:28:18 +02:00
|
|
|
|
2021-04-10 17:14:41 +02:00
|
|
|
local FRICTION = 480 * 3
|
|
|
|
local GRAV = 10
|
2021-04-18 10:09:17 +02:00
|
|
|
local DEFAULT_GROUND_LEVEL = 0
|
|
|
|
local DEFAULT_GROUND_HEIGHT = 0
|
2021-04-18 12:34:30 +02:00
|
|
|
local RESPAWN_LIMIT = -32
|
2020-08-03 10:28:18 +02:00
|
|
|
|
2021-04-10 17:14:41 +02:00
|
|
|
function Player:new(world, x, y, id)
|
|
|
|
Player.super.new(self, world, "player", x, y, 16, 16, true)
|
2021-04-18 10:09:17 +02:00
|
|
|
self.groundLevel = DEFAULT_GROUND_LEVEL
|
|
|
|
self.groundHeight = DEFAULT_GROUND_HEIGHT
|
|
|
|
self.z = self.groundLevel
|
2021-04-18 12:34:30 +02:00
|
|
|
self.grav = GRAV
|
2020-08-03 10:28:18 +02:00
|
|
|
self.tweens = TweenManager(self)
|
2020-08-01 16:57:12 +02:00
|
|
|
|
2021-04-10 14:28:20 +02:00
|
|
|
self.onGround = true
|
2021-04-10 17:14:41 +02:00
|
|
|
self.xfrc, self.yfrc = FRICTION, FRICTION
|
|
|
|
|
|
|
|
self:initTeam()
|
|
|
|
self:initInteractions()
|
|
|
|
self:initActions()
|
|
|
|
self:initPlayerCharset()
|
|
|
|
self:initMap()
|
2021-04-18 18:23:52 +02:00
|
|
|
self:initHealth()
|
2020-08-01 16:57:12 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
function Player:updateStart(dt)
|
2021-04-21 18:36:20 +02:00
|
|
|
self.interactionName = ""
|
2020-08-03 10:28:18 +02:00
|
|
|
self.tweens:update(dt)
|
2021-04-18 10:53:35 +02:00
|
|
|
self:updateTerrain()
|
2021-04-18 19:59:03 +02:00
|
|
|
self:updateActiveCharacter()
|
2021-03-14 18:21:44 +01:00
|
|
|
|
2021-04-18 12:34:30 +02:00
|
|
|
self:act()
|
2021-03-23 21:59:33 +01:00
|
|
|
|
2021-04-10 17:14:41 +02:00
|
|
|
self.world:getTileTypeAtPoint(self.x, self.y)
|
2021-04-10 14:28:20 +02:00
|
|
|
|
2021-04-10 17:14:41 +02:00
|
|
|
self:updateInteraction()
|
2021-04-10 14:28:20 +02:00
|
|
|
self:updateCurrentCharset()
|
2021-04-10 17:14:41 +02:00
|
|
|
self:updateCurrentMap()
|
2021-04-21 19:06:38 +02:00
|
|
|
self:updateOutsideMap()
|
2021-04-10 17:14:41 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
-- PHYSICS FUNCTIONS
|
|
|
|
-- Some functions to hook up the physic system
|
|
|
|
function Player:goUpward(zsp)
|
|
|
|
self.zsp = zsp
|
|
|
|
self.grav = GRAV
|
|
|
|
self.onGround = false
|
2021-03-20 17:23:14 +01:00
|
|
|
end
|
|
|
|
|
2021-04-10 14:28:20 +02:00
|
|
|
function Player:applyGravity(dt)
|
|
|
|
local grav = self.grav * -1
|
|
|
|
self.zsp = self.zsp + (grav * dt)
|
|
|
|
|
|
|
|
if utils.math.sign(self.zsp) == utils.math.sign(grav) then
|
2021-04-10 17:14:41 +02:00
|
|
|
self:checkGround()
|
2021-04-10 14:28:20 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
function Player:checkGround()
|
2021-04-18 10:09:17 +02:00
|
|
|
if (self.z + self.zsp <= self.groundLevel) then
|
2021-04-10 14:28:20 +02:00
|
|
|
self.onGround = true
|
2021-04-18 10:09:17 +02:00
|
|
|
self.z = self.groundLevel
|
2021-04-10 14:28:20 +02:00
|
|
|
self.zsp = 0
|
2021-04-10 17:14:41 +02:00
|
|
|
self:endJump()
|
2021-04-18 12:34:30 +02:00
|
|
|
if (self.z <= RESPAWN_LIMIT) then
|
|
|
|
self.x = self.lastPos.x
|
|
|
|
self.y = self.lastPos.y
|
2021-04-19 18:04:29 +02:00
|
|
|
self:takeDamage(self.fallDamage)
|
2021-04-21 16:46:41 +02:00
|
|
|
if (not utils.string.isEmpty(self.fallSound)) then
|
|
|
|
self.assets:playSFX(self.fallSound)
|
|
|
|
end
|
2021-04-18 12:34:30 +02:00
|
|
|
end
|
2021-04-10 14:28:20 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
function Player:autoMove(dt)
|
|
|
|
Player.super.autoMove(self, dt)
|
|
|
|
self.z = self.z + self.zsp
|
|
|
|
end
|
|
|
|
|
2021-04-10 17:14:41 +02:00
|
|
|
-- RESPONSES
|
|
|
|
-- Reponse to timer and collisions
|
2021-03-21 16:19:28 +01:00
|
|
|
|
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
|
2021-04-10 17:14:41 +02:00
|
|
|
self:collideWithGizmo(other)
|
|
|
|
elseif (hitbox.type == "btnInput" and other.needButton) then
|
|
|
|
self:talkToGizmo(other)
|
2021-03-20 17:23:14 +01:00
|
|
|
end
|
2021-03-21 16:30:46 +01:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2020-08-03 10:28:18 +02:00
|
|
|
function Player:timerResponse(response)
|
|
|
|
if (response == "changeCharacter") then
|
2021-04-10 17:14:41 +02:00
|
|
|
self:endCharacterSwitchAnimation()
|
2021-04-10 18:28:52 +02:00
|
|
|
elseif (response == "endFly") then
|
|
|
|
self:endFly()
|
2021-04-10 20:47:34 +02:00
|
|
|
elseif (response == "endPunch") then
|
|
|
|
self:endPunch()
|
2020-08-01 18:54:12 +02:00
|
|
|
end
|
2020-08-01 16:57:12 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
function Player:drawHUD(id)
|
2021-04-18 18:23:52 +02:00
|
|
|
self:drawHealth((424 - self.scene:getEmblemsPosition()) - 48, 168)
|
2020-08-20 15:39:02 +02:00
|
|
|
self:drawEmblems(self.scene:getEmblemsPosition(), 24)
|
2021-04-21 18:36:20 +02:00
|
|
|
if (not utils.string.isEmpty(self.interactionName)) then
|
|
|
|
local w = self.assets.fonts["small"]:getWidth(self.interactionName) + 16
|
|
|
|
love.graphics.setColor(0,0,0,0.5)
|
|
|
|
local x, y = 424 - w + 4, 240 - 24
|
|
|
|
love.graphics.rectangle("fill", x - w/2, y + 1, w, 15, 8, 8)
|
|
|
|
utils.graphics.resetColor()
|
|
|
|
self.assets.fonts["small"]:draw(self.interactionName, x, y, -1, "center")
|
|
|
|
end
|
2020-08-03 10:28:18 +02:00
|
|
|
end
|
|
|
|
|
2021-04-10 19:32:41 +02:00
|
|
|
function Player:draw()
|
|
|
|
Player.super.draw(self)
|
|
|
|
self:drawActionEffect()
|
|
|
|
end
|
|
|
|
|
2020-08-01 16:57:12 +02:00
|
|
|
return Player
|