Sounds are now played in the the game

This commit is contained in:
clb92
2016-07-05 23:28:44 +02:00
parent abe4fbc32f
commit 417c5d05fc

View File

@@ -20,6 +20,14 @@ var Game = function() {
width: 0, width: 0,
height: 0 height: 0
}; };
this.sounds = {
food: new Audio("audio/food.wav"),
bonus: new Audio("audio/bonus.wav"),
death: new Audio("audio/death3.wav"),
speedUp: new Audio("audio/speedUp.wav"),
speedDown: new Audio("audio/speedDown.wav"),
pause: new Audio("audio/pause.wav")
}
this.canvas = new Canvas(this, "gameCanvas"); this.canvas = new Canvas(this, "gameCanvas");
this.initGrid(); this.initGrid();
this.snake = new Snake(this); this.snake = new Snake(this);
@@ -77,6 +85,7 @@ Game.prototype.update = function() {
Game.prototype.togglePause = function() { Game.prototype.togglePause = function() {
this.paused = (this.paused ? false : true); this.paused = (this.paused ? false : true);
this.sounds.pause.play();
if (this.paused) { if (this.paused) {
//clearInterval(this.gameLoop); //clearInterval(this.gameLoop);
this.canvas.canvas.style.filter = "blur(40px)"; this.canvas.canvas.style.filter = "blur(40px)";
@@ -95,21 +104,26 @@ Game.prototype.applyEffect = function(effect) {
console.log("Effect pickup: " + effect); console.log("Effect pickup: " + effect);
switch (effect) { switch (effect) {
case ('food'): case ('food'):
this.sounds.food.play();
this.score++; this.score++;
this.snake.embiggen(1); this.snake.embiggen(1);
break; break;
case ('death'): case ('death'):
this.sounds.death.play();
this.end(); this.end();
break; break;
case ('faster'): case ('faster'):
this.sounds.speedUp.play();
this.speedModifier = 1.7; this.speedModifier = 1.7;
this.effects.speedChange = 180; this.effects.speedChange = 180;
break; break;
case ('slower'): case ('slower'):
this.sounds.speedDown.play();
this.speedModifier = .6; this.speedModifier = .6;
this.effects.speedChange = 100; this.effects.speedChange = 100;
break; break;
case ('bonus'): case ('bonus'):
this.sounds.bonus.play();
this.score = this.score + 15; this.score = this.score + 15;
this.snake.embiggen(6); this.snake.embiggen(6);
break; break;