-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathChym.h
94 lines (77 loc) · 1.29 KB
/
Chym.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
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
class Chym {
private:
int frameCount;
int x;
int y;
int deltaIde;
int delayFrame;
int jumpCount;
int maxJumpCount;
int moveSpeed;
bool _isDead;
public:
void respawn() {
x = 24;
y = 20;
deltaIde = -1;
moveSpeed = 1;
jumpCount = 0;
_isDead = false;
}
Chym() {
frameCount = 0;
delayFrame = 0;
maxJumpCount = 20;
respawn();
}
void render() {
if (frameCount < ANIM_FRAME / 2) {
display.drawBitmap(x, y, flappybird_frame_1, 16, 12, 1);
}
else {
display.drawBitmap(x, y, flappybird_frame_2, 16, 12, 1);
}
}
void update() {
delayFrame++;
if (delayFrame == DELAY_FRAME) {
y += deltaIde * moveSpeed;
delayFrame = 0;
}
if (y > 35) {
_isDead = true;
}
frameCount++;
if (frameCount >= ANIM_FRAME) frameCount = 0;
}
bool isDead() {
return _isDead;
}
void die() {
_isDead = true;
}
void cancelJump() {
jumpCount = 0;
flyDown();
}
void flyUp() {
if (jumpCount < maxJumpCount) {
deltaIde = -1;
moveSpeed = 3;
jumpCount++;
}
else {
flyDown();
}
}
void flyDown() {
deltaIde = 1;
moveSpeed = 1;
}
int getX() {
return x;
}
int getY() {
return y;
}
};