X-Git-Url: http://git.localhorst.tv/?a=blobdiff_plain;f=src%2Fbattle%2Fstates%2FPerformAttacks.cpp;h=92e5185cf70488a5ce8baf9a330011ef7ba51934;hb=0b11a24a8b08c49d6e4301573602fb6d01e7a8c8;hp=a1a5b8b260226a5ad816765b1d14e419417f9582;hpb=3f8fac16c7ae2cbe7da47b98aba9b558825723e7;p=l2e.git diff --git a/src/battle/states/PerformAttacks.cpp b/src/battle/states/PerformAttacks.cpp index a1a5b8b..92e5185 100644 --- a/src/battle/states/PerformAttacks.cpp +++ b/src/battle/states/PerformAttacks.cpp @@ -1,15 +1,9 @@ -/* - * PerformAttacks.cpp - * - * Created on: Aug 10, 2012 - * Author: holy - */ - #include "PerformAttacks.h" #include "../BattleState.h" #include "../Hero.h" #include "../Monster.h" +#include "../TargetSelection.h" #include "../../app/Application.h" #include "../../app/Input.h" #include "../../common/Ikari.h" @@ -23,33 +17,38 @@ using app::Application; using app::Input; -using geometry::Vector; +using math::Vector; using graphics::AnimationRunner; using std::vector; namespace battle { -void PerformAttacks::OnEnterState(Application &c, SDL_Surface *screen) { +void PerformAttacks::OnEnterState(SDL_Surface *screen) { battle->CalculateAttackOrder(); numberAnimation.reserve(battle->MaxMonsters() > battle->NumHeroes() + 1 ? battle->MaxMonsters() : battle->NumHeroes() + 1); numberPosition.reserve(numberAnimation.size()); + OnResize(screen->w, screen->h); } -void PerformAttacks::OnExitState(Application &c, SDL_Surface *screen) { +void PerformAttacks::OnExitState(SDL_Surface *screen) { battle->ClearAllAttacks(); } -void PerformAttacks::OnResumeState(Application &ctrl, SDL_Surface *screen) { +void PerformAttacks::OnResumeState(SDL_Surface *screen) { } -void PerformAttacks::OnPauseState(Application &ctrl, SDL_Surface *screen) { +void PerformAttacks::OnPauseState(SDL_Surface *screen) { } void PerformAttacks::OnResize(int width, int height) { - + const Resources &res = battle->Res(); + framePosition = battle->ScreenOffset(); + frameSize = Vector( + battle->Width(), + res.titleFrame->BorderHeight() * 2 + res.titleFont->CharHeight()); } @@ -66,13 +65,20 @@ void PerformAttacks::HandleEvents(const Input &input) { battle->CalculateDamage(); - if (battle->CurrentAttack().isMonster) { + if (battle->CurrentAttack().IsMonster()) { Monster &monster(battle->MonsterAt(battle->CurrentAttack().index)); titleBarText = monster.Name(); targetAnimation = AnimationRunner(monster.MeleeAnimation()); moveAnimation = AnimationRunner(monster.AttackAnimation()); monster.SetAnimation(moveAnimation); AddNumberAnimations(battle->MonsterAt(battle->CurrentAttack().index).GetAttackChoice().Selection()); + } else if (battle->CurrentAttack().IsCapsule()) { + Capsule &capsule(battle->GetCapsule()); + titleBarText = capsule.Name(); + targetAnimation = AnimationRunner(capsule.MeleeAnimation()); + moveAnimation = AnimationRunner(capsule.AttackAnimation()); + capsule.SetAnimation(moveAnimation); + AddNumberAnimations(capsule.GetAttackChoice().Selection()); } else { Hero &hero(battle->HeroAt(battle->CurrentAttack().index)); const AttackChoice &ac(battle->HeroAt(battle->CurrentAttack().index).GetAttackChoice()); @@ -118,13 +124,20 @@ void PerformAttacks::HandleEvents(const Input &input) { } } - if (titleBarText) titleBarTimer = GraphicsTimers().StartCountdown(850); + if (titleBarText) { + titleBarTimer = GraphicsTimers().StartCountdown(850); + textPosition = battle->ScreenOffset() + Vector( + (battle->Width() - std::strlen(titleBarText) * battle->Res().titleFont->CharWidth()) / 2, + battle->Res().titleFrame->BorderHeight()); + } if (moveAnimation.Valid()) { moveAnimation.Start(*this); - if (battle->CurrentAttack().isMonster) { + if (battle->CurrentAttack().IsMonster()) { battle->MonsterAt(battle->CurrentAttack().index).SetAnimation(moveAnimation); - } else { + } else if (battle->CurrentAttack().IsHero()) { battle->HeroAt(battle->CurrentAttack().index).SetAnimation(moveAnimation); + } else { + battle->GetCapsule().SetAnimation(moveAnimation); } } if (targetAnimation.Valid()) { @@ -140,11 +153,11 @@ void PerformAttacks::AddNumberAnimations(const TargetSelection &ts) { if (ts.IsBad(i)) { numberAnimation.push_back(NumberAnimation(ts.GetAmount(i), battle->Res().numberAnimationPrototype, battle->Res().bigNumberSprite)); numberPosition.push_back( - battle->MonsterAt(i).Position()); + battle->MonsterAt(i).Position() + battle->ScreenOffset()); } else if (ts.IsGood(i)) { numberAnimation.push_back(NumberAnimation(ts.GetAmount(i), battle->Res().numberAnimationPrototype, battle->Res().greenNumberSprite)); numberPosition.push_back( - battle->MonsterAt(i).Position()); + battle->MonsterAt(i).Position() + battle->ScreenOffset()); } } } else { @@ -152,11 +165,11 @@ void PerformAttacks::AddNumberAnimations(const TargetSelection &ts) { if (ts.IsBad(i)) { numberAnimation.push_back(NumberAnimation(ts.GetAmount(i), battle->Res().numberAnimationPrototype, battle->Res().bigNumberSprite)); numberPosition.push_back( - battle->HeroAt(i).Position()); + battle->HeroAt(i).Position() + battle->ScreenOffset()); } else if (ts.IsGood(i)) { numberAnimation.push_back(NumberAnimation(ts.GetAmount(i), battle->Res().numberAnimationPrototype, battle->Res().greenNumberSprite)); numberPosition.push_back( - battle->HeroAt(i).Position()); + battle->HeroAt(i).Position() + battle->ScreenOffset()); } } } @@ -194,7 +207,7 @@ bool PerformAttacks::HasAnimationsRunning() const { void PerformAttacks::ResetAnimation() { if (moveAnimation.Valid()) { moveAnimation.Clear(); - if (!battle->CurrentAttack().isMonster) { + if (!battle->CurrentAttack().IsMonster()) { battle->HeroAt(battle->CurrentAttack().index).GetAnimation().Clear(); } } @@ -207,55 +220,51 @@ void PerformAttacks::ResetAnimation() { } -void PerformAttacks::UpdateWorld(float deltaT) { +void PerformAttacks::UpdateWorld(Uint32 deltaT) { } void PerformAttacks::Render(SDL_Surface *screen) { - Vector offset(battle->CalculateScreenOffset(screen)); - battle->RenderBackground(screen, offset); - battle->RenderMonsters(screen, offset); - battle->RenderHeroes(screen, offset); - battle->RenderSmallHeroTags(screen, offset); - RenderTitleBar(screen, offset); - RenderNumbers(screen, offset); - RenderTargetAnimation(screen, offset); + battle->RenderBackground(screen); + battle->RenderMonsters(screen); + battle->RenderHeroes(screen); + battle->RenderCapsule(screen); + battle->RenderSmallHeroTags(screen); + RenderTitleBar(screen); + RenderNumbers(screen); + RenderTargetAnimation(screen); } -void PerformAttacks::RenderTitleBar(SDL_Surface *screen, const Vector &offset) const { +void PerformAttacks::RenderTitleBar(SDL_Surface *screen) const { if (!titleBarText || !titleBarTimer.Running()) return; - int height(battle->Res().titleFrame->BorderHeight() * 2 + battle->Res().titleFont->CharHeight()); - battle->Res().titleFrame->Draw(screen, offset, battle->Width(), height); + battle->Res().titleFrame->Draw(screen, framePosition, frameSize.X(), frameSize.Y()); - Vector textPosition( - (battle->Width() - (std::strlen(titleBarText) * battle->Res().titleFont->CharWidth())) / 2, - battle->Res().titleFrame->BorderHeight()); - battle->Res().titleFont->DrawString(titleBarText, screen, textPosition + offset); + battle->Res().titleFont->DrawString(titleBarText, screen, textPosition); } -void PerformAttacks::RenderNumbers(SDL_Surface *screen, const Vector &offset) const { +void PerformAttacks::RenderNumbers(SDL_Surface *screen) 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); - numberAnimation[i].Draw(screen, numberPosition[i] + align + offset); + numberAnimation[i].Draw(screen, numberPosition[i] + align); } } } -void PerformAttacks::RenderTargetAnimation(SDL_Surface *screen, const geometry::Vector &offset) const { +void PerformAttacks::RenderTargetAnimation(SDL_Surface *screen) const { if (!targetAnimation.Valid() || !targetAnimation.Running()) return; const TargetSelection &ts(battle->CurrentAttackAttackChoice().Selection()); if (ts.TargetsHeroes()) { for (vector >::size_type i(0), end(battle->NumHeroes()); i < end; ++i) { if (ts.IsSelected(i)) { - targetAnimation.DrawCenter(screen, battle->HeroAt(i).Position() + offset); + targetAnimation.DrawCenter(screen, battle->HeroAt(i).Position() + battle->ScreenOffset()); } } } else { for (vector >::size_type i(0), end(battle->MaxMonsters()); i < end; ++i) { if (ts.IsSelected(i)) { - targetAnimation.DrawCenter(screen, battle->MonsterAt(i).Position() + offset); + targetAnimation.DrawCenter(screen, battle->MonsterAt(i).Position() + battle->ScreenOffset()); } } }