-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.c
82 lines (69 loc) · 1.31 KB
/
main.c
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
#include "constants.h"
#include <stdbool.h>
Image crash;
Image ps1;
Image guardianWalk;
Image guardian;
int x = 0;
int y = 0;
int speed = 2;
bool walking = false;
int main() {
initialize();
while(1) {
update();
clearDisplay();
draw();
display();
}
}
void initialize() {
initializeScreen();
initializePad();
setBackgroundColor(createColor(0, 0, 0));
ps1 = createImage(img_ps1);
crash = createImage(img_crash);
guardianWalk = createImage(img_crash);
guardianWalk = moveImage(guardianWalk, 128, 112);
guardian = createImage(img_ps1);
guardian = moveImage(guardian, 128, 112);
}
void update() {
padUpdate();
if(padCheck(Pad1Up)) {
y += speed;
crash = moveImage(crash, x, y);
ps1 = moveImage(ps1, x, y);
}
if(padCheck(Pad1Down)) {
y -= speed;
crash = moveImage(crash, x, y);
ps1 = moveImage(ps1, x, y);
}
if(padCheck(Pad1Left)) {
x += speed;
crash = moveImage(crash, x, y);
ps1 = moveImage(ps1, x, y);
}
if(padCheck(Pad1Right)) {
x -= speed;
crash = moveImage(crash, x, y);
ps1 = moveImage(ps1, x, y);
}
if (padCheck(Pad1Right) || padCheck(Pad1Left) || padCheck(Pad1Up) || padCheck(Pad1Down)) {
walking = true;
}
else {
walking = false;
}
}
void draw() {
if (walking) {
drawImage(guardianWalk);
}
else {
drawImage(guardian);
}
drawImage(crash);
drawImage(ps1);
}