mirror of
https://github.com/cmclark00/mintris.git
synced 2025-05-18 05:15:20 +01:00
Update game layout and functionality in MainActivity and GameView
This commit is contained in:
parent
b481fb4e80
commit
86424eac32
3 changed files with 63 additions and 111 deletions
|
@ -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
|
||||||
|
|
|
@ -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,81 +1051,36 @@ class GameView @JvmOverloads constructor(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Special handling for landscape mode - side controls
|
// Handle movement based on locked direction
|
||||||
if (isLeftSide) {
|
when (lockedDirection) {
|
||||||
// Left side controls - move left
|
Direction.HORIZONTAL -> {
|
||||||
if (deltaY < -blockSize * minMovementThreshold) {
|
if (abs(deltaX) > blockSize * minMovementThreshold) {
|
||||||
// Swipe up on left side - rotate
|
if (deltaX > 0) {
|
||||||
if (currentTime - lastRotationTime >= rotationCooldown) {
|
gameBoard.moveRight()
|
||||||
gameBoard.rotate()
|
} else {
|
||||||
lastRotationTime = currentTime
|
gameBoard.moveLeft()
|
||||||
gameHaptics?.vibrateForPieceMove()
|
}
|
||||||
|
lastTouchX = event.x
|
||||||
|
if (currentTime - lastMoveTime >= moveCooldown) {
|
||||||
|
gameHaptics?.vibrateForPieceMove()
|
||||||
|
lastMoveTime = currentTime
|
||||||
|
}
|
||||||
invalidate()
|
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) {
|
Direction.VERTICAL -> {
|
||||||
// Right side controls - move right
|
if (deltaY > blockSize * minMovementThreshold) {
|
||||||
if (deltaY < -blockSize * minMovementThreshold) {
|
gameBoard.softDrop()
|
||||||
// Swipe up on right side - hold piece
|
lastTouchY = event.y
|
||||||
if (currentTime - lastHoldTime >= holdCooldown) {
|
if (currentTime - lastMoveTime >= moveCooldown) {
|
||||||
gameBoard.holdPiece()
|
gameHaptics?.vibrateForPieceMove()
|
||||||
lastHoldTime = currentTime
|
lastMoveTime = currentTime
|
||||||
gameHaptics?.vibrateForPieceMove()
|
}
|
||||||
invalidate()
|
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()
|
|
||||||
}
|
}
|
||||||
}
|
null -> {
|
||||||
// Standard touch controls for main board area or portrait mode
|
// No direction lock yet, don't process movement
|
||||||
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
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1145,23 +1090,12 @@ class GameView @JvmOverloads constructor(
|
||||||
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()
|
||||||
|
|
|
@ -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
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue