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

beta.r3js.org
-=yb4f310 2018-03-22 19:31:24 +01:00
parent 2fff3a0272
commit d7820f070b
1 changed files with 43 additions and 49 deletions

View File

@ -939,6 +939,10 @@ GameLib.CustomCode.prototype.advanceSnake = function(delta) {
} else {
if (this.state.eating === false) {
return;
}
temp = {
position : {
x : body.position.x,
@ -948,26 +952,25 @@ GameLib.CustomCode.prototype.advanceSnake = function(delta) {
flip : body.flip
}
if (this.state.eating === false) {
/**
* Create a new empty object at the current grid position (free it up)
*/
this.grid[body.position.x][body.position.y] = new GameLib.CustomCode.GameObject();
/**
* Create a new empty object at the current grid position (free it up)
*/
this.grid[body.position.x][body.position.y] = new GameLib.CustomCode.GameObject();
/**
* Assign the new location to the body
*/
body.position.x = backup.position.x;
body.position.y = backup.position.y;
body.orientation = backup.orientation;
body.flip = backup.flip;
/**
* Assign the new location to the body
*/
body.position.x = backup.position.x;
body.position.y = backup.position.y;
body.orientation = backup.orientation;
body.flip = backup.flip;
/**
* Update the grid with our new body
*/
this.grid[body.position.x][body.position.y] = body;
}
/**
* Update the grid with our new body
*/
this.grid[body.position.x][body.position.y] = body;
if (body.backupMesh) {
/**
@ -991,51 +994,42 @@ GameLib.CustomCode.prototype.advanceSnake = function(delta) {
body.mesh.updateInstance('position');
}
if (backup.orientation !== temp.orientation) {
if (body.orientation !== temp.orientation) {
// if ((index ) < this.snake.length) {
/**
* Our orientation changed - we should make a corner
*/
body.orientation = temp.orientation;
body.orientation = temp.orientation;
body.applyToMesh();
body.applyToMesh();
body.orientation = backup.orientation;
body.orientation = backup.orientation;
body.backupMesh = body.mesh;
body.backupMesh = body.mesh;
if (temp.orientation === GameLib.CustomCode.ORIENTATION_UP) {
body.backupMesh.position.y -= 0.5 * GameLib.CustomCode.BODY_SCALE_Y;
}
if (temp.orientation === GameLib.CustomCode.ORIENTATION_UP) {
body.backupMesh.position.y -= 0.5 * GameLib.CustomCode.BODY_SCALE_Y;
}
if (temp.orientation === GameLib.CustomCode.ORIENTATION_DOWN) {
body.backupMesh.position.y += 0.5 * GameLib.CustomCode.BODY_SCALE_Y;
}
if (temp.orientation === GameLib.CustomCode.ORIENTATION_DOWN) {
body.backupMesh.position.y += 0.5 * GameLib.CustomCode.BODY_SCALE_Y;
}
if (temp.orientation === GameLib.CustomCode.ORIENTATION_LEFT) {
body.backupMesh.position.x += 0.5 * GameLib.CustomCode.BODY_SCALE_X;
}
if (temp.orientation === GameLib.CustomCode.ORIENTATION_LEFT) {
body.backupMesh.position.x += 0.5 * GameLib.CustomCode.BODY_SCALE_X;
}
if (temp.orientation === GameLib.CustomCode.ORIENTATION_RIGHT) {
body.backupMesh.position.x -= 0.5 * GameLib.CustomCode.BODY_SCALE_X;
}
if (temp.orientation === GameLib.CustomCode.ORIENTATION_RIGHT) {
body.backupMesh.position.x -= 0.5 * GameLib.CustomCode.BODY_SCALE_X;
}
//body.backupMesh.visible = false;
//body.backupMesh.updateInstance('visible');
body.mesh = this.createGameMesh(this.materialBreadCorner);
body.mesh = this.createGameMesh(this.materialBreadCorner);
body.mesh.position.z = 5;
body.mesh.position.z = 5;
body.mesh.updateInstance('position');
body.mesh.updateInstance('position');
body.mesh.visible = true;
body.mesh.updateInstance('visible');
//}
body.mesh.visible = true;
body.mesh.updateInstance('visible');
}
backup = temp;