fix: add damage number system

Fix #39
This commit is contained in:
Kazhnuz 2020-08-22 23:53:13 +02:00
parent 4ff4c989d4
commit 5139d9727d
4 changed files with 43 additions and 0 deletions

View file

@ -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)

View file

@ -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()

View file

@ -66,6 +66,7 @@ end
function Hero:draw()
self:drawSprite(0, -self.z)
self:drawDamageNumber()
end
return Hero

View file

@ -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)