From 6d080d21d8055df9962296863b4c0954bc81410b Mon Sep 17 00:00:00 2001 From: Daniel Karbach Date: Fri, 10 Aug 2012 20:50:00 +0200 Subject: [PATCH] added run state to flee from battle also renamed State's HandleInput to HandleEvents --- Debug/src/battle/states/subdir.mk | 3 ++ Release/src/battle/states/subdir.mk | 3 ++ src/app/Application.cpp | 2 +- src/app/State.h | 2 +- src/battle/BattleState.cpp | 2 +- src/battle/BattleState.h | 2 +- src/battle/states/RunState.cpp | 66 ++++++++++++++++++++++++++ src/battle/states/RunState.h | 47 ++++++++++++++++++ src/battle/states/SelectAttackType.cpp | 2 +- src/battle/states/SelectAttackType.h | 2 +- src/battle/states/SelectIkari.cpp | 2 +- src/battle/states/SelectIkari.h | 2 +- src/battle/states/SelectItem.cpp | 2 +- src/battle/states/SelectItem.h | 2 +- src/battle/states/SelectMoveAction.cpp | 5 +- src/battle/states/SelectMoveAction.h | 2 +- src/battle/states/SelectSpell.cpp | 2 +- src/battle/states/SelectSpell.h | 2 +- src/battle/states/SelectTarget.cpp | 2 +- src/battle/states/SelectTarget.h | 2 +- src/battle/states/SwapHeroes.cpp | 2 +- src/battle/states/SwapHeroes.h | 2 +- 22 files changed, 139 insertions(+), 19 deletions(-) create mode 100644 src/battle/states/RunState.cpp create mode 100644 src/battle/states/RunState.h diff --git a/Debug/src/battle/states/subdir.mk b/Debug/src/battle/states/subdir.mk index e937fef..3d78d84 100644 --- a/Debug/src/battle/states/subdir.mk +++ b/Debug/src/battle/states/subdir.mk @@ -4,6 +4,7 @@ # Add inputs and outputs from these tool invocations to the build variables CPP_SRCS += \ +../src/battle/states/RunState.cpp \ ../src/battle/states/SelectAttackType.cpp \ ../src/battle/states/SelectIkari.cpp \ ../src/battle/states/SelectItem.cpp \ @@ -13,6 +14,7 @@ CPP_SRCS += \ ../src/battle/states/SwapHeroes.cpp OBJS += \ +./src/battle/states/RunState.o \ ./src/battle/states/SelectAttackType.o \ ./src/battle/states/SelectIkari.o \ ./src/battle/states/SelectItem.o \ @@ -22,6 +24,7 @@ OBJS += \ ./src/battle/states/SwapHeroes.o CPP_DEPS += \ +./src/battle/states/RunState.d \ ./src/battle/states/SelectAttackType.d \ ./src/battle/states/SelectIkari.d \ ./src/battle/states/SelectItem.d \ diff --git a/Release/src/battle/states/subdir.mk b/Release/src/battle/states/subdir.mk index 245dd34..0461161 100644 --- a/Release/src/battle/states/subdir.mk +++ b/Release/src/battle/states/subdir.mk @@ -4,6 +4,7 @@ # Add inputs and outputs from these tool invocations to the build variables CPP_SRCS += \ +../src/battle/states/RunState.cpp \ ../src/battle/states/SelectAttackType.cpp \ ../src/battle/states/SelectIkari.cpp \ ../src/battle/states/SelectItem.cpp \ @@ -13,6 +14,7 @@ CPP_SRCS += \ ../src/battle/states/SwapHeroes.cpp OBJS += \ +./src/battle/states/RunState.o \ ./src/battle/states/SelectAttackType.o \ ./src/battle/states/SelectIkari.o \ ./src/battle/states/SelectItem.o \ @@ -22,6 +24,7 @@ OBJS += \ ./src/battle/states/SwapHeroes.o CPP_DEPS += \ +./src/battle/states/RunState.d \ ./src/battle/states/SelectAttackType.d \ ./src/battle/states/SelectIkari.d \ ./src/battle/states/SelectItem.d \ diff --git a/src/app/Application.cpp b/src/app/Application.cpp index fc1d380..819882e 100644 --- a/src/app/Application.cpp +++ b/src/app/Application.cpp @@ -159,7 +159,7 @@ void Application::HandleEvents() { break; } } - CurrentState()->HandleInput(input); + CurrentState()->HandleEvents(input); } void Application::UpdateWorld(Uint32 deltaT) { diff --git a/src/app/State.h b/src/app/State.h index b4c26d0..c74043b 100644 --- a/src/app/State.h +++ b/src/app/State.h @@ -38,7 +38,7 @@ public: /// adapt the state's graphics to given dimensions virtual void Resize(int width, int height) = 0; - virtual void HandleInput(const Input &) = 0; + virtual void HandleEvents(const Input &) = 0; virtual void UpdateWorld(float deltaT) = 0; virtual void Render(SDL_Surface *) = 0; diff --git a/src/battle/BattleState.cpp b/src/battle/BattleState.cpp index cbea81a..6db8efa 100644 --- a/src/battle/BattleState.cpp +++ b/src/battle/BattleState.cpp @@ -201,7 +201,7 @@ void BattleState::PauseState(Application &ctrl, SDL_Surface *screen) { } -void BattleState::HandleInput(const Input &input) { +void BattleState::HandleEvents(const Input &input) { } diff --git a/src/battle/BattleState.h b/src/battle/BattleState.h index 57c037f..e3ecca9 100644 --- a/src/battle/BattleState.h +++ b/src/battle/BattleState.h @@ -65,7 +65,7 @@ public: virtual void Resize(int width, int height); - virtual void HandleInput(const app::Input &); + virtual void HandleEvents(const app::Input &); virtual void UpdateWorld(float deltaT); virtual void Render(SDL_Surface *); diff --git a/src/battle/states/RunState.cpp b/src/battle/states/RunState.cpp new file mode 100644 index 0000000..08c45e8 --- /dev/null +++ b/src/battle/states/RunState.cpp @@ -0,0 +1,66 @@ +/* + * RunState.cpp + * + * Created on: Aug 10, 2012 + * Author: holy + */ + +#include "RunState.h" + +#include "../BattleState.h" +#include "../../app/Application.h" +#include "../../app/Input.h" +#include "../../geometry/operators.h" +#include "../../geometry/Point.h" + +using app::Application; +using app::Input; +using geometry::Point; +using geometry::Vector; + +namespace battle { + +void RunState::EnterState(Application &c, SDL_Surface *screen) { + ctrl = &c; + // TODO: push battle animation if enemy is faster +} + +void RunState::ExitState(Application &c, SDL_Surface *screen) { + ctrl = 0; +} + +void RunState::ResumeState(Application &ctrl, SDL_Surface *screen) { + timer = GraphicsTimers().StartCountdown(2500); +} + +void RunState::PauseState(Application &ctrl, SDL_Surface *screen) { + +} + + +void RunState::Resize(int width, int height) { + +} + + +void RunState::HandleEvents(const Input &input) { + if (timer.Finished()) { + ctrl->PopState(); // pop self + ctrl->PopState(); // pop battle + } +} + + +void RunState::UpdateWorld(float deltaT) { + +} + +void RunState::Render(SDL_Surface *screen) { + Vector offset(battle->CalculateScreenOffset(screen)); + battle->RenderBackground(screen, offset); + battle->RenderMonsters(screen, offset); + battle->RenderHeroes(screen, offset); + // render small tags +} + +} diff --git a/src/battle/states/RunState.h b/src/battle/states/RunState.h new file mode 100644 index 0000000..870f48d --- /dev/null +++ b/src/battle/states/RunState.h @@ -0,0 +1,47 @@ +/* + * RunState.h + * + * Created on: Aug 10, 2012 + * Author: holy + */ + +#ifndef BATTLE_RUNSTATE_H_ +#define BATTLE_RUNSTATE_H_ + +#include "../../app/State.h" + +#include "../../geometry/Vector.h" + +namespace battle { + +class BattleState; + +class RunState +: public app::State { + +public: + explicit RunState(BattleState *battle) + : ctrl(0), battle(battle){ } + +public: + virtual void EnterState(app::Application &ctrl, SDL_Surface *screen); + virtual void ExitState(app::Application &ctrl, SDL_Surface *screen); + virtual void ResumeState(app::Application &ctrl, SDL_Surface *screen); + virtual void PauseState(app::Application &ctrl, SDL_Surface *screen); + + virtual void Resize(int width, int height); + + virtual void HandleEvents(const app::Input &); + virtual void UpdateWorld(float deltaT); + virtual void Render(SDL_Surface *); + +private: + app::Application *ctrl; + BattleState *battle; + app::Timer timer; + +}; + +} + +#endif /* BATTLE_RUNSTATE_H_ */ diff --git a/src/battle/states/SelectAttackType.cpp b/src/battle/states/SelectAttackType.cpp index 90d483c..b8d604d 100644 --- a/src/battle/states/SelectAttackType.cpp +++ b/src/battle/states/SelectAttackType.cpp @@ -56,7 +56,7 @@ void SelectAttackType::Resize(int width, int height) { } -void SelectAttackType::HandleInput(const Input &input) { +void SelectAttackType::HandleEvents(const Input &input) { if (input.IsDown(Input::PAD_UP)) { battle->GetAttackTypeMenu().Select(AttackChoice::MAGIC); } else if (input.IsDown(Input::PAD_RIGHT)) { diff --git a/src/battle/states/SelectAttackType.h b/src/battle/states/SelectAttackType.h index aa0a303..5679940 100644 --- a/src/battle/states/SelectAttackType.h +++ b/src/battle/states/SelectAttackType.h @@ -31,7 +31,7 @@ public: virtual void Resize(int width, int height); - virtual void HandleInput(const app::Input &); + virtual void HandleEvents(const app::Input &); virtual void UpdateWorld(float deltaT); virtual void Render(SDL_Surface *); diff --git a/src/battle/states/SelectIkari.cpp b/src/battle/states/SelectIkari.cpp index 7928888..adeafb2 100644 --- a/src/battle/states/SelectIkari.cpp +++ b/src/battle/states/SelectIkari.cpp @@ -51,7 +51,7 @@ void SelectIkari::Resize(int width, int height) { } -void SelectIkari::HandleInput(const Input &input) { +void SelectIkari::HandleEvents(const Input &input) { if (input.JustPressed(Input::ACTION_A)) { if (battle->GetIkariMenu().SelectedIsEnabled() && battle->GetIkariMenu().Selected()->HasIkari()) { const Ikari *ikari(battle->GetIkariMenu().Selected()->GetIkari()); diff --git a/src/battle/states/SelectIkari.h b/src/battle/states/SelectIkari.h index 1550ed8..02b0e25 100644 --- a/src/battle/states/SelectIkari.h +++ b/src/battle/states/SelectIkari.h @@ -33,7 +33,7 @@ public: virtual void Resize(int width, int height); - virtual void HandleInput(const app::Input &); + virtual void HandleEvents(const app::Input &); virtual void UpdateWorld(float deltaT); virtual void Render(SDL_Surface *); diff --git a/src/battle/states/SelectItem.cpp b/src/battle/states/SelectItem.cpp index 96def09..4701fb9 100644 --- a/src/battle/states/SelectItem.cpp +++ b/src/battle/states/SelectItem.cpp @@ -50,7 +50,7 @@ void SelectItem::Resize(int width, int height) { } -void SelectItem::HandleInput(const Input &input) { +void SelectItem::HandleEvents(const Input &input) { if (input.JustPressed(Input::ACTION_A)) { if (battle->GetItemMenu().SelectedIsEnabled()) { const Item *item(battle->GetItemMenu().Selected()); diff --git a/src/battle/states/SelectItem.h b/src/battle/states/SelectItem.h index be089f8..a4540bb 100644 --- a/src/battle/states/SelectItem.h +++ b/src/battle/states/SelectItem.h @@ -32,7 +32,7 @@ public: virtual void Resize(int width, int height); - virtual void HandleInput(const app::Input &); + virtual void HandleEvents(const app::Input &); virtual void UpdateWorld(float deltaT); virtual void Render(SDL_Surface *); diff --git a/src/battle/states/SelectMoveAction.cpp b/src/battle/states/SelectMoveAction.cpp index de8e97b..8aa4906 100644 --- a/src/battle/states/SelectMoveAction.cpp +++ b/src/battle/states/SelectMoveAction.cpp @@ -7,6 +7,7 @@ #include "SelectMoveAction.h" +#include "RunState.h" #include "SelectAttackType.h" #include "SwapHeroes.h" #include "../BattleState.h" @@ -44,7 +45,7 @@ void SelectMoveAction::Resize(int width, int height) { } -void SelectMoveAction::HandleInput(const Input &input) { +void SelectMoveAction::HandleEvents(const Input &input) { if (input.IsDown(Input::PAD_UP)) { battle->GetMoveMenu().Select(MoveMenu::CHANGE); } else if (input.IsDown(Input::PAD_DOWN)) { @@ -63,7 +64,7 @@ void SelectMoveAction::HandleInput(const Input &input) { ctrl->PushState(new SwapHeroes(battle, this)); break; case MoveMenu::RUN: - // TODO: switch to run state + ctrl->ChangeState(new RunState(battle)); break; } } diff --git a/src/battle/states/SelectMoveAction.h b/src/battle/states/SelectMoveAction.h index 9ba8c61..4f88c4f 100644 --- a/src/battle/states/SelectMoveAction.h +++ b/src/battle/states/SelectMoveAction.h @@ -31,7 +31,7 @@ public: virtual void Resize(int width, int height); - virtual void HandleInput(const app::Input &); + virtual void HandleEvents(const app::Input &); virtual void UpdateWorld(float deltaT); virtual void Render(SDL_Surface *); diff --git a/src/battle/states/SelectSpell.cpp b/src/battle/states/SelectSpell.cpp index 62e7c46..56f750f 100644 --- a/src/battle/states/SelectSpell.cpp +++ b/src/battle/states/SelectSpell.cpp @@ -51,7 +51,7 @@ void SelectSpell::Resize(int width, int height) { } -void SelectSpell::HandleInput(const Input &input) { +void SelectSpell::HandleEvents(const Input &input) { if (input.JustPressed(Input::ACTION_A)) { if (battle->GetSpellMenu().SelectedIsEnabled()) { const Spell *spell(battle->GetSpellMenu().Selected()); diff --git a/src/battle/states/SelectSpell.h b/src/battle/states/SelectSpell.h index eda7e91..5251a9d 100644 --- a/src/battle/states/SelectSpell.h +++ b/src/battle/states/SelectSpell.h @@ -32,7 +32,7 @@ public: virtual void Resize(int width, int height); - virtual void HandleInput(const app::Input &); + virtual void HandleEvents(const app::Input &); virtual void UpdateWorld(float deltaT); virtual void Render(SDL_Surface *); diff --git a/src/battle/states/SelectTarget.cpp b/src/battle/states/SelectTarget.cpp index 9c50991..c0ff6cc 100644 --- a/src/battle/states/SelectTarget.cpp +++ b/src/battle/states/SelectTarget.cpp @@ -44,7 +44,7 @@ void SelectTarget::Resize(int width, int height) { } -void SelectTarget::HandleInput(const Input &input) { +void SelectTarget::HandleEvents(const Input &input) { if (input.JustPressed(Input::ACTION_A)) { if (selection->CurrentIsSelected()) { ctrl->PopState(); // return control to parent diff --git a/src/battle/states/SelectTarget.h b/src/battle/states/SelectTarget.h index f84dd31..b4eb312 100644 --- a/src/battle/states/SelectTarget.h +++ b/src/battle/states/SelectTarget.h @@ -35,7 +35,7 @@ public: virtual void Resize(int width, int height); - virtual void HandleInput(const app::Input &); + virtual void HandleEvents(const app::Input &); virtual void UpdateWorld(float deltaT); virtual void Render(SDL_Surface *); diff --git a/src/battle/states/SwapHeroes.cpp b/src/battle/states/SwapHeroes.cpp index ab1e6fd..f01e60d 100644 --- a/src/battle/states/SwapHeroes.cpp +++ b/src/battle/states/SwapHeroes.cpp @@ -44,7 +44,7 @@ void SwapHeroes::Resize(int width, int height) { } -void SwapHeroes::HandleInput(const Input &input) { +void SwapHeroes::HandleEvents(const Input &input) { if (input.JustPressed(Input::ACTION_A)) { if (selected != -1 && cursor != selected) { battle->SwapHeroes(cursor, selected); diff --git a/src/battle/states/SwapHeroes.h b/src/battle/states/SwapHeroes.h index 07dba71..109a1f0 100644 --- a/src/battle/states/SwapHeroes.h +++ b/src/battle/states/SwapHeroes.h @@ -32,7 +32,7 @@ public: virtual void Resize(int width, int height); - virtual void HandleInput(const app::Input &); + virtual void HandleEvents(const app::Input &); virtual void UpdateWorld(float deltaT); virtual void Render(SDL_Surface *); -- 2.39.2