X-Git-Url: http://git.localhorst.tv/?a=blobdiff_plain;f=src%2Fbattle%2FHeroTag.cpp;h=4c344028735e14928e0fc2cd2d7921c9b559d87e;hb=cf20874f973521e84fc2aaa6cd47c56a278d9de7;hp=2461e4de92363b2a19b0c020e1dd5eb1ec6c64c1;hpb=010a336797f1419945bed60560cc61fb492793f4;p=l2e.git diff --git a/src/battle/HeroTag.cpp b/src/battle/HeroTag.cpp index 2461e4d..4c34402 100644 --- a/src/battle/HeroTag.cpp +++ b/src/battle/HeroTag.cpp @@ -7,28 +7,51 @@ #include "HeroTag.h" +#include "Hero.h" +#include "../geometry/operators.h" +#include "../geometry/Vector.h" +#include "../graphics/Frame.h" +#include "../graphics/Gauge.h" +#include "../graphics/Sprite.h" + using geometry::Point; +using geometry::Vector; namespace battle { -void HeroTag::Render(SDL_Surface *screen, int width, int height, Point position) const { - SDL_Rect destRect; - destRect.x = position.X(); - destRect.y = position.Y(); - destRect.w = width; - destRect.h = height; - - destRect.x += 1; - destRect.y += 1; - destRect.w -= 2; - destRect.h -= 2; - SDL_FillRect(screen, &destRect, SDL_MapRGB(screen->format, 0xFF, 0xFF, 0xFF)); - - destRect.x += 1; - destRect.y += 1; - destRect.w -= 2; - destRect.h -= 2; - SDL_FillRect(screen, &destRect, SDL_MapRGB(screen->format, 0, 0, 0)); +void HeroTag::Render(SDL_Surface *screen, int width, int height, Point position, bool active) const { + // frame + Vector frameOffset; + if (active) { + activeFrame->Draw(screen, position, width, height); + frameOffset = Vector(activeFrame->BorderWidth(), activeFrame->BorderHeight()); + } else { + frame->Draw(screen, position, width, height); + frameOffset = Vector(frame->BorderWidth(), frame->BorderHeight()); + } + + int yOffset((height - hero->Sprite()->Height()) / 2); + + // gauges + // NOTE: assuming frame border is unit size until charsets are impemented + int gaugeX((align == LEFT ? 10 : 6) * frameOffset.X()); + // 4 units reserved for hero, gaugeX already includes frame offset + int gaugeWidth(width - gaugeX - (align == LEFT ? 1 : 5) * frameOffset.X()); + // health gauge, second line + Vector healthGaugeOffset(gaugeX, 2 * frameOffset.Y()); + healthGauge->Draw(screen, position + healthGaugeOffset, gaugeWidth, hero->RelativeHealth(gaugeWidth)); + // mana gauge, third line + Vector manaGaugeOffset(gaugeX, 3 * frameOffset.Y()); + manaGauge->Draw(screen, position + manaGaugeOffset, gaugeWidth, hero->RelativeMana(gaugeWidth)); + // ikari gauge, fourth line + Vector ikariGaugeOffset(gaugeX, 4 * frameOffset.Y()); + ikariGauge->Draw(screen, position + ikariGaugeOffset, gaugeWidth, hero->RelativeIP(gaugeWidth)); + + // hero + Vector heroOffset( + (align == LEFT) ? yOffset : width - hero->Sprite()->Width() - yOffset, + yOffset); + hero->Sprite()->Draw(screen, position + heroOffset, 0, hero->Health() > 0 ? 0 : 2); } }