mirror of
https://github.com/curioustorvald/Terrarum.git
synced 2026-06-12 03:24:06 +09:00
fallable sim to properly work on multiple fallable "stacks"
This commit is contained in:
@@ -1,5 +1,6 @@
|
|||||||
package net.torvald.terrarum.modulebasegame.gameworld
|
package net.torvald.terrarum.modulebasegame.gameworld
|
||||||
|
|
||||||
|
import com.badlogic.gdx.Input
|
||||||
import com.badlogic.gdx.graphics.Color
|
import com.badlogic.gdx.graphics.Color
|
||||||
import net.torvald.aa.KDTree
|
import net.torvald.aa.KDTree
|
||||||
import net.torvald.terrarum.AppLoader
|
import net.torvald.terrarum.AppLoader
|
||||||
@@ -8,6 +9,7 @@ import net.torvald.terrarum.blockproperties.Block
|
|||||||
import net.torvald.terrarum.blockproperties.BlockCodex
|
import net.torvald.terrarum.blockproperties.BlockCodex
|
||||||
import net.torvald.terrarum.blockproperties.Fluid
|
import net.torvald.terrarum.blockproperties.Fluid
|
||||||
import net.torvald.terrarum.gameactors.ActorWBMovable
|
import net.torvald.terrarum.gameactors.ActorWBMovable
|
||||||
|
import net.torvald.terrarum.gamecontroller.KeyToggler
|
||||||
import net.torvald.terrarum.gameworld.FluidType
|
import net.torvald.terrarum.gameworld.FluidType
|
||||||
import net.torvald.terrarum.modulebasegame.gameactors.ActorHumanoid
|
import net.torvald.terrarum.modulebasegame.gameactors.ActorHumanoid
|
||||||
import net.torvald.terrarum.roundInt
|
import net.torvald.terrarum.roundInt
|
||||||
@@ -18,6 +20,8 @@ import net.torvald.terrarum.worlddrawer.CreateTileAtlas
|
|||||||
*/
|
*/
|
||||||
object WorldSimulator {
|
object WorldSimulator {
|
||||||
|
|
||||||
|
private val DEBUG_STEPPING_MODE = false // use period key
|
||||||
|
|
||||||
// FLUID-RELATED STUFFS //
|
// FLUID-RELATED STUFFS //
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -250,6 +254,8 @@ object WorldSimulator {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private val FALLABLE_MAX_FALL_SPEED = 2
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* displace fallable tiles. It is scanned bottom-left first. To achieve the sens ofreal
|
* displace fallable tiles. It is scanned bottom-left first. To achieve the sens ofreal
|
||||||
* falling, each tiles are displaced by ONLY ONE TILE below.
|
* falling, each tiles are displaced by ONLY ONE TILE below.
|
||||||
@@ -281,30 +287,48 @@ object WorldSimulator {
|
|||||||
// displace fallables (TODO implement blocks with fallable supports e.g. scaffolding)
|
// displace fallables (TODO implement blocks with fallable supports e.g. scaffolding)
|
||||||
// only displace SINGLE BOTTOMMOST block on single X-coord (this doesn't mean they must fall only one block)
|
// only displace SINGLE BOTTOMMOST block on single X-coord (this doesn't mean they must fall only one block)
|
||||||
// so that the "falling" should be visible to the end user
|
// so that the "falling" should be visible to the end user
|
||||||
for (x in updateXFrom..updateXTo) {
|
if (!DEBUG_STEPPING_MODE || DEBUG_STEPPING_MODE && KeyToggler.isOn (Input.Keys.PERIOD)) {
|
||||||
var fallDownCounter = 0
|
for (x in updateXFrom..updateXTo) {
|
||||||
for (y in updateYTo downTo updateYFrom) {
|
var fallDownCounter = 0
|
||||||
val currentTile = world.getTileFromTerrain(x, y)
|
var fallableStackProcessed = false
|
||||||
val prop = BlockCodex[currentTile]
|
// one "stack" is a contiguous fallable blocks, regardless of the actual block number
|
||||||
val isSolid = prop.isSolid
|
// when you are simulating the gradual falling, it is natural to process all the "stacks" at the same run,
|
||||||
val support = prop.maxSupport
|
// otherwise you'll get an artefact.
|
||||||
val isFallable = support != -1
|
for (y in updateYTo downTo updateYFrom) {
|
||||||
|
val currentTile = world.getTileFromTerrain(x, y)
|
||||||
|
val prop = BlockCodex[currentTile]
|
||||||
|
val isSolid = prop.isSolid
|
||||||
|
val support = prop.maxSupport
|
||||||
|
val isFallable = support != -1
|
||||||
|
|
||||||
if (fallDownCounter != 0 && isFallable) {
|
// mark the beginnig of the new "stack"
|
||||||
// replace blocks
|
if (fallableStackProcessed && !isFallable) {
|
||||||
world.setTileTerrain(x, y, Block.AIR)
|
fallableStackProcessed = false
|
||||||
world.setTileTerrain(x, y + fallDownCounter, currentTile)
|
} // do not chain with "else if"
|
||||||
|
|
||||||
break
|
// process the gradual falling of the selected "stack"
|
||||||
}
|
if (!fallableStackProcessed && fallDownCounter != 0 && isFallable) {
|
||||||
else if (isSolid) {
|
// replace blocks
|
||||||
fallDownCounter = 0
|
world.setTileTerrain(x, y, Block.AIR)
|
||||||
}
|
world.setTileTerrain(x, y + fallDownCounter, currentTile)
|
||||||
else if (!isSolid && !isFallable) {
|
|
||||||
fallDownCounter += 1
|
fallableStackProcessed = true
|
||||||
|
}
|
||||||
|
else if (isSolid) {
|
||||||
|
fallDownCounter = 0
|
||||||
|
}
|
||||||
|
else if (!isSolid && !isFallable && fallDownCounter < FALLABLE_MAX_FALL_SPEED) {
|
||||||
|
fallDownCounter += 1
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (DEBUG_STEPPING_MODE) {
|
||||||
|
KeyToggler.forceSet(Input.Keys.PERIOD, false)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user