mirror of
https://github.com/curioustorvald/Terrarum.git
synced 2026-03-07 20:31:51 +09:00
loading process will try to unstuck the player if the player appears to stuck in the terrain
This commit is contained in:
@@ -459,6 +459,40 @@ open class ActorWithBody : Actor {
|
||||
|
||||
private val bounceDampenVelThreshold = 0.5
|
||||
|
||||
/**
|
||||
* Used on final loading phase, move the player to the opposite direction of the gravitation, until the player's
|
||||
* not colliding
|
||||
*/
|
||||
open fun tryUnstuck() {
|
||||
val newHitbox = hitbox.clone()
|
||||
val translation = gravitation.setMagnitude(-1.0)
|
||||
|
||||
while (isColliding(newHitbox)) {
|
||||
newHitbox.translate(translation)
|
||||
}
|
||||
|
||||
hitbox.reassign(newHitbox)
|
||||
|
||||
hIntTilewiseHitbox.setFromTwoPoints(
|
||||
hitbox.startX.plus(PHYS_EPSILON_DIST).div(TILE_SIZE).floor() + 0.5,
|
||||
hitbox.startY.plus(PHYS_EPSILON_DIST).div(TILE_SIZE).floor() + 0.5,
|
||||
hitbox.endX.plus(PHYS_EPSILON_DIST).div(TILE_SIZE).floor() + 0.5,
|
||||
hitbox.endY.plus(PHYS_EPSILON_DIST).div(TILE_SIZE).floor() + 0.5
|
||||
)
|
||||
intTilewiseHitbox.setFromTwoPoints(
|
||||
hitbox.startX.div(TILE_SIZE).floor(),
|
||||
hitbox.startY.div(TILE_SIZE).floor(),
|
||||
hitbox.endX.minus(PHYS_EPSILON_DIST).div(TILE_SIZE).floor(),
|
||||
hitbox.endY.minus(PHYS_EPSILON_DIST).div(TILE_SIZE).floor()
|
||||
)
|
||||
|
||||
centrePosVector.set(hitbox.centeredX, hitbox.centeredY)
|
||||
centrePosPoint.set(hitbox.centeredX, hitbox.centeredY)
|
||||
feetPosVector.set(hitbox.centeredX, hitbox.endY)
|
||||
feetPosPoint.set(hitbox.centeredX, hitbox.endY)
|
||||
feetPosTile.set(hIntTilewiseHitbox.centeredX.floorInt(), hIntTilewiseHitbox.endY.floorInt())
|
||||
}
|
||||
|
||||
override fun update(delta: Float) {
|
||||
|
||||
// re-scale hitbox
|
||||
|
||||
@@ -372,6 +372,11 @@ open class TerrarumIngame(batch: FlippingSpriteBatch) : IngameInstance(batch) {
|
||||
}
|
||||
|
||||
|
||||
// try to unstuck the repositioned player
|
||||
codices.player.tryUnstuck()
|
||||
|
||||
|
||||
|
||||
// by doing this, whatever the "possession" the player had will be broken by the game load
|
||||
actorNowPlaying = codices.player
|
||||
actorGamer = codices.player
|
||||
|
||||
@@ -137,8 +137,7 @@ object WritePlayer {
|
||||
object ReadPlayer {
|
||||
|
||||
operator fun invoke(disk: SimpleFileSystem, dataStream: Reader): IngamePlayer =
|
||||
ReadActor(disk, dataStream) as IngamePlayer
|
||||
|
||||
ReadActor(disk, dataStream) as IngamePlayer
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -152,9 +151,11 @@ object ReadPlayer {
|
||||
object ReadActor {
|
||||
|
||||
operator fun invoke(disk: SimpleFileSystem, dataStream: Reader): Actor =
|
||||
fillInDetails(disk, Common.jsoner.fromJson(null, dataStream))
|
||||
Common.jsoner.fromJson<Actor?>(null, dataStream).also {
|
||||
fillInDetails(disk, it)
|
||||
}
|
||||
|
||||
private fun fillInDetails(disk: SimpleFileSystem, actor: Actor): Actor {
|
||||
private fun fillInDetails(disk: SimpleFileSystem, actor: Actor) {
|
||||
actor.reload()
|
||||
|
||||
|
||||
@@ -197,9 +198,6 @@ object ReadActor {
|
||||
|
||||
//actor.reassembleSprite(actor.sprite, actor.spriteGlow, null)
|
||||
}
|
||||
|
||||
|
||||
return actor
|
||||
}
|
||||
|
||||
}
|
||||
@@ -99,16 +99,16 @@ object WriteWorld {
|
||||
object ReadWorld {
|
||||
|
||||
operator fun invoke(worldDataStream: Reader, origin: File?): GameWorld =
|
||||
fillInDetails(Common.jsoner.fromJson(GameWorld::class.java, worldDataStream), origin)
|
||||
Common.jsoner.fromJson(GameWorld::class.java, worldDataStream).also {
|
||||
fillInDetails(origin, it)
|
||||
}
|
||||
|
||||
private fun fillInDetails(world: GameWorld, origin: File?): GameWorld {
|
||||
private fun fillInDetails(origin: File?, world: GameWorld) {
|
||||
world.tileNumberToNameMap.forEach { l, s ->
|
||||
world.tileNameToNumberMap[s] = l.toInt()
|
||||
}
|
||||
|
||||
ItemCodex.loadFromSave(origin, world.dynamicToStaticTable, world.dynamicItemInventory)
|
||||
|
||||
return world
|
||||
}
|
||||
|
||||
private val cw = LandUtil.CHUNK_W
|
||||
|
||||
@@ -15,16 +15,16 @@ import java.io.Reader
|
||||
object ReadSimpleWorld {
|
||||
|
||||
operator fun invoke(worldDataStream: Reader, origin: File?): GameWorld =
|
||||
fillInDetails(Common.jsoner.fromJson(SimpleGameWorld::class.java, worldDataStream), origin)
|
||||
Common.jsoner.fromJson(SimpleGameWorld::class.java, worldDataStream).also {
|
||||
fillInDetails(origin, it)
|
||||
}
|
||||
|
||||
private fun fillInDetails(world: GameWorld, origin: File?): GameWorld {
|
||||
private fun fillInDetails(origin: File?, world: GameWorld) {
|
||||
world.tileNumberToNameMap.forEach { l, s ->
|
||||
world.tileNameToNumberMap[s] = l.toInt()
|
||||
}
|
||||
|
||||
ItemCodex.loadFromSave(origin, world.dynamicToStaticTable, world.dynamicItemInventory)
|
||||
|
||||
return world
|
||||
}
|
||||
|
||||
fun readWorldAndSetNewWorld(ingame: IngameInstance, worldDataStream: Reader, origin: File?): GameWorld {
|
||||
|
||||
Reference in New Issue
Block a user