X-Git-Url: https://git.localhorst.tv/?a=blobdiff_plain;f=src%2Fbattle%2Fstates%2FPerformAttacks.cpp;h=2a8f3a53b697a4aecb3e5270c4e7c65d4be69ff9;hb=f89e79ad6fdc3009657e81f3dc3765d661f4899c;hp=dd0e0df1cd0a27de4102081e4b8a6e470e945f01;hpb=8f6a2452408f4ae35396cd7008a6fab0ecb03a46;p=l2e.git diff --git a/src/battle/states/PerformAttacks.cpp b/src/battle/states/PerformAttacks.cpp index dd0e0df..2a8f3a5 100644 --- a/src/battle/states/PerformAttacks.cpp +++ b/src/battle/states/PerformAttacks.cpp @@ -57,7 +57,7 @@ void PerformAttacks::Resize(int width, int height) { void PerformAttacks::HandleEvents(const Input &input) { - CheckNumberAnimation(); + CheckAnimations(); if (HasAnimationsRunning()) return; ResetAnimation(); AdvanceCursor(); @@ -77,8 +77,15 @@ void PerformAttacks::HandleEvents(const Input &input) { switch (ac.GetType()) { case AttackChoice::SWORD: - titleBarText = hero.HasWeapon() ? hero.Weapon()->Name() : "Melee attack!"; + if (hero.HasWeapon()) { + titleBarText = hero.Weapon()->Name(); + targetAnimation = hero.Weapon()->AttackAnimation(); + } else { + titleBarText = "Melee attack!"; + targetAnimation = hero.MeleeAnimation(); + } moveAnimation = hero.AttackAnimation(); + numberAnimation.push_back(NumberAnimation(15, battle->Res().numberAnimationPrototype, battle->Res().bigNumberSprite)); if (ac.Selection().TargetsEnemies()) { numberPosition.push_back( @@ -119,11 +126,22 @@ void PerformAttacks::HandleEvents(const Input &input) { if (titleBarText) titleBarTimer = GraphicsTimers().StartCountdown(1500); if (moveAnimation) moveAnimation->Start(*this); + if (targetAnimation) { + targetAnimationTimer = GraphicsTimers().StartCountdown(150); + } else { + targetAnimationTimer.Clear(); + } } -void PerformAttacks::CheckNumberAnimation() { - if (moveAnimation && moveAnimation->Running()) return; - if (!moveAnimation || moveAnimation->JustFinished()) { +void PerformAttacks::CheckAnimations() { + if (targetAnimation && targetAnimationTimer.JustHit()) { + targetAnimation->Start(*this); + } + if (moveAnimation && !moveAnimation->Finished()) return; + if (targetAnimation && !targetAnimation->Finished()) return; + if (moveAnimation || targetAnimation) { + moveAnimation = 0; + targetAnimation = 0; for (vector::iterator i(numberAnimation.begin()), end(numberAnimation.end()); i != end; ++i) { i->Start(*this); } @@ -137,6 +155,7 @@ void PerformAttacks::CheckNumberAnimation() { bool PerformAttacks::HasAnimationsRunning() const { if (titleBarTimer.Running()) return true; if (moveAnimation && moveAnimation->Running()) return true; + if (targetAnimation && targetAnimation->Running()) return true; for (vector::const_iterator i(numberAnimation.begin()), end(numberAnimation.end()); i != end; ++i) { if (i->Running()) return true; } @@ -144,7 +163,14 @@ bool PerformAttacks::HasAnimationsRunning() const { } void PerformAttacks::ResetAnimation() { - if (moveAnimation) moveAnimation->Stop(); + if (moveAnimation) { + moveAnimation->Stop(); + moveAnimation = 0; + } + if (targetAnimation) { + targetAnimation->Stop(); + targetAnimation = 0; + } titleBarTimer.Clear(); numberAnimation.clear(); numberPosition.clear(); @@ -175,9 +201,10 @@ void PerformAttacks::Render(SDL_Surface *screen) { battle->RenderSmallHeroTags(screen, offset); RenderTitleBar(screen, offset); RenderNumbers(screen, offset); + RenderTargetAnimation(screen, offset); } -void PerformAttacks::RenderTitleBar(SDL_Surface *screen, const Vector &offset) { +void PerformAttacks::RenderTitleBar(SDL_Surface *screen, const Vector &offset) const { if (!titleBarText || !titleBarTimer.Running()) return; int height(battle->Res().titleFrame->BorderHeight() * 2 + battle->Res().titleFont->CharHeight()); @@ -189,7 +216,7 @@ void PerformAttacks::RenderTitleBar(SDL_Surface *screen, const Vector &offs battle->Res().titleFont->DrawString(titleBarText, screen, textPosition + offset); } -void PerformAttacks::RenderNumbers(SDL_Surface *screen, const Vector &offset) { +void PerformAttacks::RenderNumbers(SDL_Surface *screen, const Vector &offset) const { for (vector::size_type i(0), end(numberAnimation.size()); i < end; ++i) { if (numberAnimation[i].Running()) { Vector align(numberAnimation[i].Width() / -2, numberAnimation[i].Height() * -3 / 4); @@ -198,4 +225,16 @@ 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 (order[cursor].isMonster) return; // no monsters for now + const TargetSelection &ts(battle->AttackChoiceAt(order[cursor].index).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)) { + targetAnimation->DrawCenter(screen, positions[i] + offset); + } + } +} + }