townengine/apps/demos/platformer/scenes/ingame.c

46 lines
1.0 KiB
C
Raw Normal View History

#include "ingame.h"
#include "title.h"
#include "scene.h"
#include "twn_game_api.h"
#include "twn_vec.h"
#include <SDL2/SDL.h>
static void ingame_tick(State *state) {
SceneIngame *scn = (SceneIngame *)state->scene;
2025-02-04 04:32:25 +00:00
input_action("player_left", "A");
input_action("player_right", "D");
input_action("player_forward", "W");
input_action("player_backward", "S");
input_action("player_jump", "SPACE");
input_action("player_run", "LSHIFT");
world_drawdef(scn->world);
player_calc(scn->player);
}
static void ingame_end(State *state) {
SceneIngame *scn = (SceneIngame *)state->scene;
player_destroy(scn->player);
world_destroy(scn->world);
free(state->scene);
}
Scene *ingame_scene(State *state) {
(void)state;
SceneIngame *new_scene = calloc(1, sizeof *new_scene);
new_scene->base.tick = ingame_tick;
new_scene->base.end = ingame_end;
new_scene->world = world_create();
new_scene->player = player_create(new_scene->world);
return (Scene *)new_scene;
}