From a8f095cf428a16f735db5c46a6d4f718a27f8d92 Mon Sep 17 00:00:00 2001 From: cmclark00 Date: Mon, 31 Mar 2025 15:20:54 -0400 Subject: [PATCH] Add counterclockwise rotation support for gamepad controls - Implemented rotateCounterClockwise method in GameBoard to handle piece rotation. - Updated GameView to call rotateCounterClockwise and added haptic feedback. - Modified GamepadController to support rotation with button B. --- .../main/java/com/mintris/game/GameView.kt | 10 +++++ .../com/mintris/game/GamepadController.kt | 11 ++++- .../main/java/com/mintris/model/GameBoard.kt | 43 +++++++++++++++++++ 3 files changed, 62 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/com/mintris/game/GameView.kt b/app/src/main/java/com/mintris/game/GameView.kt index 67bb35a..282a701 100644 --- a/app/src/main/java/com/mintris/game/GameView.kt +++ b/app/src/main/java/com/mintris/game/GameView.kt @@ -1450,6 +1450,16 @@ class GameView @JvmOverloads constructor( gameHaptics?.vibrateForPieceMove() invalidate() } + + /** + * Rotate the current piece counterclockwise (for gamepad/keyboard support) + */ + fun rotateCounterClockwise() { + if (!isActive()) return + gameBoard.rotateCounterClockwise() + gameHaptics?.vibrateForPieceMove() + invalidate() + } /** * Perform a soft drop (move down faster) (for gamepad/keyboard support) diff --git a/app/src/main/java/com/mintris/game/GamepadController.kt b/app/src/main/java/com/mintris/game/GamepadController.kt index c0d09a5..906758d 100644 --- a/app/src/main/java/com/mintris/game/GamepadController.kt +++ b/app/src/main/java/com/mintris/game/GamepadController.kt @@ -371,8 +371,7 @@ class GamepadController( } // Rotation buttons - supporting multiple buttons for different controllers KeyEvent.KEYCODE_BUTTON_A, - KeyEvent.KEYCODE_BUTTON_X, - KeyEvent.KEYCODE_BUTTON_B -> { + KeyEvent.KEYCODE_BUTTON_X -> { if (currentTime - lastRotationTime > ROTATION_COOLDOWN_MS) { gameView.rotate() vibrateForPieceRotation() @@ -380,6 +379,14 @@ class GamepadController( return true } } + KeyEvent.KEYCODE_BUTTON_B -> { + if (currentTime - lastRotationTime > ROTATION_COOLDOWN_MS) { + gameView.rotateCounterClockwise() + vibrateForPieceRotation() + lastRotationTime = currentTime + return true + } + } // Hold piece buttons KeyEvent.KEYCODE_BUTTON_Y, KeyEvent.KEYCODE_BUTTON_L1, diff --git a/app/src/main/java/com/mintris/model/GameBoard.kt b/app/src/main/java/com/mintris/model/GameBoard.kt index 31f03aa..60db089 100644 --- a/app/src/main/java/com/mintris/model/GameBoard.kt +++ b/app/src/main/java/com/mintris/model/GameBoard.kt @@ -297,6 +297,49 @@ class GameBoard( } } + /** + * Rotate the current piece counterclockwise + */ + fun rotateCounterClockwise() { + currentPiece?.let { + // Save current rotation + val originalX = it.x + val originalY = it.y + + // Try to rotate + it.rotateCounterClockwise() + + // Wall kick logic - try to move the piece if rotation causes collision + if (!canMove(0, 0)) { + // Try to move left + if (canMove(-1, 0)) { + it.x-- + } + // Try to move right + else if (canMove(1, 0)) { + it.x++ + } + // Try to move 2 spaces (for I piece) + else if (canMove(-2, 0)) { + it.x -= 2 + } + else if (canMove(2, 0)) { + it.x += 2 + } + // Try to move up for floor kicks + else if (canMove(0, -1)) { + it.y-- + } + // Revert if can't find a valid position + else { + it.rotateClockwise() + it.x = originalX + it.y = originalY + } + } + } + } + /** * Check if the current piece can move to the given position */