From c23af6471f5f123610d392eb18e977db49de03a3 Mon Sep 17 00:00:00 2001 From: Wasin Thonkaew Date: Thu, 29 Jun 2017 19:33:17 +0800 Subject: [PATCH] Fix touching collision checking with independence of screen resolution Use unproject() with screen coordinate of Viewport instead of letting libgdx determines full screen resolution and use it which might not always be the case as of desktop version of this project that has half size in both orientation of game resolution. --- core/src/io/wasin/omo/states/Difficulty.kt | 3 ++- core/src/io/wasin/omo/states/Mainmenu.kt | 3 ++- core/src/io/wasin/omo/states/Play.kt | 3 ++- core/src/io/wasin/omo/ui/TransitionState.kt | 13 ++++++++++--- .../io/wasin/omo/desktop/DesktopLauncher.kt | 5 +++-- ios-moe/xcode/ios-moe/Info.plist | 3 --- proguard.append.cfg | 18 ++++++++++++++++++ 7 files changed, 37 insertions(+), 11 deletions(-) diff --git a/core/src/io/wasin/omo/states/Difficulty.kt b/core/src/io/wasin/omo/states/Difficulty.kt index ff6b19a..f61a6be 100644 --- a/core/src/io/wasin/omo/states/Difficulty.kt +++ b/core/src/io/wasin/omo/states/Difficulty.kt @@ -26,7 +26,8 @@ class Difficulty(gsm: GameStateManager): GameState(gsm) { if (Gdx.input.justTouched()) { touchPos.x = Gdx.input.x.toFloat() touchPos.y = Gdx.input.y.toFloat() - cam.unproject(touchPos) + cam.unproject(touchPos, hudViewport.screenX.toFloat(), hudViewport.screenY.toFloat(), + hudViewport.screenWidth.toFloat(), hudViewport.screenHeight.toFloat()) for (i in 0..buttons.size-1) { if (buttons[i].contains(touchPos.x, touchPos.y)) { diff --git a/core/src/io/wasin/omo/states/Mainmenu.kt b/core/src/io/wasin/omo/states/Mainmenu.kt index daac57a..a42dd9f 100644 --- a/core/src/io/wasin/omo/states/Mainmenu.kt +++ b/core/src/io/wasin/omo/states/Mainmenu.kt @@ -23,7 +23,8 @@ class Mainmenu(gsm: GameStateManager): GameState(gsm) { if (Gdx.input.justTouched()) { touchPos.x = Gdx.input.x.toFloat() touchPos.y = Gdx.input.y.toFloat() - hudCam.unproject(touchPos) + hudCam.unproject(touchPos, hudViewport.screenX.toFloat(), hudViewport.screenY.toFloat(), + hudViewport.screenWidth.toFloat(), hudViewport.screenHeight.toFloat()) if (play.contains(touchPos.x, touchPos.y)) { gsm.setState(TransitionState(gsm, this, Difficulty(gsm), TransitionState.Type.BLACK_FADE)) diff --git a/core/src/io/wasin/omo/states/Play.kt b/core/src/io/wasin/omo/states/Play.kt index 70c0888..0ac2f31 100644 --- a/core/src/io/wasin/omo/states/Play.kt +++ b/core/src/io/wasin/omo/states/Play.kt @@ -89,7 +89,8 @@ class Play(gsm: GameStateManager, difficulty: Difficulty): GameState(gsm) { if (!showing && Gdx.input.isTouched(i)) { mouse.x = Gdx.input.getX(i).toFloat() mouse.y = Gdx.input.getY(i).toFloat() - cam.unproject(mouse) + cam.unproject(mouse, hudViewport.screenX.toFloat(), hudViewport.screenY.toFloat(), + hudViewport.screenWidth.toFloat(), hudViewport.screenHeight.toFloat()) if (mouse.y >= boardOffset && mouse.y <= boardOffset + boardHeight) { diff --git a/core/src/io/wasin/omo/ui/TransitionState.kt b/core/src/io/wasin/omo/ui/TransitionState.kt index fc3d82f..ad94597 100644 --- a/core/src/io/wasin/omo/ui/TransitionState.kt +++ b/core/src/io/wasin/omo/ui/TransitionState.kt @@ -1,9 +1,11 @@ package io.wasin.omo.ui +import com.badlogic.gdx.Application import com.badlogic.gdx.Gdx import com.badlogic.gdx.graphics.GL20 import com.badlogic.gdx.graphics.g2d.SpriteBatch import com.badlogic.gdx.graphics.g2d.TextureRegion +import com.badlogic.gdx.math.MathUtils import io.wasin.omo.Game import io.wasin.omo.handlers.GameStateManager import io.wasin.omo.states.GameState @@ -41,14 +43,18 @@ class TransitionState(gsm: GameStateManager, prev: GameState, next: GameState, t } else if (type == Type.EXPAND) { val size = 80f - expands = Array(10, { row -> Array(6, + // determine number of tiles (row & col) to fill the screen + val numRow = MathUtils.ceil(hudViewport.screenHeight / size) + val numCol = MathUtils.ceil(hudViewport.screenWidth / size) + + expands = Array(numRow, { row -> Array(numCol, { col -> ExpandingTile( col * size + size/2, row * size + size/2, size, size).also { - it.timer = (-(10 - row) - col) * delayTimerBetweenTile + it.timer = (-(numRow - row) - col) * delayTimerBetweenTile } }) }) @@ -124,7 +130,8 @@ class TransitionState(gsm: GameStateManager, prev: GameState, next: GameState, t sb.setColor(0f, 0f, 0f, alpha) sb.projectionMatrix = hudCam.combined sb.begin() - sb.draw(dark, 0f, 0f, Game.V_WIDTH, Game.V_HEIGHT) + // draw dark on the entire screen + sb.draw(dark, 0f, 0f, hudViewport.screenWidth.toFloat(), hudViewport.screenHeight.toFloat()) sb.end() // set color back to batch diff --git a/desktop/src/io/wasin/omo/desktop/DesktopLauncher.kt b/desktop/src/io/wasin/omo/desktop/DesktopLauncher.kt index b151ee3..4ca0803 100644 --- a/desktop/src/io/wasin/omo/desktop/DesktopLauncher.kt +++ b/desktop/src/io/wasin/omo/desktop/DesktopLauncher.kt @@ -7,9 +7,10 @@ import io.wasin.omo.Game object DesktopLauncher { @JvmStatic fun main(arg: Array) { val config = LwjglApplicationConfiguration() - config.width = (Game.V_WIDTH / 2f).toInt() - config.height = (Game.V_HEIGHT / 2f).toInt() + config.width = (Game.V_WIDTH / 2).toInt() + config.height = (Game.V_HEIGHT / 2).toInt() config.title = Game.TITLE + config.fullscreen = true LwjglApplication(Game(), config) } } diff --git a/ios-moe/xcode/ios-moe/Info.plist b/ios-moe/xcode/ios-moe/Info.plist index eb0f603..b5f73fc 100644 --- a/ios-moe/xcode/ios-moe/Info.plist +++ b/ios-moe/xcode/ios-moe/Info.plist @@ -33,9 +33,6 @@ UISupportedInterfaceOrientations UIInterfaceOrientationPortrait - UIInterfaceOrientationPortraitUpsideDown - UIInterfaceOrientationLandscapeLeft - UIInterfaceOrientationLandscapeRight UISupportedInterfaceOrientations~ipad diff --git a/proguard.append.cfg b/proguard.append.cfg index e62758d..f8ce514 100644 --- a/proguard.append.cfg +++ b/proguard.append.cfg @@ -37,3 +37,21 @@ -keep class com.badlogic.** { *; } -keep enum com.badlogic.** { *; } + +-keep class com.badlogic.** { *; } +-keep enum com.badlogic.** { *; } + +-keep class com.badlogic.** { *; } +-keep enum com.badlogic.** { *; } + +-keep class com.badlogic.** { *; } +-keep enum com.badlogic.** { *; } + +-keep class com.badlogic.** { *; } +-keep enum com.badlogic.** { *; } + +-keep class com.badlogic.** { *; } +-keep enum com.badlogic.** { *; } + +-keep class com.badlogic.** { *; } +-keep enum com.badlogic.** { *; }