Noah Petherbridge
a2e1bd1ccb
* Events.OnCollide now receives a CollideEvent object, which makes available the .Actor who collided and the .Overlap rect which is zero-relative to the target actor. Doodad scripts can use the .Overlap to see WHERE in their own box the other actor has intruded. * Update the LockedDoor and ElectricDoor doodads to detect when the player has entered their inner rect (since their doors are narrower than their doodad size) * Update the Button doodads to only press in when the player actually touches them (because their sizes are shorter than their doodad height) * Update the Trapdoor to only trigger its animation when the board along its top has been touched, not when the empty space below was touched from the bottom. * Events.OnLeave now implemented and fires when an actor who was previously intersecting your doodad has left. * The engine detects when an event JS callback returns false. Eventually, the OnCollide can return false to signify the collision is not accepted and the actor should be bumped away as if they hit solid geometry.
31 lines
627 B
JavaScript
31 lines
627 B
JavaScript
function main() {
|
|
console.log("%s initialized!", Self.Doodad.Title);
|
|
|
|
var timer = 0;
|
|
|
|
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);
|
|
}
|
|
|
|
Self.ShowLayer(1);
|
|
timer = setTimeout(function() {
|
|
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));
|
|
})
|
|
}
|