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.

45 lines
719 B

3 years ago
function main() {
// Switch has two frames:
// 0: Off
// 1: On
3 years ago
let state = false;
let collide = false;
3 years ago
3 years ago
Message.Subscribe("power", (powered) => {
3 years ago
state = powered;
showState(state);
});
3 years ago
Events.OnCollide((e) => {
3 years ago
if (!e.Settled || !e.Actor.IsMobile()) {
return;
}
if (collide === false) {
Sound.Play("button-down.wav")
state = !state;
Message.Publish("switch:toggle", state);
Message.Publish("power", state);
showState(state);
collide = true;
}
});
3 years ago
Events.OnLeave((e) => {
3 years ago
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);
}
}