doodle/dev-assets/doodads/switches/switch.js
Noah Petherbridge 3892087932 Doodads: Use Key and Working Warp Doors
* The "Use Key" (Q or Spacebar) now activates the Warp Door instead of a
  collision event doing so.
* Warp Doors are now functional: the player opens a door, disappears,
  the door closes; player is teleported to the linked door which opens,
  appears the player and closes.
* If the player exits thru a Blue or Orange door which is disabled
  (dotted outline), the door still opens and drops the player off but
  returns to a Disabled state, acting as a one-way door.
* Clean up several debug log lines from Doodle and doodad scripts.
2021-01-03 15:19:21 -08:00

43 lines
666 B
JavaScript

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) {
return;
}
if (collide === false) {
Sound.Play("button-down.wav")
state = !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);
}
}