doodle/dev-assets/doodads/buttons/sticky.js

36 lines
674 B
JavaScript
Raw Normal View History

function main() {
let pressed = false;
// When a sticky button receives power, it pops back up.
Message.Subscribe("power", (powered) => {
if (powered && pressed) {
Self.ShowLayer(0);
pressed = false;
Sound.Play("button-up.wav")
Message.Publish("power", false);
Various updates New doodad interactions: * Sticky Buttons will emit a "sticky:down" event to linked doodads, with a boolean value showing the Sticky Button's state. * Normal Buttons will listen for "sticky:down" -- when a linked Sticky Button is pressed, the normal Button presses in as well, and stays pressed while the sticky:down signal is true. * When the Sticky Button is released (e.g. because it received power from another doodad), any linked buttons which were sticky:down release as well. * Switch doodads emit a new "switch:toggle" event JUST BEFORE sending the "power" event. Sensitive Doodads can listen for switches in particular this way. * The Electric Door listens for switch:toggle; if a Switch is activated, the Electric Door always flips its current state (open to close, or vice versa) and ignores the immediately following power event. This allows doors to toggle on/off regardless of sync with a Switch. Other changes: * When the player character dies by fire, instead of the message saying "Watch out for fire!" it will use the name of the fire swatch that hurt the player. This way levels could make it say "Watch out for spikes!" or "lava" or whatever they want. The "Fire" attribute now just means "instantly kills the player." * Level Editor: You can now edit the Title and Author name of your level in the Page Settings window. * Bugfix: only the player character ends the game by dying in fire. Other mobile doodads just turn dark but don't end the game. * Increase the size of Trapdoor doodad sprites by 150% as they were a bit small for the player character. * Rename the game from "Project: Doodle" to "Sketchy Maze"
2021-03-31 06:33:25 +00:00
Message.Publish("sticky:down", false);
}
})
Events.OnCollide((e) => {
Improve Collision Detection: More Active w/ Actors * Improve the collision detection algorithm so that Actor OnCollide scripts get called more often WHILE an actor is moving, to prevent a fast-moving actor from zipping right through the "solid" hitbox and not giving the subject actor time to protest the movement. * It's implemented by adding a `Settled` boolean to the OnCollide event object. When the game is testing out movement, Settled=false to give the actor a chance to say "I'm solid!" and have the moving party be stopped early. * After all this is done, for any pair of actors still with overlapping hitboxes, OnCollide is called one last time with Settled=true. This is when the actor should run its actions (like publishing messages to other actors, changing state as in a trapdoor, etc.) * The new collision detection algorithm works as follows: * Stage 1 is the same as before, all mobile actors are moved and tested against level geometry. They record their Original and New position during this phase. * Stage 2 is where we re-run that movement but ping actors being intersected each step of the way. We trace the steps between Original and New position, test OnCollide handler, and if it returns false we move the mobile actor to the Last Good Position along the trace. * Stage 3 we run the final OnCollide(Settled=true) to let actors run actions they wanted to for their collide handler, WITHOUT spamming those actions during Stage 2. * This should now allow for tweaking of gravity speed and player speed without breaking all actor collision checking.
2019-07-17 04:07:38 +00:00
if (!e.Settled) {
return;
}
if (pressed) {
return;
}
// Verify they've touched the button.
if (e.Overlap.Y + e.Overlap.H < 24) {
return;
}
Sound.Play("button-down.wav")
Self.ShowLayer(1);
pressed = true;
Message.Publish("power", true);
Various updates New doodad interactions: * Sticky Buttons will emit a "sticky:down" event to linked doodads, with a boolean value showing the Sticky Button's state. * Normal Buttons will listen for "sticky:down" -- when a linked Sticky Button is pressed, the normal Button presses in as well, and stays pressed while the sticky:down signal is true. * When the Sticky Button is released (e.g. because it received power from another doodad), any linked buttons which were sticky:down release as well. * Switch doodads emit a new "switch:toggle" event JUST BEFORE sending the "power" event. Sensitive Doodads can listen for switches in particular this way. * The Electric Door listens for switch:toggle; if a Switch is activated, the Electric Door always flips its current state (open to close, or vice versa) and ignores the immediately following power event. This allows doors to toggle on/off regardless of sync with a Switch. Other changes: * When the player character dies by fire, instead of the message saying "Watch out for fire!" it will use the name of the fire swatch that hurt the player. This way levels could make it say "Watch out for spikes!" or "lava" or whatever they want. The "Fire" attribute now just means "instantly kills the player." * Level Editor: You can now edit the Title and Author name of your level in the Page Settings window. * Bugfix: only the player character ends the game by dying in fire. Other mobile doodads just turn dark but don't end the game. * Increase the size of Trapdoor doodad sprites by 150% as they were a bit small for the player character. * Rename the game from "Project: Doodle" to "Sketchy Maze"
2021-03-31 06:33:25 +00:00
Message.Publish("sticky:down", true);
});
}