-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.c
235 lines (171 loc) · 4.71 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
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
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
// GBA Game
// Name: KASHYAP PATEL
#include "boo.h"
#include "ggwp.h"
#include "title.h"
#include "human.h"
#include "myLib.h"
#include "text.h"
#include <stdio.h>
#include <stdlib.h>
int score = 0;
char scoreStr[100];
int main() {
REG_DISPCNT = MODE_3 | BG2_ENABLE;
//game isn't over
int isGameOver = 0;
int reset = 0;
//distance b/w top humans and bot humans
int dist = 70;
//where boo starts
//boo size = 25x25
int boorow = 75;
int boocol = 130;
//how much to move boo per key prss
int boomoverow = 2;
int boomovecol = 2;
//human size = 11x17
//define top humans and bottom humans
HUMAN humans1[NUMHUMANS];
HUMAN humans2[NUMHUMANS];
int colsize = 218;
//define first human in top humans
humans1[0].row = 30;
humans1[0].col = 229;
//define first human in bot humans
humans2[0].row = humans1[0].row + dist;
humans2[0].col = humans1[0].col;
//define the rest of the humans
for (int i = 1; i < NUMHUMANS; i++) {
humans1[i].row = humans1[i - 1].row + rand() % 11 + (-5);
humans1[i].col = colsize;
colsize -= 11;
humans2[i].row = humans1[i].row + dist;
humans2[i].col = humans1[i].col;
}
//start the game
int start = 1;
//has the title been shown
int showedTitle = 0;
while (1) {
if (start) {
drawImage3(0, 0, TITLE_WIDTH, TITLE_HEIGHT, title);
showedTitle = 1;
}
if ((KEY_DOWN_NOW(BUTTON_A) & showedTitle) || (reset)) {
reset = 0;
start = 0;
showedTitle = 0;
isGameOver = 0;
clear();
score = 0;
boorow = 75;
boocol = 130;
drawImage3(boorow, boocol, BOO_WIDTH, BOO_HEIGHT, boo);
drawString(5, 160, "Score: ", YELLOW);
}
if (!showedTitle && !isGameOver) {
score++;
clearScore();
sprintf(scoreStr, "%d", score);
drawString(5, 200, scoreStr, YELLOW);
for (int i = 0; i < NUMHUMANS; i++) {
drawImage3(humans1[i].row, humans1[i].col, HUMAN_WIDTH, HUMAN_HEIGHT, human);
drawImage3(humans2[i].row, humans2[i].col, HUMAN_WIDTH, HUMAN_HEIGHT, human);
}
if (boocol <= 15) {
boocol = 15;
drawRect(0, 0, 15, 160, BLACK);
}
if (boocol + BOO_WIDTH >= 239) {
boocol = 239 - BOO_WIDTH;
drawRect(0, 234, 15, 160, BLACK);
}
waitForVblank();
if (score % 10 == 0) {
for (int i = 20; i > 0; i--) {
clearHuman(humans1[i].row, humans1[i].col);
humans1[i].row = humans1[i - 1].row;
clearHuman(humans2[i].row, humans2[i].col);
humans2[i].row = humans1[i].row + dist;
}
clearHuman(humans1[0].row, humans1[0].col);
clearHuman(humans2[0].row, humans2[0].col);
if (humans1[0].row >= 30) {
humans1[0].row = humans1[0].row + rand() % 17 + (-8);
} else {
humans1[0].row = 30;
}
if (humans1[0].row <= 70) {
humans1[0].row = humans1[0].row + rand() % 17 + (-8);
} else {
humans1[0].row = 70;
}
humans2[0].row = humans1[0].row + dist;
}
if (KEY_DOWN_NOW(BUTTON_UP)) {
clearBoo(boorow, boocol);
boorow -= boomoverow;
drawImage3(boorow, boocol, BOO_WIDTH, BOO_HEIGHT, boo);
}
if (KEY_DOWN_NOW(BUTTON_DOWN)) {
clearBoo(boorow, boocol);
boorow += boomoverow;
drawImage3(boorow, boocol, BOO_WIDTH, BOO_HEIGHT, boo);
}
if (KEY_DOWN_NOW(BUTTON_LEFT)) {
clearBoo(boorow, boocol);
boocol -= boomovecol;
drawImage3(boorow, boocol, BOO_WIDTH, BOO_HEIGHT, boo);
}
if (KEY_DOWN_NOW(BUTTON_RIGHT)) {
clearBoo(boorow, boocol);
boocol += boomovecol;
drawImage3(boorow, boocol, BOO_WIDTH, BOO_HEIGHT, boo);
}
if (KEY_DOWN_NOW(BUTTON_SELECT)) {
start = 1;
}
for (int i = 0; i < NUMHUMANS; i++) {
if ((boocol > 228 - (13 * i)) && (boocol < 239 - (12 * i))) {
if ((boorow - 1 <= humans1[i].row + HUMAN_HEIGHT) || (boorow + BOO_HEIGHT + 1 >= humans2[i].row)) {
for (int i = 0; i < NUMHUMANS; i++) {
clearHuman(humans1[i].row, humans1[i].col);
clearHuman(humans2[i].row, humans2[i].col);
humans1[i].row = 40;
humans2[i].row = humans2[i].row + dist;
}
clear();
gameOver(score);
isGameOver = 1;
}
}
}
}
if (KEY_DOWN_NOW(BUTTON_A) && isGameOver) {
reset = 1;
isGameOver = 0;
}
}
return 0;
}
void clear() {
drawRect(0, 0, 240, 160, BLACK);
}
void clearHuman(int row, int col) {
drawRect(row, col, HUMAN_WIDTH, HUMAN_HEIGHT, BLACK);
}
void clearBoo(int row, int col) {
drawRect(row, col, BOO_WIDTH, BOO_WIDTH, BLACK);
}
void clearScore() {
drawRect(5, 200, 40, 10, BLACK);
}
void gameOver() {
clear();
drawImage3(0, 0, GGWP_WIDTH, GGWP_HEIGHT, ggwp);
drawString(120, 70, "Final Score: ", YELLOW);
sprintf(scoreStr, "%d", score);
drawString(120, 145, scoreStr, YELLOW);
drawString(130, 45, "(Press A to Start Over)", YELLOW);
}