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

beta.r3js.org
-=yb4f310 2018-03-20 14:29:47 +01:00
parent 9842a2799a
commit 500a20721e
1 changed files with 43 additions and 16 deletions

View File

@ -220,22 +220,49 @@ GameLib.CustomCode.SnakeBody.prototype.applyToMesh = function() {
GameLib.CustomCode.SnakeBody.prototype.advance = function(orientation, flip) {
if (orientation === GameLib.CustomCode.ORIENTATION_UP) {
this.position.y += 1;
}
if (orientation === GameLib.CustomCode.ORIENTATION_DOWN) {
this.position.y -= 1;
}
if (orientation === GameLib.CustomCode.ORIENTATION_LEFT) {
this.position.x -= 1;
}
if (orientation === GameLib.CustomCode.ORIENTATION_RIGHT) {
this.position.x += 1;
}
var crash = false;
switch (orientation) {
case GameLib.CustomCode.ORIENTATION_UP :
if ((this.position.y + 1) > GameLib.CustomCode.GRID_HEIGHT) {
crash = true;
} else {
this.position.y += 1;
}
break;
case GameLib.CustomCode.ORIENTATION_DOWN :
if ((this.position.y - 1) < 0) {
crash = true;
} else {
this.position.y -= 1;
}
break;
case GameLib.CustomCode.ORIENTATION_LEFT :
if ((this.position.x - 1) < 0) {
crash = true;
} else {
this.position.x -= 1;
}
break;
case GameLib.CustomCode.ORIENTATION_RIGHT :
if ((this.position.x + 1) > GameLib.CustomCode.GRID_WIDTH) {
crash = true;
} else {
this.position.x += 1;
}
break;
default :
console.warn('unknown orientation');
break;
}
if (!crash) {
console.log('check against body');
} else {
console.log('crashed!');
}
this.orientation = orientation;
this.flip = flip;