Skip to content

Commit a71e5ea

Browse files
committed
Fix bug of pieces locking in middle of board
1 parent 9cd8eb0 commit a71e5ea

File tree

1 file changed

+9
-9
lines changed

1 file changed

+9
-9
lines changed

Assets/Scripts/Piece.cs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -72,11 +72,13 @@ private void Update()
7272

7373
private void HandleMoveInputs()
7474
{
75-
this.moveTime = Time.time + this.moveDelay;
76-
7775
// Soft drop movement
78-
if (Input.GetKey(KeyCode.S)) {
79-
Move(Vector2Int.down);
76+
if (Input.GetKey(KeyCode.S))
77+
{
78+
if (Move(Vector2Int.down)) {
79+
// Update the step time to prevent double movement
80+
this.stepTime = Time.time + this.stepDelay;
81+
}
8082
}
8183

8284
// Left/right movement
@@ -91,11 +93,8 @@ private void Step()
9193
{
9294
this.stepTime = Time.time + this.stepDelay;
9395

94-
// Do not move down if the player is already holding down
95-
// otherwise it can cause a double movement
96-
if (!Input.GetKey(KeyCode.S)) {
97-
Move(Vector2Int.down);
98-
}
96+
// Step down to the next row
97+
Move(Vector2Int.down);
9998

10099
// Once the piece has been inactive for too long it becomes locked
101100
if (this.lockTime >= this.lockDelay) {
@@ -131,6 +130,7 @@ private bool Move(Vector2Int translation)
131130
if (valid)
132131
{
133132
this.position = newPosition;
133+
this.moveTime = Time.time + this.moveDelay;
134134
this.lockTime = 0f; // reset
135135
}
136136

0 commit comments

Comments
 (0)