Update: CC - Snake FS - Entity Loaded (21g30t1e75.js) 872 bytes modified
parent
3e0239b9a8
commit
396f0e11ce
142
21g30t1e75.js
142
21g30t1e75.js
|
@ -134,7 +134,7 @@ this.state = {
|
|||
orientation : 0,
|
||||
turning : false,
|
||||
flip : 0,
|
||||
eating : 0
|
||||
eating : false
|
||||
};
|
||||
|
||||
GameLib.CustomCode.prototype.visualizeGrid = function () {
|
||||
|
@ -805,28 +805,40 @@ GameLib.CustomCode.prototype.extend = function(gameObject, position, orientation
|
|||
throw new Error('unhandled food type: ' + gameObject.type);
|
||||
}
|
||||
|
||||
if (orientation === GameLib.CustomCode.ORIENTATION_UP) {
|
||||
body.mesh.position.y -= 0.5 * GameLib.CustomCode.BODY_SCALE_Y;
|
||||
}
|
||||
if (orientation === GameLib.CustomCode.ORIENTATION_UP) {
|
||||
body.mesh.position.y -= 0.5 * GameLib.CustomCode.BODY_SCALE_Y;
|
||||
}
|
||||
|
||||
if (orientation === GameLib.CustomCode.ORIENTATION_DOWN) {
|
||||
body.mesh.position.y += 0.5 * GameLib.CustomCode.BODY_SCALE_Y;
|
||||
}
|
||||
if (orientation === GameLib.CustomCode.ORIENTATION_DOWN) {
|
||||
body.mesh.position.y += 0.5 * GameLib.CustomCode.BODY_SCALE_Y;
|
||||
}
|
||||
|
||||
if (orientation === GameLib.CustomCode.ORIENTATION_LEFT) {
|
||||
body.mesh.position.x += 0.5 * GameLib.CustomCode.BODY_SCALE_X;
|
||||
}
|
||||
if (orientation === GameLib.CustomCode.ORIENTATION_LEFT) {
|
||||
body.mesh.position.x += 0.5 * GameLib.CustomCode.BODY_SCALE_X;
|
||||
}
|
||||
|
||||
if (orientation === GameLib.CustomCode.ORIENTATION_RIGHT) {
|
||||
body.mesh.position.x -= 0.5 * GameLib.CustomCode.BODY_SCALE_X;
|
||||
}
|
||||
if (orientation === GameLib.CustomCode.ORIENTATION_RIGHT) {
|
||||
body.mesh.position.x -= 0.5 * GameLib.CustomCode.BODY_SCALE_X;
|
||||
}
|
||||
|
||||
body.mesh.updateInstance('position');
|
||||
body.mesh.updateInstance('position');
|
||||
|
||||
this.state.eating = 2;
|
||||
this.state.eating = true;
|
||||
|
||||
this.snake.splice(1, 0, body);
|
||||
|
||||
/**
|
||||
* Food or powerup objects need to be destroyed before being replaced with a body object
|
||||
*/
|
||||
this.food.splice(
|
||||
this.food.indexOf(gameObject),
|
||||
1
|
||||
);
|
||||
|
||||
gameObject.dispose();
|
||||
|
||||
this.grid[body.position.x][body.position.y] = body;
|
||||
|
||||
}.bind(this);
|
||||
|
||||
/**
|
||||
|
@ -835,7 +847,15 @@ GameLib.CustomCode.prototype.extend = function(gameObject, position, orientation
|
|||
*/
|
||||
GameLib.CustomCode.prototype.powerup = function(gameObject) {
|
||||
console.log('powerup');
|
||||
};
|
||||
|
||||
this.powerups.splice(
|
||||
this.powerups.indexOf(gameObject),
|
||||
1
|
||||
);
|
||||
|
||||
gameObject.dispose();
|
||||
|
||||
}.bind(this);
|
||||
|
||||
/**
|
||||
* Move the snake forward and do collision detection
|
||||
|
@ -853,6 +873,7 @@ GameLib.CustomCode.prototype.advanceSnake = function(delta) {
|
|||
|
||||
var backup = null;
|
||||
var temp = null;
|
||||
var advanced = false;
|
||||
|
||||
this.snake.map(
|
||||
function(body, index) {
|
||||
|
@ -868,72 +889,19 @@ GameLib.CustomCode.prototype.advanceSnake = function(delta) {
|
|||
flip : body.flip
|
||||
}
|
||||
|
||||
var advanced = body.advance(
|
||||
advanced = body.advance(
|
||||
this.state.orientation,
|
||||
this.state.flip,
|
||||
this.grid
|
||||
);
|
||||
|
||||
if (!advanced) {
|
||||
|
||||
this.explode(body.position);
|
||||
|
||||
} else {
|
||||
|
||||
var gameObject = this.grid[body.position.x][body.position.y];
|
||||
|
||||
switch (gameObject.objectType) {
|
||||
case GameLib.CustomCode.OBJECT_TYPE_SNAKE_BODY :
|
||||
this.explode(body.position);
|
||||
break;
|
||||
case GameLib.CustomCode.OBJECT_TYPE_FOOD :
|
||||
this.extend(gameObject, body.position, body.orientation);
|
||||
break;
|
||||
case GameLib.CustomCode.OBJECT_TYPE_POWERUP:
|
||||
this.powerup(gameObject);
|
||||
break;
|
||||
default:
|
||||
/**
|
||||
* Update the grid with the body
|
||||
*/
|
||||
this.grid[body.position.x][body.position.y] = body;
|
||||
break;
|
||||
}
|
||||
|
||||
/**
|
||||
* Food or powerup objects need to be destroyed before being replaced with a body object
|
||||
*/
|
||||
if (
|
||||
gameObject.objectType === GameLib.CustomCode.OBJECT_TYPE_FOOD ||
|
||||
gameObject.objectType === GameLib.CustomCode.OBJECT_TYPE_POWERUP
|
||||
) {
|
||||
|
||||
if (gameObject.objectType === GameLib.CustomCode.OBJECT_TYPE_FOOD) {
|
||||
this.food.splice(
|
||||
this.food.indexOf(gameObject),
|
||||
1
|
||||
);
|
||||
} else {
|
||||
this.powerups.splice(
|
||||
this.powerups.indexOf(gameObject),
|
||||
1
|
||||
);
|
||||
}
|
||||
|
||||
gameObject.dispose();
|
||||
|
||||
this.grid[body.position.x][body.position.y] = body;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
backup.orientation = body.orientation;
|
||||
backup.flip = body.flip;
|
||||
}
|
||||
|
||||
if (this.state.eating > 0) {
|
||||
return
|
||||
}
|
||||
if (this.state.eating === true) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (index > 0) {
|
||||
|
||||
|
@ -1042,7 +1010,33 @@ GameLib.CustomCode.prototype.advanceSnake = function(delta) {
|
|||
)
|
||||
|
||||
this.state.turning = false;
|
||||
this.state.eating -= 1;
|
||||
|
||||
this.state.eating = false;
|
||||
|
||||
var head = this.snake[0];
|
||||
|
||||
if (!advanced) {
|
||||
|
||||
this.explode(head.position);
|
||||
|
||||
} else {
|
||||
|
||||
var gameObject = this.grid[head.position.x][head.position.y];
|
||||
|
||||
switch (gameObject.objectType) {
|
||||
case GameLib.CustomCode.OBJECT_TYPE_SNAKE_BODY :
|
||||
this.explode(head.position);
|
||||
break;
|
||||
case GameLib.CustomCode.OBJECT_TYPE_FOOD :
|
||||
this.extend(gameObject, head.position, head.orientation);
|
||||
break;
|
||||
case GameLib.CustomCode.OBJECT_TYPE_POWERUP:
|
||||
this.powerup(gameObject);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
this.visualizeGrid();
|
||||
|
||||
|
|
Loading…
Reference in New Issue