]> git.localhorst.tv Git - l2e.git/blob - src/battle/NumberAnimation.cpp
adjusted NumberAnimation to use animation runner
[l2e.git] / src / battle / NumberAnimation.cpp
1 /*
2  * NumberAnimation.cpp
3  *
4  *  Created on: Aug 12, 2012
5  *      Author: holy
6  */
7
8 #include "NumberAnimation.h"
9
10 #include "../geometry/operators.h"
11 #include "../geometry/Vector.h"
12
13 using app::State;
14 using geometry::Point;
15 using geometry::Vector;
16 using graphics::Animation;
17 using graphics::AnimationRunner;
18 using graphics::Sprite;
19
20 namespace battle {
21
22 NumberAnimation::NumberAnimation(int number, const Animation *a, const Sprite *numbers)
23 : number(number) {
24         animation[0] = AnimationRunner(a);
25         animation[1] = AnimationRunner(a);
26         animation[2] = AnimationRunner(a);
27         animation[3] = AnimationRunner(a);
28
29         animation[0].ChangeSprite(numbers);
30         animation[1].ChangeSprite(numbers);
31         animation[2].ChangeSprite(numbers);
32         animation[3].ChangeSprite(numbers);
33
34         if (number > 9999) {
35                 animation[0].SetColOffset(9);
36                 animation[1].SetColOffset(9);
37                 animation[2].SetColOffset(9);
38                 animation[3].SetColOffset(9);
39         } else {
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);
44         }
45 }
46
47 void NumberAnimation::Start(State &s) {
48         if (number > 999) {
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);
54         } else {
55                 animation[3].Start(s);
56         }
57 }
58
59 bool NumberAnimation::Running() const {
60         return animation[0].Running() || animation[1].Running() || animation[2].Running() || animation[3].Running();
61 }
62
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);
70         }
71 }
72
73
74 int NumberAnimation::Width() const {
75         if (number < 10) {
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();
81         } else {
82                 return 4 * animation[0].GetSprite()->Width();
83         }
84 }
85
86 int NumberAnimation::Height() const {
87         return animation[0].GetSprite()->Height();
88 }
89
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);
93         if (number > 999) {
94                 if (animation[0].Running()) {
95                         animation[0].Draw(dest, position);
96                 }
97                 position += step;
98         }
99         if (number > 99) {
100                 if (animation[1].Running() || animation[0].Running()) {
101                         animation[1].Draw(dest, position);
102                 }
103                 position += step;
104         }
105         if (number > 9) {
106                 if (animation[2].Running() || animation[1].Running() || animation[0].Running()) {
107                         animation[2].Draw(dest, position);
108                 }
109                 position += step;
110         }
111         if (animation[3].Running() || animation[2].Running() || animation[1].Running() || animation[0].Running()) {
112                 animation[3].Draw(dest, position);
113         }
114 }
115
116 }