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 themeSelector = binding.themeSelector
blockSkinSelector = binding.blockSkinSelector 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 // Set up progression screen
progressionScreen = binding.progressionScreen progressionScreen = binding.progressionScreen
progressionScreen.visibility = View.GONE progressionScreen.visibility = View.GONE

View file

@ -1019,16 +1019,6 @@ class GameView @JvmOverloads constructor(
return true 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) { when (event.action) {
MotionEvent.ACTION_DOWN -> { MotionEvent.ACTION_DOWN -> {
startX = event.x startX = event.x
@ -1061,50 +1051,6 @@ 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()
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()
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 // Handle movement based on locked direction
when (lockedDirection) { when (lockedDirection) {
Direction.HORIZONTAL -> { Direction.HORIZONTAL -> {
@ -1138,30 +1084,18 @@ class GameView @JvmOverloads constructor(
} }
} }
} }
}
MotionEvent.ACTION_UP -> { MotionEvent.ACTION_UP -> {
val deltaX = event.x - startX val deltaX = event.x - startX
val deltaY = event.y - startY val deltaY = event.y - startY
val moveTime = currentTime - lastTapTime val moveTime = currentTime - lastTapTime
// Special handling for taps on game board or sides // Handle taps for rotation
if (moveTime < minTapTime * 1.5 && if (moveTime < minTapTime * 1.5 &&
abs(deltaY) < maxTapMovement * 1.5 && abs(deltaY) < maxTapMovement * 1.5 &&
abs(deltaX) < maxTapMovement * 1.5) { abs(deltaX) < maxTapMovement * 1.5) {
if (isLeftSide) { if (currentTime - lastRotationTime >= rotationCooldown) {
// 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
gameBoard.rotate() gameBoard.rotate()
lastRotationTime = currentTime lastRotationTime = currentTime
gameHaptics?.vibrateForPieceMove() gameHaptics?.vibrateForPieceMove()
@ -1170,15 +1104,11 @@ class GameView @JvmOverloads constructor(
return true return true
} }
// Long swipe handling for hard drops and holds // Handle gestures
// Check for hold gesture (swipe up) // Check for hold gesture (swipe up)
if (deltaY < -blockSize * minHoldDistance && if (deltaY < -blockSize * minHoldDistance &&
abs(deltaX) / abs(deltaY) < 0.5f) { abs(deltaX) / abs(deltaY) < 0.5f) {
if (currentTime - lastHoldTime < holdCooldown) { 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)}")
gameBoard.holdPiece() gameBoard.holdPiece()
lastHoldTime = currentTime lastHoldTime = currentTime
gameHaptics?.vibrateForPieceMove() gameHaptics?.vibrateForPieceMove()
@ -1189,11 +1119,7 @@ class GameView @JvmOverloads constructor(
else if (deltaY > blockSize * minHardDropDistance && else if (deltaY > blockSize * minHardDropDistance &&
abs(deltaX) / abs(deltaY) < 0.5f && abs(deltaX) / abs(deltaY) < 0.5f &&
(deltaY / moveTime) * 1000 > minSwipeVelocity) { (deltaY / moveTime) * 1000 > minSwipeVelocity) {
if (currentTime - lastHardDropTime < hardDropCooldown) { 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)}")
gameBoard.hardDrop() gameBoard.hardDrop()
lastHardDropTime = currentTime lastHardDropTime = currentTime
invalidate() invalidate()

View file

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