]> git.localhorst.tv Git - l2e.git/commitdiff
added melee animation of monsters
authorDaniel Karbach <daniel.karbach@localhorst.tv>
Sun, 19 Aug 2012 21:53:28 +0000 (23:53 +0200)
committerDaniel Karbach <daniel.karbach@localhorst.tv>
Sun, 19 Aug 2012 21:53:28 +0000 (23:53 +0200)
src/battle/BattleState.cpp
src/battle/BattleState.h
src/battle/Monster.h
src/battle/states/PerformAttacks.cpp
src/main.cpp
test-data/attack-monster.png [new file with mode: 0644]

index d0bb108da3a65256ce0b9846a8eb6557cc663364..95f2f118d9e618f45b928180bad1698240b0969d 100644 (file)
@@ -390,6 +390,14 @@ void BattleState::ApplyDamage() {
        }
 }
 
+AttackChoice &BattleState::CurrentAttackAttackChoice() {
+       if (CurrentAttack().isMonster) {
+               return monsterAttacks[CurrentAttack().index];
+       } else {
+               return AttackChoiceAt(CurrentAttack().index);
+       }
+}
+
 void BattleState::ClearAllAttacks() {
        attackCursor = -1;
        activeHero = -1;
index ab9f731a9c838e0d9e5430bb491007c0353b35a3..8814663dae807fce9eb3226b065e60e889fdc7bb 100644 (file)
@@ -134,6 +134,7 @@ public:
        void CalculateDamage();
        void ApplyDamage();
        const Order &CurrentAttack() const { assert(attackCursor >= 0 && attackCursor < int(attackOrder.size())); return attackOrder[attackCursor]; };
+       AttackChoice &CurrentAttackAttackChoice();
        void ClearAllAttacks();
 
        bool Victory() const;
index e4d787e741e87856be256f9f626554b78d49263b..6013ebe47a027bf4fad44ca172ffa749a3945f6a 100644 (file)
@@ -52,6 +52,8 @@ public:
        const /* Script */ void *AttackScript() { return attackScript; }
        const /* Script */ void *DefenseScript() { return defenseScript; }
 
+       graphics::Animation *MeleeAnimation() { return meleeAnimation; }
+       const graphics::Animation *MeleeAnimation() const { return meleeAnimation; }
        graphics::Animation *AttackAnimation() { return attackAnimation; }
        const graphics::Animation *AttackAnimation() const { return attackAnimation; }
        graphics::Animation *SpellAnimation() { return spellAnimation; }
@@ -69,6 +71,7 @@ public:
        void SetStats(const Stats &s) { stats = s; }
        void SetReward(Uint16 exp, Uint16 gold) { expReward = exp; goldReward = gold; }
 
+       void SetMeleeAnimation(graphics::Animation *a) { meleeAnimation = a; }
        void SetAttackAnimation(graphics::Animation *a) { attackAnimation = a; }
        void SetSpellAnimation(graphics::Animation *a) { spellAnimation = a; }
 
@@ -79,6 +82,7 @@ private:
        /* Script */ void *attackScript;
        /* Script */ void *defenseScript;
 
+       graphics::Animation *meleeAnimation;
        graphics::Animation *attackAnimation;
        graphics::Animation *spellAnimation;
 
index 8550318d05cf83942cafb5619ea2a647869a98ce..10fb8bb11294c6f0f517d1def1efd528cbd86cbb 100644 (file)
@@ -74,6 +74,8 @@ void PerformAttacks::HandleEvents(const Input &input) {
                Monster &monster(battle->MonsterAt(battle->CurrentAttack().index));
                titleBarText = monster.Name();
                moveAnimation = monster.AttackAnimation();
+               targetAnimation = monster.MeleeAnimation();
+               // TODO: add number animations
        } else {
                Hero &hero(battle->HeroAt(battle->CurrentAttack().index));
                const AttackChoice &ac(battle->AttackChoiceAt(battle->CurrentAttack().index));
@@ -227,8 +229,7 @@ void PerformAttacks::RenderNumbers(SDL_Surface *screen, const Vector<int> &offse
 
 void PerformAttacks::RenderTargetAnimation(SDL_Surface *screen, const geometry::Vector<int> &offset) const {
        if (!targetAnimation || !targetAnimation->Running()) return;
-       if (battle->CurrentAttack().isMonster) return; // no monsters for now
-       const TargetSelection &ts(battle->AttackChoiceAt(battle->CurrentAttack().index).Selection());
+       const TargetSelection &ts(battle->CurrentAttackAttackChoice().Selection());
        const vector<Point<int> > &positions(ts.TargetsHeroes() ? battle->HeroesPositions() : battle->MonsterPositions());
        for (vector<Point<int> >::size_type i(0), end(positions.size()); i < end; ++i) {
                if (ts.IsSelected(i)) {
index f7707ef1cc0570053097d7e18a8271e23c921dba..14a6336f014df0d2028d3124f2699ca9a2af64b1 100644 (file)
@@ -103,6 +103,10 @@ int main(int argc, char **argv) {
                monsterAttackAnimation.AddFrame(0, 0, Vector<int>(16, 0));
                monsterAttackAnimation.AddFrame(0, 1, Vector<int>(16, 0));
                monster.SetAttackAnimation(&monsterAttackAnimation);
+               SDL_Surface *monsterMeleeImg(IMG_Load("test-data/attack-monster.png"));
+               Sprite monsterMeleeSprite(monsterMeleeImg, 96, 64);
+               SimpleAnimation monsterMeleeAnimation(&monsterMeleeSprite, framerate, 14);
+               monster.SetMeleeAnimation(&monsterMeleeAnimation);
 
                SDL_Surface *maximImg(IMG_Load("test-data/maxim.png"));
                Sprite maximSprite(maximImg, 64, 64);
diff --git a/test-data/attack-monster.png b/test-data/attack-monster.png
new file mode 100644 (file)
index 0000000..327802b
Binary files /dev/null and b/test-data/attack-monster.png differ