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.
This commit is contained in:
parent
13d40423cc
commit
8ecd448b00
|
@ -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"]);
|
||||
|
||||
|
|
|
@ -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();
|
||||
})
|
||||
}
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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;
|
||||
});
|
||||
}
|
||||
})
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user