Add map descripton and fps counter

imgbot
trivernis 1 year ago
parent eeba41edbc
commit b04d982198
Signed by: Trivernis
GPG Key ID: DFFFCC2C7A02DB45

@ -1,6 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<map version="1.9" tiledversion="1.9.1" orientation="orthogonal" renderorder="right-down" width="30" height="30" tilewidth="64" tileheight="64" infinite="0" nextlayerid="11" nextobjectid="3">
<map version="1.9" tiledversion="1.9.2" orientation="orthogonal" renderorder="right-down" width="30" height="30" tilewidth="64" tileheight="64" infinite="0" nextlayerid="11" nextobjectid="3">
<properties>
<property name="description" value="2030"/>
<property name="id" type="int" value="1"/>
</properties>
<tileset firstgid="1" source="tilesheet_complete.tsx"/>

@ -1,6 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<map version="1.9" tiledversion="1.9.1" orientation="orthogonal" renderorder="right-down" width="30" height="30" tilewidth="64" tileheight="64" infinite="0" nextlayerid="12" nextobjectid="9">
<map version="1.9" tiledversion="1.9.2" orientation="orthogonal" renderorder="right-down" width="30" height="30" tilewidth="64" tileheight="64" infinite="0" nextlayerid="12" nextobjectid="9">
<properties>
<property name="description" value="2040"/>
<property name="id" type="int" value="2"/>
</properties>
<tileset firstgid="1" source="tilesheet_complete.tsx"/>

@ -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"
)

@ -4,14 +4,15 @@ class Inventory {
val items: MutableList<InventoryItem> = 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) {

@ -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)

@ -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<Interactable>) {
@ -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()
}

@ -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()
}
}
}

@ -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)
}
}
Loading…
Cancel
Save