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

beta.r3js.org
-=yb4f310 2018-03-19 08:29:24 +01:00
parent a0a9c72e5f
commit 0f00831ae4
1 changed files with 119 additions and 123 deletions

View File

@ -69,7 +69,8 @@ this.advanceTime = 0;
*/ */
this.state = { this.state = {
orientation : 0, orientation : 0,
turning : false turning : false,
flip : false
}; };
GameLib.CustomCode.prototype.createMaterial = function(image) { GameLib.CustomCode.prototype.createMaterial = function(image) {
@ -126,16 +127,14 @@ this.meshPatty = this.createGameMesh(this.imagePatty);
* @param mesh * @param mesh
* @param position * @param position
* @param orientation * @param orientation
* @param bodyType * @param flip
* @param backup
* @constructor * @constructor
*/ */
GameLib.CustomCode.SnakeBody = function( GameLib.CustomCode.SnakeBody = function(
mesh, mesh,
position, position,
orientation, orientation,
bodyType, flip
backup
) { ) {
if (GameLib.Utils.UndefinedOrNull(mesh)) { if (GameLib.Utils.UndefinedOrNull(mesh)) {
@ -157,51 +156,49 @@ GameLib.CustomCode.SnakeBody = function(
} }
this.orientation = orientation; this.orientation = orientation;
if (GameLib.Utils.UndefinedOrNull(bodyType)) { if (GameLib.Utils.UndefinedOrNull(flip)) {
bodyType = GameLib.CustomCode.BODY_TYPE_NORMAL; flip = false;
} }
this.bodyType = bodyType; this.flip = flip;
if (GameLib.Utils.UndefinedOrNull(backup)) { this.applyToMesh(flip);
backup = null;
}
this.backup = backup;
this.applyToMesh();
}; };
GameLib.CustomCode.SnakeBody.prototype.restoreBackup = function() { // GameLib.CustomCode.SnakeBody.prototype.restoreBackup = function() {
//
// if (!this.backup) {
// console.warn('no backup to restore');
// return;
// }
//
// this.mesh.geometry = null;
// this.mesh.materials = null;
// this.mesh.remove();
//
// this.mesh = this.backup.mesh;
// this.mesh.visible = true;
// this.mesh.updateInstance('visible');
//
// this.orientation = this.backup.orientation;
//
// this.backup = null;
//
// /**
// * We don't restore the position because the position will have changed
// */
// }
if (!this.backup) { GameLib.CustomCode.SnakeBody.prototype.applyToMesh = function(flip) {
console.warn('no backup to restore');
return;
}
this.mesh.geometry = null;
this.mesh.materials = null;
this.mesh.remove();
this.mesh = this.backup.mesh;
this.mesh.visible = true;
this.mesh.updateInstance('visible');
this.orientation = this.backup.orientation;
this.bodyType = this.backup.bodyType;
this.backup = null;
/**
* We don't restore the position because the position will have changed
*/
}
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;
this.mesh.rotation.z = this.orientation * Math.PI / 2; this.mesh.rotation.z = this.orientation * Math.PI / 2;
if (flip) {
this.mesh.rotation.z += Math.PI / 2;
}
/** /**
* TODO: We don't update instance position - animation should do this * TODO: We don't update instance position - animation should do this
*/ */
@ -321,7 +318,7 @@ GameLib.CustomCode.prototype.advanceSnake = function(delta) {
backup = temp; backup = temp;
} }
body.applyToMesh(); body.applyToMesh(this.state.flip);
}.bind(this) }.bind(this)
) )
@ -400,8 +397,7 @@ GameLib.Event.Subscribe(
x : 4, x : 4,
y : 1 y : 1
}, },
0, 0
GameLib.CustomCode.BODY_TYPE_TAIL
) )
]; ];
@ -410,13 +406,13 @@ 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();
} }
); );
} }
); );