]> git.localhorst.tv Git - l2e.git/commitdiff
added run state to flee from battle
authorDaniel Karbach <daniel.karbach@localhorst.tv>
Fri, 10 Aug 2012 18:50:00 +0000 (20:50 +0200)
committerDaniel Karbach <daniel.karbach@localhorst.tv>
Fri, 10 Aug 2012 18:55:25 +0000 (20:55 +0200)
also renamed State's HandleInput to HandleEvents

22 files changed:
Debug/src/battle/states/subdir.mk
Release/src/battle/states/subdir.mk
src/app/Application.cpp
src/app/State.h
src/battle/BattleState.cpp
src/battle/BattleState.h
src/battle/states/RunState.cpp [new file with mode: 0644]
src/battle/states/RunState.h [new file with mode: 0644]
src/battle/states/SelectAttackType.cpp
src/battle/states/SelectAttackType.h
src/battle/states/SelectIkari.cpp
src/battle/states/SelectIkari.h
src/battle/states/SelectItem.cpp
src/battle/states/SelectItem.h
src/battle/states/SelectMoveAction.cpp
src/battle/states/SelectMoveAction.h
src/battle/states/SelectSpell.cpp
src/battle/states/SelectSpell.h
src/battle/states/SelectTarget.cpp
src/battle/states/SelectTarget.h
src/battle/states/SwapHeroes.cpp
src/battle/states/SwapHeroes.h

index e937fefeb9e7ce7a27fa65f7638b4c0e43b01829..3d78d840d224ea5229cc69b568b1648f7d7d8953 100644 (file)
@@ -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 \
index 245dd3470a6d7ff6da65731f6ab4829d853cacea..0461161f816a4600c47a172b0d9ef3377f5b5e9f 100644 (file)
@@ -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 \
index fc1d3801d4ab6fe65f0ea8af622904e0eb01b194..819882e7251f43e66b7ed77311f97c498e74d456 100644 (file)
@@ -159,7 +159,7 @@ void Application::HandleEvents() {
                                break;
                }
        }
-       CurrentState()->HandleInput(input);
+       CurrentState()->HandleEvents(input);
 }
 
 void Application::UpdateWorld(Uint32 deltaT) {
index b4c26d047cd7c88429e62d56a164be048fdcd7aa..c74043bf6b7bacc1e2d2f336ed99a42115f261fd 100644 (file)
@@ -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;
 
index cbea81a82cb5d1564344abe6e24d757bbca70d0e..6db8efabb2c09b57184e941e524b381eeef79e0d 100644 (file)
@@ -201,7 +201,7 @@ void BattleState::PauseState(Application &ctrl, SDL_Surface *screen) {
 }
 
 
-void BattleState::HandleInput(const Input &input) {
+void BattleState::HandleEvents(const Input &input) {
 
 }
 
index 57c037f0643c4371e51ab78c98b7e8e397327211..e3ecca915cfaa967ad4b9c765edd313c696d267c 100644 (file)
@@ -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 (file)
index 0000000..08c45e8
--- /dev/null
@@ -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<int> 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 (file)
index 0000000..870f48d
--- /dev/null
@@ -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<Uint32> timer;
+
+};
+
+}
+
+#endif /* BATTLE_RUNSTATE_H_ */
index 90d483ca693cd5018110252dddda6dd215262a20..b8d604d91a68dd28937a04f7668beb441c94fc91 100644 (file)
@@ -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)) {
index aa0a30384a0fb86b1ba555faf76e4dbf6f86ef5c..56799409e4ff3b686f8da1601c10f699b5b0e689 100644 (file)
@@ -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 *);
 
index 7928888d2bb031805d703001be8733336a180e0d..adeafb29fd7ca5ebfefe6825024e3867eb1aea5f 100644 (file)
@@ -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());
index 1550ed8844047709ee7d5d670f8b9b032a710f9d..02b0e25ff8302a5a5d5f5f872d719c909cc5f647 100644 (file)
@@ -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 *);
 
index 96def09e1bed6803972feb3521ca0ffe9af5fed4..4701fb94c2a3efbdce8232b698694eb966b419f5 100644 (file)
@@ -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());
index be089f83df381eb7ad3a85132567d37057e2b382..a4540bb62ced2721cf4bc13a8599195a18042661 100644 (file)
@@ -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 *);
 
index de8e97b4db066fca0b316cfcc767094470f8bc89..8aa49067df121ee223784ddfaec6d3faca050d15 100644 (file)
@@ -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;
                }
        }
index 9ba8c6115f500d745e36f875ee9e4d04b42fc946..4f88c4fd3e7db4e5a2498accc91bcde15408ab53 100644 (file)
@@ -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 *);
 
index 62e7c4619c4646eaaf81be6f679d84c7b11a8824..56f750fd6d17d3f0f326fe0ffeb43e99f1739a6d 100644 (file)
@@ -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());
index eda7e9166820b976ffe703a5e07173d7ac9716a7..5251a9d2c2e51b33404db017e5cc6e53c27223d5 100644 (file)
@@ -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 *);
 
index 9c50991bf00c26b9deb34acc83b61f3b4f4b7152..c0ff6cca585a0ef143e316c10dbe73df16fb2ff8 100644 (file)
@@ -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
index f84dd3176abe6a8b6a4dd48752e7e192edaae46e..b4eb312810223a73efd54798dbc38e14a4a2dd6c 100644 (file)
@@ -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 *);
 
index ab1e6fd2faadf0f64e53635bf082d542b8e6b8c7..f01e60da8603f862f97ad541a321d24c0bad750d 100644 (file)
@@ -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);
index 07dba7105f709a03dc97fdee9119ade14d24d712..109a1f015ba3caa47e67addee8e825d62fce6c86 100644 (file)
@@ -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 *);