diff options
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); |