void PerformAttacks::HandleEvents(const Input &input) {
- CheckNumberAnimation();
+ CheckAnimations();
if (HasAnimationsRunning()) return;
ResetAnimation();
AdvanceCursor();
switch (ac.GetType()) {
case AttackChoice::SWORD:
- titleBarText = hero.HasWeapon() ? hero.Weapon()->Name() : "Melee attack!";
+ if (hero.HasWeapon()) {
+ titleBarText = hero.Weapon()->Name();
+ } else {
+ titleBarText = "Melee attack!";
+ }
moveAnimation = hero.AttackAnimation();
+ targetAnimation = hero.MeleeAnimation();
+
numberAnimation.push_back(NumberAnimation(15, battle->Res().numberAnimationPrototype, battle->Res().bigNumberSprite));
if (ac.Selection().TargetsEnemies()) {
numberPosition.push_back(
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<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;
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();
+ if (moveAnimation) {
+ moveAnimation->Stop();
+ moveAnimation = 0;
+ }
+ if (targetAnimation) {
+ targetAnimation->Stop();
+ targetAnimation = 0;
+ }
titleBarTimer.Clear();
numberAnimation.clear();
numberPosition.clear();
battle->RenderSmallHeroTags(screen, offset);
RenderTitleBar(screen, offset);
RenderNumbers(screen, offset);
+ RenderTargetAnimation(screen, offset);
}
-void PerformAttacks::RenderTitleBar(SDL_Surface *screen, const Vector<int> &offset) {
+void PerformAttacks::RenderTitleBar(SDL_Surface *screen, const Vector<int> &offset) const {
if (!titleBarText || !titleBarTimer.Running()) return;
int height(battle->Res().titleFrame->BorderHeight() * 2 + battle->Res().titleFont->CharHeight());
- battle->Res().titleFrame->Draw(screen, Point<int>(offset.X(), offset.Y()), battle->BackgroundWidth(), height);
+ battle->Res().titleFrame->Draw(screen, Point<int>(offset.X(), offset.Y()), battle->Width(), height);
Point<int> 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);
}
-void PerformAttacks::RenderNumbers(SDL_Surface *screen, const Vector<int> &offset) {
+void PerformAttacks::RenderNumbers(SDL_Surface *screen, const Vector<int> &offset) const {
for (vector<NumberAnimation>::size_type i(0), end(numberAnimation.size()); i < end; ++i) {
if (numberAnimation[i].Running()) {
Vector<int> align(numberAnimation[i].Width() / -2, numberAnimation[i].Height() * -3 / 4);
}
}
+void PerformAttacks::RenderTargetAnimation(SDL_Surface *screen, const geometry::Vector<int> &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<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);
+ }
+ }
+}
+
}