# 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
# 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
: 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)
, ikariGauge(ikariGauge)
, heroTagSprites(heroTagSprites)
, heroTagFont(heroTagFont)
+ , selectFrame(selectFrame)
, attackTypeMenu(attackIcons)
, moveMenu(moveIcons)
, activeHero(-1) { }
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(); }
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;
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; }
#include "SelectAttackType.h"
+#include "SelectMoveAction.h"
+#include "SelectSpell.h"
#include "../AttackChoice.h"
#include "../BattleState.h"
#include "../../app/Application.h"
}
void SelectAttackType::ResumeState(Application &ctrl, SDL_Surface *screen) {
-
+ if (battle->AttackSelectionDone()) {
+ // pass through
+ ctrl.PopState();
+ }
}
void SelectAttackType::PauseState(Application &ctrl, SDL_Surface *screen) {
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();
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()) {
}
-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)) {
--- /dev/null
+/*
+ * 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);
+}
+
+}
--- /dev/null
+/*
+ * 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_ */
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);