You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
gamejam-22/core/src/main/kotlin/com/last/commit/map/Door.kt

49 lines
1.5 KiB
Kotlin

package com.last.commit.map
import com.badlogic.gdx.maps.tiled.TiledMapTileLayer.Cell
import com.badlogic.gdx.math.Rectangle
import com.last.commit.Wall
class Door(gridX: Int, gridY: Int, wallCollider: Rectangle, cell: Cell) :
Wall(gridX, gridY, wallCollider, cell), Interactable {
override fun interact(otherCollider: Rectangle) {
println("interacting with door $this")
if (isClosed) {
isOpen = true
} else if (isOpen) {
if (getCollider().overlaps(otherCollider)) {
// can't close the door cause it is colliding with given collider
} else {
isOpen = false
}
}
println("Door is now open = $isOpen")
}
var isOpen: Boolean
get() = !isClosed
set(isOpen) {
val currentRotation: Int = cell.getRotation()
if (isOpen) {
cell.setRotation(currentRotation + 1)
} else {
cell.setRotation(currentRotation - 1)
}
}
val isClosed: Boolean
get() {
val currentRotation: Int = cell.getRotation()
return currentRotation == 0
}
override val isCollidable: Boolean
get() = !isOpen
override fun toString(): String {
return String.format(
"Door: %f:%f - %f:%f (isOpen: %b)", wallCollider.x, wallCollider.y, wallCollider.width,
wallCollider.height, isOpen
)
}
}