Noah Petherbridge
27896a9253
Adds support for sound effects in Doodle and configures some for various doodads to start out with: * Buttons and Switches: "Clicked down" and "clicked up" sounds. * Colored Doors: an "unlocked" sound and a "door opened" sound. * Electric Door: sci-fi sounds when opening and closing. * Keys: sound effect for collecting keys. JavaScript API for Doodads adds a global function `Sound.Play(filename)` to play sounds. All sounds in the `rtp/sfx/` folder are pre-loaded on startup for efficient use in the app. Otherwise sounds are lazy-loaded on first playback.
36 lines
648 B
JavaScript
36 lines
648 B
JavaScript
function main() {
|
|
console.log("%s initialized!", Self.Title);
|
|
|
|
var pressed = false;
|
|
|
|
// When a sticky button receives power, it pops back up.
|
|
Message.Subscribe("power", function(powered) {
|
|
if (powered && pressed) {
|
|
Self.ShowLayer(0);
|
|
pressed = false;
|
|
Sound.Play("button-up.wav")
|
|
Message.Publish("power", false);
|
|
}
|
|
})
|
|
|
|
Events.OnCollide(function(e) {
|
|
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);
|
|
});
|
|
}
|