mirror of
https://gitlab.com/dosowisko.net/libsuperderpy.git
synced 2025-02-08 06:06:43 +01:00
moar macros
This commit is contained in:
parent
3d50b5d3a4
commit
c215af797d
1 changed files with 26 additions and 45 deletions
55
src/main.c
55
src/main.c
|
@ -14,6 +14,9 @@
|
||||||
PrintConsole(game, "Unload %s...", #state); name ## _Unload(game); break;
|
PrintConsole(game, "Unload %s...", #state); name ## _Unload(game); break;
|
||||||
#define LOAD_STATE(state, name) case state:\
|
#define LOAD_STATE(state, name) case state:\
|
||||||
PrintConsole(game, "Load %s...", #state); name ## _Load(game); break;
|
PrintConsole(game, "Load %s...", #state); name ## _Load(game); break;
|
||||||
|
#define KEYDOWN_STATE(state, name) else if (game.gamestate==state) { if (name ## _Keydown(&game, &ev)) break; }
|
||||||
|
#define DRAW_STATE(state, name) case state:\
|
||||||
|
name ## _Draw(&game); break;
|
||||||
|
|
||||||
float FPS = 60;
|
float FPS = 60;
|
||||||
int DISPLAY_WIDTH = 800;
|
int DISPLAY_WIDTH = 800;
|
||||||
|
@ -206,24 +209,12 @@ int main(int argc, char **argv){
|
||||||
if ((ev.type == ALLEGRO_EVENT_KEY_DOWN) && (ev.keyboard.keycode == ALLEGRO_KEY_TILDE)) {
|
if ((ev.type == ALLEGRO_EVENT_KEY_DOWN) && (ev.keyboard.keycode == ALLEGRO_KEY_TILDE)) {
|
||||||
game.showconsole = !game.showconsole;
|
game.showconsole = !game.showconsole;
|
||||||
}
|
}
|
||||||
else if (game.gamestate==GAMESTATE_LOADING) {
|
KEYDOWN_STATE(GAMESTATE_MENU, Menu)
|
||||||
if (Loading_Keydown(&game, &ev)) break;
|
KEYDOWN_STATE(GAMESTATE_LOADING, Loading)
|
||||||
}
|
KEYDOWN_STATE(GAMESTATE_ABOUT, About)
|
||||||
else if (game.gamestate==GAMESTATE_MENU) {
|
KEYDOWN_STATE(GAMESTATE_INTRO, Intro)
|
||||||
if (Menu_Keydown(&game, &ev)) break;
|
KEYDOWN_STATE(GAMESTATE_MAP, Map)
|
||||||
}
|
KEYDOWN_STATE(GAMESTATE_LEVEL, Level)
|
||||||
else if (game.gamestate==GAMESTATE_ABOUT) {
|
|
||||||
if (About_Keydown(&game, &ev)) break;
|
|
||||||
}
|
|
||||||
else if (game.gamestate==GAMESTATE_INTRO) {
|
|
||||||
if (Intro_Keydown(&game, &ev)) break;
|
|
||||||
}
|
|
||||||
else if (game.gamestate==GAMESTATE_MAP) {
|
|
||||||
if (Map_Keydown(&game, &ev)) break;
|
|
||||||
}
|
|
||||||
else if (game.gamestate==GAMESTATE_LEVEL) {
|
|
||||||
if (Level_Keydown(&game, &ev)) break;
|
|
||||||
}
|
|
||||||
else {
|
else {
|
||||||
game.showconsole = true;
|
game.showconsole = true;
|
||||||
PrintConsole(&game, "ERROR: Keystroke in unknown (%d) gamestate! (5 sec sleep)", game.gamestate);
|
PrintConsole(&game, "ERROR: Keystroke in unknown (%d) gamestate! (5 sec sleep)", game.gamestate);
|
||||||
|
@ -238,25 +229,14 @@ int main(int argc, char **argv){
|
||||||
|
|
||||||
if(redraw && al_is_event_queue_empty(game.event_queue)) {
|
if(redraw && al_is_event_queue_empty(game.event_queue)) {
|
||||||
redraw = false;
|
redraw = false;
|
||||||
if (game.gamestate==GAMESTATE_LOADING) {
|
switch (game.gamestate) {
|
||||||
Loading_Draw(&game);
|
DRAW_STATE(GAMESTATE_MENU, Menu)
|
||||||
}
|
DRAW_STATE(GAMESTATE_LOADING, Loading)
|
||||||
else if (game.gamestate==GAMESTATE_MENU) {
|
DRAW_STATE(GAMESTATE_ABOUT, About)
|
||||||
Menu_Draw(&game);
|
DRAW_STATE(GAMESTATE_INTRO, Intro)
|
||||||
}
|
DRAW_STATE(GAMESTATE_MAP, Map)
|
||||||
else if (game.gamestate==GAMESTATE_ABOUT) {
|
DRAW_STATE(GAMESTATE_LEVEL, Level)
|
||||||
About_Draw(&game);
|
default:
|
||||||
}
|
|
||||||
else if (game.gamestate==GAMESTATE_INTRO) {
|
|
||||||
Intro_Draw(&game);
|
|
||||||
}
|
|
||||||
else if (game.gamestate==GAMESTATE_MAP) {
|
|
||||||
Map_Draw(&game);
|
|
||||||
}
|
|
||||||
else if (game.gamestate==GAMESTATE_LEVEL) {
|
|
||||||
Level_Draw(&game);
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
game.showconsole = true;
|
game.showconsole = true;
|
||||||
PrintConsole(&game, "ERROR: Unknown gamestate %d reached! (5 sec sleep)", game.gamestate);
|
PrintConsole(&game, "ERROR: Unknown gamestate %d reached! (5 sec sleep)", game.gamestate);
|
||||||
DrawConsole(&game);
|
DrawConsole(&game);
|
||||||
|
@ -265,6 +245,7 @@ int main(int argc, char **argv){
|
||||||
PrintConsole(&game, "Returning to menu...");
|
PrintConsole(&game, "Returning to menu...");
|
||||||
game.gamestate = GAMESTATE_LOADING;
|
game.gamestate = GAMESTATE_LOADING;
|
||||||
game.loadstate = GAMESTATE_MENU;
|
game.loadstate = GAMESTATE_MENU;
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
DrawConsole(&game);
|
DrawConsole(&game);
|
||||||
al_flip_display();
|
al_flip_display();
|
||||||
|
|
Loading…
Reference in a new issue