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.
master
Noah 2021-01-03 15:19:21 -08:00
parent fae8c1af5e
commit 375af544a7
11 changed files with 48 additions and 31 deletions

View File

@ -1,6 +1,4 @@
function main() {
console.log("Azulian '%s' initialized!", Self.Title);
var playerSpeed = 4;
var gravity = 4;
var Vx = Vy = 0;

View File

@ -4,8 +4,6 @@ function main() {
var Vx = Vy = 0;
var altitude = Self.Position().Y; // original height in the level
console.log("Bird altitude is %d", altitude);
var direction = "left";
var states = {
flying: 0,

View File

@ -1,6 +1,4 @@
function main() {
console.log("%s initialized!", Self.Title);
var timer = 0;
var pressed = false;

View File

@ -1,6 +1,4 @@
function main() {
console.log("%s initialized!", Self.Title);
var pressed = false;
// When a sticky button receives power, it pops back up.

View File

@ -1,6 +1,4 @@
function main() {
console.log("%s initialized!", Self.Title);
Self.AddAnimation("open", 100, [0, 1, 2, 3]);
Self.AddAnimation("close", 100, [3, 2, 1, 0]);
var animating = false;
@ -9,8 +7,6 @@ function main() {
Self.SetHitbox(0, 0, 34, 76);
Message.Subscribe("power", function(powered) {
console.log("%s got power=%+v", Self.Title, powered);
if (powered) {
if (animating || opened) {
return;

View File

@ -1,6 +1,5 @@
// Exit Flag.
function main() {
console.log("%s initialized!", Self.Title);
Self.SetHitbox(22+16, 16, 75-16, 86);
Events.OnCollide(function(e) {

View File

@ -4,7 +4,6 @@
var state = false;
function main() {
console.log("%s ID '%s' initialized!", Self.Title, Self.ID());
Self.SetHitbox(0, 0, 42, 42);
// When the button is activated, don't keep toggling state until we're not

View File

@ -1,5 +1,4 @@
function main() {
console.log("%s initialized!", Self.Title);
// Switch has two frames:
// 0: Off

View File

@ -1,6 +1,4 @@
function main() {
console.log("%s initialized!", Self.Title);
var timer = 0;
Self.SetHitbox(0, 0, 72, 6);

View File

@ -1,7 +1,6 @@
function main() {
// What direction is the trapdoor facing?
var direction = Self.GetTag("direction");
console.log("Trapdoor(%s) initialized", direction);
var timer = 0;

View File

@ -1,7 +1,5 @@
// Warp Doors
function main() {
console.log("Warp Door %s Initialized", Self.Title);
Self.SetHitbox(0, 0, 34, 76);
// Are we a blue or orange door? Regular warp door will be 'none'
@ -31,12 +29,18 @@ function main() {
spriteDefault = "door-1";
}
console.log("Warp %s: default=%s disabled=%+v color=%s isState=%+v state=%+v", Self.Title, spriteDefault, spriteDisabled, color, isStateDoor, state);
// Find our linked Warp Door.
var links = Self.GetLinks()
var linkedDoor = null;
for (var i = 0; i < links.length; i++) {
if (links[i].Title.indexOf("Warp Door") > -1) {
linkedDoor = links[i];
}
}
// Subscribe to the global state-change if we are a state door.
if (isStateDoor) {
Message.Subscribe("broadcast:state-change", function(newState) {
console.log("Warp %s: received state to %+v", Self.Title, newState);
state = color === 'blue' ? !newState : newState;
// Activate or deactivate the door.
@ -44,38 +48,69 @@ function main() {
});
}
// TODO: respond to a "Use" button instead of a Collide to open the door.
Events.OnCollide(function(e) {
if (!e.Settled) {
// The player Uses the door.
var flashedCooldown = false; // "Locked Door" flashed message.
Events.OnUse(function(e) {
if (animating) {
return;
}
if (animating || collide) {
// Doors without linked exits are not usable.
if (linkedDoor === null) {
if (!flashedCooldown) {
Flash("This door is locked.");
flashedCooldown = true;
setTimeout(function() {
flashedCooldown = false;
}, 1000);
}
return;
}
// Only players can use doors for now.
if (e.Actor.IsPlayer() && e.InHitbox) {
if (e.Actor.IsPlayer()) {
if (isStateDoor && !state) {
// The state door is inactive (dotted outline).
return;
}
// Freeze the player.
e.Actor.Freeze()
// Play the open and close animation.
animating = true;
collide = true;
Self.PlayAnimation("open", function() {
e.Actor.Hide()
Self.PlayAnimation("close", function() {
Self.ShowLayerNamed(isStateDoor && !state ? spriteDisabled : spriteDefault);
e.Actor.Show()
animating = false;
// Teleport the player to the linked door. Inform the target
// door of the arrival of the player so it doesn't trigger
// to send the player back here again on a loop.
if (linkedDoor !== null) {
Message.Publish("warp-door:incoming", e.Actor);
e.Actor.MoveTo(linkedDoor.Position());
}
});
});
}
});
Events.OnLeave(function(e) {
collide = false;
// Respond to incoming warp events.
Message.Subscribe("warp-door:incoming", function(player) {
animating = true;
player.Unfreeze();
Self.PlayAnimation("open", function() {
player.Show();
Self.PlayAnimation("close", function() {
animating = false;
// If the receiving door was a State Door, fix its state.
if (isStateDoor) {
Self.ShowLayerNamed(state ? spriteDefault : spriteDisabled);
}
});
});
});
}