#include "game/debug_tree.h"
#include "game/edit_field.h"
#include "game/level.h"
+#include "game/level/console.h"
#include "game/sound_samples.h"
#include "system/error.h"
#include "system/lt.h"
typedef enum Game_state {
GAME_STATE_RUNNING = 0,
GAME_STATE_PAUSE,
+ GAME_STATE_CONSOLE,
GAME_STATE_QUIT,
GAME_STATE_N
Camera *camera;
Sprite_font *font;
Debug_tree *debug_tree;
+ Console *console;
SDL_Renderer *renderer;
} Game;
RETURN_LT(lt, NULL);
}
+ game->console = PUSH_LT(
+ lt,
+ create_console(game->level, game->font),
+ destroy_console);
+ if (game->console == NULL) {
+ RETURN_LT(lt, NULL);
+ }
+
game->state = GAME_STATE_RUNNING;
return game;
return -1;
}
+ if (game->state == GAME_STATE_CONSOLE) {
+ if (console_render(game->console, game->renderer) < 0) {
+ return -1;
+ }
+ }
+
return 0;
}
return 0;
}
- if (game->state == GAME_STATE_RUNNING) {
+ if (game->state == GAME_STATE_RUNNING || game->state == GAME_STATE_CONSOLE) {
if (level_update(game->level, delta_time) < 0) {
return -1;
}
level_toggle_debug_mode(game->level);
debug_tree_toggle_enabled(game->debug_tree);
break;
+
+ case SDLK_BACKQUOTE:
+ game->state = GAME_STATE_CONSOLE;
+ break;
}
break;
return level_event(game->level, event);
}
+static int game_event_console(Game *game, const SDL_Event *event)
+{
+ switch (event->type) {
+ case SDL_QUIT:
+ game->state = GAME_STATE_QUIT;
+ return 0;
+
+ case SDL_KEYDOWN:
+ switch (event->key.keysym.sym) {
+ case SDLK_ESCAPE:
+ case SDLK_BACKQUOTE:
+ game->state = GAME_STATE_RUNNING;
+ return 0;
+
+ default: {}
+ }
+
+ default: {}
+ }
+
+ return console_handle_event(game->console, event);
+}
+
int game_event(Game *game, const SDL_Event *event)
{
assert(game);
case GAME_STATE_PAUSE:
return game_event_pause(game, event);
+ case GAME_STATE_CONSOLE:
+ return game_event_console(game, event);
+
default: {}
}
assert(game);
assert(keyboard_state);
- if (game->state == GAME_STATE_QUIT || game->state == GAME_STATE_PAUSE) {
+ if (game->state == GAME_STATE_QUIT ||
+ game->state == GAME_STATE_PAUSE ||
+ game->state == GAME_STATE_CONSOLE) {
return 0;
}