mirror of
https://github.com/clb92/simple-js-snake.git
synced 2025-12-06 01:32:03 +01:00
Snake now mirrors correctly in based on grid instead of canvas size.
This commit is contained in:
@@ -95,31 +95,25 @@ Game.prototype.applyEffect = function(effect) {
|
|||||||
console.log("Effect pickup: " + effect);
|
console.log("Effect pickup: " + effect);
|
||||||
switch (effect) {
|
switch (effect) {
|
||||||
case ('food'):
|
case ('food'):
|
||||||
console.log("food");
|
|
||||||
this.score++;
|
this.score++;
|
||||||
this.snake.embiggen(1);
|
this.snake.embiggen(1);
|
||||||
break;
|
break;
|
||||||
case ('death'):
|
case ('death'):
|
||||||
console.log("death");
|
|
||||||
this.end();
|
this.end();
|
||||||
break;
|
break;
|
||||||
case ('faster'):
|
case ('faster'):
|
||||||
console.log("faster");
|
|
||||||
this.speedModifier = 1.7;
|
this.speedModifier = 1.7;
|
||||||
this.effects.speedChange = 180;
|
this.effects.speedChange = 180;
|
||||||
break;
|
break;
|
||||||
case ('slower'):
|
case ('slower'):
|
||||||
console.log("slower");
|
|
||||||
this.speedModifier = .6;
|
this.speedModifier = .6;
|
||||||
this.effects.speedChange = 100;
|
this.effects.speedChange = 100;
|
||||||
break;
|
break;
|
||||||
case ('bonus'):
|
case ('bonus'):
|
||||||
console.log("bonus");
|
|
||||||
this.score = this.score + 15;
|
this.score = this.score + 15;
|
||||||
this.snake.embiggen(6);
|
this.snake.embiggen(6);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
console.log(this);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Game.prototype.end = function() {
|
Game.prototype.end = function() {
|
||||||
|
|||||||
@@ -51,22 +51,20 @@ Snake.prototype.move = function() {
|
|||||||
var newX = this.locations[0][0] + 1;
|
var newX = this.locations[0][0] + 1;
|
||||||
var newY = this.locations[0][1];
|
var newY = this.locations[0][1];
|
||||||
break;
|
break;
|
||||||
default:
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
this.previousDirection = this.nextDirection;
|
this.previousDirection = this.nextDirection;
|
||||||
|
|
||||||
if (newX > this.game.canvas.width) {
|
if (newX >= this.game.grid.width) {
|
||||||
newX = 1;
|
newX = 0;
|
||||||
}
|
}
|
||||||
if (newX < this.game.canvas.width) {
|
if (newX < 0) {
|
||||||
newX = this.game.canvas.width - 1;
|
newX = this.game.grid.width - 1;
|
||||||
}
|
}
|
||||||
if (newY > this.game.canvas.height) {
|
if (newY >= this.game.grid.height) {
|
||||||
newY = 1;
|
newY = 0;
|
||||||
}
|
}
|
||||||
if (newY < this.game.canvas.height) {
|
if (newY < 0) {
|
||||||
newY = this.game.canvas.height - 1;
|
newY = this.game.grid.height - 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
var effect = this.game.resources.checkLocation(newX, newY);
|
var effect = this.game.resources.checkLocation(newX, newY);
|
||||||
|
|||||||
Reference in New Issue
Block a user