2024-09-25 15:29:58 +00:00
|
|
|
#include "ingame.h"
|
|
|
|
#include "title.h"
|
|
|
|
#include "scene.h"
|
|
|
|
|
|
|
|
#include "twn_game_api.h"
|
2024-10-07 16:57:45 +00:00
|
|
|
#include "twn_vec.h"
|
2024-09-25 15:29:58 +00:00
|
|
|
|
2024-10-06 21:00:36 +00:00
|
|
|
#include <SDL2/SDL.h>
|
|
|
|
|
2024-09-25 15:29:58 +00:00
|
|
|
|
|
|
|
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");
|
2024-10-22 17:32:17 +00:00
|
|
|
|
2025-02-04 21:54:38 +00:00
|
|
|
draw_camera_2d((Vec2){ scn->player->rect.x + scn->player->rect.w / 2 - ctx.resolution.x / 2,
|
|
|
|
scn->player->rect.y + scn->player->rect.h / 2 - ctx.resolution.y / 2 },
|
|
|
|
0, 1
|
|
|
|
);
|
|
|
|
|
2024-09-25 15:29:58 +00:00
|
|
|
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;
|
|
|
|
|
2025-01-30 18:57:20 +00:00
|
|
|
SceneIngame *new_scene = calloc(1, sizeof *new_scene);
|
2024-09-25 15:29:58 +00:00
|
|
|
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;
|
|
|
|
}
|