#include #include #include #include #include "game.h" #include "player.h" #include "wall.h" struct game game; void update_game(float dt) { for (int i = 0; i < MAX_ENTITY_COUNT; i++) { struct entity* current = &game.entities[i]; if (!entity_active(current)) continue; update_entity(current, dt); } } void draw_game() { for (int i = 0; i < MAX_ENTITY_COUNT; i++) { const struct entity* current = &game.entities[i]; //Skip inactive entities if (!entity_active(current)) continue; draw_entity(current); } } 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); }