feat: improve damage output drawing

This commit is contained in:
Kazhnuz 2021-05-09 15:07:38 +02:00
parent cc66f86bd1
commit 034fb9cee6
3 changed files with 55 additions and 34 deletions

View file

@ -9,6 +9,12 @@ local ZGRAVITY = 0.2
local MIDDLE_ARENA = 6 local MIDDLE_ARENA = 6
local outputColor = {
good = {0, 1, 0},
bad = {1, 0, 0},
pp = {0.3, 0.8, 1}
}
function Battler:new(world, x, y, z, owner) function Battler:new(world, x, y, z, owner)
Battler.super.new(self, world, x, y, z) Battler.super.new(self, world, x, y, z)
@ -26,11 +32,12 @@ function Battler:new(world, x, y, z, owner)
self.isActive = false self.isActive = false
self.debugActiveTimer = 0 self.debugActiveTimer = 0
self.damageNumber = {} self.output = {}
self.damageNumber.num = 0 self.output.string = "0"
self.damageNumber.isBad = true self.output.isBad = true
self.showDamage = false self.output.type = ""
self.damageY = 0 self.showOutput = false
self.outputY = 0
self.isSelected = false self.isSelected = false
self.owner = owner self.owner = owner
@ -42,18 +49,35 @@ function Battler:destroy()
Battler.super.destroy(self) Battler.super.destroy(self)
end end
function Battler:getDamageNumberY() function Battler:getOutputY()
return 32 return self.sprHeight or 32
end
function Battler:avoidedAttack()
self:newOutput("", "MISS")
end end
function Battler:setDamageNumber(number, isPP) function Battler:setDamageNumber(number, isPP)
self.damageNumber.isBad = number < 0 local type = "good"
self.damageNumber.isPP = (isPP == true) if (isPP == true) then type = "pp" end
self.damageNumber.num = math.abs(math.floor(number)) if (number < 0) then type = "bad" end
self.damageY = self:getDamageNumberY() - 8 local string = math.abs(math.floor(number))
self.tweens:newTween(0, 0.4, {damageY = self:getDamageNumberY()}, "outBack")
self.showDamage = true self:newOutput(type, string)
self.tweens:newTimer(0.5, "removeDamage") end
function Battler:newOutput(type, string)
self.output.type = type or ""
self.output.string = string or "error"
self.outputY = self:getOutputY() - 8
self.showOutput = true
self.tweens:newTween(0, 0.4, {outputY = self:getOutputY()}, "outQuad")
self.tweens:newTimer(0.5, "removeOutput")
end
function Battler:getOuputColor(type)
return outputColor[type] or {1,1,1}
end end
function Battler:setActive() function Battler:setActive()
@ -238,8 +262,8 @@ function Battler:timerResponse(signal)
if (signal == "resetMovement") then if (signal == "resetMovement") then
self.movementType = MOVEMENT_NONE self.movementType = MOVEMENT_NONE
elseif (signal == "removeDamage") then elseif (signal == "removeOutput") then
self.showDamage = false self.showOutput = false
end end
end end
@ -261,20 +285,13 @@ function Battler:die()
end end
-- DRAW FUNCTIONS -- DRAW FUNCTIONS
function Battler:drawDamageNumber() function Battler:drawOutput()
if (self.showDamage) then if (self.showOutput) then
local x, y = self.world.map:gridToPixel(self.x, self.y, true) local x, y = self.world.map:gridToPixel(self.x, self.y, true)
if (self.damageNumber.isBad) then local color = self:getOuputColor(self.output.type)
love.graphics.setColor(1, 0, 0, 1) love.graphics.setColor(color[1], color[2], color[3], 1)
else
if (self.damageNumber.isPP) then
love.graphics.setColor(0.3, 0.8, 1, 1)
else
love.graphics.setColor(0, 1, 0, 1)
end
end
self.assets.fonts["hudnbrs_small"]:print(self.damageNumber.num, x, y - self.damageY, "center") self.assets.fonts["hudnbrs_small"]:print(self.output.string, x, y - self.outputY - self.z, "center")
utils.graphics.resetColor() utils.graphics.resetColor()
end end
end end

View file

@ -9,6 +9,10 @@ function Ennemy:new(world, x, y, owner)
self.actionPerTurn = 2 self.actionPerTurn = 2
self:initSprite() self:initSprite()
if (self.owner.abstract.data.isAerial == true) then
self.z = 16
end
self.sprHeight = self.owner.abstract.data.hudHeight + 14
end end
function Ennemy:setCheapEffect(cheapEffect) function Ennemy:setCheapEffect(cheapEffect)
@ -22,14 +26,13 @@ function Ennemy:draw()
self:drawSprite(0, -self.z) self:drawSprite(0, -self.z)
local x, y = self.world.map:gridToPixel(self.x, self.y, true) local x, y = self.world.map:gridToPixel(self.x, self.y, true)
self.owner:drawOversprite(x - 12, y - (self.owner.abstract.data.hudHeight * self.sprite.sy) - self.z) self.owner:drawOversprite(x - 12, y - ((self.sprHeight - 8) * self.sprite.sy) - self.z)
if (self.isSelected) then if (self.isSelected) then
local height = 32 self.assets.images["cursorpeak"]:draw(x - 7, (y - 24 - self.sprHeight) - self.z)
self.assets.images["cursorpeak"]:draw(x - 7, y - 24 - 32)
end end
self:drawDamageNumber() self:drawOutput()
end end
function Ennemy:die() function Ennemy:die()

View file

@ -8,6 +8,7 @@ function Hero:new(world, x, y, owner, charnumber)
Hero.super.new(self, world, x, y, 0, owner) Hero.super.new(self, world, x, y, 0, owner)
self:initSprite() self:initSprite()
self.isKo = false self.isKo = false
self.sprHeight = 32
end end
-- UPDATE FUNCTION -- UPDATE FUNCTION
@ -87,7 +88,7 @@ function Hero:draw()
self.assets.images["cursorpeak"]:draw(x - 7, y - 24 - 32) self.assets.images["cursorpeak"]:draw(x - 7, y - 24 - 32)
end end
self:drawDamageNumber() self:drawOutput()
end end
return Hero return Hero