]> git.localhorst.tv Git - l2e.git/blob - src/battle/NumberAnimation.cpp
removed stupid file headers that eclipse put in
[l2e.git] / src / battle / NumberAnimation.cpp
1 #include "NumberAnimation.h"
2
3 #include "../geometry/Vector.h"
4
5 using app::State;
6 using geometry::Vector;
7 using graphics::Animation;
8 using graphics::AnimationRunner;
9 using graphics::Sprite;
10
11 namespace battle {
12
13 NumberAnimation::NumberAnimation(int number, const Animation *a, const Sprite *numbers)
14 : number(number) {
15         animation[0] = AnimationRunner(a);
16         animation[1] = AnimationRunner(a);
17         animation[2] = AnimationRunner(a);
18         animation[3] = AnimationRunner(a);
19
20         animation[0].ChangeSprite(numbers);
21         animation[1].ChangeSprite(numbers);
22         animation[2].ChangeSprite(numbers);
23         animation[3].ChangeSprite(numbers);
24
25         if (number > 9999) {
26                 animation[0].SetColOffset(9);
27                 animation[1].SetColOffset(9);
28                 animation[2].SetColOffset(9);
29                 animation[3].SetColOffset(9);
30         } else {
31                 animation[0].SetColOffset(number / 1000 % 10);
32                 animation[1].SetColOffset(number / 100 % 10);
33                 animation[2].SetColOffset(number / 10 % 10);
34                 animation[3].SetColOffset(number % 10);
35         }
36 }
37
38 void NumberAnimation::Start(State &s) {
39         if (number > 999) {
40                 animation[0].Start(s);
41         } else if (number > 99) {
42                 animation[1].Start(s);
43         } else if (number > 9) {
44                 animation[2].Start(s);
45         } else {
46                 animation[3].Start(s);
47         }
48 }
49
50 bool NumberAnimation::Running() const {
51         return animation[0].Running() || animation[1].Running() || animation[2].Running() || animation[3].Running();
52 }
53
54 void NumberAnimation::CheckTimers(State &s) {
55         if (animation[0].Running() && animation[0].Frame() == 1) {
56                 animation[1].Start(s);
57         } else if (animation[1].Running() && animation[1].Frame() == 1) {
58                 animation[2].Start(s);
59         } else if (animation[2].Running() && animation[2].Frame() == 1) {
60                 animation[3].Start(s);
61         }
62 }
63
64
65 int NumberAnimation::Width() const {
66         if (number < 10) {
67                 return animation[0].GetSprite()->Width();
68         } else if (number < 100) {
69                 return 2 * animation[0].GetSprite()->Width();
70         } else if (number < 1000) {
71                 return 3 * animation[0].GetSprite()->Width();
72         } else {
73                 return 4 * animation[0].GetSprite()->Width();
74         }
75 }
76
77 int NumberAnimation::Height() const {
78         return animation[0].GetSprite()->Height();
79 }
80
81 void NumberAnimation::Draw(SDL_Surface *dest, const Vector<int> &positionIn) const {
82         Vector<int> position(positionIn);
83         Vector<int> step(animation[0].GetSprite()->Width(), 0);
84         if (number > 999) {
85                 if (animation[0].Running()) {
86                         animation[0].Draw(dest, position);
87                 }
88                 position += step;
89         }
90         if (number > 99) {
91                 if (animation[1].Running() || animation[0].Running()) {
92                         animation[1].Draw(dest, position);
93                 }
94                 position += step;
95         }
96         if (number > 9) {
97                 if (animation[2].Running() || animation[1].Running() || animation[0].Running()) {
98                         animation[2].Draw(dest, position);
99                 }
100                 position += step;
101         }
102         if (animation[3].Running() || animation[2].Running() || animation[1].Running() || animation[0].Running()) {
103                 animation[3].Draw(dest, position);
104         }
105 }
106
107 }