diff options
| author | 2019-03-04 17:41:42 +0000 | |
|---|---|---|
| committer | 2019-03-04 17:41:42 +0000 | |
| commit | 90a6b134231db335ae5868d04078f23ed6844ce4 (patch) | |
| tree | af171cac59d4e155b7ba148268ff9378601b2a8a | |
| parent | ee51791f917dff3c15cc13c0fad1e10d791274bf (diff) | |
| download | cetris-90a6b134231db335ae5868d04078f23ed6844ce4.tar.gz cetris-90a6b134231db335ae5868d04078f23ed6844ce4.tar.bz2 cetris-90a6b134231db335ae5868d04078f23ed6844ce4.zip | |
add color support
| -rw-r--r-- | cetris.c | 38 | ||||
| -rw-r--r-- | cetris.h | 13 | ||||
| -rw-r--r-- | ncurses_ui.c | 14 |
3 files changed, 53 insertions, 12 deletions
@@ -203,7 +203,7 @@ void rotate_matrix(struct cetris_game* g, int clockwise) { wall_kick = (next == RRIGHT) ? 3 : 4;
break;
default: // check for UB causing invalid rotations
- assert(false);
+ assert(0);
}
int set_current = 0;
@@ -322,13 +322,34 @@ void clear_move_queue(struct cetris_game* g) { void init_piece_queue(struct cetris_game* g) {
for (int i = 0; i < 7; i++) {
switch (i) {
- case 0: g->piece_queue[i].t = O; break;
- case 1: g->piece_queue[i].t = I; break;
- case 2: g->piece_queue[i].t = S; break;
- case 3: g->piece_queue[i].t = Z; break;
- case 4: g->piece_queue[i].t = L; break;
- case 5: g->piece_queue[i].t = J; break;
- case 6: g->piece_queue[i].t = T; break;
+ case 0:
+ g->piece_queue[i].t = O;
+ g->piece_queue[i].c = COLOR_O;
+ break;
+ case 1:
+ g->piece_queue[i].t = I;
+ g->piece_queue[i].c = COLOR_I;
+ break;
+ case 2:
+ g->piece_queue[i].t = S;
+ g->piece_queue[i].c = COLOR_S;
+ break;
+ case 3:
+ g->piece_queue[i].t = Z;
+ g->piece_queue[i].c = COLOR_Z;
+ break;
+ case 4:
+ g->piece_queue[i].t = L;
+ g->piece_queue[i].c = COLOR_L;
+ break;
+ case 5:
+ g->piece_queue[i].t = J;
+ g->piece_queue[i].c = COLOR_J;
+ break;
+ case 6:
+ g->piece_queue[i].t = T;
+ g->piece_queue[i].c = COLOR_T;
+ break;
}
memcpy(g->piece_queue[i].mat, default_matrices[i], sizeof(piece_matrix));
g->piece_queue[i].r = INIT;
@@ -442,6 +463,7 @@ void wipe_board(struct cetris_game* g) { r = (vec2){x + g->current.pos.x, y + g->current.pos.y};
if (g->current.mat[y][x]) {
g->board[r.x][r.y].occupied = 1;
+ g->board[r.x][r.y].c = g->current.c;
}
}
}
@@ -16,6 +16,17 @@ typedef enum { } type;
typedef enum {
+ COLOR_NONE,
+ COLOR_O,
+ COLOR_I,
+ COLOR_S,
+ COLOR_Z,
+ COLOR_L,
+ COLOR_J,
+ COLOR_T
+} color;
+
+typedef enum {
INIT,
RRIGHT,
RLEFT,
@@ -27,6 +38,7 @@ typedef int piece_matrix[4][4]; struct tetrimino {
type t;
rstate r;
+ color c;
piece_matrix mat;
vec2 pos;
};
@@ -35,6 +47,7 @@ typedef struct { int occupied;
int constant;
int remove_tick;
+ color c;
} slot;
enum movements {
diff --git a/ncurses_ui.c b/ncurses_ui.c index 0f5af4e..1ae07b2 100644 --- a/ncurses_ui.c +++ b/ncurses_ui.c @@ -40,10 +40,14 @@ void curses_init() { timeout(1000 / CETRIS_HZ);
start_color();
- init_pair(0, COLOR_MAGENTA, COLOR_BLACK);
- init_pair(1, COLOR_GREEN, COLOR_BLACK);
- init_pair(2, COLOR_BLUE, COLOR_BLACK);
- init_pair(3, COLOR_YELLOW, COLOR_BLACK);
+ init_pair(COLOR_NONE, COLOR_BLACK, COLOR_BLACK);
+ init_pair(COLOR_O, COLOR_MAGENTA, COLOR_BLACK);
+ init_pair(COLOR_Z, COLOR_RED, COLOR_BLACK);
+ init_pair(COLOR_S, COLOR_CYAN, COLOR_BLACK);
+ init_pair(COLOR_T, COLOR_WHITE, COLOR_BLACK);
+ init_pair(COLOR_L, COLOR_GREEN, COLOR_BLACK);
+ init_pair(COLOR_I, COLOR_BLUE, COLOR_BLACK);
+ init_pair(COLOR_J, COLOR_YELLOW, COLOR_BLACK);
clear();
}
@@ -52,6 +56,7 @@ void draw_board(struct cetris_game* g) { for (int x = 0; x < BOARD_X; x++) {
for (int y = 0; y < BOARD_Y; y++) {
if (g->board[x][y].occupied) {
+ attron(COLOR_PAIR(g->board[x][y].c));
if (g->board[x][y].remove_tick > 0) {
if (g->tick % 2 == 0) {
mvaddstr(y + 1, x * 2 + X_OFFSET, BLOCK);
@@ -59,6 +64,7 @@ void draw_board(struct cetris_game* g) { } else {
mvaddstr(y + 1, x * 2 + X_OFFSET, BLOCK);
}
+ attroff(COLOR_PAIR(g->board[x][y].c));
}
}
}
|