Merge branch 'main' of github.com:Trivernis/gamejam-22

main
trivernis 2 years ago
commit 4c508a2e55
Signed by: Trivernis
GPG Key ID: DFFFCC2C7A02DB45

@ -1,5 +1,7 @@
package com.last.commit.map package com.last.commit.map
import GameState
import Position
import com.badlogic.gdx.Gdx import com.badlogic.gdx.Gdx
import com.badlogic.gdx.graphics.OrthographicCamera import com.badlogic.gdx.graphics.OrthographicCamera
import com.badlogic.gdx.graphics.g2d.SpriteBatch import com.badlogic.gdx.graphics.g2d.SpriteBatch
@ -10,15 +12,13 @@ import com.badlogic.gdx.maps.tiled.TmxMapLoader
import com.badlogic.gdx.maps.tiled.renderers.OrthogonalTiledMapRenderer 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.scenes.scene2d.ui.Image import com.badlogic.gdx.scenes.scene2d.ui.Image
import com.badlogic.gdx.utils.Array
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 com.last.commit.inventory.InventoryItemTextureLoader
import Position
import GameState
class TimeMap(fileName: String, val state: GameState) { class TimeMap(fileName: String, val state: GameState) {
@ -29,8 +29,8 @@ class TimeMap(fileName: String, val state: GameState) {
private val doors = Array<Door>() private val doors = Array<Door>()
private val collectibles = Array<Collectible>() private val collectibles = Array<Collectible>()
val mapLoader: TmxMapLoader = TmxMapLoader() val mapLoader: TmxMapLoader = TmxMapLoader()
var mapRenderer: OrthogonalTiledMapRenderer lateinit var mapRenderer: OrthogonalTiledMapRenderer
var map: TiledMap lateinit var map: TiledMap
var gridWidth = 0 var gridWidth = 0
var gridHeight = 0 var gridHeight = 0
var width = 0 var width = 0
@ -44,14 +44,19 @@ class TimeMap(fileName: String, val state: GameState) {
init { init {
map = mapLoader.load(fileName) loadMap(fileName)
mapRenderer = OrthogonalTiledMapRenderer(map)
loadDimensions() loadDimensions()
loadWalls() loadWalls()
loadCollectibles() loadCollectibles()
this.textureLoader.parse() this.textureLoader.parse()
} }
private fun loadMap(fileName: String) {
println("Loading map $fileName")
map = mapLoader.load(fileName)
mapRenderer = OrthogonalTiledMapRenderer(map)
}
fun teleport(player: Player) { fun teleport(player: Player) {
val teleporters = map.layers["Teleporter"].objects val teleporters = map.layers["Teleporter"].objects
for (teleporter in teleporters) { for (teleporter in teleporters) {
@ -60,8 +65,7 @@ class TimeMap(fileName: String, val state: GameState) {
state.soundEngine.play(GameSoundEffect.TIME_TRAVEL) state.soundEngine.play(GameSoundEffect.TIME_TRAVEL)
val targetMap = teleporter.properties.get("target", String::class.java) val targetMap = teleporter.properties.get("target", String::class.java)
System.out.println("Teleporting to targetMap $targetMap") System.out.println("Teleporting to targetMap $targetMap")
map = mapLoader.load("tiled/$targetMap") loadMap("tiled/$targetMap")
mapRenderer.map = map
loadDimensions() loadDimensions()
loadWalls() loadWalls()
loadCollectibles() loadCollectibles()
@ -98,7 +102,7 @@ class TimeMap(fileName: String, val state: GameState) {
if (prop.containsKey("description")) { if (prop.containsKey("description")) {
this.description = prop.get("description", String::class.java) this.description = prop.get("description", String::class.java)
} else { } else {
this.description = "Unknown time" this.description = "Unknown time"
} }
this.state.mapDescription = this.description this.state.mapDescription = this.description
@ -203,7 +207,7 @@ 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 -> this.collectibles.forEach { coll ->
val image = Image(textureLoader.getTexture(coll.name)) val image = Image(textureLoader.getTexture(coll.name))
image.x = coll.pos.x + this.getTileWidth() * 0.1f image.x = coll.pos.x + this.getTileWidth() * 0.1f
image.y = coll.pos.y + this.getTileHeight() * 0.1f image.y = coll.pos.y + this.getTileHeight() * 0.1f

Loading…
Cancel
Save