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 SwapHeroes::SwapHeroes(Battle *battle, SelectMoveAction *parent)
26 void SwapHeroes::OnEnterState(SDL_Surface *screen) {
27 OnResize(screen->w, screen->h);
30 void SwapHeroes::OnExitState(SDL_Surface *screen) {
34 void SwapHeroes::OnResumeState(SDL_Surface *screen) {
38 void SwapHeroes::OnPauseState(SDL_Surface *screen) {
43 void SwapHeroes::OnResize(int width, int height) {
44 Vector<int> offset(parent->ScreenOffset());
45 // offset the cursor by 1/8th to the left and bottom
46 cursorOffset = Vector<int>(parent->Res().swapCursor->Width() / -8, parent->Res().swapCursor->Height() / 8);
47 indicatorOffset = Vector<int>(0, 0);
50 positions.reserve(battle->NumHeroes());
51 for (int i(0), end(battle->NumHeroes()); i < end; ++i) {
52 Vector<int> positionCorrection(
53 parent->Res().swapCursor->Width() / 2,
54 parent->HeroTagAt(i).HeroSprite()->Height() - parent->Res().swapCursor->Height() / 2);
55 // indicator offsets are inverted for heroes
56 positionCorrection -= cursorOffset;
57 positions.push_back(parent->HeroTagPositionAt(i)
58 + parent->HeroTagAt(i).HeroOffset()
65 void SwapHeroes::HandleEvents(const Input &input) {
66 if (input.JustPressed(Input::ACTION_A)) {
67 if (selected != -1 && cursor != selected) {
68 battle->SwapHeroes(cursor, selected);
74 if (input.JustPressed(Input::ACTION_B)) {
75 if (cursor == selected) {
82 if (input.JustPressed(Input::PAD_UP)) {
85 if (input.JustPressed(Input::PAD_RIGHT)) {
88 if (input.JustPressed(Input::PAD_DOWN)) {
91 if (input.JustPressed(Input::PAD_LEFT)) {
97 void SwapHeroes::MoveUp() {
99 if (battle->HeroPositionOccupied(cursor + 2)) {
107 void SwapHeroes::MoveRight() {
108 if (cursor < 3 && battle->HeroPositionOccupied(cursor + 1)) {
115 void SwapHeroes::MoveDown() {
117 if (battle->HeroPositionOccupied(cursor + 2)) {
125 void SwapHeroes::MoveLeft() {
129 cursor = battle->NumHeroes();
134 void SwapHeroes::UpdateWorld(Uint32 deltaT) {
138 void SwapHeroes::Render(SDL_Surface *screen) {
139 parent->Render(screen);
140 RenderCursors(screen);
143 void SwapHeroes::RenderCursors(SDL_Surface *screen) {
145 for (vector<Vector<int> >::size_type i(0), end(positions.size());
147 if (selected == int(i)) {
148 parent->Res().swapCursor->DrawTopRight(screen, positions[i]);
152 flipFlop = !flipFlop;
153 parent->Res().swapCursor->DrawTopRight(screen, positions[cursor] + cursorOffset);