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"
15 using app::Application;
17 using geometry::Vector;
22 void SwapHeroes::EnterState(Application &c, SDL_Surface *screen) {
26 void SwapHeroes::ExitState(Application &c, SDL_Surface *screen) {
30 void SwapHeroes::ResumeState(Application &ctrl, SDL_Surface *screen) {
34 void SwapHeroes::PauseState(Application &ctrl, SDL_Surface *screen) {
39 void SwapHeroes::Resize(int width, int height) {
44 void SwapHeroes::HandleEvents(const Input &input) {
45 if (input.JustPressed(Input::ACTION_A)) {
46 if (selected != -1 && cursor != selected) {
47 battle->SwapHeroes(cursor, selected);
53 if (input.JustPressed(Input::ACTION_B)) {
54 if (cursor == selected) {
61 if (input.JustPressed(Input::PAD_UP)) {
64 if (input.JustPressed(Input::PAD_RIGHT)) {
67 if (input.JustPressed(Input::PAD_DOWN)) {
70 if (input.JustPressed(Input::PAD_LEFT)) {
76 void SwapHeroes::MoveUp() {
78 if (battle->HeroPositionOccupied(cursor + 2)) {
86 void SwapHeroes::MoveRight() {
87 if (cursor < 3 && battle->HeroPositionOccupied(cursor + 1)) {
94 void SwapHeroes::MoveDown() {
96 if (battle->HeroPositionOccupied(cursor + 2)) {
104 void SwapHeroes::MoveLeft() {
108 cursor = battle->NumHeroes();
113 void SwapHeroes::UpdateWorld(float deltaT) {
117 void SwapHeroes::Render(SDL_Surface *screen) {
118 Vector<int> offset(battle->CalculateScreenOffset(screen));
119 parent->Render(screen);
120 RenderCursors(screen, offset);
123 void SwapHeroes::RenderCursors(SDL_Surface *screen, const geometry::Vector<int> &offset) {
124 // offset the cursor by 1/8th to the left and bottom
125 Vector<int> cursorOffset(battle->Res().swapCursor->Width() / -8, battle->Res().swapCursor->Height() / 8);
126 Vector<int> indicatorOffset(0, 0);
127 vector<Vector<int> > positions;
128 for (int i(0), end(battle->NumHeroes()); i < end; ++i) {
129 Vector<int> positionCorrection(battle->Res().swapCursor->Width() / 2, battle->HeroTagAt(i).HeroSprite()->Height() - battle->Res().swapCursor->Height() / 2);
130 // indicator offsets are inverted for heroes
131 positionCorrection -= cursorOffset;
132 positions.push_back(battle->HeroTagPositionAt(i) + battle->HeroTagAt(i).HeroOffset() + positionCorrection);
135 for (vector<Vector<int> >::size_type i(0); i < positions.size(); ++i) {
136 if (selected == int(i)) {
137 battle->Res().swapCursor->DrawTopRight(screen, positions[i] + offset);
141 flipFlop = !flipFlop;
142 battle->Res().swapCursor->DrawTopRight(screen, positions[cursor] + offset + cursorOffset);