using app::Input;
using geometry::Point;
using geometry::Vector;
+using graphics::AnimationRunner;
using std::vector;
namespace battle {
if (battle->CurrentAttack().isMonster) {
Monster &monster(battle->MonsterAt(battle->CurrentAttack().index));
titleBarText = monster.Name();
- moveAnimation = monster.AttackAnimation();
- targetAnimation = monster.MeleeAnimation();
+ targetAnimation = AnimationRunner(monster.MeleeAnimation());
+ moveAnimation = AnimationRunner(monster.AttackAnimation());
+ monster.SetAnimation(moveAnimation);
AddNumberAnimations(battle->MonsterAttackChoiceAt(battle->CurrentAttack().index).Selection());
} else {
Hero &hero(battle->HeroAt(battle->CurrentAttack().index));
case AttackChoice::SWORD:
if (hero.HasWeapon()) {
titleBarText = hero.Weapon()->Name();
- targetAnimation = hero.Weapon()->AttackAnimation();
+ targetAnimation = AnimationRunner(hero.Weapon()->AttackAnimation());
} else {
titleBarText = "Melee attack!";
- targetAnimation = hero.MeleeAnimation();
+ targetAnimation = AnimationRunner(hero.MeleeAnimation());
}
- moveAnimation = hero.AttackAnimation();
+ moveAnimation = AnimationRunner(hero.AttackAnimation());
AddNumberAnimations(ac.Selection());
break;
case AttackChoice::MAGIC:
titleBarText = ac.GetSpell()->Name();
- moveAnimation = hero.SpellAnimation();
+ moveAnimation = AnimationRunner(hero.SpellAnimation());
break;
case AttackChoice::DEFEND:
titleBarText = "Defends.";
- moveAnimation = 0;
+ moveAnimation.Clear();
break;
case AttackChoice::IKARI:
if (ac.GetItem()->HasIkari()) {
titleBarText = ac.GetItem()->GetIkari()->Name();
if (ac.GetItem()->GetIkari()->IsMagical()) {
- moveAnimation = hero.SpellAnimation();
+ moveAnimation = AnimationRunner(hero.SpellAnimation());
} else {
- moveAnimation = hero.AttackAnimation();
+ moveAnimation = AnimationRunner(hero.AttackAnimation());
}
}
break;
case AttackChoice::ITEM:
titleBarText = ac.GetItem()->Name();
- moveAnimation = 0;
+ moveAnimation.Clear();
break;
case AttackChoice::UNDECIDED:
titleBarText = "UNDECIDED";
- moveAnimation = 0;
+ moveAnimation.Clear();
break;
}
+ hero.SetAnimation(moveAnimation);
}
if (titleBarText) titleBarTimer = GraphicsTimers().StartCountdown(850);
- if (moveAnimation) moveAnimation->Start(*this);
- if (targetAnimation) {
+ if (moveAnimation.Valid()) moveAnimation.Start(*this);
+ if (targetAnimation.Valid()) {
targetAnimationTimer = GraphicsTimers().StartCountdown(150);
} else {
targetAnimationTimer.Clear();
}
void PerformAttacks::CheckAnimations() {
- if (targetAnimation && targetAnimationTimer.JustHit()) {
- targetAnimation->Start(*this);
+ if (targetAnimation.Valid() && targetAnimationTimer.JustHit()) {
+ targetAnimation.Start(*this);
}
- if (moveAnimation && !moveAnimation->Finished()) return;
- if (targetAnimation && !targetAnimation->Finished()) return;
- if (moveAnimation || targetAnimation) {
- moveAnimation = 0;
- targetAnimation = 0;
+ if (moveAnimation.Valid() && !moveAnimation.Finished()) return;
+ if (targetAnimation.Valid() && !targetAnimation.Finished()) return;
+ if (moveAnimation.Valid() || targetAnimation.Valid()) {
+ moveAnimation.Clear();
+ targetAnimation.Clear();
for (vector<NumberAnimation>::iterator i(numberAnimation.begin()), end(numberAnimation.end()); i != end; ++i) {
i->Start(*this);
}
bool PerformAttacks::HasAnimationsRunning() const {
if (titleBarTimer.Running()) return true;
- if (moveAnimation && moveAnimation->Running()) return true;
- if (targetAnimation && targetAnimation->Running()) return true;
+ if (moveAnimation.Valid() && moveAnimation.Running()) return true;
+ if (targetAnimation.Valid() && targetAnimation.Running()) return true;
for (vector<NumberAnimation>::const_iterator i(numberAnimation.begin()), end(numberAnimation.end()); i != end; ++i) {
if (i->Running()) return true;
}
}
void PerformAttacks::ResetAnimation() {
- if (moveAnimation) {
- moveAnimation->Stop();
- moveAnimation = 0;
+ if (moveAnimation.Valid()) {
+ moveAnimation.Clear();
+ if (!battle->CurrentAttack().isMonster) {
+ battle->HeroAt(battle->CurrentAttack().index).GetAnimation().Clear();
+ }
}
- if (targetAnimation) {
- targetAnimation->Stop();
- targetAnimation = 0;
+ if (targetAnimation.Valid()) {
+ targetAnimation.Clear();
}
titleBarTimer.Clear();
numberAnimation.clear();
}
void PerformAttacks::RenderTargetAnimation(SDL_Surface *screen, const geometry::Vector<int> &offset) const {
- if (!targetAnimation || !targetAnimation->Running()) return;
+ if (!targetAnimation.Valid() || !targetAnimation.Running()) return;
const TargetSelection &ts(battle->CurrentAttackAttackChoice().Selection());
const vector<Point<int> > &positions(ts.TargetsHeroes() ? battle->HeroesPositions() : battle->MonsterPositions());
for (vector<Point<int> >::size_type i(0), end(positions.size()); i < end; ++i) {
if (ts.IsSelected(i)) {
- targetAnimation->DrawCenter(screen, positions[i] + offset);
+ targetAnimation.DrawCenter(screen, positions[i] + offset);
}
}
}