From c9a8845b53ab13c00ed535a2075cc45765dbbfea Mon Sep 17 00:00:00 2001 From: BoredGuy Date: Mon, 23 Mar 2026 19:28:36 +0300 Subject: Level Loading!!! --- src/game.c | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) (limited to 'src/game.c') diff --git a/src/game.c b/src/game.c index ee4dee9..7872e34 100644 --- a/src/game.c +++ b/src/game.c @@ -1,6 +1,10 @@ #include #include +#include +#include #include "game.h" +#include "player.h" +#include "wall.h" struct game game; @@ -28,3 +32,35 @@ void draw_game() { void init_game() { memset(&game, 0, sizeof(struct game)); } + +void load_level_from_tiled_csv(const char* filename) { + int length; + unsigned char* level_data_raw = LoadFileData(filename, &length); + + char* buffer = malloc(length + 1); + memcpy(buffer, level_data_raw, length); + buffer[length] = '\0'; + + UnloadFileData(level_data_raw); + + int y_pos = 0, x_pos; + char *copy = buffer, *line = NULL; + + while (((line = strsep(©, "\n")) != NULL) && + strcmp(line, "") != 0) { + x_pos = 0; + + char* tile_string; + while ((tile_string = strsep(&line, ",")) != NULL) { + int tile = atoi(tile_string); + + if (tile != -1) + add_wall(x_pos * 128 + 128 / 2, y_pos * 128 + 128 / 2, tile); + x_pos++; + } + + y_pos++; + } + + free(buffer); +} -- cgit v1.2.3