2019-08-14 16:26:23 +02:00
|
|
|
local Battler = require("scenes.battlesystem.actors.battler")
|
|
|
|
local Hero = Battler:extend()
|
2019-03-10 13:11:26 +01:00
|
|
|
|
2019-08-14 17:32:33 +02:00
|
|
|
-- INIT FUNCTIONS
|
|
|
|
-- Initialize the hero
|
|
|
|
|
2020-07-19 17:06:17 +02:00
|
|
|
function Hero:new(world, x, y, owner, charnumber)
|
2020-08-03 17:38:30 +02:00
|
|
|
Hero.super.new(self, world, x, y, 0, owner)
|
2019-08-14 20:24:32 +02:00
|
|
|
self:initSprite()
|
2020-08-22 23:28:05 +02:00
|
|
|
self.isKo = false
|
2021-05-09 15:07:38 +02:00
|
|
|
self.sprHeight = 32
|
2019-08-19 15:34:52 +02:00
|
|
|
end
|
|
|
|
|
2019-08-14 17:32:33 +02:00
|
|
|
-- UPDATE FUNCTION
|
|
|
|
-- Update the hero
|
|
|
|
|
2019-08-14 16:26:23 +02:00
|
|
|
function Hero:update(dt)
|
2019-08-16 23:04:30 +02:00
|
|
|
Hero.super.update(self, dt)
|
2020-07-25 16:47:29 +02:00
|
|
|
self:updateAnimation(dt)
|
2019-08-24 15:44:07 +02:00
|
|
|
end
|
2019-03-10 13:11:26 +01:00
|
|
|
|
2020-08-05 11:40:29 +02:00
|
|
|
-- HURT/DEATH FUNCTIONS
|
|
|
|
|
|
|
|
function Hero:getHurt()
|
|
|
|
self:changeAnimation("hurt")
|
|
|
|
end
|
|
|
|
|
|
|
|
function Hero:die()
|
2020-08-22 23:28:05 +02:00
|
|
|
if (not self.isKo) then
|
|
|
|
self:changeAnimation("getKo")
|
|
|
|
self.isKo = true
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2021-03-12 21:50:27 +01:00
|
|
|
function Hero:revive()
|
|
|
|
if (self.isKo) then
|
|
|
|
self:changeAnimation("idle")
|
|
|
|
self.isKo = false
|
2021-03-13 15:49:21 +01:00
|
|
|
self.isDefending = false
|
2021-03-12 21:50:27 +01:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2020-08-22 23:28:05 +02:00
|
|
|
function Hero:setAsKo()
|
2020-08-05 11:40:29 +02:00
|
|
|
self:changeAnimation("ko")
|
2020-08-22 23:28:05 +02:00
|
|
|
self.isKo = true
|
2020-08-05 11:40:29 +02:00
|
|
|
end
|
|
|
|
|
2019-08-24 15:44:07 +02:00
|
|
|
-- ASSETS FUNCTIONS
|
|
|
|
-- Load and play assets needed by the character
|
2019-08-14 17:32:33 +02:00
|
|
|
|
2020-08-04 22:19:11 +02:00
|
|
|
function Hero:getSpritePath()
|
|
|
|
return "datas/gamedata/characters/" .. self.owner.name .. "/sprites"
|
2019-08-14 17:32:33 +02:00
|
|
|
end
|
|
|
|
|
2020-07-25 16:47:29 +02:00
|
|
|
function Hero:updateAnimation(dt)
|
|
|
|
if (self.z > 0 and self.jump.useDefaultAnimation) then
|
|
|
|
if self.zspeed > 0 then
|
|
|
|
self:changeAnimation("jump")
|
|
|
|
else
|
|
|
|
self:changeAnimation("fall")
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2021-08-07 00:04:49 +02:00
|
|
|
self:setCustomSpeed(self.speed * 160 * dt)
|
2020-07-25 16:47:29 +02:00
|
|
|
end
|
|
|
|
|
2020-08-05 11:40:29 +02:00
|
|
|
function Hero:getNewAnimation(animation)
|
|
|
|
if (animation == "hurt") then
|
|
|
|
self:changeAnimation("idle")
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2021-03-13 18:00:39 +01:00
|
|
|
function Hero:flee()
|
|
|
|
if (not self.isKo) then
|
|
|
|
self:changeAnimation("walk")
|
|
|
|
self:goTo(-80, self.y, 3)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2019-08-14 20:24:32 +02:00
|
|
|
-- DRAW FUNCTIONS
|
|
|
|
-- Draw everything related to the hero
|
|
|
|
|
2019-08-14 17:32:33 +02:00
|
|
|
function Hero:draw()
|
2019-08-24 16:13:22 +02:00
|
|
|
self:drawSprite(0, -self.z)
|
2020-08-23 09:53:10 +02:00
|
|
|
|
|
|
|
if (self.isSelected) then
|
|
|
|
local x, y = self.world.map:gridToPixel(self.x, self.y, true)
|
|
|
|
self.assets.images["cursorpeak"]:draw(x - 7, y - 24 - 32)
|
|
|
|
end
|
|
|
|
|
2021-05-09 15:07:38 +02:00
|
|
|
self:drawOutput()
|
2019-08-14 17:32:33 +02:00
|
|
|
end
|
|
|
|
|
2019-08-14 16:26:23 +02:00
|
|
|
return Hero
|