#include "game.h" #include "../textures.h" #include "../game_api.h" #include "state.h" #include "scenes/scene.h" #include "scenes/title.h" #include #include #include void game_step(int64_t delta) { (void)delta; } void game_tick(void) { if (ctx.tick_count == 0) { ctx.udata = ccalloc(1, sizeof (struct state)); struct state *state = ctx.udata; state->ctx = &ctx; state->scene = title_scene(state); input_add_action(&ctx.input, "debug_dump_atlases"); input_bind_action_scancode(&ctx.input, "debug_dump_atlases", SDL_SCANCODE_HOME); input_add_action(&ctx.input, "debug_toggle"); input_bind_action_scancode(&ctx.input, "debug_toggle", SDL_SCANCODE_BACKSPACE); input_add_action(&ctx.input, "player_left"); input_bind_action_scancode(&ctx.input, "player_left", SDL_SCANCODE_LEFT); input_add_action(&ctx.input, "player_right"); input_bind_action_scancode(&ctx.input, "player_right", SDL_SCANCODE_RIGHT); input_add_action(&ctx.input, "player_jump"); input_bind_action_scancode(&ctx.input, "player_jump", SDL_SCANCODE_X); input_add_action(&ctx.input, "ui_accept"); input_bind_action_scancode(&ctx.input, "ui_accept", SDL_SCANCODE_RETURN); } struct state *state = ctx.udata; if (input_is_action_just_pressed(&ctx.input, "debug_dump_atlases")) { textures_dump_atlases(&ctx.texture_cache); } if (input_is_action_just_pressed(&ctx.input, "debug_toggle")) { ctx.debug = !ctx.debug; } state->scene->tick(state); /* there's a scene switch pending, we can do it now that the tick is done */ if (state->next_scene != NULL) { state->scene->end(state); state->scene = state->next_scene; state->is_scene_switching = false; state->next_scene = NULL; } } void game_end(void) { struct state *state = ctx.udata; state->scene->end(state); free(state); }