Built-in doodads and levels of Sketchy Maze.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

89 lines
2.0 KiB

3 years ago
// Trapdoors.
3 years ago
3 years ago
// What direction is the trapdoor facing?
const direction = Self.GetTag("direction");
3 years ago
3 years ago
function main() {
3 years ago
// Set our hitbox based on our orientation.
3 years ago
let thickness = 10;
let doodadSize = 86;
3 years ago
if (direction === "left") {
Self.SetHitbox(48, 0, doodadSize, doodadSize);
} else if (direction === "right") {
Self.SetHitbox(0, 0, thickness, doodadSize);
} else if (direction === "up") {
Self.SetHitbox(0, doodadSize - thickness, doodadSize, doodadSize);
} else { // Down, default.
Self.SetHitbox(0, 0, doodadSize, thickness);
}
3 years ago
let animationSpeed = 100;
let opened = false;
3 years ago
// Register our animations.
3 years ago
let frames = [];
for (let i = 1; i <= 4; i++) {
3 years ago
frames.push(direction + i);
}
Self.AddAnimation("open", animationSpeed, frames);
frames.reverse();
Self.AddAnimation("close", animationSpeed, frames);
3 years ago
Events.OnCollide((e) => {
3 years ago
if (opened) {
return;
}
// Is the actor colliding our solid part?
if (e.InHitbox) {
// Are they touching our opening side?
if (direction === "left") {
if (doodadSize - e.Overlap.X < thickness) {
// Touching the right edge, open the door.
opened = true;
Self.PlayAnimation("open", null);
return;
}
if (e.Overlap.W === doodadSize - thickness) {
return false;
}
} else if (direction === "right") {
if (e.Overlap.X > 0) {
return false;
} else if (e.Settled) {
opened = true;
Self.PlayAnimation("open", null);
}
} else if (direction === "up") {
if (doodadSize - e.Overlap.Y < thickness) {
// Touching the bottom edge, open the door.
opened = true;
Self.PlayAnimation("open", null);
return;
}
if (e.Overlap.H === doodadSize - thickness) {
return false;
}
} else if (direction === "down") {
if (e.Overlap.Y > 0) {
return false;
} else if (e.Settled) {
opened = true;
Self.PlayAnimation("open", null);
}
}
return true;
}
});
3 years ago
Events.OnLeave(() => {
3 years ago
if (opened) {
3 years ago
Self.PlayAnimation("close", () => {
3 years ago
opened = false;
});
}
})
}