]> git.localhorst.tv Git - l2e.git/blob - src/battle/HeroTag.cpp
added gauges for health, mana, and ikari displays
[l2e.git] / src / battle / HeroTag.cpp
1 /*
2  * HeroTag.cpp
3  *
4  *  Created on: Aug 6, 2012
5  *      Author: holy
6  */
7
8 #include "HeroTag.h"
9
10 #include "Hero.h"
11 #include "../geometry/operators.h"
12 #include "../geometry/Vector.h"
13 #include "../graphics/Frame.h"
14 #include "../graphics/Gauge.h"
15 #include "../graphics/Sprite.h"
16
17 using geometry::Point;
18 using geometry::Vector;
19
20 namespace battle {
21
22 void HeroTag::Render(SDL_Surface *screen, int width, int height, Point<int> position, bool active) const {
23         // frame
24         Vector<int> frameOffset;
25         if (active) {
26                 activeFrame->Draw(screen, position, width, height);
27                 frameOffset = Vector<int>(activeFrame->BorderWidth(), activeFrame->BorderHeight());
28         } else {
29                 frame->Draw(screen, position, width, height);
30                 frameOffset = Vector<int>(frame->BorderWidth(), frame->BorderHeight());
31         }
32
33         int yOffset((height - hero->Sprite()->Height()) / 2);
34
35         // gauges
36         // NOTE: assuming frame border is unit size until charsets are impemented
37         int gaugeX((align == LEFT ? 10 : 6) * frameOffset.X());
38         // 4 units reserved for hero, gaugeX already includes frame offset
39         int gaugeWidth(width - gaugeX - (align == LEFT ? 1 : 5) * frameOffset.X());
40         // health gauge, second line
41         Vector<int> healthGaugeOffset(gaugeX, 2 * frameOffset.Y());
42         healthGauge->Draw(screen, position + healthGaugeOffset, gaugeWidth, hero->RelativeHealth(256));
43         // mana gauge, third line
44         Vector<int> manaGaugeOffset(gaugeX, 3 * frameOffset.Y());
45         manaGauge->Draw(screen, position + manaGaugeOffset, gaugeWidth, hero->RelativeMana(256));
46         // ikari gauge, fourth line
47         Vector<int> ikariGaugeOffset(gaugeX, 4 * frameOffset.Y());
48         ikariGauge->Draw(screen, position + ikariGaugeOffset, gaugeWidth, hero->RelativeIP(256));
49
50         // hero
51         Vector<int> heroOffset(
52                         (align == LEFT) ? yOffset : width - hero->Sprite()->Width() - yOffset,
53                         yOffset);
54         hero->Sprite()->Draw(screen, position + heroOffset, 0, hero->Health() > 0 ? 0 : 2);
55 }
56
57 }