From ef31a446cd3e02f54f99868d57e24a2422a42705 Mon Sep 17 00:00:00 2001 From: Quinn Date: Fri, 24 Jan 2025 17:24:51 +0100 Subject: [PATCH] add clear rows method --- src/game/game.c | 31 +++++++++++++++++++++++++++++++ src/window/colour.h | 34 ++++++++++++++++++++++++---------- 2 files changed, 55 insertions(+), 10 deletions(-) diff --git a/src/game/game.c b/src/game/game.c index 6004dfd..9a7935b 100644 --- a/src/game/game.c +++ b/src/game/game.c @@ -1,11 +1,42 @@ #include "game.h" #include +#include +#include #include "../main.h" #include "shapes.h" +static void clear_row(Row* row, uint8_t y) { + // move the rows down from the specified height + for (; y > 0; y--) + memcpy(row[y].columns, row[y - 1].columns, COLUMNS * sizeof(Colour)); + + memset(row[0].columns, NONE, sizeof(Colour)); +} + +static void clear_rows(Row* row) { + // start at the lowest row + // integer will wrap + for (uint8_t y = ROWS - 1; y < ROWS; y--) { + Row* crow = &row[y]; // the current row + bool nfilled = false; // whether this row is filled + + // loop through all the columns or till nfilled is true + for (uint8_t x = 0; x < COLUMNS; x++) { + if (crow->columns[x].packed == NONE) { + nfilled = true; + break; + } + } + + // continue if the row isn;t filled + if (!nfilled) + clear_row(crow, y); + } +} + // sets a shape to the screen static void _set_shape(Row* row, const Shape shape, const Colour colour, const uint8_t pos_x) { for (uint8_t y = 0; y < SHAPE_HEIGHT; y++) { diff --git a/src/window/colour.h b/src/window/colour.h index e38f57d..dc761e9 100644 --- a/src/window/colour.h +++ b/src/window/colour.h @@ -12,14 +12,28 @@ typedef union { }; } Colour; -#define COLOUR_RED ((Colour){0b11000011}) -#define COLOUR_YELLOW ((Colour){0b11110011}) -#define COLOUR_ORANGE ((Colour){0b11100011}) -#define COLOUR_GREEN ((Colour){0b00110011}) -#define COLOUR_CYAN ((Colour){0b00111111}) -#define COLOUR_BLUE ((Colour){0b00001111}) -#define COLOUR_MAGENTA ((Colour){0b11001111}) -#define COLOUR_NONE ((Colour){0}) -#define COLOUR_BLACK ((Colour){3}) -#define COLOUR_WHITE ((Colour){0xFF}) +#define RED ((uint8_t)0b11000011) +#define YELLOW ((uint8_t)0b11110011) +#define ORANGE ((uint8_t)0b11100011) +#define GREEN ((uint8_t)0b00110011) +#define CYAN ((uint8_t)0b00111111) +#define BLUE ((uint8_t)0b00001111) +#define MAGENTA ((uint8_t)0b11001111) + +#define NONE ((uint8_t)0) +#define BLACK ((uint8_t)3) +#define WHITE ((uint8_t)0xFF) + + +#define COLOUR_RED ((Colour){RED}) +#define COLOUR_YELLOW ((Colour){YELLOW}) +#define COLOUR_ORANGE ((Colour){ORANGE}) +#define COLOUR_GREEN ((Colour){GREEN}) +#define COLOUR_CYAN ((Colour){CYAN}) +#define COLOUR_BLUE ((Colour){BLUE}) +#define COLOUR_MAGENTA ((Colour){MAGENTA}) + +#define COLOUR_NONE ((Colour){NONE}) +#define COLOUR_BLACK ((Colour){BLACK}) +#define COLOUR_WHITE ((Colour){WHITE})