diff --git a/core/src/main/kotlin/com/last/commit/FirstScreen.kt b/core/src/main/kotlin/com/last/commit/FirstScreen.kt index eaae4c7..015ed69 100644 --- a/core/src/main/kotlin/com/last/commit/FirstScreen.kt +++ b/core/src/main/kotlin/com/last/commit/FirstScreen.kt @@ -1,5 +1,6 @@ package com.last.commit +import GameState import com.badlogic.gdx.Gdx import com.badlogic.gdx.Input.Keys import com.badlogic.gdx.InputProcessor @@ -15,12 +16,12 @@ import com.badlogic.gdx.math.MathUtils import com.badlogic.gdx.math.Vector2 import com.badlogic.gdx.math.Vector3 import com.badlogic.gdx.utils.Json +import com.last.commit.config.ActionCommand import com.last.commit.config.GameConfig import com.last.commit.map.Interactable import com.last.commit.map.TimeMap import com.last.commit.stages.InventoryStage import kotlin.math.floor -import GameState /** First screen of the application. Displayed after the application is created. */ class FirstScreen(val gameState: GameState) : Screen, InputProcessor { @@ -245,26 +246,25 @@ class FirstScreen(val gameState: GameState) : Screen, InputProcessor { } override fun keyUp(keycode: Int): Boolean { - if (keycode == Keys.ESCAPE) { + if (gameState.settings.getAction(keycode) == ActionCommand.OPEN_MENU) { Gdx.app.exit() } return false } override fun keyTyped(character: Char): Boolean { - val keyCode = character.code + val characterUpperCase = character.uppercase() + val characterKey = Keys.valueOf(characterUpperCase) - if (gameState.settings.isInteractPressed(keyCode)) { + if (gameState.settings.getAction(characterKey) == ActionCommand.INTERACT) { openDoor() - } else if (gameState.settings.isTimeTravelPressed(keyCode)) { + } else if (gameState.settings.getAction(characterKey) == ActionCommand.TIME_TRAVEL) { map.teleport(player) - } else if (gameState.settings.isOpenInventoryPressed(keyCode)) { + } else if (gameState.settings.getAction(characterKey) == ActionCommand.OPEN_INVENTORY) { inventoryStage.visible = !inventoryStage.visible } else if (character == 'p') { gameState.inventory.add("compass") inventoryStage.refresh() - } else if (gameState.settings.isInteractPressed(keyCode)) { - this.openDoor() } return false } diff --git a/core/src/main/kotlin/com/last/commit/Game.kt b/core/src/main/kotlin/com/last/commit/Game.kt index 1c5501f..68d4009 100644 --- a/core/src/main/kotlin/com/last/commit/Game.kt +++ b/core/src/main/kotlin/com/last/commit/Game.kt @@ -1,9 +1,9 @@ package com.last.commit +import GameState import com.badlogic.gdx.Game +import com.last.commit.config.GameSettings import com.last.commit.inventory.Inventory -import com.last.commit.config.PlayerSettings -import GameState /** [com.badlogic.gdx.ApplicationListener] implementation shared by all platforms. */ class Game : Game() { @@ -18,7 +18,7 @@ class Game : Game() { fun createState() { state = GameState( Inventory(), - PlayerSettings() + GameSettings() ) } } \ No newline at end of file diff --git a/core/src/main/kotlin/com/last/commit/GameState.kt b/core/src/main/kotlin/com/last/commit/GameState.kt index e276981..e2796f7 100644 --- a/core/src/main/kotlin/com/last/commit/GameState.kt +++ b/core/src/main/kotlin/com/last/commit/GameState.kt @@ -1,7 +1,7 @@ import com.last.commit.inventory.Inventory -import com.last.commit.config.PlayerSettings +import com.last.commit.config.GameSettings -public data class GameState( - public val inventory: Inventory, - public val settings: PlayerSettings, +data class GameState( + val inventory: Inventory, + val settings: GameSettings, ) \ No newline at end of file diff --git a/core/src/main/kotlin/com/last/commit/config/PlayerSettings.kt b/core/src/main/kotlin/com/last/commit/config/GameSettings.kt similarity index 54% rename from core/src/main/kotlin/com/last/commit/config/PlayerSettings.kt rename to core/src/main/kotlin/com/last/commit/config/GameSettings.kt index f24066a..d779b54 100644 --- a/core/src/main/kotlin/com/last/commit/config/PlayerSettings.kt +++ b/core/src/main/kotlin/com/last/commit/config/GameSettings.kt @@ -3,21 +3,20 @@ package com.last.commit.config import com.badlogic.gdx.Input.Keys import java.util.* -class PlayerSettings { +class GameSettings { val fullscreen: Boolean = false private val actionKeys: EnumMap> = EnumMap(ActionCommand::class.java) private val actionKeysReversed: HashMap = hashMapOf() - init { actionKeys[ActionCommand.UP] = listOf(Keys.UP, Keys.W) actionKeys[ActionCommand.DOWN] = listOf(Keys.DOWN, Keys.S) actionKeys[ActionCommand.LEFT] = listOf(Keys.LEFT, Keys.A) actionKeys[ActionCommand.RIGHT] = listOf(Keys.RIGHT, Keys.D) actionKeys[ActionCommand.OPEN_MENU] = listOf(Keys.ESCAPE) - actionKeys[ActionCommand.OPEN_INVENTORY] = listOf(Keys.I, Keys.A) + actionKeys[ActionCommand.OPEN_INVENTORY] = listOf(Keys.I) actionKeys[ActionCommand.TIME_TRAVEL] = listOf(Keys.T) actionKeys[ActionCommand.INTERACT] = listOf(Keys.E) @@ -38,41 +37,10 @@ class PlayerSettings { return actionKeysReversed[keyCode] } + fun getKeyCode(actionCommand: ActionCommand): List? { return actionKeys[actionCommand] } - private fun isActionPressed(actionCommand: ActionCommand, keyCode: Int): Boolean { - return actionCommand == getAction(keyCode) - } - - fun isOpenMenuPressed(keyCode: Int): Boolean { - return isActionPressed(ActionCommand.OPEN_MENU, keyCode) - } - fun isOpenInventoryPressed(keyCode: Int): Boolean { - return isActionPressed(ActionCommand.OPEN_INVENTORY, keyCode) - } - - fun isUpPressed(keyCode: Int): Boolean { - return isActionPressed(ActionCommand.UP, keyCode) - } - - fun isDownPressed(keyCode: Int): Boolean { - return isActionPressed(ActionCommand.DOWN, keyCode) - } - - fun isLeftPressed(keyCode: Int): Boolean { - return isActionPressed(ActionCommand.LEFT, keyCode) - } - fun isRightPressed(keyCode: Int): Boolean { - return isActionPressed(ActionCommand.RIGHT, keyCode) - } - fun isTimeTravelPressed(keyCode: Int): Boolean { - return isActionPressed(ActionCommand.TIME_TRAVEL, keyCode) - } - - fun isInteractPressed(keyCode: Int): Boolean { - return isActionPressed(ActionCommand.INTERACT, keyCode) - } } \ No newline at end of file