From 7d99c088284dbb3bb8de3fc65836c0bb69102fc7 Mon Sep 17 00:00:00 2001 From: Justin Worthe Date: Sat, 2 Aug 2014 20:36:37 +0200 Subject: Added om-nom sound effects --- assets/audio/nom.ogg | Bin 0 -> 16556 bytes assets/audio/om.ogg | Bin 0 -> 13620 bytes game/prefabs/player.js | 23 +++++++++++++++++++++-- game/states/play.js | 15 ++++++++++++--- game/states/preload.js | 4 ++++ 5 files changed, 37 insertions(+), 5 deletions(-) create mode 100644 assets/audio/nom.ogg create mode 100644 assets/audio/om.ogg diff --git a/assets/audio/nom.ogg b/assets/audio/nom.ogg new file mode 100644 index 0000000..350d117 Binary files /dev/null and b/assets/audio/nom.ogg differ diff --git a/assets/audio/om.ogg b/assets/audio/om.ogg new file mode 100644 index 0000000..2bb4115 Binary files /dev/null and b/assets/audio/om.ogg differ diff --git a/game/prefabs/player.js b/game/prefabs/player.js index 95ea761..df991b2 100644 --- a/game/prefabs/player.js +++ b/game/prefabs/player.js @@ -1,6 +1,8 @@ 'use strict'; -var Player = function(game, x, y, key, frame) { +var Player = function(game, x, y, key, frame, soundKey) { + var player = this; + Phaser.Sprite.call(this, game, x, y, key, frame); this.animations.add('active', [0]); this.animations.add('waiting', [1]); @@ -9,12 +11,29 @@ var Player = function(game, x, y, key, frame) { this.moving = false; this.scale = {x: 0.01, y: 0.01}; this.anchor = {x: 0.5, y: 0.5}; - + this.game.physics.arcade.enableBody(this); this.score = 0; + this.maxScore = 1; this.isMyTurn = false; this.animIsMyTurn = true; + + this.scoreSound = game.sound.add(soundKey); + + + //BEWARE! HORRIBLE HACK AHEAD! + //Intercepts the call to get a new buffer so that we can set the playbackRate. + var audioContext = this.scoreSound.context; + var childContext = Object.create(audioContext); + this.scoreSound.context = childContext; + + childContext.createBufferSource = function() { + var source = audioContext.createBufferSource(); + var scoreFraction = player.score / player.maxScore; + source.playbackRate.value = 0.75 + scoreFraction*6; + return source; + } }; Player.prototype = Object.create(Phaser.Sprite.prototype); diff --git a/game/states/play.js b/game/states/play.js index 6ea7611..1b59596 100644 --- a/game/states/play.js +++ b/game/states/play.js @@ -127,7 +127,6 @@ Play.prototype = { var levelText = this.game.cache.getText('level'); var splitRows = levelText.split('\n'); - for (var x=0; x