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.
 
 
 

66 lines
1.5 KiB

var animating = false;
var opened = false;
var powerState = false;
// Function to handle the door opening or closing.
function setPoweredState(powered) {
powerState = powered;
console.log("setPoweredState: %+v", powered)
if (powered) {
if (animating || opened) {
return;
}
animating = true;
Sound.Play("electric-door.wav")
Self.PlayAnimation("open", function() {
opened = true;
animating = false;
});
} else {
animating = true;
Sound.Play("electric-door.wav")
Self.PlayAnimation("close", function() {
opened = false;
animating = false;
})
}
}
function main() {
Self.AddAnimation("open", 100, [0, 1, 2, 3]);
Self.AddAnimation("close", 100, [3, 2, 1, 0]);
Self.SetHitbox(0, 0, 34, 76);
// A linked Switch that activates the door will send the Toggle signal
// immediately before the Power signal. The door can just invert its
// state on this signal, and ignore the very next Power signal. Ordinary
// power sources like Buttons will work as normal, as they emit only a power
// signal.
var ignoreNextPower = false;
Message.Subscribe("switch:toggle", function(powered) {
console.log("A switch powered %+v, setPoweredState(%+v) to opposite", powered, powerState);
ignoreNextPower = true;
setPoweredState(!powerState);
})
Message.Subscribe("power", function(powered) {
if (ignoreNextPower) {
ignoreNextPower = false;
return;
}
setPoweredState(powered);
});
Events.OnCollide(function(e) {
if (e.InHitbox) {
if (!opened) {
return false;
}
}
});
}