townengine/apps/testgame/scenes/ingame.c

89 lines
2.9 KiB
C
Raw Normal View History

2024-07-08 00:44:20 +00:00
#include "ingame.h"
#include "title.h"
#include "scene.h"
#include "townengine/game_api.h"
2024-07-08 06:46:12 +00:00
2024-07-08 00:44:20 +00:00
static void ingame_tick(struct state *state) {
struct scene_ingame *scn = (struct scene_ingame *)state->scene;
world_drawdef(scn->world);
player_calc(scn->player);
2024-07-08 15:13:33 +00:00
2024-07-30 15:05:05 +00:00
static t_camera cam = { .pos = { 0, 0, 1 }, .target = { 0, 0, -1 }, .up = { 0, 1, 0 }, .fov = (float)M_PI_2 };
if (input_is_action_pressed(&ctx.input, "player_left"))
cam.pos.x -= 0.01f;
if (input_is_action_pressed(&ctx.input, "player_right"))
cam.pos.x += 0.01f;
2024-07-29 22:20:30 +00:00
if (input_is_action_pressed(&ctx.input, "player_jump"))
2024-07-30 15:05:05 +00:00
cam.pos.z += 0.01f;
2024-07-30 12:30:35 +00:00
m_sprite(m_set(path, "/assets/light.png"),
m_set(rect, ((t_frect){ 48, 64, 64, 64 })),
m_opt(color, ((t_color){ 255, 0, 0, 255 })));
2024-07-30 12:30:35 +00:00
m_sprite(m_set(path, "/assets/light.png"),
m_set(rect, ((t_frect){ 64, 64, 64, 64 })),
m_opt(color, ((t_color){ 0, 255, 0, 255 })));
2024-07-30 12:30:35 +00:00
m_sprite(m_set(path, "/assets/light.png"),
m_set(rect, ((t_frect){ 80, 64, 64, 64 })),
m_opt(color, ((t_color){ 0, 0, 255, 255 })));
2024-07-30 12:30:35 +00:00
m_sprite(m_set(path, "/assets/player/baron-walk.png"),
m_set(rect, ((t_frect){ 32, 32, 64, 64 })),
m_opt(rotation, (float)M_PI * 2 * (float)(ctx.tick_count % 64) / 64 ));
2024-07-30 12:30:35 +00:00
m_sprite(m_set(path, "/assets/player/baron-walk.png"),
m_set(rect, ((t_frect){ 128, 32, 128, 64 })),
m_opt(rotation, (float)M_PI * 2 * (float)(ctx.tick_count % 64) / 64 ));
2024-07-27 13:55:38 +00:00
2024-07-30 12:30:35 +00:00
set_camera(&cam);
unfurl_triangle("/assets/big-violet.png",
(t_fvec3){ -1, -1, 0 },
(t_fvec3){ 1, -1, 0 },
(t_fvec3){ 1, 1, 0 },
2024-07-19 21:48:30 +00:00
(t_shvec2){ 0, 2048 },
(t_shvec2){ 2048, 2048 },
(t_shvec2){ 2048, 0 });
unfurl_triangle("/assets/big-violet.png",
(t_fvec3){ 1, 1, 0 },
(t_fvec3){ -1, 1, 0 },
(t_fvec3){ -1, -1, 0 },
2024-07-19 21:48:30 +00:00
(t_shvec2){ 2048, 0 },
(t_shvec2){ 0, 0 },
(t_shvec2){ 0, 2048 });
2024-07-08 00:44:20 +00:00
}
static void ingame_end(struct state *state) {
struct scene_ingame *scn = (struct scene_ingame *)state->scene;
player_destroy(scn->player);
world_destroy(scn->world);
free(state->scene);
2024-07-08 00:44:20 +00:00
}
struct scene *ingame_scene(struct state *state) {
(void)state;
struct scene_ingame *new_scene = ccalloc(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);
2024-07-08 15:00:38 +00:00
play_audio_ex("music/repeat-test.xm", "soundtrack", (t_play_audio_args){
2024-07-08 06:46:12 +00:00
.volume = 0.8f,
2024-07-08 15:00:38 +00:00
.panning = -0.5f,
.repeat = true,
2024-07-08 06:46:12 +00:00
});
2024-07-08 00:44:20 +00:00
return (struct scene *)new_scene;
}