Update: CC - Snake FS - Entity Loaded (21g30t1e75.js) 128 bytes modified
parent
a0a9c72e5f
commit
0f00831ae4
|
@ -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
|
|
||||||
)
|
)
|
||||||
];
|
];
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue