]> git.localhorst.tv Git - l2e.git/blob - src/battle/NumberAnimation.cpp
fcc707f7802e25f28c4bc2a4751d6abbd741e332
[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/Vector.h"
11
12 using app::State;
13 using geometry::Vector;
14 using graphics::Animation;
15 using graphics::AnimationRunner;
16 using graphics::Sprite;
17
18 namespace battle {
19
20 NumberAnimation::NumberAnimation(int number, const Animation *a, const Sprite *numbers)
21 : number(number) {
22         animation[0] = AnimationRunner(a);
23         animation[1] = AnimationRunner(a);
24         animation[2] = AnimationRunner(a);
25         animation[3] = AnimationRunner(a);
26
27         animation[0].ChangeSprite(numbers);
28         animation[1].ChangeSprite(numbers);
29         animation[2].ChangeSprite(numbers);
30         animation[3].ChangeSprite(numbers);
31
32         if (number > 9999) {
33                 animation[0].SetColOffset(9);
34                 animation[1].SetColOffset(9);
35                 animation[2].SetColOffset(9);
36                 animation[3].SetColOffset(9);
37         } else {
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);
42         }
43 }
44
45 void NumberAnimation::Start(State &s) {
46         if (number > 999) {
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);
52         } else {
53                 animation[3].Start(s);
54         }
55 }
56
57 bool NumberAnimation::Running() const {
58         return animation[0].Running() || animation[1].Running() || animation[2].Running() || animation[3].Running();
59 }
60
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);
68         }
69 }
70
71
72 int NumberAnimation::Width() const {
73         if (number < 10) {
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();
79         } else {
80                 return 4 * animation[0].GetSprite()->Width();
81         }
82 }
83
84 int NumberAnimation::Height() const {
85         return animation[0].GetSprite()->Height();
86 }
87
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);
91         if (number > 999) {
92                 if (animation[0].Running()) {
93                         animation[0].Draw(dest, position);
94                 }
95                 position += step;
96         }
97         if (number > 99) {
98                 if (animation[1].Running() || animation[0].Running()) {
99                         animation[1].Draw(dest, position);
100                 }
101                 position += step;
102         }
103         if (number > 9) {
104                 if (animation[2].Running() || animation[1].Running() || animation[0].Running()) {
105                         animation[2].Draw(dest, position);
106                 }
107                 position += step;
108         }
109         if (animation[3].Running() || animation[2].Running() || animation[1].Running() || animation[0].Running()) {
110                 animation[3].Draw(dest, position);
111         }
112 }
113
114 }