]> git.localhorst.tv Git - l2e.git/commitdiff
split battle state into (so far) 2 states
authorDaniel Karbach <daniel.karbach@localhorst.tv>
Tue, 7 Aug 2012 11:52:31 +0000 (13:52 +0200)
committerDaniel Karbach <daniel.karbach@localhorst.tv>
Tue, 7 Aug 2012 12:25:39 +0000 (14:25 +0200)
12 files changed:
Debug/makefile
Debug/sources.mk
Debug/src/battle/states/subdir.mk [new file with mode: 0644]
Release/makefile
Release/sources.mk
Release/src/battle/states/subdir.mk [new file with mode: 0644]
src/battle/BattleState.cpp
src/battle/BattleState.h
src/battle/states/SelectAttackType.cpp [new file with mode: 0644]
src/battle/states/SelectAttackType.h [new file with mode: 0644]
src/battle/states/SelectMoveAction.cpp [new file with mode: 0644]
src/battle/states/SelectMoveAction.h [new file with mode: 0644]

index 507437a93cbfa29ba2e0136e4c244d637cf0e2b3..2000ebcd34b347f68ab026de81d88b18bde22bd3 100644 (file)
@@ -10,6 +10,7 @@ RM := rm -rf
 -include sources.mk
 -include src/sdl/subdir.mk
 -include src/graphics/subdir.mk
+-include src/battle/states/subdir.mk
 -include src/battle/subdir.mk
 -include src/app/subdir.mk
 -include src/subdir.mk
index 0fdadd38f9a63f83ae891efcde4019c97aab7708..cd96090ff8d18c7de1c1ac69c7862905e62beeac 100644 (file)
@@ -26,6 +26,7 @@ SUBDIRS := \
 src/sdl \
 src \
 src/graphics \
+src/battle/states \
 src/battle \
 src/app \
 
diff --git a/Debug/src/battle/states/subdir.mk b/Debug/src/battle/states/subdir.mk
new file mode 100644 (file)
index 0000000..8a61792
--- /dev/null
@@ -0,0 +1,27 @@
+################################################################################
+# Automatically-generated file. Do not edit!
+################################################################################
+
+# Add inputs and outputs from these tool invocations to the build variables 
+CPP_SRCS += \
+../src/battle/states/SelectAttackType.cpp \
+../src/battle/states/SelectMoveAction.cpp 
+
+OBJS += \
+./src/battle/states/SelectAttackType.o \
+./src/battle/states/SelectMoveAction.o 
+
+CPP_DEPS += \
+./src/battle/states/SelectAttackType.d \
+./src/battle/states/SelectMoveAction.d 
+
+
+# Each subdirectory must supply rules for building sources it contributes
+src/battle/states/%.o: ../src/battle/states/%.cpp
+       @echo 'Building file: $<'
+       @echo 'Invoking: GCC C++ Compiler'
+       g++ -I/usr/include/SDL -O0 -g3 -Wall -c -fmessage-length=0 -MMD -MP -MF"$(@:%.o=%.d)" -MT"$(@:%.o=%.d)" -o "$@" "$<"
+       @echo 'Finished building: $<'
+       @echo ' '
+
+
index 507437a93cbfa29ba2e0136e4c244d637cf0e2b3..2000ebcd34b347f68ab026de81d88b18bde22bd3 100644 (file)
@@ -10,6 +10,7 @@ RM := rm -rf
 -include sources.mk
 -include src/sdl/subdir.mk
 -include src/graphics/subdir.mk
+-include src/battle/states/subdir.mk
 -include src/battle/subdir.mk
 -include src/app/subdir.mk
 -include src/subdir.mk
index 0fdadd38f9a63f83ae891efcde4019c97aab7708..cd96090ff8d18c7de1c1ac69c7862905e62beeac 100644 (file)
@@ -26,6 +26,7 @@ SUBDIRS := \
 src/sdl \
 src \
 src/graphics \
+src/battle/states \
 src/battle \
 src/app \
 
