From 375af544a7aea1ec830076c29f42c81da6dc0f88 Mon Sep 17 00:00:00 2001 From: Noah Petherbridge Date: Sun, 3 Jan 2021 15:19:21 -0800 Subject: [PATCH] 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. --- dev-assets/doodads/azulian/azulian-red.js | 2 - dev-assets/doodads/bird/bird.js | 2 - dev-assets/doodads/buttons/button.js | 2 - dev-assets/doodads/buttons/sticky.js | 2 - dev-assets/doodads/doors/electric-door.js | 4 -- dev-assets/doodads/objects/exit-flag.js | 1 - dev-assets/doodads/on-off/state-button.js | 1 - dev-assets/doodads/switches/switch.js | 1 - dev-assets/doodads/trapdoors/down.js | 2 - dev-assets/doodads/trapdoors/trapdoor.js | 1 - dev-assets/doodads/warp-door/warp-door.js | 61 ++++++++++++++++++----- 11 files changed, 48 insertions(+), 31 deletions(-) diff --git a/dev-assets/doodads/azulian/azulian-red.js b/dev-assets/doodads/azulian/azulian-red.js index 87d7d4c..e3a4ea0 100644 --- a/dev-assets/doodads/azulian/azulian-red.js +++ b/dev-assets/doodads/azulian/azulian-red.js @@ -1,6 +1,4 @@ function main() { - console.log("Azulian '%s' initialized!", Self.Title); - var playerSpeed = 4; var gravity = 4; var Vx = Vy = 0; diff --git a/dev-assets/doodads/bird/bird.js b/dev-assets/doodads/bird/bird.js index ca8db3e..d7bb2a7 100644 --- a/dev-assets/doodads/bird/bird.js +++ b/dev-assets/doodads/bird/bird.js @@ -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, diff --git a/dev-assets/doodads/buttons/button.js b/dev-assets/doodads/buttons/button.js index c9c8237..3745467 100644 --- a/dev-assets/doodads/buttons/button.js +++ b/dev-assets/doodads/buttons/button.js @@ -1,6 +1,4 @@ function main() { - console.log("%s initialized!", Self.Title); - var timer = 0; var pressed = false; diff --git a/dev-assets/doodads/buttons/sticky.js b/dev-assets/doodads/buttons/sticky.js index 9dac758..0958454 100644 --- a/dev-assets/doodads/buttons/sticky.js +++ b/dev-assets/doodads/buttons/sticky.js @@ -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. diff --git a/dev-assets/doodads/doors/electric-door.js b/dev-assets/doodads/doors/electric-door.js index 8bc9b0e..646cf4f 100644 --- a/dev-assets/doodads/doors/electric-door.js +++ b/dev-assets/doodads/doors/electric-door.js @@ -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; diff --git a/dev-assets/doodads/objects/exit-flag.js b/dev-assets/doodads/objects/exit-flag.js index 08680a9..fe530fe 100644 --- a/dev-assets/doodads/objects/exit-flag.js +++ b/dev-assets/doodads/objects/exit-flag.js @@ -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) { diff --git a/dev-assets/doodads/on-off/state-button.js b/dev-assets/doodads/on-off/state-button.js index c5e7bd7..f0b02a6 100644 --- a/dev-assets/doodads/on-off/state-button.js +++ b/dev-assets/doodads/on-off/state-button.js @@ -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 diff --git a/dev-assets/doodads/switches/switch.js b/dev-assets/doodads/switches/switch.js index c62689a..f51f9cc 100644 --- a/dev-assets/doodads/switches/switch.js +++ b/dev-assets/doodads/switches/switch.js @@ -1,5 +1,4 @@ function main() { - console.log("%s initialized!", Self.Title); // Switch has two frames: // 0: Off diff --git a/dev-assets/doodads/trapdoors/down.js b/dev-assets/doodads/trapdoors/down.js index cc45c41..3ea5fba 100644 --- a/dev-assets/doodads/trapdoors/down.js +++ b/dev-assets/doodads/trapdoors/down.js @@ -1,6 +1,4 @@ function main() { - console.log("%s initialized!", Self.Title); - var timer = 0; Self.SetHitbox(0, 0, 72, 6); diff --git a/dev-assets/doodads/trapdoors/trapdoor.js b/dev-assets/doodads/trapdoors/trapdoor.js index fb23362..5ad50c2 100644 --- a/dev-assets/doodads/trapdoors/trapdoor.js +++ b/dev-assets/doodads/trapdoors/trapdoor.js @@ -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; diff --git a/dev-assets/doodads/warp-door/warp-door.js b/dev-assets/doodads/warp-door/warp-door.js index 2dc73ab..0cb6e1a 100644 --- a/dev-assets/doodads/warp-door/warp-door.js +++ b/dev-assets/doodads/warp-door/warp-door.js @@ -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); + } + }); + }); }); }