add clear rows method

This commit is contained in:
2025-01-24 17:24:51 +01:00
parent 8ade7fa456
commit ef31a446cd
2 changed files with 55 additions and 10 deletions

View File

@@ -1,11 +1,42 @@
#include "game.h" #include "game.h"
#include <stdbool.h> #include <stdbool.h>
#include <stdint.h>
#include <string.h>
#include "../main.h" #include "../main.h"
#include "shapes.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 // sets a shape to the screen
static void _set_shape(Row* row, const Shape shape, const Colour colour, const uint8_t pos_x) { 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++) { for (uint8_t y = 0; y < SHAPE_HEIGHT; y++) {

View File

@@ -12,14 +12,28 @@ typedef union {
}; };
} Colour; } 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 RED ((uint8_t)0b11000011)
#define COLOUR_BLACK ((Colour){3}) #define YELLOW ((uint8_t)0b11110011)
#define COLOUR_WHITE ((Colour){0xFF}) #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})