Example doodads from 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.
 
 
 

79 lines
1.9 KiB

// Warp Doors
function main() {
Self.SetHitbox(0, 0, 34, 76);
var animating = false;
var collide = false;
// Declare animations and sprite names.
var animSpeed = 100;
var spriteDefault = "door-1";
Self.AddAnimation("open", animSpeed, ["door-2", "door-3", "door-4"]);
Self.AddAnimation("close", animSpeed, ["door-4", "door-3", "door-2", "door-1"]);
// Find our linked Warp Door.
var links = Self.GetLinks()
var linkedDoor = null;
for (var i = 0; i < links.length; i++) {
if (links[i].Title.indexOf("Warp Door") > -1) {
linkedDoor = links[i];
}
}
// The player Uses the door.
var flashedCooldown = false; // "Locked Door" flashed message.
Events.OnUse(function (e) {
if (animating) {
return;
}
// Doors without linked exits are not usable.
if (linkedDoor === null) {
if (!flashedCooldown) {
Flash("This door is locked.");
flashedCooldown = true;
setTimeout(function () {
flashedCooldown = false;
}, 1000);
}
return;
}
// Only players can use doors for now.
if (e.Actor.IsPlayer()) {
// Freeze the player.
e.Actor.Freeze()
// Play the open and close animation.
animating = true;
Self.PlayAnimation("open", function () {
e.Actor.Hide()
Self.PlayAnimation("close", function () {
Self.ShowLayerNamed(spriteDefault);
animating = false;
// Teleport the player to the linked door. Inform the target
// door of the arrival of the player so it doesn't trigger
// to send the player back here again on a loop.
if (linkedDoor !== null) {
Message.Publish("warp-door:incoming", e.Actor);
e.Actor.MoveTo(linkedDoor.Position());
}
});
});
}
});
// Respond to incoming warp events.
Message.Subscribe("warp-door:incoming", function (player) {
animating = true;
player.Unfreeze();
Self.PlayAnimation("open", function () {
player.Show();
Self.PlayAnimation("close", function () {
animating = false;
});
});
});
}