]> git.localhorst.tv Git - l2e.git/blob - src/battle/HeroTag.cpp
added and implemented swap heroes 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         // frame
33         const Frame *frame(active ? battle->Res().activeHeroTagFrame : battle->Res().heroTagFrame);
34         Vector<int> frameOffset(frame->BorderWidth(), frame->BorderHeight());
35         Vector<int> alignOffset((index % 2) ? 4 * battle->Res().heroTagFont->CharWidth() : 0, 0);
36         frame->Draw(screen, position, width, height);
37
38         const Hero &hero(battle->HeroAt(index));
39
40         // gauges
41         // NOTE: assuming frame border is unit size until charsets are impemented
42         int gaugeX(((index % 2) ? 10 : 6) * battle->Res().heroTagFont->CharWidth());
43         // 4 units reserved for hero, gaugeX already includes frame offset
44         int gaugeWidth(width - gaugeX - ((index % 2) ? 1 : 5) * battle->Res().heroTagFont->CharWidth());
45         // health gauge, second line
46         Vector<int> healthGaugeOffset(gaugeX, frameOffset.Y() + battle->Res().heroTagFont->CharHeight());
47         battle->Res().healthGauge->Draw(screen, position + healthGaugeOffset, gaugeWidth, hero.RelativeHealth(255));
48         // mana gauge, third line
49         Vector<int> manaGaugeOffset(gaugeX, frameOffset.Y() + 2 * battle->Res().heroTagFont->CharHeight());
50         battle->Res().manaGauge->Draw(screen, position + manaGaugeOffset, gaugeWidth, hero.RelativeMana(255));
51         // ikari gauge, fourth line
52         Vector<int> ikariGaugeOffset(gaugeX, frameOffset.Y() + 3 * battle->Res().heroTagFont->CharHeight());
53         battle->Res().ikariGauge->Draw(screen, position + ikariGaugeOffset, gaugeWidth, hero.RelativeIP(255));
54
55         // labels
56         int labelX(((index % 2) ? 5 : 1) * battle->Res().heroTagFont->CharWidth());
57         // level
58         Vector<int> levelLabelOffset(gaugeX, frameOffset.Y());
59         battle->Res().heroTagLabels->Draw(screen, position + levelLabelOffset, 0, 0);
60         // hp
61         Vector<int> healthLabelOffset(labelX, frameOffset.Y() + battle->Res().heroTagFont->CharHeight());
62         battle->Res().heroTagLabels->Draw(screen, position + healthLabelOffset, 0, 1);
63         // mp
64         Vector<int> manaLabelOffset(labelX, frameOffset.Y() + 2 * battle->Res().heroTagFont->CharHeight());
65         battle->Res().heroTagLabels->Draw(screen, position + manaLabelOffset, 0, 2);
66         // cm
67         Vector<int> moveLabelOffset(labelX, frameOffset.Y() + 3 * battle->Res().heroTagFont->CharHeight());
68         battle->Res().heroTagLabels->Draw(screen, position + moveLabelOffset, 0, 3);
69         // ip
70         Vector<int> ikariLabelOffset(labelX + 3 * battle->Res().heroTagFont->CharWidth(), frameOffset.Y() + 3 * battle->Res().heroTagFont->CharHeight());
71         battle->Res().heroTagLabels->Draw(screen, position + ikariLabelOffset, 0, 4);
72
73         // numbers
74         // level
75         Vector<int> levelNumberOffset(gaugeX + battle->Res().heroTagLabels->Width(), levelLabelOffset.Y());
76         battle->Res().heroTagFont->DrawNumber(hero.Level(), screen, position + levelNumberOffset, 2);
77         // health
78         Vector<int> healthNumberOffset(labelX + battle->Res().heroTagLabels->Width(), healthLabelOffset.Y());
79         battle->Res().heroTagFont->DrawNumber(hero.Health(), screen, position + healthNumberOffset, 3);
80         //mana
81         Vector<int> manaNumberOffset(labelX + battle->Res().heroTagLabels->Width(), manaLabelOffset.Y());
82         battle->Res().heroTagFont->DrawNumber(hero.Mana(), screen, position + manaNumberOffset, 3);
83
84         // name
85         battle->Res().normalFont->DrawString(hero.Name(), screen, position + frameOffset + alignOffset, 5);
86
87         // attack icon
88         if (battle->AttackChoiceAt(index).GetType() != AttackChoice::UNDECIDED) {
89                 Vector<int> attackIconOffset(labelX + battle->Res().heroTagLabels->Width(), frameOffset.Y() + 3 * battle->Res().heroTagFont->CharHeight());
90                 battle->Res().attackChoiceIcons->Draw(screen, position + attackIconOffset, 0, battle->AttackChoiceAt(index).GetType());
91         }
92
93         // hero
94         HeroSprite()->Draw(screen, position + HeroOffset(), 0, battle->HeroAt(index).Health() > 0 ? 0 : 2);
95 }
96
97 Vector<int> HeroTag::HeroOffset() const {
98         return Vector<int>(
99                         (index % 2) ? battle->Res().normalFont->CharWidth() : 10 * battle->Res().normalFont->CharWidth(),
100                         battle->Res().normalFont->CharWidth());
101 }
102
103 }