4 * Created on: Aug 12, 2012
8 #include "NumberAnimation.h"
10 #include "../geometry/Vector.h"
13 using geometry::Vector;
14 using graphics::Animation;
15 using graphics::AnimationRunner;
16 using graphics::Sprite;
20 NumberAnimation::NumberAnimation(int number, const Animation *a, const Sprite *numbers)
22 animation[0] = AnimationRunner(a);
23 animation[1] = AnimationRunner(a);
24 animation[2] = AnimationRunner(a);
25 animation[3] = AnimationRunner(a);
27 animation[0].ChangeSprite(numbers);
28 animation[1].ChangeSprite(numbers);
29 animation[2].ChangeSprite(numbers);
30 animation[3].ChangeSprite(numbers);
33 animation[0].SetColOffset(9);
34 animation[1].SetColOffset(9);
35 animation[2].SetColOffset(9);
36 animation[3].SetColOffset(9);
38 animation[0].SetColOffset(number / 1000 % 10);
39 animation[1].SetColOffset(number / 100 % 10);
40 animation[2].SetColOffset(number / 10 % 10);
41 animation[3].SetColOffset(number % 10);
45 void NumberAnimation::Start(State &s) {
47 animation[0].Start(s);
48 } else if (number > 99) {
49 animation[1].Start(s);
50 } else if (number > 9) {
51 animation[2].Start(s);
53 animation[3].Start(s);
57 bool NumberAnimation::Running() const {
58 return animation[0].Running() || animation[1].Running() || animation[2].Running() || animation[3].Running();
61 void NumberAnimation::CheckTimers(State &s) {
62 if (animation[0].Running() && animation[0].Frame() == 1) {
63 animation[1].Start(s);
64 } else if (animation[1].Running() && animation[1].Frame() == 1) {
65 animation[2].Start(s);
66 } else if (animation[2].Running() && animation[2].Frame() == 1) {
67 animation[3].Start(s);
72 int NumberAnimation::Width() const {
74 return animation[0].GetSprite()->Width();
75 } else if (number < 100) {
76 return 2 * animation[0].GetSprite()->Width();
77 } else if (number < 1000) {
78 return 3 * animation[0].GetSprite()->Width();
80 return 4 * animation[0].GetSprite()->Width();
84 int NumberAnimation::Height() const {
85 return animation[0].GetSprite()->Height();
88 void NumberAnimation::Draw(SDL_Surface *dest, const Vector<int> &positionIn) const {
89 Vector<int> position(positionIn);
90 Vector<int> step(animation[0].GetSprite()->Width(), 0);
92 if (animation[0].Running()) {
93 animation[0].Draw(dest, position);
98 if (animation[1].Running() || animation[0].Running()) {
99 animation[1].Draw(dest, position);
104 if (animation[2].Running() || animation[1].Running() || animation[0].Running()) {
105 animation[2].Draw(dest, position);
109 if (animation[3].Running() || animation[2].Running() || animation[1].Running() || animation[0].Running()) {
110 animation[3].Draw(dest, position);