diff --git a/21g30t1e75.js b/21g30t1e75.js index 210761a..197a228 100644 --- a/21g30t1e75.js +++ b/21g30t1e75.js @@ -187,26 +187,20 @@ GameLib.CustomCode.prototype.advanceSnake = function(delta) { var head = this.snake[0].clone(); head.advance(); - this.snake = this.snake.reduce( + var snake = this.snake.reduce( function(result, body, index) { - if ((index + 1) === this.snake.length) { + if ((index + 1) >= this.snake.length) { /** * we're done */ return result; - } else if ((index) === this.snake.length) { - /** - * Pop it - */ - this.snake[index].mesh.geometry = null; - this.snake[index].mesh.materials = null; - this.snake[index].mesh.remove(); + } else { /** * Move the body over */ - result.push(this.snake[index]); + result.push(this.snake[index + 1]); } return result; @@ -215,6 +209,11 @@ GameLib.CustomCode.prototype.advanceSnake = function(delta) { [head] ) + var tail = this.snake.pop(); + tail.mesh.geometry = null; + tail.mesh.materials = null; + tail.mesh.remove(); + }.bind(this); /*