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 "../../math/Vector.h"
16 using app::Application;
23 void SwapHeroes::OnEnterState(SDL_Surface *screen) {
27 void SwapHeroes::OnExitState(SDL_Surface *screen) {
31 void SwapHeroes::OnResumeState(SDL_Surface *screen) {
35 void SwapHeroes::OnPauseState(SDL_Surface *screen) {
40 void SwapHeroes::OnResize(int width, int height) {
45 void SwapHeroes::HandleEvents(const Input &input) {
46 if (input.JustPressed(Input::ACTION_A)) {
47 if (selected != -1 && cursor != selected) {
48 battle->SwapHeroes(cursor, selected);
54 if (input.JustPressed(Input::ACTION_B)) {
55 if (cursor == selected) {
62 if (input.JustPressed(Input::PAD_UP)) {
65 if (input.JustPressed(Input::PAD_RIGHT)) {
68 if (input.JustPressed(Input::PAD_DOWN)) {
71 if (input.JustPressed(Input::PAD_LEFT)) {
77 void SwapHeroes::MoveUp() {
79 if (battle->HeroPositionOccupied(cursor + 2)) {
87 void SwapHeroes::MoveRight() {
88 if (cursor < 3 && battle->HeroPositionOccupied(cursor + 1)) {
95 void SwapHeroes::MoveDown() {
97 if (battle->HeroPositionOccupied(cursor + 2)) {
105 void SwapHeroes::MoveLeft() {
109 cursor = battle->NumHeroes();
114 void SwapHeroes::UpdateWorld(Uint32 deltaT) {
118 void SwapHeroes::Render(SDL_Surface *screen) {
119 Vector<int> offset(battle->CalculateScreenOffset(screen));
120 parent->Render(screen);
121 RenderCursors(screen, offset);
124 void SwapHeroes::RenderCursors(SDL_Surface *screen, const math::Vector<int> &offset) {
125 // offset the cursor by 1/8th to the left and bottom
126 Vector<int> cursorOffset(battle->Res().swapCursor->Width() / -8, battle->Res().swapCursor->Height() / 8);
127 Vector<int> indicatorOffset(0, 0);
128 vector<Vector<int> > positions;
129 for (int i(0), end(battle->NumHeroes()); i < end; ++i) {
130 Vector<int> positionCorrection(battle->Res().swapCursor->Width() / 2, battle->HeroTagAt(i).HeroSprite()->Height() - battle->Res().swapCursor->Height() / 2);
131 // indicator offsets are inverted for heroes
132 positionCorrection -= cursorOffset;
133 positions.push_back(battle->HeroTagPositionAt(i) + battle->HeroTagAt(i).HeroOffset() + positionCorrection);
136 for (vector<Vector<int> >::size_type i(0); i < positions.size(); ++i) {
137 if (selected == int(i)) {
138 battle->Res().swapCursor->DrawTopRight(screen, positions[i] + offset);
142 flipFlop = !flipFlop;
143 battle->Res().swapCursor->DrawTopRight(screen, positions[cursor] + offset + cursorOffset);