Skip to content

Commit

Permalink
Fix touching collision checking with independence of screen resolution
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
haxpor committed Jun 29, 2017
1 parent 3b90773 commit c23af64
Show file tree
Hide file tree
Showing 7 changed files with 37 additions and 11 deletions.
3 changes: 2 additions & 1 deletion core/src/io/wasin/omo/states/Difficulty.kt
Expand Up @@ -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)) {
Expand Down
3 changes: 2 additions & 1 deletion core/src/io/wasin/omo/states/Mainmenu.kt
Expand Up @@ -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))
Expand Down
3 changes: 2 additions & 1 deletion core/src/io/wasin/omo/states/Play.kt
Expand Up @@ -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) {

Expand Down
13 changes: 10 additions & 3 deletions 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
Expand Down Expand Up @@ -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
}
})
})
Expand Down Expand Up @@ -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
Expand Down
5 changes: 3 additions & 2 deletions desktop/src/io/wasin/omo/desktop/DesktopLauncher.kt
Expand Up @@ -7,9 +7,10 @@ import io.wasin.omo.Game
object DesktopLauncher {
@JvmStatic fun main(arg: Array<String>) {
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)
}
}
3 changes: 0 additions & 3 deletions ios-moe/xcode/ios-moe/Info.plist
Expand Up @@ -33,9 +33,6 @@
<key>UISupportedInterfaceOrientations</key>
<array>
<string>UIInterfaceOrientationPortrait</string>
<string>UIInterfaceOrientationPortraitUpsideDown</string>
<string>UIInterfaceOrientationLandscapeLeft</string>
<string>UIInterfaceOrientationLandscapeRight</string>
</array>
<key>UISupportedInterfaceOrientations~ipad</key>
<array>
Expand Down
18 changes: 18 additions & 0 deletions proguard.append.cfg
Expand Up @@ -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.** { *; }

0 comments on commit c23af64

Please sign in to comment.