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.

46 lines
780 B

3 years ago
function main() {
// Switch has two frames:
// 0: Off
// 1: On
var state = false;
var collide = false;
Message.Subscribe("power", function (powered) {
state = powered;
showState(state);
});
Events.OnCollide(function (e) {
if (!e.Settled || !e.Actor.IsMobile()) {
return;
}
if (collide === false) {
Sound.Play("button-down.wav")
state = !state;
var nonce = Math.random() * 2147483647;
Message.Publish("switch:toggle", state);
Message.Publish("power", state);
showState(state);
collide = true;
}
});
Events.OnLeave(function (e) {
collide = false;
});
}
// showState shows the on/off frame based on the boolean powered state.
function showState(state) {
if (state) {
Self.ShowLayer(1);
} else {
Self.ShowLayer(0);
}
}