allow setting of game status & escape exits window

This commit is contained in:
2025-02-14 19:27:30 +01:00
parent f8f6f654b6
commit 9dfdd1818a
3 changed files with 17 additions and 1 deletions

View File

@@ -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);
}

View File

@@ -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

View File

@@ -1,5 +1,12 @@
#include "game.h"
#include <SDL_keyboard.h>
#include <SDL_scancode.h>
#include <stdbool.h>
#include <stdint.h>
#include <stdlib.h>
#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) {