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 outputColor = {
good = {0, 1, 0},
bad = {1, 0, 0},
pp = {0.3, 0.8, 1}
}
function Battler:new(world, x, y, z, owner)
Battler.super.new(self, world, x, y, z)
@ -26,11 +32,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.output = {}
self.output.string = "0"
self.output.isBad = true
self.output.type = ""
self.showOutput = false
self.outputY = 0
self.isSelected = false
self.owner = owner
@ -42,18 +49,35 @@ function Battler:destroy()
Battler.super.destroy(self)
end
function Battler:getDamageNumberY()
return 32
function Battler:getOutputY()
return self.sprHeight or 32
end
function Battler:avoidedAttack()
self:newOutput("", "MISS")
end
function Battler:setDamageNumber(number, isPP)
self.damageNumber.isBad = number < 0
self.damageNumber.isPP = (isPP == true)
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")
local type = "good"
if (isPP == true) then type = "pp" end
if (number < 0) then type = "bad" end
local string = math.abs(math.floor(number))
self:newOutput(type, string)
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
function Battler:setActive()
@ -238,8 +262,8 @@ function Battler:timerResponse(signal)
if (signal == "resetMovement") then
self.movementType = MOVEMENT_NONE
elseif (signal == "removeDamage") then
self.showDamage = false
elseif (signal == "removeOutput") then
self.showOutput = false
end
end
@ -261,20 +285,13 @@ function Battler:die()
end
-- DRAW FUNCTIONS
function Battler:drawDamageNumber()
if (self.showDamage) then
function Battler:drawOutput()
if (self.showOutput) 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
if (self.damageNumber.isPP) then
love.graphics.setColor(0.3, 0.8, 1, 1)
else
love.graphics.setColor(0, 1, 0, 1)
end
end
local color = self:getOuputColor(self.output.type)
love.graphics.setColor(color[1], color[2], color[3], 1)
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()
end
end

View file

@ -9,6 +9,10 @@ function Ennemy:new(world, x, y, owner)
self.actionPerTurn = 2
self:initSprite()
if (self.owner.abstract.data.isAerial == true) then
self.z = 16
end
self.sprHeight = self.owner.abstract.data.hudHeight + 14
end
function Ennemy:setCheapEffect(cheapEffect)
@ -22,14 +26,13 @@ function Ennemy:draw()
self:drawSprite(0, -self.z)
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
local height = 32
self.assets.images["cursorpeak"]:draw(x - 7, y - 24 - 32)
self.assets.images["cursorpeak"]:draw(x - 7, (y - 24 - self.sprHeight) - self.z)
end
self:drawDamageNumber()
self:drawOutput()
end
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)
self:initSprite()
self.isKo = false
self.sprHeight = 32
end
-- UPDATE FUNCTION
@ -87,7 +88,7 @@ function Hero:draw()
self.assets.images["cursorpeak"]:draw(x - 7, y - 24 - 32)
end
self:drawDamageNumber()
self:drawOutput()
end
return Hero