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;
|
var animFrame = animStart;
|
||||||
|
|
||||||
Self.SetGravity(true);
|
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-left", 100, ["blu-wl1", "blu-wl2", "blu-wl3", "blu-wl4"]);
|
||||||
Self.AddAnimation("walk-right", 100, ["blu-wr1", "blu-wr2", "blu-wr3", "blu-wr4"]);
|
Self.AddAnimation("walk-right", 100, ["blu-wr1", "blu-wr2", "blu-wr3", "blu-wr4"]);
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,7 @@
|
||||||
function main() {
|
function main() {
|
||||||
Events.OnCollide(function(e) {
|
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();
|
Self.Destroy();
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,25 +2,33 @@ function main() {
|
||||||
Self.AddAnimation("open", 0, [1]);
|
Self.AddAnimation("open", 0, [1]);
|
||||||
var unlocked = false;
|
var unlocked = false;
|
||||||
|
|
||||||
Events.OnCollide(function(e) {
|
// Map our door names to key names.
|
||||||
console.log("%s was touched by %s!", Self.Doodad.Title, e.Actor.ID());
|
var KeyMap = {
|
||||||
console.log("my box: %+v and theirs: %+v", Self.GetBoundingRect(), e.Actor.GetBoundingRect());
|
"Blue Door": "Blue Key",
|
||||||
console.warn("But the overlap is: %+v", e.Overlap);
|
"Red Door": "Red Key",
|
||||||
console.log(Object.keys(e));
|
"Green Door": "Green Key",
|
||||||
|
"Yellow Door": "Yellow Key"
|
||||||
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;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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) {
|
||||||
if (unlocked) {
|
if (unlocked) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (e.InHitbox) {
|
||||||
|
var data = e.Actor.GetData("key:" + KeyMap[Self.Doodad.Title]);
|
||||||
|
if (data === "") {
|
||||||
|
// Door is locked.
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
unlocked = true;
|
unlocked = true;
|
||||||
Self.PlayAnimation("open", null);
|
Self.PlayAnimation("open", null);
|
||||||
|
}
|
||||||
});
|
});
|
||||||
Events.OnLeave(function(e) {
|
Events.OnLeave(function(e) {
|
||||||
console.log("%s has stopped touching %s", e, Self.Doodad.Title)
|
console.log("%s has stopped touching %s", e, Self.Doodad.Title)
|
||||||
|
|
|
@ -3,6 +3,8 @@ function main() {
|
||||||
|
|
||||||
var timer = 0;
|
var timer = 0;
|
||||||
|
|
||||||
|
Self.SetHitbox(0, 0, 72, 9);
|
||||||
|
|
||||||
var animationSpeed = 100;
|
var animationSpeed = 100;
|
||||||
var opened = false;
|
var opened = false;
|
||||||
Self.AddAnimation("open", animationSpeed, ["down1", "down2", "down3", "down4"]);
|
Self.AddAnimation("open", animationSpeed, ["down1", "down2", "down3", "down4"]);
|
||||||
|
@ -13,18 +15,24 @@ function main() {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Not touching the top of the door means door doesn't open.
|
// Is the actor colliding our solid part?
|
||||||
if (e.Overlap.Y > 9) {
|
if (e.InHitbox) {
|
||||||
return;
|
// Touching the top or the bottom?
|
||||||
}
|
if (e.Overlap.Y > 0) {
|
||||||
|
return false; // solid wall when touched from below
|
||||||
|
} else {
|
||||||
opened = true;
|
opened = true;
|
||||||
Self.PlayAnimation("open", function() {
|
Self.PlayAnimation("open", function() {
|
||||||
});
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
Events.OnLeave(function() {
|
Events.OnLeave(function() {
|
||||||
|
if (opened) {
|
||||||
Self.PlayAnimation("close", function() {
|
Self.PlayAnimation("close", function() {
|
||||||
opened = false;
|
opened = false;
|
||||||
});
|
});
|
||||||
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user