1 #include "SwapHeroes.h"
3 #include "SelectMoveAction.h"
4 #include "../BattleState.h"
5 #include "../../app/Application.h"
6 #include "../../app/Input.h"
7 #include "../../math/Vector.h"
9 using app::Application;
16 void SwapHeroes::OnEnterState(SDL_Surface *screen) {
17 OnResize(screen->w, screen->h);
20 void SwapHeroes::OnExitState(SDL_Surface *screen) {
24 void SwapHeroes::OnResumeState(SDL_Surface *screen) {
28 void SwapHeroes::OnPauseState(SDL_Surface *screen) {
33 void SwapHeroes::OnResize(int width, int height) {
34 Vector<int> offset(battle->ScreenOffset());
35 // offset the cursor by 1/8th to the left and bottom
36 cursorOffset = Vector<int>(battle->Res().swapCursor->Width() / -8, battle->Res().swapCursor->Height() / 8);
37 indicatorOffset = Vector<int>(0, 0);
40 positions.reserve(battle->NumHeroes());
41 for (int i(0), end(battle->NumHeroes()); i < end; ++i) {
42 Vector<int> positionCorrection(
43 battle->Res().swapCursor->Width() / 2,
44 battle->HeroTagAt(i).HeroSprite()->Height() - battle->Res().swapCursor->Height() / 2);
45 // indicator offsets are inverted for heroes
46 positionCorrection -= cursorOffset;
47 positions.push_back(battle->HeroTagPositionAt(i)
48 + battle->HeroTagAt(i).HeroOffset()
55 void SwapHeroes::HandleEvents(const Input &input) {
56 if (input.JustPressed(Input::ACTION_A)) {
57 if (selected != -1 && cursor != selected) {
58 battle->SwapHeroes(cursor, selected);
64 if (input.JustPressed(Input::ACTION_B)) {
65 if (cursor == selected) {
72 if (input.JustPressed(Input::PAD_UP)) {
75 if (input.JustPressed(Input::PAD_RIGHT)) {
78 if (input.JustPressed(Input::PAD_DOWN)) {
81 if (input.JustPressed(Input::PAD_LEFT)) {
87 void SwapHeroes::MoveUp() {
89 if (battle->HeroPositionOccupied(cursor + 2)) {
97 void SwapHeroes::MoveRight() {
98 if (cursor < 3 && battle->HeroPositionOccupied(cursor + 1)) {
105 void SwapHeroes::MoveDown() {
107 if (battle->HeroPositionOccupied(cursor + 2)) {
115 void SwapHeroes::MoveLeft() {
119 cursor = battle->NumHeroes();
124 void SwapHeroes::UpdateWorld(Uint32 deltaT) {
128 void SwapHeroes::Render(SDL_Surface *screen) {
129 parent->Render(screen);
130 RenderCursors(screen);
133 void SwapHeroes::RenderCursors(SDL_Surface *screen) {
135 for (vector<Vector<int> >::size_type i(0), end(positions.size());
137 if (selected == int(i)) {
138 battle->Res().swapCursor->DrawTopRight(screen, positions[i]);
142 flipFlop = !flipFlop;
143 battle->Res().swapCursor->DrawTopRight(screen, positions[cursor] + cursorOffset);