mirror of
https://github.com/cmclark00/mintris.git
synced 2025-05-18 00:15:20 +01:00
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.
This commit is contained in:
parent
b739d0ec3a
commit
a8f095cf42
3 changed files with 62 additions and 2 deletions
|
@ -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)
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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
|
||||
*/
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue