diff options
Diffstat (limited to 'src/game.c')
| -rw-r--r-- | src/game.c | 36 |
1 files changed, 36 insertions, 0 deletions
@@ -1,6 +1,10 @@ #include <stdio.h> #include <string.h> +#include <stdlib.h> +#include <raylib.h> #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); +} |
