-
Notifications
You must be signed in to change notification settings - Fork 1
/
Animation.h
68 lines (55 loc) · 910 Bytes
/
Animation.h
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
#ifndef __ANIMATION_H__
#define __ANIMATION_H__
#include "SDL/include/SDL_rect.h"
#define MAX_FRAMES 25
class Animation
{
public:
bool loop = true;
float speed = 1.0f;
SDL_Rect frames[MAX_FRAMES];
private:
float current_frame;
int last_frame = 0;
int loops = 0;
public:
void PushBack(const SDL_Rect& rect)
{
frames[last_frame++] = rect;
}
SDL_Rect& GetCurrentFrame()
{
current_frame += speed;
if (current_frame >= last_frame)
{
current_frame = (loop) ? 0.0f : last_frame - 1;
loops++;
}
return frames[(int)current_frame];
}
bool Finished() const
{
return loops > 0;
}
void Reset()
{
current_frame = 0;
loops = 0;
}
void setFrame(int frame) {
current_frame = frame;
loops = 0.0;
}
int getFrame() {
return current_frame;
}
bool islastframe() {
if (current_frame >= last_frame-1) {
return true;
}
else {
return false;
}
}
};
#endif