]> git.localhorst.tv Git - l2e.git/commitdiff
added capsule attack/animation handling
authorDaniel Karbach <daniel.karbach@localhorst.tv>
Sun, 2 Dec 2012 18:49:03 +0000 (19:49 +0100)
committerDaniel Karbach <daniel.karbach@localhorst.tv>
Sun, 2 Dec 2012 19:02:35 +0000 (20:02 +0100)
also revamped animation related code for debugability

20 files changed:
src/battle/AttackChoice.h
src/battle/BattleState.cpp
src/battle/BattleState.h
src/battle/Capsule.h
src/battle/NumberAnimation.cpp
src/battle/TargetSelection.cpp
src/battle/TargetSelection.h
src/battle/states/PerformAttacks.cpp
src/graphics/Animation.cpp
src/graphics/Animation.h
src/graphics/ComplexAnimation.cpp
src/graphics/ComplexAnimation.h
src/graphics/SimpleAnimation.cpp
src/graphics/SimpleAnimation.h
src/main.cpp
src/menu/ConfigMenu.cpp
src/menu/InventoryMenu.cpp
src/menu/ScenarioMenu.cpp
src/menu/SpellMenu.cpp
test-data/flash.png

index 8577976ce708d6eeb16a13fe752e6998af54df9c..b73e4203b54ef9f710867b5008b3bd636dc36e82 100644 (file)
@@ -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 {
 
index 9830e8c6a0b976f41f26642f024d34d2032e6e6e..0171e1480f56a7d52b905a86e577525d0a2597a0 100644 (file)
@@ -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<Monster>::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();
 }
 
index 3a9500c5d5228d41c2bd71ba42a27d593c41a4a3..1c994e4f88a664c2d572173fd79c156d1daf0687 100644 (file)
@@ -78,6 +78,8 @@ public:
        const HeroTag &HeroTagAt(int index) const { assert(index >= 0 && index < NumHeroes()); return heroTags[index]; }
        const geometry::Vector<int> &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;
 
index c16196c6339b7fd7d9246825d9cbbad91ab54394..c5050f7be59548da08076876132139c486f8e0f2 100644 (file)
@@ -9,9 +9,6 @@
 #include "../graphics/fwd.h"
 #include "../graphics/Menu.h"
 
-#include <vector>
-#include <SDL.h>
-
 namespace battle {
 
 class Capsule {
index 166ace69f411db14cda4d1ae7cbecdbb5cf51d1a..63d16562f1324822d8c8eac50aa6580b54e88611 100644 (file)
@@ -1,6 +1,7 @@
 #include "NumberAnimation.h"
 
 #include "../geometry/Vector.h"
+#include "../graphics/Sprite.h"
 
 using app::State;
 using geometry::Vector;
index 42a88e4673b0444129fac3587564f090a578ee55..961f57cf845cdf703014c83345dc569803a231f9 100644 (file)
@@ -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();
index dc03285ced2c7884b8f67bdb412d1c896cbabe13..ba5317899cfeb6ef63196b9d61de74d5975da659 100644 (file)
@@ -1,13 +1,16 @@
 #ifndef BATTLE_TARGETSELECTION_H_
 #define BATTLE_TARGETSELECTION_H_
 
-#include "fwd.h"
-#include "../common/fwd.h"
+namespace common {
+       class TargetingMode;
+}
 
 #include <vector>
 
 namespace battle {
 
+class BattleState;
+
 class TargetSelection {
 
 public:
index fac7cdf855aa42a4c8422f38e5ebd715afd52608..43414eb89a60d86e7964ad2f63861da7818f5b8e 100644 (file)
@@ -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();
                }
        }
index d4a17d950e127ed0f0316c37b0bd2ce8dba5bd58..f55a9aa9fc6520b7c46e1532f8c83fccd9dece55 100644 (file)
@@ -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 <cassert>
+
 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<Uint32>();
+}
+
+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<int> 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<int> position) const {
+       geometry::Vector<int> offset(-GetSprite()->Width(), 0);
+       Draw(dest, position + offset);
+}
+
+void AnimationRunner::DrawCenter(SDL_Surface *dest, geometry::Vector<int> position) const {
+       Draw(dest, position - (GetSprite()->Size() / 2));
+}
+
+void AnimationRunner::DrawCenterBottom(SDL_Surface *dest, geometry::Vector<int> position) const {
+       geometry::Vector<int> offset(-GetSprite()->Width() / 2, -GetSprite()->Height());
+       Draw(dest, position + offset);
+}
+
+int AnimationRunner::Frame() const {
+       return Running()
+                       ? ((timer.Iteration() + frameShift) % animation->NumFrames())
+                       : 0;
+}
+
+
 }
