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(
|
GameLib.CustomCode.SnakeBody = function(
|
||||||
bodyType,
|
bodyType,
|
||||||
mesh,
|
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)) {
|
if (GameLib.Utils.UndefinedOrNull(bodyType)) {
|
||||||
throw new Error('no body type specified');
|
throw new Error('no body type specified');
|
||||||
}
|
}
|
||||||
|
@ -124,12 +117,24 @@ GameLib.CustomCode.SnakeBody = function(
|
||||||
}
|
}
|
||||||
this.mesh = mesh.clone();
|
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) {
|
switch (this.bodyType) {
|
||||||
case GameLib.CustomCode.BODY_TYPE_HEAD :
|
case GameLib.CustomCode.BODY_TYPE_HEAD :
|
||||||
break;
|
break;
|
||||||
case GameLib.CustomCode.BODY_TYPE_TAIL :
|
case GameLib.CustomCode.BODY_TYPE_TAIL :
|
||||||
this.mesh.rotation.z += Math.PI;
|
this.rotation += Math.PI;
|
||||||
this.mesh.updateInstance('rotation');
|
|
||||||
this.position.x += 1;
|
this.position.x += 1;
|
||||||
break;
|
break;
|
||||||
default :
|
default :
|
||||||
|
@ -137,7 +142,7 @@ GameLib.CustomCode.SnakeBody = function(
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
this.applyPositionToMesh();
|
this.applyToMesh();
|
||||||
};
|
};
|
||||||
|
|
||||||
GameLib.CustomCode.SnakeBody.prototype.clone = function() {
|
GameLib.CustomCode.SnakeBody.prototype.clone = function() {
|
||||||
|
@ -152,13 +157,17 @@ GameLib.CustomCode.SnakeBody.prototype.clone = function() {
|
||||||
}
|
}
|
||||||
|
|
||||||
GameLib.CustomCode.SnakeBody.prototype.applyPositionToMesh = function() {
|
GameLib.CustomCode.SnakeBody.prototype.applyPositionToMesh = 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.rotation;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* TODO: We don't update instance position - animation should do this
|
* TODO: We don't update instance position - animation should do this
|
||||||
*/
|
*/
|
||||||
this.mesh.updateInstance('position');
|
this.mesh.updateInstance('position');
|
||||||
|
this.mesh.updateInstance('rotation');
|
||||||
}
|
}
|
||||||
|
|
||||||
GameLib.CustomCode.SnakeBody.prototype.advance = function(direction) {
|
GameLib.CustomCode.SnakeBody.prototype.advance = function(direction) {
|
||||||
|
|
Loading…
Reference in New Issue