Update game layout and functionality in MainActivity and GameView

This commit is contained in:
Corey 2025-03-31 04:05:50 -04:00
parent b481fb4e80
commit 86424eac32
3 changed files with 63 additions and 111 deletions

View file

@ -93,6 +93,16 @@ class MainActivity : AppCompatActivity() {
themeSelector = binding.themeSelector
blockSkinSelector = binding.blockSkinSelector
// Set up touch event forwarding
binding.touchInterceptor?.setOnTouchListener { _, event ->
if (gameView.visibility == View.VISIBLE && !gameView.isPaused && !gameView.isGameOver()) {
gameView.onTouchEvent(event)
true
} else {
false
}
}
// Set up progression screen
progressionScreen = binding.progressionScreen
progressionScreen.visibility = View.GONE

View file

@ -1019,16 +1019,6 @@ class GameView @JvmOverloads constructor(
return true
}
// Define the game board boundaries
val boardRight = boardLeft + (gameBoard.width * blockSize)
val boardBottom = boardTop + (gameBoard.height * blockSize)
// Determine if touch is on left side, right side, or within board area
val isLeftSide = event.x < boardLeft
val isRightSide = event.x > boardRight
val isWithinBoard = event.x >= boardLeft && event.x <= boardRight &&
event.y >= boardTop && event.y <= boardBottom
when (event.action) {
MotionEvent.ACTION_DOWN -> {
startX = event.x
@ -1061,81 +1051,36 @@ class GameView @JvmOverloads constructor(
}
}
// Special handling for landscape mode - side controls
if (isLeftSide) {
// Left side controls - move left
if (deltaY < -blockSize * minMovementThreshold) {
// Swipe up on left side - rotate
if (currentTime - lastRotationTime >= rotationCooldown) {
gameBoard.rotate()
lastRotationTime = currentTime
gameHaptics?.vibrateForPieceMove()
// Handle movement based on locked direction
when (lockedDirection) {
Direction.HORIZONTAL -> {
if (abs(deltaX) > blockSize * minMovementThreshold) {
if (deltaX > 0) {
gameBoard.moveRight()
} else {
gameBoard.moveLeft()
}
lastTouchX = event.x
if (currentTime - lastMoveTime >= moveCooldown) {
gameHaptics?.vibrateForPieceMove()
lastMoveTime = currentTime
}
invalidate()
}
} else if (deltaY > blockSize * minMovementThreshold) {
// Swipe down on left side - move left
gameBoard.moveLeft()
lastTouchY = event.y
if (currentTime - lastMoveTime >= moveCooldown) {
gameHaptics?.vibrateForPieceMove()
lastMoveTime = currentTime
}
invalidate()
}
} else if (isRightSide) {
// Right side controls - move right
if (deltaY < -blockSize * minMovementThreshold) {
// Swipe up on right side - hold piece
if (currentTime - lastHoldTime >= holdCooldown) {
gameBoard.holdPiece()
lastHoldTime = currentTime
gameHaptics?.vibrateForPieceMove()
Direction.VERTICAL -> {
if (deltaY > blockSize * minMovementThreshold) {
gameBoard.softDrop()
lastTouchY = event.y
if (currentTime - lastMoveTime >= moveCooldown) {
gameHaptics?.vibrateForPieceMove()
lastMoveTime = currentTime
}
invalidate()
}
} else if (deltaY > blockSize * minMovementThreshold) {
// Swipe down on right side - move right
gameBoard.moveRight()
lastTouchY = event.y
if (currentTime - lastMoveTime >= moveCooldown) {
gameHaptics?.vibrateForPieceMove()
lastMoveTime = currentTime
}
invalidate()
}
}
// Standard touch controls for main board area or portrait mode
else {
// Handle movement based on locked direction
when (lockedDirection) {
Direction.HORIZONTAL -> {
if (abs(deltaX) > blockSize * minMovementThreshold) {
if (deltaX > 0) {
gameBoard.moveRight()
} else {
gameBoard.moveLeft()
}
lastTouchX = event.x
if (currentTime - lastMoveTime >= moveCooldown) {
gameHaptics?.vibrateForPieceMove()
lastMoveTime = currentTime
}
invalidate()
}
}
Direction.VERTICAL -> {
if (deltaY > blockSize * minMovementThreshold) {
gameBoard.softDrop()
lastTouchY = event.y
if (currentTime - lastMoveTime >= moveCooldown) {
gameHaptics?.vibrateForPieceMove()
lastMoveTime = currentTime
}
invalidate()
}
}
null -> {
// No direction lock yet, don't process movement
}
null -> {
// No direction lock yet, don't process movement
}
}
}
@ -1145,23 +1090,12 @@ class GameView @JvmOverloads constructor(
val deltaY = event.y - startY
val moveTime = currentTime - lastTapTime
// Special handling for taps on game board or sides
// Handle taps for rotation
if (moveTime < minTapTime * 1.5 &&
abs(deltaY) < maxTapMovement * 1.5 &&
abs(deltaX) < maxTapMovement * 1.5) {
if (isLeftSide) {
// Tap on left side - move left
gameBoard.moveLeft()
gameHaptics?.vibrateForPieceMove()
invalidate()
} else if (isRightSide) {
// Tap on right side - move right
gameBoard.moveRight()
gameHaptics?.vibrateForPieceMove()
invalidate()
} else if (isWithinBoard && currentTime - lastRotationTime >= rotationCooldown) {
// Tap on board - rotate
if (currentTime - lastRotationTime >= rotationCooldown) {
gameBoard.rotate()
lastRotationTime = currentTime
gameHaptics?.vibrateForPieceMove()
@ -1170,15 +1104,11 @@ class GameView @JvmOverloads constructor(
return true
}
// Long swipe handling for hard drops and holds
// Handle gestures
// Check for hold gesture (swipe up)
if (deltaY < -blockSize * minHoldDistance &&
abs(deltaX) / abs(deltaY) < 0.5f) {
if (currentTime - lastHoldTime < holdCooldown) {
Log.d(TAG, "Hold blocked by cooldown - time since last: ${currentTime - lastHoldTime}ms, cooldown: ${holdCooldown}ms")
} else {
// Process the hold
Log.d(TAG, "Hold detected - deltaY: $deltaY, ratio: ${abs(deltaX) / abs(deltaY)}")
if (currentTime - lastHoldTime >= holdCooldown) {
gameBoard.holdPiece()
lastHoldTime = currentTime
gameHaptics?.vibrateForPieceMove()
@ -1189,11 +1119,7 @@ class GameView @JvmOverloads constructor(
else if (deltaY > blockSize * minHardDropDistance &&
abs(deltaX) / abs(deltaY) < 0.5f &&
(deltaY / moveTime) * 1000 > minSwipeVelocity) {
if (currentTime - lastHardDropTime < hardDropCooldown) {
Log.d(TAG, "Hard drop blocked by cooldown - time since last: ${currentTime - lastHardDropTime}ms, cooldown: ${hardDropCooldown}ms")
} else {
// Process the hard drop
Log.d(TAG, "Hard drop detected - deltaY: $deltaY, velocity: ${(deltaY / moveTime) * 1000}, ratio: ${abs(deltaX) / abs(deltaY)}")
if (currentTime - lastHardDropTime >= hardDropCooldown) {
gameBoard.hardDrop()
lastHardDropTime = currentTime
invalidate()

View file

@ -8,16 +8,24 @@
android:fitsSystemWindows="true"
tools:context=".MainActivity">
<!-- Full Screen Touch Interceptor -->
<View
android:id="@+id/touchInterceptor"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:clickable="true"
android:focusable="true" />
<!-- Game Container with Glow - Centered -->
<FrameLayout
android:id="@+id/gameContainer"
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_margin="12dp"
android:layout_margin="0dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintDimensionRatio="1:2"
app:layout_constraintEnd_toStartOf="@+id/rightControlsPanel"
app:layout_constraintStart_toEndOf="@+id/leftControlsPanel"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent">
<com.mintris.game.GameView
@ -30,10 +38,12 @@
android:id="@+id/glowBorder"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/glow_border" />
android:background="@drawable/glow_border"
android:clickable="false"
android:focusable="false" />
</FrameLayout>
<!-- Left Side Controls Panel -->
<!-- Left Side Controls Panel - Overlay -->
<androidx.constraintlayout.widget.ConstraintLayout
android:id="@+id/leftControlsPanel"
android:layout_width="0dp"
@ -42,7 +52,10 @@
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintWidth_percent="0.25">
app:layout_constraintWidth_percent="0.25"
android:clickable="false"
android:focusable="false"
android:elevation="1dp">
<!-- Hold Piece View -->
<TextView
@ -83,7 +96,7 @@
android:layout_marginBottom="24dp" />
</androidx.constraintlayout.widget.ConstraintLayout>
<!-- Right Side Controls Panel -->
<!-- Right Side Controls Panel - Overlay -->
<androidx.constraintlayout.widget.ConstraintLayout
android:id="@+id/rightControlsPanel"
android:layout_width="0dp"
@ -92,7 +105,10 @@
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintWidth_percent="0.25">
app:layout_constraintWidth_percent="0.25"
android:clickable="false"
android:focusable="false"
android:elevation="1dp">
<!-- Next Piece Preview -->
<TextView