# Add inputs and outputs from these tool invocations to the build variables
CPP_SRCS += \
+../src/battle/states/PerformAttacks.cpp \
../src/battle/states/RunState.cpp \
../src/battle/states/SelectAttackType.cpp \
../src/battle/states/SelectIkari.cpp \
../src/battle/states/SwapHeroes.cpp
OBJS += \
+./src/battle/states/PerformAttacks.o \
./src/battle/states/RunState.o \
./src/battle/states/SelectAttackType.o \
./src/battle/states/SelectIkari.o \
./src/battle/states/SwapHeroes.o
CPP_DEPS += \
+./src/battle/states/PerformAttacks.d \
./src/battle/states/RunState.d \
./src/battle/states/SelectAttackType.d \
./src/battle/states/SelectIkari.d \
# Add inputs and outputs from these tool invocations to the build variables
CPP_SRCS += \
+../src/battle/states/PerformAttacks.cpp \
../src/battle/states/RunState.cpp \
../src/battle/states/SelectAttackType.cpp \
../src/battle/states/SelectIkari.cpp \
../src/battle/states/SwapHeroes.cpp
OBJS += \
+./src/battle/states/PerformAttacks.o \
./src/battle/states/RunState.o \
./src/battle/states/SelectAttackType.o \
./src/battle/states/SelectIkari.o \
./src/battle/states/SwapHeroes.o
CPP_DEPS += \
+./src/battle/states/PerformAttacks.d \
./src/battle/states/RunState.d \
./src/battle/states/SelectAttackType.d \
./src/battle/states/SelectIkari.d \
#include "PartyLayout.h"
#include "states/SelectMoveAction.h"
+#include "states/PerformAttacks.h"
#include "../app/Application.h"
#include "../app/Input.h"
#include "../common/Ikari.h"
itemMenu.AddEmptyEntry();
}
}
+ ClearAllAttacks();
}
void BattleState::ExitState(Application &ctrl, SDL_Surface *screen) {
ctrl.PopState(); // quit the battle scene
return;
}
- // reset attack choices
- activeHero = -1;
- for (vector<Hero>::size_type i(0), end(heroes.size()); i < end; ++i) {
- attackChoices[i] = AttackChoice(this);
+ if (AttackSelectionDone()) {
+ ctrl.PushState(new PerformAttacks(this));
+ } else {
+ ctrl.PushState(new SelectMoveAction(this));
}
- ctrl.PushState(new SelectMoveAction(this));
}
void BattleState::PauseState(Application &ctrl, SDL_Surface *screen) {
}
+void BattleState::ClearAllAttacks() {
+ activeHero = -1;
+ for (vector<Hero>::size_type i(0), end(heroes.size()); i < end; ++i) {
+ attackChoices[i] = AttackChoice(this);
+ }
+}
+
+
void BattleState::HandleEvents(const Input &input) {
}
const Hero &ActiveHero() const { return heroes[activeHero]; }
Hero &HeroAt(std::vector<Hero>::size_type index) { return heroes[index]; }
const Hero &HeroAt(std::vector<Hero>::size_type index) const { return heroes[index]; }
+ Monster &MonsterAt(std::vector<Monster>::size_type index) { return monsters[index]; }
+ const Monster &MonsterAt(std::vector<Monster>::size_type index) const { return monsters[index]; }
void SwapHeroes(std::vector<Hero>::size_type lhs, std::vector<Hero>::size_type rhs);
const HeroTag &ActiveHeroTag() const { return heroTags[activeHero]; }
const HeroTag &HeroTagAt(std::vector<Hero>::size_type index) const { return heroTags[index]; }
bool HeroPositionOccupied(int index) { return index >= 0 && index < int(heroes.size()); }
std::vector<Hero> &Heroes() { return heroes; }
const std::vector<Hero> &Heroes() const { return heroes; }
+ std::vector<Monster> &Monsters() { return monsters; }
+ const std::vector<Monster> &Monsters() const { return monsters; }
void SetRunaway() { ranAway = true; }
+ void ClearAllAttacks();
public:
geometry::Vector<int> CalculateScreenOffset(SDL_Surface *screen) const {
// temporary setters until loader is implemented
public:
+ void SetName(const char *n) { name = n; }
void SetSprite(graphics::Sprite *s) { sprite = s; }
void SetMaxHealth(Uint16 m) { maxHealth = m; }
void SetHealth(Uint16 h) { health = h; }
--- /dev/null
+/*
+ * PerformAttacks.cpp
+ *
+ * Created on: Aug 10, 2012
+ * Author: holy
+ */
+
+#include "PerformAttacks.h"
+
+#include "../BattleState.h"
+#include "../Hero.h"
+#include "../Monster.h"
+#include "../../app/Application.h"
+#include "../../app/Input.h"
+#include "../../common/Ikari.h"
+#include "../../common/Item.h"
+#include "../../common/Spell.h"
+#include "../../geometry/operators.h"
+#include "../../geometry/Point.h"
+#include "../../graphics/Font.h"
+#include "../../graphics/Frame.h"
+
+#include <cstring>
+
+using app::Application;
+using app::Input;
+using geometry::Point;
+using geometry::Vector;
+
+namespace battle {
+
+void PerformAttacks::EnterState(Application &c, SDL_Surface *screen) {
+ ctrl = &c;
+ // TODO: push battle animation if enemy is faster
+}
+
+void PerformAttacks::ExitState(Application &c, SDL_Surface *screen) {
+ ctrl = 0;
+}
+
+void PerformAttacks::ResumeState(Application &ctrl, SDL_Surface *screen) {
+ fakeMoveTimer = GraphicsTimers().StartCountdown(850);
+}
+
+void PerformAttacks::PauseState(Application &ctrl, SDL_Surface *screen) {
+
+}
+
+
+void PerformAttacks::Resize(int width, int height) {
+
+}
+
+
+void PerformAttacks::HandleEvents(const Input &input) {
+ if (fakeMoveTimer.JustHit()) {
+ if (monsters) {
+ if (titleBarText) {
+ titleBarText = 0;
+ ++cursor;
+ while (cursor < (int)battle->Monsters().size() && !battle->MonsterPositionOccupied(cursor)) {
+ ++cursor;
+ }
+ if (cursor >= (int)battle->Monsters().size()) {
+ battle->ClearAllAttacks();
+ ctrl->PopState();
+ }
+ } else {
+ titleBarText = battle->MonsterAt(cursor).Name();
+ }
+ } else {
+ if (titleBarText) {
+ titleBarText = 0;
+ ++cursor;
+ if (cursor == (int)battle->Heroes().size()) {
+ cursor = 0;
+ monsters = true;
+ }
+ } else {
+ const AttackChoice &ac(battle->AttackChoiceAt(cursor));
+ switch (ac.GetType()) {
+ case AttackChoice::SWORD:
+ titleBarText = battle->HeroAt(cursor).HasWeapon() ? battle->HeroAt(cursor).Weapon()->Name() : "Gauntlet";
+ break;
+ case AttackChoice::MAGIC:
+ titleBarText = ac.GetSpell()->Name();
+ break;
+ case AttackChoice::DEFEND:
+ titleBarText = "Defends.";
+ break;
+ case AttackChoice::IKARI:
+ titleBarText = ac.GetItem()->HasIkari() ? ac.GetItem()->GetIkari()->Name() : "No Ikari?";
+ break;
+ case AttackChoice::ITEM:
+ titleBarText = ac.GetItem()->Name();
+ break;
+ case AttackChoice::UNDECIDED:
+ titleBarText = "WTF???";
+ break;
+ }
+ }
+ }
+ }
+}
+
+
+void PerformAttacks::UpdateWorld(float deltaT) {
+
+}
+
+void PerformAttacks::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
+ RenderTitleBar(screen, offset);
+}
+
+void PerformAttacks::RenderTitleBar(SDL_Surface *screen, const Vector<int> &offset) {
+ if (!titleBarText) return;
+
+ int height(battle->Res().titleFrame->BorderHeight() * 2 + battle->Res().titleFont->CharHeight());
+ battle->Res().titleFrame->Draw(screen, Point<int>(offset.X(), offset.Y()), battle->BackgroundWidth(), height);
+
+ Point<int> textPosition(
+ (battle->BackgroundWidth() - (std::strlen(titleBarText) * battle->Res().titleFont->CharWidth())) / 2,
+ battle->Res().titleFrame->BorderHeight());
+ battle->Res().titleFont->DrawString(titleBarText, screen, textPosition + offset);
+}
+
+}
--- /dev/null
+/*
+ * PerformAttacks.h
+ *
+ * Created on: Aug 10, 2012
+ * Author: holy
+ */
+
+#ifndef BATTLE_PERFORMATTACKS_H_
+#define BATTLE_PERFORMATTACKS_H_
+
+#include "../../app/State.h"
+
+#include "../../geometry/Vector.h"
+
+namespace battle {
+
+class BattleState;
+
+class PerformAttacks
+: public app::State {
+
+public:
+ explicit PerformAttacks(BattleState *battle)
+ : ctrl(0), battle(battle), titleBarText(0), cursor(0), monsters(false) { }
+
+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:
+ void RenderTitleBar(SDL_Surface *screen, const geometry::Vector<int> &offset);
+
+private:
+ app::Application *ctrl;
+ BattleState *battle;
+ const char *titleBarText;
+ app::Timer<Uint32> fakeMoveTimer;
+ int cursor;
+ bool monsters;
+
+};
+
+}
+
+#endif /* BATTLE_PERFORMATTACKS_H_ */
void SelectIkari::ResumeState(Application &ctrl, SDL_Surface *screen) {
if (battle->ActiveHeroTargets().HasSelected()) {
+ battle->SetAttackType(AttackChoice::IKARI);
+ battle->ActiveHeroAttackChoice().SetItem(battle->GetIkariMenu().Selected());
ctrl.PopState();
}
}
void SelectItem::ResumeState(Application &ctrl, SDL_Surface *screen) {
if (battle->ActiveHeroTargets().HasSelected()) {
+ battle->SetAttackType(AttackChoice::ITEM);
+ battle->ActiveHeroAttackChoice().SetItem(battle->GetItemMenu().Selected());
ctrl.PopState();
}
}
void SelectSpell::ResumeState(Application &ctrl, SDL_Surface *screen) {
if (battle->ActiveHeroTargets().HasSelected()) {
+ battle->SetAttackType(AttackChoice::MAGIC);
+ battle->ActiveHeroAttackChoice().SetSpell(battle->GetSpellMenu().Selected());
ctrl.PopState();
}
}
SDL_Surface *monsterImg(IMG_Load("test-data/monster.png"));
Sprite dummySprite(monsterImg, 64, 64);
Monster monster;
+ monster.SetName("Monster");
monster.SetSprite(&dummySprite);
monster.SetMaxHealth(10);
monster.SetHealth(10);