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 <stdbool.h>
#include <stdint.h>
#include <string.h>
#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++) {