diff options
Diffstat (limited to 'src/gen_tiles.c')
-rw-r--r-- | src/gen_tiles.c | 28 |
1 files changed, 19 insertions, 9 deletions
diff --git a/src/gen_tiles.c b/src/gen_tiles.c index 6a73872..de07f30 100644 --- a/src/gen_tiles.c +++ b/src/gen_tiles.c @@ -6,13 +6,18 @@ #include "ppm.h" #include "config.h" +#define TILE_TYPES 5 #define TILE_WIDTH 3 #define TILE_HEIGHT 3 // possible types: X T I -char symetry[TILES_CAP] = "XTIIT"; +char symetry[TILE_TYPES] = "XTIIT"; -small_t tiles[TILES_CAP][TILE_WIDTH*TILE_HEIGHT] = { +char tile_names[TILE_TYPES][7] = { + "blank", "t", "plus", "line", "corner" +}; + +small_t tiles[TILE_TYPES][TILE_WIDTH*TILE_HEIGHT] = { { 0, 0, 0, 0, 0, 0, @@ -36,7 +41,7 @@ small_t tiles[TILES_CAP][TILE_WIDTH*TILE_HEIGHT] = { } }; -small_t tiles_connections[TILES_CAP][4] = { +small_t tiles_connections[TILE_TYPES][4] = { { 0, 0, 0, 0 }, { 0, 1, 1, 1 }, { 1, 1, 1, 1 }, @@ -51,12 +56,12 @@ void set_color(small_t *pixels, small_t *t, int x, int y, char k, char blank, ch } FILE *fp; -void save(small_t *t, small_t *n, int i) +void save(small_t *t, small_t *c, int n, int i) { #ifdef GENERATE_PPM_TILES char file_name[64] = {0}; - sprintf(file_name, "files/tiles/tile_%d.ppm", i); + sprintf(file_name, "files/tiles/tile_%d.ppm", n); small_t *pixels = malloc(TILE_WIDTH * TILE_HEIGHT *3); for(int y = 0; y < TILE_HEIGHT; y++) @@ -70,11 +75,16 @@ void save(small_t *t, small_t *n, int i) free(pixels); printf("Saved file: %s\n", file_name); #endif +#ifdef TILESET_NAME + char command[128]; + sprintf(command, "cp files/tilesets/%s/%s.ppm files/tiles/tile_%d.ppm", TILESET_NAME, tile_names[i], n); + system(command); +#endif small_t connections = 0; - for(int c = 0; c < 4; c++) + for(int ci = 0; ci < 4; ci++) { - connections |= (n[c] << (3-c)); + connections |= (c[ci] << (3-ci)); } fwrite(&connections, sizeof(connections), 1, fp); @@ -90,13 +100,13 @@ void gen_rotations() size_t tiles_sz = sizeof(tiles_to_load)/sizeof(int); fwrite(&tiles_sz, sizeof(size_t), sizeof(size_t), fp); - char syms[TILES_CAP]; + char syms[TILE_TYPES]; size_t sym_sz = 0; for(size_t n = 0; n < tiles_sz; n++) { int i = tiles_to_load[n]; - save(tiles[i], tiles_connections[i], n); + save(tiles[i], tiles_connections[i], n, i); syms[sym_sz++] = symetry[i]; } |