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::ComplexAnimation;
17 using graphics::Sprite;
21 NumberAnimation::NumberAnimation(int number, const ComplexAnimation &a, const Sprite *numbers)
28 animation[0].ChangeSprite(numbers);
29 animation[1].ChangeSprite(numbers);
30 animation[2].ChangeSprite(numbers);
31 animation[3].ChangeSprite(numbers);
34 animation[0].SetColOffset(9);
35 animation[1].SetColOffset(9);
36 animation[2].SetColOffset(9);
37 animation[3].SetColOffset(9);
39 animation[0].SetColOffset(number / 1000 % 10);
40 animation[1].SetColOffset(number / 100 % 10);
41 animation[2].SetColOffset(number / 10 % 10);
42 animation[3].SetColOffset(number % 10);
46 void NumberAnimation::Start(State &s) {
48 animation[0].Start(s);
49 } else if (number > 99) {
50 animation[1].Start(s);
51 } else if (number > 9) {
52 animation[2].Start(s);
54 animation[3].Start(s);
58 bool NumberAnimation::Running() const {
59 return animation[0].Running() || animation[1].Running() || animation[2].Running() || animation[3].Running();
62 void NumberAnimation::CheckTimers(State &s) {
63 if (animation[0].Running() && animation[0].Frame() == 1) {
64 animation[1].Start(s);
65 } else if (animation[1].Running() && animation[1].Frame() == 1) {
66 animation[2].Start(s);
67 } else if (animation[2].Running() && animation[2].Frame() == 1) {
68 animation[3].Start(s);
73 int NumberAnimation::Width() const {
75 return animation[0].GetSprite()->Width();
76 } else if (number < 100) {
77 return 2 * animation[0].GetSprite()->Width();
78 } else if (number < 1000) {
79 return 3 * animation[0].GetSprite()->Width();
81 return 4 * animation[0].GetSprite()->Width();
85 int NumberAnimation::Height() const {
86 return animation[0].GetSprite()->Height();
89 void NumberAnimation::Draw(SDL_Surface *dest, const Point<int> &positionIn) const {
90 Point<int> position(positionIn);
91 Vector<int> step(animation[0].GetSprite()->Width(), 0);
93 if (animation[0].Running()) {
94 animation[0].Draw(dest, position);
99 if (animation[1].Running() || animation[0].Running()) {
100 animation[1].Draw(dest, position);
105 if (animation[2].Running() || animation[1].Running() || animation[0].Running()) {
106 animation[2].Draw(dest, position);
110 if (animation[3].Running() || animation[2].Running() || animation[1].Running() || animation[0].Running()) {
111 animation[3].Draw(dest, position);