]> git.localhorst.tv Git - l2e.git/commitdiff
added spell selection battle state
authorDaniel Karbach <daniel.karbach@localhorst.tv>
Wed, 8 Aug 2012 16:13:29 +0000 (18:13 +0200)
committerDaniel Karbach <daniel.karbach@localhorst.tv>
Wed, 8 Aug 2012 16:13:29 +0000 (18:13 +0200)
Debug/src/battle/states/subdir.mk
Release/src/battle/states/subdir.mk
src/battle/BattleState.h
src/battle/Hero.h
src/battle/states/SelectAttackType.cpp
src/battle/states/SelectMoveAction.cpp
src/battle/states/SelectSpell.cpp [new file with mode: 0644]
src/battle/states/SelectSpell.h [new file with mode: 0644]
src/main.cpp
test-data/battle-bg.png
test-data/select-frame.png [new file with mode: 0644]

index 8a617921514b98df1a0f73a6ccda37c9a6bcb757..bb15270d3754b521b1b38c76c98be4dae88048fc 100644 (file)
@@ -5,15 +5,18 @@
 # Add inputs and outputs from these tool invocations to the build variables 
 CPP_SRCS += \
 ../src/battle/states/SelectAttackType.cpp \
-../src/battle/states/SelectMoveAction.cpp 
+../src/battle/states/SelectMoveAction.cpp \
+../src/battle/states/SelectSpell.cpp 
 
 OBJS += \
 ./src/battle/states/SelectAttackType.o \
-./src/battle/states/SelectMoveAction.o 
+./src/battle/states/SelectMoveAction.o \
+./src/battle/states/SelectSpell.o 
 
 CPP_DEPS += \
 ./src/battle/states/SelectAttackType.d \
-./src/battle/states/SelectMoveAction.d 
+./src/battle/states/SelectMoveAction.d \
+./src/battle/states/SelectSpell.d 
 
 
 # Each subdirectory must supply rules for building sources it contributes
index 05f8177eaf459b3fc568ad33b4786eb7779ececf..a1256fc712b1b45b51f19ad4b45ff4de8c86fc57 100644 (file)
@@ -5,15 +5,18 @@
 # Add inputs and outputs from these tool invocations to the build variables 
 CPP_SRCS += \
 ../src/battle/states/SelectAttackType.cpp \
-../src/battle/states/SelectMoveAction.cpp 
+../src/battle/states/SelectMoveAction.cpp \
+../src/battle/states/SelectSpell.cpp 
 
 OBJS += \
 ./src/battle/states/SelectAttackType.o \
-./src/battle/states/SelectMoveAction.o 
+./src/battle/states/SelectMoveAction.o \
+./src/battle/states/SelectSpell.o 
 
 CPP_DEPS += \
 ./src/battle/states/SelectAttackType.d \
-./src/battle/states/SelectMoveAction.d 
+./src/battle/states/SelectMoveAction.d \
+./src/battle/states/SelectSpell.d 
 
 
 # Each subdirectory must supply rules for building sources it contributes
