-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.c
executable file
·147 lines (124 loc) · 2.58 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
#include <stdlib.h>
#include "myLib.h"
#include "game.h"
// Prototypes
void initialize();
void startState();
void winState();
void pauseState();
void loseState();
void gameState();
// State Prototypes
void startState();
void goToStart();
void gameState();
void goToGame();
void pauseState();
void goToPause();
void winState();
void goToWin();
void loseState();
void goToLose();
// States
enum {START, GAME, PAUSE, WIN, LOSE};
int state;
// Button Variables
unsigned short buttons;
unsigned short oldButtons;
// Random Seed
int seed;
int main() {
initialize();
while(1) {
// Update button variables
oldButtons = buttons;
buttons = BUTTONS;
// State Machine
switch(state) {
case START:
startState();
break;
case GAME:
gameState();
break;
case PAUSE:
pauseState();
break;
case WIN:
winState();
break;
case LOSE:
loseState();
break;
}
}
}
// the following functions up GBA states //
void initialize() {
REG_DISPCTL = MODE3 | BG2_ENABLE;
goToStart();
}
void startState(){
seed++;
if (BUTTON_PRESSED(BUTTON_START)) {
goToGame();
srand(seed);
initGame();
}
}
void goToStart() {
fillScreen(WHITE);
drawString(80, 100, "START", BLACK);
state = START;
}
void gameState() {
updateGame();
waitForVBlank();
drawGame();
if (BUTTON_PRESSED(BUTTON_START)) {
goToPause();
}
if (BUTTON_PRESSED(BUTTON_B)) {
goToLose();
}
if (goalsRemaining == 0) {
goToWin();
}
}
void goToGame() {
fillScreen(DARKBLUE);
state = GAME;
}
void pauseState() {
if (BUTTON_PRESSED(BUTTON_START)) {
goToGame();
}
if (BUTTON_PRESSED(BUTTON_SELECT)) {
goToStart();
}
}
void goToPause() {
fillScreen(BABY);
drawString(80, 100, "PAUSE", WHITE);
state = PAUSE;
}
void winState() {
if (BUTTON_PRESSED(BUTTON_START)) {
goToStart();
}
}
void goToWin() {
fillScreen(TEAL);
drawString(80, 100, "YOU WIN!", BABY);
state = WIN;
}
void loseState() {
if (BUTTON_PRESSED(BUTTON_START)) {
goToStart();
}
}
void goToLose() {
fillScreen(PINK);
drawString(80, 100, "YOU LOSE!", WHITE);
state = LOSE;
}