diff --git a/src/error.c b/src/error.c index ea9495a..c0384c3 100644 --- a/src/error.c +++ b/src/error.c @@ -18,6 +18,10 @@ static gamestatus status = STATUS_RUNNING; +void set_gamestatus(gamestatus nstatus) { + status = nstatus; +} + gamestatus get_gamestatus(void) { return status; } @@ -52,6 +56,6 @@ void error(gamestatus error_code, char const* fmt, ...) { SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_ERROR, "something went wrong! :O", buf, NULL); // set status, but exit immediately, as code is not allowed to execute beyond this point - status = error_code; + set_gamestatus(error_code); exit(status); } diff --git a/src/error.h b/src/error.h index a5fe13e..f475d9d 100644 --- a/src/error.h +++ b/src/error.h @@ -27,6 +27,7 @@ enum { }; typedef int8_t gamestatus; +void set_gamestatus(gamestatus); // sets the current status of the game gamestatus get_gamestatus(void); // gets the current status of the game void debug(char const*, ...); // prints a debug message to stdout if the DEBUG environment variable is set, otherwise the call is ignored. void info(char const*, ...); // prints an info message to stdout diff --git a/src/game/game.c b/src/game/game.c index a5ed63c..ce6c44b 100644 --- a/src/game/game.c +++ b/src/game/game.c @@ -1,5 +1,12 @@ #include "game.h" +#include +#include +#include +#include +#include + +#include "../error.h" #include "gametime.h" void game_init(gamedata* dat) { @@ -10,6 +17,10 @@ void game_init(gamedata* dat) { void game_update(gamedata* dat) { gametime_update(&dat->time); + uint8_t const* keys = SDL_GetKeyboardState(NULL); + + if (keys[SDL_SCANCODE_ESCAPE]) + set_gamestatus(STATUS_SUCCESS); } void game_free(gamedata* dat) {