diff --git a/dev-assets/doodads/azulian/azulian.js b/dev-assets/doodads/azulian/azulian.js index 69bf9c8..5178cc7 100644 --- a/dev-assets/doodads/azulian/azulian.js +++ b/dev-assets/doodads/azulian/azulian.js @@ -10,6 +10,7 @@ function main() { var animFrame = animStart; Self.SetGravity(true); + Self.SetHitbox(7, 4, 17, 28); Self.AddAnimation("walk-left", 100, ["blu-wl1", "blu-wl2", "blu-wl3", "blu-wl4"]); Self.AddAnimation("walk-right", 100, ["blu-wr1", "blu-wr2", "blu-wr3", "blu-wr4"]); diff --git a/dev-assets/doodads/doors/keys.js b/dev-assets/doodads/doors/keys.js index ab81605..7c9a495 100644 --- a/dev-assets/doodads/doors/keys.js +++ b/dev-assets/doodads/doors/keys.js @@ -1,5 +1,7 @@ function main() { Events.OnCollide(function(e) { + console.log("%s picked up by %s", Self.Doodad.Title, e.Actor.Title); + e.Actor.SetData("key:" + Self.Doodad.Title, "true"); Self.Destroy(); }) } diff --git a/dev-assets/doodads/doors/locked-door.js b/dev-assets/doodads/doors/locked-door.js index 0c18d2f..cabbce2 100644 --- a/dev-assets/doodads/doors/locked-door.js +++ b/dev-assets/doodads/doors/locked-door.js @@ -2,25 +2,33 @@ 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) { - 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; } - unlocked = true; - Self.PlayAnimation("open", null); + 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) diff --git a/dev-assets/doodads/trapdoors/down.js b/dev-assets/doodads/trapdoors/down.js index 0764ccb..e861082 100644 --- a/dev-assets/doodads/trapdoors/down.js +++ b/dev-assets/doodads/trapdoors/down.js @@ -3,6 +3,8 @@ function main() { var timer = 0; + Self.SetHitbox(0, 0, 72, 9); + var animationSpeed = 100; var opened = false; Self.AddAnimation("open", animationSpeed, ["down1", "down2", "down3", "down4"]); @@ -13,18 +15,24 @@ function main() { return; } - // Not touching the top of the door means door doesn't open. - if (e.Overlap.Y > 9) { - return; + // Is the actor colliding our solid part? + if (e.InHitbox) { + // Touching the top or the bottom? + if (e.Overlap.Y > 0) { + return false; // solid wall when touched from below + } else { + opened = true; + Self.PlayAnimation("open", function() { + }); + } } - - opened = true; - Self.PlayAnimation("open", function() { - }); }); + Events.OnLeave(function() { - Self.PlayAnimation("close", function() { - opened = false; - }); + if (opened) { + Self.PlayAnimation("close", function() { + opened = false; + }); + } }) }