]> git.localhorst.tv Git - l2e.git/blob - src/battle/HeroTag.cpp
added small hero tags (used in battle animation and run state)
[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 "AttackChoice.h"
11 #include "BattleState.h"
12 #include "Hero.h"
13 #include "Resources.h"
14 #include "../geometry/operators.h"
15 #include "../geometry/Vector.h"
16 #include "../graphics/Font.h"
17 #include "../graphics/Frame.h"
18 #include "../graphics/Gauge.h"
19 #include "../graphics/Sprite.h"
20
21 using geometry::Point;
22 using geometry::Vector;
23 using graphics::Frame;
24
25 namespace battle {
26
27 const graphics::Sprite *HeroTag::HeroSprite() const {
28         return battle->HeroAt(index).Sprite();
29 }
30
31 void HeroTag::Render(SDL_Surface *screen, int width, int height, Point<int> position, bool active) const {
32         const Resources &r(battle->Res());
33
34         // frame
35         const Frame *frame(active ? r.activeHeroTagFrame : r.heroTagFrame);
36         Vector<int> frameOffset(frame->BorderWidth(), frame->BorderHeight());
37         Vector<int> alignOffset((index % 2) ? 4 * r.heroTagFont->CharWidth() : 0, 0);
38         frame->Draw(screen, position, width, height);
39
40         const Hero &hero(battle->HeroAt(index));
41
42         // gauges
43         // NOTE: assuming frame border is unit size until charsets are impemented
44         int gaugeX(((index % 2) ? 10 : 6) * r.heroTagFont->CharWidth());
45         // 4 units reserved for hero, gaugeX already includes frame offset
46         int gaugeWidth(width - gaugeX - ((index % 2) ? 1 : 5) * r.heroTagFont->CharWidth());
47         // health gauge, second line
48         Vector<int> healthGaugeOffset(gaugeX, frameOffset.Y() + r.heroTagFont->CharHeight());
49         r.healthGauge->Draw(screen, position + healthGaugeOffset, gaugeWidth, hero.RelativeHealth(255));
50         // mana gauge, third line
51         Vector<int> manaGaugeOffset(gaugeX, frameOffset.Y() + 2 * r.heroTagFont->CharHeight());
52         r.manaGauge->Draw(screen, position + manaGaugeOffset, gaugeWidth, hero.RelativeMana(255));
53         // ikari gauge, fourth line
54         Vector<int> ikariGaugeOffset(gaugeX, frameOffset.Y() + 3 * r.heroTagFont->CharHeight());
55         r.ikariGauge->Draw(screen, position + ikariGaugeOffset, gaugeWidth, hero.RelativeIP(255));
56
57         // labels
58         int labelX(((index % 2) ? 5 : 1) * r.heroTagFont->CharWidth());
59         // level
60         Vector<int> levelLabelOffset(gaugeX, frameOffset.Y());
61         r.heroTagLabels->Draw(screen, position + levelLabelOffset, r.levelLabelCol, r.levelLabelRow);
62         // hp
63         Vector<int> healthLabelOffset(labelX, frameOffset.Y() + r.heroTagFont->CharHeight());
64         r.heroTagLabels->Draw(screen, position + healthLabelOffset, r.healthLabelCol, r.healthLabelRow);
65         // mp
66         Vector<int> manaLabelOffset(labelX, frameOffset.Y() + 2 * r.heroTagFont->CharHeight());
67         r.heroTagLabels->Draw(screen, position + manaLabelOffset, r.manaLabelCol, r.manaLabelRow);
68         // cm
69         Vector<int> moveLabelOffset(labelX, frameOffset.Y() + 3 * r.heroTagFont->CharHeight());
70         r.heroTagLabels->Draw(screen, position + moveLabelOffset, r.moveLabelCol, r.moveLabelRow);
71         // ip
72         Vector<int> ikariLabelOffset(labelX + 3 * r.heroTagFont->CharWidth(), frameOffset.Y() + 3 * r.heroTagFont->CharHeight());
73         r.heroTagLabels->Draw(screen, position + ikariLabelOffset, r.ikariLabelCol, r.ikariLabelRow);
74
75         // numbers
76         // level
77         Vector<int> levelNumberOffset(gaugeX + r.heroTagLabels->Width(), levelLabelOffset.Y());
78         r.heroTagFont->DrawNumber(hero.Level(), screen, position + levelNumberOffset, 2);
79         // health
80         Vector<int> healthNumberOffset(labelX + r.heroTagLabels->Width(), healthLabelOffset.Y());
81         r.heroTagFont->DrawNumber(hero.Health(), screen, position + healthNumberOffset, 3);
82         //mana
83         Vector<int> manaNumberOffset(labelX + r.heroTagLabels->Width(), manaLabelOffset.Y());
84         r.heroTagFont->DrawNumber(hero.Mana(), screen, position + manaNumberOffset, 3);
85
86         // name
87         r.normalFont->DrawString(hero.Name(), screen, position + frameOffset + alignOffset, 5);
88
89         // attack icon
90         if (battle->AttackChoiceAt(index).GetType() != AttackChoice::UNDECIDED) {
91                 Vector<int> attackIconOffset(labelX + r.heroTagLabels->Width(), frameOffset.Y() + 3 * r.heroTagFont->CharHeight());
92                 r.attackChoiceIcons->Draw(screen, position + attackIconOffset, 0, battle->AttackChoiceAt(index).GetType());
93         }
94
95         // hero
96         HeroSprite()->Draw(screen, position + HeroOffset(), 0, battle->HeroAt(index).Health() > 0 ? 0 : 2);
97 }
98
99 Vector<int> HeroTag::HeroOffset() const {
100         return Vector<int>(
101                         (index % 2) ? battle->Res().normalFont->CharWidth() : 10 * battle->Res().normalFont->CharWidth(),
102                         battle->Res().normalFont->CharWidth());
103 }
104
105 }