sonic-radiance/sonic-radiance.love/scenes/battlesystem/actors/hero.lua

95 lines
1.8 KiB
Lua
Raw Normal View History

local Battler = require("scenes.battlesystem.actors.battler")
local Hero = Battler:extend()
2019-08-14 17:32:33 +02:00
-- INIT FUNCTIONS
-- Initialize the hero
function Hero:new(world, x, y, owner, charnumber)
Hero.super.new(self, world, x, y, 0, owner)
self:initSprite()
self.isKo = false
2021-05-09 15:07:38 +02:00
self.sprHeight = 32
end
2019-08-14 17:32:33 +02:00
-- UPDATE FUNCTION
-- Update the hero
function Hero:update(dt)
2019-08-16 23:04:30 +02:00
Hero.super.update(self, dt)
self:updateAnimation(dt)
end
2020-08-05 11:40:29 +02:00
-- HURT/DEATH FUNCTIONS
function Hero:getHurt()
self:changeAnimation("hurt")
end
function Hero:die()
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
function Hero:setAsKo()
2020-08-05 11:40:29 +02:00
self:changeAnimation("ko")
self.isKo = true
2020-08-05 11:40:29 +02:00
end
-- 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
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
2020-07-25 17:07:53 +02:00
self:setCustomSpeed(self.gspeed * 160 * dt)
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
-- 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)
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
return Hero