Update: CC - Snake FS - Entity Loaded (21g30t1e75.js) 1022 bytes modified
parent
9f31af8037
commit
034b6eed73
153
21g30t1e75.js
153
21g30t1e75.js
|
@ -34,6 +34,11 @@ GameLib.CustomCode.FOOD_ONION_RING = 3;
|
||||||
GameLib.CustomCode.FOOD_PATTY = 4;
|
GameLib.CustomCode.FOOD_PATTY = 4;
|
||||||
GameLib.CustomCode.FOOD_TOMATO = 5;
|
GameLib.CustomCode.FOOD_TOMATO = 5;
|
||||||
|
|
||||||
|
GameLib.CustomCode.OCCUPIED_TYPE_NONE = 0;
|
||||||
|
GameLib.CustomCode.OCCUPIED_TYPE_SNAKE_BODY = 1;
|
||||||
|
GameLib.CustomCode.OCCUPIED_TYPE_FOOD = 2;
|
||||||
|
GameLib.CustomCode.OCCUPIED_TYPE_POWERUP = 3;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get runtime
|
* Get runtime
|
||||||
*/
|
*/
|
||||||
|
@ -98,12 +103,13 @@ this.animationRotation = GameLib.EntityManager.Instance.findComponentById('z628k
|
||||||
* Game objects
|
* Game objects
|
||||||
*/
|
*/
|
||||||
this.snake = [];
|
this.snake = [];
|
||||||
this.grid = [];
|
this.grid = [[]];
|
||||||
this.speed = GameLib.CustomCode.SPEED_INITIAL;
|
this.speed = GameLib.CustomCode.SPEED_INITIAL;
|
||||||
this.advanceTime = 0;
|
this.advanceTime = 0;
|
||||||
this.foodTime = 0;
|
this.foodTime = 0;
|
||||||
this.foodSpeed = GameLib.CustomCode.FOOD_SPEED_INITIAL;
|
this.foodSpeed = GameLib.CustomCode.FOOD_SPEED_INITIAL;
|
||||||
this.foodItems = [];
|
this.food = [];
|
||||||
|
this.powerups = [];
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Orientation is 0, 1, 2 or 3, (up, left, down, right) -
|
* Orientation is 0, 1, 2 or 3, (up, left, down, right) -
|
||||||
|
@ -226,6 +232,13 @@ GameLib.CustomCode.prototype.createFood = function(delta) {
|
||||||
//mesh.updateInstance('scale');
|
//mesh.updateInstance('scale');
|
||||||
mesh.updateInstance('visible');
|
mesh.updateInstance('visible');
|
||||||
|
|
||||||
|
this.food.push(
|
||||||
|
{
|
||||||
|
type : foodType,
|
||||||
|
mesh : mesh
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
}.bind(this);
|
}.bind(this);
|
||||||
|
|
||||||
|
|
||||||
|
@ -289,18 +302,11 @@ GameLib.CustomCode.SnakeBody = function(
|
||||||
this.applyToMesh();
|
this.applyToMesh();
|
||||||
};
|
};
|
||||||
|
|
||||||
GameLib.CustomCode.SnakeBody.LastZ = 0;
|
|
||||||
|
|
||||||
GameLib.CustomCode.SnakeBody.prototype.applyToMesh = function() {
|
GameLib.CustomCode.SnakeBody.prototype.applyToMesh = function() {
|
||||||
|
|
||||||
this.mesh.position.x = (this.position.x * GameLib.CustomCode.BODY_SCALE_X) + GameLib.CustomCode.GRID_OFFSET_X;
|
this.mesh.position.x = (this.position.x * GameLib.CustomCode.BODY_SCALE_X) + GameLib.CustomCode.GRID_OFFSET_X;
|
||||||
this.mesh.position.y = (this.position.y * GameLib.CustomCode.BODY_SCALE_Y) + GameLib.CustomCode.GRID_OFFSET_Y;
|
this.mesh.position.y = (this.position.y * GameLib.CustomCode.BODY_SCALE_Y) + GameLib.CustomCode.GRID_OFFSET_Y;
|
||||||
|
|
||||||
//if ((this.mesh.rotation.z - (this.orientation * Math.PI / 2)) > Math.PI) {
|
|
||||||
// this.mesh.rotation.z -= Math.PI;
|
|
||||||
// this.mesh.updateInstance('rotation');
|
|
||||||
//}
|
|
||||||
|
|
||||||
this.mesh.rotation.z = this.orientation * Math.PI / 2;
|
this.mesh.rotation.z = this.orientation * Math.PI / 2;
|
||||||
|
|
||||||
if (this.backupMesh) {
|
if (this.backupMesh) {
|
||||||
|
@ -309,13 +315,7 @@ GameLib.CustomCode.SnakeBody.prototype.applyToMesh = function() {
|
||||||
this.mesh.updateInstance('rotation');
|
this.mesh.updateInstance('rotation');
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* TODO: We don't update instance position - animation should do this
|
|
||||||
*/
|
|
||||||
// this.mesh.updateInstance('position');
|
|
||||||
//if (!this.isTail) {
|
|
||||||
this.mesh.updateInstance('rotation');
|
this.mesh.updateInstance('rotation');
|
||||||
//}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
GameLib.CustomCode.SnakeBody.prototype.advance = function(orientation, flip) {
|
GameLib.CustomCode.SnakeBody.prototype.advance = function(orientation, flip) {
|
||||||
|
@ -362,12 +362,73 @@ GameLib.CustomCode.SnakeBody.prototype.advance = function(orientation, flip) {
|
||||||
console.log('crashed!');
|
console.log('crashed!');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
this.orientation = orientation;
|
this.orientation = orientation;
|
||||||
|
|
||||||
this.flip = flip;
|
this.flip = flip;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
GameLib.CustomCode.prototype.initializeGrid = function() {
|
||||||
|
|
||||||
|
this.grid = [];
|
||||||
|
|
||||||
|
for (var x = 0; x < GameLib.CustomCode.GRID_WIDTH; x++) {
|
||||||
|
this.grid[x] = [];
|
||||||
|
for (var y = 0; y < GameLib.CustomCode.GRID_HEIGHT; y++) {
|
||||||
|
this.grid[x][y] = {
|
||||||
|
occupied : false,
|
||||||
|
type : GameLib.CustomCode.OCCUPIED_TYPE_NONE,
|
||||||
|
index : -1
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}.bind(this);
|
||||||
|
|
||||||
|
GameLib.CustomCode.prototype.rebuildGrid = function() {
|
||||||
|
|
||||||
|
this.initializeGrid();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* First add all the snake body parts
|
||||||
|
*/
|
||||||
|
this.snake.map(
|
||||||
|
function(body, index) {
|
||||||
|
this.grid[body.position.x][body.position.y] = {
|
||||||
|
occupied: true,
|
||||||
|
type : GameLib.CustomCode.OCCUPIED_TYPE_SNAKE_BODY,
|
||||||
|
index : index
|
||||||
|
}
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Then add all the food bits
|
||||||
|
*/
|
||||||
|
this.food.map(
|
||||||
|
function(food, index) {
|
||||||
|
this.grid[food.position.x][food.position.y] = {
|
||||||
|
occupied: true,
|
||||||
|
type : GameLib.CustomCode.OCCUPIED_TYPE_FOOD,
|
||||||
|
index : index
|
||||||
|
}
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* And also all the power ups
|
||||||
|
*/
|
||||||
|
this.powerups.map(
|
||||||
|
function(powerup, index) {
|
||||||
|
this.grid[powerup.position.x][powerup.position.y] = {
|
||||||
|
occupied: true,
|
||||||
|
type : GameLib.CustomCode.OCCUPIED_TYPE_POWERUP,
|
||||||
|
index : index
|
||||||
|
}
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
}.bind(this);
|
||||||
|
|
||||||
GameLib.CustomCode.prototype.advanceSnake = function(delta) {
|
GameLib.CustomCode.prototype.advanceSnake = function(delta) {
|
||||||
|
|
||||||
this.advanceTime += delta;
|
this.advanceTime += delta;
|
||||||
|
@ -504,25 +565,13 @@ GameLib.CustomCode.prototype.advanceSnake = function(delta) {
|
||||||
|
|
||||||
this.state.turning = false;
|
this.state.turning = false;
|
||||||
|
|
||||||
}.bind(this);
|
/**
|
||||||
|
* At this point - we advanced the whole snake - time to rebuild the grid
|
||||||
|
*/
|
||||||
GameLib.CustomCode.prototype.initializeGrid = function() {
|
this.rebuildGrid();
|
||||||
|
|
||||||
this.grid = [];
|
|
||||||
|
|
||||||
for (var x = 0; x < GameLib.CustomCode.GRID_WIDTH; x++) {
|
|
||||||
this.grid[x] = [];
|
|
||||||
for (var y = 0; y < GameLib.CustomCode.GRID_HEIGHT; y++) {
|
|
||||||
this.grid[x][y] = {
|
|
||||||
mesh : null
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}.bind(this);
|
}.bind(this);
|
||||||
|
|
||||||
|
|
||||||
GameLib.Event.Subscribe(
|
GameLib.Event.Subscribe(
|
||||||
GameLib.Event.GAME_START,
|
GameLib.Event.GAME_START,
|
||||||
function() {
|
function() {
|
||||||
|
@ -538,6 +587,22 @@ GameLib.Event.Subscribe(
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
|
this.food.map(
|
||||||
|
function(food) {
|
||||||
|
food.mesh.geometry = null;
|
||||||
|
food.mesh.materials = null;
|
||||||
|
food.mesh.remove();
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
|
this.powerups.map(
|
||||||
|
function(powerup) {
|
||||||
|
powerup.mesh.geometry = null;
|
||||||
|
powerup.mesh.materials = null;
|
||||||
|
powerup.mesh.remove();
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
this.state = {
|
this.state = {
|
||||||
orientation : GameLib.CustomCode.ORIENTATION_UP
|
orientation : GameLib.CustomCode.ORIENTATION_UP
|
||||||
};
|
};
|
||||||
|
@ -580,8 +645,6 @@ GameLib.Event.Subscribe(
|
||||||
)
|
)
|
||||||
];
|
];
|
||||||
|
|
||||||
//this.snake[3].mesh.position.z += 1;
|
|
||||||
|
|
||||||
this.snake[0].mesh.updateInstance('position');
|
this.snake[0].mesh.updateInstance('position');
|
||||||
this.snake[1].mesh.updateInstance('position');
|
this.snake[1].mesh.updateInstance('position');
|
||||||
this.snake[2].mesh.updateInstance('position');
|
this.snake[2].mesh.updateInstance('position');
|
||||||
|
@ -590,28 +653,11 @@ GameLib.Event.Subscribe(
|
||||||
this.animation.meshes.push(this.snake[0].mesh);
|
this.animation.meshes.push(this.snake[0].mesh);
|
||||||
this.animation.meshes.push(this.snake[1].mesh);
|
this.animation.meshes.push(this.snake[1].mesh);
|
||||||
this.animation.meshes.push(this.snake[2].mesh);
|
this.animation.meshes.push(this.snake[2].mesh);
|
||||||
|
|
||||||
//this.snake[2].mesh.instance.add(this.snake[3].mesh.instance);
|
|
||||||
this.animation.meshes.push(this.snake[3].mesh);
|
this.animation.meshes.push(this.snake[3].mesh);
|
||||||
|
|
||||||
|
//this.snake[2].mesh.instance.add(this.snake[3].mesh.instance);
|
||||||
//this.animationRotation.meshes.push(this.snake[3].mesh);
|
//this.animationRotation.meshes.push(this.snake[3].mesh);
|
||||||
|
|
||||||
/**
|
|
||||||
* Cleanup grid
|
|
||||||
*
|
|
||||||
this.grid.map(
|
|
||||||
function(x) {
|
|
||||||
x.map(
|
|
||||||
function(y) {
|
|
||||||
y.mesh.geometry = null;
|
|
||||||
y.mesh.materials = null;
|
|
||||||
y.mesh.remove();
|
|
||||||
}
|
|
||||||
);
|
|
||||||
}
|
|
||||||
);
|
|
||||||
*/
|
|
||||||
|
|
||||||
this.initializeGrid();
|
this.initializeGrid();
|
||||||
//this.visualizeGrid();
|
//this.visualizeGrid();
|
||||||
|
|
||||||
|
@ -622,7 +668,8 @@ function(y) {
|
||||||
this.speed = GameLib.CustomCode.SPEED_INITIAL;
|
this.speed = GameLib.CustomCode.SPEED_INITIAL;
|
||||||
this.foodTime = 0;
|
this.foodTime = 0;
|
||||||
this.foodSpeed = GameLib.CustomCode.FOOD_SPEED_INITIAL;
|
this.foodSpeed = GameLib.CustomCode.FOOD_SPEED_INITIAL;
|
||||||
this.foodItems = [];
|
this.food = [];
|
||||||
|
this.powerups = [];
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Re-initialize our other custom code components
|
* Re-initialize our other custom code components
|
||||||
|
|
Loading…
Reference in New Issue