From ef788afd70e171ae6cf9b81e92786155e21ff4e9 Mon Sep 17 00:00:00 2001 From: Kazhnuz Date: Thu, 11 Mar 2021 23:47:32 +0100 Subject: [PATCH] feat: add boss hp bar Fixes #25 --- sonic-radiance.love/assets/gui/crown.png | Bin 0 -> 922 bytes sonic-radiance.love/assets/gui/hpbar_boss.png | Bin 0 -> 744 bytes .../assets/gui/strings/boss.png | Bin 0 -> 646 bytes .../game/modules/gui/bosshpbar.lua | 30 ++++++++++++++++++ .../scenes/battlesystem/actors/ennemy.lua | 2 +- .../scenes/battlesystem/assets.lua | 1 + .../battlesystem/controllers/ennemy.lua | 6 ++++ .../controllers/fighters/villain.lua | 17 +++++++++- 8 files changed, 54 insertions(+), 2 deletions(-) create mode 100644 sonic-radiance.love/assets/gui/crown.png create mode 100644 sonic-radiance.love/assets/gui/hpbar_boss.png create mode 100644 sonic-radiance.love/assets/gui/strings/boss.png create mode 100644 sonic-radiance.love/game/modules/gui/bosshpbar.lua diff --git a/sonic-radiance.love/assets/gui/crown.png b/sonic-radiance.love/assets/gui/crown.png new file mode 100644 index 0000000000000000000000000000000000000000..8371f003caa433e9b1449a1cfeb9342d1435003b GIT binary patch literal 922 zcmV;L17-Y)P)EX>4Tx04R}tk-JO7P!z_$rb^J!6+*3G)xkXa5Rx<` zDK3tJYr#Qu@ipilAi6rZ3WA^rA};;|z7{F*+$7KXt};05McE_!Ms}cHC>%b-jaa;Pdq0ZrcGQT zp4hYv#z(|Ga!FK(FNlXtIw0{Y(#qW`;OM%oiJ2YGAo!YQ$5-aYfU~ zpIi4>VZ6;)Q!BE6PIkj+USC?IIz&5$6jW?Lg8>V9@Q_fUZxuEYRCQ7;WT-1i**5p- zcYOq!lUy&EW@b?)PtkP%dyBsrTZOSv&nZgI?Jth=F#v>ifm+pZevTcdb^-*Sfor`! zU#1)MfbeCscX_6aJ2*UJsF}Yx>ArfS117QXY^b-p!*Jpta|zR|8e>V zWVe9yEwFz83>L|It;M~=etz>D+GW$sQG2LJ#8WJyFpR5;76lQB=iKorM+1*#+{ zi7SH%8@uj=&{R7yI`s=MnK=3-aB+}{kdP3klf@7mOc-$_aWgT&#SJ07mgsZPnwCOj z;7yl%@Bh1Z|9b};gmP_Bt}SdMlxvIcwZ!*Yn?u)ipj=x5uO?b+(OQcPD{Je*{fu&L zIceTuNEZcCYxj+1!S2Z6t&^ot%JcF%OTeP~3_wcGFb8uW6)Uc_`-Z|6=O#~qDOZ;P z=Z_DG0~7lHOjoWgjdE4C@@SK~BU)?my_QVs&gL(@%J2{-!-~kTvJ$$s`$oAM6GUN+ za#b4TY67ZUTcl^LwL_xNC=8G=AB9F>tAU{?@M;NI4BE5A_gc$&0F3CB>-T#An1eYB zE6117UFml?CJQSE!1d|uZ=5pG!uN}SLTLwzKTr-F7DxFQ%zT>uuF{xIczX_F`55qa w9KblBc$fy@c;AFhu+(3c(Z?r1;@1Ft1N}1?$4z-2HUIzs07*qoM6N<$g4||{bN~PV literal 0 HcmV?d00001 diff --git a/sonic-radiance.love/assets/gui/hpbar_boss.png b/sonic-radiance.love/assets/gui/hpbar_boss.png new file mode 100644 index 0000000000000000000000000000000000000000..6686087e77bbf798a091bcd581f67c5b50c1c016 GIT binary patch literal 744 zcmVP)EX>4Tx04R}tkv&MmKpe$iTcxG6IM_kOAwzYtAS&XhRVYG*P%E_RU~=gfG-*gu zTpR`0f`cE6RRx%k-{RDAVPqQIx48bLV{L}6cZWRPkQ)=9KT2|nOqex zax9<*6_Voz|AXJ%n#IWpHz|??dS7h&V+0890jVfq16NwdUuyz0pQJZB zTKov;+XgPKJDR))Tbr*WBLP`#607veZ@j1~@nb zMoW~v?(yzWcW?imY4`U7{e^OPy0|u500006VoOIv0RI600RN!9r;`8x010qNS#tmY zE+YT{E+YYWr9XB6000McNliru9AtNs7*h&BZ0338hSad^gZEa<4bO1wgWnpw> zWFU8GbZ8()Y-w$9b7k&M7zY3V0KG{>K~!ko?U%t0!ypVp<7xl@%igI{g&<`%XW<)>KuCF@td;oGI5cPckxdVvCK7gzSqTC0N zl|Xdt1IQ{Ms`&u20*LB9_K?|o$eHU7joD1-K|Kk!s2-(+q|3F4(3`%OA|z}_J3BKt z*^C|4UbOo;;$;+mJeAv?`C9L&28=IasuDpN%oYkUMNIuiO!WqLwvQd{YJ6>EX>4Tx04R}tkv&MmKpe$iTcxG6IM_kOAwzYtAS&XhRVYG*P%E_RU~=gfG-*gu zTpR`0f`cE6RRx%k-{RDAVPqQIx48bLV{L}6cZWRPkQ)=9KT2|nOqex zax9<*6_Voz|AXJ%n#IWpHz|??dS7h&V+0890jVfq16NwdUuyz0pQJZB zTKov;+XgPKJDR))Tbr*WBLP`#607veZ@j1~@nb zMoW~v?(yzWcW?imY4`U7{e^OPy0|u500006VoOIv0RI600RN!9r;`8x010qNS#tmY zE+YT{E+YYWr9XB6000McNliru9BQ5)9m(KtI0338hSad^gZEa<4bO1wgWnpw> zWFU8GbZ8()Y-w$9b7k&M7zY3V09#2!K~y-)&66<>z#t3*FBSj)vO5)}lt9D)^@a`< z+X@DV%_;!WcdnTcv4^j+5)G16&odMLUWQ#9&?~7=F>>FkP4D0KSi0U!btBWB{kz`Y g0!14-V|L=7-b)EM7L5M>5&!@I07*qoM6N<$f^*;vYybcN literal 0 HcmV?d00001 diff --git a/sonic-radiance.love/game/modules/gui/bosshpbar.lua b/sonic-radiance.love/game/modules/gui/bosshpbar.lua new file mode 100644 index 0000000..c00c2e5 --- /dev/null +++ b/sonic-radiance.love/game/modules/gui/bosshpbar.lua @@ -0,0 +1,30 @@ +local BossHpBar = Object:extend() + +local TweenManager = require "game.modules.tweenmanager" +local ComplexHPBar = require "game.modules.gui.complexhpbar" + +function BossHpBar:new(hp) + self.tweens = TweenManager(self) + self.hp = hp + self.baseHP = hp + self.hpbar = ComplexHPBar(120) + self.hpbar:setColorForeground(248/255, 160/255, 0, 1) + self.hpbar:setColorBackground(112/255, 0, 0) + + self.bossTexture = love.graphics.newImage("assets/gui/strings/boss.png") +end + +function BossHpBar:setHP(newHP) + self.tweens:newTween(0, 0.1, {hp = newHP}, 'inCubic') +end + +function BossHpBar:update(dt) + self.tweens:update(dt) +end + +function BossHpBar:draw(x, y) + self.hpbar:draw(x, y, self.hp / self.baseHP) + love.graphics.draw(self.bossTexture, x + 98, y + 10) +end + +return BossHpBar \ No newline at end of file diff --git a/sonic-radiance.love/scenes/battlesystem/actors/ennemy.lua b/sonic-radiance.love/scenes/battlesystem/actors/ennemy.lua index f75a9eb..63cbfc2 100644 --- a/sonic-radiance.love/scenes/battlesystem/actors/ennemy.lua +++ b/sonic-radiance.love/scenes/battlesystem/actors/ennemy.lua @@ -22,7 +22,7 @@ function Ennemy:draw() self:drawSprite(0, -self.z) local x, y = self.world.map:gridToPixel(self.x, self.y, true) - self.owner:drawHUD(x - 12, y - self.owner.abstract.data.hudHeight - self.z) + self.owner:drawOversprite(x - 12, y - (self.owner.abstract.data.hudHeight * self.sprite.sy) - self.z) if (self.isSelected) then local height = 32 diff --git a/sonic-radiance.love/scenes/battlesystem/assets.lua b/sonic-radiance.love/scenes/battlesystem/assets.lua index 7191589..5425526 100644 --- a/sonic-radiance.love/scenes/battlesystem/assets.lua +++ b/sonic-radiance.love/scenes/battlesystem/assets.lua @@ -37,6 +37,7 @@ return { {"game", "assets/gui/strings/game.png"}, {"over", "assets/gui/strings/over.png"}, {"arrow", "assets/gui/arrow.png"}, + {"crown", "assets/gui/crown.png"} }, ["fonts"] = { {"small", "assets/gui/fonts/PixelOperator.ttf", 16}, diff --git a/sonic-radiance.love/scenes/battlesystem/controllers/ennemy.lua b/sonic-radiance.love/scenes/battlesystem/controllers/ennemy.lua index bf3724a..d9a2652 100644 --- a/sonic-radiance.love/scenes/battlesystem/controllers/ennemy.lua +++ b/sonic-radiance.love/scenes/battlesystem/controllers/ennemy.lua @@ -37,4 +37,10 @@ function EnnemyController:addBoss(ennData) self:add(boss) end +function EnnemyController:draw() + for i, villain in ipairs(self.list) do + villain:drawHUD() + end +end + return EnnemyController diff --git a/sonic-radiance.love/scenes/battlesystem/controllers/fighters/villain.lua b/sonic-radiance.love/scenes/battlesystem/controllers/fighters/villain.lua index 6751c1d..948a6cf 100644 --- a/sonic-radiance.love/scenes/battlesystem/controllers/fighters/villain.lua +++ b/sonic-radiance.love/scenes/battlesystem/controllers/fighters/villain.lua @@ -2,6 +2,7 @@ local FighterParent = require "scenes.battlesystem.controllers.fighters.parent" local VillainFighter = FighterParent:extend() local SimpleHPBar = require "game.modules.gui.simplehpbar" +local BossHPBar = require "game.modules.gui.bosshpbar" local EnnemyAction = require "scenes.battlesystem.controllers.fighters.systems.ennemyaction" local behaviourList = require "scenes.battlesystem.controllers.fighters.systems.behaviours" @@ -24,6 +25,11 @@ end function VillainFighter:updateAssets(dt) self.hpbar:update(dt) + if (self.bossHpBar ~= nil) then + self.bossHpBar:update(dt) + else + self.bossHpBar = BossHPBar(self.abstract.hp) + end end function VillainFighter:getAbstract() @@ -84,6 +90,7 @@ end function VillainFighter:setHP(value, relative) VillainFighter.super.setHP(self, value, relative) self.hpbar:setHP(self.abstract.hp) + self.bossHpBar:setHP(self.abstract.hp) end -- DRAW FUNCTIONS @@ -92,9 +99,17 @@ function VillainFighter:drawIcon(x, y) self.assets.fonts["hudnbrs_small"]:print(self.id, x+10, y+8) end -function VillainFighter:drawHUD(x, y) +function VillainFighter:drawOversprite(x, y) if (not self.isBoss) then self.hpbar:draw(x, y) + else + self.assets.images["crown"]:draw(x, y - 2) + end +end + +function VillainFighter:drawHUD() + if (self.isBoss and self.bossHpBar ~= nil) then + self.bossHpBar:draw(280, 28) end end