4 * Created on: Aug 10, 2012
8 #include "SwapHeroes.h"
10 #include "SelectMoveAction.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 SwapHeroes::EnterState(Application &c, SDL_Surface *screen) {
29 void SwapHeroes::ExitState(Application &c, SDL_Surface *screen) {
33 void SwapHeroes::ResumeState(Application &ctrl, SDL_Surface *screen) {
37 void SwapHeroes::PauseState(Application &ctrl, SDL_Surface *screen) {
42 void SwapHeroes::Resize(int width, int height) {
47 void SwapHeroes::HandleEvents(const Input &input) {
48 if (input.JustPressed(Input::ACTION_A)) {
49 if (selected != -1 && cursor != selected) {
50 battle->SwapHeroes(cursor, selected);
56 if (input.JustPressed(Input::ACTION_B)) {
57 if (cursor == selected) {
64 if (input.JustPressed(Input::PAD_UP)) {
67 if (input.JustPressed(Input::PAD_RIGHT)) {
70 if (input.JustPressed(Input::PAD_DOWN)) {
73 if (input.JustPressed(Input::PAD_LEFT)) {
79 void SwapHeroes::MoveUp() {
81 if (battle->HeroPositionOccupied(cursor + 2)) {
89 void SwapHeroes::MoveRight() {
90 if (cursor < 3 && battle->HeroPositionOccupied(cursor + 1)) {
97 void SwapHeroes::MoveDown() {
99 if (battle->HeroPositionOccupied(cursor + 2)) {
107 void SwapHeroes::MoveLeft() {
111 cursor = battle->Heroes().size();
116 void SwapHeroes::UpdateWorld(float deltaT) {
120 void SwapHeroes::Render(SDL_Surface *screen) {
121 Vector<int> offset(battle->CalculateScreenOffset(screen));
122 parent->Render(screen);
123 RenderCursors(screen, offset);
126 void SwapHeroes::RenderCursors(SDL_Surface *screen, const geometry::Vector<int> &offset) {
127 // offset the cursor by 1/8th to the left and bottom
128 Vector<int> cursorOffset(battle->Res().swapCursor->Width() / -8, battle->Res().swapCursor->Height() / 8);
129 Vector<int> indicatorOffset(0, 0);
130 vector<Point<int> > positions;
131 for (vector<Hero>::size_type i(0), end(battle->Heroes().size()); i < end; ++i) {
132 Vector<int> positionCorrection(battle->Res().swapCursor->Width() / 2, battle->HeroTagAt(i).HeroSprite()->Height() - battle->Res().swapCursor->Height() / 2);
133 // indicator offsets are inverted for heroes
134 positionCorrection -= cursorOffset;
135 positions.push_back(battle->HeroTagPositionAt(i) + battle->HeroTagAt(i).HeroOffset() + positionCorrection);
138 for (vector<Point<int> >::size_type i(0); i < positions.size(); ++i) {
139 if (selected == int(i)) {
140 battle->Res().swapCursor->DrawTopRight(screen, positions[i] + offset);
144 flipFlop = !flipFlop;
145 battle->Res().swapCursor->DrawTopRight(screen, positions[cursor] + offset + cursorOffset);