From: Daniel Karbach Date: Sun, 19 Aug 2012 21:53:28 +0000 (+0200) Subject: added melee animation of monsters X-Git-Url: https://git.localhorst.tv/?a=commitdiff_plain;h=d4609ba1798d82cce128b5985d60cb212b760246;p=l2e.git added melee animation of monsters --- diff --git a/src/battle/BattleState.cpp b/src/battle/BattleState.cpp index d0bb108..95f2f11 100644 --- a/src/battle/BattleState.cpp +++ b/src/battle/BattleState.cpp @@ -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; diff --git a/src/battle/BattleState.h b/src/battle/BattleState.h index ab9f731..8814663 100644 --- a/src/battle/BattleState.h +++ b/src/battle/BattleState.h @@ -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; diff --git a/src/battle/Monster.h b/src/battle/Monster.h index e4d787e..6013ebe 100644 --- a/src/battle/Monster.h +++ b/src/battle/Monster.h @@ -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; diff --git a/src/battle/states/PerformAttacks.cpp b/src/battle/states/PerformAttacks.cpp index 8550318..10fb8bb 100644 --- a/src/battle/states/PerformAttacks.cpp +++ b/src/battle/states/PerformAttacks.cpp @@ -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 &offse void PerformAttacks::RenderTargetAnimation(SDL_Surface *screen, const geometry::Vector &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 > &positions(ts.TargetsHeroes() ? battle->HeroesPositions() : battle->MonsterPositions()); for (vector >::size_type i(0), end(positions.size()); i < end; ++i) { if (ts.IsSelected(i)) { diff --git a/src/main.cpp b/src/main.cpp index f7707ef..14a6336 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -103,6 +103,10 @@ int main(int argc, char **argv) { monsterAttackAnimation.AddFrame(0, 0, Vector(16, 0)); monsterAttackAnimation.AddFrame(0, 1, Vector(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 index 0000000..327802b Binary files /dev/null and b/test-data/attack-monster.png differ