Update: CC - Snake FS - Entity Loaded (21g30t1e75.js) 164 bytes modified

beta.r3js.org
-=yb4f310 2018-03-12 21:37:49 +01:00
parent 659e69ef09
commit 5b86265f47
1 changed files with 15 additions and 26 deletions

View File

@ -187,35 +187,24 @@ GameLib.CustomCode.prototype.advanceSnake = function(delta) {
var head = this.snake[0].clone();
head.advance();
var snake = this.snake.reduce(
function(result, body, index) {
if ((index + 1) >= this.snake.length) {
/**
* we're done
*/
return result;
} else {
/**
* Move the body over
*/
result.push(this.snake[index + 1]);
}
return result;
}.bind(this),
[head]
)
var oldHead = this.snake.shift();
oldHead.mesh.geometry = null;
oldHead.mesh.materials = null;
oldHead.mesh.remove();
var tail = this.snake.pop();
tail.mesh.geometry = null;
tail.mesh.materials = null;
tail.mesh.remove();
var oldTail = this.snake.pop();
this.snake = snake;
var snake = [head];
this.snake.map(
function(body) {
snake.push(body);
}
);
snake.push(oldTail);
this.snake = snake;
}.bind(this);
/*