townengine/src/game/scenes/ingame.c

90 lines
2.9 KiB
C

#include "ingame.h"
#include "title.h"
#include "scene.h"
#include "../../audio.h"
static void ingame_tick(struct state *state) {
struct scene_ingame *scn = (struct scene_ingame *)state->scene;
world_drawdef(scn->world);
player_calc(scn->player);
push_sprite_ex((t_frect){ .x = 32, .y = 64, .w = 64, .h = 64 }, (t_push_sprite_args){
.path = "/assets/light.png",
.color = (t_color){255, 0, 0, 255},
.blend = true });
push_sprite_ex((t_frect){ .x = 48, .y = 64, .w = 64, .h = 64 }, (t_push_sprite_args){
.path = "/assets/light.png",
.color = (t_color){0, 255, 0, 255},
.blend = true });
push_sprite_ex((t_frect){ .x = 64, .y = 64, .w = 64, .h = 64 }, (t_push_sprite_args){
.path = "/assets/light.png",
.color = (t_color){0, 0, 255, 255},
.blend = true });
push_sprite_ex((t_frect){ .x = 32, .y = 32, .w = 64, .h = 64 }, (t_push_sprite_args){
.path = "/assets/player/baron-walk.png",
.color = (t_color){255, 255, 255, 255},
.rotation = (float)M_PI * 2 * (float)(ctx.tick_count % 64) / 64,
.blend = true });
push_sprite_ex((t_frect){ .x = 64, .y = 32, .w = 64, .h = 64 }, (t_push_sprite_args){
.path = "/assets/player/baron-walk.png",
.color = (t_color){255, 255, 255, 255},
.rotation = (float)M_PI / 64,
.blend = true });
push_sprite_ex((t_frect){ .x = 96, .y = 32, .w = 64, .h = 64 }, (t_push_sprite_args){
.path = "/assets/player/baron-walk.png",
.color = (t_color){255, 255, 255, 255},
.blend = true });
unfurl_triangle("/assets/big-violet.png",
(t_fvec3){ -1, -1, 0 },
(t_fvec3){ 1, -1, 0 },
(t_fvec3){ 1, 1, 0 },
(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 },
(t_shvec2){ 2048, 0 },
(t_shvec2){ 0, 0 },
(t_shvec2){ 0, 2048 });
}
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);
}
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);
play_audio_ex("music/repeat-test.xm", "soundtrack", (t_play_audio_args){
.volume = 0.8f,
.panning = -0.5f,
.repeat = true,
});
return (struct scene *)new_scene;
}