Wall slide

Compare the time it takes to reach the ground with the slide enabled and disabled.
Interactive demo#Platformers
A slower descent while the player presses against a wall.
Both runs start beside the same wall. With sliding enabled, falling speed stops increasing at 24 pixels per second. That buys time to line up the next wall jump.
Code
namespace wall_slide_lesson;
import stage;
import std;
import math;
// Accelerate under gravity until the slide reaches its speed limit.
fn slide_distance(time: f64, gravity: f64, cap: f64, limited: bool) -> f64 {
let at_cap = cap / gravity;
if limited && time > at_cap {
return gravity * at_cap * at_cap / 2.0 + cap * (time - at_cap);
}
return gravity * time * time / 2.0;
}
export "wall-slide" fn draw(time: f64, dt: f64, px: f64, py: f64, hover: bool) {
artwork("cave");
let t = time % 3.3;
let fallen = slide_distance(t, 126.0, 24.0, toggle("on"));
ledge(98, 6, 31, 94);
ledge(0, 90, 160, 10);
actor(90.5, min(90.0, 26.0 + fallen), if fallen >= 64 { STAND } else { BRACE }, 2, "base", "runner");
}

Comments
No comments yet.