start new wipe approach

This commit is contained in:
Wolfgang Hottgenroth 2024-05-03 16:21:20 +02:00
parent 09fe302e63
commit 78df7eee66
3 changed files with 22 additions and 6 deletions

View File

@ -69,24 +69,26 @@ void gameExec(void *handle) {
proceedDelay--; proceedDelay--;
if (proceedDelay == 0) { if (proceedDelay == 0) {
rowIndex = 0; rowIndex = 0;
state = e_ClearRows; state = e_Down;
} }
break; break;
case e_ClearRows:
state = e_Down;
break;
case e_Down: case e_Down:
if (! stoneMoveDown()) { if (! stoneMoveDown()) {
soundCtrl(SOUND_LOCK); soundCtrl(SOUND_LOCK);
state = e_NewStone; stoneLock();
state = e_ClearRows;
} else { } else {
proceedDelay = delayFactor(level); proceedDelay = delayFactor(level);
state = e_DownDelay; state = e_DownDelay;
} }
break; break;
case e_ClearRows:
// clear filled lines
state = e_NewStone;
break;
// --- phase: game over --------------------------------------------------- // --- phase: game over ---------------------------------------------------
case e_GameOver: case e_GameOver:
soundCtrl(SOUND_GAMEOVER); soundCtrl(SOUND_GAMEOVER);

View File

@ -1,6 +1,7 @@
#include <stdint.h> #include <stdint.h>
#include <stddef.h> #include <stddef.h>
#include <stdlib.h> #include <stdlib.h>
#include <stdbool.h>
#include "shapes.h" #include "shapes.h"
#include "myrand.h" #include "myrand.h"
@ -19,6 +20,7 @@ typedef struct {
orientation_t orientation; orientation_t orientation;
uint8_t x; // column uint8_t x; // column
uint8_t y; // row uint8_t y; // row
bool locked;
} stone_t; } stone_t;
typedef struct { typedef struct {
@ -363,6 +365,11 @@ void stoneCreate() {
stone.orientation = e_0; stone.orientation = e_0;
stone.x = 4; stone.x = 4;
stone.y = 0; stone.y = 0;
stone.locked = false;
}
void stoneLock() {
stone.locked = true;
} }
uint8_t stoneIsValid() { uint8_t stoneIsValid() {
@ -376,6 +383,12 @@ static uint8_t move(direction_t direction) {
if (motions[stone.shape].nullRotation && (direction == e_RotateLeft || direction == e_RotateRight)) { if (motions[stone.shape].nullRotation && (direction == e_RotateLeft || direction == e_RotateRight)) {
return 1; return 1;
} }
// if the stone is already locked, do nothing
if (stone.locked) {
return 0;
}
// check whether the pixels to move to are free // check whether the pixels to move to are free
if (canvasIsPixelFree(stone.x + motions[stone.shape].motion[direction][stone.orientation].set[0].x, if (canvasIsPixelFree(stone.x + motions[stone.shape].motion[direction][stone.orientation].set[0].x,
stone.y + motions[stone.shape].motion[direction][stone.orientation].set[0].y) && stone.y + motions[stone.shape].motion[direction][stone.orientation].set[0].y) &&

View File

@ -5,6 +5,7 @@
void shapesInit(); void shapesInit();
void stoneCreate(); void stoneCreate();
void stoneLock();
uint8_t stoneIsValid(); uint8_t stoneIsValid();
uint8_t stoneDraw(); uint8_t stoneDraw();
uint8_t stoneMoveDown(); uint8_t stoneMoveDown();