diff --git a/Release/src/battle/states/subdir.mk b/Release/src/battle/states/subdir.mk
new file mode 100644 (file)
index 0000000..05f8177
--- /dev/null
@@ -0,0 +1,27 @@
+################################################################################
+# Automatically-generated file. Do not edit!
+################################################################################
+
+# Add inputs and outputs from these tool invocations to the build variables 
+CPP_SRCS += \
+../src/battle/states/SelectAttackType.cpp \
+../src/battle/states/SelectMoveAction.cpp 
+
+OBJS += \
+./src/battle/states/SelectAttackType.o \
+./src/battle/states/SelectMoveAction.o 
+
+CPP_DEPS += \
+./src/battle/states/SelectAttackType.d \
+./src/battle/states/SelectMoveAction.d 
+
+
+# Each subdirectory must supply rules for building sources it contributes
+src/battle/states/%.o: ../src/battle/states/%.cpp
+       @echo 'Building file: $<'
+       @echo 'Invoking: GCC C++ Compiler'
+       g++ -I/usr/include/SDL -O3 -Wall -c -fmessage-length=0 -MMD -MP -MF"$(@:%.o=%.d)" -MT"$(@:%.o=%.d)" -o "$@" "$<"
+       @echo 'Finished building: $<'
+       @echo ' '
+
+
index a2c306a2ef7050d1fd9d0a468d768d152962229b..4e12f7929a5be2ada8fa319e6ce275827375fae0 100644 (file)
@@ -8,6 +8,7 @@
 #include "BattleState.h"
 
 #include "PartyLayout.h"
+#include "states/SelectMoveAction.h"
 #include "../app/Application.h"
 #include "../app/Input.h"
 #include "../geometry/operators.h"
