Add sound effects

master
Skylar Ittner 8 years ago
parent 6a5fa9b4f8
commit 4dfbc2cda2

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

@ -20,8 +20,10 @@ var audio_stay_stopped = false;
var audio_doneplaying = true; var audio_doneplaying = true;
var audio_isplaying = false; var audio_isplaying = false;
var audio; var audio;
var sound;
var MUSIC_DIR = getWwwFolderPath() + "assets/audio/"; var MUSIC_DIR = getWwwFolderPath() + "assets/audio/";
var SOUND_DIR = getWwwFolderPath() + "assets/sound/";
function queuesong(song) { function queuesong(song) {
if (audio_isplaying) { if (audio_isplaying) {
@ -61,6 +63,14 @@ function playAudio() {
audio.play({playAudioWhenScreenIsLocked: false}); audio.play({playAudioWhenScreenIsLocked: false});
} }
function playSound(soundname) {
if (localStorage.getItem("sounds") === "mute") {
return;
}
sound = new Media(SOUND_DIR + soundname + ".mp3", null, null, null);
sound.play({playAudioWhenScreenIsLocked: false});
}
document.addEventListener("pause", function () { document.addEventListener("pause", function () {
audio.pause(); audio.pause();
audio_doneplaying = false; audio_doneplaying = false;

@ -38,10 +38,12 @@ function buycoins(productId) {
}); });
}) })
.then(function () { .then(function () {
playSound("coin");
showSuccessMessage("Thanks for your purchase!"); showSuccessMessage("Thanks for your purchase!");
refreshcoins(); refreshcoins();
}) })
.catch(function (err) { .catch(function (err) {
playSound("error");
console.log("Error: " + err.message); console.log("Error: " + err.message);
showErrorMessage("Error: " + err.message); showErrorMessage("Error: " + err.message);
}); });
@ -67,10 +69,12 @@ function buycoins(productId) {
}); });
}) })
.then(function () { .then(function () {
playSound("coin");
showSuccessMessage("Thanks for your purchase!"); showSuccessMessage("Thanks for your purchase!");
refreshcoins(); refreshcoins();
}) })
.catch(function (err) { .catch(function (err) {
playSound("error");
console.log("Error: " + err.message); console.log("Error: " + err.message);
showErrorMessage("Error: " + err.message); showErrorMessage("Error: " + err.message);
}); });
@ -87,8 +91,10 @@ function buyitem(id, cost) {
lang: USER_LANGUAGE lang: USER_LANGUAGE
}, function (data) { }, function (data) {
if (data.status == 'OK') { if (data.status == 'OK') {
playSound("coin");
showSuccessMessage(data.message); showSuccessMessage(data.message);
} else { } else {
playSound("error");
showErrorMessage(data.message); showErrorMessage(data.message);
} }
loadstorefront(); loadstorefront();

@ -61,6 +61,7 @@
content = ""; content = "";
} }
if (content == '') { if (content == '') {
playSound("error");
showErrorMessage("There is nobody nearby to give an item to."); showErrorMessage("There is nobody nearby to give an item to.");
} else { } else {
$('#nearby-players-dropdown').html(content); $('#nearby-players-dropdown').html(content);
@ -84,6 +85,7 @@
syncStats(); syncStats();
showSuccessMessage("Transferred!"); showSuccessMessage("Transferred!");
} else { } else {
playSound("error");
showErrorMessage(data.message); showErrorMessage(data.message);
} }
}).fail(function () { }).fail(function () {
@ -101,6 +103,7 @@
loadinventory(); loadinventory();
syncStats(); syncStats();
} else { } else {
playSound("error");
showErrorMessage(data.message); showErrorMessage(data.message);
} }
}).fail(function () { }).fail(function () {

@ -184,16 +184,22 @@
case 3: case 3:
$('#place-log').prepend("Attacking....<br />"); $('#place-log').prepend("Attacking....<br />");
} }
if (data.levelup === true) {
playSound("levelup");
} else {
playSound("woosh");
}
resync(); resync();
} else { } else {
playSound("error");
$('#capturebtn').text(data.message); $('#capturebtn').text(data.message);
$('#capturebtn').removeClass('btn-primary'); $('#capturebtn').removeClass('btn-primary');
$('#capturebtn').addClass('btn-warning'); $('#capturebtn').addClass('btn-warning');
$('#place-log').prepend(data.message + "<br />"); $('#place-log').prepend(data.message + "<br />");
resync(); resync();
} }
//alert(data.message);
}).fail(function () { }).fail(function () {
playSound("error");
$('#capturebtn').text("Try that again."); $('#capturebtn').text("Try that again.");
$('#capturebtn').removeClass('btn-primary'); $('#capturebtn').removeClass('btn-primary');
$('#capturebtn').addClass('btn-warning'); $('#capturebtn').addClass('btn-warning');
@ -223,7 +229,13 @@
case 3: case 3:
$('#place-log').prepend("Recharging....<br />"); $('#place-log').prepend("Recharging....<br />");
} }
if (data.levelup === true) {
playSound("levelup");
} else {
playSound("refill");
}
} else { } else {
playSound("error");
$('#refillbtn').text(data.message); $('#refillbtn').text(data.message);
$('#refillbtn').removeClass('btn-primary'); $('#refillbtn').removeClass('btn-primary');
$('#refillbtn').addClass('btn-warning'); $('#refillbtn').addClass('btn-warning');
@ -231,6 +243,7 @@
} }
resync(); resync();
}).fail(function () { }).fail(function () {
playSound("error");
$('#refillbtn').text("Try that again."); $('#refillbtn').text("Try that again.");
$('#refillbtn').removeClass('btn-primary'); $('#refillbtn').removeClass('btn-primary');
$('#refillbtn').addClass('btn-warning'); $('#refillbtn').addClass('btn-warning');
@ -251,16 +264,22 @@
if (data.status === 'OK') { if (data.status === 'OK') {
$('#capturebtn').text(data.message); $('#capturebtn').text(data.message);
$('#place-log').prepend("Claimed!<br />"); $('#place-log').prepend("Claimed!<br />");
if (data.levelup === true) {
playSound("levelup");
} else {
playSound("claim");
}
resync(); resync();
} else { } else {
playSound("error");
$('#capturebtn').text(data.message); $('#capturebtn').text(data.message);
$('#capturebtn').removeClass('btn-primary'); $('#capturebtn').removeClass('btn-primary');
$('#capturebtn').addClass('btn-warning'); $('#capturebtn').addClass('btn-warning');
$('#place-log').prepend(data.message + "<br />"); $('#place-log').prepend(data.message + "<br />");
resync(); resync();
} }
//alert(data.message);
}).fail(function () { }).fail(function () {
playSound("error");
$('#capturebtn').text("Try that again."); $('#capturebtn').text("Try that again.");
$('#capturebtn').removeClass('btn-primary'); $('#capturebtn').removeClass('btn-primary');
$('#capturebtn').addClass('btn-warning'); $('#capturebtn').addClass('btn-warning');

@ -29,6 +29,9 @@
<div class="list-group-item" onclick="toggleMusic()"> <div class="list-group-item" onclick="toggleMusic()">
Turn music <span id="toggle-music-onoff-label">off</span> Turn music <span id="toggle-music-onoff-label">off</span>
</div> </div>
<div class="list-group-item" onclick="toggleSounds()">
Turn sounds <span id="toggle-sounds-onoff-label">off</span>
</div>
<div class='list-group-item' onclick='openscreen("munzeelink")'> <div class='list-group-item' onclick='openscreen("munzeelink")'>
Link with Munzee account Link with Munzee account
<br /> <br />
@ -54,6 +57,11 @@
} else { } else {
$('#toggle-music-onoff-label').text("off"); $('#toggle-music-onoff-label').text("off");
} }
if (localStorage.getItem("sounds") == "mute") {
$('#toggle-sounds-onoff-label').text("on");
} else {
$('#toggle-sounds-onoff-label').text("off");
}
} }
function toggleMusic() { function toggleMusic() {
@ -66,6 +74,15 @@
} }
loadToggles(); loadToggles();
} }
function toggleSounds() {
if (localStorage.getItem("sounds") == "mute") {
localStorage.setItem("sounds", "");
} else {
localStorage.setItem("sounds", "mute");
}
loadToggles();
}
loadToggles(); loadToggles();