Skip to content

Instantly share code, notes, and snippets.

@dsetzer
Last active May 10, 2020 13:28
Show Gist options
  • Save dsetzer/17aa190311197677fe6e2048f4d7f78b to your computer and use it in GitHub Desktop.
Save dsetzer/17aa190311197677fe6e2048f4d7f78b to your computer and use it in GitHub Desktop.
/**
* BustabitAudio class
*/
(function () {
window.BustabitAudio = function () {
this.audio = {
won: new Audio("https://www.soundjay.com/misc/small-bell-ring-01a.mp3"),
lost: new Audio("http://www.freesfx.co.uk/rx2/mp3s/5/16873_1461333020.mp3")
};
this.audio.won.volume = 0.5;
this.audio.lost.volume = 1;
engine.on('game_crash', this._onGameCrash, this);
engine.on('cashed_out', this._onCashedOut, this);
};
BustabitAudio.prototype.play = function (name) {
if (this.audio[name]) this.audio[name].play();
};
BustabitAudio.prototype.playURL = function (url, volume=1) {
var audio = new Audio(url);
audio.volume = volume;
audio.play();
};
BustabitAudio.prototype._onGameCrash = function (data) {
if (engine.lastGamePlay() == 'LOST') {
this.play('lost');
}
};
BustabitAudio.prototype._onCashedOut = function (data) {
if (data.username == engine.getUsername()) {
this.play('won');
}
};
}) ();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment