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