]> git.localhorst.tv Git - l2e.git/blobdiff - src/battle/HeroTag.cpp
changed gauge level interpretation
[l2e.git] / src / battle / HeroTag.cpp
index 713fb8fe35774fbf9766ef72f8791236d8d6b277..4c344028735e14928e0fc2cd2d7921c9b559d87e 100644 (file)
@@ -10,6 +10,8 @@
 #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;
@@ -18,27 +20,37 @@ using geometry::Vector;
 namespace battle {
 
 void HeroTag::Render(SDL_Surface *screen, int width, int height, Point<int> position, bool active) 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, active ? 0 : 0xFF, active ? 0 : 0xFF));
-
-       destRect.x += 1;
-       destRect.y += 1;
-       destRect.w -= 2;
-       destRect.h -= 2;
-       SDL_FillRect(screen, &destRect, SDL_MapRGB(screen->format, 0, 0, 0));
-
+       // frame
+       Vector<int> frameOffset;
+       if (active) {
+               activeFrame->Draw(screen, position, width, height);
+               frameOffset = Vector<int>(activeFrame->BorderWidth(), activeFrame->BorderHeight());
+       } else {
+               frame->Draw(screen, position, width, height);
+               frameOffset = Vector<int>(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<int> healthGaugeOffset(gaugeX, 2 * frameOffset.Y());
+       healthGauge->Draw(screen, position + healthGaugeOffset, gaugeWidth, hero->RelativeHealth(gaugeWidth));
+       // mana gauge, third line
+       Vector<int> manaGaugeOffset(gaugeX, 3 * frameOffset.Y());
+       manaGauge->Draw(screen, position + manaGaugeOffset, gaugeWidth, hero->RelativeMana(gaugeWidth));
+       // ikari gauge, fourth line
+       Vector<int> ikariGaugeOffset(gaugeX, 4 * frameOffset.Y());
+       ikariGauge->Draw(screen, position + ikariGaugeOffset, gaugeWidth, hero->RelativeIP(gaugeWidth));
+
+       // hero
        Vector<int> heroOffset(
-                       (align == LEFT) ? 3 : width - hero->Sprite()->Width() - 3,
-                       height - hero->Sprite()->Height() - 3);
+                       (align == LEFT) ? yOffset : width - hero->Sprite()->Width() - yOffset,
+                       yOffset);
        hero->Sprite()->Draw(screen, position + heroOffset, 0, hero->Health() > 0 ? 0 : 2);
 }