Skip to content

Commit

Permalink
Fix bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
lucasnlm committed May 11, 2021
1 parent abf5812 commit 97cddae
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 16 deletions.
4 changes: 2 additions & 2 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ android {

defaultConfig {
// versionCode and versionName must be hardcoded to support F-droid
versionCode 1001041
versionName '10.1.4'
versionCode 1001051
versionName '10.1.5'
minSdkVersion 21
targetSdkVersion 30
multiDexEnabled true
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/java/dev/lucasnlm/antimine/GameActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ class GameActivity :
tapToBegin.visibility = View.GONE
}

if (it.turn < 3 && it.saveId == 0L) {
if (it.turn < 1 && it.saveId == 0L) {
val color = usingTheme.palette.covered.toAndroidColor(168)
val tint = ColorStateList.valueOf(color)
val controlText = gameViewModel.getControlDescription(applicationContext)
Expand Down
1 change: 1 addition & 0 deletions app/src/main/res/layout/activity_main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
android:layout_height="match_parent"
android:fitsSystemWindows="false"
android:animateLayoutChanges="true"
android:paddingHorizontal="16dp"
tools:context=".main.MainActivity">

<ScrollView
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
package dev.lucasnlm.antimine.gdx.controller

import android.util.SizeF
import com.badlogic.gdx.Gdx
import com.badlogic.gdx.graphics.Camera
Expand All @@ -12,6 +11,7 @@ class CameraController(
private val camera: Camera,
) {
private val velocity: Vector2 = Vector2.Zero.cpy()
private var touch: Vector2? = null

private fun limitSpeed(minefieldSize: SizeF) {
val padding = renderSettings.internalPadding
Expand Down Expand Up @@ -53,10 +53,31 @@ class CameraController(
}
}

fun addVelocity(dx: Float, dy: Float) {
val zoom = (camera as OrthographicCamera).zoom
velocity.add(dx * zoom, dy * zoom)
camera.update(true)
fun freeTouch(x: Float, y: Float) {
touch?.let {
val dx = it.x - x
val dy = y - it.y
velocity.add(dx * Gdx.graphics.deltaTime, dy * Gdx.graphics.deltaTime)
}
touch = null
}

fun startTouch(x: Float, y: Float) {
if (touch == null) {
touch = Vector2(x, y)
}
}

fun translate(dx: Float, dy: Float, x: Float, y: Float) {
touch?.let {
if (Vector2(x, y).sub(it.x, it.y).len() > renderSettings.areaSize) {
camera.run {
translate(dx, dy, 0f)
update(true)
Gdx.graphics.requestRendering()
}
}
}
}

companion object {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,11 +70,12 @@ class MinefieldStage(
fun changeZoom(zoomMultiplier: Float) {
(camera as OrthographicCamera).apply {
val newZoom = if (zoomMultiplier > 1.0) {
zoom + 2.0f * zoomMultiplier * Gdx.graphics.deltaTime
zoom + zoom * zoomMultiplier * Gdx.graphics.deltaTime
} else {
zoom - 2.0f * (1.0f / zoomMultiplier) * Gdx.graphics.deltaTime
zoom - 2.0f * zoom * (1.0f / zoomMultiplier) * Gdx.graphics.deltaTime
}
zoom = newZoom.coerceIn(0.7f, 4.0f)
currentZoom = zoom
update(true)

GdxLocal.zoomLevelAlpha = when {
Expand Down Expand Up @@ -327,6 +328,11 @@ class MinefieldStage(
}
}

override fun touchUp(screenX: Int, screenY: Int, pointer: Int, button: Int): Boolean {
cameraController.freeTouch(screenX.toFloat(), screenY.toFloat())
return super.touchUp(screenX, screenY, pointer, button)
}

override fun touchDragged(screenX: Int, screenY: Int, pointer: Int): Boolean {
return minefieldSize?.let {
val dx = Gdx.input.deltaX.toFloat()
Expand All @@ -336,12 +342,17 @@ class MinefieldStage(
inputEvents.clear()
}

if (dx * dx + dy * dy > actionSettings.touchSensibility * 8) {
cameraController.addVelocity(
-dx * currentZoom,
dy * currentZoom,
)
}
cameraController.startTouch(
x = screenX.toFloat(),
y = screenY.toFloat(),
)

cameraController.translate(
dx = -dx * currentZoom,
dy = dy * currentZoom,
x = screenX.toFloat(),
y = screenY.toFloat(),
)

true
} != null
Expand Down

0 comments on commit 97cddae

Please sign in to comment.