#include "../../common/Spell.h"
#include "../../geometry/operators.h"
#include "../../geometry/Point.h"
+#include "../../graphics/Animation.h"
#include "../../graphics/Font.h"
#include "../../graphics/Frame.h"
-#include "../../graphics/SimpleAnimation.h"
#include <cstring>
using app::Input;
using geometry::Point;
using geometry::Vector;
-using graphics::SimpleAnimation;
namespace battle {
void PerformAttacks::EnterState(Application &c, SDL_Surface *screen) {
ctrl = &c;
- // TODO: push battle animation if enemy is faster
}
void PerformAttacks::ExitState(Application &c, SDL_Surface *screen) {
}
} else {
if (cursor == 0) {
- battle->HeroAnimationAt(battle->NumHeroes() - 1).Stop();
+ if (battle->HeroAt(battle->NumHeroes() - 1).AttackAnimation()) {
+ battle->HeroAt(battle->NumHeroes() - 1).AttackAnimation()->Stop();
+ }
+ if (battle->HeroAt(battle->NumHeroes() - 1).SpellAnimation()) {
+ battle->HeroAt(battle->NumHeroes() - 1).SpellAnimation()->Stop();
+ }
}
titleBarText = battle->MonsterAt(cursor).Name();
}
switch (ac.GetType()) {
case AttackChoice::SWORD:
- battle->HeroAnimationAt(cursor) = SimpleAnimation(
- battle->HeroAt(cursor).Sprite(),
- battle->HeroAt(cursor).AttackFrameTime(),
- battle->HeroAt(cursor).AttackFrames(), 2);
+ if (battle->HeroAt(cursor).AttackAnimation()) {
+ battle->HeroAt(cursor).AttackAnimation()->Start(*this);
+ }
break;
case AttackChoice::MAGIC:
- battle->HeroAnimationAt(cursor) = SimpleAnimation(
- battle->HeroAt(cursor).Sprite(),
- battle->HeroAt(cursor).SpellFrameTime(),
- battle->HeroAt(cursor).SpellFrames(), 3);
+ if (battle->HeroAt(cursor).SpellAnimation()) {
+ battle->HeroAt(cursor).SpellAnimation()->Start(*this);
+ }
break;
case AttackChoice::DEFEND:
break;
case AttackChoice::IKARI:
if (ac.GetItem()->HasIkari()) {
if (ac.GetItem()->GetIkari()->IsMagical()) {
- battle->HeroAnimationAt(cursor) = SimpleAnimation(
- battle->HeroAt(cursor).Sprite(),
- battle->HeroAt(cursor).SpellFrameTime(),
- battle->HeroAt(cursor).SpellFrames(), 3);
+ if (battle->HeroAt(cursor).SpellAnimation()) {
+ battle->HeroAt(cursor).SpellAnimation()->Start(*this);
+ }
} else {
- battle->HeroAnimationAt(cursor) = SimpleAnimation(
- battle->HeroAt(cursor).Sprite(),
- battle->HeroAt(cursor).AttackFrameTime(),
- battle->HeroAt(cursor).AttackFrames(), 2);
+ if (battle->HeroAt(cursor).AttackAnimation()) {
+ battle->HeroAt(cursor).AttackAnimation()->Start(*this);
+ }
}
}
break;
case AttackChoice::UNDECIDED:
break;
}
- battle->HeroAnimationAt(cursor).Start(*this);
++cursor;
if (cursor == battle->NumHeroes()) {
}
} else {
if (cursor > 0) {
- battle->HeroAnimationAt(cursor - 1).Stop();
+ if (battle->HeroAt(cursor - 1).AttackAnimation()) {
+ battle->HeroAt(cursor - 1).AttackAnimation()->Stop();
+ }
+ if (battle->HeroAt(cursor - 1).SpellAnimation()) {
+ battle->HeroAt(cursor - 1).SpellAnimation()->Stop();
+ }
}
switch (ac.GetType()) {
case AttackChoice::SWORD:
#include "common/Item.h"
#include "common/Spell.h"
#include "geometry/Point.h"
+#include "geometry/Vector.h"
+#include "graphics/ComplexAnimation.h"
#include "graphics/Font.h"
#include "graphics/Frame.h"
#include "graphics/Gauge.h"
using common::Item;
using common::Spell;
using geometry::Point;
+using geometry::Vector;
+using graphics::ComplexAnimation;
using graphics::Font;
using graphics::Frame;
using graphics::Gauge;
maxim.SetMaxMana(20);
maxim.SetMana(20);
maxim.SetIP(0);
- maxim.SetAttackFrames(3, 125);
- maxim.SetSpellFrames(2, 125);
+ ComplexAnimation maximAttackAnimation(&maximSprite, 30);
+ maximAttackAnimation.AddFrames(2, 0, Vector<int>(), 2);
+ maximAttackAnimation.AddFrames(2, 0, Vector<int>(4, 0), 2);
+ maximAttackAnimation.AddFrame(2, 1, Vector<int>(4, 0));
+ maximAttackAnimation.AddFrames(2, 1, Vector<int>(-2, 0), 2);
+ maximAttackAnimation.AddFrame(2, 1, Vector<int>(-8, 0));
+ maximAttackAnimation.AddFrames(2, 2, Vector<int>(-8, 0), 2);
+ maximAttackAnimation.AddFrame(2, 2, Vector<int>(-4, 0));
+ maxim.SetAttackAnimation(&maximAttackAnimation);
+ ComplexAnimation maximSpellAnimation(&maximSprite, 150);
+ maximSpellAnimation.AddFrames(3, 0, Vector<int>(), 2);
+ maximSpellAnimation.AddFrame(3, 1);
+ maxim.SetSpellAnimation(&maximSpellAnimation);
SDL_Surface *selanImg(IMG_Load("test-data/selan.png"));
Sprite selanSprite(selanImg, 64, 64);
selan.SetMaxMana(23);
selan.SetMana(23);
selan.SetIP(1);
- selan.SetAttackFrames(3, 125);
- selan.SetSpellFrames(4, 125);
+ ComplexAnimation selanAttackAnimation(&selanSprite, 30);
+ selanAttackAnimation.AddFrames(1, 0, Vector<int>(4, 0), 2);
+ selanAttackAnimation.AddFrame(1, 0, Vector<int>(8, 2));
+ selanAttackAnimation.AddFrame(2, 0, Vector<int>(10, 4));
+ selanAttackAnimation.AddFrame(2, 0, Vector<int>(14, 4));
+ selanAttackAnimation.AddFrames(2, 0, Vector<int>(12, 2), 3);
+ selanAttackAnimation.AddFrames(2, 1, Vector<int>(14, 2), 2);
+ selanAttackAnimation.AddFrame(2, 1, Vector<int>(2, 0));
+ selanAttackAnimation.AddFrame(2, 2, Vector<int>(-2, -4));
+ selanAttackAnimation.AddFrame(2, 2, Vector<int>(-8, -8));
+ selanAttackAnimation.AddFrame(2, 2);
+ selan.SetAttackAnimation(&selanAttackAnimation);
+ ComplexAnimation selanSpellAnimation(&selanSprite, 30);
+ selanAttackAnimation.AddFrames(2, 0, Vector<int>(), 3);
+ selanAttackAnimation.AddFrames(2, 1, Vector<int>(), 2);
+ selanAttackAnimation.AddFrames(2, 2, Vector<int>(), 3);
+ selanAttackAnimation.AddFrames(2, 3, Vector<int>(), 2);
+ selan.SetSpellAnimation(&selanSpellAnimation);
SDL_Surface *guyImg(IMG_Load("test-data/guy.png"));
Sprite guySprite(guyImg, 64, 64);
guy.SetMaxMana(0);
guy.SetMana(0);
guy.SetIP(254);
- guy.SetAttackFrames(3, 125);
- guy.SetSpellFrames(0, 125);
+ ComplexAnimation guyAttackAnimation(&guySprite, 30);
+ guyAttackAnimation.AddFrames(1, 0, Vector<int>(-4, 0), 2);
+ guyAttackAnimation.AddFrames(1, 0, Vector<int>(-8, 0), 2);
+ guyAttackAnimation.AddFrames(2, 0, Vector<int>(-8, 0), 2);
+ guyAttackAnimation.AddFrame(2, 0, Vector<int>(-4, 0));
+ guyAttackAnimation.AddFrames(2, 0, Vector<int>(), 2);
+ guyAttackAnimation.AddFrame(2, 1);
+ guyAttackAnimation.AddFrame(2, 1, Vector<int>(4, 0));
+ guyAttackAnimation.AddFrame(2, 1, Vector<int>(10, 0));
+ guyAttackAnimation.AddFrame(2, 2, Vector<int>(10, 0));
+ guyAttackAnimation.AddFrame(2, 2);
+ guy.SetAttackAnimation(&guyAttackAnimation);
SDL_Surface *dekarImg(IMG_Load("test-data/dekar.png"));
Sprite dekarSprite(dekarImg, 64, 64);
dekar.SetMaxMana(0);
dekar.SetMana(0);
dekar.SetIP(255);
- dekar.SetAttackFrames(3, 125);
- dekar.SetSpellFrames(3, 125);
+ ComplexAnimation dekarAttackAnimation(&dekarSprite, 30);
+ dekarAttackAnimation.AddFrame(1, 0, Vector<int>(4, 0));
+ dekarAttackAnimation.AddFrame(1, 0, Vector<int>(8, 2));
+ dekarAttackAnimation.AddFrame(2, 0, Vector<int>(12, 4));
+ dekarAttackAnimation.AddFrame(2, 0, Vector<int>(16, 4));
+ dekarAttackAnimation.AddFrames(2, 0, Vector<int>(10, 2), 4);
+ dekarAttackAnimation.AddFrame(2, 1, Vector<int>(6, 2));
+ dekarAttackAnimation.AddFrame(2, 1, Vector<int>());
+ dekarAttackAnimation.AddFrame(2, 2, Vector<int>(-2, 0));
+ dekarAttackAnimation.AddFrames(2, 2, Vector<int>(0, 0), 3);
+ dekar.SetAttackAnimation(&dekarAttackAnimation);
+ ComplexAnimation dekarSpellAnimation(&dekarSprite, 30);
+ dekarSpellAnimation.AddFrames(2, 0, Vector<int>(), 6);
+ dekarSpellAnimation.AddFrames(2, 1, Vector<int>(), 2);
+ dekarSpellAnimation.AddFrames(2, 2, Vector<int>(), 3);
+ dekar.SetSpellAnimation(&dekarSpellAnimation);
battle::Resources battleRes;