From 3e7efc0fb78375c8ac3abb5a7b376a19a5712809 Mon Sep 17 00:00:00 2001 From: trivernis Date: Sat, 19 Nov 2022 22:12:25 +0100 Subject: [PATCH] Add rendering of collectables on the map --- .../kotlin/com/last/commit/map/TimeMap.kt | 20 ++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) 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 ec8cf01..7571482 100644 --- a/core/src/main/kotlin/com/last/commit/map/TimeMap.kt +++ b/core/src/main/kotlin/com/last/commit/map/TimeMap.kt @@ -11,16 +11,19 @@ import com.badlogic.gdx.maps.tiled.renderers.OrthogonalTiledMapRenderer import com.badlogic.gdx.math.Rectangle import com.badlogic.gdx.math.Vector2 import com.badlogic.gdx.utils.Array +import com.badlogic.gdx.scenes.scene2d.ui.Image import com.last.commit.Collidable import com.last.commit.Player import com.last.commit.Wall import com.last.commit.audio.GameSoundEffect +import com.last.commit.inventory.InventoryItemTextureLoader import Position import GameState class TimeMap(fileName: String, val state: GameState) { private val CELL_SIZE = 64 + val textureLoader = InventoryItemTextureLoader("sprites/genericItems_spritesheet_colored") private val walls = Array() private val doors = Array() @@ -46,6 +49,7 @@ class TimeMap(fileName: String, val state: GameState) { loadDimensions() loadWalls() loadCollectibles() + this.textureLoader.parse() } fun teleport(player: Player) { @@ -91,7 +95,12 @@ 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) + + if (prop.containsKey("description")) { + this.description = prop.get("description", String::class.java) + } else { + this.description = "Unknown time" + } this.state.mapDescription = this.description this.width = gridWidth * CELL_SIZE this.height = gridHeight * CELL_SIZE @@ -105,6 +114,7 @@ class TimeMap(fileName: String, val state: GameState) { walls.clear() doors.clear() val wallsLayer = map.layers["Walls"] as TiledMapTileLayer + for (column in 0 until wallsLayer.width) { for (row in 0 until wallsLayer.height) { val cell: TiledMapTileLayer.Cell? = wallsLayer.getCell(column, row) @@ -191,6 +201,14 @@ class TimeMap(fileName: String, val state: GameState) { fun render(batch: SpriteBatch, camera: OrthographicCamera, delta: Float) { mapRenderer.setView(camera) mapRenderer.render() + this.collectibles.forEach { coll -> + val image = Image(textureLoader.getTexture(coll.name)) + image.x = coll.pos.x + this.getTileWidth() * 0.1f + image.y = coll.pos.y + this.getTileHeight() * 0.1f + image.width = this.getTileWidth() * 0.8f + image.height = this.getTileHeight() * 0.8f + image.draw(batch, 1f) + } } fun isCollidingWith(collidable: Collidable): Boolean {