]> git.localhorst.tv Git - l2e.git/blob - src/battle/states/SwapHeroes.cpp
removed useless comments
[l2e.git] / src / battle / states / SwapHeroes.cpp
1 #include "SwapHeroes.h"
2
3 #include "SelectMoveAction.h"
4 #include "../BattleState.h"
5 #include "../../app/Application.h"
6 #include "../../app/Input.h"
7 #include "../../math/Vector.h"
8
9 using app::Application;
10 using app::Input;
11 using math::Vector;
12 using std::vector;
13
14 namespace battle {
15
16 void SwapHeroes::OnEnterState(SDL_Surface *screen) {
17
18 }
19
20 void SwapHeroes::OnExitState(SDL_Surface *screen) {
21
22 }
23
24 void SwapHeroes::OnResumeState(SDL_Surface *screen) {
25
26 }
27
28 void SwapHeroes::OnPauseState(SDL_Surface *screen) {
29
30 }
31
32
33 void SwapHeroes::OnResize(int width, int height) {
34
35 }
36
37
38 void SwapHeroes::HandleEvents(const Input &input) {
39         if (input.JustPressed(Input::ACTION_A)) {
40                 if (selected != -1 && cursor != selected) {
41                         battle->SwapHeroes(cursor, selected);
42                         selected = -1;
43                 } else {
44                         selected = cursor;
45                 }
46         }
47         if (input.JustPressed(Input::ACTION_B)) {
48                 if (cursor == selected) {
49                         selected = -1;
50                 } else {
51                         Ctrl().PopState();
52                 }
53         }
54
55         if (input.JustPressed(Input::PAD_UP)) {
56                 MoveUp();
57         }
58         if (input.JustPressed(Input::PAD_RIGHT)) {
59                 MoveRight();
60         }
61         if (input.JustPressed(Input::PAD_DOWN)) {
62                 MoveDown();
63         }
64         if (input.JustPressed(Input::PAD_LEFT)) {
65                 MoveLeft();
66         }
67 }
68
69
70 void SwapHeroes::MoveUp() {
71         if (cursor < 2) {
72                 if (battle->HeroPositionOccupied(cursor + 2)) {
73                         cursor += 2;
74                 }
75         } else {
76                 cursor -= 2;
77         }
78 }
79
80 void SwapHeroes::MoveRight() {
81         if (cursor < 3 && battle->HeroPositionOccupied(cursor + 1)) {
82                 ++cursor;
83         } else {
84                 cursor = 0;
85         }
86 }
87
88 void SwapHeroes::MoveDown() {
89         if (cursor < 2) {
90                 if (battle->HeroPositionOccupied(cursor + 2)) {
91                         cursor += 2;
92                 }
93         } else {
94                 cursor -= 2;
95         }
96 }
97
98 void SwapHeroes::MoveLeft() {
99         if (cursor > 0) {
100                 --cursor;
101         } else {
102                 cursor = battle->NumHeroes();
103         }
104 }
105
106
107 void SwapHeroes::UpdateWorld(Uint32 deltaT) {
108
109 }
110
111 void SwapHeroes::Render(SDL_Surface *screen) {
112         Vector<int> offset(battle->CalculateScreenOffset(screen));
113         parent->Render(screen);
114         RenderCursors(screen, offset);
115 }
116
117 void SwapHeroes::RenderCursors(SDL_Surface *screen, const math::Vector<int> &offset) {
118         // offset the cursor by 1/8th to the left and bottom
119         Vector<int> cursorOffset(battle->Res().swapCursor->Width() / -8, battle->Res().swapCursor->Height() / 8);
120         Vector<int> indicatorOffset(0, 0);
121         vector<Vector<int> > positions;
122         for (int i(0), end(battle->NumHeroes()); i < end; ++i) {
123                 Vector<int> positionCorrection(battle->Res().swapCursor->Width() / 2, battle->HeroTagAt(i).HeroSprite()->Height() - battle->Res().swapCursor->Height() / 2);
124                 // indicator offsets are inverted for heroes
125                 positionCorrection -= cursorOffset;
126                 positions.push_back(battle->HeroTagPositionAt(i) + battle->HeroTagAt(i).HeroOffset() + positionCorrection);
127         }
128         if (flipFlop) {
129                 for (vector<Vector<int> >::size_type i(0); i < positions.size(); ++i) {
130                         if (selected == int(i)) {
131                                 battle->Res().swapCursor->DrawTopRight(screen, positions[i] + offset);
132                         }
133                 }
134         }
135         flipFlop = !flipFlop;
136         battle->Res().swapCursor->DrawTopRight(screen, positions[cursor] + offset + cursorOffset);
137 }
138
139 }