mirror of
https://github.com/curioustorvald/Terrarum.git
synced 2026-06-12 19:44:05 +09:00
fix: bad spawn pos for fixtures with spawn offsets
This commit is contained in:
@@ -195,6 +195,8 @@ open class FixtureBase : ActorWithBody, CuedByTerrainChange {
|
|||||||
}
|
}
|
||||||
|
|
||||||
open fun canSpawnHere0(posX: Int, posY: Int): Boolean {
|
open fun canSpawnHere0(posX: Int, posY: Int): Boolean {
|
||||||
|
val (ox, oy) = spawnCustomGetSpawningOffset()
|
||||||
|
val posX = posX + ox; val posY = posY + oy
|
||||||
val everyBlockboxPos = getBlockBoxPositions(posX, posY)
|
val everyBlockboxPos = getBlockBoxPositions(posX, posY)
|
||||||
|
|
||||||
// check for existing blocks (and fixtures)
|
// check for existing blocks (and fixtures)
|
||||||
@@ -215,7 +217,12 @@ open class FixtureBase : ActorWithBody, CuedByTerrainChange {
|
|||||||
// check for floors, if spawnNeedsFloor == true
|
// check for floors, if spawnNeedsFloor == true
|
||||||
if (spawnNeedsFloor || spawnNeedsCeiling) {
|
if (spawnNeedsFloor || spawnNeedsCeiling) {
|
||||||
val yOff = if (spawnNeedsFloor) 1 else -1
|
val yOff = if (spawnNeedsFloor) 1 else -1
|
||||||
cannotSpawnNoFloor = everyBlockboxPos.filter { if (spawnNeedsFloor) it.second == posY + blockBox.height - 1 else it.second == posY }.any { (x, y) ->
|
cannotSpawnNoFloor = everyBlockboxPos.filter {
|
||||||
|
if (spawnNeedsFloor)
|
||||||
|
it.second == posY - oy + blockBox.height - 1
|
||||||
|
else
|
||||||
|
it.second == posY - oy
|
||||||
|
}.any { (x, y) ->
|
||||||
world!!.getTileFromTerrain(x, y + yOff).let {
|
world!!.getTileFromTerrain(x, y + yOff).let {
|
||||||
!canSpawnOnThisFloor(it)
|
!canSpawnOnThisFloor(it)
|
||||||
}
|
}
|
||||||
@@ -229,7 +236,7 @@ open class FixtureBase : ActorWithBody, CuedByTerrainChange {
|
|||||||
else if (spawnNeedsWall)
|
else if (spawnNeedsWall)
|
||||||
cannotSpawn = cannotSpawn or cannotSpawnNoWall
|
cannotSpawn = cannotSpawn or cannotSpawnNoWall
|
||||||
|
|
||||||
return !cannotSpawn
|
return (!cannotSpawn)
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -308,19 +315,28 @@ open class FixtureBase : ActorWithBody, CuedByTerrainChange {
|
|||||||
// posY: bottom of the blockBox
|
// posY: bottom of the blockBox
|
||||||
// using the actor's hitbox
|
// using the actor's hitbox
|
||||||
|
|
||||||
val (ox, oy) = spawnCustomGetSpawningOffset()
|
val posXmouse = posX0
|
||||||
val posX0 = posX0 + ox
|
val posYmouse = posY0
|
||||||
val posY0 = posY0 + oy
|
|
||||||
|
|
||||||
val posX = ox + (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
|
// `tl` stands for top-left
|
||||||
val posY = oy + posY0 - blockBox.height + 1
|
val posXtl = (posXmouse - 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 posYtl = posYmouse - blockBox.height + 1
|
||||||
|
|
||||||
|
if (!canSpawnHere(posXmouse, posYmouse)) {
|
||||||
|
printdbg(this, "cannot spawn fixture1 ${nameFun()} at F${INGAME.WORLD_UPDATE_TIMER}, has tile collision; xy=($posXtl,$posYtl) tDim=(${blockBox.width},${blockBox.height})")
|
||||||
|
|
||||||
|
// val (ox, oy) = spawnCustomGetSpawningOffset()
|
||||||
|
// val canSpawnHerePosX = (posXmouse - 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 canSpawnHerePosY = posYmouse - blockBox.height + 1
|
||||||
|
// val canSpawnHere0PosX = canSpawnHerePosX + ox
|
||||||
|
// val canSpawnHere0PosY = canSpawnHerePosY + oy
|
||||||
|
// val everyBlockboxPos = getBlockBoxPositions(canSpawnHere0PosX, canSpawnHere0PosY)
|
||||||
|
// printdbg(this, "posXYmouse=($posXmouse,$posYmouse), everyBlockboxPos=$everyBlockboxPos, canSpawnHere0PosXY=($canSpawnHere0PosX,$canSpawnHere0PosY)")
|
||||||
|
|
||||||
if (!canSpawnHere(posX0, posY0)) {
|
|
||||||
printdbg(this, "cannot spawn fixture1 ${nameFun()} at F${INGAME.WORLD_UPDATE_TIMER}, has tile collision; xy=($posX,$posY) tDim=(${blockBox.width},${blockBox.height})")
|
|
||||||
printStackTrace(this)
|
printStackTrace(this)
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
printdbg(this, "spawn fixture ${nameFun()} at F${INGAME.WORLD_UPDATE_TIMER}, xy=($posX,$posY) tDim=(${blockBox.width},${blockBox.height})")
|
printdbg(this, "spawn fixture ${nameFun()} at F${INGAME.WORLD_UPDATE_TIMER}, xy=($posXtl,$posYtl) tDim=(${blockBox.width},${blockBox.height})")
|
||||||
|
|
||||||
|
|
||||||
// at this point, worldBlockPos was set by the canSpawnHere() function
|
// at this point, worldBlockPos was set by the canSpawnHere() function
|
||||||
@@ -331,14 +347,14 @@ open class FixtureBase : ActorWithBody, CuedByTerrainChange {
|
|||||||
|
|
||||||
this.isVisible = true
|
this.isVisible = true
|
||||||
this.hitbox.setFromWidthHeight(
|
this.hitbox.setFromWidthHeight(
|
||||||
posX * TILE_SIZED,
|
posXtl * TILE_SIZED,
|
||||||
posY * TILE_SIZED,
|
posYtl * TILE_SIZED,
|
||||||
blockBox.width * TILE_SIZED,
|
blockBox.width * TILE_SIZED,
|
||||||
blockBox.height * TILE_SIZED
|
blockBox.height * TILE_SIZED
|
||||||
)
|
)
|
||||||
this.intTilewiseHitbox.setFromWidthHeight(
|
this.intTilewiseHitbox.setFromWidthHeight(
|
||||||
posX.toDouble(),
|
posXtl.toDouble(),
|
||||||
posY.toDouble(),
|
posYtl.toDouble(),
|
||||||
blockBox.width.toDouble(),
|
blockBox.width.toDouble(),
|
||||||
blockBox.height.toDouble()
|
blockBox.height.toDouble()
|
||||||
)
|
)
|
||||||
@@ -349,9 +365,9 @@ open class FixtureBase : ActorWithBody, CuedByTerrainChange {
|
|||||||
|
|
||||||
actorThatInstalledThisFixture = installersUUID
|
actorThatInstalledThisFixture = installersUUID
|
||||||
|
|
||||||
makeNoiseAndDust(posX, posY)
|
makeNoiseAndDust(posXtl, posYtl)
|
||||||
|
|
||||||
onSpawn(posX0, posY0)
|
onSpawn(posXmouse, posYmouse)
|
||||||
|
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -50,7 +50,7 @@ class UIQuickslotBar : UICanvas() {
|
|||||||
const val COMMON_OPEN_CLOSE = 0.12f
|
const val COMMON_OPEN_CLOSE = 0.12f
|
||||||
// val QUICKSLOT_ITEMCOUNT_TEXTCOL = Color(0xdb6f00ff.toInt())
|
// val QUICKSLOT_ITEMCOUNT_TEXTCOL = Color(0xdb6f00ff.toInt())
|
||||||
// val QUICKSLOT_ITEMCOUNT_TEXTCOL = Color(0x0099bbff.toInt())
|
// val QUICKSLOT_ITEMCOUNT_TEXTCOL = Color(0x0099bbff.toInt())
|
||||||
val QUICKSLOT_ITEMCOUNT_TEXTCOL = Color(0xce773bff.toInt())
|
val QUICKSLOT_ITEMCOUNT_TEXTCOL = Color(0xc36f37ff.toInt())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user