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 // TODO: get real hero/monster
118 foreignAnimations.push_back(battle->HeroAt(0).AttackAnimation());
119 battle->HeroAt(0).AttackAnimation()->Start(*state);
124 bool AttackAnimation::ExecuteSpellAnimation() {
125 // TODO: get real hero/monster
126 foreignAnimations.push_back(battle->HeroAt(0).SpellAnimation());
127 battle->HeroAt(0).SpellAnimation()->Start(*state);
132 bool AttackAnimation::ExecuteTargetAnimation() {
133 // TODO: get real positions
135 am.animation = (Animation *) text[cursor + 1].ptr;
136 am.animation->Start(*state);
137 am.position = Point<int>(100, 100);
138 animations.push_back(am);
143 bool AttackAnimation::ExecuteFullscreenAnimation() {
145 am.animation = (Animation *) text[cursor + 1].ptr;
146 am.animation->Start(*state);
147 am.position = Point<int>(0, 0);
148 animations.push_back(am);
154 bool AttackAnimation::Finished() const {
155 return cursor >= int(text.size());
158 void AttackAnimation::Render(SDL_Surface *screen, const geometry::Vector<int> &offset) const {
159 for (vector<AnimationMemo>::const_iterator i(animations.begin()), end(animations.end()); i != end; ++i) {
160 if (i->animation->Running()) {
161 i->animation->Draw(screen, i->position + offset);