]> git.localhorst.tv Git - l2e.git/blob - src/battle/HeroTag.cpp
added struct for battle resources
[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 "Resources.h"
12 #include "../geometry/operators.h"
13 #include "../geometry/Vector.h"
14 #include "../graphics/Font.h"
15 #include "../graphics/Frame.h"
16 #include "../graphics/Gauge.h"
17 #include "../graphics/Sprite.h"
18
19 using geometry::Point;
20 using geometry::Vector;
21 using graphics::Frame;
22
23 namespace battle {
24
25 void HeroTag::Render(SDL_Surface *screen, int width, int height, Point<int> position, bool active) const {
26         // frame
27         const Frame *frame(active ? res->activeHeroTagFrame : res->heroTagFrame);
28         Vector<int> frameOffset(frame->BorderWidth(), frame->BorderHeight());
29         frame->Draw(screen, position, width, height);
30
31         int yOffset((height - hero->Sprite()->Height()) / 2);
32
33         // gauges
34         // NOTE: assuming frame border is unit size until charsets are impemented
35         int gaugeX((align == LEFT ? 10 : 6) * res->heroTagFont->CharWidth());
36         // 4 units reserved for hero, gaugeX already includes frame offset
37         int gaugeWidth(width - gaugeX - (align == LEFT ? 1 : 5) * res->heroTagFont->CharWidth());
38         // health gauge, second line
39         Vector<int> healthGaugeOffset(gaugeX, frameOffset.Y() + res->heroTagFont->CharHeight());
40         res->healthGauge->Draw(screen, position + healthGaugeOffset, gaugeWidth, hero->RelativeHealth(gaugeWidth));
41         // mana gauge, third line
42         Vector<int> manaGaugeOffset(gaugeX, frameOffset.Y() + 2 * res->heroTagFont->CharHeight());
43         res->manaGauge->Draw(screen, position + manaGaugeOffset, gaugeWidth, hero->RelativeMana(gaugeWidth));
44         // ikari gauge, fourth line
45         Vector<int> ikariGaugeOffset(gaugeX, frameOffset.Y() + 3 * res->heroTagFont->CharHeight());
46         res->ikariGauge->Draw(screen, position + ikariGaugeOffset, gaugeWidth, hero->RelativeIP(gaugeWidth));
47
48         // labels
49         int labelX((align == LEFT ? 5 : 1) * res->heroTagFont->CharWidth());
50         // level
51         Vector<int> levelLabelOffset(gaugeX, frameOffset.Y());
52         res->heroTagLabels->Draw(screen, position + levelLabelOffset, 0, 0);
53         // hp
54         Vector<int> healthLabelOffset(labelX, frameOffset.Y() + res->heroTagFont->CharHeight());
55         res->heroTagLabels->Draw(screen, position + healthLabelOffset, 0, 1);
56         // mp
57         Vector<int> manaLabelOffset(labelX, frameOffset.Y() + 2 * res->heroTagFont->CharHeight());
58         res->heroTagLabels->Draw(screen, position + manaLabelOffset, 0, 2);
59         // cm
60         Vector<int> moveLabelOffset(labelX, frameOffset.Y() + 3 * res->heroTagFont->CharHeight());
61         res->heroTagLabels->Draw(screen, position + moveLabelOffset, 0, 3);
62         // ip
63         Vector<int> ikariLabelOffset(labelX + 3 * res->heroTagFont->CharWidth(), frameOffset.Y() + 3 * res->heroTagFont->CharHeight());
64         res->heroTagLabels->Draw(screen, position + ikariLabelOffset, 0, 4);
65
66         // numbers
67         // level
68         Vector<int> levelNumberOffset(gaugeX + res->heroTagLabels->Width(), levelLabelOffset.Y());
69         res->heroTagFont->DrawNumber(hero->Level(), screen, position + levelNumberOffset, 2);
70         // health
71         Vector<int> healthNumberOffset(labelX + res->heroTagLabels->Width(), healthLabelOffset.Y());
72         res->heroTagFont->DrawNumber(hero->Health(), screen, position + healthNumberOffset, 3);
73         //mana
74         Vector<int> manaNumberOffset(labelX + res->heroTagLabels->Width(), manaLabelOffset.Y());
75         res->heroTagFont->DrawNumber(hero->Mana(), screen, position + manaNumberOffset, 3);
76
77         // hero
78         Vector<int> heroOffset(
79                         (align == LEFT) ? yOffset : width - hero->Sprite()->Width() - yOffset,
80                         yOffset);
81         hero->Sprite()->Draw(screen, position + heroOffset, 0, hero->Health() > 0 ? 0 : 2);
82 }
83
84 }