mirror of
https://github.com/curioustorvald/Terrarum.git
synced 2026-06-11 19:14:05 +09:00
fixture ghost is now red when it cant be placed there
This commit is contained in:
@@ -225,6 +225,24 @@ open class FixtureBase : ActorWithBody, CuedByTerrainChange {
|
||||
}
|
||||
}
|
||||
|
||||
fun canSpawnHere(posX0: Int, posY0: Int): Boolean {
|
||||
val posX = (posX0 - blockBox.width.minus(1).div(2)) fmod world!!.width // width.minus(1) so that spawning position would be same as the ghost's position
|
||||
val posY = posY0 - blockBox.height + 1
|
||||
|
||||
// check for existing blocks (and fixtures)
|
||||
var hasCollision = false
|
||||
worldBlockPos = Point2i(posX, posY)
|
||||
forEachBlockbox { x, y, _, _ ->
|
||||
if (!hasCollision) {
|
||||
val tile = world!!.getTileFromTerrain(x, y)
|
||||
if (!BlockCodex[tile].hasTag("INCONSEQUENTIAL")) {
|
||||
hasCollision = true
|
||||
}
|
||||
}
|
||||
}
|
||||
return !hasCollision
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds this instance of the fixture to the world. Physical dimension is derived from [blockBox].
|
||||
*
|
||||
@@ -243,24 +261,10 @@ open class FixtureBase : ActorWithBody, CuedByTerrainChange {
|
||||
// posY: bottom of the blockBox
|
||||
// using the actor's hitbox
|
||||
|
||||
|
||||
val posX = (posX0 - blockBox.width.minus(1).div(2)) fmod world!!.width // width.minus(1) so that spawning position would be same as the ghost's position
|
||||
val posY = posY0 - blockBox.height + 1
|
||||
|
||||
// set the position of this actor
|
||||
worldBlockPos = Point2i(posX, posY)
|
||||
|
||||
// check for existing blocks (and fixtures)
|
||||
var hasCollision = false
|
||||
forEachBlockbox { x, y, _, _ ->
|
||||
if (!hasCollision) {
|
||||
val tile = world!!.getTileFromTerrain(x, y)
|
||||
if (!BlockCodex[tile].hasTag("INCONSEQUENTIAL")) {
|
||||
hasCollision = true
|
||||
}
|
||||
}
|
||||
}
|
||||
if (hasCollision) {
|
||||
if (!canSpawnHere(posX0, posY0)) {
|
||||
printdbg(this, "cannot spawn fixture ${nameFun()} at F${INGAME.WORLD_UPDATE_TIMER}, has tile collision; xy=($posX,$posY) tDim=(${blockBox.width},${blockBox.height})")
|
||||
return false
|
||||
}
|
||||
|
||||
@@ -223,23 +223,23 @@ open class FixtureSwingingDoorBase : FixtureBase {
|
||||
|
||||
}
|
||||
|
||||
private fun mouseOnLeftSide(): Boolean {
|
||||
private fun mouseOnLeftSide(mx: Double, my: Double): Boolean {
|
||||
val ww = INGAME.world.width * TILE_SIZED
|
||||
val pivot = this@FixtureSwingingDoorBase.hitbox.centeredX
|
||||
// note: this function uses startX while the dual other function uses endX; the "dist" must be same between two functions
|
||||
val dist = pivot - Terrarum.mouseX // NOTE: order is different from the other function
|
||||
val dist2 = pivot - (Terrarum.mouseX - ww)
|
||||
val dist = pivot - mx // NOTE: order is different from the other function
|
||||
val dist2 = pivot - (mx - ww)
|
||||
val distLim = this@FixtureSwingingDoorBase.hitbox.width
|
||||
return (dist in 0.0..distLim || dist2 in 0.0..distLim) && (Terrarum.mouseY - hitbox.hitboxStart.y) in 0.0..hitbox.height
|
||||
return (dist in 0.0..distLim || dist2 in 0.0..distLim) && (my - hitbox.hitboxStart.y) in 0.0..hitbox.height
|
||||
}
|
||||
|
||||
private fun mouseOnRightSide(): Boolean {
|
||||
private fun mouseOnRightSide(mx: Double, my: Double): Boolean {
|
||||
val ww = INGAME.world.width * TILE_SIZED
|
||||
val pivot = this@FixtureSwingingDoorBase.hitbox.centeredX
|
||||
val dist = Terrarum.mouseX - pivot // NOTE: order is different from the other function
|
||||
val dist2 = (Terrarum.mouseX + ww) - pivot
|
||||
val dist = mx - pivot // NOTE: order is different from the other function
|
||||
val dist2 = (mx + ww) - pivot
|
||||
val distLim = this@FixtureSwingingDoorBase.hitbox.width
|
||||
return dist in 0.0..distLim || dist2 in 0.0..distLim && (Terrarum.mouseY - hitbox.hitboxStart.y) in 0.0..hitbox.height
|
||||
return dist in 0.0..distLim || dist2 in 0.0..distLim && (my - hitbox.hitboxStart.y) in 0.0..hitbox.height
|
||||
}
|
||||
|
||||
private fun ActorWithBody.ontheLeftSideOfDoor(): Boolean {
|
||||
@@ -313,16 +313,16 @@ open class FixtureSwingingDoorBase : FixtureBase {
|
||||
if (mouseUp && Gdx.input.isButtonPressed(App.getConfigInt("config_mousesecondary"))) {
|
||||
|
||||
INGAME.actorNowPlaying?.let { player ->
|
||||
mouseInInteractableRange(player) {
|
||||
mouseInInteractableRange(player) { mx, my, _, _ ->
|
||||
// keep opened/closed as long as the mouse is down
|
||||
if (doorStateTimer != 0f) {
|
||||
oldStateBeforeMouseDown = doorState
|
||||
}
|
||||
|
||||
if (oldStateBeforeMouseDown == 0) {
|
||||
if (mouseOnLeftSide())
|
||||
if (mouseOnLeftSide(mx, my))
|
||||
openToLeft(1)
|
||||
else if (mouseOnRightSide())
|
||||
else if (mouseOnRightSide(mx, my))
|
||||
openToRight(1)
|
||||
}
|
||||
else {
|
||||
|
||||
Reference in New Issue
Block a user