mirror of
https://github.com/curioustorvald/Terrarum.git
synced 2026-03-07 12:21:52 +09:00
platform surface friction
This commit is contained in:
@@ -7,6 +7,8 @@ import com.badlogic.gdx.graphics.g2d.SpriteBatch
|
|||||||
import com.badlogic.gdx.graphics.g2d.TextureRegion
|
import com.badlogic.gdx.graphics.g2d.TextureRegion
|
||||||
import net.torvald.terrarum.INGAME
|
import net.torvald.terrarum.INGAME
|
||||||
import net.torvald.terrarum.TerrarumAppConfiguration.TILE_SIZE
|
import net.torvald.terrarum.TerrarumAppConfiguration.TILE_SIZE
|
||||||
|
import net.torvald.terrarum.blockproperties.Block
|
||||||
|
import net.torvald.terrarum.gameitems.ItemID
|
||||||
import net.torvald.terrarum.modulebasegame.gameactors.ActorHumanoid
|
import net.torvald.terrarum.modulebasegame.gameactors.ActorHumanoid
|
||||||
import org.dyn4j.geometry.Vector2
|
import org.dyn4j.geometry.Vector2
|
||||||
|
|
||||||
@@ -21,7 +23,7 @@ import org.dyn4j.geometry.Vector2
|
|||||||
*/
|
*/
|
||||||
open class ActorMovingPlatform() : ActorWithBody() {
|
open class ActorMovingPlatform() : ActorWithBody() {
|
||||||
|
|
||||||
protected var tilewiseWidth = 3
|
protected var tilewiseWidth = 3 // default fallback value when no args were given
|
||||||
|
|
||||||
constructor(newTilewiseWidth: Int) : this() {
|
constructor(newTilewiseWidth: Int) : this() {
|
||||||
this.tilewiseWidth = newTilewiseWidth
|
this.tilewiseWidth = newTilewiseWidth
|
||||||
@@ -50,6 +52,9 @@ open class ActorMovingPlatform() : ActorWithBody() {
|
|||||||
/** Minimum combined Y velocity to count as "jumping up" (prevents mount while jumping). */
|
/** Minimum combined Y velocity to count as "jumping up" (prevents mount while jumping). */
|
||||||
@Transient private val JUMP_THRESHOLD_Y = -0.5
|
@Transient private val JUMP_THRESHOLD_Y = -0.5
|
||||||
|
|
||||||
|
/** Block whose friction this platform impersonates. Riders use this for feet friction. */
|
||||||
|
var surfaceBlock: ItemID = Block.STONE
|
||||||
|
|
||||||
@Transient private var platformTexture: Texture? = null
|
@Transient private var platformTexture: Texture? = null
|
||||||
@Transient private var platformTextureRegion: TextureRegion? = null
|
@Transient private var platformTextureRegion: TextureRegion? = null
|
||||||
|
|
||||||
|
|||||||
@@ -294,6 +294,7 @@ open class ActorWithBody : Actor {
|
|||||||
private inline val grounded: Boolean
|
private inline val grounded: Boolean
|
||||||
get() = if (world == null) true else {
|
get() = if (world == null) true else {
|
||||||
isNoClip ||
|
isNoClip ||
|
||||||
|
platformsRiding.isNotEmpty() ||
|
||||||
(world!!.gravitation.y > 0 && isWalled(hitbox, COLLIDING_BOTTOM) ||
|
(world!!.gravitation.y > 0 && isWalled(hitbox, COLLIDING_BOTTOM) ||
|
||||||
world!!.gravitation.y < 0 && isWalled(hitbox, COLLIDING_TOP))
|
world!!.gravitation.y < 0 && isWalled(hitbox, COLLIDING_TOP))
|
||||||
}
|
}
|
||||||
@@ -1692,6 +1693,14 @@ open class ActorWithBody : Actor {
|
|||||||
// after all, feet friction is what it matters
|
// after all, feet friction is what it matters
|
||||||
internal inline val feetFriction: Double
|
internal inline val feetFriction: Double
|
||||||
get() {
|
get() {
|
||||||
|
// When riding a platform, use the platform's surface block friction
|
||||||
|
if (platformsRiding.isNotEmpty()) {
|
||||||
|
val platform = INGAME.getActorByID(platformsRiding[0])
|
||||||
|
if (platform is ActorMovingPlatform) {
|
||||||
|
return getTileFriction(platform.surfaceBlock)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
var friction = 0.0
|
var friction = 0.0
|
||||||
forEachFeetTileNum {
|
forEachFeetTileNum {
|
||||||
// get max friction
|
// get max friction
|
||||||
|
|||||||
Reference in New Issue
Block a user