diff --git a/assets/tiled/base.tmx b/assets/tiled/base.tmx index 0cfcfef..b712d73 100644 --- a/assets/tiled/base.tmx +++ b/assets/tiled/base.tmx @@ -1,6 +1,7 @@ - + + diff --git a/assets/tiled/demo.tmx b/assets/tiled/demo.tmx index 4e1640b..6d4babc 100644 --- a/assets/tiled/demo.tmx +++ b/assets/tiled/demo.tmx @@ -1,6 +1,7 @@ - + + diff --git a/core/src/main/kotlin/com/last/commit/GameState.kt b/core/src/main/kotlin/com/last/commit/GameState.kt index 96c0650..dee46a3 100644 --- a/core/src/main/kotlin/com/last/commit/GameState.kt +++ b/core/src/main/kotlin/com/last/commit/GameState.kt @@ -5,5 +5,6 @@ import com.last.commit.audio.SoundEngine data class GameState( val inventory: Inventory, val settings: GameSettings, - public val soundEngine: SoundEngine, + val soundEngine: SoundEngine, + var mapDescription: String = "2020" ) \ No newline at end of file diff --git a/core/src/main/kotlin/com/last/commit/inventory/Inventory.kt b/core/src/main/kotlin/com/last/commit/inventory/Inventory.kt index 41aa062..b76e193 100644 --- a/core/src/main/kotlin/com/last/commit/inventory/Inventory.kt +++ b/core/src/main/kotlin/com/last/commit/inventory/Inventory.kt @@ -4,14 +4,15 @@ class Inventory { val items: MutableList = ArrayList() public var updated = false - private set /** * @param name the name of the subtexture loaded from xml */ fun add(name: String) { - items.add(InventoryItem(name)) - this.updated = true + if (this.items.size < 8) { + items.add(InventoryItem(name)) + this.updated = true + } } fun remove(name: String) { 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 1553f3b..ec8cf01 100644 --- a/core/src/main/kotlin/com/last/commit/map/TimeMap.kt +++ b/core/src/main/kotlin/com/last/commit/map/TimeMap.kt @@ -36,6 +36,8 @@ class TimeMap(fileName: String, val state: GameState) { var mapTileHeight = 0 var halfMapTileWidth = 0f var halfMapTileHeight = 0f + var description: String = "2020" + private set init { @@ -89,6 +91,8 @@ class TimeMap(fileName: String, val state: GameState) { val prop = map.properties this.gridWidth = prop.get("width", Int::class.java) this.gridHeight = prop.get("height", Int::class.java) + this.description = prop.get("description", String::class.java) + this.state.mapDescription = this.description this.width = gridWidth * CELL_SIZE this.height = gridHeight * CELL_SIZE this.mapTileWidth = map.properties.get("tilewidth", Int::class.java) 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 cf36271..089bb7f 100644 --- a/core/src/main/kotlin/com/last/commit/screen/FirstScreen.kt +++ b/core/src/main/kotlin/com/last/commit/screen/FirstScreen.kt @@ -20,7 +20,7 @@ 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.InventoryStage +import com.last.commit.stages.UIStage import kotlin.math.floor /** First screen of the application. Displayed after the application is created. */ @@ -28,7 +28,7 @@ class FirstScreen(private val parent: Game) : TimeTravelScreen() { val gameState = parent.state - val viewportSize = 800f + val viewportSize = 1200f private var delta = 0.008f private var isColliding = false @@ -44,7 +44,7 @@ class FirstScreen(private val parent: Game) : TimeTravelScreen() { val highlightColor = Color(0f, 0f, 1f, 0.5f) - var inventoryStage: InventoryStage + var uiStage: UIStage init { @@ -57,7 +57,7 @@ class FirstScreen(private val parent: Game) : TimeTravelScreen() { handleRatioChange() - inventoryStage = InventoryStage("sprites/genericItems_spritesheet_colored", gameState.inventory) + uiStage = UIStage("sprites/genericItems_spritesheet_colored", gameState) shapeRenderer.setAutoShapeType(true) player.addItemToInventory("drill") @@ -68,11 +68,9 @@ class FirstScreen(private val parent: Game) : TimeTravelScreen() { openDoor() } else if (gameState.settings.getAction(keyCode) == ActionCommand.TIME_TRAVEL) { map.teleport(player) - } else if (gameState.settings.getAction(keyCode) == ActionCommand.OPEN_INVENTORY) { - inventoryStage.visible = !inventoryStage.visible } else if (keyCode == Input.Keys.P) { gameState.inventory.add("compass") - inventoryStage.refresh() + uiStage.refresh() } if (gameState.settings.getAction(keyCode) == ActionCommand.OPEN_MENU) { @@ -119,10 +117,10 @@ class FirstScreen(private val parent: Game) : TimeTravelScreen() { batch.end() val interactables = map.getInteractablesAt(player.getAbsoluteDirection()) - // TODO: auslagern in sperate Methode renderInteractables(interactables) - inventoryStage.draw() + uiStage.act(delta) + uiStage.draw() } fun renderInteractables(interactables: List) { @@ -243,7 +241,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. - inventoryStage.resize(width, height) + uiStage.resize(width, height) handleRatioChange() } diff --git a/core/src/main/kotlin/com/last/commit/stages/InventoryStage.kt b/core/src/main/kotlin/com/last/commit/stages/InventoryStage.kt deleted file mode 100644 index e7c4d30..0000000 --- a/core/src/main/kotlin/com/last/commit/stages/InventoryStage.kt +++ /dev/null @@ -1,47 +0,0 @@ -package com.last.commit.stages - -import com.badlogic.gdx.scenes.scene2d.Stage -import com.badlogic.gdx.scenes.scene2d.ui.Image -import com.last.commit.inventory.Inventory -import com.last.commit.inventory.InventoryItemTextureLoader - -class InventoryStage(path: String, val inventory: Inventory) : Stage() { - val textureLoader = InventoryItemTextureLoader(path) - - init { - textureLoader.parse() - } - - var visible = false - set(visible) { - field = visible - if (visible) { - refresh() - } - } - - fun refresh() { - super.clear() - inventory.items.forEachIndexed { index, inventoryItem -> - val image = Image(textureLoader.getTexture(inventoryItem.name)) - image.x = index * 32f - image.width = 32f - image.height = 32f - - addActor(image) - } - } - - fun resize(width: Int, height: Int) { - viewport.update(width, height, true) - } - - override fun draw() { - if (inventory.updated) { - this.refresh() - } - if (visible) { - super.draw() - } - } -} \ No newline at end of file diff --git a/core/src/main/kotlin/com/last/commit/stages/UIStage.kt b/core/src/main/kotlin/com/last/commit/stages/UIStage.kt new file mode 100644 index 0000000..9dc93c6 --- /dev/null +++ b/core/src/main/kotlin/com/last/commit/stages/UIStage.kt @@ -0,0 +1,69 @@ +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.inventory.InventoryItemTextureLoader + +class UIStage(path: String, val state: GameState) : Stage() { + val textureLoader = InventoryItemTextureLoader(path) + private val labelStyle = Label.LabelStyle(BitmapFont(), Color.BLACK) + var mapLabel = Label(state.mapDescription, labelStyle) + var fpsLabel = Label("0", labelStyle) + private var lastFpsUpdate = 0L + + init { + textureLoader.parse() + } + + fun refresh() { + super.clear() + state.inventory.items.forEachIndexed { index, inventoryItem -> + val image = Image(textureLoader.getTexture(inventoryItem.name)) + image.x = index * 32f + image.width = 32f + image.height = 32f + + addActor(image) + } + } + + fun resize(width: Int, height: Int) { + viewport.update(width, height, true) + } + + override fun act(delta: Float) { + if (state.inventory.updated) { + this.refresh() + state.inventory.updated = false + } + this.addFpsLabel(delta) + this.addMapDescriptionLabel() + } + + override fun draw() { + super.draw() + } + + private fun addFpsLabel(delta: Float) { + if (System.currentTimeMillis() - lastFpsUpdate > 500) { + actors.removeValue(this.fpsLabel, true) + fpsLabel = Label((1 / delta).toInt().toString(), labelStyle) + fpsLabel.x = this.viewport.worldWidth - fpsLabel.width + fpsLabel.y = this.viewport.worldHeight - fpsLabel.height + addActor(fpsLabel) + lastFpsUpdate = System.currentTimeMillis() + } + } + + private fun addMapDescriptionLabel() { + this.actors.removeValue(this.mapLabel, true) + this.mapLabel = Label(state.mapDescription, labelStyle) + mapLabel.x = 0f + mapLabel.y = this.viewport.worldHeight - mapLabel.height + addActor(mapLabel) + } +}