Pause menu reachable after very much pain
This commit is contained in:
parent
2a13aaff90
commit
889825b371
3 changed files with 18 additions and 8 deletions
|
@ -8,7 +8,6 @@ import org.hexworks.amethyst.api.entity.Entity
|
||||||
import org.hexworks.amethyst.api.entity.EntityType
|
import org.hexworks.amethyst.api.entity.EntityType
|
||||||
import org.hexworks.zircon.api.uievent.KeyCode
|
import org.hexworks.zircon.api.uievent.KeyCode
|
||||||
import org.hexworks.zircon.api.uievent.KeyboardEvent
|
import org.hexworks.zircon.api.uievent.KeyboardEvent
|
||||||
import kotlin.system.exitProcess
|
|
||||||
|
|
||||||
// InputReceiver is pretty simple, it just checks for WASD, and acts accordingly
|
// InputReceiver is pretty simple, it just checks for WASD, and acts accordingly
|
||||||
object InputReceiver : BaseBehavior<GameContext>() {
|
object InputReceiver : BaseBehavior<GameContext>() {
|
||||||
|
@ -20,6 +19,7 @@ object InputReceiver : BaseBehavior<GameContext>() {
|
||||||
val currentPos = player.position
|
val currentPos = player.position
|
||||||
// We only want KeyboardEvents for now so we check with the is operator.
|
// We only want KeyboardEvents for now so we check with the is operator.
|
||||||
// This is similar as the instanceof operator in Java but a bit more useful.
|
// This is similar as the instanceof operator in Java but a bit more useful.
|
||||||
|
|
||||||
if (uiEvent is KeyboardEvent) {
|
if (uiEvent is KeyboardEvent) {
|
||||||
// We use when which is similar to switch in Java to check which key was pressed.
|
// We use when which is similar to switch in Java to check which key was pressed.
|
||||||
// Zircon has a KeyCode for all keys which can be pressed. when in Kotlin is also an expression,
|
// Zircon has a KeyCode for all keys which can be pressed. when in Kotlin is also an expression,
|
||||||
|
@ -30,8 +30,6 @@ object InputReceiver : BaseBehavior<GameContext>() {
|
||||||
KeyCode.KEY_A -> currentPos.withRelativeX(-1)
|
KeyCode.KEY_A -> currentPos.withRelativeX(-1)
|
||||||
KeyCode.KEY_S -> currentPos.withRelativeY(1)
|
KeyCode.KEY_S -> currentPos.withRelativeY(1)
|
||||||
KeyCode.KEY_D -> currentPos.withRelativeX(1)
|
KeyCode.KEY_D -> currentPos.withRelativeX(1)
|
||||||
|
|
||||||
KeyCode.ESCAPE -> exitProcess(0)
|
|
||||||
else -> {
|
else -> {
|
||||||
// If some key is pressed other than WASD, then we just return the current position, so no movement will happen
|
// If some key is pressed other than WASD, then we just return the current position, so no movement will happen
|
||||||
currentPos
|
currentPos
|
||||||
|
|
|
@ -8,7 +8,7 @@ import org.hexworks.zircon.api.component.ComponentAlignment
|
||||||
import org.hexworks.zircon.api.grid.TileGrid
|
import org.hexworks.zircon.api.grid.TileGrid
|
||||||
import org.hexworks.zircon.api.view.base.BaseView
|
import org.hexworks.zircon.api.view.base.BaseView
|
||||||
|
|
||||||
class PauseView (private val grid: TileGrid, theme: ColorTheme = GameConfig.THEME) : BaseView(grid, theme) {
|
class PauseView(public val grid: TileGrid, theme: ColorTheme = GameConfig.THEME) : BaseView(grid, theme) {
|
||||||
init {
|
init {
|
||||||
val msg = "Pre-Game Configuration"
|
val msg = "Pre-Game Configuration"
|
||||||
|
|
||||||
|
|
|
@ -13,8 +13,7 @@ import org.hexworks.zircon.api.component.ColorTheme
|
||||||
import org.hexworks.zircon.api.component.ComponentAlignment
|
import org.hexworks.zircon.api.component.ComponentAlignment
|
||||||
import org.hexworks.zircon.api.game.ProjectionMode
|
import org.hexworks.zircon.api.game.ProjectionMode
|
||||||
import org.hexworks.zircon.api.grid.TileGrid
|
import org.hexworks.zircon.api.grid.TileGrid
|
||||||
import org.hexworks.zircon.api.uievent.KeyboardEventType
|
import org.hexworks.zircon.api.uievent.*
|
||||||
import org.hexworks.zircon.api.uievent.Processed
|
|
||||||
import org.hexworks.zircon.api.view.base.BaseView
|
import org.hexworks.zircon.api.view.base.BaseView
|
||||||
import org.hexworks.zircon.internal.game.impl.GameAreaComponentRenderer
|
import org.hexworks.zircon.internal.game.impl.GameAreaComponentRenderer
|
||||||
|
|
||||||
|
@ -50,10 +49,23 @@ class PlayView (private val grid: TileGrid, private val game: Game = GameBuilder
|
||||||
screen.addComponents(sidebar, logArea, gameComponent)
|
screen.addComponents(sidebar, logArea, gameComponent)
|
||||||
|
|
||||||
// modify our PlayView to update our world whenever the user presses a key
|
// modify our PlayView to update our world whenever the user presses a key
|
||||||
screen.handleKeyboardEvents(KeyboardEventType.KEY_PRESSED) {event, _ ->
|
screen.handleKeyboardEvents(KeyboardEventType.KEY_PRESSED) { event, _ ->
|
||||||
game.world.update(screen, event, game)
|
game.world.update(screen, event, game)
|
||||||
Processed
|
Processed
|
||||||
}
|
}
|
||||||
|
|
||||||
|
grid.handleKeyboardEvents(KeyboardEventType.KEY_PRESSED) label@{ event: KeyboardEvent, phase: UIEventPhase? ->
|
||||||
|
// we filter for KeyCode.ESCAPE only
|
||||||
|
if (event.code == KeyCode.ESCAPE) {
|
||||||
|
// only prints it when we press Arrow Up
|
||||||
|
replaceWith(PauseView(grid))
|
||||||
|
return@label UIEventResponse.processed()
|
||||||
|
} else {
|
||||||
|
// otherwise we just pass on it
|
||||||
|
return@label UIEventResponse.pass() // we didn't handle it so we pass on the event
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Reference in a new issue