Skip to content

Commit

Permalink
Fix bug of pieces locking in middle of board
Browse files Browse the repository at this point in the history
  • Loading branch information
adamgraham committed Dec 8, 2021
1 parent 9cd8eb0 commit a71e5ea
Showing 1 changed file with 9 additions and 9 deletions.
18 changes: 9 additions & 9 deletions Assets/Scripts/Piece.cs
Original file line number Diff line number Diff line change
Expand Up @@ -72,11 +72,13 @@ private void Update()

private void HandleMoveInputs()
{
this.moveTime = Time.time + this.moveDelay;

// Soft drop movement
if (Input.GetKey(KeyCode.S)) {
Move(Vector2Int.down);
if (Input.GetKey(KeyCode.S))
{
if (Move(Vector2Int.down)) {
// Update the step time to prevent double movement
this.stepTime = Time.time + this.stepDelay;
}
}

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

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

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

Expand Down

0 comments on commit a71e5ea

Please sign in to comment.