show dialog when door is closed

main
Matthias 2 years ago
parent e0ca135712
commit 739cebf937

@ -1,14 +1,15 @@
package com.last.commit package com.last.commit
import GameState
import com.badlogic.gdx.Game import com.badlogic.gdx.Game
import com.badlogic.gdx.Gdx import com.badlogic.gdx.Gdx
import com.badlogic.gdx.InputMultiplexer import com.badlogic.gdx.InputMultiplexer
import com.badlogic.gdx.scenes.scene2d.ui.Skin
import com.last.commit.audio.SoundEngine import com.last.commit.audio.SoundEngine
import com.last.commit.config.GameSettings import com.last.commit.config.GameSettings
import com.last.commit.config.TimeTravelAssetManager import com.last.commit.config.TimeTravelAssetManager
import com.last.commit.inventory.Inventory import com.last.commit.inventory.Inventory
import com.last.commit.screen.* import com.last.commit.screen.*
import com.last.commit.stages.DialogStage
/** [com.badlogic.gdx.ApplicationListener] implementation shared by all platforms. */ /** [com.badlogic.gdx.ApplicationListener] implementation shared by all platforms. */
@ -55,7 +56,9 @@ class Game : Game() {
Inventory(), Inventory(),
GameSettings(), GameSettings(),
SoundEngine(), SoundEngine(),
TimeTravelAssetManager() TimeTravelAssetManager(),
null,
DialogStage(Skin(Gdx.files.internal("ui/uiskin.json")))
) )
} }
} }

@ -1,13 +1,17 @@
import com.last.commit.inventory.Inventory package com.last.commit
import com.last.commit.config.GameSettings
import com.last.commit.audio.SoundEngine import com.last.commit.audio.SoundEngine
import com.last.commit.config.GameSettings
import com.last.commit.config.TimeTravelAssetManager import com.last.commit.config.TimeTravelAssetManager
import com.last.commit.inventory.Inventory
import com.last.commit.map.MapState import com.last.commit.map.MapState
import com.last.commit.stages.DialogStage
data class GameState( data class GameState(
val inventory: Inventory, val inventory: Inventory,
val settings: GameSettings, val settings: GameSettings,
val soundEngine: SoundEngine, val soundEngine: SoundEngine,
val assetManager: TimeTravelAssetManager, val assetManager: TimeTravelAssetManager,
var map: MapState? = null var map: MapState? = null,
val dialogStage: DialogStage
) )

@ -4,8 +4,6 @@ import com.badlogic.gdx.graphics.g2d.SpriteBatch
import com.badlogic.gdx.graphics.g2d.TextureRegion import com.badlogic.gdx.graphics.g2d.TextureRegion
import com.badlogic.gdx.math.Rectangle import com.badlogic.gdx.math.Rectangle
import com.badlogic.gdx.math.Vector2 import com.badlogic.gdx.math.Vector2
import com.last.commit.inventory.Inventory
import GameState
import com.last.commit.audio.GameSoundEffect import com.last.commit.audio.GameSoundEffect

@ -1,8 +1,8 @@
package com.last.commit.map package com.last.commit.map
import GameState
import com.badlogic.gdx.math.Rectangle import com.badlogic.gdx.math.Rectangle
import com.badlogic.gdx.math.Vector2 import com.badlogic.gdx.math.Vector2
import com.last.commit.GameState
import com.last.commit.audio.GameSoundEffect import com.last.commit.audio.GameSoundEffect
import com.last.commit.inventory.InventoryItem import com.last.commit.inventory.InventoryItem

