Move left or right to walk through the cabin.

0:01 / 0:30
Playback speed

Roof cutaway

Step just inside the cabin, then step back out before the roof finishes fading. Watch the tiles as the fade reverses.

Interactive demo#TopDownDarkwood

Fading the roof as a character enters a room reveals the interior from above.

The roof tiles share one layer above the courier and furniture. Crossing into the cabin fades that layer to transparent over about half a second. Stepping outside brings it back. Cross again mid-fade and the roof reverses from its current opacity.

Code

src/demos/roof_cutaway.goose
namespace roof_cutaway_lesson;
import stage;
import std;
import math;

var ranger = CourierTurn {};

const fade_seconds = 0.55;
const left = 52.0;
const right = 126.0;
var roof_alpha = 1.0;
var last_time = -1.0;
var last_target = 1.0;
export "roof-cutaway" fn draw(time: f64, dt: f64, px: f64, py: f64, hover: bool) {
    let phase = (time / 4.0) % 2.0;
    let x = if hover { px } else { 20 + 136 * pingpong(phase) };
    let cut = toggle("cut");
    let inside = x >= left && x <= right;
    let target = if cut && inside { 0.0 } else { 1.0 };
    if last_time < 0 || (dt == 0 && time != last_time) {
        // When scrubbing the automatic walk, recover time since the last crossing.
        roof_alpha = target;
        if cut && !hover {
            let entry = if phase < 1 { left } else { right };
            let exit_edge = if phase < 1 { right } else { left };
            let distance = if inside { abs(x - entry) } else { abs(x - exit_edge) };
            let progress = clamp(distance / (34 * fade_seconds), 0.0, 1.0);
            roof_alpha = mix_value(1 - target, target, progress);
        }
    } else if dt == 0 && target != last_target {
        roof_alpha = target;
    } else {
        let step = dt / fade_seconds;
        roof_alpha += clamp(target - roof_alpha, -step, step);
    }
    last_target = target;
    last_time = time;
    artwork("clearing");
    artwork("cabin", left, 23, right - left, 52);
    var travel = if phase < 1 { 0.0 } else { PI };
    if hover { travel = if x < ranger.x { PI } else if x > ranger.x { 0.0 } else { ranger.last_aim }; }
    steer_courier(ranger, time, x, 55, travel, travel, travel);
    draw_steering_courier(ranger);
    save();
    opacity(roof_alpha);
    artwork("roof", left, 23, right - left, 52);
    restore();
}

Stage drawing helpers · All demos on GitHub

Comments

No comments yet.