diff --git a/src/game/game.c b/src/game/game.c index 9581685..37fd323 100644 --- a/src/game/game.c +++ b/src/game/game.c @@ -38,11 +38,11 @@ void next_shape(void) { dat.pdat.sel = (i8vec2){COLUMNS / 2 - SHAPE_WIDTH / 2, 0}; dat.pdat.cur = dat.pdat.nxt[dat.pdat.idx]; dat.pdat.idx++; - if (dat.pdat.idx < TETROMINO_COUNT) return; + if (dat.pdat.idx < TETC) return; // shuffle all next shapes, preserving the last dat.pdat.idx = 0; - shuffle(dat.pdat.nxt, TETROMINO_COUNT, sizeof(u8)); + shuffle(dat.pdat.nxt, TETC, sizeof(u8)); } struct gamedata* game_init(void) { @@ -51,12 +51,12 @@ struct gamedata* game_init(void) { // populate the data arrays for (int i = 0; i < ROWS; i++) dat.rows[i] = rowdat + i * COLUMNS; - for (int i = 0; i < TETROMINO_COUNT; i++) + for (int i = 0; i < TETC; i++) dat.pdat.nxt[i] = i; // initialise the placing data correctly dat.pdat.sel = (i8vec2){COLUMNS / 2 - SHAPE_WIDTH / 2, 0}; - shuffle(dat.pdat.nxt, TETROMINO_COUNT, sizeof(u8)); + shuffle(dat.pdat.nxt, TETC, sizeof(u8)); dat.pdat.cur = dat.pdat.nxt[dat.pdat.idx]; dat.pdat.idx++; return &dat; diff --git a/src/game/game.h b/src/game/game.h index 3c31e4b..f4afe93 100644 --- a/src/game/game.h +++ b/src/game/game.h @@ -21,10 +21,10 @@ /* contains the placement data */ struct pdat { - u8 nxt[TETROMINO_COUNT]; // shuffled data representing the next shapes - i8vec2 sel; // position of the current shape - u8 idx; // the index of the current shape - u8 cur; // the current id of the shape + u8 nxt[TETC]; // shuffled data representing the next shapes + i8vec2 sel; // position of the current shape + u8 idx; // the index of the current shape + u8 cur; // the current id of the shape }; /* contains game data that's commonly shared */ diff --git a/src/game/tetromino/shapes.c b/src/game/tetromino/shapes.c index 2286512..a8c2cb6 100644 --- a/src/game/tetromino/shapes.c +++ b/src/game/tetromino/shapes.c @@ -15,46 +15,46 @@ void shape_getblocks(u8 id, i8vec2* restrict out) { switch (id) { // O tetromino - case TETROMINO_O | TETROMINO_ROTATED_0: - case TETROMINO_O | TETROMINO_ROTATED_90: - case TETROMINO_O | TETROMINO_ROTATED_180: - case TETROMINO_O | TETROMINO_ROTATED_270: dat = (struct blockdat){1, 1, 2, 1, 1, 2, 2, 2}; break; + case TET_O | TET_R0: + case TET_O | TET_R90: + case TET_O | TET_R180: + case TET_O | TET_R270: dat = (struct blockdat){1, 1, 2, 1, 1, 2, 2, 2}; break; // I tetromino - case TETROMINO_I | TETROMINO_ROTATED_0: dat = (struct blockdat){0, 1, 1, 1, 2, 1, 3, 1}; break; - case TETROMINO_I | TETROMINO_ROTATED_90: dat = (struct blockdat){2, 0, 2, 1, 2, 2, 2, 3}; break; - case TETROMINO_I | TETROMINO_ROTATED_180: dat = (struct blockdat){0, 2, 1, 2, 2, 2, 3, 2}; break; - case TETROMINO_I | TETROMINO_ROTATED_270: dat = (struct blockdat){1, 0, 1, 1, 1, 2, 1, 3}; break; + case TET_I | TET_R0: dat = (struct blockdat){0, 1, 1, 1, 2, 1, 3, 1}; break; + case TET_I | TET_R90: dat = (struct blockdat){2, 0, 2, 1, 2, 2, 2, 3}; break; + case TET_I | TET_R180: dat = (struct blockdat){0, 2, 1, 2, 2, 2, 3, 2}; break; + case TET_I | TET_R270: dat = (struct blockdat){1, 0, 1, 1, 1, 2, 1, 3}; break; // S tetromino - case TETROMINO_S | TETROMINO_ROTATED_0: dat = (struct blockdat){1, 0, 2, 0, 0, 1, 1, 1}; break; - case TETROMINO_S | TETROMINO_ROTATED_90: dat = (struct blockdat){1, 0, 1, 1, 2, 1, 2, 2}; break; - case TETROMINO_S | TETROMINO_ROTATED_180: dat = (struct blockdat){1, 1, 2, 1, 0, 2, 1, 2}; break; - case TETROMINO_S | TETROMINO_ROTATED_270: dat = (struct blockdat){0, 0, 0, 1, 1, 1, 1, 2}; break; + case TET_S | TET_R0: dat = (struct blockdat){1, 0, 2, 0, 0, 1, 1, 1}; break; + case TET_S | TET_R90: dat = (struct blockdat){1, 0, 1, 1, 2, 1, 2, 2}; break; + case TET_S | TET_R180: dat = (struct blockdat){1, 1, 2, 1, 0, 2, 1, 2}; break; + case TET_S | TET_R270: dat = (struct blockdat){0, 0, 0, 1, 1, 1, 1, 2}; break; // Z tetromino - case TETROMINO_Z | TETROMINO_ROTATED_0: dat = (struct blockdat){0, 0, 1, 0, 1, 1, 2, 1}; break; - case TETROMINO_Z | TETROMINO_ROTATED_90: dat = (struct blockdat){2, 0, 1, 1, 2, 1, 1, 2}; break; - case TETROMINO_Z | TETROMINO_ROTATED_180: dat = (struct blockdat){0, 1, 1, 1, 1, 2, 2, 2}; break; - case TETROMINO_Z | TETROMINO_ROTATED_270: dat = (struct blockdat){1, 0, 0, 1, 1, 1, 0, 2}; break; + case TET_Z | TET_R0: dat = (struct blockdat){0, 0, 1, 0, 1, 1, 2, 1}; break; + case TET_Z | TET_R90: dat = (struct blockdat){2, 0, 1, 1, 2, 1, 1, 2}; break; + case TET_Z | TET_R180: dat = (struct blockdat){0, 1, 1, 1, 1, 2, 2, 2}; break; + case TET_Z | TET_R270: dat = (struct blockdat){1, 0, 0, 1, 1, 1, 0, 2}; break; // T tetromino - case TETROMINO_T | TETROMINO_ROTATED_0: dat = (struct blockdat){0, 1, 1, 1, 2, 1, 1, 2}; break; - case TETROMINO_T | TETROMINO_ROTATED_90: dat = (struct blockdat){1, 0, 0, 1, 1, 1, 1, 2}; break; - case TETROMINO_T | TETROMINO_ROTATED_180: dat = (struct blockdat){1, 0, 0, 1, 1, 1, 2, 1}; break; - case TETROMINO_T | TETROMINO_ROTATED_270: dat = (struct blockdat){1, 0, 1, 1, 2, 1, 1, 2}; break; + case TET_T | TET_R0: dat = (struct blockdat){0, 1, 1, 1, 2, 1, 1, 2}; break; + case TET_T | TET_R90: dat = (struct blockdat){1, 0, 0, 1, 1, 1, 1, 2}; break; + case TET_T | TET_R180: dat = (struct blockdat){1, 0, 0, 1, 1, 1, 2, 1}; break; + case TET_T | TET_R270: dat = (struct blockdat){1, 0, 1, 1, 2, 1, 1, 2}; break; // L tetromino - case TETROMINO_L | TETROMINO_ROTATED_0: dat = (struct blockdat){1, 0, 1, 1, 1, 2, 2, 2}; break; - case TETROMINO_L | TETROMINO_ROTATED_90: dat = (struct blockdat){0, 1, 1, 1, 2, 1, 0, 2}; break; - case TETROMINO_L | TETROMINO_ROTATED_180: dat = (struct blockdat){0, 0, 1, 0, 1, 1, 1, 2}; break; - case TETROMINO_L | TETROMINO_ROTATED_270: dat = (struct blockdat){2, 0, 0, 1, 1, 1, 2, 1}; break; + case TET_L | TET_R0: dat = (struct blockdat){1, 0, 1, 1, 1, 2, 2, 2}; break; + case TET_L | TET_R90: dat = (struct blockdat){0, 1, 1, 1, 2, 1, 0, 2}; break; + case TET_L | TET_R180: dat = (struct blockdat){0, 0, 1, 0, 1, 1, 1, 2}; break; + case TET_L | TET_R270: dat = (struct blockdat){2, 0, 0, 1, 1, 1, 2, 1}; break; // J tetromino - case TETROMINO_J | TETROMINO_ROTATED_0: dat = (struct blockdat){1, 0, 1, 1, 0, 2, 1, 2}; break; - case TETROMINO_J | TETROMINO_ROTATED_90: dat = (struct blockdat){0, 0, 0, 1, 1, 1, 2, 1}; break; - case TETROMINO_J | TETROMINO_ROTATED_180: dat = (struct blockdat){1, 0, 2, 0, 1, 1, 1, 2}; break; - case TETROMINO_J | TETROMINO_ROTATED_270: dat = (struct blockdat){0, 1, 1, 1, 2, 1, 2, 2}; break; + case TET_J | TET_R0: dat = (struct blockdat){1, 0, 1, 1, 0, 2, 1, 2}; break; + case TET_J | TET_R90: dat = (struct blockdat){0, 0, 0, 1, 1, 1, 2, 1}; break; + case TET_J | TET_R180: dat = (struct blockdat){1, 0, 2, 0, 1, 1, 1, 2}; break; + case TET_J | TET_R270: dat = (struct blockdat){0, 1, 1, 1, 2, 1, 2, 2}; break; default: #ifndef NDEBUG @@ -71,13 +71,13 @@ void shape_getblocks(u8 id, i8vec2* restrict out) { colour8 colour_from_id(u8 id) { switch (id & 7) { - case TETROMINO_O: return COLOUR8_YELLOW; - case TETROMINO_I: return COLOUR8_CYAN; - case TETROMINO_S: return COLOUR8_GREEN; - case TETROMINO_Z: return COLOUR8_RED; - case TETROMINO_T: return COLOUR8_MAGENTA; - case TETROMINO_L: return COLOUR8_ORANGE; - case TETROMINO_J: return COLOUR8_BLUE; - default: return COLOUR8_BLACK; + case TET_O: return COLOUR8_YELLOW; + case TET_I: return COLOUR8_CYAN; + case TET_S: return COLOUR8_GREEN; + case TET_Z: return COLOUR8_RED; + case TET_T: return COLOUR8_MAGENTA; + case TET_L: return COLOUR8_ORANGE; + case TET_J: return COLOUR8_BLUE; + default: return COLOUR8_BLACK; } } diff --git a/src/game/tetromino/shapes.h b/src/game/tetromino/shapes.h index 0321d7f..cc1aacb 100644 --- a/src/game/tetromino/shapes.h +++ b/src/game/tetromino/shapes.h @@ -6,23 +6,23 @@ #include "../../util/types.h" #include "../../util/vec.h" -enum { - TETROMINO_O = 0, - TETROMINO_I = 1, - TETROMINO_S = 2, - TETROMINO_Z = 3, - TETROMINO_T = 4, - TETROMINO_L = 5, - TETROMINO_J = 6, - TETROMINO_ROTATED_0 = 0, - TETROMINO_ROTATED_90 = 8, - TETROMINO_ROTATED_180 = 16, - TETROMINO_ROTATED_270 = 24, +enum tetromino { + TET_O = 0, + TET_I = 1, + TET_S = 2, + TET_Z = 3, + TET_T = 4, + TET_L = 5, + TET_J = 6, + TET_R0 = 0, + TET_R90 = 8, + TET_R180 = 16, + TET_R270 = 24, }; -#define SHAPE_WIDTH 4 -#define SHAPE_HEIGHT 4 -#define TETROMINO_COUNT 7 +#define SHAPE_WIDTH 4 +#define SHAPE_HEIGHT 4 +#define TETC 7 void shape_getblocks(u8 id, i8vec2* out); colour8 colour_from_id(u8 id);