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.
This commit is contained in:
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);
var timer = 0;
var pressed = false;
Events.OnCollide(function(e) {
if (!e.Settled) {
@ -13,7 +14,12 @@ function main() {
return;
}
Message.Publish("power", true);
if (!pressed) {
Sound.Play("button-down.wav")
Message.Publish("power", true);
pressed = true;
}
if (timer > 0) {
clearTimeout(timer);
@ -21,9 +27,11 @@ function main() {
Self.ShowLayer(1);
timer = setTimeout(function() {
Sound.Play("button-up.wav")
Self.ShowLayer(0);
Message.Publish("power", false);
timer = 0;
pressed = false;
}, 200);
});
}

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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