moving platform wip

This commit is contained in:
minjaesong
2026-02-08 02:06:29 +09:00
parent 4997353f83
commit ff9f02322b
6 changed files with 277 additions and 14 deletions

View File

@@ -1480,8 +1480,16 @@ open class TerrarumIngame(batch: FlippingSpriteBatch) : IngameInstance(batch) {
actorNowPlaying?.update(delta)*/
}
else {
// Pass 1: update moving platforms first so riders get displaced before their own update
actorContainerActive.forEach {
if (it != actorNowPlaying) {
if (it is ActorMovingPlatform && it != actorNowPlaying) {
it.update(delta)
}
}
// Pass 2: update all non-platform actors with existing callbacks
actorContainerActive.forEach {
if (it !is ActorMovingPlatform && it != actorNowPlaying) {
it.update(delta)
if (it is Pocketed) {
@@ -1515,6 +1523,8 @@ open class TerrarumIngame(batch: FlippingSpriteBatch) : IngameInstance(batch) {
}
}
}
// Pass 3: update player
actorNowPlaying?.update(delta)
//AmmoMeterProxy(player, uiVitalItem.UI as UIVitalMetre)
}

View File

@@ -0,0 +1,32 @@
package net.torvald.terrarum.modulebasegame.console
import net.torvald.terrarum.INGAME
import net.torvald.terrarum.Terrarum
import net.torvald.terrarum.console.ConsoleAlias
import net.torvald.terrarum.console.ConsoleCommand
import net.torvald.terrarum.console.Echo
import net.torvald.terrarum.modulebasegame.gameactors.ActorTestPlatform
/**
* Created by minjaesong on 2026-02-08.
*/
@ConsoleAlias("spawnplatform")
internal object SpawnMovingPlatform : ConsoleCommand {
override fun execute(args: Array<String>) {
val mouseX = Terrarum.mouseX
val mouseY = Terrarum.mouseY
val platform = ActorTestPlatform()
// setPosition places bottom-centre at the given point; offset Y so the platform is centred at cursor
platform.setPosition(mouseX, mouseY + platform.hitbox.height / 2.0)
INGAME.queueActorAddition(platform)
Echo("Spawned ActorTestPlatform at (${"%.1f".format(mouseX)}, ${"%.1f".format(mouseY)})")
}
override fun printUsage() {
Echo("usage: spawnplatform")
Echo("Spawns a test moving platform centred at the mouse cursor.")
}
}

View File

@@ -1,9 +1,77 @@
package net.torvald.terrarum.modulebasegame.gameactors
import net.torvald.terrarum.gameactors.ActorMovingPlatform
import kotlin.math.cos
import kotlin.math.sin
/**
* Test platform that randomly selects a movement pattern on spawn.
*
* Patterns:
* - 0: Horizontal pingpong (sine-eased)
* - 1: Vertical pingpong (sine-eased)
* - 2: Clockwise circular (constant speed)
* - 3: Counter-clockwise circular (constant speed)
*
* Created by minjaesong on 2022-03-02.
*/
class ActorTestPlatform : ActorMovingPlatform() {
}
class ActorTestPlatform : ActorMovingPlatform(8) {
/** Movement pattern index (0-3). */
private val pattern: Int = (0..3).random()
/** Speed in pixels per tick (2.0 to 4.0). */
private val speed: Double = 2.0 + Math.random() * 2.0
/** Current phase angle in radians. */
private var phase: Double = 0.0
/**
* Phase step per tick.
*
* For pingpong: peak speed = amplitude * phaseStep = speed
* period = 128 ticks (~2s), so phaseStep = 2*PI/128
* amplitude = speed / phaseStep
*
* For circular: speed = radius * phaseStep
* using same phaseStep, radius = speed / phaseStep
*/
@Transient private val PERIOD_TICKS = 128.0
@Transient private val phaseStep: Double = 2.0 * Math.PI / PERIOD_TICKS
/** Amplitude for pingpong patterns, radius for circular patterns. */
@Transient private val amplitude: Double = speed / phaseStep
override fun updateImpl(delta: Float) {
val oldPhase = phase
phase += phaseStep
when (pattern) {
0 -> {
// Horizontal pingpong: position = A * sin(phase)
// Velocity = finite difference to prevent float drift
val dx = amplitude * (sin(phase) - sin(oldPhase))
platformVelocity.set(dx, 0.0)
}
1 -> {
// Vertical pingpong: position = A * sin(phase)
val dy = amplitude * (sin(phase) - sin(oldPhase))
platformVelocity.set(0.0, dy)
}
2 -> {
// Clockwise circular: position on circle (cos, sin)
val dx = amplitude * (cos(phase) - cos(oldPhase))
val dy = amplitude * (sin(phase) - sin(oldPhase))
platformVelocity.set(dx, dy)
}
3 -> {
// Counter-clockwise circular: negate Y component
val dx = amplitude * (cos(phase) - cos(oldPhase))
val dy = -(amplitude * (sin(phase) - sin(oldPhase)))
platformVelocity.set(dx, dy)
}
}
super.updateImpl(delta)
}
}