-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.c
91 lines (81 loc) · 1.99 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
#include "main.h"
#include "draw.h"
#include "gba.h"
#include "logic.h"
#include <stdio.h>
#include <stdlib.h>
enum gba_state {
START,
TITLE,
INIT_PLAY,
PLAY,
INIT_WIN,
WIN,
LOSE,
};
int main(void) {
// Manipulate REG_DISPCNT here to set Mode 3. //
REG_DISPCNT = 0x403;
// Save current and previous state of button input.
u32 previousButtons = BUTTONS;
u32 currentButtons = BUTTONS;
// Load initial application state
enum gba_state state = START;
// Create player struct
// PLAYER player;
while (1) {
currentButtons = BUTTONS; // Load the current state of the buttons
if (KEY_DOWN(BUTTON_SELECT, currentButtons)) {
state = START;
}
switch (state) {
case START:
waitForVBlank();
drawTitleScreen();
state = TITLE; // go to title screen after startup
break;
case TITLE:
// if press anykey -> go to PLAY
drawTitleMessage();
if (KEY_JUST_PRESSED(ANY_KEY, currentButtons, previousButtons)) {
state = INIT_PLAY;
}
break;
case INIT_PLAY: // we have these init states to prevent having to rewrite static images
// Set up play screen and then go to PLAY
waitForVBlank();
drawGameBackground();
waitForVBlank();
initPlayer();
waitForVBlank();
initBoss();
initBullets(); // Just sets up the bullet structs in the array
state = PLAY;
break;
case PLAY:
waitForVBlank();
moveSprites();
updateLasers();
updateScore();
if (updateBullets()) {
state = LOSE;
}
if (checkWin()) {
state = INIT_WIN;
}
break;
case INIT_WIN:
waitForVBlank();
drawTitleScreen();
drawWinMessage();
state = WIN;
case WIN:
break;
case LOSE:
loseScreen();
break;
}
previousButtons = currentButtons; // Store the current state of the buttons
}
return 0;
}