mirror of
https://github.com/cmclark00/tetris-3d.git
synced 2025-05-17 15:15:20 +01:00
Fix gameplay issues: 1. Reduced movement sensitivity and speed 2. Fixed double-tap rotation issue 3. Added clearer rotation instructions
This commit is contained in:
parent
c76cde0f1f
commit
f7f79f2b91
2 changed files with 40 additions and 13 deletions
|
@ -55,14 +55,16 @@ class TetrisGameView @JvmOverloads constructor(
|
|||
private val autoRepeatHandler = Handler(Looper.getMainLooper())
|
||||
private var isAutoRepeating = false
|
||||
private var currentMovement: (() -> Unit)? = null
|
||||
private val autoRepeatDelay = 40L // Faster repeat for smoother movement
|
||||
private val initialAutoRepeatDelay = 100L // Initial delay before repeating
|
||||
private val autoRepeatDelay = 150L // Increased delay between movements for slower response
|
||||
private val initialAutoRepeatDelay = 200L // Increased initial delay
|
||||
private val interpolator = DecelerateInterpolator(1.5f)
|
||||
|
||||
// Touch tracking for continuous swipe
|
||||
private var lastTouchX = 0f
|
||||
private var lastTouchY = 0f
|
||||
private var swipeThreshold = 15f // Distance needed to trigger a move while dragging
|
||||
private var swipeThreshold = 30f // Increased threshold to prevent accidental moves
|
||||
private var lastMoveTime = 0L
|
||||
private val moveCooldown = 200L // Add cooldown between movements
|
||||
|
||||
// Refresh timer
|
||||
private val refreshHandler = Handler(Looper.getMainLooper())
|
||||
|
@ -329,6 +331,12 @@ class TetrisGameView @JvmOverloads constructor(
|
|||
MotionEvent.ACTION_MOVE -> {
|
||||
val diffX = event.x - lastTouchX
|
||||
val diffY = event.y - lastTouchY
|
||||
val currentTime = System.currentTimeMillis()
|
||||
|
||||
// Check if cooldown has elapsed since last move
|
||||
if (currentTime - lastMoveTime < moveCooldown) {
|
||||
return true
|
||||
}
|
||||
|
||||
// Check if drag distance exceeds threshold for continuous movement
|
||||
if (abs(diffX) > swipeThreshold && abs(diffX) > abs(diffY)) {
|
||||
|
@ -341,6 +349,7 @@ class TetrisGameView @JvmOverloads constructor(
|
|||
// Update last position after processing the move
|
||||
lastTouchX = event.x
|
||||
lastTouchY = event.y
|
||||
lastMoveTime = currentTime
|
||||
invalidate()
|
||||
return true
|
||||
} else if (abs(diffY) > swipeThreshold && abs(diffY) > abs(diffX)) {
|
||||
|
@ -350,6 +359,7 @@ class TetrisGameView @JvmOverloads constructor(
|
|||
// Update last position after processing the move
|
||||
lastTouchX = event.x
|
||||
lastTouchY = event.y
|
||||
lastMoveTime = currentTime
|
||||
invalidate()
|
||||
return true
|
||||
}
|
||||
|
@ -401,15 +411,17 @@ class TetrisGameView @JvmOverloads constructor(
|
|||
return true
|
||||
}
|
||||
|
||||
override fun onSingleTapUp(e: MotionEvent): Boolean {
|
||||
override fun onSingleTapConfirmed(e: MotionEvent): Boolean {
|
||||
// Use onSingleTapConfirmed instead of onSingleTapUp for better tap detection
|
||||
|
||||
// Determine if tap is on left or right side of screen
|
||||
val screenMiddle = width / 2
|
||||
|
||||
if (e.x < screenMiddle) {
|
||||
// Left side - rotate counterclockwise (in a real 3D game)
|
||||
// Left side - rotate X axis (horizontal rotation)
|
||||
game?.rotate3DX()
|
||||
} else {
|
||||
// Right side - rotate clockwise
|
||||
// Right side - rotate Y axis (vertical rotation)
|
||||
game?.rotate3DY()
|
||||
}
|
||||
|
||||
|
@ -431,12 +443,13 @@ class TetrisGameView @JvmOverloads constructor(
|
|||
// Horizontal swipe
|
||||
if (abs(velocityX) > minSwipeVelocity && abs(diffX) > minSwipeDistance) {
|
||||
if (diffX > 0) {
|
||||
// Swipe right - use auto-repeat for smoother movement
|
||||
startAutoRepeat { game?.moveRight() }
|
||||
// Swipe right - move right once, not auto-repeat
|
||||
game?.moveRight()
|
||||
} else {
|
||||
// Swipe left - use auto-repeat for smoother movement
|
||||
startAutoRepeat { game?.moveLeft() }
|
||||
// Swipe left - move left once, not auto-repeat
|
||||
game?.moveLeft()
|
||||
}
|
||||
invalidate()
|
||||
return true
|
||||
}
|
||||
} else {
|
||||
|
|
|
@ -29,12 +29,26 @@
|
|||
android:layout_width="0dp"
|
||||
android:layout_height="0dp"
|
||||
android:layout_marginTop="16dp"
|
||||
app:layout_constraintBottom_toTopOf="@+id/controlsHint"
|
||||
app:layout_constraintBottom_toTopOf="@+id/rotationHint"
|
||||
app:layout_constraintDimensionRatio="1:2"
|
||||
app:layout_constraintEnd_toStartOf="@+id/infoPanel"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@+id/gameTitle" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/rotationHint"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginStart="16dp"
|
||||
android:layout_marginEnd="16dp"
|
||||
android:gravity="center"
|
||||
android:text="Tap LEFT side: Horizontal Rotation (X) • Tap RIGHT side: Vertical Rotation (Y)"
|
||||
android:textColor="#ffaa00"
|
||||
android:textSize="13sp"
|
||||
app:layout_constraintBottom_toTopOf="@+id/controlsHint"
|
||||
app:layout_constraintEnd_toStartOf="@+id/infoPanel"
|
||||
app:layout_constraintStart_toStartOf="parent" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/controlsHint"
|
||||
android:layout_width="0dp"
|
||||
|
@ -43,9 +57,9 @@
|
|||
android:layout_marginEnd="16dp"
|
||||
android:layout_marginBottom="16dp"
|
||||
android:gravity="center"
|
||||
android:text="Swipe left/right to move • Swipe down for soft drop • Swipe up for hard drop • Tap to rotate"
|
||||
android:text="Swipe left/right to move • Swipe down for soft drop • Swipe up for hard drop"
|
||||
android:textColor="#00ffff"
|
||||
android:textSize="14sp"
|
||||
android:textSize="13sp"
|
||||
app:layout_constraintBottom_toBottomOf="parent"
|
||||
app:layout_constraintEnd_toStartOf="@+id/infoPanel"
|
||||
app:layout_constraintStart_toStartOf="parent" />
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue