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) {
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) {
38 void SwapHeroes::HandleEvents(const Input &input) {
39 if (input.JustPressed(Input::ACTION_A)) {
40 if (selected != -1 && cursor != selected) {
41 battle->SwapHeroes(cursor, selected);
47 if (input.JustPressed(Input::ACTION_B)) {
48 if (cursor == selected) {
55 if (input.JustPressed(Input::PAD_UP)) {
58 if (input.JustPressed(Input::PAD_RIGHT)) {
61 if (input.JustPressed(Input::PAD_DOWN)) {
64 if (input.JustPressed(Input::PAD_LEFT)) {
70 void SwapHeroes::MoveUp() {
72 if (battle->HeroPositionOccupied(cursor + 2)) {
80 void SwapHeroes::MoveRight() {
81 if (cursor < 3 && battle->HeroPositionOccupied(cursor + 1)) {
88 void SwapHeroes::MoveDown() {
90 if (battle->HeroPositionOccupied(cursor + 2)) {
98 void SwapHeroes::MoveLeft() {
102 cursor = battle->NumHeroes();
107 void SwapHeroes::UpdateWorld(Uint32 deltaT) {
111 void SwapHeroes::Render(SDL_Surface *screen) {
112 Vector<int> offset(battle->CalculateScreenOffset(screen));
113 parent->Render(screen);
114 RenderCursors(screen, offset);
117 void SwapHeroes::RenderCursors(SDL_Surface *screen, const math::Vector<int> &offset) {
118 // offset the cursor by 1/8th to the left and bottom
119 Vector<int> cursorOffset(battle->Res().swapCursor->Width() / -8, battle->Res().swapCursor->Height() / 8);
120 Vector<int> indicatorOffset(0, 0);
121 vector<Vector<int> > positions;
122 for (int i(0), end(battle->NumHeroes()); i < end; ++i) {
123 Vector<int> positionCorrection(battle->Res().swapCursor->Width() / 2, battle->HeroTagAt(i).HeroSprite()->Height() - battle->Res().swapCursor->Height() / 2);
124 // indicator offsets are inverted for heroes
125 positionCorrection -= cursorOffset;
126 positions.push_back(battle->HeroTagPositionAt(i) + battle->HeroTagAt(i).HeroOffset() + positionCorrection);
129 for (vector<Vector<int> >::size_type i(0); i < positions.size(); ++i) {
130 if (selected == int(i)) {
131 battle->Res().swapCursor->DrawTopRight(screen, positions[i] + offset);
135 flipFlop = !flipFlop;
136 battle->Res().swapCursor->DrawTopRight(screen, positions[cursor] + offset + cursorOffset);