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.
35 lines
674 B
35 lines
674 B
function main() {
|
|
let pressed = false;
|
|
|
|
// When a sticky button receives power, it pops back up.
|
|
Message.Subscribe("power", (powered) => {
|
|
if (powered && pressed) {
|
|
Self.ShowLayer(0);
|
|
pressed = false;
|
|
Sound.Play("button-up.wav")
|
|
Message.Publish("power", false);
|
|
Message.Publish("sticky:down", false);
|
|
}
|
|
})
|
|
|
|
Events.OnCollide((e) => {
|
|
if (!e.Settled) {
|
|
return;
|
|
}
|
|
|
|
if (pressed) {
|
|
return;
|
|
}
|
|
|
|
// Verify they've touched the button.
|
|
if (e.Overlap.Y + e.Overlap.H < 24) {
|
|
return;
|
|
}
|
|
|
|
Sound.Play("button-down.wav")
|
|
Self.ShowLayer(1);
|
|
pressed = true;
|
|
Message.Publish("power", true);
|
|
Message.Publish("sticky:down", true);
|
|
});
|
|
}
|
|
|