index 72342f0961e0616de36b058305a7fa30127722a5..858b111c426283008570054b8f48030dee72901a 100644 (file)
@@ -37,7 +37,7 @@ class BattleState
 : public app::State {
 
 public:
-       BattleState(SDL_Surface *background, const PartyLayout &monstersLayout, const PartyLayout &heroesLayout, const graphics::Sprite *attackIcons, const graphics::Sprite *moveIcons, const graphics::Frame *heroTagFrame, const graphics::Frame *activeHeroTagFrame, const graphics::Gauge *healthGauge, const graphics::Gauge *manaGauge, const graphics::Gauge *ikariGauge, const graphics::Sprite *heroTagSprites, const graphics::Font *heroTagFont)
+       BattleState(SDL_Surface *background, const PartyLayout &monstersLayout, const PartyLayout &heroesLayout, const graphics::Sprite *attackIcons, const graphics::Sprite *moveIcons, const graphics::Frame *heroTagFrame, const graphics::Frame *activeHeroTagFrame, const graphics::Gauge *healthGauge, const graphics::Gauge *manaGauge, const graphics::Gauge *ikariGauge, const graphics::Sprite *heroTagSprites, const graphics::Font *heroTagFont, const graphics::Frame *selectFrame)
        : background(background)
        , monstersLayout(&monstersLayout)
        , heroesLayout(&heroesLayout)
@@ -48,6 +48,7 @@ public:
        , ikariGauge(ikariGauge)
        , heroTagSprites(heroTagSprites)
        , heroTagFont(heroTagFont)
+       , selectFrame(selectFrame)
        , attackTypeMenu(attackIcons)
        , moveMenu(moveIcons)
        , activeHero(-1) { }
@@ -71,9 +72,14 @@ public:
 public:
        AttackTypeMenu &GetAttackTypeMenu() { return attackTypeMenu; }
        MoveMenu &GetMoveMenu() { return moveMenu; }
+       const graphics::Frame &GetSelectFrame() const { return *selectFrame; }
 
        bool HasMoreHeroes() const { return activeHero < (int) heroes.size(); }
        void NextHero() { ++activeHero; }
+       bool BeforeFirstHero() const { return activeHero < 0; }
+       void PreviousHero() { --activeHero; }
+       Hero &ActiveHero() { return heroes[activeHero]; }
+       const Hero &ActiveHero() const { return heroes[activeHero]; }
        bool HasChosenAttackType() const { return attackChoices[activeHero].GetType() != AttackChoice::UNDECIDED; }
        void SetAttackType(AttackChoice::Type t) { attackChoices[activeHero].SetType(t); }
        bool AttackSelectionDone() const { return activeHero >= (int) heroes.size(); }
@@ -103,6 +109,7 @@ private:
        const graphics::Gauge *ikariGauge;
        const graphics::Sprite *heroTagSprites;
        const graphics::Font *heroTagFont;
+       const graphics::Frame *selectFrame;
        AttackTypeMenu attackTypeMenu;
        MoveMenu moveMenu;
        std::vector<geometry::Point<int> > monsterPositions;
index b1982b05285ab7cc2b73f80ee91e208b5f3230b6..69db286c74d32fb69fa64a8ffe575439e90c0d4b 100644 (file)
@@ -32,6 +32,7 @@ public:
        Uint16 MaxMana() const { return maxMana; }
        Uint16 Mana() const { return mana; }
        int RelativeMana(int max) const { return maxMana == 0 ? 0 : mana * max / maxMana; }
+       bool CanUseMagic() const { return maxMana > 0; }
 
        Uint8 IP() const { return ip; }
        int RelativeIP(int max) const { return ip * max / 255; }
index b3b3e0b0a6290195e56f63a2b47f543fee7f4619..7dd06f6217b8e610f49828b891994b020ef20c1d 100644 (file)
@@ -7,6 +7,8 @@
 
 #include "SelectAttackType.h"
 
+#include "SelectMoveAction.h"
+#include "SelectSpell.h"
 #include "../AttackChoice.h"
 #include "../BattleState.h"
 #include "../../app/Application.h"
@@ -31,7 +33,10 @@ void SelectAttackType::ExitState(Application &c, SDL_Surface *screen) {
 }
 
 void SelectAttackType::ResumeState(Application &ctrl, SDL_Surface *screen) {
-
+       if (battle->AttackSelectionDone()) {
+               // pass through
+               ctrl.PopState();
+       }
 }
 
 void SelectAttackType::PauseState(Application &ctrl, SDL_Surface *screen) {
@@ -65,8 +70,9 @@ void SelectAttackType::HandleInput(const Input &input) {
                                battle->NextHero();
                                break;
                        case AttackChoice::MAGIC:
-                               // TODO: switch to spell select
-                               battle->NextHero();
+                               if (battle->ActiveHero().CanUseMagic()) {
+                                       ctrl->PushState(new SelectSpell(battle, this));
+                               }
                                break;
                        case AttackChoice::DEFEND:
                                battle->NextHero();
@@ -82,6 +88,12 @@ void SelectAttackType::HandleInput(const Input &input) {
                        default:
                                throw std::logic_error("selected invalid attack type");
                }
+       } else if (input.JustPressed(Input::ACTION_B)) {
+               battle->SetAttackType(AttackChoice::UNDECIDED);
+               battle->PreviousHero();
+               if (battle->BeforeFirstHero()) {
+                       ctrl->ChangeState(new SelectMoveAction(battle));
+               }
        }
 
        if (battle->AttackSelectionDone()) {
index 5631e69856f166b930cb1fb7023eb97987ff2e97..c728db0e61c6bd51502329e2ba7a84026d0fa7c1 100644 (file)
@@ -43,7 +43,7 @@ void SelectMoveAction::Resize(int width, int height) {
 }
 
 
-void SelectMoveAction::HandleInput(const app::Input &input) {
+void SelectMoveAction::HandleInput(const Input &input) {
        if (input.IsDown(Input::PAD_UP)) {
                battle->GetMoveMenu().Select(MoveMenu::CHANGE);
        } else if (input.IsDown(Input::PAD_DOWN)) {
diff --git a/src/battle/states/SelectSpell.cpp b/src/battle/states/SelectSpell.cpp
new file mode 100644 (file)
index 0000000..66b55f1
--- /dev/null
@@ -0,0 +1,75 @@
+/*
+ * SelectSpell.cpp
+ *
+ *  Created on: Aug 8, 2012
+ *      Author: holy
+ */
+
+#include "SelectSpell.h"
+
+#include "SelectAttackType.h"
+#include "SelectMoveAction.h"
+#include "../BattleState.h"
+#include "../../app/Application.h"
+#include "../../app/Input.h"
+#include "../../geometry/operators.h"
+#include "../../geometry/Point.h"
+#include "../../graphics/Frame.h"
+
+using app::Application;
+using app::Input;
+using geometry::Point;
+using geometry::Vector;
+using graphics::Frame;
+
+namespace battle {
+
+void SelectSpell::EnterState(Application &c, SDL_Surface *screen) {
+       ctrl = &c;
+}
+
+void SelectSpell::ExitState(Application &c, SDL_Surface *screen) {
+       ctrl = 0;
+}
+
+void SelectSpell::ResumeState(Application &ctrl, SDL_Surface *screen) {
+
+}
+
+void SelectSpell::PauseState(Application &ctrl, SDL_Surface *screen) {
+
+}
+
+
+void SelectSpell::Resize(int width, int height) {
+
+}
+
+
+void SelectSpell::HandleInput(const Input &input) {
+       if (input.JustPressed(Input::ACTION_A)) {
+               // TODO: switch to target select
+               battle->NextHero();
+               ctrl->PopState();
+       }
+       if (input.JustPressed(Input::ACTION_B)) {
+               ctrl->PopState(); // return control to parent
+       }
+}
+
+void SelectSpell::UpdateWorld(float deltaT) {
+
+}
+
+void SelectSpell::Render(SDL_Surface *screen) {
+       parent->Render(screen);
+       const Frame &frame(battle->GetSelectFrame());
+       Point<int> position(frame.BorderWidth(), frame.BorderHeight());
+       Vector<int> offset(battle->CalculateScreenOffset(screen));
+       int width(battle->BackgroundWidth() - 2 * frame.BorderWidth());
+       // TODO: replace with font height
+       int height(frame.BorderHeight() * 13);
+       frame.Draw(screen, position + offset, width, height);
+}
+
+}
diff --git a/src/battle/states/SelectSpell.h b/src/battle/states/SelectSpell.h
new file mode 100644 (file)
index 0000000..e0bb118
--- /dev/null
@@ -0,0 +1,46 @@
+/*
+ * SelectSpell.h
+ *
+ *  Created on: Aug 8, 2012
+ *      Author: holy
+ */
+
+#ifndef BATTLE_SELECTSPELL_H_
+#define BATTLE_SELECTSPELL_H_
+
+#include "../../app/State.h"
+
+namespace battle {
+
+class BattleState;
+class SelectAttackType;
+
+class SelectSpell
+: public app::State {
+
+public:
+       SelectSpell(BattleState *battle, SelectAttackType *parent)
+       : ctrl(0), battle(battle), parent(parent) { }
+
+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 HandleInput(const app::Input &);
+       virtual void UpdateWorld(float deltaT);
+       virtual void Render(SDL_Surface *);
+
+private:
+       app::Application *ctrl;
+       BattleState *battle;
+       SelectAttackType *parent;
+
+};
+
+}
+
+#endif /* BATTLE_SELECTSPELL_H_ */
index c8668dca1145f8c3da24bca4d50691be768b9c02..97a93994a634c8bcd018fb75803fcbc656d175a4 100644 (file)
@@ -138,7 +138,11 @@ int main(int argc, char **argv) {
                Gauge manaGauge(gauges, 0, 32, 0, 0, 16, 6, 1, 6);
                Gauge ikariGauge(gauges, 0, 48, 0, 0, 16, 6, 1, 6);
 
-               BattleState *battleState(new BattleState(bg, monstersLayout, heroesLayout, &attackIconsSprite, &moveIconsSprite, &heroTagFrame, &activeHeroTagFrame, &healthGauge, &manaGauge, &ikariGauge, &heroTagSprite, &heroTagFont));
+               SDL_Surface *selectFrameImg(IMG_Load("test-data/select-frame.png"));
+               Frame selectFrame(selectFrameImg, 16, 16);
+
+               // TODO: create a container for all the battle resources
+               BattleState *battleState(new BattleState(bg, monstersLayout, heroesLayout, &attackIconsSprite, &moveIconsSprite, &heroTagFrame, &activeHeroTagFrame, &healthGauge, &manaGauge, &ikariGauge, &heroTagSprite, &heroTagFont, &selectFrame));
                battleState->AddMonster(monster);
                battleState->AddMonster(monster);
                battleState->AddMonster(monster);
index 65fa4087c0e8c54024ed97ef827e50bbac2e134d..73e42b94fd2c501efc70ea661335d114bbbdf537 100644 (file)
Binary files a/test-data/battle-bg.png and b/test-data/battle-bg.png differ
diff --git a/test-data/select-frame.png b/test-data/select-frame.png
new file mode 100644 (file)
index 0000000..cf10326
Binary files /dev/null and b/test-data/select-frame.png differ