Merge remote-tracking branch 'origin/main'

# Conflicts:
#	core/src/main/kotlin/com/last/commit/FirstScreen.kt
#	core/src/main/kotlin/com/last/commit/Game.kt
viewport-stuff
trivernis 2 years ago
commit 4fdee63537
Signed by: Trivernis
GPG Key ID: DFFFCC2C7A02DB45

@ -252,14 +252,16 @@ class FirstScreen(val gameState: GameState) : Screen, InputProcessor {
}
override fun keyTyped(character: Char): Boolean {
if (character == 'e') {
val keyCode = character.code
if (game.settings.isInteractPressed(keyCode)) {
openDoor()
} else if (character == 't') {
} else if (game.settings.isTimeTravelPressed(keyCode)) {
map.teleport(player)
} else if (character == 'i') {
} else if (game.settings.isOpenInventoryPressed(keyCode)) {
inventoryStage.visible = !inventoryStage.visible
} else if (character == 'p') {
gameState.inventory.add("compass")
player.inventory.add("compass")
inventoryStage.refresh()
}
return false

@ -9,11 +9,14 @@ class Game : Game() {
private lateinit var state: GameState
var settings = PlayerSettings()
override fun create() {
setScreen(FirstScreen(this))
createState()
setScreen(FirstScreen(state))
}
fun createState() {
state = GameState(
Inventory()

@ -0,0 +1,14 @@
package com.last.commit.config
enum class ActionCommand {
//move
UP, DOWN, LEFT, RIGHT,
//interaction
OPEN_INVENTORY, TIME_TRAVEL,
INTERACT,
//program interaction
OPEN_MENU,
}

@ -0,0 +1,78 @@
package com.last.commit.config
import com.badlogic.gdx.Input.Keys
import java.util.*
class PlayerSettings {
val fullscreen: Boolean = false
private val actionKeys: EnumMap<ActionCommand, List<Int>> = EnumMap(ActionCommand::class.java)
private val actionKeysReversed: HashMap<Int, ActionCommand> = 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.TIME_TRAVEL] = listOf(Keys.T)
actionKeys[ActionCommand.INTERACT] = listOf(Keys.E)
setReversed(actionKeys)
}
private fun setReversed(actionKeys: EnumMap<ActionCommand, List<Int>>) {
for (actionCode in actionKeys.keys){
for (key in actionKeys.getValue(actionCode)) {
actionKeysReversed[key] = actionCode
}
}
}
fun getAction(keyCode: Int): ActionCommand? {
return actionKeysReversed[keyCode]
}
fun getKeyCode(actionCommand: ActionCommand): List<Int>? {
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)
}
}
Loading…
Cancel
Save