From 28913a2f8c6ee59cd418da944ff4a339fb4e520b Mon Sep 17 00:00:00 2001 From: clb92 Date: Tue, 5 Jul 2016 22:44:53 +0200 Subject: [PATCH] Snake now mirrors correctly in based on grid instead of canvas size. --- js/game.class.js | 6 ------ js/snake.class.js | 18 ++++++++---------- 2 files changed, 8 insertions(+), 16 deletions(-) diff --git a/js/game.class.js b/js/game.class.js index 0184d99..540b9ca 100644 --- a/js/game.class.js +++ b/js/game.class.js @@ -95,31 +95,25 @@ Game.prototype.applyEffect = function(effect) { console.log("Effect pickup: " + effect); switch (effect) { case ('food'): - console.log("food"); this.score++; this.snake.embiggen(1); break; case ('death'): - console.log("death"); this.end(); break; case ('faster'): - console.log("faster"); this.speedModifier = 1.7; this.effects.speedChange = 180; break; case ('slower'): - console.log("slower"); this.speedModifier = .6; this.effects.speedChange = 100; break; case ('bonus'): - console.log("bonus"); this.score = this.score + 15; this.snake.embiggen(6); break; } - console.log(this); } Game.prototype.end = function() { diff --git a/js/snake.class.js b/js/snake.class.js index 98c7a7b..26e56c2 100644 --- a/js/snake.class.js +++ b/js/snake.class.js @@ -51,22 +51,20 @@ Snake.prototype.move = function() { var newX = this.locations[0][0] + 1; var newY = this.locations[0][1]; break; - default: - break; } this.previousDirection = this.nextDirection; - if (newX > this.game.canvas.width) { - newX = 1; + if (newX >= this.game.grid.width) { + newX = 0; } - if (newX < this.game.canvas.width) { - newX = this.game.canvas.width - 1; + if (newX < 0) { + newX = this.game.grid.width - 1; } - if (newY > this.game.canvas.height) { - newY = 1; + if (newY >= this.game.grid.height) { + newY = 0; } - if (newY < this.game.canvas.height) { - newY = this.game.canvas.height - 1; + if (newY < 0) { + newY = this.game.grid.height - 1; } var effect = this.game.resources.checkLocation(newX, newY);