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

beta.r3js.org
-=yb4f310 2018-03-19 10:08:33 +01:00
parent 1a381dc930
commit df847e3fe2
1 changed files with 28 additions and 21 deletions

View File

@ -167,8 +167,8 @@ GameLib.CustomCode.SnakeBody = function(
backupMesh = null; backupMesh = null;
} }
this.backupMesh = backupMesh; this.backupMesh = backupMesh;
this.applyToMesh(flip); this.applyToMesh();
}; };
// GameLib.CustomCode.SnakeBody.prototype.restoreBackup = function() { // GameLib.CustomCode.SnakeBody.prototype.restoreBackup = function() {
@ -195,7 +195,7 @@ GameLib.CustomCode.SnakeBody = function(
// */ // */
// } // }
GameLib.CustomCode.SnakeBody.prototype.applyToMesh = function(flip) { GameLib.CustomCode.SnakeBody.prototype.applyToMesh = function() {
this.mesh.position.x = this.position.x + GameLib.CustomCode.GRID_OFFSET_X; this.mesh.position.x = this.position.x + GameLib.CustomCode.GRID_OFFSET_X;
this.mesh.position.y = this.position.y + GameLib.CustomCode.GRID_OFFSET_Y; this.mesh.position.y = this.position.y + GameLib.CustomCode.GRID_OFFSET_Y;
@ -203,7 +203,7 @@ GameLib.CustomCode.SnakeBody.prototype.applyToMesh = function(flip) {
this.mesh.rotation.z = this.orientation * Math.PI / 2; this.mesh.rotation.z = this.orientation * Math.PI / 2;
if (this.backupMesh) { if (this.backupMesh) {
this.mesh.rotation.z += ((Math.PI / 2) * flip); this.mesh.rotation.z += ((Math.PI / 2) * this.flip);
} }
/** /**
@ -213,7 +213,7 @@ GameLib.CustomCode.SnakeBody.prototype.applyToMesh = function(flip) {
this.mesh.updateInstance('rotation'); this.mesh.updateInstance('rotation');
} }
GameLib.CustomCode.SnakeBody.prototype.advance = function(orientation) { GameLib.CustomCode.SnakeBody.prototype.advance = function(orientation, flip) {
if (orientation === GameLib.CustomCode.ORIENTATION_UP) { if (orientation === GameLib.CustomCode.ORIENTATION_UP) {
this.position.y += 1; this.position.y += 1;
@ -232,6 +232,8 @@ GameLib.CustomCode.SnakeBody.prototype.advance = function(orientation) {
} }
this.orientation = orientation; this.orientation = orientation;
this.flip = flip;
} }
GameLib.CustomCode.prototype.advanceSnake = function(delta) { GameLib.CustomCode.prototype.advanceSnake = function(delta) {
@ -258,14 +260,17 @@ GameLib.CustomCode.prototype.advanceSnake = function(delta) {
x : body.position.x, x : body.position.x,
y : body.position.y y : body.position.y
}, },
orientation : body.orientation orientation : body.orientation,
flip : body.flip
} }
body.advance( body.advance(
this.state.orientation this.state.orientation,
this.state.flip
); );
backup.orientation = body.orientation; backup.orientation = body.orientation;
backup.flip = body.flip;
} }
if (index > 0) { if (index > 0) {
@ -275,15 +280,17 @@ GameLib.CustomCode.prototype.advanceSnake = function(delta) {
x : body.position.x, x : body.position.x,
y : body.position.y y : body.position.y
}, },
orientation : body.orientation orientation : body.orientation,
flip : body.flip
} }
body.position.x = backup.position.x; body.position.x = backup.position.x;
body.position.y = backup.position.y; body.position.y = backup.position.y;
body.orientation = backup.orientation; body.orientation = backup.orientation;
body.flip = backup.flip;
backup = temp; backup = temp;
if (body.backupMesh) { if (body.backupMesh) {
/** /**
* We used to be a corner, change back * We used to be a corner, change back
@ -319,14 +326,14 @@ GameLib.CustomCode.prototype.advanceSnake = function(delta) {
body.backupMesh.updateInstance('visible'); body.backupMesh.updateInstance('visible');
body.mesh = this.meshBreadCorner.clone(); body.mesh = this.meshBreadCorner.clone();
} }
//body.orientation = this.snake[index - 1].orientation; //body.orientation = this.snake[index - 1].orientation;
} }
} }
body.applyToMesh(this.state.flip); body.applyToMesh();
}.bind(this) }.bind(this)
) )
@ -415,11 +422,11 @@ GameLib.Event.Subscribe(
this.grid.map( this.grid.map(
function(x) { function(x) {
x.map( x.map(
function(y) { function(y) {
y.mesh.geometry = null; y.mesh.geometry = null;
y.mesh.materials = null; y.mesh.materials = null;
y.mesh.remove(); y.mesh.remove();
} }
); );
} }
); );