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 = {
orientation : 0,
turning : false
turning : false,
flip : false
};
GameLib.CustomCode.prototype.createMaterial = function(image) {
@ -126,16 +127,14 @@ this.meshPatty = this.createGameMesh(this.imagePatty);
* @param mesh
* @param position
* @param orientation
* @param bodyType
* @param backup
* @param flip
* @constructor
*/
GameLib.CustomCode.SnakeBody = function(
mesh,
position,
orientation,
bodyType,
backup
flip
) {
if (GameLib.Utils.UndefinedOrNull(mesh)) {
@ -157,51 +156,49 @@ GameLib.CustomCode.SnakeBody = function(
}
this.orientation = orientation;
if (GameLib.Utils.UndefinedOrNull(bodyType)) {
bodyType = GameLib.CustomCode.BODY_TYPE_NORMAL;
if (GameLib.Utils.UndefinedOrNull(flip)) {
flip = false;
}
this.bodyType = bodyType;
this.flip = flip;
if (GameLib.Utils.UndefinedOrNull(backup)) {
backup = null;
}
this.backup = backup;
this.applyToMesh();
this.applyToMesh(flip);
};
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) {
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() {
GameLib.CustomCode.SnakeBody.prototype.applyToMesh = function(flip) {
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.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
*/
@ -321,7 +318,7 @@ GameLib.CustomCode.prototype.advanceSnake = function(delta) {
backup = temp;
}
body.applyToMesh();
body.applyToMesh(this.state.flip);
}.bind(this)
)
@ -400,8 +397,7 @@ GameLib.Event.Subscribe(
x : 4,
y : 1
},
0,
GameLib.CustomCode.BODY_TYPE_TAIL
0
)
];