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::StartTimer(int ms) {
31 text.push_back(START_TIMER);
35 void AttackAnimation::PlayAttackAnimation() {
36 text.push_back(ATTACK_ANIMATION);
39 void AttackAnimation::PlaySpellAnimation() {
40 text.push_back(SPELL_ANIMATION);
43 void AttackAnimation::PlayTargetAnimation(graphics::Animation *a) {
44 text.push_back(TARGET_ANIMATION);
48 void AttackAnimation::PlayFullscreenAnimation(graphics::Animation *a) {
49 text.push_back(FULLSCREEN_ANIMATION);
53 void AttackAnimation::WaitForTimer() {
54 text.push_back(WAIT_TIMER);
57 void AttackAnimation::WaitForAnimations() {
58 text.push_back(WAIT_ANIMATIONS);
62 void AttackAnimation::Start(BattleState *b, app::State *s) {
69 void AttackAnimation::Update() {
71 if (ExecuteCommand()) break;
75 bool AttackAnimation::ExecuteCommand() {
76 switch (text[cursor].command) {
80 return ExecuteStartTimer();
81 case ATTACK_ANIMATION:
82 return ExecuteAttackAnimation();
84 return ExecuteSpellAnimation();
85 case TARGET_ANIMATION:
86 return ExecuteTargetAnimation();
87 case FULLSCREEN_ANIMATION:
88 return ExecuteFullscreenAnimation();
90 return ExecuteWaitTimer();
92 return ExecuteWaitAnimations();
94 ++cursor; // skip unknown command (which should never happen anyway)
99 bool AttackAnimation::ExecuteStartTimer() {
100 timer = state->GraphicsTimers().StartCountdown(text[cursor + 1].number);
105 bool AttackAnimation::ExecuteAttackAnimation() {
106 // TODO: get real hero/monster
107 foreignAnimations.push_back(battle->HeroAt(0).AttackAnimation());
108 battle->HeroAt(0).AttackAnimation()->Start(*state);
113 bool AttackAnimation::ExecuteSpellAnimation() {
114 // TODO: get real hero/monster
115 foreignAnimations.push_back(battle->HeroAt(0).SpellAnimation());
116 battle->HeroAt(0).SpellAnimation()->Start(*state);
121 bool AttackAnimation::ExecuteTargetAnimation() {
122 // TODO: get real positions
124 am.animation = (Animation *) text[cursor + 1].ptr;
125 am.animation->Start(*state);
126 am.position = Point<int>(100, 100);
127 animations.push_back(am);
132 bool AttackAnimation::ExecuteFullscreenAnimation() {
134 am.animation = (Animation *) text[cursor + 1].ptr;
135 am.animation->Start(*state);
136 am.position = Point<int>(0, 0);
137 animations.push_back(am);
142 bool AttackAnimation::ExecuteWaitTimer() {
143 if (timer.Running()) {
151 bool AttackAnimation::ExecuteWaitAnimations() {
152 for (vector<AnimationMemo>::const_iterator i(animations.begin()), end(animations.end()); i != end; ++i) {
153 if (i->animation->Running()) return true;
155 for (vector<Animation *>::const_iterator i(foreignAnimations.begin()), end(foreignAnimations.end()); i != end; ++i) {
156 if ((*i)->Running()) return true;
163 bool AttackAnimation::Finished() const {
164 return cursor >= int(text.size());
167 void AttackAnimation::Render(SDL_Surface *screen, const geometry::Vector<int> &offset) const {
168 for (vector<AnimationMemo>::const_iterator i(animations.begin()), end(animations.end()); i != end; ++i) {
169 if (i->animation->Running()) {
170 i->animation->Draw(screen, i->position + offset);