diff options
author | Justin Worthe <justin.worthe@gmail.com> | 2014-08-02 20:36:37 +0200 |
---|---|---|
committer | Justin Worthe <justin.worthe@gmail.com> | 2014-08-02 20:36:37 +0200 |
commit | 7d99c088284dbb3bb8de3fc65836c0bb69102fc7 (patch) | |
tree | 07fef14f88990dca78a5e83b0dca8bef757b9833 /game/prefabs/player.js | |
parent | 4f29b497e772d5cb9dd818c00adab8f634f5e7ad (diff) |
Added om-nom sound effects
Diffstat (limited to 'game/prefabs/player.js')
-rw-r--r-- | game/prefabs/player.js | 23 |
1 files changed, 21 insertions, 2 deletions
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); |