From: Daniel Karbach Date: Fri, 10 Aug 2012 23:11:46 +0000 (+0200) Subject: added dummy state that echoes all selected attacks X-Git-Url: https://git.localhorst.tv/?a=commitdiff_plain;h=222167ba3722dc7f47ff7510006bd516e0010a50;p=l2e.git added dummy state that echoes all selected attacks --- 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 c01542a..30f5576 100644 Binary files a/test-data/large-font.png and b/test-data/large-font.png differ