]> git.localhorst.tv Git - l2e.git/blobdiff - src/battle/states/PerformAttacks.cpp
added simple attack animations
[l2e.git] / src / battle / states / PerformAttacks.cpp
index 35253ce099c2ae6bcf1617b81145798855379ce8..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 {
 
@@ -58,26 +60,70 @@ void PerformAttacks::HandleEvents(const Input &input) {
                        if (titleBarText) {
                                titleBarText = 0;
                                ++cursor;
-                               while (cursor < (int)battle->Monsters().size() && !battle->MonsterPositionOccupied(cursor)) {
+                               while (cursor < battle->MaxMonsters() && !battle->MonsterPositionOccupied(cursor)) {
                                        ++cursor;
                                }
-                               if (cursor >= (int)battle->Monsters().size()) {
+                               if (cursor >= battle->MaxMonsters()) {
                                        battle->ClearAllAttacks();
                                        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 == (int)battle->Heroes().size()) {
+                               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";
@@ -113,7 +159,7 @@ void PerformAttacks::Render(SDL_Surface *screen) {
        battle->RenderBackground(screen, offset);
        battle->RenderMonsters(screen, offset);
        battle->RenderHeroes(screen, offset);
-       // render small tags
+       battle->RenderSmallHeroTags(screen, offset);
        RenderTitleBar(screen, offset);
 }