0:01 / 0:30
Playback speed

Jump buffering

Watch the button and the feet separately. Which happens first, the press or the takeoff?

Interactive demo#PlatformersCeleste

Remembering a jump pressed just before landing and firing it at touchdown.

The button flashes 110 milliseconds before the feet reach the floor. With a 150-millisecond buffer, the landing consumes that stored press and starts the next jump. With the buffer off, that early press expires in the air.

Code

src/demos/jump_buffer.goose
namespace jump_buffer_lesson;
import stage;
import std;
import math;

// An early press remains available until the buffer expires.
fn buffer_accepts(pressed: f64, landing: f64, window: f64) -> bool {
    let age = landing - pressed;
    return age >= 0.0 && age <= window;
}

export "jump-buffer" fn draw(time: f64, dt: f64, px: f64, py: f64, hover: bool) {
    artwork("valley");
    let t = time % 2.8;
    let landing = 1.0;
    let pressed = 0.89;
    let buffered = toggle("on") && buffer_accepts(pressed, landing, 0.15);
    var y = 78.0;
    if t < landing {
        y = 22 + 56 * t * t;
    }
    else if buffered {
        y -= max(0.0, rise(t - landing, 105, 170));
    }
    ledge(0, 78, 160, 22);
    signal_jump(t >= pressed && t < pressed + 0.1);
    let pose = if t < landing { DESCEND } else if y == 78 { walk(t) } else { air_pose(105 - 170 * (t - landing)) };
    actor(40 + 28 * t, y, pose, 2, "base", "runner");
}

Stage drawing helpers · All demos on GitHub

Comments

No comments yet.