index 50330957ab9d28412cb1314c70596f86d75ead1f..79bfa852b887f02316afad317a5bfdd912348eb5 100644 (file)
@@ -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 <memory>
@@ -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<Uint32>(); }
 
-       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<Uint32>();
-       }
-       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<Uint32> &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<int> position) const {
-               GetSprite()->Draw(dest, position + animation->Offset(Frame()), animation->Col(Frame()) + ColOffset(), animation->Row(Frame()) + RowOffset());
-       }
-       void DrawTopRight(SDL_Surface *dest, geometry::Vector<int> position) const {
-               geometry::Vector<int> offset(-GetSprite()->Width(), 0);
-               Draw(dest, position + offset);
-       }
-       void DrawCenter(SDL_Surface *dest, geometry::Vector<int> position) const {
-               Draw(dest, position - (GetSprite()->Size() / 2));
-       }
-       void DrawCenterBottom(SDL_Surface *dest, geometry::Vector<int> position) const {
-               geometry::Vector<int> 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<int> position) const;
+       void DrawTopRight(SDL_Surface *dest, geometry::Vector<int> position) const;
+       void DrawCenter(SDL_Surface *dest, geometry::Vector<int> position) const;
+       void DrawCenterBottom(SDL_Surface *dest, geometry::Vector<int> position) const;
+
+       int Frame() const;
 
 private:
        const Animation *animation;
index f999c4af18f748d7129e71056074aa40b49e586b..bd2eaf8732b7044b28a1d770d87539301a4f474a 100644 (file)
@@ -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<int> ComplexAnimation::Offset(int frame) const {
+       return frames[frame].disposition;
+}
+
+
 void ComplexAnimation::CreateTypeDescription() {
        ComplexAnimation ca;
        Animation *a(&ca);
index f4a5db575d8f657809ffeaf3684b0f7fd2d6f12c..eeeef680d37b558a8a06ebaa226c2b0d9d85ed4d 100644 (file)
@@ -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<int> 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<int> Offset(int frame) const;
 
 private:
        const FrameProp *frames;
index baed3419188b2f393e0e27ade3d3b56f7e38f0f3..24985f91ebb12e5db89143389f29a29a71f2d4d8 100644 (file)
@@ -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);
index 49eff9a79bc5c5385cc8c2456fc912538c94691d..88a41c5ba52e859137549e5d68737beacf340264 100644 (file)
@@ -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;
index 59348338391daea0d5c6ea5fdb1578fdd4f32fe3..53301ce5f5c785fa7c97d6d49f047936fa35e91c 100644 (file)
@@ -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<int>(0, -16));
+               flashAttackFrames[1] = graphics::ComplexAnimation::FrameProp(0, 0, Vector<int>(0, -16));
+               flashAttackFrames[2] = graphics::ComplexAnimation::FrameProp(0, 1, Vector<int>(0, -16));
+               flashAttackFrames[3] = graphics::ComplexAnimation::FrameProp(0, 0, Vector<int>(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);
index 9c903eb607ee3893b50032313050f312ae6d19c0..6d6e2d12543e51a8e47f644aa064d85b7da02df7 100644 (file)
@@ -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"
index eb74ab8b5ea899a5220c2e959a5c37f92c3666c1..c980f9719a3c120e0097f5a8c19bcb63cbdced90 100644 (file)
@@ -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"
index 9896d8605ee3b55019e449cb09be3a680344bceb..2c317bb29c158eaf77daeec8a61607830ba8eb84 100644 (file)
@@ -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"
index b42a39afa04d4724a3385282fe7d02545a5c9dd6..bb66d3c6fcbddff09d6ae5187a0c2b72e3b540fa 100644 (file)
@@ -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"
index 298ff836a19981f49bd3131349133de186eff9f4..85fd123eb0b6dc04365fbeb63d569be2f3869385 100644 (file)
Binary files a/test-data/flash.png and b/test-data/flash.png differ