Update: CC - Snake FS - Entity Loaded (21g30t1e75.js) 1614 bytes modified
parent
c39dc83dda
commit
cc02305c6e
288
21g30t1e75.js
288
21g30t1e75.js
|
@ -136,8 +136,8 @@ this.state = {
|
||||||
turning : false,
|
turning : false,
|
||||||
flip : 0,
|
flip : 0,
|
||||||
eating : false,
|
eating : false,
|
||||||
exploding : false,
|
exploding : false,
|
||||||
lives : 2
|
lives : 2
|
||||||
};
|
};
|
||||||
|
|
||||||
GameLib.CustomCode.prototype.visualizeGrid = function () {
|
GameLib.CustomCode.prototype.visualizeGrid = function () {
|
||||||
|
@ -333,24 +333,24 @@ GameLib.CustomCode.GameObject.prototype.applyToMesh = function(updateInstance) {
|
||||||
*/
|
*/
|
||||||
GameLib.CustomCode.prototype.getFreeGridPosition = function() {
|
GameLib.CustomCode.prototype.getFreeGridPosition = function() {
|
||||||
|
|
||||||
var positions = [];
|
var positions = [];
|
||||||
|
|
||||||
this.grid.map(
|
this.grid.map(
|
||||||
function(row, x) {
|
function(row, x) {
|
||||||
row.map(
|
row.map(
|
||||||
function(object, y) {
|
function(object, y) {
|
||||||
if (object.objectType === GameLib.CustomCode.OBJECT_TYPE_NONE) {
|
if (object.objectType === GameLib.CustomCode.OBJECT_TYPE_NONE) {
|
||||||
positions.push(
|
positions.push(
|
||||||
{
|
{
|
||||||
x : x,
|
x : x,
|
||||||
y : y
|
y : y
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
var index = GameLib.Utils.GetRandomInt(0, positions.length);
|
var index = GameLib.Utils.GetRandomInt(0, positions.length);
|
||||||
|
|
||||||
|
@ -531,7 +531,7 @@ GameLib.CustomCode.prototype.createGameObject = function(
|
||||||
if (currentGameObject.objectType === GameLib.CustomCode.OBJECT_TYPE_SNAKE_BODY) {
|
if (currentGameObject.objectType === GameLib.CustomCode.OBJECT_TYPE_SNAKE_BODY) {
|
||||||
console.warn('should not reach this code if collision detection is perfect');
|
console.warn('should not reach this code if collision detection is perfect');
|
||||||
this.explode(currentGameObject.position);
|
this.explode(currentGameObject.position);
|
||||||
return;
|
return gameObject;
|
||||||
}
|
}
|
||||||
|
|
||||||
this.grid[gameObject.position.x][gameObject.position.y].dispose();
|
this.grid[gameObject.position.x][gameObject.position.y].dispose();
|
||||||
|
@ -751,14 +751,14 @@ GameLib.CustomCode.prototype.initializeGrid = function() {
|
||||||
GameLib.CustomCode.prototype.explode = function(position) {
|
GameLib.CustomCode.prototype.explode = function(position) {
|
||||||
console.log('explode snake at position : ' + position.x + ', ' + position.y);
|
console.log('explode snake at position : ' + position.x + ', ' + position.y);
|
||||||
|
|
||||||
this.state.exploding = true;
|
this.state.exploding = true;
|
||||||
this.state.lives -= 1;
|
this.state.lives -= 1;
|
||||||
|
|
||||||
this.particleEnginePickle.position.x = (position.x * GameLib.CustomCode.BODY_SCALE_X) + GameLib.CustomCode.GRID_OFFSET_X;
|
this.particleEnginePickle.position.x = (position.x * GameLib.CustomCode.BODY_SCALE_X) + GameLib.CustomCode.GRID_OFFSET_X;
|
||||||
this.particleEnginePickle.position.y = (position.y * GameLib.CustomCode.BODY_SCALE_Y) + GameLib.CustomCode.GRID_OFFSET_Y;
|
this.particleEnginePickle.position.y = (position.y * GameLib.CustomCode.BODY_SCALE_Y) + GameLib.CustomCode.GRID_OFFSET_Y;
|
||||||
this.particleEnginePickle.updateInstance('position');
|
this.particleEnginePickle.updateInstance('position');
|
||||||
|
|
||||||
this.particleEnginePickle.enabled = true;
|
this.particleEnginePickle.enabled = true;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -779,10 +779,10 @@ GameLib.CustomCode.prototype.extend = function(gameObject, position, orientation
|
||||||
body = this.createGameObject(
|
body = this.createGameObject(
|
||||||
GameLib.CustomCode.OBJECT_TYPE_SNAKE_BODY,
|
GameLib.CustomCode.OBJECT_TYPE_SNAKE_BODY,
|
||||||
GameLib.CustomCode.BODY_TYPE_BREAD_BACON,
|
GameLib.CustomCode.BODY_TYPE_BREAD_BACON,
|
||||||
{
|
{
|
||||||
x : position.x,
|
x : position.x,
|
||||||
y : position.y
|
y : position.y
|
||||||
},
|
},
|
||||||
orientation
|
orientation
|
||||||
)
|
)
|
||||||
break;
|
break;
|
||||||
|
@ -791,9 +791,9 @@ GameLib.CustomCode.prototype.extend = function(gameObject, position, orientation
|
||||||
GameLib.CustomCode.OBJECT_TYPE_SNAKE_BODY,
|
GameLib.CustomCode.OBJECT_TYPE_SNAKE_BODY,
|
||||||
GameLib.CustomCode.BODY_TYPE_BREAD_CHEESE,
|
GameLib.CustomCode.BODY_TYPE_BREAD_CHEESE,
|
||||||
{
|
{
|
||||||
x : position.x,
|
x : position.x,
|
||||||
y : position.y
|
y : position.y
|
||||||
},
|
},
|
||||||
orientation
|
orientation
|
||||||
)
|
)
|
||||||
break;
|
break;
|
||||||
|
@ -802,9 +802,9 @@ GameLib.CustomCode.prototype.extend = function(gameObject, position, orientation
|
||||||
GameLib.CustomCode.OBJECT_TYPE_SNAKE_BODY,
|
GameLib.CustomCode.OBJECT_TYPE_SNAKE_BODY,
|
||||||
GameLib.CustomCode.BODY_TYPE_BREAD_ONION,
|
GameLib.CustomCode.BODY_TYPE_BREAD_ONION,
|
||||||
{
|
{
|
||||||
x : position.x,
|
x : position.x,
|
||||||
y : position.y
|
y : position.y
|
||||||
},
|
},
|
||||||
orientation
|
orientation
|
||||||
)
|
)
|
||||||
break;
|
break;
|
||||||
|
@ -813,9 +813,9 @@ GameLib.CustomCode.prototype.extend = function(gameObject, position, orientation
|
||||||
GameLib.CustomCode.OBJECT_TYPE_SNAKE_BODY,
|
GameLib.CustomCode.OBJECT_TYPE_SNAKE_BODY,
|
||||||
GameLib.CustomCode.BODY_TYPE_BREAD_ONION_RING,
|
GameLib.CustomCode.BODY_TYPE_BREAD_ONION_RING,
|
||||||
{
|
{
|
||||||
x : position.x,
|
x : position.x,
|
||||||
y : position.y
|
y : position.y
|
||||||
},
|
},
|
||||||
orientation
|
orientation
|
||||||
)
|
)
|
||||||
break;
|
break;
|
||||||
|
@ -824,9 +824,9 @@ GameLib.CustomCode.prototype.extend = function(gameObject, position, orientation
|
||||||
GameLib.CustomCode.OBJECT_TYPE_SNAKE_BODY,
|
GameLib.CustomCode.OBJECT_TYPE_SNAKE_BODY,
|
||||||
GameLib.CustomCode.BODY_TYPE_BREAD_PATTY,
|
GameLib.CustomCode.BODY_TYPE_BREAD_PATTY,
|
||||||
{
|
{
|
||||||
x : position.x,
|
x : position.x,
|
||||||
y : position.y
|
y : position.y
|
||||||
},
|
},
|
||||||
orientation
|
orientation
|
||||||
)
|
)
|
||||||
break;
|
break;
|
||||||
|
@ -835,9 +835,9 @@ GameLib.CustomCode.prototype.extend = function(gameObject, position, orientation
|
||||||
GameLib.CustomCode.OBJECT_TYPE_SNAKE_BODY,
|
GameLib.CustomCode.OBJECT_TYPE_SNAKE_BODY,
|
||||||
GameLib.CustomCode.BODY_TYPE_BREAD_TOMATO,
|
GameLib.CustomCode.BODY_TYPE_BREAD_TOMATO,
|
||||||
{
|
{
|
||||||
x : position.x,
|
x : position.x,
|
||||||
y : position.y
|
y : position.y
|
||||||
},
|
},
|
||||||
orientation
|
orientation
|
||||||
)
|
)
|
||||||
break;
|
break;
|
||||||
|
@ -845,7 +845,7 @@ GameLib.CustomCode.prototype.extend = function(gameObject, position, orientation
|
||||||
throw new Error('unhandled food type: ' + gameObject.type);
|
throw new Error('unhandled food type: ' + gameObject.type);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
if (orientation === GameLib.CustomCode.ORIENTATION_UP) {
|
if (orientation === GameLib.CustomCode.ORIENTATION_UP) {
|
||||||
body.mesh.position.y -= 0.5 * GameLib.CustomCode.BODY_SCALE_Y;
|
body.mesh.position.y -= 0.5 * GameLib.CustomCode.BODY_SCALE_Y;
|
||||||
}
|
}
|
||||||
|
@ -900,41 +900,41 @@ GameLib.CustomCode.prototype.powerup = function(gameObject) {
|
||||||
|
|
||||||
GameLib.CustomCode.prototype.createCorner = function(body, temp) {
|
GameLib.CustomCode.prototype.createCorner = function(body, temp) {
|
||||||
|
|
||||||
var backupOrientation = body.orientation;
|
var backupOrientation = body.orientation;
|
||||||
|
|
||||||
body.orientation = temp.orientation;
|
body.orientation = temp.orientation;
|
||||||
|
|
||||||
body.applyToMesh();
|
body.applyToMesh();
|
||||||
|
|
||||||
body.orientation = backupOrientation;
|
body.orientation = backupOrientation;
|
||||||
|
|
||||||
body.backupMesh = body.mesh;
|
body.backupMesh = body.mesh;
|
||||||
|
|
||||||
if (temp.orientation === GameLib.CustomCode.ORIENTATION_UP) {
|
if (temp.orientation === GameLib.CustomCode.ORIENTATION_UP) {
|
||||||
body.backupMesh.position.y -= 0.5 * GameLib.CustomCode.BODY_SCALE_Y;
|
body.backupMesh.position.y -= 0.5 * GameLib.CustomCode.BODY_SCALE_Y;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (temp.orientation === GameLib.CustomCode.ORIENTATION_DOWN) {
|
if (temp.orientation === GameLib.CustomCode.ORIENTATION_DOWN) {
|
||||||
body.backupMesh.position.y += 0.5 * GameLib.CustomCode.BODY_SCALE_Y;
|
body.backupMesh.position.y += 0.5 * GameLib.CustomCode.BODY_SCALE_Y;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (temp.orientation === GameLib.CustomCode.ORIENTATION_LEFT) {
|
if (temp.orientation === GameLib.CustomCode.ORIENTATION_LEFT) {
|
||||||
body.backupMesh.position.x += 0.5 * GameLib.CustomCode.BODY_SCALE_X;
|
body.backupMesh.position.x += 0.5 * GameLib.CustomCode.BODY_SCALE_X;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (temp.orientation === GameLib.CustomCode.ORIENTATION_RIGHT) {
|
if (temp.orientation === GameLib.CustomCode.ORIENTATION_RIGHT) {
|
||||||
body.backupMesh.position.x -= 0.5 * GameLib.CustomCode.BODY_SCALE_X;
|
body.backupMesh.position.x -= 0.5 * GameLib.CustomCode.BODY_SCALE_X;
|
||||||
}
|
}
|
||||||
|
|
||||||
body.mesh = this.createGameMesh(this.materialBreadCorner);
|
body.mesh = this.createGameMesh(this.materialBreadCorner);
|
||||||
|
|
||||||
body.mesh.position.z = 5;
|
body.mesh.position.z = 5;
|
||||||
|
|
||||||
body.mesh.updateInstance('position');
|
body.mesh.updateInstance('position');
|
||||||
|
|
||||||
body.mesh.visible = true;
|
body.mesh.visible = true;
|
||||||
|
|
||||||
body.mesh.updateInstance('visible');
|
body.mesh.updateInstance('visible');
|
||||||
|
|
||||||
}.bind(this);
|
}.bind(this);
|
||||||
|
|
||||||
|
@ -976,39 +976,43 @@ GameLib.CustomCode.prototype.advanceSnake = function(delta) {
|
||||||
this.grid
|
this.grid
|
||||||
);
|
);
|
||||||
|
|
||||||
this.grid[backup.position.x][backup.position.y] = new GameLib.CustomCode.GameObject();
|
this.grid[backup.position.x][backup.position.y] = new GameLib.CustomCode.GameObject();
|
||||||
|
|
||||||
if (!advanced) {
|
if (!advanced) {
|
||||||
|
|
||||||
this.explode(body.position);
|
this.explode(body.position);
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
var gameObject = this.grid[body.position.x][body.position.y];
|
var gameObject = this.grid[body.position.x][body.position.y];
|
||||||
|
|
||||||
switch (gameObject.objectType) {
|
switch (gameObject.objectType) {
|
||||||
case GameLib.CustomCode.OBJECT_TYPE_SNAKE_BODY :
|
case GameLib.CustomCode.OBJECT_TYPE_SNAKE_BODY :
|
||||||
this.explode(body.position);
|
this.explode(body.position);
|
||||||
break;
|
break;
|
||||||
case GameLib.CustomCode.OBJECT_TYPE_FOOD :
|
case GameLib.CustomCode.OBJECT_TYPE_FOOD :
|
||||||
this.extend(gameObject, backup.position, backup.orientation);
|
this.extend(gameObject, backup.position, backup.orientation);
|
||||||
break;
|
break;
|
||||||
case GameLib.CustomCode.OBJECT_TYPE_POWERUP:
|
case GameLib.CustomCode.OBJECT_TYPE_POWERUP:
|
||||||
this.powerup(gameObject);
|
this.powerup(gameObject);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
this.grid[body.position.x][body.position.y] = body
|
this.grid[body.position.x][body.position.y] = body
|
||||||
this.visualizeGrid();
|
this.visualizeGrid();
|
||||||
backup.orientation = body.orientation;
|
backup.orientation = body.orientation;
|
||||||
backup.flip = body.flip;
|
backup.flip = body.flip;
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
temp = {
|
if (this.state.exploding === true) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
temp = {
|
||||||
position : {
|
position : {
|
||||||
x : body.position.x,
|
x : body.position.x,
|
||||||
y : body.position.y
|
y : body.position.y
|
||||||
|
@ -1017,62 +1021,62 @@ GameLib.CustomCode.prototype.advanceSnake = function(delta) {
|
||||||
flip : body.flip
|
flip : body.flip
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this.state.eating === true) {
|
if (this.state.eating === true) {
|
||||||
|
|
||||||
if ((body.orientation !== backup.orientation) &&
|
if ((body.orientation !== backup.orientation) &&
|
||||||
(index === 1)) {
|
(index === 1)) {
|
||||||
body.orientation = backup.orientation;
|
body.orientation = backup.orientation;
|
||||||
body.flip = backup.flip;
|
body.flip = backup.flip;
|
||||||
this.createCorner(body, temp);
|
this.createCorner(body, temp);
|
||||||
body.applyToMesh();
|
body.applyToMesh();
|
||||||
}
|
}
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create a new empty object at the current grid position (free it up)
|
* Create a new empty object at the current grid position (free it up)
|
||||||
*/
|
*/
|
||||||
this.grid[body.position.x][body.position.y] = new GameLib.CustomCode.GameObject();
|
this.grid[body.position.x][body.position.y] = new GameLib.CustomCode.GameObject();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Assign the new location to the body
|
* Assign the new location to the body
|
||||||
*/
|
*/
|
||||||
body.position.x = backup.position.x;
|
body.position.x = backup.position.x;
|
||||||
body.position.y = backup.position.y;
|
body.position.y = backup.position.y;
|
||||||
body.orientation = backup.orientation;
|
body.orientation = backup.orientation;
|
||||||
body.flip = backup.flip;
|
body.flip = backup.flip;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Update the grid with our new body
|
* Update the grid with our new body
|
||||||
*/
|
*/
|
||||||
this.grid[body.position.x][body.position.y] = body;
|
this.grid[body.position.x][body.position.y] = body;
|
||||||
|
|
||||||
if (body.backupMesh) {
|
if (body.backupMesh) {
|
||||||
/**
|
/**
|
||||||
* We used to be a corner, change back
|
* We used to be a corner, change back
|
||||||
* @type {null}
|
* @type {null}
|
||||||
*/
|
*/
|
||||||
body.mesh.geometry = null;
|
body.mesh.geometry = null;
|
||||||
|
|
||||||
body.mesh.materials = null;
|
body.mesh.materials = null;
|
||||||
|
|
||||||
body.mesh.remove();
|
body.mesh.remove();
|
||||||
|
|
||||||
body.mesh = body.backupMesh;
|
body.mesh = body.backupMesh;
|
||||||
|
|
||||||
body.backupMesh = null;
|
body.backupMesh = null;
|
||||||
|
|
||||||
body.mesh.visible = true;
|
body.mesh.visible = true;
|
||||||
|
|
||||||
body.mesh.updateInstance('visible');
|
body.mesh.updateInstance('visible');
|
||||||
|
|
||||||
body.mesh.updateInstance('position');
|
body.mesh.updateInstance('position');
|
||||||
}
|
}
|
||||||
|
|
||||||
if (body.orientation !== temp.orientation) {
|
if (body.orientation !== temp.orientation) {
|
||||||
this.createCorner(body, temp);
|
this.createCorner(body, temp);
|
||||||
}
|
}
|
||||||
|
|
||||||
backup = temp;
|
backup = temp;
|
||||||
}
|
}
|
||||||
|
@ -1086,8 +1090,6 @@ GameLib.CustomCode.prototype.advanceSnake = function(delta) {
|
||||||
|
|
||||||
this.state.eating = false;
|
this.state.eating = false;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
this.visualizeGrid();
|
this.visualizeGrid();
|
||||||
|
|
||||||
}.bind(this);
|
}.bind(this);
|
||||||
|
@ -1117,14 +1119,14 @@ GameLib.Event.Subscribe(
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
this.state = {
|
this.state = {
|
||||||
orientation : 0,
|
orientation : 0,
|
||||||
turning : false,
|
turning : false,
|
||||||
flip : 0,
|
flip : 0,
|
||||||
eating : false,
|
eating : false,
|
||||||
exploding : false,
|
exploding : false,
|
||||||
lives : 2
|
lives : 2
|
||||||
};
|
};
|
||||||
|
|
||||||
this.initializeGrid();
|
this.initializeGrid();
|
||||||
this.visualizeGrid();
|
this.visualizeGrid();
|
||||||
|
|
Loading…
Reference in New Issue