]> git.localhorst.tv Git - l2e.git/commitdiff
added simple attack animations
authorDaniel Karbach <daniel.karbach@localhorst.tv>
Sat, 11 Aug 2012 21:51:08 +0000 (23:51 +0200)
committerDaniel Karbach <daniel.karbach@localhorst.tv>
Sat, 11 Aug 2012 21:51:08 +0000 (23:51 +0200)
src/app/Timer.h
src/battle/BattleState.cpp
src/battle/BattleState.h
src/battle/Hero.h
src/battle/states/PerformAttacks.cpp
src/graphics/Animation.h
src/main.cpp

index b7711d679481746e8be3c96d41a28e7fd3260770..2d6326f76576c582bb36d2c49a3ee49e4cbdb2ed 100644 (file)
@@ -94,6 +94,7 @@ public:
 public:
        void Update(Time delta) {
                for (typename std::list<TimerData<Time> >::iterator i(data.begin()), end(data.end()); i != end;) {
+                       TimerData<Time> &t(*i);
                        if (i->target > 0) {
                                Time intervalTime(i->time);
                                while (intervalTime > i->target) intervalTime -= i->target;
index 6aeaae5f7e4ee98ac845c79c26f558abefba03c4..1b4401065e9d2c17cc1e8961c8941e1dc00d7c08 100644 (file)
@@ -266,8 +266,12 @@ 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) {
-               int row(heroes[i].Health() > 0 ? 0 : 2);
-               heroes[i].Sprite()->DrawCenterBottom(screen, heroesPositions[i] + offset, 1, row);
+               if (HeroAnimationAt(i).Running()) {
+                       HeroAnimationAt(i).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 b491af862c99485c080c156836d3a2c9e7413b26..736e2c17ad3f15dbf733220728b53fce1df6a5c8 100644 (file)
@@ -19,6 +19,7 @@
 #include "../app/State.h"
 #include "../geometry/Point.h"
 #include "../geometry/Vector.h"
+#include "../graphics/Animation.h"
 #include "../graphics/Menu.h"
 
 #include <vector>
@@ -96,6 +97,9 @@ public:
        Monster &MonsterAt(int index) { return monsters[index]; }
        const Monster &MonsterAt(int index) const { return monsters[index]; }
 
+       graphics::Animation &HeroAnimationAt(int index) { return heroAnimations[index]; }
+       const graphics::Animation &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]; }
 
@@ -149,6 +153,7 @@ private:
        std::vector<geometry::Point<int> > heroesPositions;
        std::vector<Monster> monsters;
        Hero heroes[4];
+       graphics::Animation heroAnimations[4];
        graphics::Menu<const common::Spell *> spellMenus[4];
        graphics::Menu<const common::Item *> itemMenu;
        graphics::Menu<const common::Item *> ikariMenus[4];
index 3274fe21b64d7a2cb373d9a12bce7c061a77abff..11f1e332400eeed439b8fe021931af1dcd265d88 100644 (file)
@@ -67,7 +67,9 @@ public:
        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; }
 
 // temporary setters until loader is implemented
 public:
@@ -90,8 +92,8 @@ public:
 
        void AddSpell(const common::Spell *s) { spells.push_back(s); }
 
-       void SetAttackFrames(int num) { attackFrames = num; }
-       void SetSpellFrames(int num) { spellFrames = num; }
+       void SetAttackFrames(int num, int time) { attackFrames = num; attackFrameTime = time; }
+       void SetSpellFrames(int num, int time) { spellFrames = num; spellFrameTime = time; }
 
 private:
        const char *name;
@@ -108,7 +110,9 @@ private:
        std::vector<const common::Spell *> spells;
 
        int attackFrames;
+       int attackFrameTime;
        int spellFrames;
+       int spellFrameTime;
 
        Uint16 maxHealth, health;
        Uint16 maxMana, mana;
index 5906650e0418a42949ed44bb26ffaf3e697bd821..09366d4d3ec3b642e1002eb13522fa82bc590553 100644 (file)
@@ -17,6 +17,7 @@
 #include "../../common/Spell.h"
 #include "../../geometry/operators.h"
 #include "../../geometry/Point.h"
+#include "../../graphics/Animation.h"
 #include "../../graphics/Font.h"
 #include "../../graphics/Frame.h"
 
@@ -26,6 +27,7 @@ using app::Application;
 using app::Input;
 using geometry::Point;
 using geometry::Vector;
+using graphics::Animation;
 
 namespace battle {
 
@@ -66,18 +68,62 @@ void PerformAttacks::HandleEvents(const Input &input) {
                                        ctrl->PopState();
                                }
                        } else {
+                               if (cursor == 0) {
+                                       battle->HeroAnimationAt(battle->NumHeroes() - 1).Stop();
+                               }
                                titleBarText = battle->MonsterAt(cursor).Name();
                        }
                } else {
+                       const AttackChoice &ac(battle->AttackChoiceAt(cursor));
                        if (titleBarText) {
                                titleBarText = 0;
+
+                               switch (ac.GetType()) {
+                                       case AttackChoice::SWORD:
+                                               battle->HeroAnimationAt(cursor) = Animation(
+                                                               battle->HeroAt(cursor).Sprite(),
+                                                               battle->HeroAt(cursor).AttackFrameTime(),
+                                                               battle->HeroAt(cursor).AttackFrames(), 2);
+                                               break;
+                                       case AttackChoice::MAGIC:
+                                               battle->HeroAnimationAt(cursor) = Animation(
+                                                               battle->HeroAt(cursor).Sprite(),
+                                                               battle->HeroAt(cursor).SpellFrameTime(),
+                                                               battle->HeroAt(cursor).SpellFrames(), 3);
+                                               break;
+                                       case AttackChoice::DEFEND:
+                                               break;
+                                       case AttackChoice::IKARI:
+                                               if (ac.GetItem()->HasIkari()) {
+                                                       if (ac.GetItem()->GetIkari()->IsMagical()) {
+                                                               battle->HeroAnimationAt(cursor) = Animation(
+                                                                               battle->HeroAt(cursor).Sprite(),
+                                                                               battle->HeroAt(cursor).SpellFrameTime(),
+                                                                               battle->HeroAt(cursor).SpellFrames(), 3);
+                                                       } else {
+                                                               battle->HeroAnimationAt(cursor) = Animation(
+                                                                               battle->HeroAt(cursor).Sprite(),
+                                                                               battle->HeroAt(cursor).AttackFrameTime(),
+                                                                               battle->HeroAt(cursor).AttackFrames(), 2);
+                                                       }
+                                               }
+                                               break;
+                                       case AttackChoice::ITEM:
+                                               break;
+                                       case AttackChoice::UNDECIDED:
+                                               break;
+                               }
+                               battle->HeroAnimationAt(cursor).Start(*this);
+
                                ++cursor;
                                if (cursor == battle->NumHeroes()) {
                                        cursor = 0;
                                        monsters = true;
                                }
                        } else {
-                               const AttackChoice &ac(battle->AttackChoiceAt(cursor));
+                               if (cursor > 0) {
+                                       battle->HeroAnimationAt(cursor - 1).Stop();
+                               }
                                switch (ac.GetType()) {
                                        case AttackChoice::SWORD:
                                                titleBarText = battle->HeroAt(cursor).HasWeapon() ? battle->HeroAt(cursor).Weapon()->Name() : "Gauntlet";
index fc9de19c352f36f898a06a74cdb285cc146d7eb3..146184c865726f3f5c1db3842e7b6530b201b6d0 100644 (file)
@@ -42,6 +42,9 @@ public:
        void Draw(SDL_Surface *dest, geometry::Point<int> position) {
                sprite->Draw(dest, position, col, Running() ? row + (timer.Iteration() % numFrames) : row);
        }
+       void DrawCenterBottom(SDL_Surface *dest, geometry::Point<int> position) const {
+               sprite->DrawCenterBottom(dest, position, col, Running() ? row + (timer.Iteration() % numFrames) : row);
+       }
 
 private:
        const Sprite *sprite;
index dfe9618cf844ccada668f5a34a01af3fb84dce68..730c5aa01cee254d90a08f7a7ca46df43dc34bd9 100644 (file)
@@ -97,8 +97,8 @@ int main(int argc, char **argv) {
                maxim.SetMaxMana(20);
                maxim.SetMana(20);
                maxim.SetIP(0);
-               maxim.SetAttackFrames(3);
-               maxim.SetSpellFrames(2);
+               maxim.SetAttackFrames(3, 125);
+               maxim.SetSpellFrames(2, 125);
 
                SDL_Surface *selanImg(IMG_Load("test-data/selan.png"));
                Sprite selanSprite(selanImg, 64, 64);
@@ -111,8 +111,8 @@ int main(int argc, char **argv) {
                selan.SetMaxMana(23);
                selan.SetMana(23);
                selan.SetIP(1);
-               selan.SetAttackFrames(3);
-               selan.SetSpellFrames(4);
+               selan.SetAttackFrames(3, 125);
+               selan.SetSpellFrames(4, 125);
 
                SDL_Surface *guyImg(IMG_Load("test-data/guy.png"));
                Sprite guySprite(guyImg, 64, 64);
@@ -125,8 +125,8 @@ int main(int argc, char **argv) {
                guy.SetMaxMana(0);
                guy.SetMana(0);
                guy.SetIP(254);
-               guy.SetAttackFrames(3);
-               guy.SetSpellFrames(0);
+               guy.SetAttackFrames(3, 125);
+               guy.SetSpellFrames(0, 125);
 
                SDL_Surface *dekarImg(IMG_Load("test-data/dekar.png"));
                Sprite dekarSprite(dekarImg, 64, 64);
@@ -139,8 +139,8 @@ int main(int argc, char **argv) {
                dekar.SetMaxMana(0);
                dekar.SetMana(0);
                dekar.SetIP(255);
-               dekar.SetAttackFrames(3);
-               dekar.SetSpellFrames(3);
+               dekar.SetAttackFrames(3, 125);
+               dekar.SetSpellFrames(3, 125);
 
                battle::Resources battleRes;