From 739cebf93753d69e2e04d84b22a51fd4823760aa Mon Sep 17 00:00:00 2001 From: Matthias Date: Sun, 20 Nov 2022 10:43:39 +0100 Subject: [PATCH] show dialog when door is closed --- core/src/main/kotlin/com/last/commit/Game.kt | 7 +++++-- core/src/main/kotlin/com/last/commit/GameState.kt | 10 +++++++--- core/src/main/kotlin/com/last/commit/Player.kt | 2 -- .../kotlin/com/last/commit/map/Collectible.kt | 2 +- core/src/main/kotlin/com/last/commit/map/Door.kt | 14 +++++++++++--- .../kotlin/com/last/commit/map/Interactable.kt | 2 +- .../main/kotlin/com/last/commit/map/TimeMap.kt | 9 +++++++-- .../kotlin/com/last/commit/screen/FirstScreen.kt | 15 ++++++--------- .../kotlin/com/last/commit/screen/Settings.kt | 1 + .../main/kotlin/com/last/commit/stages/UIStage.kt | 2 +- 10 files changed, 40 insertions(+), 24 deletions(-) diff --git a/core/src/main/kotlin/com/last/commit/Game.kt b/core/src/main/kotlin/com/last/commit/Game.kt index 4ec69b4..67e4b87 100644 --- a/core/src/main/kotlin/com/last/commit/Game.kt +++ b/core/src/main/kotlin/com/last/commit/Game.kt @@ -1,14 +1,15 @@ package com.last.commit -import GameState import com.badlogic.gdx.Game import com.badlogic.gdx.Gdx import com.badlogic.gdx.InputMultiplexer +import com.badlogic.gdx.scenes.scene2d.ui.Skin import com.last.commit.audio.SoundEngine import com.last.commit.config.GameSettings import com.last.commit.config.TimeTravelAssetManager import com.last.commit.inventory.Inventory import com.last.commit.screen.* +import com.last.commit.stages.DialogStage /** [com.badlogic.gdx.ApplicationListener] implementation shared by all platforms. */ @@ -55,7 +56,9 @@ class Game : Game() { Inventory(), GameSettings(), SoundEngine(), - TimeTravelAssetManager() + TimeTravelAssetManager(), + null, + DialogStage(Skin(Gdx.files.internal("ui/uiskin.json"))) ) } } \ 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 9736d6e..a6f40b2 100644 --- a/core/src/main/kotlin/com/last/commit/GameState.kt +++ b/core/src/main/kotlin/com/last/commit/GameState.kt @@ -1,13 +1,17 @@ -import com.last.commit.inventory.Inventory -import com.last.commit.config.GameSettings +package com.last.commit + import com.last.commit.audio.SoundEngine +import com.last.commit.config.GameSettings import com.last.commit.config.TimeTravelAssetManager +import com.last.commit.inventory.Inventory import com.last.commit.map.MapState +import com.last.commit.stages.DialogStage data class GameState( val inventory: Inventory, val settings: GameSettings, val soundEngine: SoundEngine, val assetManager: TimeTravelAssetManager, - var map: MapState? = null + var map: MapState? = null, + val dialogStage: DialogStage ) \ No newline at end of file diff --git a/core/src/main/kotlin/com/last/commit/Player.kt b/core/src/main/kotlin/com/last/commit/Player.kt index 9d8c1bb..0d320b9 100644 --- a/core/src/main/kotlin/com/last/commit/Player.kt +++ b/core/src/main/kotlin/com/last/commit/Player.kt @@ -4,8 +4,6 @@ import com.badlogic.gdx.graphics.g2d.SpriteBatch import com.badlogic.gdx.graphics.g2d.TextureRegion import com.badlogic.gdx.math.Rectangle import com.badlogic.gdx.math.Vector2 -import com.last.commit.inventory.Inventory -import GameState import com.last.commit.audio.GameSoundEffect diff --git a/core/src/main/kotlin/com/last/commit/map/Collectible.kt b/core/src/main/kotlin/com/last/commit/map/Collectible.kt index dd844dc..ce1a9e7 100644 --- a/core/src/main/kotlin/com/last/commit/map/Collectible.kt +++ b/core/src/main/kotlin/com/last/commit/map/Collectible.kt @@ -1,8 +1,8 @@ package com.last.commit.map -import GameState import com.badlogic.gdx.math.Rectangle import com.badlogic.gdx.math.Vector2 +import com.last.commit.GameState import com.last.commit.audio.GameSoundEffect import com.last.commit.inventory.InventoryItem diff --git a/core/src/main/kotlin/com/last/commit/map/Door.kt b/core/src/main/kotlin/com/last/commit/map/Door.kt index 491fdb0..487a705 100644 --- a/core/src/main/kotlin/com/last/commit/map/Door.kt +++ b/core/src/main/kotlin/com/last/commit/map/Door.kt @@ -1,8 +1,8 @@ package com.last.commit.map -import GameState import com.badlogic.gdx.maps.tiled.TiledMapTileLayer.Cell import com.badlogic.gdx.math.Rectangle +import com.last.commit.GameState import com.last.commit.Wall import com.last.commit.audio.GameSoundEffect import com.last.commit.inventory.InventoryItem @@ -17,11 +17,19 @@ class Door(gridX: Int, gridY: Int, wallCollider: Rectangle, cell: Cell) : val item: InventoryItem? = state.inventory.items.find { it.name == requiredItem } + val result: Boolean if (item == null) { - return requiredItem == "" + result = requiredItem == "" } else { - return requiredItem == item.name + result = requiredItem == item.name } + + if (result) { + } else { + state.dialogStage.setTexts("This dor is blocked. You need a key") + state.dialogStage.show() + } + return result } override fun interact(otherCollider: Rectangle, state: GameState) { diff --git a/core/src/main/kotlin/com/last/commit/map/Interactable.kt b/core/src/main/kotlin/com/last/commit/map/Interactable.kt index 8e2b494..cf883be 100644 --- a/core/src/main/kotlin/com/last/commit/map/Interactable.kt +++ b/core/src/main/kotlin/com/last/commit/map/Interactable.kt @@ -1,7 +1,7 @@ package com.last.commit.map -import GameState import com.badlogic.gdx.math.Rectangle +import com.last.commit.GameState interface Interactable { fun getCollider(): Rectangle diff --git a/core/src/main/kotlin/com/last/commit/map/TimeMap.kt b/core/src/main/kotlin/com/last/commit/map/TimeMap.kt index 1498316..b606d0c 100644 --- a/core/src/main/kotlin/com/last/commit/map/TimeMap.kt +++ b/core/src/main/kotlin/com/last/commit/map/TimeMap.kt @@ -1,6 +1,5 @@ package com.last.commit.map -import GameState import com.badlogic.gdx.Gdx import com.badlogic.gdx.graphics.OrthographicCamera import com.badlogic.gdx.graphics.g2d.SpriteBatch @@ -11,6 +10,7 @@ import com.badlogic.gdx.math.Rectangle import com.badlogic.gdx.math.Vector2 import com.badlogic.gdx.scenes.scene2d.ui.Image import com.last.commit.Collidable +import com.last.commit.GameState import com.last.commit.Player import com.last.commit.audio.GameSoundEffect import com.last.commit.inventory.InventoryItemTextureLoader @@ -121,7 +121,12 @@ class TimeMap(fileName: String, val state: GameState) { val interactable: Interactable = this.findInteractableAtPosition(gridX, gridY) ?: return //else continue - interactable.interact(blockingCollider, state) + if (interactable.canInteract(state)) { + println("Interacting with element at $gridX:$gridY") + interactable.interact(blockingCollider, state) + } else { + println("Cannot interact with $gridX:$gridY") + } } diff --git a/core/src/main/kotlin/com/last/commit/screen/FirstScreen.kt b/core/src/main/kotlin/com/last/commit/screen/FirstScreen.kt index 2cf2693..4e82b04 100644 --- a/core/src/main/kotlin/com/last/commit/screen/FirstScreen.kt +++ b/core/src/main/kotlin/com/last/commit/screen/FirstScreen.kt @@ -12,7 +12,6 @@ import com.badlogic.gdx.graphics.glutils.ShapeRenderer import com.badlogic.gdx.math.MathUtils import com.badlogic.gdx.math.Vector2 import com.badlogic.gdx.math.Vector3 -import com.badlogic.gdx.scenes.scene2d.ui.Skin import com.badlogic.gdx.utils.Json import com.last.commit.Game import com.last.commit.Player @@ -21,7 +20,6 @@ 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.DialogStage import com.last.commit.stages.UIStage import kotlin.math.floor @@ -48,7 +46,6 @@ class FirstScreen(private val parent: Game) : TimeTravelScreen() { var pause = true var uiStage: UIStage - val dialogStage = DialogStage(Skin(Gdx.files.internal("ui/uiskin.json"))) init { @@ -70,7 +67,7 @@ class FirstScreen(private val parent: Game) : TimeTravelScreen() { } override fun getInputProcessors(): Array { - return arrayOf(dialogStage) + return arrayOf(gameState.dialogStage) } override fun handleKeyInput(action: ActionCommand) { @@ -85,8 +82,8 @@ class FirstScreen(private val parent: Game) : TimeTravelScreen() { } ActionCommand.JUMP -> { - dialogStage.setTexts("Hello", "Please read the documentation") - dialogStage.show() + gameState.dialogStage.setTexts("Hello", "Please read the documentation") + gameState.dialogStage.show() } else -> {} @@ -125,7 +122,7 @@ class FirstScreen(private val parent: Game) : TimeTravelScreen() { override fun render(delta: Float) { if (!pause) { uiStage.act(delta) - dialogStage.act(delta) + gameState.dialogStage.act(delta) handleInput(delta) handleMapBorderCollision() @@ -142,7 +139,7 @@ class FirstScreen(private val parent: Game) : TimeTravelScreen() { renderInteractables(interactables) uiStage.draw() - dialogStage.draw() + gameState.dialogStage.draw() } } @@ -265,7 +262,7 @@ class FirstScreen(private val parent: Game) : TimeTravelScreen() { override fun resize(width: Int, height: Int) { // Resize your screen here. The parameters represent the new window size. uiStage.resize(width, height) - dialogStage.resize(width, height) + gameState.dialogStage.resize(width, height) handleRatioChange() } diff --git a/core/src/main/kotlin/com/last/commit/screen/Settings.kt b/core/src/main/kotlin/com/last/commit/screen/Settings.kt index 0ee6139..f6aa6dd 100644 --- a/core/src/main/kotlin/com/last/commit/screen/Settings.kt +++ b/core/src/main/kotlin/com/last/commit/screen/Settings.kt @@ -127,6 +127,7 @@ class Settings(val parent: Game) : TimeTravelScreen() { } override fun resize(width: Int, height: Int) { + stage.viewport.update(width, height) } override fun pause() { diff --git a/core/src/main/kotlin/com/last/commit/stages/UIStage.kt b/core/src/main/kotlin/com/last/commit/stages/UIStage.kt index b286f15..7602727 100644 --- a/core/src/main/kotlin/com/last/commit/stages/UIStage.kt +++ b/core/src/main/kotlin/com/last/commit/stages/UIStage.kt @@ -1,11 +1,11 @@ package com.last.commit.stages -import GameState import com.badlogic.gdx.graphics.Color import com.badlogic.gdx.graphics.g2d.BitmapFont import com.badlogic.gdx.scenes.scene2d.Stage import com.badlogic.gdx.scenes.scene2d.ui.Image import com.badlogic.gdx.scenes.scene2d.ui.Label +import com.last.commit.GameState import com.last.commit.inventory.InventoryItemTextureLoader class UIStage(path: String, val state: GameState) : Stage() {