aboutsummaryrefslogtreecommitdiff
path: root/file.c
diff options
context:
space:
mode:
authorThomas Guillermo Albers Raviola <thomas@thomaslabs.org>2026-01-16 23:26:01 +0100
committerThomas Guillermo Albers Raviola <thomas@thomaslabs.org>2026-01-16 23:26:01 +0100
commitc15c603b35e86fd42e6db94a7382ba7a1ddadd6e (patch)
treeab56040ce4768564bef5fbe9e65fe4c025cea6ce /file.c
Initial commit
Diffstat (limited to 'file.c')
-rw-r--r--file.c42
1 files changed, 42 insertions, 0 deletions
diff --git a/file.c b/file.c
new file mode 100644
index 0000000..64ee1c8
--- /dev/null
+++ b/file.c
@@ -0,0 +1,42 @@
+#include "game.h"
+#include <stdio.h>
+
+void load_config(const char *config)
+{
+ FILE *file = fopen(config, "r");
+
+ if(!file)
+ die("Config \'%s\' could not be found\n", config);
+
+ char buffer[64];
+
+ struct Entity *e;
+ int use_src_rect, mirror;
+ char texture[16];
+
+ while( !feof(file) && game->num_tiles < MAX_TILES )
+ {
+ if( !fgets(buffer, 64,file) )
+ break;
+
+ if(buffer[0] == '#')
+ continue;
+
+ // Tile
+ e = &game->tiles[game->num_tiles ++];
+
+ sscanf(buffer, "%f %f %d %d %d %d %s\n", &e->x, &e->y,
+ &e->w, &e->h, &use_src_rect, &mirror, texture);
+
+ e->use_src_rect = use_src_rect ? true : false;
+ e->mirror = mirror ? true : false;
+ e->collidable = true;
+ e->fixed = true;
+ e->texture = load_texture(texture);
+
+ e->name = malloc(32);
+ sprintf(e->name, "brick %d", game->num_tiles);
+ }
+
+ fclose(file);
+}