diff --git a/app/Game/Client/AudioPlayer.js b/app/Game/Client/AudioPlayer.js new file mode 100644 index 0000000..a43866e --- /dev/null +++ b/app/Game/Client/AudioPlayer.js @@ -0,0 +1,36 @@ +define([ +], + +function () { + + function AudioPlayer(path) { + this.audio = new Audio(path); + this.audio.loop = true; + this.audio.volume = 0.1; + + this.audio.addEventListener('timeupdate', function(){ + var buffer = 1 + if(this.currentTime > this.duration - buffer) { + this.currentTime = 1 + this.play() + } + }, false); + } + + AudioPlayer.prototype.play = function() { + this.audio.play(); + this.doPlay = true; + } + + AudioPlayer.prototype.stop = function() { + this.audio.stop(); + this.doPlay = false; + }; + + AudioPlayer.prototype.destroy = function() { + this.stop(); + }; + + return AudioPlayer; + +}); \ No newline at end of file diff --git a/app/Game/Client/GameController.js b/app/Game/Client/GameController.js index d9cb328..d219c32 100755 --- a/app/Game/Client/GameController.js +++ b/app/Game/Client/GameController.js @@ -11,10 +11,11 @@ define([ "Game/Client/GameObjects/Doll", "Game/Client/View/DomController", "Lib/Utilities/Protocol/Helper", - "Game/Client/Me" + "Game/Client/Me", + "Game/Client/AudioPlayer" ], -function (Parent, Box2D, PhysicsEngine, ViewManager, PlayerController, Nc, requestAnimFrame, Settings, GameObject, Doll, DomController, ProtocolHelper, Me) { +function (Parent, Box2D, PhysicsEngine, ViewManager, PlayerController, Nc, requestAnimFrame, Settings, GameObject, Doll, DomController, ProtocolHelper, Me, AudioPlayer) { if (!window.cancelAnimationFrame) { window.cancelAnimationFrame = function(id) { @@ -28,6 +29,7 @@ function (Parent, Box2D, PhysicsEngine, ViewManager, PlayerController, Nc, reque this.view = ViewManager.createView(); this.me = null; this.animationRequestId = null; + this.audioPlayer = null; Parent.call(this, options); @@ -105,6 +107,9 @@ function (Parent, Box2D, PhysicsEngine, ViewManager, PlayerController, Nc, reque this.onSpawnPlayer(options.spawnedPlayers[i]); } } + + this.audioPlayer = new AudioPlayer(Settings.AUDIO_PATH + "city.mp3"); + this.audioPlayer.play(); }; GameController.prototype.onWorldUpdate = function (updateData) { @@ -266,6 +271,8 @@ function (Parent, Box2D, PhysicsEngine, ViewManager, PlayerController, Nc, reque Parent.prototype.destroy.call(this); + this.audioPlayer.destroy(); + this.view.destroy(); }; diff --git a/app/Game/Config/Settings.js b/app/Game/Config/Settings.js index 8ed08f1..895db8a 100755 --- a/app/Game/Config/Settings.js +++ b/app/Game/Config/Settings.js @@ -21,6 +21,7 @@ define(function() { GRAPHICS_SUBPATH_CHARACTERS: 'Characters/', GRAPHICS_SUBPATH_TILES: 'Tiles/', MAPS_PATH: 'static/maps/tiled/', + AUDIO_PATH: 'static/sounds/', RATIO: 21, //35 // original tile size is 25 but we want it to resize to 20 diff --git a/static/sounds/city.mp3 b/static/sounds/city.mp3 new file mode 100644 index 0000000..6ff3ec2 Binary files /dev/null and b/static/sounds/city.mp3 differ