Built-in doodads and levels of Sketchy Maze.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

61 lines
1.1 KiB

3 years ago
function main() {
3 years ago
let timer = 0;
let pressed = false;
3 years ago
// Has a linked Sticky Button been pressed permanently down?
3 years ago
let stickyDown = false;
Message.Subscribe("sticky:down", (down) => {
3 years ago
stickyDown = down;
Self.ShowLayer(stickyDown ? 1 : 0);
});
3 years ago
// Track who all is colliding with us.
let colliders = {};
Events.OnCollide((e) => {
3 years ago
if (!e.Settled) {
return;
}
3 years ago
if (colliders[e.Actor.ID()] == undefined) {
colliders[e.Actor.ID()] = true;
}
3 years ago
// If a linked Sticky Button is pressed, button stays down too and
// doesn't interact.
if (stickyDown) {
return;
}
// Verify they've touched the button.
if (e.Overlap.Y + e.Overlap.H < 24) {
return;
}
if (!pressed && !stickyDown) {
Sound.Play("button-down.wav")
Message.Publish("power", true);
pressed = true;
}
if (timer > 0) {
clearTimeout(timer);
}
Self.ShowLayer(1);
3 years ago
});
Events.OnLeave((e) => {
delete colliders[e.Actor.ID()];
if (Object.keys(colliders).length === 0 && !stickyDown) {
3 years ago
Sound.Play("button-up.wav")
Self.ShowLayer(0);
Message.Publish("power", false);
timer = 0;
pressed = false;
3 years ago
}
3 years ago
});
}