4 * Created on: Aug 13, 2012
8 #include "AttackAnimation.h"
10 #include "BattleState.h"
11 #include "../app/State.h"
12 #include "../graphics/Animation.h"
14 using geometry::Point;
15 using graphics::Animation;
20 AttackAnimation::~AttackAnimation() {
21 for (vector<AnimationMemo>::const_iterator i(animations.begin()), end(animations.end()); i != end; ++i) {
24 for (vector<Animation *>::const_iterator i(foreignAnimations.begin()), end(foreignAnimations.end()); i != end; ++i) {
30 void AttackAnimation::Wait(int ms) {
35 void AttackAnimation::WaitForAnimation() {
36 text.push_back(WAIT_ANIMATION);
39 void AttackAnimation::PlayAttackAnimation() {
40 text.push_back(ATTACK_ANIMATION);
43 void AttackAnimation::PlaySpellAnimation() {
44 text.push_back(SPELL_ANIMATION);
47 void AttackAnimation::PlayTargetAnimation(graphics::Animation *a) {
48 text.push_back(TARGET_ANIMATION);
52 void AttackAnimation::PlayFullscreenAnimation(graphics::Animation *a) {
53 text.push_back(FULLSCREEN_ANIMATION);
58 void AttackAnimation::Start(BattleState *b, app::State *s) {
65 void AttackAnimation::Update() {
67 if (ExecuteCommand()) break;
71 bool AttackAnimation::ExecuteCommand() {
72 switch (text[cursor].command) {
76 return ExecuteWaitAnimation();
77 case ATTACK_ANIMATION:
78 return ExecuteAttackAnimation();
80 return ExecuteSpellAnimation();
81 case TARGET_ANIMATION:
82 return ExecuteTargetAnimation();
83 case FULLSCREEN_ANIMATION:
84 return ExecuteFullscreenAnimation();
86 ++cursor; // skip unknown command (which should never happen anyway)
90 bool AttackAnimation::ExecuteWait() {
91 if (timer.Started()) {
92 if (timer.Running()) {
99 timer = state->GraphicsTimers().StartCountdown(text[cursor + 1].number);
105 bool AttackAnimation::ExecuteWaitAnimation() {
106 for (vector<AnimationMemo>::const_iterator i(animations.begin()), end(animations.end()); i != end; ++i) {
107 if (i->animation->Running()) return true;
109 for (vector<Animation *>::const_iterator i(foreignAnimations.begin()), end(foreignAnimations.end()); i != end; ++i) {
110 if ((*i)->Running()) return true;
116 bool AttackAnimation::ExecuteAttackAnimation() {
117 foreignAnimations.push_back(battle->HeroAt(0).AttackAnimation());
118 battle->HeroAt(0).AttackAnimation()->Start(*state);
123 bool AttackAnimation::ExecuteSpellAnimation() {
124 foreignAnimations.push_back(battle->HeroAt(0).SpellAnimation());
125 battle->HeroAt(0).SpellAnimation()->Start(*state);
130 bool AttackAnimation::ExecuteTargetAnimation() {
132 am.animation = (Animation *) text[cursor + 1].ptr;
133 am.animation->Start(*state);
134 am.position = Point<int>(100, 100);
135 animations.push_back(am);
140 bool AttackAnimation::ExecuteFullscreenAnimation() {
142 am.animation = (Animation *) text[cursor + 1].ptr;
143 am.animation->Start(*state);
144 am.position = Point<int>(100, 100);
145 animations.push_back(am);
151 bool AttackAnimation::Finished() const {
152 return cursor >= int(text.size());
155 void AttackAnimation::Render(SDL_Surface *screen, const geometry::Vector<int> &offset) const {
156 for (vector<AnimationMemo>::const_iterator i(animations.begin()), end(animations.end()); i != end; ++i) {
157 if (i->animation->Running()) {
158 i->animation->Draw(screen, i->position + offset);