From: Daniel Karbach Date: Sun, 2 Dec 2012 18:49:03 +0000 (+0100) Subject: added capsule attack/animation handling X-Git-Url: https://git.localhorst.tv/?a=commitdiff_plain;h=2255d436a0c2acc10b015827366a72b2ece86094;p=l2e.git added capsule attack/animation handling also revamped animation related code for debugability --- diff --git a/src/battle/AttackChoice.h b/src/battle/AttackChoice.h index 8577976..b73e420 100644 --- a/src/battle/AttackChoice.h +++ b/src/battle/AttackChoice.h @@ -1,8 +1,12 @@ #ifndef BATTLE_ATTACKCHOICE_H_ #define BATTLE_ATTACKCHOICE_H_ +namespace common { + class Item; + class Spell; +} + #include "TargetSelection.h" -#include "../common/fwd.h" namespace battle { diff --git a/src/battle/BattleState.cpp b/src/battle/BattleState.cpp index 9830e8c..0171e14 100644 --- a/src/battle/BattleState.cpp +++ b/src/battle/BattleState.cpp @@ -177,9 +177,7 @@ class OrderCompare { public: OrderCompare(BattleState *battle) : battle(battle) { } bool operator ()(const BattleState::Order &lhs, const BattleState::Order &rhs) { - int lagl(lhs.isMonster ? battle->MonsterAt(lhs.index).GetStats().Agility() : battle->HeroAt(lhs.index).GetStats().Agility()); - int ragl(rhs.isMonster ? battle->MonsterAt(rhs.index).GetStats().Agility() : battle->HeroAt(rhs.index).GetStats().Agility()); - return lagl > ragl; + return lhs.GetStats(*battle).Agility() > rhs.GetStats(*battle).Agility(); } private: BattleState *battle; @@ -188,12 +186,15 @@ class OrderCompare { void BattleState::CalculateAttackOrder() { attackOrder.reserve(monsters.size() + NumHeroes()); for (int i(0); i < NumHeroes(); ++i) { - attackOrder.push_back(Order(i, false)); + attackOrder.push_back(Order(Order::HERO, i)); } for (vector::size_type i(0), end(monsters.size()); i < end; ++i) { - attackOrder.push_back(Order(i, true)); + attackOrder.push_back(Order(Order::MONSTER, i)); MonsterAt(i).GetAttackChoice() = AttackChoice(this); } + if (capsule.Health() > 0) { + attackOrder.push_back(Order(Order::CAPSULE)); + } std::sort(attackOrder.begin(), attackOrder.end(), OrderCompare(this)); } @@ -204,10 +205,12 @@ void BattleState::NextAttack() { } ++attackCursor; while (attackCursor < int(attackOrder.size())) { - if (attackOrder[attackCursor].isMonster) { + if (attackOrder[attackCursor].IsMonster()) { if (MonsterAt(attackOrder[attackCursor].index).Health() > 0) break; - } else { + } else if (attackOrder[attackCursor].IsHero()) { if (HeroAt(attackOrder[attackCursor].index).Health() > 0) break; + } else { + if (capsule.Health() > 0) break; } ++attackCursor; } @@ -219,23 +222,20 @@ bool BattleState::AttacksFinished() const { } void BattleState::CalculateDamage() { - if (CurrentAttack().isMonster) { + if (CurrentAttack().IsMonster()) { DecideMonsterAttack(MonsterAt(CurrentAttack().index)); + } else if (CurrentAttack().IsCapsule()) { + DecideCapsuleAttack(); } - AttackChoice &ac(CurrentAttack().isMonster ? MonsterAt(CurrentAttack().index).GetAttackChoice() : HeroAt(CurrentAttack().index).GetAttackChoice()); + AttackChoice &ac = CurrentAttack().GetAttackChoice(*this); if (ac.GetType() == AttackChoice::DEFEND) return; TargetSelection &ts(ac.Selection()); - if (CurrentAttack().isMonster) { - const Stats &attackerStats(MonsterAt(CurrentAttack().index).GetStats()); - CalculateDamage(attackerStats, ts); - } else { - const Stats &attackerStats(HeroAt(CurrentAttack().index).GetStats()); - CalculateDamage(attackerStats, ts); - } + const Stats &attackerStats = CurrentAttack().GetStats(*this); + CalculateDamage(attackerStats, ts); } -void BattleState::DecideMonsterAttack(Monster &m) const { +void BattleState::DecideMonsterAttack(Monster &m) { AttackChoice &ac(m.GetAttackChoice()); TargetSelection &ts(ac.Selection()); ac.Reset(); @@ -249,6 +249,46 @@ void BattleState::DecideMonsterAttack(Monster &m) const { ts.Select(target); } +void BattleState::DecideCapsuleAttack() { + AttackChoice &ac(capsule.GetAttackChoice()); + TargetSelection &ts(ac.Selection()); + ac.Reset(); + int target(rand() % monsters.size()); + while (!MonsterPositionOccupied(target)) { + target = rand() % monsters.size(); + } + ac.SetType(AttackChoice::SWORD); + ts.SelectMonsters(); + ts.SetSingle(); + ts.Select(target); +} + +AttackChoice &BattleState::Order::GetAttackChoice(BattleState &b) const { + switch (by) { + case HERO: + return b.HeroAt(index).GetAttackChoice(); + case CAPSULE: + return b.GetCapsule().GetAttackChoice(); + case MONSTER: + return b.MonsterAt(index).GetAttackChoice(); + default: + throw std::runtime_error("invalid case in BttleStats::Order::GetAttackChoice()"); + } +} + +Stats &BattleState::Order::GetStats(BattleState &b) const { + switch (by) { + case HERO: + return b.HeroAt(index).GetStats(); + case CAPSULE: + return b.GetCapsule().GetStats(); + case MONSTER: + return b.MonsterAt(index).GetStats(); + default: + throw std::runtime_error("invalid case in BttleStats::Order::GetAttackChoice()"); + } +} + void BattleState::CalculateDamage(const Stats &attackerStats, TargetSelection &ts) const { bool hitSome(false); if (ts.TargetsMonsters()) { @@ -304,7 +344,7 @@ Uint16 BattleState::CalculateDamage(const Stats &attacker, const Stats &defender void BattleState::ApplyDamage() { if (attackCursor < 0) return; - AttackChoice &ac(CurrentAttack().isMonster ? MonsterAt(CurrentAttack().index).GetAttackChoice() : HeroAt(CurrentAttack().index).GetAttackChoice()); + AttackChoice &ac = CurrentAttack().GetAttackChoice(*this); TargetSelection &ts(ac.Selection()); if (ts.TargetsMonsters()) { for (int i(0); i < MaxMonsters(); ++i) { @@ -328,11 +368,7 @@ void BattleState::ApplyDamage() { } AttackChoice &BattleState::CurrentAttackAttackChoice() { - if (CurrentAttack().isMonster) { - return MonsterAt(CurrentAttack().index).GetAttackChoice(); - } else { - return HeroAt(CurrentAttack().index).GetAttackChoice(); - } + return CurrentAttack().GetAttackChoice(*this); } void BattleState::ClearAllAttacks() { @@ -344,6 +380,7 @@ void BattleState::ClearAllAttacks() { for (int i(0); i < MaxMonsters(); ++i) { MonsterAt(i).GetAttackChoice() = AttackChoice(this); } + capsule.GetAttackChoice() = AttackChoice(this); attackOrder.clear(); } diff --git a/src/battle/BattleState.h b/src/battle/BattleState.h index 3a9500c..1c994e4 100644 --- a/src/battle/BattleState.h +++ b/src/battle/BattleState.h @@ -78,6 +78,8 @@ public: const HeroTag &HeroTagAt(int index) const { assert(index >= 0 && index < NumHeroes()); return heroTags[index]; } const geometry::Vector &HeroTagPositionAt(int index) const { assert(index >= 0 && index < NumHeroes()); return heroTagPositions[index]; } + Capsule &GetCapsule() { return capsule; } + bool HasChosenAttackType() const { return ActiveHero().GetAttackChoice().GetType() != AttackChoice::UNDECIDED; } bool AttackSelectionDone() const { return activeHero >= numHeroes; } @@ -91,10 +93,20 @@ public: void SetRunaway() { ranAway = true; } struct Order { - Order(int index, bool isMonster) - : index(index), isMonster(isMonster) { } + enum Performer { + HERO, + CAPSULE, + MONSTER, + }; + Order(Performer by, int index = 0) + : index(index), by(by) { } + AttackChoice &GetAttackChoice(BattleState &) const; + common::Stats &GetStats(BattleState &) const; + bool IsHero() const { return by == HERO; } + bool IsCapsule() const { return by == CAPSULE; } + bool IsMonster() const { return by == MONSTER; } int index; - bool isMonster; + Performer by; }; void CalculateAttackOrder(); @@ -137,7 +149,8 @@ private: private: void LoadInventory(); - void DecideMonsterAttack(Monster &) const; + void DecideMonsterAttack(Monster &); + void DecideCapsuleAttack(); void CalculateDamage(const common::Stats &attackerStats, TargetSelection &targets) const; Uint16 CalculateDamage(const common::Stats &attacker, const common::Stats &defender) const; diff --git a/src/battle/Capsule.h b/src/battle/Capsule.h index c16196c..c5050f7 100644 --- a/src/battle/Capsule.h +++ b/src/battle/Capsule.h @@ -9,9 +9,6 @@ #include "../graphics/fwd.h" #include "../graphics/Menu.h" -#include -#include - namespace battle { class Capsule { diff --git a/src/battle/NumberAnimation.cpp b/src/battle/NumberAnimation.cpp index 166ace6..63d1656 100644 --- a/src/battle/NumberAnimation.cpp +++ b/src/battle/NumberAnimation.cpp @@ -1,6 +1,7 @@ #include "NumberAnimation.h" #include "../geometry/Vector.h" +#include "../graphics/Sprite.h" using app::State; using geometry::Vector; diff --git a/src/battle/TargetSelection.cpp b/src/battle/TargetSelection.cpp index 42a88e4..961f57c 100644 --- a/src/battle/TargetSelection.cpp +++ b/src/battle/TargetSelection.cpp @@ -67,6 +67,7 @@ void TargetSelection::MoveUp() { } void TargetSelection::MoveRight() { + assert(battle); if (TargetsMonsters()) { cursor = (cursor + 1) % battle->MaxMonsters(); while (!battle->MonsterPositionOccupied(cursor)) { @@ -78,6 +79,7 @@ void TargetSelection::MoveRight() { } void TargetSelection::MoveDown() { + assert(battle); if (TargetsMonsters()) { SelectHeroes(); return; @@ -89,6 +91,7 @@ void TargetSelection::MoveDown() { } void TargetSelection::MoveLeft() { + assert(battle); if (TargetsMonsters()) { cursor = (cursor + battle->MaxMonsters() - 1) % battle->MaxMonsters(); FindNextEnemy(); @@ -98,6 +101,7 @@ void TargetSelection::MoveLeft() { } void TargetSelection::FindNextEnemy() { + assert(battle); int start(cursor); while (!battle->MonsterPositionOccupied(cursor)) { cursor = (cursor + battle->MaxMonsters() - 1) % battle->MaxMonsters(); diff --git a/src/battle/TargetSelection.h b/src/battle/TargetSelection.h index dc03285..ba53178 100644 --- a/src/battle/TargetSelection.h +++ b/src/battle/TargetSelection.h @@ -1,13 +1,16 @@ #ifndef BATTLE_TARGETSELECTION_H_ #define BATTLE_TARGETSELECTION_H_ -#include "fwd.h" -#include "../common/fwd.h" +namespace common { + class TargetingMode; +} #include namespace battle { +class BattleState; + class TargetSelection { public: diff --git a/src/battle/states/PerformAttacks.cpp b/src/battle/states/PerformAttacks.cpp index fac7cdf..43414eb 100644 --- a/src/battle/states/PerformAttacks.cpp +++ b/src/battle/states/PerformAttacks.cpp @@ -67,13 +67,20 @@ void PerformAttacks::HandleEvents(const Input &input) { battle->CalculateDamage(); - if (battle->CurrentAttack().isMonster) { + if (battle->CurrentAttack().IsMonster()) { Monster &monster(battle->MonsterAt(battle->CurrentAttack().index)); titleBarText = monster.Name(); targetAnimation = AnimationRunner(monster.MeleeAnimation()); moveAnimation = AnimationRunner(monster.AttackAnimation()); monster.SetAnimation(moveAnimation); AddNumberAnimations(battle->MonsterAt(battle->CurrentAttack().index).GetAttackChoice().Selection()); + } else if (battle->CurrentAttack().IsCapsule()) { + Capsule &capsule(battle->GetCapsule()); + titleBarText = capsule.Name(); + targetAnimation = AnimationRunner(capsule.MeleeAnimation()); + moveAnimation = AnimationRunner(capsule.AttackAnimation()); + capsule.SetAnimation(moveAnimation); + AddNumberAnimations(capsule.GetAttackChoice().Selection()); } else { Hero &hero(battle->HeroAt(battle->CurrentAttack().index)); const AttackChoice &ac(battle->HeroAt(battle->CurrentAttack().index).GetAttackChoice()); @@ -122,10 +129,12 @@ void PerformAttacks::HandleEvents(const Input &input) { if (titleBarText) titleBarTimer = GraphicsTimers().StartCountdown(850); if (moveAnimation.Valid()) { moveAnimation.Start(*this); - if (battle->CurrentAttack().isMonster) { + if (battle->CurrentAttack().IsMonster()) { battle->MonsterAt(battle->CurrentAttack().index).SetAnimation(moveAnimation); - } else { + } else if (battle->CurrentAttack().IsHero()) { battle->HeroAt(battle->CurrentAttack().index).SetAnimation(moveAnimation); + } else { + battle->GetCapsule().SetAnimation(moveAnimation); } } if (targetAnimation.Valid()) { @@ -195,7 +204,7 @@ bool PerformAttacks::HasAnimationsRunning() const { void PerformAttacks::ResetAnimation() { if (moveAnimation.Valid()) { moveAnimation.Clear(); - if (!battle->CurrentAttack().isMonster) { + if (!battle->CurrentAttack().IsMonster()) { battle->HeroAt(battle->CurrentAttack().index).GetAnimation().Clear(); } } diff --git a/src/graphics/Animation.cpp b/src/graphics/Animation.cpp index d4a17d9..f55a9aa 100644 --- a/src/graphics/Animation.cpp +++ b/src/graphics/Animation.cpp @@ -1,9 +1,13 @@ #include "Animation.h" #include "Sprite.h" +#include "../app/Application.h" +#include "../app/State.h" #include "../loader/Interpreter.h" #include "../loader/TypeDescription.h" +#include + using loader::FieldDescription; using loader::Interpreter; using loader::TypeDescription; @@ -22,4 +26,69 @@ void Animation::AddFields(TypeDescription &td, const Animation &a, std::ptrdiff_ td.AddField("repeat", FieldDescription(((char *)&a.repeat) - ((char *)&a) - offset, Interpreter::BOOLEAN_ID).SetDescription("whether the animation should start over at the beginning after reaching the last frame")); } + +void AnimationRunner::Start(app::State &ctrl) { + assert(animation); + timer = ctrl.GraphicsTimers().StartInterval(animation->FrameTime()); +} + +void AnimationRunner::Start(app::Application &ctrl) { + assert(animation); + timer = ctrl.GlobalTimers().StartInterval(animation->FrameTime()); +} + +void AnimationRunner::Stop() { + timer = app::Timer(); +} + +bool AnimationRunner::Started() const { + return timer.Started(); +} + +bool AnimationRunner::Running() const { + return animation + && timer.Running() + && (animation->Repeat() + || timer.Iteration() < animation->NumFrames()); +} + +bool AnimationRunner::Finished() const { + return Started() && !Running(); +} + +bool AnimationRunner::JustFinished() const { + return animation + && timer.JustHit() + && timer.Iteration() == animation->NumFrames(); +} + + +void AnimationRunner::Draw(SDL_Surface *dest, geometry::Vector position) const { + GetSprite()->Draw(dest, + position + animation->Offset(Frame()), + animation->Col(Frame()) + ColOffset(), + animation->Row(Frame()) + RowOffset()); +} + +void AnimationRunner::DrawTopRight(SDL_Surface *dest, geometry::Vector position) const { + geometry::Vector offset(-GetSprite()->Width(), 0); + Draw(dest, position + offset); +} + +void AnimationRunner::DrawCenter(SDL_Surface *dest, geometry::Vector position) const { + Draw(dest, position - (GetSprite()->Size() / 2)); +} + +void AnimationRunner::DrawCenterBottom(SDL_Surface *dest, geometry::Vector position) const { + geometry::Vector offset(-GetSprite()->Width() / 2, -GetSprite()->Height()); + Draw(dest, position + offset); +} + +int AnimationRunner::Frame() const { + return Running() + ? ((timer.Iteration() + frameShift) % animation->NumFrames()) + : 0; +} + + } diff --git a/src/graphics/Animation.h b/src/graphics/Animation.h index 5033095..79bfa85 100644 --- a/src/graphics/Animation.h +++ b/src/graphics/Animation.h @@ -1,11 +1,15 @@ #ifndef GRAPHICS_ANIMATION_H_ #define GRAPHICS_ANIMATION_H_ -#include "Sprite.h" -#include "../app/Application.h" -#include "../app/State.h" +namespace app { + class Application; + class State; +} +namespace loader { + class TypeDescription; +} + #include "../app/Timer.h" -#include "../loader/fwd.h" #include "../geometry/Vector.h" #include @@ -13,6 +17,8 @@ namespace graphics { +class Sprite; + class Animation { public: @@ -64,27 +70,13 @@ public: bool Valid() const { return animation; } void Clear() { animation = 0; timer = app::Timer(); } - void Start(app::State &ctrl) { - timer = ctrl.GraphicsTimers().StartInterval(animation->FrameTime()); - } - void Start(app::Application &ctrl) { - timer = ctrl.GlobalTimers().StartInterval(animation->FrameTime()); - } - void Stop() { - timer = app::Timer(); - } - bool Started() const { - return timer.Started(); - } - bool Running() const { - return timer.Running() && (animation->Repeat() || timer.Iteration() < animation->NumFrames()); - } - bool Finished() const { - return Started() && !Running(); - } - bool JustFinished() const { - return timer.JustHit() && timer.Iteration() == animation->NumFrames(); - } + void Start(app::State &ctrl); + void Start(app::Application &ctrl); + void Stop(); + bool Started() const; + bool Running() const; + bool Finished() const; + bool JustFinished() const; const app::Timer &GetTimer() { return timer; } @@ -101,22 +93,12 @@ public: void ChangeSprite(const Sprite *s) { sprite = s; } const Sprite *GetSprite() const { return sprite ? sprite : animation->GetSprite(); } - void Draw(SDL_Surface *dest, geometry::Vector position) const { - GetSprite()->Draw(dest, position + animation->Offset(Frame()), animation->Col(Frame()) + ColOffset(), animation->Row(Frame()) + RowOffset()); - } - void DrawTopRight(SDL_Surface *dest, geometry::Vector position) const { - geometry::Vector offset(-GetSprite()->Width(), 0); - Draw(dest, position + offset); - } - void DrawCenter(SDL_Surface *dest, geometry::Vector position) const { - Draw(dest, position - (GetSprite()->Size() / 2)); - } - void DrawCenterBottom(SDL_Surface *dest, geometry::Vector position) const { - geometry::Vector offset(-GetSprite()->Width() / 2, -GetSprite()->Height()); - Draw(dest, position + offset); - } - - int Frame() const { return Running() ? ((timer.Iteration() + frameShift) % animation->NumFrames()) : 0; } + void Draw(SDL_Surface *dest, geometry::Vector position) const; + void DrawTopRight(SDL_Surface *dest, geometry::Vector position) const; + void DrawCenter(SDL_Surface *dest, geometry::Vector position) const; + void DrawCenterBottom(SDL_Surface *dest, geometry::Vector position) const; + + int Frame() const; private: const Animation *animation; diff --git a/src/graphics/ComplexAnimation.cpp b/src/graphics/ComplexAnimation.cpp index f999c4a..bd2eaf8 100644 --- a/src/graphics/ComplexAnimation.cpp +++ b/src/graphics/ComplexAnimation.cpp @@ -3,12 +3,47 @@ #include "../loader/Interpreter.h" #include "../loader/TypeDescription.h" +using geometry::Vector; using loader::FieldDescription; using loader::Interpreter; using loader::TypeDescription; namespace graphics { +ComplexAnimation::ComplexAnimation() +: frames(0) +, numFrames(0) { + +} + +ComplexAnimation::ComplexAnimation( + const Sprite *sprite, + int frameTime, + bool repeat) +: Animation(sprite, frameTime, repeat) +, frames(0) +, numFrames(0) { + +} + + +int ComplexAnimation::NumFrames() const { + return numFrames; +} + +int ComplexAnimation::Col(int frame) const { + return frames[frame].col; +} + +int ComplexAnimation::Row(int frame) const { + return frames[frame].row; +} + +Vector ComplexAnimation::Offset(int frame) const { + return frames[frame].disposition; +} + + void ComplexAnimation::CreateTypeDescription() { ComplexAnimation ca; Animation *a(&ca); diff --git a/src/graphics/ComplexAnimation.h b/src/graphics/ComplexAnimation.h index f4a5db5..eeeef68 100644 --- a/src/graphics/ComplexAnimation.h +++ b/src/graphics/ComplexAnimation.h @@ -12,9 +12,8 @@ public: static const int TYPE_ID = 402; public: - ComplexAnimation() : frames(0), numFrames(0) { } - ComplexAnimation(const Sprite *sprite, int frameTime, bool repeat = false) - : Animation(sprite, frameTime, repeat), frames(0), numFrames(0) { } + ComplexAnimation(); + ComplexAnimation(const Sprite *sprite, int frameTime, bool repeat = false); public: struct FrameProp { @@ -32,10 +31,10 @@ public: static void Construct(void *); protected: - virtual int NumFrames() const { return numFrames; }; - virtual int Col(int frame) const { return frames[frame].col; } - virtual int Row(int frame) const { return frames[frame].row; } - virtual geometry::Vector Offset(int frame) const { return frames[frame].disposition; } + virtual int NumFrames() const; + virtual int Col(int frame) const; + virtual int Row(int frame) const; + virtual geometry::Vector Offset(int frame) const; private: const FrameProp *frames; diff --git a/src/graphics/SimpleAnimation.cpp b/src/graphics/SimpleAnimation.cpp index baed341..24985f9 100644 --- a/src/graphics/SimpleAnimation.cpp +++ b/src/graphics/SimpleAnimation.cpp @@ -9,6 +9,41 @@ using loader::TypeDescription; namespace graphics { +SimpleAnimation::SimpleAnimation() +: numFrames(0) +, col(0) +, row(0) { + +} + +SimpleAnimation::SimpleAnimation( + const Sprite *sprite, + int frameTime, + int numFrames, + int col, + int row, + bool repeat) +: Animation(sprite, frameTime, repeat) +, numFrames(numFrames) +, col(col) +, row(row) { + +} + + +int SimpleAnimation::NumFrames() const { + return numFrames; +} + +int SimpleAnimation::Col(int frame) const { + return col; +} + +int SimpleAnimation::Row(int frame) const { + return row + frame; +} + + void SimpleAnimation::CreateTypeDescription() { SimpleAnimation sa; Animation *a(&sa); diff --git a/src/graphics/SimpleAnimation.h b/src/graphics/SimpleAnimation.h index 49eff9a..88a41c5 100644 --- a/src/graphics/SimpleAnimation.h +++ b/src/graphics/SimpleAnimation.h @@ -12,10 +12,9 @@ public: static const int TYPE_ID = 408; public: - SimpleAnimation() - : numFrames(0), col(0), row(0) { } - SimpleAnimation(const Sprite *sprite, int frameTime, int numFrames, int col = 0, int row = 0, bool repeat = false) - : Animation(sprite, frameTime, repeat), numFrames(numFrames), col(col), row(row) { } + SimpleAnimation(); + SimpleAnimation(const Sprite *sprite, int frameTime, int numFrames, + int col = 0, int row = 0, bool repeat = false); public: void SetNumFrames(int n) { numFrames = n; } @@ -26,9 +25,9 @@ public: static void Construct(void *); protected: - virtual int NumFrames() const { return numFrames; }; - virtual int Col(int frame) const { return col; } - virtual int Row(int frame) const { return row + frame; } + virtual int NumFrames() const; + virtual int Col(int frame) const; + virtual int Row(int frame) const; private: int numFrames; diff --git a/src/main.cpp b/src/main.cpp index 5934833..53301ce 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -279,17 +279,34 @@ int main(int argc, char **argv) { gameState.heroes[3].MapEntity().SetFlags(Entity::FLAG_NONBLOCKING); gameState.heroes[2].MapEntity().AddFollower(&gameState.heroes[3].MapEntity()); + graphics::Sprite flashSprite(IMG_Load("test-data/flash.png"), 96, 96); + graphics::ComplexAnimation flashAttackAnimation(&flashSprite, 132); + graphics::ComplexAnimation::FrameProp flashAttackFrames[4]; + flashAttackFrames[0] = graphics::ComplexAnimation::FrameProp(0, 1, Vector(0, -16)); + flashAttackFrames[1] = graphics::ComplexAnimation::FrameProp(0, 0, Vector(0, -16)); + flashAttackFrames[2] = graphics::ComplexAnimation::FrameProp(0, 1, Vector(0, -16)); + flashAttackFrames[3] = graphics::ComplexAnimation::FrameProp(0, 0, Vector(0, -16)); + flashAttackAnimation.SetFrames(flashAttackFrames, 4); + Capsule capsule; + capsule.SetName("Flash"); + capsule.SetHealth(5, 5); + capsule.SetLevel(1); + capsule.GetStats().SetAttack(12); + capsule.GetStats().SetDefense(18); + capsule.GetStats().SetStrength(2); + capsule.GetStats().SetAgility(11); + capsule.GetStats().SetIntelligence(16); + capsule.GetStats().SetGut(23); + capsule.GetStats().SetMagicResistance(11); + capsule.SetBattleSprite(&flashSprite); + capsule.SetAttackAnimation(&flashAttackAnimation); + capsule.SetMeleeAnimation(gameState.heroes[0].MeleeAnimation()); + InitScreen screen(width, height); app::State *state(0); if (battle) { - graphics::Sprite flashSprite(IMG_Load("test-data/flash.png"), 96, 96); - Capsule capsule; - capsule.SetName("Flash"); - capsule.SetHealth(13, 13); - capsule.SetBattleSprite(&flashSprite); - BattleState *battleState(new BattleState(&gameConfig, bg, &monstersLayout)); battleState->AddMonster(monster); battleState->AddMonster(monster); diff --git a/src/menu/ConfigMenu.cpp b/src/menu/ConfigMenu.cpp index 9c903eb..6d6e2d1 100644 --- a/src/menu/ConfigMenu.cpp +++ b/src/menu/ConfigMenu.cpp @@ -2,6 +2,8 @@ #include "PartyMenu.h" #include "Resources.h" +#include "../app/Application.h" +#include "../app/Input.h" #include "../common/GameConfig.h" #include "../common/GameState.h" #include "../graphics/Font.h" diff --git a/src/menu/InventoryMenu.cpp b/src/menu/InventoryMenu.cpp index eb74ab8..c980f97 100644 --- a/src/menu/InventoryMenu.cpp +++ b/src/menu/InventoryMenu.cpp @@ -2,6 +2,7 @@ #include "PartyMenu.h" #include "Resources.h" +#include "../app/Application.h" #include "../app/Input.h" #include "../common/GameConfig.h" #include "../common/GameState.h" diff --git a/src/menu/ScenarioMenu.cpp b/src/menu/ScenarioMenu.cpp index 9896d86..2c317bb 100644 --- a/src/menu/ScenarioMenu.cpp +++ b/src/menu/ScenarioMenu.cpp @@ -2,6 +2,7 @@ #include "PartyMenu.h" #include "Resources.h" +#include "../app/Application.h" #include "../app/Input.h" #include "../common/GameConfig.h" #include "../common/GameState.h" diff --git a/src/menu/SpellMenu.cpp b/src/menu/SpellMenu.cpp index b42a39a..bb66d3c 100644 --- a/src/menu/SpellMenu.cpp +++ b/src/menu/SpellMenu.cpp @@ -3,6 +3,7 @@ #include "HeroStatus.h" #include "PartyMenu.h" #include "Resources.h" +#include "../app/Application.h" #include "../app/Input.h" #include "../common/GameConfig.h" #include "../common/GameState.h" diff --git a/test-data/flash.png b/test-data/flash.png index 298ff83..85fd123 100644 Binary files a/test-data/flash.png and b/test-data/flash.png differ