awesome!!!

This commit is contained in:
veclavtalica
2024-07-08 03:44:20 +03:00
commit 206a5b7cad
529 changed files with 148340 additions and 0 deletions

32
src/game/scenes/ingame.c Normal file
View File

@@ -0,0 +1,32 @@
#include "ingame.h"
#include "title.h"
#include "scene.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);
}
static void ingame_end(struct state *state) {
struct scene_ingame *scn = (struct scene_ingame *)state->scene;
player_destroy(scn->player);
world_destroy(scn->world);
}
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);
return (struct scene *)new_scene;
}

23
src/game/scenes/ingame.h Normal file
View File

@@ -0,0 +1,23 @@
#ifndef INGAME_H
#define INGAME_H
#include "../../game_api.h"
#include "../state.h"
#include "scene.h"
#include "../player.h"
#include "../world.h"
struct scene_ingame {
struct scene base;
struct world *world;
struct player *player;
};
struct scene *ingame_scene(struct state *state);
#endif

8
src/game/scenes/scene.c Normal file
View File

@@ -0,0 +1,8 @@
#include "scene.h"
#include "../state.h"
void switch_to(struct state *state, struct scene *(*scene_func)(struct state *)) {
state->next_scene = scene_func(state);
state->is_scene_switching = true;
}

16
src/game/scenes/scene.h Normal file
View File

@@ -0,0 +1,16 @@
#ifndef SCENE_H
#define SCENE_H
struct state;
struct scene {
char *id;
void (*tick)(struct state *);
void (*end)(struct state *);
};
void switch_to(struct state *state, struct scene *(*scene_func)(struct state *));
#endif

41
src/game/scenes/title.c Normal file
View File

@@ -0,0 +1,41 @@
#include "title.h"
#include "ingame.h"
#include "../world.h"
#include "../player.h"
#include "../../game_api.h"
static void title_tick(struct state *state) {
struct scene_title *scn = (struct scene_title *)state->scene;
(void)scn;
if (input_is_action_just_pressed(&state->ctx->input, "ui_accept")) {
switch_to(state, ingame_scene);
}
push_sprite("/assets/title.png", (t_frect) {
(RENDER_BASE_WIDTH / 2) - (320 / 2), 64, 320, 128
});
}
static void title_end(struct state *state) {
struct scene_title *scn = (struct scene_title *)state->scene;
player_destroy(scn->player);
world_destroy(scn->world);
}
struct scene *title_scene(struct state *state) {
(void)state;
struct scene_title *new_scene = ccalloc(1, sizeof *new_scene);
new_scene->base.tick = title_tick;
new_scene->base.end = title_end;
new_scene->world = world_create();
new_scene->player = player_create(new_scene->world);
return (struct scene *)new_scene;
}

23
src/game/scenes/title.h Normal file
View File

@@ -0,0 +1,23 @@
#ifndef TITLE_H
#define TITLE_H
#include "../../game_api.h"
#include "../state.h"
#include "scene.h"
#include "../player.h"
#include "../world.h"
struct scene_title {
struct scene base;
struct world *world;
struct player *player;
};
struct scene *title_scene(struct state *state);
#endif