mirror of
https://github.com/curioustorvald/Terrarum.git
synced 2026-03-07 20:31:51 +09:00
turns out it was not a cause of the "oscillating platform" bug
This commit is contained in:
@@ -1285,12 +1285,12 @@ open class ActorWithBody : Actor {
|
||||
(BlockCodex[tile].isSolid)
|
||||
|
||||
// the location and size of the platform in world coord
|
||||
protected var platformsToIgnore: Hitbox? = null
|
||||
protected var platformToIgnore: Hitbox? = null
|
||||
|
||||
private fun standingOnIgnoredPlatform(): Boolean = platformsToIgnore.let {
|
||||
private fun standingOnIgnoredPlatform(): Boolean = platformToIgnore.let {
|
||||
return if (it != null)
|
||||
hitbox.startX >= it.startX && hitbox.endX <= it.endX - PHYS_EPSILON_DIST &&
|
||||
it.startY <= hitbox.endY && hitbox.endY <= it.endY - PHYS_EPSILON_DIST
|
||||
hitbox.startX >= it.startX && hitbox.endX < it.endX - PHYS_EPSILON_DIST &&
|
||||
it.startY <= hitbox.endY && hitbox.endY < it.endY - PHYS_EPSILON_DIST
|
||||
else false
|
||||
}
|
||||
|
||||
@@ -1303,17 +1303,15 @@ open class ActorWithBody : Actor {
|
||||
// regular solid block
|
||||
(BlockCodex[tile].isSolid) ||
|
||||
// or platforms that are not on the "ignored list" (the list is updated on the update())
|
||||
(this is ActorHumanoid && BlockCodex[tile].isPlatform && !standingOnIgnoredPlatform())
|
||||
|
||||
/*
|
||||
// platforms, moving downward AND not "going down"
|
||||
(this is ActorHumanoid && BlockCodex[tile].isPlatform &&
|
||||
externalV.y + (controllerV?.y ?: 0.0) >= 0.0 &&
|
||||
!this.isDownDown && this.axisY <= 0f) ||
|
||||
// platforms, moving downward
|
||||
(this !is ActorHumanoid && BlockCodex[tile].isPlatform &&
|
||||
externalV.y + (controllerV?.y ?: 0.0) >= 0.0)
|
||||
*/
|
||||
// THIS IS NOT A CAUSE OF THE "OSCILLATING PLATFORM" BUG
|
||||
//(this is ActorHumanoid && BlockCodex[tile].isPlatform && !standingOnIgnoredPlatform())
|
||||
// platforms, moving downward AND not "going down"
|
||||
(this is ActorHumanoid && BlockCodex[tile].isPlatform &&
|
||||
externalV.y + (controllerV?.y ?: 0.0) >= 0.0 &&
|
||||
!this.isDownDown && this.axisY <= 0f) ||
|
||||
// platforms, moving downward
|
||||
(this !is ActorHumanoid && BlockCodex[tile].isPlatform &&
|
||||
externalV.y + (controllerV?.y ?: 0.0) >= 0.0)
|
||||
// TODO: as for the platform, only apply it when it's a feet tile
|
||||
|
||||
|
||||
@@ -1747,7 +1745,7 @@ open class ActorWithBody : Actor {
|
||||
}
|
||||
|
||||
|
||||
private fun forEachOccupyingTileNum(consumer: (ItemID?) -> Unit) {
|
||||
fun forEachOccupyingTileNum(consumer: (ItemID?) -> Unit) {
|
||||
if (world == null) return
|
||||
|
||||
|
||||
@@ -1761,7 +1759,7 @@ open class ActorWithBody : Actor {
|
||||
return tiles.forEach(consumer)
|
||||
}
|
||||
|
||||
private fun forEachOccupyingTile(consumer: (BlockProp?) -> Unit) {
|
||||
fun forEachOccupyingTile(consumer: (BlockProp?) -> Unit) {
|
||||
if (world == null) return
|
||||
|
||||
|
||||
@@ -1775,7 +1773,7 @@ open class ActorWithBody : Actor {
|
||||
return tileProps.forEach(consumer)
|
||||
}
|
||||
|
||||
private fun forEachOccupyingFluid(consumer: (GameWorld.FluidInfo?) -> Unit) {
|
||||
fun forEachOccupyingFluid(consumer: (GameWorld.FluidInfo?) -> Unit) {
|
||||
if (world == null) return
|
||||
|
||||
|
||||
@@ -1790,7 +1788,7 @@ open class ActorWithBody : Actor {
|
||||
return fluids.forEach(consumer)
|
||||
}
|
||||
|
||||
private fun forEachOccupyingTilePos(hitbox: Hitbox, consumer: (BlockAddress) -> Unit) {
|
||||
fun forEachOccupyingTilePos(hitbox: Hitbox, consumer: (BlockAddress) -> Unit) {
|
||||
if (world == null) return
|
||||
|
||||
|
||||
@@ -1812,7 +1810,7 @@ open class ActorWithBody : Actor {
|
||||
return tilePosList.forEach(consumer)
|
||||
}
|
||||
|
||||
private fun forEachFeetTileNum(consumer: (ItemID?) -> Unit) {
|
||||
fun forEachFeetTileNum(consumer: (ItemID?) -> Unit) {
|
||||
if (world == null) return
|
||||
|
||||
|
||||
@@ -1828,7 +1826,7 @@ open class ActorWithBody : Actor {
|
||||
return tiles.forEach(consumer)
|
||||
}
|
||||
|
||||
private fun forEachFeetTile(consumer: (BlockProp?) -> Unit) {
|
||||
fun forEachFeetTile(consumer: (BlockProp?) -> Unit) {
|
||||
if (world == null) return
|
||||
|
||||
|
||||
|
||||
@@ -7,6 +7,7 @@ import net.torvald.gdx.graphics.Cvec
|
||||
import net.torvald.spriteanimation.HasAssembledSprite
|
||||
import net.torvald.terrarum.*
|
||||
import net.torvald.terrarum.App.printdbg
|
||||
import net.torvald.terrarum.TerrarumAppConfiguration.TILE_SIZED
|
||||
import net.torvald.terrarum.gameactors.*
|
||||
import net.torvald.terrarum.gameactors.faction.Faction
|
||||
import net.torvald.terrarum.gameitems.GameItem
|
||||
@@ -197,7 +198,7 @@ open class ActorHumanoid : ActorWithBody, Controllable, Pocketed, Factionable, L
|
||||
|
||||
if (isNoClip) {
|
||||
//grounded = true
|
||||
platformsToIgnore = null
|
||||
platformToIgnore = null
|
||||
}
|
||||
|
||||
// reset control box of AI
|
||||
@@ -474,7 +475,6 @@ open class ActorHumanoid : ActorWithBody, Controllable, Pocketed, Factionable, L
|
||||
* @param absAxisVal (set AXIS_KEYBOARD if keyboard controlled)
|
||||
*/
|
||||
private fun walkVertical(up: Boolean, absAxisVal: Float) {
|
||||
if (up && walledTop || !up && walledBottom) return
|
||||
|
||||
|
||||
if (avAcceleration.isNaN()) {
|
||||
@@ -482,6 +482,7 @@ open class ActorHumanoid : ActorWithBody, Controllable, Pocketed, Factionable, L
|
||||
}
|
||||
|
||||
|
||||
// if (up && walledTop || !up && walledBottom) return
|
||||
readonly_totalY =
|
||||
if (absAxisVal == AXIS_KEYBOARD)
|
||||
avAcceleration * applyVelo(walkCounterY) * (if (up) -1f else 1f)
|
||||
@@ -501,9 +502,31 @@ open class ActorHumanoid : ActorWithBody, Controllable, Pocketed, Factionable, L
|
||||
isWalkingV = true
|
||||
|
||||
|
||||
// determine a platform to ignore
|
||||
world?.let { world ->
|
||||
var hasPlatformOnTheFeet = false
|
||||
forEachFeetTile { if (it?.isPlatform == true) hasPlatformOnTheFeet = true }
|
||||
|
||||
// TODO do something to the ActorWithBody.platformsToIgnore
|
||||
|
||||
if (hasPlatformOnTheFeet) {
|
||||
// equation copied verbatim from the ActorWthBody.forEachFeetTile
|
||||
val y = hitbox.endY.plus(1.0).div(TerrarumAppConfiguration.TILE_SIZE).floorInt()
|
||||
var wxStart = hIntTilewiseHitbox.startX.toInt()
|
||||
var wxEnd = wxStart
|
||||
// scan to the left
|
||||
while (BlockCodex[world.getTileFromTerrain(wxStart, y)].isPlatform) wxStart -= 1
|
||||
// scan to the right
|
||||
while (BlockCodex[world.getTileFromTerrain(wxEnd, y)].isPlatform) wxEnd += 1
|
||||
|
||||
platformToIgnore = Hitbox.fromTwoPoints(
|
||||
(wxStart+1) * TILE_SIZED,
|
||||
y * TILE_SIZED,
|
||||
wxEnd * TILE_SIZED,
|
||||
(y+1) * TILE_SIZED,
|
||||
true
|
||||
)
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
private fun applyAccel(x: Int): Double {
|
||||
@@ -528,7 +551,7 @@ open class ActorHumanoid : ActorWithBody, Controllable, Pocketed, Factionable, L
|
||||
private fun walkVStop() {
|
||||
walkCounterY = 0
|
||||
isWalkingV = false
|
||||
platformsToIgnore = null
|
||||
platformToIgnore = null
|
||||
}
|
||||
|
||||
private fun getJumpAcc(pwr: Double, timedJumpCharge: Double): Double {
|
||||
|
||||
Reference in New Issue
Block a user