doodle/dev-assets/doodads/doors/locked-door.js
Noah Petherbridge 99eab19c5b Pub/Sub Messages Between Linked Actors (JavaScript)
* Implement the pub/sub message passing system that lets the JavaScript
  VM of one actor (say, a Button) send messages to other linked actors
  in the level (say, an Electric Door)
* Buttons now emit a "power(true)" message while pressed and
  "power(false)" when released. Sticky Buttons do not release and so do
  not send the power(false) message.
* Electric Doors listen for the "power" event and open or close
  themselves based on the boolean value received.
* If a Sticky Button receives power and is currently pressed down, it
  will pop back up (reset to "off" position) and notify its linked
  actors that they have lost power too. So if a Sticky Button held an
  Electric Door open, and another Button powers the Sticky Button, it
  would pop back up and also close the Electric Door.
2019-06-23 17:34:11 -07:00

39 lines
838 B
JavaScript

function main() {
Self.AddAnimation("open", 0, [1]);
var unlocked = false;
// Self.Canvas.SetBackground(RGBA(0, 255, 255, 100));
// Map our door names to key names.
var KeyMap = {
"Blue Door": "Blue Key",
"Red Door": "Red Key",
"Green Door": "Green Key",
"Yellow Door": "Yellow Key"
}
// log.Warn("%s loaded!", Self.Doodad.Title);
// console.log("%s Setting hitbox", Self.Doodad.Title);
Self.SetHitbox(16, 0, 32, 64);
Events.OnCollide(function(e) {
if (unlocked) {
return;
}
if (e.InHitbox) {
var data = e.Actor.GetData("key:" + KeyMap[Self.Doodad.Title]);
if (data === "") {
// Door is locked.
return false;
}
unlocked = true;
Self.PlayAnimation("open", null);
}
});
// Events.OnLeave(function(e) {
// console.log("%s has stopped touching %s", e, Self.Doodad.Title)
// })
}