4 * Created on: Aug 12, 2012
8 #include "NumberAnimation.h"
10 #include "../geometry/operators.h"
11 #include "../geometry/Vector.h"
14 using geometry::Point;
15 using geometry::Vector;
16 using graphics::Animation;
17 using graphics::AnimationRunner;
18 using graphics::Sprite;
22 NumberAnimation::NumberAnimation(int number, const Animation *a, const Sprite *numbers)
24 animation[0] = AnimationRunner(a);
25 animation[1] = AnimationRunner(a);
26 animation[2] = AnimationRunner(a);
27 animation[3] = AnimationRunner(a);
29 animation[0].ChangeSprite(numbers);
30 animation[1].ChangeSprite(numbers);
31 animation[2].ChangeSprite(numbers);
32 animation[3].ChangeSprite(numbers);
35 animation[0].SetColOffset(9);
36 animation[1].SetColOffset(9);
37 animation[2].SetColOffset(9);
38 animation[3].SetColOffset(9);
40 animation[0].SetColOffset(number / 1000 % 10);
41 animation[1].SetColOffset(number / 100 % 10);
42 animation[2].SetColOffset(number / 10 % 10);
43 animation[3].SetColOffset(number % 10);
47 void NumberAnimation::Start(State &s) {
49 animation[0].Start(s);
50 } else if (number > 99) {
51 animation[1].Start(s);
52 } else if (number > 9) {
53 animation[2].Start(s);
55 animation[3].Start(s);
59 bool NumberAnimation::Running() const {
60 return animation[0].Running() || animation[1].Running() || animation[2].Running() || animation[3].Running();
63 void NumberAnimation::CheckTimers(State &s) {
64 if (animation[0].Running() && animation[0].Frame() == 1) {
65 animation[1].Start(s);
66 } else if (animation[1].Running() && animation[1].Frame() == 1) {
67 animation[2].Start(s);
68 } else if (animation[2].Running() && animation[2].Frame() == 1) {
69 animation[3].Start(s);
74 int NumberAnimation::Width() const {
76 return animation[0].GetSprite()->Width();
77 } else if (number < 100) {
78 return 2 * animation[0].GetSprite()->Width();
79 } else if (number < 1000) {
80 return 3 * animation[0].GetSprite()->Width();
82 return 4 * animation[0].GetSprite()->Width();
86 int NumberAnimation::Height() const {
87 return animation[0].GetSprite()->Height();
90 void NumberAnimation::Draw(SDL_Surface *dest, const Point<int> &positionIn) const {
91 Point<int> position(positionIn);
92 Vector<int> step(animation[0].GetSprite()->Width(), 0);
94 if (animation[0].Running()) {
95 animation[0].Draw(dest, position);
100 if (animation[1].Running() || animation[0].Running()) {
101 animation[1].Draw(dest, position);
106 if (animation[2].Running() || animation[1].Running() || animation[0].Running()) {
107 animation[2].Draw(dest, position);
111 if (animation[3].Running() || animation[2].Running() || animation[1].Running() || animation[0].Running()) {
112 animation[3].Draw(dest, position);