diff --git a/sonic-radiance.love/scenes/battlesystem/actors/battler.lua b/sonic-radiance.love/scenes/battlesystem/actors/battler.lua index bef1e9c..3529c59 100644 --- a/sonic-radiance.love/scenes/battlesystem/actors/battler.lua +++ b/sonic-radiance.love/scenes/battlesystem/actors/battler.lua @@ -26,6 +26,12 @@ function Battler:new(world, x, y, z, owner) self.isActive = false self.debugActiveTimer = 0 + self.damageNumber = {} + self.damageNumber.num = 0 + self.damageNumber.isBad = true + self.showDamage = false + self.damageY = 0 + self.isSelected = false self.owner = owner end @@ -34,6 +40,19 @@ function Battler:destroy() Battler.super.destroy(self) end +function Battler:getDamageNumberY() + return 32 +end + +function Battler:setDamageNumber(number) + self.damageNumber.isBad = number < 0 + self.damageNumber.num = math.abs(math.floor(number)) + self.damageY = self:getDamageNumberY() - 8 + self.tweens:newTween(0, 0.4, {damageY = self:getDamageNumberY()}, "outBack") + self.showDamage = true + self.tweens:newTimer(0.5, "removeDamage") +end + function Battler:setActive() core.debug:print("cbs/actor","actor " .. self.id .. " is active") self.isActive = true @@ -216,6 +235,8 @@ function Battler:timerResponse(signal) if (signal == "resetMovement") then self.movementType = MOVEMENT_NONE + elseif (signal == "removeDamage") then + self.showDamage = false end end @@ -237,6 +258,20 @@ function Battler:die() end -- DRAW FUNCTIONS +function Battler:drawDamageNumber() + if (self.showDamage) then + local x, y = self.world.map:gridToPixel(self.x, self.y, true) + if (self.damageNumber.isBad) then + love.graphics.setColor(1, 0, 0, 1) + else + love.graphics.setColor(0, 1, 0, 1) + end + + self.assets.fonts["hudnbrs_small"]:print(self.damageNumber.num, x, y - self.damageY, "center") + utils.graphics.resetColor() + end +end + function Battler:draw() local x, y = self.world.map:gridToPixel(self.x, self.y, true) love.graphics.setColor(1, 0, 0, 1) diff --git a/sonic-radiance.love/scenes/battlesystem/actors/ennemy.lua b/sonic-radiance.love/scenes/battlesystem/actors/ennemy.lua index 0259c4f..f75a9eb 100644 --- a/sonic-radiance.love/scenes/battlesystem/actors/ennemy.lua +++ b/sonic-radiance.love/scenes/battlesystem/actors/ennemy.lua @@ -28,6 +28,8 @@ function Ennemy:draw() local height = 32 self.assets.images["cursorpeak"]:draw(x - 7, y - 24 - 32) end + + self:drawDamageNumber() end function Ennemy:die() diff --git a/sonic-radiance.love/scenes/battlesystem/actors/hero.lua b/sonic-radiance.love/scenes/battlesystem/actors/hero.lua index 4c67468..a261d0b 100644 --- a/sonic-radiance.love/scenes/battlesystem/actors/hero.lua +++ b/sonic-radiance.love/scenes/battlesystem/actors/hero.lua @@ -66,6 +66,7 @@ end function Hero:draw() self:drawSprite(0, -self.z) + self:drawDamageNumber() end return Hero diff --git a/sonic-radiance.love/scenes/battlesystem/controllers/fighters/parent.lua b/sonic-radiance.love/scenes/battlesystem/controllers/fighters/parent.lua index be72284..f8e54fd 100644 --- a/sonic-radiance.love/scenes/battlesystem/controllers/fighters/parent.lua +++ b/sonic-radiance.love/scenes/battlesystem/controllers/fighters/parent.lua @@ -25,7 +25,12 @@ end -- LIFE handling functions function FighterParent:setHP(value, relative) + local relativeNumber = value + if (not relative) then + relativeNumber = relative - self.abstract.hp + end self.abstract:setHP(value, relative) + self.actor:setDamageNumber(relativeNumber) end function FighterParent:setPP(value, relative)