From 222167ba3722dc7f47ff7510006bd516e0010a50 Mon Sep 17 00:00:00 2001 From: Daniel Karbach Date: Sat, 11 Aug 2012 01:11:46 +0200 Subject: [PATCH] added dummy state that echoes all selected attacks --- Debug/src/battle/states/subdir.mk | 3 + Release/src/battle/states/subdir.mk | 3 + src/battle/BattleState.cpp | 19 +++- src/battle/BattleState.h | 5 + src/battle/Monster.h | 1 + src/battle/states/PerformAttacks.cpp | 132 +++++++++++++++++++++++++++ src/battle/states/PerformAttacks.h | 53 +++++++++++ src/battle/states/SelectIkari.cpp | 2 + src/battle/states/SelectItem.cpp | 2 + src/battle/states/SelectSpell.cpp | 2 + src/main.cpp | 1 + test-data/large-font.png | Bin 539 -> 1626 bytes 12 files changed, 218 insertions(+), 5 deletions(-) create mode 100644 src/battle/states/PerformAttacks.cpp create mode 100644 src/battle/states/PerformAttacks.h diff --git a/Debug/src/battle/states/subdir.mk b/Debug/src/battle/states/subdir.mk index 3d78d84..9b3a196 100644 --- a/Debug/src/battle/states/subdir.mk +++ b/Debug/src/battle/states/subdir.mk @@ -4,6 +4,7 @@ # 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 \ @@ -14,6 +15,7 @@ CPP_SRCS += \ ../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 \ @@ -24,6 +26,7 @@ OBJS += \ ./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 \ diff --git a/Release/src/battle/states/subdir.mk b/Release/src/battle/states/subdir.mk index 0461161..0a764ce 100644 --- a/Release/src/battle/states/subdir.mk +++ b/Release/src/battle/states/subdir.mk @@ -4,6 +4,7 @@ # 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 \ @@ -14,6 +15,7 @@ CPP_SRCS += \ ../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 \ @@ -24,6 +26,7 @@ OBJS += \ ./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 \ diff --git a/src/battle/BattleState.cpp b/src/battle/BattleState.cpp index c294e1a..b5c91f8 100644 --- a/src/battle/BattleState.cpp +++ b/src/battle/BattleState.cpp @@ -9,6 +9,7 @@ #include "PartyLayout.h" #include "states/SelectMoveAction.h" +#include "states/PerformAttacks.h" #include "../app/Application.h" #include "../app/Input.h" #include "../common/Ikari.h" @@ -180,6 +181,7 @@ void BattleState::LoadInventory() { itemMenu.AddEmptyEntry(); } } + ClearAllAttacks(); } void BattleState::ExitState(Application &ctrl, SDL_Surface *screen) { @@ -192,12 +194,11 @@ void BattleState::ResumeState(Application &ctrl, SDL_Surface *screen) { ctrl.PopState(); // quit the battle scene return; } - // reset attack choices - activeHero = -1; - for (vector::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) { @@ -205,6 +206,14 @@ void BattleState::PauseState(Application &ctrl, SDL_Surface *screen) { } +void BattleState::ClearAllAttacks() { + activeHero = -1; + for (vector::size_type i(0), end(heroes.size()); i < end; ++i) { + attackChoices[i] = AttackChoice(this); + } +} + + void BattleState::HandleEvents(const Input &input) { } diff --git a/src/battle/BattleState.h b/src/battle/BattleState.h index e94ed41..347afc3 100644 --- a/src/battle/BattleState.h +++ b/src/battle/BattleState.h @@ -83,6 +83,8 @@ public: const Hero &ActiveHero() const { return heroes[activeHero]; } Hero &HeroAt(std::vector::size_type index) { return heroes[index]; } const Hero &HeroAt(std::vector::size_type index) const { return heroes[index]; } + Monster &MonsterAt(std::vector::size_type index) { return monsters[index]; } + const Monster &MonsterAt(std::vector::size_type index) const { return monsters[index]; } void SwapHeroes(std::vector::size_type lhs, std::vector::size_type rhs); const HeroTag &ActiveHeroTag() const { return heroTags[activeHero]; } const HeroTag &HeroTagAt(std::vector::size_type index) const { return heroTags[index]; } @@ -109,8 +111,11 @@ public: bool HeroPositionOccupied(int index) { return index >= 0 && index < int(heroes.size()); } std::vector &Heroes() { return heroes; } const std::vector &Heroes() const { return heroes; } + std::vector &Monsters() { return monsters; } + const std::vector &Monsters() const { return monsters; } void SetRunaway() { ranAway = true; } + void ClearAllAttacks(); public: geometry::Vector CalculateScreenOffset(SDL_Surface *screen) const { diff --git a/src/battle/Monster.h b/src/battle/Monster.h index d3a7162..f37786a 100644 --- a/src/battle/Monster.h +++ b/src/battle/Monster.h @@ -51,6 +51,7 @@ public: // 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; } diff --git a/src/battle/states/PerformAttacks.cpp b/src/battle/states/PerformAttacks.cpp new file mode 100644 index 0000000..35253ce --- /dev/null +++ b/src/battle/states/PerformAttacks.cpp @@ -0,0 +1,132 @@ +/* + * 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 + +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 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 &offset) { + if (!titleBarText) return; + + int height(battle->Res().titleFrame->BorderHeight() * 2 + battle->Res().titleFont->CharHeight()); + battle->Res().titleFrame->Draw(screen, Point(offset.X(), offset.Y()), battle->BackgroundWidth(), height); + + Point textPosition( + (battle->BackgroundWidth() - (std::strlen(titleBarText) * battle->Res().titleFont->CharWidth())) / 2, + battle->Res().titleFrame->BorderHeight()); + battle->Res().titleFont->DrawString(titleBarText, screen, textPosition + offset); +} + +} diff --git a/src/battle/states/PerformAttacks.h b/src/battle/states/PerformAttacks.h new file mode 100644 index 0000000..f6157e1 --- /dev/null +++ b/src/battle/states/PerformAttacks.h @@ -0,0 +1,53 @@ +/* + * 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 &offset); + +private: + app::Application *ctrl; + BattleState *battle; + const char *titleBarText; + app::Timer fakeMoveTimer; + int cursor; + bool monsters; + +}; + +} + +#endif /* BATTLE_PERFORMATTACKS_H_ */ diff --git a/src/battle/states/SelectIkari.cpp b/src/battle/states/SelectIkari.cpp index adeafb2..605ba2c 100644 --- a/src/battle/states/SelectIkari.cpp +++ b/src/battle/states/SelectIkari.cpp @@ -37,6 +37,8 @@ void SelectIkari::ExitState(Application &c, SDL_Surface *screen) { void SelectIkari::ResumeState(Application &ctrl, SDL_Surface *screen) { if (battle->ActiveHeroTargets().HasSelected()) { + battle->SetAttackType(AttackChoice::IKARI); + battle->ActiveHeroAttackChoice().SetItem(battle->GetIkariMenu().Selected()); ctrl.PopState(); } } diff --git a/src/battle/states/SelectItem.cpp b/src/battle/states/SelectItem.cpp index 4701fb9..a8c23bb 100644 --- a/src/battle/states/SelectItem.cpp +++ b/src/battle/states/SelectItem.cpp @@ -36,6 +36,8 @@ void SelectItem::ExitState(Application &c, SDL_Surface *screen) { void SelectItem::ResumeState(Application &ctrl, SDL_Surface *screen) { if (battle->ActiveHeroTargets().HasSelected()) { + battle->SetAttackType(AttackChoice::ITEM); + battle->ActiveHeroAttackChoice().SetItem(battle->GetItemMenu().Selected()); ctrl.PopState(); } } diff --git a/src/battle/states/SelectSpell.cpp b/src/battle/states/SelectSpell.cpp index 56f750f..a9c06cc 100644 --- a/src/battle/states/SelectSpell.cpp +++ b/src/battle/states/SelectSpell.cpp @@ -37,6 +37,8 @@ void SelectSpell::ExitState(Application &c, SDL_Surface *screen) { void SelectSpell::ResumeState(Application &ctrl, SDL_Surface *screen) { if (battle->ActiveHeroTargets().HasSelected()) { + battle->SetAttackType(AttackChoice::MAGIC); + battle->ActiveHeroAttackChoice().SetSpell(battle->GetSpellMenu().Selected()); ctrl.PopState(); } } diff --git a/src/main.cpp b/src/main.cpp index e39d318..cb4ad91 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -81,6 +81,7 @@ int main(int argc, char **argv) { 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); diff --git a/test-data/large-font.png b/test-data/large-font.png index c01542a7aa7f44cfea9ad7c323923dabeefde6ba..30f5576ca6a9ac1737a326700db36a365d597bb8 100644 GIT binary patch delta 1610 zcmV-Q2DSN{1lkOcBYy@VNklbab9|L=lOlv{p0*0vIUXASn~vRde>%;Ij;tYi(p61_GXE zpw@5i+I&avH-CO_E9R)4AW{40T3<_#XCMIU8z{QfXZ1|@tW17%9xxX}onj&e0!}p0 z-G-3gxYwk2F=`wT0|6%*D7u$%Yx%nyi&4cuz&-|gdS9sCJjv5*{HI<&0|6(*Kv6va zW*M}%eCIy~v+@8t8EAHI+}aFvYbJbjEY(`R^A`gF0Dk}g000005Ja|3zIPUxH&Lqx zw2rmUmH*CI*YeJAN3YM5I-k+wTkhi8L!fu=hTa|rt>w!D0Ud<*g^QXGt@U?$%kQn> zdo%61nsjvEuGLws*Ea(JBMj8K{!6ZA9<@GAZ~3dm1UW-K%|v%Sx7vB_7zpqQ2Y7*i zb7G*?8Gk);b#=r(WB;#mZ2zz75Nj(K0DCIRz^fq5CZ`t3^eM^KP3+{+l;N_mv%AFD*rFJ z@)!t+Fwp4LpQDkFT8pQSQ(_=sL<|J17#kUp3V$$AeC#rMeVJYIPo;Ar?0){I#7YbV ztYo0x`Pq8cm+4)XrnZKUu1T*odF}SqOcZ^;a$hQUKR*Tn000000000i%re>F*>ed* zmtUI)iC$l5*7Mt?H-G8#${`N~bg*1+?AdcF^p@Y+7c9E(-)dhLtDk>ukA(MgWFX)q z1AmnoVzv3gtnc#-uFs8ufDXJsfENf513e0{&)%^Q0|8Go(5my%rAA^t)ilwoyo-SV z2D-22N-??y>n%Swhqc(}jM#^PfD;Wg`x`mBFJ8(>OtiOo7zjAgK&#W+s-!R6Suha5 zK>K_%Kh?~;=jkyl0|5-Qu8C6Hv9^gA2mk;800000 zZ~$RBiQQ&hxw}WeU3sCX=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