-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.c
executable file
·143 lines (107 loc) · 4.06 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
#include "gba.h"
#include "logic.h"
#include "draw.h"
// TA-TODO: Include any header files for title screen or exit
// screen images generated by nin10kit. Example for the provided garbage
// image:
// #include "images/garbage.h"
#include <stdio.h>
#include <stdlib.h>
#include "images/start_screen.h"
#include "images/garbage.h"
// AppState enum definition
typedef enum {
// TA-TODO: Add any additional states you need for your app.
START,
START_NODRAW,
APP_INIT,
APP,
APP_EXIT,
APP_EXIT_NODRAW,
} GBAState;
int main(void) {
// TA-TODO: Manipulate REG_DISPCNT here to set Mode 3.
REG_DISPCNT = MODE3 | BG2_ENABLE;
GBAState state = START;
// We store the "previous" and "current" states.
AppState currentAppState, nextAppState;
// We store the current and previous values of the button input.
u32 previousButtons = BUTTONS;
u32 currentButtons = BUTTONS;
while (1) {
// Load the current state of the buttons
currentButtons = BUTTONS;
if (currentAppState.win && !currentAppState.gameOver) {
initializeAppState(¤tAppState);
state = START;
}
// TA-TODO: Manipulate the state machine below as needed.
switch(state) {
case START:
// Wait for VBlank
waitForVBlank();
// TA-TODO: Draw the start state here.
drawFullScreenImageDMA(start_screen);
drawRectDMA(153, 145, 50, 2, BACKGROUND);
drawRectDMA(147, 200, 30, 13, RED);
drawString(200, 150, "Malek", WHITE);
state = START_NODRAW;
break;
case START_NODRAW:
// TA-TODO: Check for a button press here to start the app.
// Start the app by switching the state to APP_INIT.
for (int i = 0; i < 10; i++) {
if (KEY_JUST_PRESSED((1<<i), currentButtons, previousButtons)) {
state = APP_INIT;
break;
}
}
break;
case APP_INIT:
fillScreenDMA(BACKGROUND);
// drawGround(&ground);
//drawMario(&mario);
// drawBlock(&block);
// Initialize the app. Switch to the APP state.
initializeAppState(¤tAppState);
// Draw the initial state of the app
fullDrawAppState(¤tAppState);
state = APP;
break;
case APP:
// Process the app for one frame, store the next state
nextAppState = processAppState(¤tAppState, previousButtons, currentButtons);
// Wait for VBlank before we do any drawing.
waitForVBlank();
// Undraw the previous state
undrawAppState(&nextAppState);
// Draw the current state
drawAppState(&nextAppState);
// Now set the current state as the next state for the next iter.
currentAppState = nextAppState;
// Check if the app is exiting. If it is, then go to the exit state.
if (nextAppState.gameOver) {
state = APP_EXIT;
}
break;
case APP_EXIT:
// Wait for VBlank
waitForVBlank();
// TA-TODO: Draw the exit / gameover screen
state = APP_EXIT_NODRAW;
break;
case APP_EXIT_NODRAW:
// TA-TODO: Check for a button press here to go back to the start screen
for (int i = 0; i < 10; i++) {
if (KEY_JUST_PRESSED((1<<i), currentButtons, previousButtons)) {
state = START;
break;
}
}
break;
}
// Store the current state of the buttons
previousButtons = currentButtons;
}
return 0;
}