summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--build.ninja2
-rw-r--r--inc/tetromino.h212
-rw-r--r--src/main.c2
3 files changed, 215 insertions, 1 deletions
diff --git a/build.ninja b/build.ninja
index 24e82cc..cf22797 100644
--- a/build.ninja
+++ b/build.ninja
@@ -1,7 +1,7 @@
# tg_tetris build.ninja
# build system inspired by ~elly
-cflags = -Wall -Wextra -g
+cflags = -Iinc -Wall -Wextra -g
ldflags =
rule cc
diff --git a/inc/tetromino.h b/inc/tetromino.h
new file mode 100644
index 0000000..ebe5930
--- /dev/null
+++ b/inc/tetromino.h
@@ -0,0 +1,212 @@
+enum TetrominoTypes {
+ I = 0,
+ J,
+ L,
+ O,
+ S,
+ T,
+ Z
+};
+
+enum Direction {
+ NORTH = 0,
+ EAST,
+ SOUTH,
+ WEST
+};
+
+struct Tetromino {
+ int size;
+ struct Color color;
+ int directions[4][4][4];
+};
+
+struct Tetromino Tetrominos[7] = {
+ [I] = {
+ .size = 4,
+ .color = SKYBLUE,
+ .directions = {
+ [NORTH] = {
+ {0, 0, 0, 0},
+ {1, 1, 1, 1},
+ {0, 0, 0, 0},
+ {0, 0, 0, 0}
+
+ },
+ [EAST] = {
+ {0, 0, 1, 0},
+ {0, 0, 1, 0},
+ {0, 0, 1, 0},
+ {0, 0, 1, 0}
+ },
+ [SOUTH] = {
+ {0, 0, 0, 0},
+ {0, 0, 0, 0},
+ {1, 1, 1, 1},
+ {0, 0, 0, 0}
+ },
+ [WEST] = {
+ {0, 1, 0, 0},
+ {0, 1, 0, 0},
+ {0, 1, 0, 0},
+ {0, 1, 0, 0}
+ }
+ }
+ },
+ [J] = {
+ .size = 3,
+ .color = BLUE,
+ .directions = {
+ [NORTH] = {
+ {1, 0, 0},
+ {1, 1, 1},
+ {0, 0, 0}
+ },
+ [EAST] = {
+ {0, 1, 1},
+ {0, 1, 0},
+ {0, 1, 0}
+ },
+ [SOUTH] = {
+ {0, 0, 0},
+ {1, 1, 1},
+ {0, 0, 1}
+ },
+ [WEST] = {
+ {0, 1, 0},
+ {0, 1, 0},
+ {1, 1, 0}
+ }
+ }
+ },
+ [L] = {
+ .size = 3,
+ .color = ORANGE,
+ .directions = {
+ [NORTH] = {
+ {0, 0, 1},
+ {1, 1, 1},
+ {0, 0, 0}
+ },
+ [EAST] = {
+ {0, 1, 0},
+ {0, 1, 0},
+ {0, 1, 1}
+ },
+ [SOUTH] = {
+ {0, 0, 0},
+ {1, 1, 1},
+ {1, 0, 0}
+ },
+ [WEST] = {
+ {1, 1, 0},
+ {0, 1, 0},
+ {0, 1, 0}
+ }
+ }
+ },
+ [O] = {
+ .size = 3,
+ .color = YELLOW,
+ .directions = {
+ [NORTH] = {
+ {0, 1, 1},
+ {0, 1, 1},
+ {0, 0, 0}
+ },
+ [EAST] = {
+ {0, 1, 1},
+ {0, 1, 1},
+ {0, 0, 0}
+ },
+ [SOUTH] = {
+ {0, 1, 1},
+ {0, 1, 1},
+ {0, 0, 0}
+ },
+ [WEST] = {
+ {0, 1, 1},
+ {0, 1, 1},
+ {0, 0, 0}
+ }
+ }
+ },
+ [S] = {
+ .size = 3,
+ .color = GREEN,
+ .directions = {
+ [NORTH] = {
+ {0, 1, 1},
+ {1, 1, 0},
+ {0, 0, 0}
+ },
+ [EAST] = {
+ {0, 1, 0},
+ {0, 1, 1},
+ {0, 0, 1}
+ },
+ [SOUTH] = {
+ {0, 0, 0},
+ {0, 1, 1},
+ {1, 1, 0}
+ },
+ [WEST] = {
+ {1, 0, 0},
+ {1, 1, 0},
+ {0, 1, 0}
+ }
+ }
+ },
+ [T] = {
+ .size = 3,
+ .color = PURPLE,
+ .directions = {
+ [NORTH] = {
+ {0, 1, 0},
+ {1, 1, 1},
+ {0, 0, 0}
+ },
+ [EAST] = {
+ {0, 1, 0},
+ {0, 1, 1},
+ {0, 1, 0}
+ },
+ [SOUTH] = {
+ {0, 0, 0},
+ {1, 1, 1},
+ {0, 1, 0}
+ },
+ [WEST] = {
+ {0, 1, 0},
+ {1, 1, 0},
+ {0, 1, 0}
+ }
+ }
+ },
+ [Z] = {
+ .size = 3,
+ .color = RED,
+ .directions = {
+ [NORTH] = {
+ {1, 1, 0},
+ {0, 1, 1},
+ {0, 0, 0}
+ },
+ [EAST] = {
+ {0, 0, 1},
+ {0, 1, 1},
+ {0, 1, 0}
+ },
+ [SOUTH] = {
+ {0, 0, 0},
+ {1, 1, 0},
+ {0, 1, 1}
+ },
+ [WEST] = {
+ {0, 1, 0},
+ {1, 1, 0},
+ {1, 0, 0}
+ }
+ }
+ }
+};
diff --git a/src/main.c b/src/main.c
index 661233b..1761efe 100644
--- a/src/main.c
+++ b/src/main.c
@@ -8,6 +8,8 @@
#define BLOCK_SIZE 25
+#include "tetromino.h"
+
struct Color matrix[MATRIX_WIDTH][MATRIX_HEIGHT];
void render_matrix(void);