4 * Created on: Aug 9, 2012
8 #include "SelectTarget.h"
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"
17 using app::Application;
19 using geometry::Point;
20 using geometry::Vector;
25 void SelectTarget::EnterState(Application &c, SDL_Surface *screen) {
29 void SelectTarget::ExitState(Application &c, SDL_Surface *screen) {
33 void SelectTarget::ResumeState(Application &ctrl, SDL_Surface *screen) {
37 void SelectTarget::PauseState(Application &ctrl, SDL_Surface *screen) {
42 void SelectTarget::Resize(int width, int height) {
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
53 if (selection->SelectSingle()) {
54 ctrl->PopState(); // return control to parent
58 if (input.JustPressed(Input::ACTION_B)) {
59 if (selection->CurrentIsSelected()) {
60 selection->Unselect();
62 selection->UnselectAll();
63 ctrl->PopState(); // return control to parent
67 if (input.JustPressed(Input::PAD_UP)) {
70 if (input.JustPressed(Input::PAD_RIGHT)) {
71 selection->MoveRight();
73 if (input.JustPressed(Input::PAD_DOWN)) {
74 selection->MoveDown();
76 if (input.JustPressed(Input::PAD_LEFT)) {
77 selection->MoveLeft();
81 void SelectTarget::UpdateWorld(float deltaT) {
85 void SelectTarget::Render(SDL_Surface *screen) {
86 Vector<int> offset(battle->CalculateScreenOffset(screen));
87 parent->Render(screen);
88 RenderCursors(screen, offset);
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->TargetsMonsters()) {
98 for (int i(0), end(battle->MaxMonsters()); i < end; ++i) {
99 positions.push_back(battle->MonsterAt(i).Position());
102 for (int i(0), end(battle->NumHeroes()); i < end; ++i) {
103 positions.push_back(battle->HeroTagPositionAt(i) + battle->HeroTagAt(i).HeroOffset());
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);
113 flipFlop = !flipFlop;
114 cursorIcon->DrawTopRight(screen, positions[selection->Current()] + offset + cursorOffset);