2021-08-09 04:54:37 +00:00
|
|
|
// Anvil
|
|
|
|
var falling = false;
|
|
|
|
|
|
|
|
function main() {
|
|
|
|
// Note: doodad is not "solid" but hurts if it falls on you.
|
|
|
|
Self.SetHitbox(0, 0, 48, 25);
|
|
|
|
Self.SetMobile(true);
|
|
|
|
Self.SetGravity(true);
|
2022-02-20 19:48:36 +00:00
|
|
|
Self.SetInvulnerable(true);
|
2021-08-09 04:54:37 +00:00
|
|
|
|
|
|
|
// Monitor our Y position to tell if we've been falling.
|
2022-01-17 04:09:27 +00:00
|
|
|
let lastPoint = Self.Position();
|
|
|
|
setInterval(() => {
|
|
|
|
let nowAt = Self.Position();
|
2021-08-09 04:54:37 +00:00
|
|
|
if (nowAt.Y > lastPoint.Y) {
|
|
|
|
falling = true;
|
|
|
|
} else {
|
|
|
|
falling = false;
|
|
|
|
}
|
|
|
|
lastPoint = nowAt;
|
|
|
|
}, 100);
|
|
|
|
|
2022-01-17 04:09:27 +00:00
|
|
|
Events.OnCollide((e) => {
|
2021-08-09 04:54:37 +00:00
|
|
|
if (!e.Settled) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Were we falling?
|
|
|
|
if (falling) {
|
|
|
|
if (e.InHitbox) {
|
|
|
|
if (e.Actor.IsPlayer()) {
|
|
|
|
// Fatal to the player.
|
|
|
|
Sound.Play("crumbly-break.wav");
|
|
|
|
FailLevel("Watch out for anvils!");
|
|
|
|
return;
|
|
|
|
}
|
2022-02-20 19:48:36 +00:00
|
|
|
else if (e.Actor.IsMobile() && !e.Actor.Invulnerable()) {
|
2021-08-09 04:54:37 +00:00
|
|
|
// Destroy mobile doodads.
|
|
|
|
Sound.Play("crumbly-break.wav");
|
|
|
|
e.Actor.Destroy();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
// When we receive power, we reset to our original position.
|
2022-01-17 04:09:27 +00:00
|
|
|
let origPoint = Self.Position();
|
|
|
|
Message.Subscribe("power", (powered) => {
|
2021-08-09 04:54:37 +00:00
|
|
|
Self.MoveTo(origPoint);
|
|
|
|
Self.SetVelocity(Vector(0, 0));
|
|
|
|
});
|
|
|
|
}
|