aboutsummaryrefslogtreecommitdiff
path: root/src/gen_tiles.c
diff options
context:
space:
mode:
authorkartofen <mladenovnasko0@gmail.com>2022-08-10 14:30:55 +0300
committerkartofen <mladenovnasko0@gmail.com>2022-08-10 14:30:55 +0300
commitbb820d973e9f53d33a32c46659e2a163e68be4ba (patch)
tree64fa131417125f68e5adf944a49baad45d09be8f /src/gen_tiles.c
parent3009bdfe5c9d06dd03d9a36a5919fcb1c834137c (diff)
add more tiles
Diffstat (limited to 'src/gen_tiles.c')
-rw-r--r--src/gen_tiles.c85
1 files changed, 38 insertions, 47 deletions
diff --git a/src/gen_tiles.c b/src/gen_tiles.c
index fecba4e..fbfe378 100644
--- a/src/gen_tiles.c
+++ b/src/gen_tiles.c
@@ -4,7 +4,7 @@
#include <sys/stat.h>
#include "ppm.h"
-#define TILES 3
+#define TILES 5
#define TILE_WIDTH 3
#define TILE_HEIGHT 3
#define TILE_SZ ((TILE_WIDTH) * (TILE_HEIGHT))
@@ -12,7 +12,7 @@
FILE *fp;
// possible types: X T I
-char symetry[TILES] = "XTI";
+char symetry[TILES] = "XTXIT";
small_t tiles[TILES][TILE_SZ] = {
{
@@ -23,13 +23,17 @@ small_t tiles[TILES][TILE_SZ] = {
0, 1, 0,
1, 1, 1,
0, 0, 0
- // }, {
- // 0, 1, 0,
- // 1, 1, 1,
- // 0, 1, 0
- },{
- 0, 0, 0,
+ }, {
+ 0, 1, 0,
1, 1, 1,
+ 0, 1, 0
+ },{
+ 0, 1, 0,
+ 0, 1, 0,
+ 0, 1, 0
+ }, {
+ 0, 1, 0,
+ 1, 1, 0,
0, 0, 0
}
};
@@ -37,37 +41,22 @@ small_t tiles[TILES][TILE_SZ] = {
small_t tiles_connections[TILES][4] = {
{ 0, 0, 0, 0 },
{ 1, 1, 1, 0 },
- // { 1, 1, 1, 1 },
- { 0, 1, 1, 0 },
+ { 1, 1, 1, 1 },
+ { 1, 0, 0, 1 },
+ { 1, 0, 1, 0 },
};
-int rotate(int x, int y, int r)
+int rotate(int x, int y, int r, int w)
{
switch(r) {
case 0: // no roatate
- return y * TILE_WIDTH + x;
+ return y * w + x;
case 1: // right
- return (TILE_SZ-TILE_WIDTH) + y - (x * TILE_WIDTH);
+ return (w*w - w) + y - (x * w);
case 2: // left
- return (TILE_WIDTH-1) - y + (x * TILE_WIDTH);
+ return (w-1) - y + (x * w);
case 3: // down
- return (TILE_SZ-1) - (y * TILE_WIDTH) - x;
- }
-
- return -1;
-}
-
-int crotate(int n, int r)
-{
- switch(r) {
- case 0:
- return n;
- case 1:
- return (n + 1) % 4;
- case 2:
- return (n + 2) % 4;
- case 3:
- return (n + 3) % 4;
+ return (w*w-1) - (y * w) - x;
}
return -1;
@@ -77,13 +66,15 @@ void rotate_tiles(small_t *tile, int i, int r)
{
for(size_t y = 0; y < TILE_HEIGHT; y++)
for(size_t x = 0; x < TILE_WIDTH; x++)
- tile[y * TILE_WIDTH + x] = tiles[i][rotate(x, y, r)];
+ tile[y * TILE_WIDTH + x] = tiles[i][rotate(x, y, r, TILE_WIDTH)];
}
void rotate_connections(small_t *tc, int i, int r)
{
- for(int j = 0; j < 4; j++)
- tc[j] = tiles_connections[i][crotate(j, r)];
+ for(int y = 0; y < 2; y++)
+ for(int x = 0; x < 2; x++)
+ tc[y * 2 + x] = tiles_connections[i][rotate(x, y, r, 2)];
+
}
void save(small_t *t, small_t *n, int i)
@@ -110,30 +101,30 @@ void gen_rotations()
fp = fopen("files/tiles/tiles.dat", "wb");
- for(int i = 0, r = 0; i < TILES; i++)
+ for(int i = 0, n = 0; i < TILES; i++, n++)
{
small_t tile[TILE_SZ];
small_t tile_connections[4];
switch(symetry[i])
{
case 'X':
- save(tiles[i], tiles_connections[i], i+r);
+ save(tiles[i], tiles_connections[i], n);
break;
case 'T': ;
- for(; r < 4; r++) {
- rotate_tiles(tile, i, r);
- rotate_connections(tile_connections, i, r);
+ for(int j = 0; j < 4; j++) {
+ rotate_tiles(tile, i, j);
+ rotate_connections(tile_connections, i, j);
- save(tile, tile_connections, i+r);
- }
- r--;
+ save(tile, tile_connections, n);
+ n++;
+ } n--;
break;
case 'I':
- save(tiles[i], tiles_connections[i], i+r);
- r++;
- rotate_tiles(tile, i, 2);
- rotate_connections(tile_connections, i, 2);
- save(tile, tile_connections, i+r);
+ save(tiles[i], tiles_connections[i], n);
+ n++;
+ rotate_tiles(tile, i, 1);
+ rotate_connections(tile_connections, i, 1);
+ save(tile, tile_connections, n);
break;
}
}