Add rendering of collectables on the map

imgbot
trivernis 2 years ago
parent 4e217aca5e
commit 3e7efc0fb7
Signed by: Trivernis
GPG Key ID: DFFFCC2C7A02DB45

@ -11,16 +11,19 @@ import com.badlogic.gdx.maps.tiled.renderers.OrthogonalTiledMapRenderer
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.badlogic.gdx.utils.Array import com.badlogic.gdx.utils.Array
import com.badlogic.gdx.scenes.scene2d.ui.Image
import com.last.commit.Collidable import com.last.commit.Collidable
import com.last.commit.Player import com.last.commit.Player
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.InventoryItemTextureLoader
import Position import Position
import GameState import GameState
class TimeMap(fileName: String, val state: GameState) { class TimeMap(fileName: String, val state: GameState) {
private val CELL_SIZE = 64 private val CELL_SIZE = 64
val textureLoader = InventoryItemTextureLoader("sprites/genericItems_spritesheet_colored")
private val walls = Array<Wall>() private val walls = Array<Wall>()
private val doors = Array<Door>() private val doors = Array<Door>()
@ -46,6 +49,7 @@ class TimeMap(fileName: String, val state: GameState) {
loadDimensions() loadDimensions()
loadWalls() loadWalls()
loadCollectibles() loadCollectibles()
this.textureLoader.parse()
} }
fun teleport(player: Player) { fun teleport(player: Player) {
@ -91,7 +95,12 @@ class TimeMap(fileName: String, val state: GameState) {
val prop = map.properties val prop = map.properties
this.gridWidth = prop.get("width", Int::class.java) this.gridWidth = prop.get("width", Int::class.java)
this.gridHeight = prop.get("height", 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.state.mapDescription = this.description
this.width = gridWidth * CELL_SIZE this.width = gridWidth * CELL_SIZE
this.height = gridHeight * CELL_SIZE this.height = gridHeight * CELL_SIZE
@ -105,6 +114,7 @@ class TimeMap(fileName: String, val state: GameState) {
walls.clear() walls.clear()
doors.clear() doors.clear()
val wallsLayer = map.layers["Walls"] as TiledMapTileLayer val wallsLayer = map.layers["Walls"] as TiledMapTileLayer
for (column in 0 until wallsLayer.width) { for (column in 0 until wallsLayer.width) {
for (row in 0 until wallsLayer.height) { for (row in 0 until wallsLayer.height) {
val cell: TiledMapTileLayer.Cell? = wallsLayer.getCell(column, row) 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) { fun render(batch: SpriteBatch, camera: OrthographicCamera, delta: Float) {
mapRenderer.setView(camera) mapRenderer.setView(camera)
mapRenderer.render() 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 { fun isCollidingWith(collidable: Collidable): Boolean {

Loading…
Cancel
Save