-
Notifications
You must be signed in to change notification settings - Fork 1
/
animation.cpp
153 lines (123 loc) · 3.01 KB
/
animation.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
/*
* animation.cpp
*
* Created on: 2013-11-03
* Author: Liam
*/
#include "animation.h"
Animation::Animation():m_frames(NULL), m_currentcount(1), m_timer(0), m_maxtime(0), m_framecount(0), m_currentframe() {}
Animation::Animation(Image *frames, float maxtime, int framecount):m_currentcount(1), m_timer(0), m_maxtime(maxtime), m_framecount(framecount) {
m_frames = new Image[framecount];
for (int i = 0; i < framecount; ++i) {
m_frames[i] = frames[i];
}
m_currentframe = m_frames[0];
}
Animation::Animation(const Animation &src):m_currentcount(1), m_timer(0), m_maxtime(src.m_maxtime), m_framecount(src.m_framecount) {
m_frames = new Image[m_framecount];
for (int i = 0; i < m_framecount; ++i) {
m_frames[i] = src.m_frames[i];
}
m_currentframe = m_frames[0];
}
Animation &Animation::operator=(const Animation &src) {
m_timer = 0;
m_maxtime = src.m_maxtime;
m_framecount = src.m_framecount;
if (m_frames) {
delete [] m_frames;
}
m_frames = new Image[m_framecount];
for (int i = 0; i < m_framecount; ++i) {
m_frames[i] = src.m_frames[i];
}
m_currentframe = m_frames[0];
m_currentcount = 1;
return *this;
}
void Animation::update(float dt) {
m_timer += dt;
if (m_timer > m_maxtime / m_framecount) {
m_timer = 0;
m_currentcount += 1;
if (m_currentcount > m_framecount) {
m_currentcount = 1;
}
m_currentframe = m_frames[m_currentcount - 1];
}
}
Image &Animation::getImage() {
return m_currentframe;
}
Animation::~Animation() {
if (m_frames) {
delete [] m_frames;
}
}
CHAR playerLeft1Chars[] = {
255, 201, 255,
255, 254, 255,
98, 254, 98
};
CHAR playerLeft2Chars[] = {
255, 201, 255,
255, 254, 255,
255, 98, 255
};
CHAR playerLeft3Chars[] = {
255, 201, 255,
255, 254, 255,
98, 254, 98
};
CHAR playerLeft4Chars[] = {
255, 201, 255,
255, 254, 255,
255, 98, 255
};
CHAR playerRight1Chars[] = {
255, 187, 255,
255, 254, 255,
100, 254, 100
};
CHAR playerRight2Chars[] = {
255, 187, 255,
255, 254, 255,
255, 100, 255
};
CHAR playerRight3Chars[] = {
255, 187, 255,
255, 254, 255,
100, 254, 100
};
CHAR playerRight4Chars[] = {
255, 187, 255,
255, 254, 255,
255, 100, 255
};
COL playerCols[] = {
15 | BACKGROUND_BLUE, 15 | BACKGROUND_BLUE, 15 | BACKGROUND_BLUE,
15 | BACKGROUND_BLUE, 15 | BACKGROUND_BLUE, 15 | BACKGROUND_BLUE,
15 | BACKGROUND_BLUE, 15 | BACKGROUND_BLUE, 15 | BACKGROUND_BLUE
};
Image left1(3, 3, playerLeft1Chars, playerCols);
Image left2(3, 3, playerLeft2Chars, playerCols);
Image left3(3, 3, playerLeft3Chars, playerCols);
Image left4(3, 3, playerLeft4Chars, playerCols);
Image right1(3, 3, playerRight1Chars, playerCols);
Image right2(3, 3, playerRight2Chars, playerCols);
Image right3(3, 3, playerRight3Chars, playerCols);
Image right4(3, 3, playerRight4Chars, playerCols);
Image PLAYER_LEFT_FRAMES[4] = {
left1,
left2,
left3,
left4
};
Image PLAYER_RIGHT_FRAMES[4] = {
right1,
right2,
right3,
right4
};
const Animation PLAYER_RIGHT_ANIMATION(PLAYER_RIGHT_FRAMES, .5f, 4);
const Animation PLAYER_LEFT_ANIMATION(PLAYER_LEFT_FRAMES, .5f, 4);