Merge remote-tracking branch 'origin/main'

main
lihell 1 year ago
commit 602ccf1084

@ -14,4 +14,5 @@ data class GameState(
val assetManager: TimeTravelAssetManager,
var map: MapState? = null,
val dialogStage: DialogStage
)
) {
}

@ -5,7 +5,8 @@ import com.last.commit.GameState
class Inventory() {
val items: MutableList<InventoryItem> = ArrayList()
public var updated = false
var updated = false
private val requiredItems = listOf("ram", "iphone", "ipod", "screwdriver")
/**
* @param name the name of the subtexture loaded from xml
@ -30,4 +31,10 @@ class Inventory() {
fun remove(name: String) {
items.removeIf() { item -> item.name == name }
}
fun checkVictoryCondition(): Boolean {
return requiredItems.all {itemName ->
items.find { it.name == itemName } != null
}
}
}

@ -13,6 +13,7 @@ class InventoryItemTextureLoader(path: String) {
private val textureMapping: FileHandle
private lateinit var subTextures: Array<XmlReader.Element>
private val textures: HashMap<String, TextureRegion> = HashMap()
private var initialized: Boolean = false
init {
itemsSpriteSheet = Texture("${path}.png")
@ -20,6 +21,9 @@ class InventoryItemTextureLoader(path: String) {
}
fun getTexture(itemName: String): TextureRegion {
if (!initialized) {
this.parse()
}
var itemTexture = textures.get(itemName)
if (itemTexture == null) {
@ -39,5 +43,6 @@ class InventoryItemTextureLoader(path: String) {
val textureAtlasElement = xml.parse(textureMapping)
this.subTextures = textureAtlasElement.getChildrenByName("SubTexture")
println("Found ${subTextures.size} textures")
this.initialized = true
}
}

@ -2,6 +2,7 @@ package com.last.commit.map
import com.badlogic.gdx.math.Rectangle
import com.badlogic.gdx.math.Vector2
import com.badlogic.gdx.scenes.scene2d.ui.Image
import com.last.commit.GameState
import com.last.commit.audio.GameSoundEffect
import com.last.commit.inventory.InventoryItem
@ -10,7 +11,8 @@ class Collectible(
name: String,
val pos: Position,
val size: Vector2,
val requiredItem: String
val requiredItem: String,
val image: Image
) : Interactable {
val name: String

@ -1,29 +1,29 @@
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
val gridSize: Vector2
val tileSize: Vector2
val tileSize: Vector2
val description: String?
val collectibles: ArrayList<Collectible> = ArrayList()
val teleporters: ArrayList<RectangleMapObject> = ArrayList()
val walls: ArrayList<Wall> = ArrayList()
val doors: ArrayList<Door> = ArrayList()
init {
val prop = map.properties
val gridWidth = prop.get("width", Int::class.java)
@ -50,8 +50,8 @@ class MapState(val map: TiledMap) {
println("No Teleporters defined!")
}
}
private fun loadCollectibles() {
private fun loadCollectibles() {
val collectiableLayer = map.layers["Collectibles"]
if (collectiableLayer == null) {
println("Could not load collectibles layer. Check map.")
@ -62,7 +62,7 @@ class MapState(val map: TiledMap) {
println("Loaded ${collectibles.size} collectibles")
}
private fun createCollectible(obj: MapObject): Collectible? {
val x = obj.properties.get("x", Float::class.java)
val y = obj.properties.get("y", Float::class.java)
@ -72,13 +72,18 @@ class MapState(val map: TiledMap) {
val width = obj.properties.get("width", Float::class.java)
val height = obj.properties.get("height", Float::class.java)
val size = Vector2(width, height)
return if (obj is RectangleMapObject) {
val itemName: String? = obj.properties.get("item", String::class.java)
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
}
@ -94,14 +99,17 @@ 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 wallCollider = Rectangle(
column.toFloat() * wallsLayer.tileWidth,
row.toFloat() * wallsLayer.tileHeight, wallsLayer.tileWidth.toFloat(),
wallsLayer.tileHeight.toFloat()
)
val cell = wallsLayer.getCell(column, row) ?: continue
val isDoor: Boolean =
cell.getTile().getProperties().get("isDoor", false, Boolean::class.java)
val wallCollider =
Rectangle(
column.toFloat() * wallsLayer.tileWidth,
row.toFloat() * wallsLayer.tileHeight,
wallsLayer.tileWidth.toFloat(),
wallsLayer.tileHeight.toFloat()
)
if (java.lang.Boolean.TRUE == isDoor) {
doors.add(Door(column, row, wallCollider, cell))
} else {
@ -110,5 +118,4 @@ class MapState(val map: TiledMap) {
}
}
}
}
}

@ -46,11 +46,10 @@ class TimeMap(fileName: String, val state: GameState) {
init {
map = mapLoader.load(fileName)
mapState = MapState(map)
mapState = MapState(map, textureLoader)
state.map = mapState
mapStates[fileName] = mapState
mapRenderer = OrthogonalTiledMapRenderer(map)
this.textureLoader.parse()
}
@ -63,6 +62,9 @@ class TimeMap(fileName: String, val state: GameState) {
val targetMap = teleporter.properties.get("target", String::class.java)
System.out.println("Teleporting to targetMap $targetMap")
loadMap("tiled/$targetMap")
val mapDescription = mapState.description
state.dialogStage.setTexts("You teleported to $mapDescription")
state.dialogStage.show()
}
}
@ -74,7 +76,7 @@ class TimeMap(fileName: String, val state: GameState) {
} else {
val map = mapLoader.load(name)
mapRenderer.map = map
mapState = MapState(map)
mapState = MapState(map, textureLoader)
mapStates[name] = mapState
}
state.map = mapState

@ -123,7 +123,12 @@ class FirstScreen(private val parent: Game) : TimeTravelScreen() {
}
override fun render(delta: Float) {
if (!pause) {
if (gameState.inventory.checkVictoryCondition()) {
gameState.dialogStage.show()
gameState.dialogStage.act(delta)
gameState.dialogStage.setTexts("You won!")
gameState.dialogStage.draw()
} else if (!pause) {
uiStage.act(delta)
gameState.dialogStage.act(delta)
handleInput(delta)

@ -2,6 +2,7 @@ package com.last.commit.stages
import com.badlogic.gdx.graphics.Color
import com.badlogic.gdx.graphics.g2d.BitmapFont
import com.badlogic.gdx.graphics.glutils.ShapeRenderer
import com.badlogic.gdx.scenes.scene2d.Stage
import com.badlogic.gdx.scenes.scene2d.ui.Image
import com.badlogic.gdx.scenes.scene2d.ui.Label

Loading…
Cancel
Save