|
|
|
@ -1,17 +1,17 @@
|
|
|
|
|
package com.last.commit.map
|
|
|
|
|
|
|
|
|
|
import com.last.commit.map.Collectible
|
|
|
|
|
import com.last.commit.map.Door
|
|
|
|
|
import com.last.commit.Wall
|
|
|
|
|
import com.badlogic.gdx.maps.tiled.TiledMap
|
|
|
|
|
import com.badlogic.gdx.maps.tiled.TiledMapTileLayer
|
|
|
|
|
import com.badlogic.gdx.maps.MapObject
|
|
|
|
|
import com.badlogic.gdx.maps.objects.RectangleMapObject
|
|
|
|
|
import com.badlogic.gdx.math.Vector2
|
|
|
|
|
import com.badlogic.gdx.maps.tiled.TiledMap
|
|
|
|
|
import com.badlogic.gdx.maps.tiled.TiledMapTileLayer
|
|
|
|
|
import com.badlogic.gdx.math.Rectangle
|
|
|
|
|
import kotlin.math.round;
|
|
|
|
|
import com.badlogic.gdx.math.Vector2
|
|
|
|
|
import com.badlogic.gdx.scenes.scene2d.ui.Image
|
|
|
|
|
import com.last.commit.Wall
|
|
|
|
|
import com.last.commit.inventory.InventoryItemTextureLoader
|
|
|
|
|
import kotlin.math.round
|
|
|
|
|
|
|
|
|
|
class MapState(val map: TiledMap) {
|
|
|
|
|
class MapState(val map: TiledMap, val textureLoader: InventoryItemTextureLoader) {
|
|
|
|
|
private val CELL_SIZE = 64
|
|
|
|
|
|
|
|
|
|
val size: Vector2
|
|
|
|
@ -78,7 +78,12 @@ class MapState(val map: TiledMap) {
|
|
|
|
|
val requiredItem = obj.properties.get("requiredItem", String::class.java) ?: ""
|
|
|
|
|
|
|
|
|
|
if (itemName != null) {
|
|
|
|
|
Collectible(itemName, Position(coords, gridCoords), size, requiredItem)
|
|
|
|
|
val image = Image(textureLoader.getTexture(itemName))
|
|
|
|
|
image.x = coords.x + tileSize.x * 0.1f
|
|
|
|
|
image.y = coords.y + tileSize.y * 0.1f
|
|
|
|
|
image.width = tileSize.x * 0.8f
|
|
|
|
|
image.height = tileSize.y * 0.8f
|
|
|
|
|
Collectible(itemName, Position(coords, gridCoords), size, requiredItem, image)
|
|
|
|
|
} else {
|
|
|
|
|
null
|
|
|
|
|
}
|
|
|
|
@ -95,11 +100,14 @@ class MapState(val map: TiledMap) {
|
|
|
|
|
for (column in 0 until wallsLayer.width) {
|
|
|
|
|
for (row in 0 until wallsLayer.height) {
|
|
|
|
|
val cell = wallsLayer.getCell(column, row) ?: continue
|
|
|
|
|
val isDoor: Boolean = cell.getTile().getProperties().get("isDoor", false, Boolean::class.java)
|
|
|
|
|
val isDoor: Boolean =
|
|
|
|
|
cell.getTile().getProperties().get("isDoor", false, Boolean::class.java)
|
|
|
|
|
|
|
|
|
|
val wallCollider = Rectangle(
|
|
|
|
|
val wallCollider =
|
|
|
|
|
Rectangle(
|
|
|
|
|
column.toFloat() * wallsLayer.tileWidth,
|
|
|
|
|
row.toFloat() * wallsLayer.tileHeight, wallsLayer.tileWidth.toFloat(),
|
|
|
|
|
row.toFloat() * wallsLayer.tileHeight,
|
|
|
|
|
wallsLayer.tileWidth.toFloat(),
|
|
|
|
|
wallsLayer.tileHeight.toFloat()
|
|
|
|
|
)
|
|
|
|
|
if (java.lang.Boolean.TRUE == isDoor) {
|
|
|
|
@ -110,5 +118,4 @@ class MapState(val map: TiledMap) {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|