Update: CC - Snake FS - Entity Loaded (21g30t1e75.js) 872 bytes modified
parent
3e0239b9a8
commit
396f0e11ce
114
21g30t1e75.js
114
21g30t1e75.js
|
@ -134,7 +134,7 @@ this.state = {
|
||||||
orientation : 0,
|
orientation : 0,
|
||||||
turning : false,
|
turning : false,
|
||||||
flip : 0,
|
flip : 0,
|
||||||
eating : 0
|
eating : false
|
||||||
};
|
};
|
||||||
|
|
||||||
GameLib.CustomCode.prototype.visualizeGrid = function () {
|
GameLib.CustomCode.prototype.visualizeGrid = function () {
|
||||||
|
@ -823,10 +823,22 @@ GameLib.CustomCode.prototype.extend = function(gameObject, position, orientation
|
||||||
|
|
||||||
body.mesh.updateInstance('position');
|
body.mesh.updateInstance('position');
|
||||||
|
|
||||||
this.state.eating = 2;
|
this.state.eating = true;
|
||||||
|
|
||||||
this.snake.splice(1, 0, body);
|
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);
|
}.bind(this);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -835,7 +847,15 @@ GameLib.CustomCode.prototype.extend = function(gameObject, position, orientation
|
||||||
*/
|
*/
|
||||||
GameLib.CustomCode.prototype.powerup = function(gameObject) {
|
GameLib.CustomCode.prototype.powerup = function(gameObject) {
|
||||||
console.log('powerup');
|
console.log('powerup');
|
||||||
};
|
|
||||||
|
this.powerups.splice(
|
||||||
|
this.powerups.indexOf(gameObject),
|
||||||
|
1
|
||||||
|
);
|
||||||
|
|
||||||
|
gameObject.dispose();
|
||||||
|
|
||||||
|
}.bind(this);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Move the snake forward and do collision detection
|
* Move the snake forward and do collision detection
|
||||||
|
@ -853,6 +873,7 @@ GameLib.CustomCode.prototype.advanceSnake = function(delta) {
|
||||||
|
|
||||||
var backup = null;
|
var backup = null;
|
||||||
var temp = null;
|
var temp = null;
|
||||||
|
var advanced = false;
|
||||||
|
|
||||||
this.snake.map(
|
this.snake.map(
|
||||||
function(body, index) {
|
function(body, index) {
|
||||||
|
@ -868,71 +889,18 @@ GameLib.CustomCode.prototype.advanceSnake = function(delta) {
|
||||||
flip : body.flip
|
flip : body.flip
|
||||||
}
|
}
|
||||||
|
|
||||||
var advanced = body.advance(
|
advanced = body.advance(
|
||||||
this.state.orientation,
|
this.state.orientation,
|
||||||
this.state.flip,
|
this.state.flip,
|
||||||
this.grid
|
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.orientation = body.orientation;
|
||||||
backup.flip = body.flip;
|
backup.flip = body.flip;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this.state.eating > 0) {
|
if (this.state.eating === true) {
|
||||||
return
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (index > 0) {
|
if (index > 0) {
|
||||||
|
@ -1042,7 +1010,33 @@ GameLib.CustomCode.prototype.advanceSnake = function(delta) {
|
||||||
)
|
)
|
||||||
|
|
||||||
this.state.turning = false;
|
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();
|
this.visualizeGrid();
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue