]> git.localhorst.tv Git - l2e.git/commitdiff
added complex attack and spell animations
authorDaniel Karbach <daniel.karbach@localhorst.tv>
Sun, 12 Aug 2012 00:15:03 +0000 (02:15 +0200)
committerDaniel Karbach <daniel.karbach@localhorst.tv>
Sun, 12 Aug 2012 00:15:03 +0000 (02:15 +0200)
src/battle/BattleState.cpp
src/battle/BattleState.h
src/battle/Hero.cpp
src/battle/Hero.h
src/battle/states/PerformAttacks.cpp
src/main.cpp
test-data/dekar.png
test-data/guy.png
test-data/maxim.png
test-data/selan.png

index 1b4401065e9d2c17cc1e8961c8941e1dc00d7c08..03cbb213623b26bf9cd0383dcfd2a26f7c95b9ad 100644 (file)
@@ -266,8 +266,10 @@ void BattleState::RenderMonsters(SDL_Surface *screen, const Vector<int> &offset)
 
 void BattleState::RenderHeroes(SDL_Surface *screen, const Vector<int> &offset) {
        for (int i(0); i < numHeroes; ++i) {
-               if (HeroAnimationAt(i).Running()) {
-                       HeroAnimationAt(i).DrawCenterBottom(screen, heroesPositions[i] + offset);
+               if (heroes[i].AttackAnimation() && heroes[i].AttackAnimation()->Running()) {
+                       heroes[i].AttackAnimation()->DrawCenterBottom(screen, heroesPositions[i] + offset);
+               } else if (heroes[i].SpellAnimation() && heroes[i].SpellAnimation()->Running()) {
+                       heroes[i].SpellAnimation()->DrawCenterBottom(screen, heroesPositions[i] + offset);
                } else {
                        int row(heroes[i].Health() > 0 ? 0 : 2);
                        heroes[i].Sprite()->DrawCenterBottom(screen, heroesPositions[i] + offset, 1, row);
index 77e2b5dbdfa214db81bcd6a8f1313b18e05ce49f..40dd51d9f671d8b79fb8a9c63d72d2586ad62c14 100644 (file)
@@ -19,8 +19,8 @@
 #include "../app/State.h"
 #include "../geometry/Point.h"
 #include "../geometry/Vector.h"
+#include "../graphics/Animation.h"
 #include "../graphics/Menu.h"
-#include "../graphics/SimpleAnimation.h"
 
 #include <vector>
 #include <SDL.h>
@@ -97,9 +97,6 @@ public:
        Monster &MonsterAt(int index) { return monsters[index]; }
        const Monster &MonsterAt(int index) const { return monsters[index]; }
 
-       graphics::SimpleAnimation &HeroAnimationAt(int index) { return heroAnimations[index]; }
-       const graphics::SimpleAnimation &HeroAnimationAt(int index) const { return heroAnimations[index]; }
-
        const HeroTag &HeroTagAt(int index) const { return heroTags[index]; }
        const geometry::Point<int> &HeroTagPositionAt(int index) const { return heroTagPositions[index]; }
 
@@ -153,7 +150,6 @@ private:
        std::vector<geometry::Point<int> > heroesPositions;
        std::vector<Monster> monsters;
        Hero heroes[4];
-       graphics::SimpleAnimation heroAnimations[4];
        graphics::Menu<const common::Spell *> spellMenus[4];
        graphics::Menu<const common::Item *> itemMenu;
        graphics::Menu<const common::Item *> ikariMenus[4];
index 4bcc6d30175b9372170288cf0d3c3e6551d1b2da..ff411137773ee72a21fa20ec54ba5115f3cdd914 100644 (file)
@@ -20,6 +20,9 @@ Hero::Hero()
 , ring(0)
 , jewel(0)
 
+, attackAnimation(0)
+, spellAnimation(0)
+
 , maxHealth(0)
 , health(0)
 , maxMana(0)
index 11f1e332400eeed439b8fe021931af1dcd265d88..97a21c23377d177d855db1bbdcda0194266bbf24 100644 (file)
@@ -15,7 +15,10 @@ namespace common {
        class Item;
        class Spell;
 }
-namespace graphics { class Sprite; }
+namespace graphics {
+       class Animation;
+       class Sprite;
+}
 
 namespace battle {
 
@@ -66,10 +69,10 @@ public:
        bool HasRing() const { return ring; }
        bool HasJewel() const { return jewel; }
 
-       int AttackFrames() const { return attackFrames; }
-       int AttackFrameTime() const { return attackFrameTime; }
-       int SpellFrames() const { return spellFrames; }
-       int SpellFrameTime() const { return spellFrameTime; }
+       graphics::Animation *AttackAnimation() { return attackAnimation; }
+       const graphics::Animation *AttackAnimation() const { return attackAnimation; }
+       graphics::Animation *SpellAnimation() { return spellAnimation; }
+       const graphics::Animation *SpellAnimation() const { return spellAnimation; }
 
 // temporary setters until loader is implemented
 public:
@@ -92,8 +95,8 @@ public:
 
        void AddSpell(const common::Spell *s) { spells.push_back(s); }
 
-       void SetAttackFrames(int num, int time) { attackFrames = num; attackFrameTime = time; }
-       void SetSpellFrames(int num, int time) { spellFrames = num; spellFrameTime = time; }
+       void SetAttackAnimation(graphics::Animation *a) { attackAnimation = a; }
+       void SetSpellAnimation(graphics::Animation *a) { spellAnimation = a; }
 
 private:
        const char *name;
@@ -106,14 +109,12 @@ private:
        const common::Item *ring;
        const common::Item *jewel;
 
+       graphics::Animation *attackAnimation;
+       graphics::Animation *spellAnimation;
+
        // TODO: vector does not seem to be a good choice
        std::vector<const common::Spell *> spells;
 
-       int attackFrames;
-       int attackFrameTime;
-       int spellFrames;
-       int spellFrameTime;
-
        Uint16 maxHealth, health;
        Uint16 maxMana, mana;
 
index c34e1144cdc6e4e54de9ca9ec1b6130bb6dafbd6..93a09ef77d8baa79726a59149880a1518364451f 100644 (file)
@@ -17,9 +17,9 @@
 #include "../../common/Spell.h"
 #include "../../geometry/operators.h"
 #include "../../geometry/Point.h"
+#include "../../graphics/Animation.h"
 #include "../../graphics/Font.h"
 #include "../../graphics/Frame.h"
-#include "../../graphics/SimpleAnimation.h"
 
 #include <cstring>
 
@@ -27,13 +27,11 @@ using app::Application;
 using app::Input;
 using geometry::Point;
 using geometry::Vector;
-using graphics::SimpleAnimation;
 
 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) {
@@ -69,7 +67,12 @@ void PerformAttacks::HandleEvents(const Input &input) {
                                }
                        } else {
                                if (cursor == 0) {
-                                       battle->HeroAnimationAt(battle->NumHeroes() - 1).Stop();
+                                       if (battle->HeroAt(battle->NumHeroes() - 1).AttackAnimation()) {
+                                               battle->HeroAt(battle->NumHeroes() - 1).AttackAnimation()->Stop();
+                                       }
+                                       if (battle->HeroAt(battle->NumHeroes() - 1).SpellAnimation()) {
+                                               battle->HeroAt(battle->NumHeroes() - 1).SpellAnimation()->Stop();
+                                       }
                                }
                                titleBarText = battle->MonsterAt(cursor).Name();
                        }
@@ -80,31 +83,27 @@ void PerformAttacks::HandleEvents(const Input &input) {
 
                                switch (ac.GetType()) {
                                        case AttackChoice::SWORD:
-                                               battle->HeroAnimationAt(cursor) = SimpleAnimation(
-                                                               battle->HeroAt(cursor).Sprite(),
-                                                               battle->HeroAt(cursor).AttackFrameTime(),
-                                                               battle->HeroAt(cursor).AttackFrames(), 2);
+                                               if (battle->HeroAt(cursor).AttackAnimation()) {
+                                                       battle->HeroAt(cursor).AttackAnimation()->Start(*this);
+                                               }
                                                break;
                                        case AttackChoice::MAGIC:
-                                               battle->HeroAnimationAt(cursor) = SimpleAnimation(
-                                                               battle->HeroAt(cursor).Sprite(),
-                                                               battle->HeroAt(cursor).SpellFrameTime(),
-                                                               battle->HeroAt(cursor).SpellFrames(), 3);
+                                               if (battle->HeroAt(cursor).SpellAnimation()) {
+                                                       battle->HeroAt(cursor).SpellAnimation()->Start(*this);
+                                               }
                                                break;
                                        case AttackChoice::DEFEND:
                                                break;
                                        case AttackChoice::IKARI:
                                                if (ac.GetItem()->HasIkari()) {
                                                        if (ac.GetItem()->GetIkari()->IsMagical()) {
-                                                               battle->HeroAnimationAt(cursor) = SimpleAnimation(
-                                                                               battle->HeroAt(cursor).Sprite(),
-                                                                               battle->HeroAt(cursor).SpellFrameTime(),
-                                                                               battle->HeroAt(cursor).SpellFrames(), 3);
+                                                               if (battle->HeroAt(cursor).SpellAnimation()) {
+                                                                       battle->HeroAt(cursor).SpellAnimation()->Start(*this);
+                                                               }
                                                        } else {
-                                                               battle->HeroAnimationAt(cursor) = SimpleAnimation(
-                                                                               battle->HeroAt(cursor).Sprite(),
-                                                                               battle->HeroAt(cursor).AttackFrameTime(),
-                                                                               battle->HeroAt(cursor).AttackFrames(), 2);
+                                                               if (battle->HeroAt(cursor).AttackAnimation()) {
+                                                                       battle->HeroAt(cursor).AttackAnimation()->Start(*this);
+                                                               }
                                                        }
                                                }
                                                break;
@@ -113,7 +112,6 @@ void PerformAttacks::HandleEvents(const Input &input) {
                                        case AttackChoice::UNDECIDED:
                                                break;
                                }
-                               battle->HeroAnimationAt(cursor).Start(*this);
 
                                ++cursor;
                                if (cursor == battle->NumHeroes()) {
@@ -122,7 +120,12 @@ void PerformAttacks::HandleEvents(const Input &input) {
                                }
                        } else {
                                if (cursor > 0) {
-                                       battle->HeroAnimationAt(cursor - 1).Stop();
+                                       if (battle->HeroAt(cursor - 1).AttackAnimation()) {
+                                               battle->HeroAt(cursor - 1).AttackAnimation()->Stop();
+                                       }
+                                       if (battle->HeroAt(cursor - 1).SpellAnimation()) {
+                                               battle->HeroAt(cursor - 1).SpellAnimation()->Stop();
+                                       }
                                }
                                switch (ac.GetType()) {
                                        case AttackChoice::SWORD:
index 730c5aa01cee254d90a08f7a7ca46df43dc34bd9..aff39b5fee7c6145b17eb51809d7c841803a2c9d 100644 (file)
@@ -17,6 +17,8 @@
 #include "common/Item.h"
 #include "common/Spell.h"
 #include "geometry/Point.h"
+#include "geometry/Vector.h"
+#include "graphics/ComplexAnimation.h"
 #include "graphics/Font.h"
 #include "graphics/Frame.h"
 #include "graphics/Gauge.h"
@@ -42,6 +44,8 @@ using common::Inventory;
 using common::Item;
 using common::Spell;
 using geometry::Point;
+using geometry::Vector;
+using graphics::ComplexAnimation;
 using graphics::Font;
 using graphics::Frame;
 using graphics::Gauge;
@@ -97,8 +101,19 @@ int main(int argc, char **argv) {
                maxim.SetMaxMana(20);
                maxim.SetMana(20);
                maxim.SetIP(0);
-               maxim.SetAttackFrames(3, 125);
-               maxim.SetSpellFrames(2, 125);
+               ComplexAnimation maximAttackAnimation(&maximSprite, 30);
+               maximAttackAnimation.AddFrames(2, 0, Vector<int>(), 2);
+               maximAttackAnimation.AddFrames(2, 0, Vector<int>(4, 0), 2);
+               maximAttackAnimation.AddFrame(2, 1, Vector<int>(4, 0));
+               maximAttackAnimation.AddFrames(2, 1, Vector<int>(-2, 0), 2);
+               maximAttackAnimation.AddFrame(2, 1, Vector<int>(-8, 0));
+               maximAttackAnimation.AddFrames(2, 2, Vector<int>(-8, 0), 2);
+               maximAttackAnimation.AddFrame(2, 2, Vector<int>(-4, 0));
+               maxim.SetAttackAnimation(&maximAttackAnimation);
+               ComplexAnimation maximSpellAnimation(&maximSprite, 150);
+               maximSpellAnimation.AddFrames(3, 0, Vector<int>(), 2);
+               maximSpellAnimation.AddFrame(3, 1);
+               maxim.SetSpellAnimation(&maximSpellAnimation);
 
                SDL_Surface *selanImg(IMG_Load("test-data/selan.png"));
                Sprite selanSprite(selanImg, 64, 64);
@@ -111,8 +126,24 @@ int main(int argc, char **argv) {
                selan.SetMaxMana(23);
                selan.SetMana(23);
                selan.SetIP(1);
-               selan.SetAttackFrames(3, 125);
-               selan.SetSpellFrames(4, 125);
+               ComplexAnimation selanAttackAnimation(&selanSprite, 30);
+               selanAttackAnimation.AddFrames(1, 0, Vector<int>(4, 0), 2);
+               selanAttackAnimation.AddFrame(1, 0, Vector<int>(8, 2));
+               selanAttackAnimation.AddFrame(2, 0, Vector<int>(10, 4));
+               selanAttackAnimation.AddFrame(2, 0, Vector<int>(14, 4));
+               selanAttackAnimation.AddFrames(2, 0, Vector<int>(12, 2), 3);
+               selanAttackAnimation.AddFrames(2, 1, Vector<int>(14, 2), 2);
+               selanAttackAnimation.AddFrame(2, 1, Vector<int>(2, 0));
+               selanAttackAnimation.AddFrame(2, 2, Vector<int>(-2, -4));
+               selanAttackAnimation.AddFrame(2, 2, Vector<int>(-8, -8));
+               selanAttackAnimation.AddFrame(2, 2);
+               selan.SetAttackAnimation(&selanAttackAnimation);
+               ComplexAnimation selanSpellAnimation(&selanSprite, 30);
+               selanAttackAnimation.AddFrames(2, 0, Vector<int>(), 3);
+               selanAttackAnimation.AddFrames(2, 1, Vector<int>(), 2);
+               selanAttackAnimation.AddFrames(2, 2, Vector<int>(), 3);
+               selanAttackAnimation.AddFrames(2, 3, Vector<int>(), 2);
+               selan.SetSpellAnimation(&selanSpellAnimation);
 
                SDL_Surface *guyImg(IMG_Load("test-data/guy.png"));
                Sprite guySprite(guyImg, 64, 64);
@@ -125,8 +156,18 @@ int main(int argc, char **argv) {
                guy.SetMaxMana(0);
                guy.SetMana(0);
                guy.SetIP(254);
-               guy.SetAttackFrames(3, 125);
-               guy.SetSpellFrames(0, 125);
+               ComplexAnimation guyAttackAnimation(&guySprite, 30);
+               guyAttackAnimation.AddFrames(1, 0, Vector<int>(-4, 0), 2);
+               guyAttackAnimation.AddFrames(1, 0, Vector<int>(-8, 0), 2);
+               guyAttackAnimation.AddFrames(2, 0, Vector<int>(-8, 0), 2);
+               guyAttackAnimation.AddFrame(2, 0, Vector<int>(-4, 0));
+               guyAttackAnimation.AddFrames(2, 0, Vector<int>(), 2);
+               guyAttackAnimation.AddFrame(2, 1);
+               guyAttackAnimation.AddFrame(2, 1, Vector<int>(4, 0));
+               guyAttackAnimation.AddFrame(2, 1, Vector<int>(10, 0));
+               guyAttackAnimation.AddFrame(2, 2, Vector<int>(10, 0));
+               guyAttackAnimation.AddFrame(2, 2);
+               guy.SetAttackAnimation(&guyAttackAnimation);
 
                SDL_Surface *dekarImg(IMG_Load("test-data/dekar.png"));
                Sprite dekarSprite(dekarImg, 64, 64);
@@ -139,8 +180,22 @@ int main(int argc, char **argv) {
                dekar.SetMaxMana(0);
                dekar.SetMana(0);
                dekar.SetIP(255);
-               dekar.SetAttackFrames(3, 125);
-               dekar.SetSpellFrames(3, 125);
+               ComplexAnimation dekarAttackAnimation(&dekarSprite, 30);
+               dekarAttackAnimation.AddFrame(1, 0, Vector<int>(4, 0));
+               dekarAttackAnimation.AddFrame(1, 0, Vector<int>(8, 2));
+               dekarAttackAnimation.AddFrame(2, 0, Vector<int>(12, 4));
+               dekarAttackAnimation.AddFrame(2, 0, Vector<int>(16, 4));
+               dekarAttackAnimation.AddFrames(2, 0, Vector<int>(10, 2), 4);
+               dekarAttackAnimation.AddFrame(2, 1, Vector<int>(6, 2));
+               dekarAttackAnimation.AddFrame(2, 1, Vector<int>());
+               dekarAttackAnimation.AddFrame(2, 2, Vector<int>(-2, 0));
+               dekarAttackAnimation.AddFrames(2, 2, Vector<int>(0, 0), 3);
+               dekar.SetAttackAnimation(&dekarAttackAnimation);
+               ComplexAnimation dekarSpellAnimation(&dekarSprite, 30);
+               dekarSpellAnimation.AddFrames(2, 0, Vector<int>(), 6);
+               dekarSpellAnimation.AddFrames(2, 1, Vector<int>(), 2);
+               dekarSpellAnimation.AddFrames(2, 2, Vector<int>(), 3);
+               dekar.SetSpellAnimation(&dekarSpellAnimation);
 
                battle::Resources battleRes;
 
index 5671f49445569258b32ad3b11abf9be35b6a1ebb..0f75139577da94a95eaf2013c53ec014cc402740 100644 (file)
Binary files a/test-data/dekar.png and b/test-data/dekar.png differ
index a292ec1b859ab53dbdd6d376da6b46e0ee6e0082..fc9330fe0c14b36909b64c62e97d477d2f25bd02 100644 (file)
Binary files a/test-data/guy.png and b/test-data/guy.png differ
index bb195c1bec00a87b2878a2ee94e32651e8c311e7..609651099ebf37139472c7db99c32d7a4fc239d6 100644 (file)
Binary files a/test-data/maxim.png and b/test-data/maxim.png differ
index 7da4e59b7e32c4475361277a782ba35d3d0bb22a..72cce66817f10bd434819df22f8e0777b44b72e7 100644 (file)
Binary files a/test-data/selan.png and b/test-data/selan.png differ