diff --git a/21g30t1e75.js b/21g30t1e75.js index 94afea8..eb469fa 100644 --- a/21g30t1e75.js +++ b/21g30t1e75.js @@ -237,30 +237,49 @@ GameLib.CustomCode.prototype.advanceSnake = function(delta) { return; } + var backup = null; + var temp = null; + this.snake.map( function(body, index) { if (index === 0) { + + backup = { + position : { + x : body.position.x, + y : body.position.y + }, + orientation : body.orientation + } + body.advance( this.state.orientation ); } - - if (index + 1 <= this.snake.length) { + + if (index > 0) { + + temp = { + position : { + x : body.position.x, + y : body.position.y + }, + orientation : body.orientation + } - this.snake[index+1].orientation = body.orientation; - this.snake[index+1].position.x = body.position.x; - this.snake[index+1].position.y = body.position.y; - + body.position.x = backup.position.x; + body.position.y = backup.position.y; + body.orientation = backup.orientation; + backup = temp; } - body.applyToMesh(); - + }.bind(this) ) - + return; }.bind(this);