diff --git a/dev-assets/doodads/buttons/button.js b/dev-assets/doodads/buttons/button.js index 83318fb..4cb1d9e 100644 --- a/dev-assets/doodads/buttons/button.js +++ b/dev-assets/doodads/buttons/button.js @@ -3,7 +3,15 @@ function main() { var timer = 0; - Events.OnCollide( function() { + Events.OnCollide(function(e) { + // Verify they've touched the button. + if (e.Overlap.Y + e.Overlap.H < 24) { + Self.Canvas.SetBackground(RGBA(0, 255, 0, 153)); + return; + } + + Self.Canvas.SetBackground(RGBA(255, 255, 0, 153)); + if (timer > 0) { clearTimeout(timer); } @@ -13,5 +21,10 @@ function main() { Self.ShowLayer(0); timer = 0; }, 200); + }); + + Events.OnLeave(function(e) { + console.log("%s has stopped touching %s", e, Self.Doodad.Title) + Self.Canvas.SetBackground(RGBA(0, 0, 1, 0)); }) } diff --git a/dev-assets/doodads/buttons/sticky.js b/dev-assets/doodads/buttons/sticky.js index cf4fe74..a3e1373 100644 --- a/dev-assets/doodads/buttons/sticky.js +++ b/dev-assets/doodads/buttons/sticky.js @@ -1,7 +1,19 @@ function main() { console.log("%s initialized!", Self.Doodad.Title); - Events.OnCollide( function() { + var pressed = false; + + Events.OnCollide(function(e) { + if (pressed) { + return; + } + + // Verify they've touched the button. + if (e.Overlap.Y + e.Overlap.H < 24) { + return; + } + Self.ShowLayer(1); - }) + pressed = true; + }); } diff --git a/dev-assets/doodads/doors/electric-door.js b/dev-assets/doodads/doors/electric-door.js index b665d73..b9ae2b7 100644 --- a/dev-assets/doodads/doors/electric-door.js +++ b/dev-assets/doodads/doors/electric-door.js @@ -1,16 +1,29 @@ function main() { console.log("%s initialized!", Self.Doodad.Title); - var err = Self.AddAnimation("open", 100, [0, 1, 2, 3]); - console.error("door error: %s", err) + Self.AddAnimation("open", 100, [0, 1, 2, 3]); + Self.AddAnimation("close", 100, [3, 2, 1, 0]); var animating = false; + var opened = false; - Events.OnCollide(function() { - if (animating) { + Events.OnCollide(function(e) { + if (animating || opened) { return; } - animating = true; - Self.PlayAnimation("open", null); + if (e.Overlap.X + e.Overlap.W >= 16 && e.Overlap.X < 48) { + animating = true; + Self.PlayAnimation("open", function() { + opened = true; + animating = false; + }); + } }); + Events.OnLeave(function() { + if (opened) { + Self.PlayAnimation("close", function() { + opened = false; + }); + } + }) } diff --git a/dev-assets/doodads/doors/locked-door.js b/dev-assets/doodads/doors/locked-door.js index 75545f9..0c18d2f 100644 --- a/dev-assets/doodads/doors/locked-door.js +++ b/dev-assets/doodads/doors/locked-door.js @@ -3,6 +3,18 @@ function main() { var unlocked = false; Events.OnCollide(function(e) { + console.log("%s was touched by %s!", Self.Doodad.Title, e.Actor.ID()); + console.log("my box: %+v and theirs: %+v", Self.GetBoundingRect(), e.Actor.GetBoundingRect()); + console.warn("But the overlap is: %+v", e.Overlap); + console.log(Object.keys(e)); + + if (e.Overlap.X + e.Overlap.W >= 16 && e.Overlap.X < 48) { + Self.Canvas.SetBackground(RGBA(255, 0, 0, 153)); + } else { + Self.Canvas.SetBackground(RGBA(0, 255, 0, 153)); + return; + } + if (unlocked) { return; } @@ -10,4 +22,8 @@ function main() { 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)); + }) } diff --git a/dev-assets/doodads/trapdoors/down.js b/dev-assets/doodads/trapdoors/down.js index 209eedc..0764ccb 100644 --- a/dev-assets/doodads/trapdoors/down.js +++ b/dev-assets/doodads/trapdoors/down.js @@ -4,22 +4,27 @@ function main() { var timer = 0; var animationSpeed = 100; - var animating = false; + var opened = false; Self.AddAnimation("open", animationSpeed, ["down1", "down2", "down3", "down4"]); Self.AddAnimation("close", animationSpeed, ["down4", "down3", "down2", "down1"]); - Events.OnCollide( function() { - if (animating) { + Events.OnCollide( function(e) { + if (opened) { return; } - animating = true; + // Not touching the top of the door means door doesn't open. + if (e.Overlap.Y > 9) { + return; + } + + opened = true; Self.PlayAnimation("open", function() { - setTimeout(function() { - Self.PlayAnimation("close", function() { - animating = false; - }); - }, 3000); - }) + }); }); + Events.OnLeave(function() { + Self.PlayAnimation("close", function() { + opened = false; + }); + }) }