Update: CC - Snake FS - Entity Loaded (21g30t1e75.js) 61 bytes modified
parent
5b86265f47
commit
2bb687727d
|
@ -52,6 +52,10 @@ this.snake = [];
|
|||
this.grid = [];
|
||||
this.speed = GameLib.CustomCode.SPEED_INITIAL;
|
||||
this.advanceTime = 0;
|
||||
this.direction = {
|
||||
x : -1,
|
||||
y : 0
|
||||
}
|
||||
|
||||
GameLib.CustomCode.prototype.createMaterial = function(image) {
|
||||
var diffuseMap = new GameLib.D3.Texture.Image(
|
||||
|
@ -88,9 +92,9 @@ GameLib.CustomCode.prototype.createGameMesh = function(image) {
|
|||
/**
|
||||
* Create our objects
|
||||
*/
|
||||
this.meshEnd = this.createGameMesh(this.imageEnd);
|
||||
this.meshEnd.useQuaternion = false;
|
||||
this.meshEnd.rotation.z = Math.PI / 2;
|
||||
this.meshEnd = this.createGameMesh(this.imageEnd);
|
||||
this.meshEnd.useQuaternion = false;
|
||||
this.meshEnd.rotation.z = Math.PI / 2;
|
||||
this.meshEnd.updateInstance('rotation');
|
||||
|
||||
this.meshPatty = this.createGameMesh(this.imagePatty);
|
||||
|
@ -99,8 +103,7 @@ this.meshBodyPatty = this.createGameMesh(this.imageBodyPatty);
|
|||
GameLib.CustomCode.SnakeBody = function(
|
||||
bodyType,
|
||||
mesh,
|
||||
position,
|
||||
direction
|
||||
position
|
||||
) {
|
||||
if (GameLib.Utils.UndefinedOrNull(position)) {
|
||||
position = {
|
||||
|
@ -110,14 +113,6 @@ GameLib.CustomCode.SnakeBody = function(
|
|||
}
|
||||
this.position = position;
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(direction)) {
|
||||
direction = {
|
||||
x : -1,
|
||||
y : 0
|
||||
};
|
||||
}
|
||||
this.direction = direction;
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(bodyType)) {
|
||||
throw new Error('no body type specified');
|
||||
}
|
||||
|
@ -126,7 +121,7 @@ GameLib.CustomCode.SnakeBody = function(
|
|||
if (GameLib.Utils.UndefinedOrNull(mesh)) {
|
||||
throw new Error('no mesh specified');
|
||||
}
|
||||
this.mesh = mesh.clone();
|
||||
this.mesh = mesh;
|
||||
|
||||
switch (this.bodyType) {
|
||||
case GameLib.CustomCode.BODY_TYPE_HEAD :
|
||||
|
@ -147,14 +142,10 @@ GameLib.CustomCode.SnakeBody = function(
|
|||
GameLib.CustomCode.SnakeBody.prototype.clone = function() {
|
||||
return new GameLib.CustomCode.SnakeBody(
|
||||
this.bodyType,
|
||||
this.mesh,
|
||||
this.mesh.clone(),
|
||||
{
|
||||
x : this.position.x,
|
||||
y : this.position.y
|
||||
},
|
||||
{
|
||||
x : this.direction.x,
|
||||
y : this.direction.y
|
||||
}
|
||||
);
|
||||
}
|
||||
|
@ -169,9 +160,9 @@ GameLib.CustomCode.SnakeBody.prototype.applyPositionToMesh = function() {
|
|||
this.mesh.updateInstance('position');
|
||||
}
|
||||
|
||||
GameLib.CustomCode.SnakeBody.prototype.advance = function() {
|
||||
this.position.x += this.direction.x;
|
||||
this.position.y += this.direction.y;
|
||||
GameLib.CustomCode.SnakeBody.prototype.advance = function(direction) {
|
||||
this.position.x += direction.x;
|
||||
this.position.y += direction.y;
|
||||
}
|
||||
|
||||
GameLib.CustomCode.prototype.advanceSnake = function(delta) {
|
||||
|
@ -185,25 +176,35 @@ GameLib.CustomCode.prototype.advanceSnake = function(delta) {
|
|||
}
|
||||
|
||||
var head = this.snake[0].clone();
|
||||
head.advance();
|
||||
head.advance(this.direction);
|
||||
|
||||
var oldHead = this.snake.shift();
|
||||
oldHead.mesh.geometry = null;
|
||||
oldHead.mesh.materials = null;
|
||||
oldHead.mesh.remove();
|
||||
|
||||
var oldTail = this.snake.pop();
|
||||
var position = oldHead.position;
|
||||
|
||||
var snake = [head];
|
||||
|
||||
this.snake.map(
|
||||
function(body) {
|
||||
|
||||
var tempPosition = {
|
||||
x : body.position.x,
|
||||
y : body.position.y
|
||||
};
|
||||
|
||||
body.position.x = position.x;
|
||||
body.position.y = position.y;
|
||||
|
||||
snake.push(body);
|
||||
|
||||
position.x = tempPosition.x;
|
||||
position.y = tempPosition.y;
|
||||
}
|
||||
);
|
||||
|
||||
snake.push(oldTail);
|
||||
|
||||
this.snake = snake;
|
||||
}.bind(this);
|
||||
|
||||
|
|
Loading…
Reference in New Issue