0:01 / 0:30
Playback speed

Moving platform

Watch the feet against the left edge of the platform. What happens when the rider stops inheriting its movement?

Interactive demo#Platformers

A moving surface that can carry a standing player along with it.

With carrying enabled, the rider receives the platform’s horizontal displacement and keeps the same spot on deck. Without it, the platform slides out from under the rider.

Code

src/demos/moving_platform.goose
namespace moving_platform_lesson;
import stage;
import std;
import math;

// The platform completes a smooth out-and-back trip in four seconds.
fn platform_offset(time: f64) -> f64 {
    40.0 * (1.0 - cos(time * 1.5707963267948966))
}

export "moving-platform" fn draw(time: f64, dt: f64, px: f64, py: f64, hover: bool) {
    artwork("cave");
    let t = time % 4.0;
    let dx = platform_offset(t);
    line(24, 78, 136, 78, "#3d494a");
    line(24, 79, 136, 79, "#ba9770");
    draw_prop("lift", 18 + dx, 67, 40, 12);
    let carry = toggle("on");
    let lost_at = acos(0.5) / (PI / 2.0);
    let fall = if carry { 0.0 } else { max(0.0, t - lost_at) };
    actor(38 + (if carry { dx } else { 0.0 }), 67 + 85 * fall * fall, if fall > 0 { DESCEND } else { STAND }, 2, "base", "runner");
}

Stage drawing helpers · All demos on GitHub

Comments

No comments yet.