1 #include "NumberAnimation.h"
3 #include "../math/Vector.h"
4 #include "../graphics/Sprite.h"
8 using graphics::Animation;
9 using graphics::AnimationRunner;
10 using graphics::Sprite;
14 NumberAnimation::NumberAnimation(int number, const Animation *a, const Sprite *numbers)
16 animation[0] = AnimationRunner(a);
17 animation[1] = AnimationRunner(a);
18 animation[2] = AnimationRunner(a);
19 animation[3] = AnimationRunner(a);
21 animation[0].ChangeSprite(numbers);
22 animation[1].ChangeSprite(numbers);
23 animation[2].ChangeSprite(numbers);
24 animation[3].ChangeSprite(numbers);
27 animation[0].SetColOffset(9);
28 animation[1].SetColOffset(9);
29 animation[2].SetColOffset(9);
30 animation[3].SetColOffset(9);
32 animation[0].SetColOffset(number / 1000 % 10);
33 animation[1].SetColOffset(number / 100 % 10);
34 animation[2].SetColOffset(number / 10 % 10);
35 animation[3].SetColOffset(number % 10);
39 void NumberAnimation::Start(State &s) {
41 animation[0].Start(s);
42 } else if (number > 99) {
43 animation[1].Start(s);
44 } else if (number > 9) {
45 animation[2].Start(s);
47 animation[3].Start(s);
51 bool NumberAnimation::Running() const {
52 return animation[0].Running() || animation[1].Running() || animation[2].Running() || animation[3].Running();
55 void NumberAnimation::CheckTimers(State &s) {
56 if (animation[0].Running() && animation[0].Frame() == 1) {
57 animation[1].Start(s);
58 } else if (animation[1].Running() && animation[1].Frame() == 1) {
59 animation[2].Start(s);
60 } else if (animation[2].Running() && animation[2].Frame() == 1) {
61 animation[3].Start(s);
66 int NumberAnimation::Width() const {
68 return animation[0].GetSprite()->Width();
69 } else if (number < 100) {
70 return 2 * animation[0].GetSprite()->Width();
71 } else if (number < 1000) {
72 return 3 * animation[0].GetSprite()->Width();
74 return 4 * animation[0].GetSprite()->Width();
78 int NumberAnimation::Height() const {
79 return animation[0].GetSprite()->Height();
82 void NumberAnimation::Draw(SDL_Surface *dest, const Vector<int> &positionIn) const {
83 Vector<int> position(positionIn);
84 Vector<int> step(animation[0].GetSprite()->Width(), 0);
86 if (animation[0].Running()) {
87 animation[0].Draw(dest, position);
92 if (animation[1].Running() || animation[0].Running()) {
93 animation[1].Draw(dest, position);
98 if (animation[2].Running() || animation[1].Running() || animation[0].Running()) {
99 animation[2].Draw(dest, position);
103 if (animation[3].Running() || animation[2].Running() || animation[1].Running() || animation[0].Running()) {
104 animation[3].Draw(dest, position);