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.

56 lines
1.1 KiB

3 years ago
// State Block Control Button
// Button is "OFF" by default.
3 years ago
let state = false;
3 years ago
function main() {
Self.SetHitbox(0, 0, 42, 42);
// When the button is activated, don't keep toggling state until we're not
// being touched again.
3 years ago
let colliding = false;
3 years ago
// If we receive a state change event from a DIFFERENT on/off button, update
// ourself to match the state received.
3 years ago
Message.Subscribe("broadcast:state-change", (value) => {
3 years ago
state = value;
showSprite();
});
3 years ago
Events.OnCollide((e) => {
3 years ago
if (colliding) {
return false;
}
// Only trigger for mobile characters.
if (e.Actor.IsMobile()) {
// Only activate if touched from the bottom or sides.
if (e.Overlap.Y === 0) {
return false;
}
colliding = true;
state = !state;
Message.Broadcast("broadcast:state-change", state);
showSprite();
}
// Always a solid button.
return false;
});
3 years ago
Events.OnLeave((e) => {
3 years ago
colliding = false;
})
}
// Update the active layer based on the current button state.
function showSprite() {
if (state) {
Self.ShowLayer(1);
} else {
Self.ShowLayer(0);
}
}