@@ -50,6 +51,7 @@ void BattleState::EnterState(Application &ctrl, SDL_Surface *screen) {
        for (vector<Hero>::size_type i(0), end(heroes.size()); i < end; ++i) {
                heroTags.push_back(HeroTag(&heroes[i], HeroTag::Alignment((i + 1) % 2)));
        }
+       ctrl.PushState(new SelectMoveAction(this));
 }
 
 void BattleState::ExitState() {
@@ -58,35 +60,7 @@ void BattleState::ExitState() {
 
 
 void BattleState::HandleInput(const Input &input) {
-       if (moveChoice == -1) {
-               if (input.IsDown(Input::PAD_UP)) {
-                       moveMenu.Select(MoveMenu::CHANGE);
-               } else if (input.IsDown(Input::PAD_DOWN)) {
-                       moveMenu.Select(MoveMenu::RUN);
-               } else {
-                       moveMenu.Select(MoveMenu::ATTACK);
-               }
-
-               if (input.JustPressed(Input::ACTION_A)) {
-                       moveChoice = moveMenu.Selected();
-               }
-       } else {
-               if (input.IsDown(Input::PAD_UP)) {
-                       attackTypeMenu.Select(AttackTypeMenu::MAGIC);
-               } else if (input.IsDown(Input::PAD_RIGHT)) {
-                       attackTypeMenu.Select(AttackTypeMenu::DEFEND);
-               } else if (input.IsDown(Input::PAD_DOWN)) {
-                       attackTypeMenu.Select(AttackTypeMenu::IKARI);
-               } else if (input.IsDown(Input::PAD_LEFT)) {
-                       attackTypeMenu.Select(AttackTypeMenu::ITEM);
-               } else {
-                       attackTypeMenu.Select(AttackTypeMenu::SWORD);
-               }
-
-               if (input.JustPressed(Input::ACTION_A)) {
-                       activeHero = (activeHero + 1) % 4;
-               }
-       }
+
 }
 
 void BattleState::UpdateWorld(float deltaT) {
@@ -94,19 +68,13 @@ void BattleState::UpdateWorld(float deltaT) {
 }
 
 void BattleState::Render(SDL_Surface *screen) {
-       Vector<int> offset(
-                       (screen->w - background->w) / 2,
-                       (screen->h - background->h) / 2);
+       Vector<int> offset(CalculateScreenOffset(screen));
 
        RenderBackground(screen, offset);
        RenderMonsters(screen, offset);
 //     RenderHeroes(screen, offset);
        RenderHeroTags(screen, offset);
-       if (moveChoice == -1) {
-               RenderMoveMenu(screen, offset);
-       } else {
-               RenderAttackTypeMenu(screen, offset);
-       }
+       RenderAttackTypeMenu(screen, offset);
 }
 
 void BattleState::RenderBackground(SDL_Surface *screen, const Vector<int> &offset) {
@@ -133,9 +101,9 @@ void BattleState::RenderHeroes(SDL_Surface *screen, const Vector<int> &offset) {
 }
 
 void BattleState::RenderHeroTags(SDL_Surface *screen, const Vector<int> &offset) {
-       int uiHeight(background->h / 2), uiOffset(uiHeight);
+       int uiHeight(BackgroundHeight() / 2), uiOffset(uiHeight);
        int tagHeight((uiHeight - attackTypeMenu.IconHeight()) / 2);
-       int tagWidth((background->w - attackTypeMenu.IconWidth()) / 2);
+       int tagWidth((BackgroundWidth() - attackTypeMenu.IconWidth()) / 2);
 
        Point<int> tagPosition[4];
        tagPosition[0] = Point<int>(0, uiOffset);
@@ -150,16 +118,9 @@ void BattleState::RenderHeroTags(SDL_Surface *screen, const Vector<int> &offset)
 
 void BattleState::RenderAttackTypeMenu(SDL_Surface *screen, const Vector<int> &offset) {
        Point<int> position(
-                       (background->w - attackTypeMenu.Width()) / 2,
-                       (background->h * 3 / 4) - (attackTypeMenu.Height() / 2));
+                       (BackgroundWidth() - attackTypeMenu.Width()) / 2,
+                       (BackgroundHeight() * 3 / 4) - (attackTypeMenu.Height() / 2));
        attackTypeMenu.Render(screen, position + offset);
 }
 
-void BattleState::RenderMoveMenu(SDL_Surface *screen, const Vector<int> &offset) {
-       Point<int> position(
-                       (background->w - moveMenu.Width()) / 2,
-                       (background->h * 3 / 4) - (moveMenu.Height() / 2));
-       moveMenu.Render(screen, position + offset);
-}
-
 }
index daf1cae65f10c0f4c85267cdfc34bf39368360a1..a3c0879cedbbace7352a0ad547a090e9be8e41ae 100644 (file)
@@ -55,13 +55,24 @@ public:
        virtual void UpdateWorld(float deltaT);
        virtual void Render(SDL_Surface *);
 
-private:
+public:
+       AttackTypeMenu &GetAttackTypeMenu() { return attackTypeMenu; }
+       MoveMenu &GetMoveMenu() { return moveMenu; }
+
+public:
+       geometry::Vector<int> CalculateScreenOffset(SDL_Surface *screen) const {
+               return geometry::Vector<int>(
+                               (screen->w - background->w) / 2,
+                               (screen->h - background->h) / 2);
+       }
+       int BackgroundWidth() const { return background->w; }
+       int BackgroundHeight() const { return background->h; }
+
        void RenderBackground(SDL_Surface *screen, const geometry::Vector<int> &offset);
        void RenderMonsters(SDL_Surface *screen, const geometry::Vector<int> &offset);
        void RenderHeroes(SDL_Surface *screen, const geometry::Vector<int> &offset);
        void RenderHeroTags(SDL_Surface *screen, const geometry::Vector<int> &offset);
        void RenderAttackTypeMenu(SDL_Surface *screen, const geometry::Vector<int> &offset);
-       void RenderMoveMenu(SDL_Surface *screen, const geometry::Vector<int> &offset);
 
 private:
        SDL_Surface *background;
diff --git a/src/battle/states/SelectAttackType.cpp b/src/battle/states/SelectAttackType.cpp
new file mode 100644 (file)
index 0000000..1d76b6c
--- /dev/null
@@ -0,0 +1,87 @@
+/*
+ * SelectAttackType.cpp
+ *
+ *  Created on: Aug 7, 2012
+ *      Author: holy
+ */
+
+#include "SelectAttackType.h"
+
+#include "../BattleState.h"
+#include "../../app/Input.h"
+#include "../../geometry/operators.h"
+
+using app::Input;
+using geometry::Point;
+using geometry::Vector;
+
+namespace battle {
+
+void SelectAttackType::EnterState(app::Application &c, SDL_Surface *screen) {
+       ctrl = &c;
+}
+
+void SelectAttackType::ExitState() {
+       ctrl = 0;
+}
+
+
+void SelectAttackType::Resize(int width, int height) {
+
+}
+
+
+void SelectAttackType::HandleInput(const Input &input) {
+       if (input.IsDown(Input::PAD_UP)) {
+               battle->GetAttackTypeMenu().Select(AttackTypeMenu::MAGIC);
+       } else if (input.IsDown(Input::PAD_RIGHT)) {
+               battle->GetAttackTypeMenu().Select(AttackTypeMenu::DEFEND);
+       } else if (input.IsDown(Input::PAD_DOWN)) {
+               battle->GetAttackTypeMenu().Select(AttackTypeMenu::IKARI);
+       } else if (input.IsDown(Input::PAD_LEFT)) {
+               battle->GetAttackTypeMenu().Select(AttackTypeMenu::ITEM);
+       } else {
+               battle->GetAttackTypeMenu().Select(AttackTypeMenu::SWORD);
+       }
+
+       if (input.JustPressed(Input::ACTION_A)) {
+               switch (battle->GetAttackTypeMenu().Selected()) {
+                       case AttackTypeMenu::SWORD:
+                               // TODO: switch to next character
+                               break;
+                       case AttackTypeMenu::MAGIC:
+                               // TODO: switch to spell select
+                               break;
+                       case AttackTypeMenu::DEFEND:
+                               // TODO: switch to next character
+                               break;
+                       case AttackTypeMenu::IKARI:
+                               // TODO: switch to ikari attack select
+                               break;
+                       case AttackTypeMenu::ITEM:
+                               // TODO: switch to item select
+                               break;
+               }
+       }
+}
+
+void SelectAttackType::UpdateWorld(float deltaT) {
+
+}
+
+void SelectAttackType::Render(SDL_Surface *screen) {
+       Vector<int> offset(battle->CalculateScreenOffset(screen));
+       battle->RenderBackground(screen, offset);
+       battle->RenderMonsters(screen, offset);
+       battle->RenderHeroTags(screen, offset);
+       RenderMenu(screen, offset);
+}
+
+void SelectAttackType::RenderMenu(SDL_Surface *screen, const Vector<int> &offset) {
+       Point<int> position(
+                       (battle->BackgroundWidth() - battle->GetAttackTypeMenu().Width()) / 2,
+                       (battle->BackgroundHeight() * 3 / 4) - (battle->GetAttackTypeMenu().Height() / 2));
+       battle->GetAttackTypeMenu().Render(screen, position + offset);
+}
+
+}
diff --git a/src/battle/states/SelectAttackType.h b/src/battle/states/SelectAttackType.h
new file mode 100644 (file)
index 0000000..3b10188
--- /dev/null
@@ -0,0 +1,47 @@
+/*
+ * SelectAttackType.h
+ *
+ *  Created on: Aug 7, 2012
+ *      Author: holy
+ */
+
+#ifndef BATTLE_SELECTATTACKTYPE_H_
+#define BATTLE_SELECTATTACKTYPE_H_
+
+#include "../../app/State.h"
+#include "../../geometry/Vector.h"
+
+namespace battle {
+
+class AttackTypeMenu;
+class BattleState;
+
+class SelectAttackType
+: public app::State {
+
+public:
+       explicit SelectAttackType(BattleState *battle)
+       : ctrl(0), battle(battle) { }
+       ~SelectAttackType() { }
+
+public:
+       virtual void EnterState(app::Application &ctrl, SDL_Surface *screen);
+       virtual void ExitState();
+
+       virtual void Resize(int width, int height);
+
+       virtual void HandleInput(const app::Input &);
+       virtual void UpdateWorld(float deltaT);
+       virtual void Render(SDL_Surface *);
+
+private:
+       void RenderMenu(SDL_Surface *screen, const geometry::Vector<int> &offset);
+
+private:
+       app::Application *ctrl;
+       BattleState *battle;
+
+};
+
+}
+#endif /* BATTLE_SELECTATTACKTYPE_H_ */
diff --git a/src/battle/states/SelectMoveAction.cpp b/src/battle/states/SelectMoveAction.cpp
new file mode 100644 (file)
index 0000000..4a19d48
--- /dev/null
@@ -0,0 +1,80 @@
+/*
+ * SelectMoveAction.cpp
+ *
+ *  Created on: Aug 7, 2012
+ *      Author: holy
+ */
+
+#include "SelectMoveAction.h"
+
+#include "SelectAttackType.h"
+#include "../BattleState.h"
+#include "../MoveMenu.h"
+#include "../../app/Application.h"
+#include "../../app/Input.h"
+#include "../../geometry/operators.h"
+
+using app::Input;
+using geometry::Point;
+using geometry::Vector;
+
+namespace battle {
+
+void SelectMoveAction::EnterState(app::Application &c, SDL_Surface *screen) {
+       ctrl = &c;
+}
+
+void SelectMoveAction::ExitState() {
+       ctrl = 0;
+}
+
+
+void SelectMoveAction::Resize(int width, int height) {
+
+}
+
+
+void SelectMoveAction::HandleInput(const app::Input &input) {
+       if (input.IsDown(Input::PAD_UP)) {
+               battle->GetMoveMenu().Select(MoveMenu::CHANGE);
+       } else if (input.IsDown(Input::PAD_DOWN)) {
+               battle->GetMoveMenu().Select(MoveMenu::RUN);
+       } else {
+               battle->GetMoveMenu().Select(MoveMenu::ATTACK);
+       }
+
+       if (input.JustPressed(Input::ACTION_A)) {
+               switch (battle->GetMoveMenu().Selected()) {
+                       case MoveMenu::ATTACK:
+                               ctrl->ChangeState(new SelectAttackType(battle));
+                               break;
+                       case MoveMenu::CHANGE:
+                               // TODO: switch to change state
+                               break;
+                       case MoveMenu::RUN:
+                               // TODO: switch to run state
+                               break;
+               }
+       }
+}
+
+void SelectMoveAction::UpdateWorld(float deltaT) {
+
+}
+
+void SelectMoveAction::Render(SDL_Surface *screen) {
+       Vector<int> offset(battle->CalculateScreenOffset(screen));
+       battle->RenderBackground(screen, offset);
+       battle->RenderMonsters(screen, offset);
+       battle->RenderHeroTags(screen, offset);
+       RenderMenu(screen, offset);
+}
+
+void SelectMoveAction::RenderMenu(SDL_Surface *screen, const Vector<int> &offset) {
+       Point<int> position(
+                       (battle->BackgroundWidth() - battle->GetMoveMenu().Width()) / 2,
+                       (battle->BackgroundHeight() * 3 / 4) - (battle->GetMoveMenu().Height() / 2));
+       battle->GetMoveMenu().Render(screen, position + offset);
+}
+
+}
diff --git a/src/battle/states/SelectMoveAction.h b/src/battle/states/SelectMoveAction.h
new file mode 100644 (file)
index 0000000..c135663
--- /dev/null
@@ -0,0 +1,48 @@
+/*
+ * SelectMoveAction.h
+ *
+ *  Created on: Aug 7, 2012
+ *      Author: holy
+ */
+
+#ifndef BATTLE_SELECTMOVEACTION_H_
+#define BATTLE_SELECTMOVEACTION_H_
+
+#include "../../app/State.h"
+#include "../../geometry/Vector.h"
+
+namespace battle {
+
+class BattleState;
+class MoveMenu;
+
+class SelectMoveAction
+: public app::State {
+
+public:
+       explicit SelectMoveAction(BattleState *battle)
+       : ctrl(0), battle(battle) { }
+       ~SelectMoveAction() { }
+
+public:
+       virtual void EnterState(app::Application &ctrl, SDL_Surface *screen);
+       virtual void ExitState();
+
+       virtual void Resize(int width, int height);
+
+       virtual void HandleInput(const app::Input &);
+       virtual void UpdateWorld(float deltaT);
+       virtual void Render(SDL_Surface *);
+
+private:
+       void RenderMenu(SDL_Surface *screen, const geometry::Vector<int> &offset);
+
+private:
+       app::Application *ctrl;
+       BattleState *battle;
+
+};
+
+}
+
+#endif /* BATTLE_SELECTMOVEACTION_H_ */