doodle/dev-assets/doodads/doors/locked-door.js
Noah Petherbridge 1523deeb9c Return False: Solid Collision Between Actors
* Implement the handler code for `return false` when actors are
  colliding with each other and wish to act like solid walls.
* The locked doors will `return false` when they're closed and the
  colliding actor does not have the matching key.
* Add arbitrary key/value storage to Actors. The colored keys will set
  an actor value "key:%TITLE%" on the one who touched the key before
  destroying itself. The colored doors check that key when touched to
  decide whether to open.
* The trapdoor now only opens if you're touching it from the top (your
  overlap box Y value is 0), but if you touch it from below and the door
  is closed, it acts like a solid object.
2019-05-28 21:43:30 -07:00

38 lines
814 B
JavaScript

function main() {
Self.AddAnimation("open", 0, [1]);
var unlocked = false;
// 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)
Self.Canvas.SetBackground(RGBA(0, 0, 1, 0));
})
}