0:01 / 0:30
Playback speed

One-way platform

Compare the same jump through the one-way plank and against a solid ceiling.

Interactive demo#Platformers

A surface you can jump through from below and land on from above.

The upper face catches the player on the way down. Switch the plank to solid and its underside stops the same jump as soon as the head touches it.

Code

src/demos/one_way_platform.goose
namespace one_way_platform_lesson;
import stage;
import std;
import math;

// A one-way platform catches falling feet on its upper face.
fn one_way_feet(time: f64, top: f64) -> f64 {
    let speed = 134.0;
    let gravity = 168.0;
    let feet = 91.0 - speed * time + gravity * time * time / 2.0;
    if time >= speed / gravity {
        return min(feet, top);
    }
    return feet;
}

export "one-way-platform" fn draw(time: f64, dt: f64, px: f64, py: f64, hover: bool) {
    artwork("valley");
    let t = time % 2.5;
    let top = 55.0;
    var y = one_way_feet(t, top);
    if !toggle("on") {
        let underside = top + 7;
        let contact = (134.0 - sqrt(134.0 * 134.0 - 336.0 * (91.0 - underside - 24.0))) / 168.0;
        if t >= contact {
            y = underside + 24 + 84 * (t - contact) * (t - contact);
        }
    }
    ledge(0, 91, 160, 9);
    ledge(48, top, 65, 7);
    let pose = if y >= 91 || (t >= 134.0 / 168.0 && y == top) { STAND }
               else if !toggle("on") && y >= top + 7 + 24 && t > 0.15 { DESCEND }
               else { air_pose(134 - 168 * t) };
    actor(80, min(91.0, y), pose, 2, "base", "runner");
}

Stage drawing helpers · All demos on GitHub

Comments

No comments yet.