From: Daniel Karbach Date: Wed, 8 Aug 2012 16:13:29 +0000 (+0200) Subject: added spell selection battle state X-Git-Url: https://git.localhorst.tv/?a=commitdiff_plain;h=185c6c79f8ba30981aad4e1d66f98143a344b95e;p=l2e.git added spell selection battle state --- diff --git a/Debug/src/battle/states/subdir.mk b/Debug/src/battle/states/subdir.mk index 8a61792..bb15270 100644 --- a/Debug/src/battle/states/subdir.mk +++ b/Debug/src/battle/states/subdir.mk @@ -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 diff --git a/Release/src/battle/states/subdir.mk b/Release/src/battle/states/subdir.mk index 05f8177..a1256fc 100644 --- a/Release/src/battle/states/subdir.mk +++ b/Release/src/battle/states/subdir.mk @@ -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 diff --git a/src/battle/BattleState.h b/src/battle/BattleState.h index 72342f0..858b111 100644 --- a/src/battle/BattleState.h +++ b/src/battle/BattleState.h @@ -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 > monsterPositions; diff --git a/src/battle/Hero.h b/src/battle/Hero.h index b1982b0..69db286 100644 --- a/src/battle/Hero.h +++ b/src/battle/Hero.h @@ -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; } diff --git a/src/battle/states/SelectAttackType.cpp b/src/battle/states/SelectAttackType.cpp index b3b3e0b..7dd06f6 100644 --- a/src/battle/states/SelectAttackType.cpp +++ b/src/battle/states/SelectAttackType.cpp @@ -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()) { diff --git a/src/battle/states/SelectMoveAction.cpp b/src/battle/states/SelectMoveAction.cpp index 5631e69..c728db0 100644 --- a/src/battle/states/SelectMoveAction.cpp +++ b/src/battle/states/SelectMoveAction.cpp @@ -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 index 0000000..66b55f1 --- /dev/null +++ b/src/battle/states/SelectSpell.cpp @@ -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 position(frame.BorderWidth(), frame.BorderHeight()); + Vector 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 index 0000000..e0bb118 --- /dev/null +++ b/src/battle/states/SelectSpell.h @@ -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_ */ diff --git a/src/main.cpp b/src/main.cpp index c8668dc..97a9399 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -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); diff --git a/test-data/battle-bg.png b/test-data/battle-bg.png index 65fa408..73e42b9 100644 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 index 0000000..cf10326 Binary files /dev/null and b/test-data/select-frame.png differ