summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJustin Worthe <justin.worthe@gmail.com>2014-08-02 20:36:37 +0200
committerJustin Worthe <justin.worthe@gmail.com>2014-08-02 20:36:37 +0200
commit7d99c088284dbb3bb8de3fc65836c0bb69102fc7 (patch)
tree07fef14f88990dca78a5e83b0dca8bef757b9833
parent4f29b497e772d5cb9dd818c00adab8f634f5e7ad (diff)
Added om-nom sound effects
-rw-r--r--assets/audio/nom.oggbin0 -> 16556 bytes
-rw-r--r--assets/audio/om.oggbin0 -> 13620 bytes
-rw-r--r--game/prefabs/player.js23
-rw-r--r--game/states/play.js15
-rw-r--r--game/states/preload.js4
5 files changed, 37 insertions, 5 deletions
diff --git a/assets/audio/nom.ogg b/assets/audio/nom.ogg
new file mode 100644
index 0000000..350d117
--- /dev/null
+++ b/assets/audio/nom.ogg
Binary files differ
diff --git a/assets/audio/om.ogg b/assets/audio/om.ogg
new file mode 100644
index 0000000..2bb4115
--- /dev/null
+++ b/assets/audio/om.ogg
Binary files 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<splitRows.length; x++) {
for (var y=0; y<splitRows[x].length; y++) {
switch(splitRows[x][y]) {
@@ -141,17 +140,26 @@ Play.prototype = {
this.pills.add(new BonusPill(this.game, x, y));
break;
case 'A':
- this.playerA = new Player(this.game, x, y, 'player-a', 0);
+ this.playerA = new Player(this.game, x, y, 'player-a', 0, 'omSound');
this.players.add(this.playerA);
break;
case 'B':
- this.playerB = new Player(this.game, x, y, 'player-b', 0);
+ this.playerB = new Player(this.game, x, y, 'player-b', 0, 'nomSound');
this.players.add(this.playerB);
break;
}
}
}
+ var maxScore = 0;
+ this.pills.forEach(function(pill) {
+ maxScore += pill.score;
+ }, this);
+
+ this.players.forEach(function(player) {
+ player.maxScore = maxScore;
+ }, this);
+
this.walls.forEach(function(wall) {
this.addToMap(wall.x, wall.y);
}, this);
@@ -209,6 +217,7 @@ Play.prototype = {
playerPillCollision: function(player, pill) {
player.score += pill.score;
pill.destroy();
+ player.scoreSound.play();
this.playerAScoreText.setText(this.playerA.score+'');
this.playerBScoreText.setText(this.playerB.score+'');
diff --git a/game/states/preload.js b/game/states/preload.js
index 0797077..4e13679 100644
--- a/game/states/preload.js
+++ b/game/states/preload.js
@@ -20,9 +20,13 @@ Preload.prototype = {
this.load.bitmapFont('spaced-scorefont-a', 'assets/fonts/scorefont-a.png', 'assets/fonts/scorefont.fnt', undefined, 10);
this.load.bitmapFont('scorefont-a', 'assets/fonts/scorefont-a.png', 'assets/fonts/scorefont.fnt');
+ this.load.audio('omSound', 'assets/audio/om.ogg', true);
this.load.bitmapFont('spaced-scorefont-b', 'assets/fonts/scorefont-b.png', 'assets/fonts/scorefont.fnt', undefined, 10);
this.load.bitmapFont('scorefont-b', 'assets/fonts/scorefont-b.png', 'assets/fonts/scorefont.fnt');
+ this.load.audio('nomSound', 'assets/audio/nom.ogg', true);
+
+
this.load.text('level', 'assets/levels/maze.lvl');
},