2019-12-31 02:13:28 +00:00
|
|
|
// Crumbly Floor.
|
|
|
|
function main() {
|
2021-01-04 01:06:33 +00:00
|
|
|
Self.SetHitbox(0, 0, 98, 11);
|
2019-12-31 02:13:28 +00:00
|
|
|
|
|
|
|
Self.AddAnimation("shake", 100, ["shake1", "shake2", "floor", "shake1", "shake2", "floor"]);
|
|
|
|
Self.AddAnimation("fall", 100, ["fall1", "fall2", "fall3", "fall4"]);
|
|
|
|
|
|
|
|
// Recover time for the floor to respawn.
|
2022-01-17 04:09:27 +00:00
|
|
|
let recover = 5000;
|
2019-12-31 02:13:28 +00:00
|
|
|
|
|
|
|
// States of the floor.
|
2022-01-17 04:09:27 +00:00
|
|
|
let stateSolid = 0;
|
|
|
|
let stateShaking = 1;
|
|
|
|
let stateFalling = 2;
|
|
|
|
let stateFallen = 3;
|
|
|
|
let state = stateSolid;
|
2019-12-31 02:13:28 +00:00
|
|
|
|
2022-01-17 04:09:27 +00:00
|
|
|
Events.OnCollide((e) => {
|
2019-12-31 02:13:28 +00:00
|
|
|
|
|
|
|
// If the floor is falling, the player passes right thru.
|
|
|
|
if (state === stateFalling || state === stateFallen) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Floor is solid until it begins to fall.
|
|
|
|
if (e.InHitbox && (state === stateSolid || state === stateShaking)) {
|
|
|
|
// Only activate when touched from the top.
|
|
|
|
if (e.Overlap.Y > 0) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2020-01-03 06:05:49 +00:00
|
|
|
// If movement is not settled, be solid.
|
|
|
|
if (!e.Settled) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2019-12-31 02:13:28 +00:00
|
|
|
// Begin the animation sequence if we're in the solid state.
|
|
|
|
if (state === stateSolid) {
|
|
|
|
state = stateShaking;
|
2022-01-17 04:09:27 +00:00
|
|
|
Self.PlayAnimation("shake", () => {
|
2019-12-31 02:13:28 +00:00
|
|
|
state = stateFalling;
|
2022-01-17 04:09:27 +00:00
|
|
|
Self.PlayAnimation("fall", () => {
|
2020-05-23 03:07:48 +00:00
|
|
|
Sound.Play("crumbly-break.wav")
|
2019-12-31 02:13:28 +00:00
|
|
|
state = stateFallen;
|
|
|
|
Self.ShowLayerNamed("fallen");
|
|
|
|
|
|
|
|
// Recover after a while.
|
2022-01-17 04:09:27 +00:00
|
|
|
setTimeout(() => {
|
2019-12-31 02:13:28 +00:00
|
|
|
Self.ShowLayer(0);
|
|
|
|
state = stateSolid;
|
|
|
|
}, recover);
|
|
|
|
});
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|