mirror of
https://github.com/thepigeongenerator/sdl_template.git
synced 2025-12-17 05:55:47 +01:00
allow setting of game status & escape exits window
This commit is contained in:
@@ -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);
|
||||
}
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user