diff --git a/core/src/main/kotlin/com/last/commit/FirstScreen.kt b/core/src/main/kotlin/com/last/commit/FirstScreen.kt index 015ed69..9b9a4f0 100644 --- a/core/src/main/kotlin/com/last/commit/FirstScreen.kt +++ b/core/src/main/kotlin/com/last/commit/FirstScreen.kt @@ -128,11 +128,12 @@ class FirstScreen(val gameState: GameState) : Screen, InputProcessor { } private fun handleInput() { + val horizontalMovement = Vector2() - if (Gdx.input.isKeyPressed(Keys.A) || Gdx.input.isKeyPressed(Keys.LEFT)) { + if (isKeyPressed(gameState.settings.getKeyCode(ActionCommand.LEFT))) { horizontalMovement.sub(Vector2.X) } - if (Gdx.input.isKeyPressed(Keys.D) || Gdx.input.isKeyPressed(Keys.RIGHT)) { + if (isKeyPressed(gameState.settings.getKeyCode(ActionCommand.RIGHT))) { horizontalMovement.add(Vector2.X) } this.player.move(horizontalMovement, delta) @@ -142,10 +143,10 @@ class FirstScreen(val gameState: GameState) : Screen, InputProcessor { this.player.move(horizontalMovement, delta) } val verticalMovement = Vector2() - if (Gdx.input.isKeyPressed(Keys.W) || Gdx.input.isKeyPressed(Keys.UP)) { + if (isKeyPressed(gameState.settings.getKeyCode(ActionCommand.UP))) { verticalMovement.add(Vector2.Y) } - if (Gdx.input.isKeyPressed(Keys.S) || Gdx.input.isKeyPressed(Keys.DOWN)) { + if (isKeyPressed(gameState.settings.getKeyCode(ActionCommand.DOWN))) { verticalMovement.sub(Vector2.Y) } this.player.move(verticalMovement, delta) @@ -160,6 +161,15 @@ class FirstScreen(val gameState: GameState) : Screen, InputProcessor { } } + fun isKeyPressed(keyCodes: List): Boolean{ + for (key in keyCodes) { + if (Gdx.input.isKeyPressed(key)) { + return true + } + } + return false + } + private fun spawnPlayer() { val playerSpawn: Vector2 = map.getPlayerSpawn() this.player.position = playerSpawn diff --git a/core/src/main/kotlin/com/last/commit/config/GameSettings.kt b/core/src/main/kotlin/com/last/commit/config/GameSettings.kt index d779b54..76a3ea1 100644 --- a/core/src/main/kotlin/com/last/commit/config/GameSettings.kt +++ b/core/src/main/kotlin/com/last/commit/config/GameSettings.kt @@ -38,9 +38,13 @@ class GameSettings { } - fun getKeyCode(actionCommand: ActionCommand): List? { - return actionKeys[actionCommand] + fun getKeyCode(actionCommand: ActionCommand): List { + return if (Objects.nonNull(actionKeys[actionCommand])) { + actionKeys[actionCommand]!! + } else { + listOf() + } } } \ No newline at end of file