Update: CC - Snake FS - Entity Loaded (21g30t1e75.js) 136 bytes modified
parent
814fde174e
commit
eae9a7f6d2
|
@ -104,16 +104,9 @@ this.meshBodyPatty = this.createGameMesh(this.imageBodyPatty);
|
|||
GameLib.CustomCode.SnakeBody = function(
|
||||
bodyType,
|
||||
mesh,
|
||||
position
|
||||
position,
|
||||
rotation
|
||||
) {
|
||||
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(bodyType)) {
|
||||
throw new Error('no body type specified');
|
||||
}
|
||||
|
@ -124,12 +117,24 @@ 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 :
|
||||
|
@ -137,7 +142,7 @@ GameLib.CustomCode.SnakeBody = function(
|
|||
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) {
|
||||
|
|
Loading…
Reference in New Issue