doodle/dev-assets/doodads/doors/electric-door.js
Noah Petherbridge 1a8a5eb94b Polish and bugfixes
- Fix a memory sharing bug in the Giant Screenshot feature.
- Main Menu to eagerload chunks in the background to make scrolling less
  jittery. No time for a loadscreen!
- Extra script debugging: names/IDs of doodads are shown when they send
  messages to one another.
- Level Properties: you can edit the Bounded max width/height values for
  the level.

Doodad changes:

- Buttons: fix a timing bug and keep better track of who is stepping on it,
  only popping up when all colliders have left. The effect: they pop up
  immediately (not after 200ms) and are more reliable.
- Keys: zero-qty keys will no longer put themselves into the inventory of
  characters who already have one except for the player character. So
  the Thief will not steal them if she already has the key.

Added to the JavaScript API:

* time.Hour, time.Minute, time.Second, time.Millisecond, time.Microsecond
2021-10-09 20:45:38 -07:00

65 lines
1.4 KiB
JavaScript

var animating = false;
var opened = false;
var powerState = false;
// Function to handle the door opening or closing.
function setPoweredState(powered) {
powerState = 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) {
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;
}
}
});
}