Skip to content

Commit

Permalink
Add score system promoting multiple row combos
Browse files Browse the repository at this point in the history
The way it works is quite simple. For every row you clear you get 50 points, but each more row is going to count more times (1st row counts once, 2nd row counts twice and so on).

Signed-off-by: efindus <[email protected]>
  • Loading branch information
efindus committed Feb 1, 2022
1 parent d7774d5 commit 627854b
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions tetris.c
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
#include <unistd.h>

// TODO: add wall kicks
// TODO: add score and award more for multiple rows cleared

// Constants
#define HEIGHT 22
Expand Down Expand Up @@ -87,7 +86,7 @@ int comingUp[COMING_UP_AMOUNT];

TetrominoState currentTetromino;
XsetAttributes attributes;
int rowsCleared = 0;
int rowsCleared = 0, score = 0;

int mpvSubprocessPID = -1;

Expand Down Expand Up @@ -217,7 +216,7 @@ void drawFrame() {
printf("\x1b[0m\n");
}

printf("\x1b[38;5;2m[SCORE] Rows cleared: %d\x1b[0m\n", rowsCleared);
printf("\x1b[38;5;2m[SCORE: %d] (Rows cleared: %d)\x1b[0m\n", score, rowsCleared);
}

/*
Expand Down Expand Up @@ -355,6 +354,8 @@ void createNewTetromino() {
* Checks for full rows and clears them
*/
void cleanupBoard() {
int originalCleared = rowsCleared;

for (int y = 1; y < HEIGHT + 1; y++) {
int amount = 0;
for (int x = 1; x < WIDTH + 1; x++) {
Expand All @@ -379,6 +380,11 @@ void cleanupBoard() {
rowsCleared++;
}
}

while(rowsCleared - originalCleared != 0) {
score += 50 * (rowsCleared - originalCleared);
originalCleared++;
}
}

void tick() {
Expand Down

0 comments on commit 627854b

Please sign in to comment.