Noah Petherbridge
99eab19c5b
* 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.
48 lines
913 B
JavaScript
48 lines
913 B
JavaScript
function main() {
|
|
console.log("%s initialized!", Self.Doodad.Title);
|
|
|
|
Self.AddAnimation("open", 100, [0, 1, 2, 3]);
|
|
Self.AddAnimation("close", 100, [3, 2, 1, 0]);
|
|
var animating = false;
|
|
var opened = false;
|
|
|
|
Self.SetHitbox(16, 0, 32, 64);
|
|
|
|
Message.Subscribe("power", function(powered) {
|
|
console.log("%s got power=%+v", Self.Doodad.Title, powered);
|
|
|
|
if (powered) {
|
|
if (animating || opened) {
|
|
return;
|
|
}
|
|
|
|
animating = true;
|
|
Self.PlayAnimation("open", function() {
|
|
opened = true;
|
|
animating = false;
|
|
});
|
|
} else {
|
|
animating = true;
|
|
Self.PlayAnimation("close", function() {
|
|
opened = false;
|
|
animating = false;
|
|
})
|
|
}
|
|
});
|
|
|
|
Events.OnCollide(function(e) {
|
|
if (e.InHitbox) {
|
|
if (!opened) {
|
|
return false;
|
|
}
|
|
}
|
|
});
|
|
Events.OnLeave(function() {
|
|
// if (opened) {
|
|
// Self.PlayAnimation("close", function() {
|
|
// opened = false;
|
|
// });
|
|
// }
|
|
})
|
|
}
|