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

beta.r3js.org
-=yb4f310 2018-03-13 13:33:59 +01:00
parent 814fde174e
commit eae9a7f6d2
1 changed files with 23 additions and 14 deletions

View File

@ -104,16 +104,9 @@ this.meshBodyPatty = this.createGameMesh(this.imageBodyPatty);
GameLib.CustomCode.SnakeBody = function(
bodyType,
mesh,
position
) {
if (GameLib.Utils.UndefinedOrNull(position)) {
position = {
x : Math.round(GameLib.CustomCode.GRID_WIDTH / 2),
y : Math.round(GameLib.CustomCode.GRID_HEIGHT / 2)
};
}
this.position = position;
position,
rotation
) {
if (GameLib.Utils.UndefinedOrNull(bodyType)) {
throw new Error('no body type specified');
}
@ -124,20 +117,32 @@ GameLib.CustomCode.SnakeBody = function(
}
this.mesh = mesh.clone();
if (GameLib.Utils.UndefinedOrNull(position)) {
position = {
x : Math.round(GameLib.CustomCode.GRID_WIDTH / 2),
y : Math.round(GameLib.CustomCode.GRID_HEIGHT / 2)
};
}
this.position = position;
if (GameLib.Utils.UndefinedOrNull(rotation)) {
rotation = 0;
}
this.rotation = rotation;
switch (this.bodyType) {
case GameLib.CustomCode.BODY_TYPE_HEAD :
break;
case GameLib.CustomCode.BODY_TYPE_TAIL :
this.mesh.rotation.z += Math.PI;
this.mesh.updateInstance('rotation');
this.rotation += Math.PI;
this.position.x += 1;
break;
default :
throw new Error('unreachable statement');
break;
}
this.applyPositionToMesh();
this.applyToMesh();
};
GameLib.CustomCode.SnakeBody.prototype.clone = function() {
@ -152,13 +157,17 @@ GameLib.CustomCode.SnakeBody.prototype.clone = function() {
}
GameLib.CustomCode.SnakeBody.prototype.applyPositionToMesh = function() {
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.rotation;
/**
* TODO: We don't update instance position - animation should do this
*/
this.mesh.updateInstance('position');
this.mesh.updateInstance('rotation');
}
GameLib.CustomCode.SnakeBody.prototype.advance = function(direction) {