]> git.localhorst.tv Git - l2e.git/blob - src/battle/states/SelectTarget.cpp
added numbers animation for monsters' attacks
[l2e.git] / src / battle / states / SelectTarget.cpp
1 /*
2  * SelectTarget.cpp
3  *
4  *  Created on: Aug 9, 2012
5  *      Author: holy
6  */
7
8 #include "SelectTarget.h"
9
10 #include "SelectAttackType.h"
11 #include "../BattleState.h"
12 #include "../../app/Application.h"
13 #include "../../app/Input.h"
14 #include "../../geometry/operators.h"
15 #include "../../geometry/Point.h"
16
17 using app::Application;
18 using app::Input;
19 using geometry::Point;
20 using geometry::Vector;
21 using std::vector;
22
23 namespace battle {
24
25 void SelectTarget::EnterState(Application &c, SDL_Surface *screen) {
26         ctrl = &c;
27 }
28
29 void SelectTarget::ExitState(Application &c, SDL_Surface *screen) {
30         ctrl = 0;
31 }
32
33 void SelectTarget::ResumeState(Application &ctrl, SDL_Surface *screen) {
34
35 }
36
37 void SelectTarget::PauseState(Application &ctrl, SDL_Surface *screen) {
38
39 }
40
41
42 void SelectTarget::Resize(int width, int height) {
43
44 }
45
46
47 void SelectTarget::HandleEvents(const Input &input) {
48         if (input.JustPressed(Input::ACTION_A)) {
49                 if (selection->CurrentIsSelected()) {
50                         ctrl->PopState(); // return control to parent
51                 } else {
52                         selection->Select();
53                         if (selection->SelectSingle()) {
54                                 ctrl->PopState(); // return control to parent
55                         }
56                 }
57         }
58         if (input.JustPressed(Input::ACTION_B)) {
59                 if (selection->CurrentIsSelected()) {
60                         selection->Unselect();
61                 } else {
62                         selection->UnselectAll();
63                         ctrl->PopState(); // return control to parent
64                 }
65         }
66
67         if (input.JustPressed(Input::PAD_UP)) {
68                 selection->MoveUp();
69         }
70         if (input.JustPressed(Input::PAD_RIGHT)) {
71                 selection->MoveRight();
72         }
73         if (input.JustPressed(Input::PAD_DOWN)) {
74                 selection->MoveDown();
75         }
76         if (input.JustPressed(Input::PAD_LEFT)) {
77                 selection->MoveLeft();
78         }
79 }
80
81 void SelectTarget::UpdateWorld(float deltaT) {
82
83 }
84
85 void SelectTarget::Render(SDL_Surface *screen) {
86         Vector<int> offset(battle->CalculateScreenOffset(screen));
87         parent->Render(screen);
88         RenderCursors(screen, offset);
89 }
90
91 void SelectTarget::RenderCursors(SDL_Surface *screen, const geometry::Vector<int> &offset) {
92         // TODO: this should be related to the enemy's width
93         Vector<int> cursorOffset(cursorIcon->Width() / -2, cursorIcon->Height());
94         // offset the indicator by 1/8th to the right and top
95         Vector<int> indicatorOffset(cursorOffset + Vector<int>(cursorIcon->Width() / 8, cursorIcon->Height() / -8));
96         vector<Point<int> > positions;
97         if (selection->TargetsEnemies()) {
98                 for (vector<Point<int> >::const_iterator i(battle->MonsterPositions().begin()), end(battle->MonsterPositions().end()); i != end; ++i) {
99                         positions.push_back(*i);
100                 }
101         } else {
102                 for (int i(0), end(battle->NumHeroes()); i < end; ++i) {
103                         positions.push_back(battle->HeroTagPositionAt(i) + battle->HeroTagAt(i).HeroOffset());
104                 }
105         }
106         if (flipFlop) {
107                 for (vector<Point<int> >::size_type i(0); i < positions.size(); ++i) {
108                         if (selection->IsSelected(i)) {
109                                 cursorIcon->DrawTopRight(screen, positions[i] + indicatorOffset + offset);
110                         }
111                 }
112         }
113         flipFlop = !flipFlop;
114         cursorIcon->DrawTopRight(screen, positions[selection->Current()] + offset + cursorOffset);
115 }
116
117 }