diff --git a/game-ctrl/game.c b/game-ctrl/game.c index 756f202..cc3d209 100644 --- a/game-ctrl/game.c +++ b/game-ctrl/game.c @@ -69,24 +69,26 @@ void gameExec(void *handle) { proceedDelay--; if (proceedDelay == 0) { rowIndex = 0; - state = e_ClearRows; + state = e_Down; } break; - case e_ClearRows: - state = e_Down; - break; - case e_Down: if (! stoneMoveDown()) { soundCtrl(SOUND_LOCK); - state = e_NewStone; + stoneLock(); + state = e_ClearRows; } else { proceedDelay = delayFactor(level); state = e_DownDelay; } break; + case e_ClearRows: + // clear filled lines + state = e_NewStone; + break; + // --- phase: game over --------------------------------------------------- case e_GameOver: soundCtrl(SOUND_GAMEOVER); diff --git a/game-ctrl/shapes.c b/game-ctrl/shapes.c index a9ffb7a..9be8844 100644 --- a/game-ctrl/shapes.c +++ b/game-ctrl/shapes.c @@ -1,6 +1,7 @@ #include #include #include +#include #include "shapes.h" #include "myrand.h" @@ -19,6 +20,7 @@ typedef struct { orientation_t orientation; uint8_t x; // column uint8_t y; // row + bool locked; } stone_t; typedef struct { @@ -363,6 +365,11 @@ void stoneCreate() { stone.orientation = e_0; stone.x = 4; stone.y = 0; + stone.locked = false; +} + +void stoneLock() { + stone.locked = true; } 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)) { return 1; } + + // if the stone is already locked, do nothing + if (stone.locked) { + return 0; + } + // check whether the pixels to move to are free 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) && diff --git a/game-ctrl/shapes.h b/game-ctrl/shapes.h index 0950917..a34e1cb 100644 --- a/game-ctrl/shapes.h +++ b/game-ctrl/shapes.h @@ -5,6 +5,7 @@ void shapesInit(); void stoneCreate(); +void stoneLock(); uint8_t stoneIsValid(); uint8_t stoneDraw(); uint8_t stoneMoveDown();