Add Initial Sound Effects

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.
master
Noah 2020-05-22 20:07:48 -07:00
parent 227a58bb39
commit 2aecd1f198
7 changed files with 19 additions and 1 deletions

View File

@ -2,6 +2,7 @@ function main() {
console.log("%s initialized!", Self.Title); console.log("%s initialized!", Self.Title);
var timer = 0; var timer = 0;
var pressed = false;
Events.OnCollide(function(e) { Events.OnCollide(function(e) {
if (!e.Settled) { if (!e.Settled) {
@ -13,7 +14,12 @@ function main() {
return; return;
} }
Message.Publish("power", true); if (!pressed) {
Sound.Play("button-down.wav")
Message.Publish("power", true);
pressed = true;
}
if (timer > 0) { if (timer > 0) {
clearTimeout(timer); clearTimeout(timer);
@ -21,9 +27,11 @@ function main() {
Self.ShowLayer(1); Self.ShowLayer(1);
timer = setTimeout(function() { timer = setTimeout(function() {
Sound.Play("button-up.wav")
Self.ShowLayer(0); Self.ShowLayer(0);
Message.Publish("power", false); Message.Publish("power", false);
timer = 0; timer = 0;
pressed = false;
}, 200); }, 200);
}); });
} }

View File

@ -8,6 +8,7 @@ function main() {
if (powered && pressed) { if (powered && pressed) {
Self.ShowLayer(0); Self.ShowLayer(0);
pressed = false; pressed = false;
Sound.Play("button-up.wav")
Message.Publish("power", false); Message.Publish("power", false);
} }
}) })
@ -26,6 +27,7 @@ function main() {
return; return;
} }
Sound.Play("button-down.wav")
Self.ShowLayer(1); Self.ShowLayer(1);
pressed = true; pressed = true;
Message.Publish("power", true); Message.Publish("power", true);

View File

@ -43,6 +43,7 @@ function main() {
Self.PlayAnimation("shake", function() { Self.PlayAnimation("shake", function() {
state = stateFalling; state = stateFalling;
Self.PlayAnimation("fall", function() { Self.PlayAnimation("fall", function() {
Sound.Play("crumbly-break.wav")
state = stateFallen; state = stateFallen;
Self.ShowLayerNamed("fallen"); Self.ShowLayerNamed("fallen");

View File

@ -32,6 +32,7 @@ function main() {
if (unlocked) { if (unlocked) {
Self.ShowLayer(enterSide < 0 ? layer.right : layer.left); Self.ShowLayer(enterSide < 0 ? layer.right : layer.left);
opened = true; opened = true;
Sound.Play("door-open.wav")
return; return;
} }
@ -45,11 +46,13 @@ function main() {
if (e.Settled) { if (e.Settled) {
unlocked = true; unlocked = true;
Self.ShowLayer(enterSide < 0 ? layer.right : layer.left); Self.ShowLayer(enterSide < 0 ? layer.right : layer.left);
Sound.Play("unlock.wav")
} }
} }
}); });
Events.OnLeave(function(e) { Events.OnLeave(function(e) {
Self.ShowLayer(layer.closed); Self.ShowLayer(layer.closed);
// Sound.Play("door-close.wav")
// Reset collision state. // Reset collision state.
opened = false; opened = false;

View File

@ -17,12 +17,14 @@ function main() {
} }
animating = true; animating = true;
Sound.Play("electric-door.wav")
Self.PlayAnimation("open", function() { Self.PlayAnimation("open", function() {
opened = true; opened = true;
animating = false; animating = false;
}); });
} else { } else {
animating = true; animating = true;
Sound.Play("electric-door.wav")
Self.PlayAnimation("close", function() { Self.PlayAnimation("close", function() {
opened = false; opened = false;
animating = false; animating = false;

View File

@ -3,6 +3,7 @@ function main() {
Events.OnCollide(function(e) { Events.OnCollide(function(e) {
if (e.Settled) { if (e.Settled) {
Sound.Play("item-get.wav")
e.Actor.AddItem(Self.Filename, 0); e.Actor.AddItem(Self.Filename, 0);
Self.Destroy(); Self.Destroy();
} }

View File

@ -19,6 +19,7 @@ function main() {
} }
if (collide === false) { if (collide === false) {
Sound.Play("button-down.wav")
state = !state; state = !state;
Message.Publish("power", state); Message.Publish("power", state);
showState(state); showState(state);