More small changes

This commit is contained in:
clb92
2016-07-06 04:15:13 +02:00
parent cede8d45cb
commit 1d1ccf30d7
3 changed files with 25 additions and 2 deletions

View File

@@ -15,11 +15,15 @@ var Canvas = function(game, canvasId) {
Canvas.prototype.drawAll = function() { Canvas.prototype.drawAll = function() {
for (var h = 0; h < this.game.grid.height; h++) { for (var h = 0; h < this.game.grid.height; h++) {
for (var w = 0; w < this.game.grid.width; w++) { for (var w = 0; w < this.game.grid.width; w++) {
// this.context.shadowBlur = 0;
// this.context.shadowColor = this.color;
this.context.fillStyle = this.color; this.context.fillStyle = this.color;
this.context.fillRect(w * this.game.gridSize, h * this.game.gridSize, this.game.gridSize, this.game.gridSize); this.context.fillRect(w * this.game.gridSize, h * this.game.gridSize, this.game.gridSize, this.game.gridSize);
for (var i in this.game.snake.locations) { for (var i in this.game.snake.locations) {
if (this.game.snake.locations[i][0] === w && this.game.snake.locations[i][1] === h) { if (this.game.snake.locations[i][0] === w && this.game.snake.locations[i][1] === h) {
// this.context.shadowBlur = 60;
// this.context.shadowColor = "purple";
this.context.fillStyle = "purple"; this.context.fillStyle = "purple";
this.context.fillRect(w * this.game.gridSize, h * this.game.gridSize, this.game.gridSize, this.game.gridSize); this.context.fillRect(w * this.game.gridSize, h * this.game.gridSize, this.game.gridSize, this.game.gridSize);
} }
@@ -31,27 +35,43 @@ Canvas.prototype.drawAll = function() {
Canvas.prototype.setTile = function(type, x, y) { Canvas.prototype.setTile = function(type, x, y) {
switch (type) { switch (type) {
case ('board'): case ('board'):
// this.context.shadowBlur = 0;
// this.context.shadowColor = this.color;
this.context.fillStyle = this.color; this.context.fillStyle = this.color;
break; break;
case ('snake'): case ('snake'):
// this.context.shadowBlur = 60;
// this.context.shadowColor = "purple";
this.context.fillStyle = "purple"; this.context.fillStyle = "purple";
break; break;
case ('food'): case ('food'):
// this.context.shadowBlur = 60;
// this.context.shadowColor = "green";
this.context.fillStyle = "green"; this.context.fillStyle = "green";
break; break;
case ('death'): case ('death'):
// this.context.shadowBlur = 60;
// this.context.shadowColor = "red";
this.context.fillStyle = "red"; this.context.fillStyle = "red";
break; break;
case ('faster'): case ('faster'):
// this.context.shadowBlur = 60;
// this.context.shadowColor = "#708BF4";
this.context.fillStyle = "#708BF4"; this.context.fillStyle = "#708BF4";
break; break;
case ('slower'): case ('slower'):
// this.context.shadowBlur = 60;
// this.context.shadowColor = "#3135C4";
this.context.fillStyle = "#3135C4"; this.context.fillStyle = "#3135C4";
break; break;
case ('bonus'): case ('bonus'):
// this.context.shadowBlur = 60;
// this.context.shadowColor = "gold";
this.context.fillStyle = "gold"; this.context.fillStyle = "gold";
break; break;
default: default:
// this.context.shadowBlur = 0;
// this.context.shadowColor = this.color;
this.context.fillStyle = this.color; this.context.fillStyle = this.color;
break; break;
} }
@@ -59,6 +79,8 @@ Canvas.prototype.setTile = function(type, x, y) {
} }
Canvas.prototype.prep = function() { Canvas.prototype.prep = function() {
// this.context.shadowBlur = 0;
// this.context.shadowColor = this.color;
this.context.fillStyle = this.color; this.context.fillStyle = this.color;
this.context.fillRect(0, 0, this.canvas.width, this.canvas.height); this.context.fillRect(0, 0, this.canvas.width, this.canvas.height);
} }

View File

@@ -92,7 +92,7 @@ Resources.prototype.despawnDrop = function(i) {
this.locations.splice(i, 1); this.locations.splice(i, 1);
} }
Resources.prototype.removeDrop = function(x, y, despawn = false) { Resources.prototype.removeDrop = function(x, y) {
for (var i = 0; i < this.locations.length; i++) { for (var i = 0; i < this.locations.length; i++) {
if (this.locations[i][0] === x) { if (this.locations[i][0] === x) {
for (var i = 0; i < this.locations.length; i++) { for (var i = 0; i < this.locations.length; i++) {

View File

@@ -13,7 +13,7 @@ var Snake = function(game) {
} }
} }
Snake.prototype.changeDirection = function(direction = '') { Snake.prototype.changeDirection = function(direction) {
if (direction !== '') { if (direction !== '') {
switch (this.previousDirection) { switch (this.previousDirection) {
case ('up'): case ('up'):
@@ -91,6 +91,7 @@ Snake.prototype.move = function() {
} }
this.locations.unshift([newX, newY]); this.locations.unshift([newX, newY]);
this.game.canvas.setTile('snake', this.locations[0][0], this.locations[0][1]); this.game.canvas.setTile('snake', this.locations[0][0], this.locations[0][1]);
} }
} }