update door handling

viewport-stuff
Matthias 2 years ago
parent 9e6bca542a
commit 26cbf95526

@ -51,7 +51,7 @@ class FirstScreen : Screen, InputProcessor {
player.addItemToInventory("drill")
inventoryStage = InventoryStage(player.inventory)
shapeRenderer.setAutoShapeType(true);
shapeRenderer.setAutoShapeType(true)
Gdx.input.setInputProcessor(this)
}
@ -75,7 +75,7 @@ class FirstScreen : Screen, InputProcessor {
val mousePosition: Vector2 = getMousePosition()
player.lookAt(mousePosition)
var interactables = map.getInteractablesAt(
val interactables = map.getInteractablesAt(
player.getAbsoluteDirection()
)
@ -94,11 +94,11 @@ class FirstScreen : Screen, InputProcessor {
}
fun renderInteractables(interactables: List<Interactable>) {
Gdx.gl.glEnable(GL20.GL_BLEND);
Gdx.gl.glBlendFunc(GL20.GL_SRC_ALPHA, GL20.GL_ONE_MINUS_SRC_ALPHA);
shapeRenderer.setProjectionMatrix(this.camera.combined);
shapeRenderer.setColor(highlightColor);
shapeRenderer.begin(ShapeRenderer.ShapeType.Filled);
Gdx.gl.glEnable(GL20.GL_BLEND)
Gdx.gl.glBlendFunc(GL20.GL_SRC_ALPHA, GL20.GL_ONE_MINUS_SRC_ALPHA)
shapeRenderer.setProjectionMatrix(this.camera.combined)
shapeRenderer.setColor(highlightColor)
shapeRenderer.begin(ShapeRenderer.ShapeType.Filled)
for (interactable in interactables) {
shapeRenderer.rect(
interactable.getCollider().x,
@ -108,7 +108,7 @@ class FirstScreen : Screen, InputProcessor {
)
}
shapeRenderer.end()
Gdx.gl.glDisable(GL20.GL_BLEND);
Gdx.gl.glDisable(GL20.GL_BLEND)
}
private fun getMousePosition(): Vector2 {
@ -164,7 +164,7 @@ class FirstScreen : Screen, InputProcessor {
}
private fun checkCollision() {
this.isColliding = map.isCollidingWithWall(player)
this.isColliding = map.isCollidingWith(player)
}
fun updateCamera() {

@ -6,9 +6,9 @@ import com.last.commit.Wall
class Door(gridX: Int, gridY: Int, wallCollider: Rectangle, cell: Cell) :
Wall(gridX, gridY, wallCollider, cell), Toggleable {
override fun toggle() {
println("Toggling door$this")
Wall(gridX, gridY, wallCollider, cell), Interactable {
override fun interact() {
println("Toggling door $this")
isOpen = !isOpen
}

@ -20,6 +20,7 @@ class TimeMap(fileName: String) {
private val CELL_SIZE = 64
private val walls = Array<Wall>()
private val doors = Array<Door>()
private val collectibles = Array<Collectible>()
val mapLoader: TmxMapLoader = TmxMapLoader()
var mapRenderer: OrthogonalTiledMapRenderer
@ -93,6 +94,7 @@ class TimeMap(fileName: String) {
private fun loadWalls() {
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) {
@ -104,13 +106,11 @@ class TimeMap(fileName: String) {
row.toFloat() * wallsLayer.tileHeight, wallsLayer.tileWidth.toFloat(),
wallsLayer.tileHeight.toFloat()
)
val wall: Wall
if (java.lang.Boolean.TRUE == isDoor) {
wall = Door(column, row, wallCollider, cell)
doors.add(Door(column, row, wallCollider, cell))
} else {
wall = Wall(column, row, wallCollider, cell)
walls.add(Wall(column, row, wallCollider, cell))
}
walls.add(wall)
}
}
}
@ -141,9 +141,9 @@ class TimeMap(fileName: String) {
}
private fun findDoorByGridPosition(gridX: Int, gridY: Int): Door? {
for (wall in walls) {
if (wall.gridX == gridX && wall.gridY == gridY && wall is Door) {
return wall
for (door in doors) {
if (door.gridX == gridX && door.gridY == gridY && door is Door) {
return door
}
}
return null
@ -180,12 +180,18 @@ class TimeMap(fileName: String) {
mapRenderer.render()
}
fun isCollidingWithWall(collidable: Collidable): Boolean {
fun isCollidingWith(collidable: Collidable): Boolean {
for (wall in walls) {
if (wall.collidesWidth(collidable)) {
return true
}
}
for (door in doors) {
if (door.collidesWidth(collidable)) {
return true
}
}
return false
}
@ -193,8 +199,8 @@ class TimeMap(fileName: String) {
val interactables = ArrayList<Interactable>()
val c = collectibles.filter { it.getCollider().contains(absoluteDirection) }
interactables.addAll(c)
val w = walls.filter { it.getCollider().contains(absoluteDirection) }
// interactables.addAll(w)
val w = doors.filter { it.getCollider().contains(absoluteDirection) }
interactables.addAll(w)
return interactables
}

@ -1,9 +0,0 @@
package com.last.commit.map
interface Toggleable : Interactable {
fun toggle()
override fun interact() {
toggle()
}
}
Loading…
Cancel
Save