X-Git-Url: http://git.localhorst.tv/?a=blobdiff_plain;f=src%2Fbattle%2Fstates%2FPerformAttacks.cpp;h=6c318aaf04138e86c627a94429dcdec23e260911;hb=8456b7dac2051bfd2b507a39854c1428eb4d91cd;hp=b5cd9bebec80754ee019001b972616b557829e34;hpb=aedc31b88715246abc00a0ab333bea6e17bbb780;p=l2e.git diff --git a/src/battle/states/PerformAttacks.cpp b/src/battle/states/PerformAttacks.cpp index b5cd9be..6c318aa 100644 --- a/src/battle/states/PerformAttacks.cpp +++ b/src/battle/states/PerformAttacks.cpp @@ -7,6 +7,7 @@ #include "PerformAttacks.h" +#include "../AttackAnimation.h" #include "../BattleState.h" #include "../Hero.h" #include "../Monster.h" @@ -57,6 +58,7 @@ void PerformAttacks::Resize(int width, int height) { void PerformAttacks::HandleEvents(const Input &input) { + if (attackAnimation) attackAnimation->Update(); CheckNumberAnimation(); if (HasAnimationsRunning()) return; ResetAnimation(); @@ -77,8 +79,19 @@ void PerformAttacks::HandleEvents(const Input &input) { switch (ac.GetType()) { case AttackChoice::SWORD: - titleBarText = hero.HasWeapon() ? hero.Weapon()->Name() : "Melee attack!"; - moveAnimation = hero.AttackAnimation(); + if (hero.HasWeapon()) { + titleBarText = hero.Weapon()->Name(); + moveAnimation = hero.AttackAnimation(); + } else { + titleBarText = "Melee attack!"; + if (hero.MeleeAnimation()) { + moveAnimation = 0; + attackAnimation = hero.MeleeAnimation(); + } else { + moveAnimation = hero.AttackAnimation(); + attackAnimation = 0; + } + } numberAnimation.push_back(NumberAnimation(15, battle->Res().numberAnimationPrototype, battle->Res().bigNumberSprite)); if (ac.Selection().TargetsEnemies()) { numberPosition.push_back( @@ -119,11 +132,15 @@ void PerformAttacks::HandleEvents(const Input &input) { if (titleBarText) titleBarTimer = GraphicsTimers().StartCountdown(1500); if (moveAnimation) moveAnimation->Start(*this); + if (attackAnimation) attackAnimation->Start(battle, this); } void PerformAttacks::CheckNumberAnimation() { if (moveAnimation && moveAnimation->Running()) return; - if (!moveAnimation || moveAnimation->JustFinished()) { + if (attackAnimation && !attackAnimation->Finished()) return; + if (moveAnimation || attackAnimation) { + moveAnimation = 0; + attackAnimation = 0; for (vector::iterator i(numberAnimation.begin()), end(numberAnimation.end()); i != end; ++i) { i->Start(*this); } @@ -145,6 +162,7 @@ bool PerformAttacks::HasAnimationsRunning() const { void PerformAttacks::ResetAnimation() { if (moveAnimation) moveAnimation->Stop(); + if (attackAnimation) attackAnimation = 0; titleBarTimer.Clear(); numberAnimation.clear(); numberPosition.clear(); @@ -175,16 +193,17 @@ void PerformAttacks::Render(SDL_Surface *screen) { battle->RenderSmallHeroTags(screen, offset); RenderTitleBar(screen, offset); RenderNumbers(screen, offset); + if (attackAnimation) attackAnimation->Render(screen, offset); } void PerformAttacks::RenderTitleBar(SDL_Surface *screen, const Vector &offset) { if (!titleBarText || !titleBarTimer.Running()) return; int height(battle->Res().titleFrame->BorderHeight() * 2 + battle->Res().titleFont->CharHeight()); - battle->Res().titleFrame->Draw(screen, Point(offset.X(), offset.Y()), battle->BackgroundWidth(), height); + battle->Res().titleFrame->Draw(screen, Point(offset.X(), offset.Y()), battle->Width(), height); Point textPosition( - (battle->BackgroundWidth() - (std::strlen(titleBarText) * battle->Res().titleFont->CharWidth())) / 2, + (battle->Width() - (std::strlen(titleBarText) * battle->Res().titleFont->CharWidth())) / 2, battle->Res().titleFrame->BorderHeight()); battle->Res().titleFont->DrawString(titleBarText, screen, textPosition + offset); }