@ -1,8 +1,8 @@
package com.last.commit.map package com.last.commit.map
import GameState
import com.badlogic.gdx.maps.tiled.TiledMapTileLayer.Cell import com.badlogic.gdx.maps.tiled.TiledMapTileLayer.Cell
import com.badlogic.gdx.math.Rectangle import com.badlogic.gdx.math.Rectangle
import com.last.commit.GameState
import com.last.commit.Wall import com.last.commit.Wall
import com.last.commit.audio.GameSoundEffect import com.last.commit.audio.GameSoundEffect
import com.last.commit.inventory.InventoryItem 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 item: InventoryItem? = state.inventory.items.find { it.name == requiredItem }
val result: Boolean
if (item == null) { if (item == null) {
return requiredItem == "" result = requiredItem == ""
} else { } 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) { override fun interact(otherCollider: Rectangle, state: GameState) {

@ -1,7 +1,7 @@
package com.last.commit.map package com.last.commit.map
import GameState
import com.badlogic.gdx.math.Rectangle import com.badlogic.gdx.math.Rectangle
import com.last.commit.GameState
interface Interactable { interface Interactable {
fun getCollider(): Rectangle fun getCollider(): Rectangle

@ -1,6 +1,5 @@
package com.last.commit.map package com.last.commit.map
import GameState
import com.badlogic.gdx.Gdx import com.badlogic.gdx.Gdx
import com.badlogic.gdx.graphics.OrthographicCamera import com.badlogic.gdx.graphics.OrthographicCamera
import com.badlogic.gdx.graphics.g2d.SpriteBatch 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.math.Vector2
import com.badlogic.gdx.scenes.scene2d.ui.Image import com.badlogic.gdx.scenes.scene2d.ui.Image
import com.last.commit.Collidable import com.last.commit.Collidable
import com.last.commit.GameState
import com.last.commit.Player import com.last.commit.Player
import com.last.commit.audio.GameSoundEffect import com.last.commit.audio.GameSoundEffect
import com.last.commit.inventory.InventoryItemTextureLoader 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 val interactable: Interactable = this.findInteractableAtPosition(gridX, gridY) ?: return
//else continue //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")
}
} }

@ -12,7 +12,6 @@ import com.badlogic.gdx.graphics.glutils.ShapeRenderer
import com.badlogic.gdx.math.MathUtils import com.badlogic.gdx.math.MathUtils
import com.badlogic.gdx.math.Vector2 import com.badlogic.gdx.math.Vector2
import com.badlogic.gdx.math.Vector3 import com.badlogic.gdx.math.Vector3
import com.badlogic.gdx.scenes.scene2d.ui.Skin
import com.badlogic.gdx.utils.Json import com.badlogic.gdx.utils.Json
import com.last.commit.Game import com.last.commit.Game
import com.last.commit.Player 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.config.GameConfig
import com.last.commit.map.Interactable import com.last.commit.map.Interactable
import com.last.commit.map.TimeMap import com.last.commit.map.TimeMap
import com.last.commit.stages.DialogStage
import com.last.commit.stages.UIStage import com.last.commit.stages.UIStage
import kotlin.math.floor import kotlin.math.floor
@ -48,7 +46,6 @@ class FirstScreen(private val parent: Game) : TimeTravelScreen() {
var pause = true var pause = true
var uiStage: UIStage var uiStage: UIStage
val dialogStage = DialogStage(Skin(Gdx.files.internal("ui/uiskin.json")))
init { init {
@ -70,7 +67,7 @@ class FirstScreen(private val parent: Game) : TimeTravelScreen() {
} }
override fun getInputProcessors(): Array<InputProcessor> { override fun getInputProcessors(): Array<InputProcessor> {
return arrayOf(dialogStage) return arrayOf(gameState.dialogStage)
} }
override fun handleKeyInput(action: ActionCommand) { override fun handleKeyInput(action: ActionCommand) {
@ -85,8 +82,8 @@ class FirstScreen(private val parent: Game) : TimeTravelScreen() {
} }
ActionCommand.JUMP -> { ActionCommand.JUMP -> {
dialogStage.setTexts("Hello", "Please read the documentation") gameState.dialogStage.setTexts("Hello", "Please read the documentation")
dialogStage.show() gameState.dialogStage.show()
} }
else -> {} else -> {}
@ -125,7 +122,7 @@ class FirstScreen(private val parent: Game) : TimeTravelScreen() {
override fun render(delta: Float) { override fun render(delta: Float) {
if (!pause) { if (!pause) {
uiStage.act(delta) uiStage.act(delta)
dialogStage.act(delta) gameState.dialogStage.act(delta)
handleInput(delta) handleInput(delta)
handleMapBorderCollision() handleMapBorderCollision()
@ -142,7 +139,7 @@ class FirstScreen(private val parent: Game) : TimeTravelScreen() {
renderInteractables(interactables) renderInteractables(interactables)
uiStage.draw() 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) { override fun resize(width: Int, height: Int) {
// Resize your screen here. The parameters represent the new window size. // Resize your screen here. The parameters represent the new window size.
uiStage.resize(width, height) uiStage.resize(width, height)
dialogStage.resize(width, height) gameState.dialogStage.resize(width, height)
handleRatioChange() handleRatioChange()
} }

@ -127,6 +127,7 @@ class Settings(val parent: Game) : TimeTravelScreen() {
} }
override fun resize(width: Int, height: Int) { override fun resize(width: Int, height: Int) {
stage.viewport.update(width, height)
} }
override fun pause() { override fun pause() {

@ -1,11 +1,11 @@
package com.last.commit.stages package com.last.commit.stages
import GameState
import com.badlogic.gdx.graphics.Color import com.badlogic.gdx.graphics.Color
import com.badlogic.gdx.graphics.g2d.BitmapFont import com.badlogic.gdx.graphics.g2d.BitmapFont
import com.badlogic.gdx.scenes.scene2d.Stage import com.badlogic.gdx.scenes.scene2d.Stage
import com.badlogic.gdx.scenes.scene2d.ui.Image import com.badlogic.gdx.scenes.scene2d.ui.Image
import com.badlogic.gdx.scenes.scene2d.ui.Label import com.badlogic.gdx.scenes.scene2d.ui.Label
import com.last.commit.GameState
import com.last.commit.inventory.InventoryItemTextureLoader import com.last.commit.inventory.InventoryItemTextureLoader
class UIStage(path: String, val state: GameState) : Stage() { class UIStage(path: String, val state: GameState) : Stage() {

Loading…
Cancel
Save