Move your pointer to walk the monkey in and out.

0:01 / 0:30
Playback speed

Trigger

Walk into the dashed zone and out the far side. At which boundary does the lamp switch off?

Interactive demo#Collision

A zone you can walk through that notices when you do.

Unlike a wall, a trigger doesn’t block anything. It only reports that something entered or left. Doors that open, checkpoints, pickups and cutscene starts are all triggers.

Code

src/demos/trigger.goose
namespace trigger_lesson;
import stage;
import std;
import math;

export "trigger" fn draw(time: f64, dt: f64, px: f64, py: f64, hover: bool) {
    artwork("hall", 0, 0, W, 125);
    let x = if hover { px } else { 80 + sin(time * 0.9) * 68 };
    let inside = x > 58 && x < 104;
    ground();
    opacity(if inside { 0.3 } else { 0.1 });
    rect(58, 34, 46, GY - 34, MOSS);
    opacity(1);
    dash_box(58.5, 34.5, 45, GY - 35, MOSS);
    rect(134, 40, 2, GY - 40, STONE2);
    rect(130, 30, 10, 10, if inside { SUN } else { LINE });
    box(130, 30, 10, 10, INK);
    if inside {
        ring(135, 35, 10 + sin(time * 8), SUN, 2, 2);
    }
    actor(x, GY, walk(time), 2, "base", "knight", !hover && cos(time * 0.9) < 0);
}

Stage drawing helpers · All demos on GitHub

Comments

No comments yet.