Update: CC - Snake FS - Entity Loaded (21g30t1e75.js) 1442 bytes modified
parent
1f0b599d61
commit
b02a42f6e2
339
21g30t1e75.js
339
21g30t1e75.js
|
@ -1,140 +1,142 @@
|
||||||
if (this.parentEntity === data.entity) {
|
if (this.parentEntity === data.entity) {
|
||||||
console.log('snake entity loaded');
|
console.log('snake entity loaded');
|
||||||
} else {
|
} else {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Defines
|
* Defines
|
||||||
*/
|
*/
|
||||||
GameLib.CustomCode.BODY_TYPE_NORMAL = 0x1;
|
GameLib.CustomCode.BODY_TYPE_NORMAL = 0x1;
|
||||||
GameLib.CustomCode.BODY_TYPE_TAIL = 0x2;
|
GameLib.CustomCode.BODY_TYPE_TAIL = 0x2;
|
||||||
GameLib.CustomCode.BODY_TYPE_CORNER = 0x3;
|
GameLib.CustomCode.BODY_TYPE_CORNER = 0x3;
|
||||||
|
|
||||||
GameLib.CustomCode.GRID_WIDTH = 11;
|
GameLib.CustomCode.GRID_WIDTH = 11;
|
||||||
GameLib.CustomCode.GRID_HEIGHT = 10;
|
GameLib.CustomCode.GRID_HEIGHT = 10;
|
||||||
|
|
||||||
GameLib.CustomCode.GRID_OFFSET_X = 1;
|
GameLib.CustomCode.GRID_OFFSET_X = 1;
|
||||||
GameLib.CustomCode.GRID_OFFSET_Y = 8;
|
GameLib.CustomCode.GRID_OFFSET_Y = 8;
|
||||||
|
|
||||||
GameLib.CustomCode.SPEED_INITIAL = 1;
|
GameLib.CustomCode.SPEED_INITIAL = 1;
|
||||||
|
|
||||||
GameLib.CustomCode.ORIENTATION_UP = 0;
|
GameLib.CustomCode.ORIENTATION_UP = 0;
|
||||||
GameLib.CustomCode.ORIENTATION_LEFT = 1;
|
GameLib.CustomCode.ORIENTATION_LEFT = 1;
|
||||||
GameLib.CustomCode.ORIENTATION_DOWN = 2;
|
GameLib.CustomCode.ORIENTATION_DOWN = 2;
|
||||||
GameLib.CustomCode.ORIENTATION_RIGHT = 3;
|
GameLib.CustomCode.ORIENTATION_RIGHT = 3;
|
||||||
|
|
||||||
GameLib.CustomCode.FOOD_SPEED_INITIAL = 3;
|
GameLib.CustomCode.FOOD_SPEED_INITIAL = 3;
|
||||||
GameLib.CustomCode.MAX_FOOD_ITEMS = 6;
|
GameLib.CustomCode.MAX_FOOD_ITEMS = 6;
|
||||||
|
|
||||||
GameLib.CustomCode.POWERUP_WAIT_TIME_MIN = 5;
|
GameLib.CustomCode.POWERUP_WAIT_TIME_MIN = 5;
|
||||||
GameLib.CustomCode.POWERUP_WAIT_TIME_MAX = 10;
|
GameLib.CustomCode.POWERUP_WAIT_TIME_MAX = 10;
|
||||||
GameLib.CustomCode.POWERUP_DURATION = 7;
|
GameLib.CustomCode.POWERUP_DURATION = 7;
|
||||||
GameLib.CustomCode.POWERUP_SPEED = 0;
|
GameLib.CustomCode.POWERUP_SPEED = 0;
|
||||||
GameLib.CustomCode.POWERUP_LIFE = 1;
|
GameLib.CustomCode.POWERUP_LIFE = 1;
|
||||||
GameLib.CustomCode.POWERUP_SLOW = 2;
|
GameLib.CustomCode.POWERUP_SLOW = 2;
|
||||||
GameLib.CustomCode.MAX_POWERUP_ITEMS = 3;
|
GameLib.CustomCode.MAX_POWERUP_ITEMS = 3;
|
||||||
|
|
||||||
GameLib.CustomCode.FOOD_BACON = 0;
|
GameLib.CustomCode.FOOD_BACON = 0;
|
||||||
GameLib.CustomCode.FOOD_CHEESE = 1;
|
GameLib.CustomCode.FOOD_CHEESE = 1;
|
||||||
GameLib.CustomCode.FOOD_ONION = 2;
|
GameLib.CustomCode.FOOD_ONION = 2;
|
||||||
GameLib.CustomCode.FOOD_ONION_RING = 3;
|
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.BODY_TYPE_BREAD_BACON = 0;
|
GameLib.CustomCode.BODY_TYPE_BREAD_BACON = 0;
|
||||||
GameLib.CustomCode.BODY_TYPE_BREAD_CHEESE = 1;
|
GameLib.CustomCode.BODY_TYPE_BREAD_CHEESE = 1;
|
||||||
GameLib.CustomCode.BODY_TYPE_BREAD_ONION = 2;
|
GameLib.CustomCode.BODY_TYPE_BREAD_ONION = 2;
|
||||||
GameLib.CustomCode.BODY_TYPE_BREAD_ONION_RING = 3;
|
GameLib.CustomCode.BODY_TYPE_BREAD_ONION_RING = 3;
|
||||||
GameLib.CustomCode.BODY_TYPE_BREAD_PATTY = 4;
|
GameLib.CustomCode.BODY_TYPE_BREAD_PATTY = 4;
|
||||||
GameLib.CustomCode.BODY_TYPE_BREAD_HEAD = 5;
|
GameLib.CustomCode.BODY_TYPE_BREAD_TOMATO = 5;
|
||||||
GameLib.CustomCode.BODY_TYPE_BREAD_TAIL = 6;
|
GameLib.CustomCode.BODY_TYPE_BREAD_HEAD = 6;
|
||||||
GameLib.CustomCode.BODY_TYPE_BREAD_CORNER = 7;
|
GameLib.CustomCode.BODY_TYPE_BREAD_TAIL = 7;
|
||||||
|
GameLib.CustomCode.BODY_TYPE_BREAD_CORNER = 8;
|
||||||
|
|
||||||
GameLib.CustomCode.OBJECT_TYPE_NONE = 0;
|
GameLib.CustomCode.OBJECT_TYPE_NONE = 0;
|
||||||
GameLib.CustomCode.OBJECT_TYPE_SNAKE_BODY = 1;
|
GameLib.CustomCode.OBJECT_TYPE_SNAKE_BODY = 1;
|
||||||
GameLib.CustomCode.OBJECT_TYPE_FOOD = 2;
|
GameLib.CustomCode.OBJECT_TYPE_FOOD = 2;
|
||||||
GameLib.CustomCode.OBJECT_TYPE_POWERUP = 3;
|
GameLib.CustomCode.OBJECT_TYPE_POWERUP = 3;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get runtime
|
* Get runtime
|
||||||
*/
|
*/
|
||||||
this.runtime = GameLib.Utils.GetRuntime();
|
this.runtime = GameLib.Utils.GetRuntime();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Custom Code Components
|
* Custom Code Components
|
||||||
*/
|
*/
|
||||||
this.beforeRender = GameLib.EntityManager.Instance.findComponentById('zjq6ach3jt');
|
this.beforeRender = GameLib.EntityManager.Instance.findComponentById('zjq6ach3jt');
|
||||||
this.keyUp = GameLib.EntityManager.Instance.findComponentById('306204wy29');
|
this.keyUp = GameLib.EntityManager.Instance.findComponentById('306204wy29');
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Geometries
|
* Geometries
|
||||||
*/
|
*/
|
||||||
this.geometryBody = GameLib.EntityManager.Instance.findComponentById('8f5q7k5ozp');
|
this.geometryBody = GameLib.EntityManager.Instance.findComponentById('8f5q7k5ozp');
|
||||||
|
|
||||||
GameLib.CustomCode.BODY_SCALE_X = this.geometryBody.width;
|
GameLib.CustomCode.BODY_SCALE_X = this.geometryBody.width;
|
||||||
GameLib.CustomCode.BODY_SCALE_Y = this.geometryBody.height;
|
GameLib.CustomCode.BODY_SCALE_Y = this.geometryBody.height;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Materials
|
* Materials
|
||||||
*/
|
*/
|
||||||
this.materialTomato = GameLib.EntityManager.Instance.findComponentById('merwtvkm1t');
|
this.materialTomato = GameLib.EntityManager.Instance.findComponentById('merwtvkm1t');
|
||||||
this.materialBacon = GameLib.EntityManager.Instance.findComponentById('x5ffcl6ojc');
|
this.materialBacon = GameLib.EntityManager.Instance.findComponentById('x5ffcl6ojc');
|
||||||
this.materialCheese = GameLib.EntityManager.Instance.findComponentById('0rxqy5eddx');
|
this.materialCheese = GameLib.EntityManager.Instance.findComponentById('0rxqy5eddx');
|
||||||
this.materialOnionRing = GameLib.EntityManager.Instance.findComponentById('gz8zex5xug');
|
this.materialOnionRing = GameLib.EntityManager.Instance.findComponentById('gz8zex5xug');
|
||||||
this.materialPatty = GameLib.EntityManager.Instance.findComponentById('f7y8nurbcv');
|
this.materialPatty = GameLib.EntityManager.Instance.findComponentById('f7y8nurbcv');
|
||||||
this.materialOnion = GameLib.EntityManager.Instance.findComponentById('im3tsuzwrp');
|
this.materialOnion = GameLib.EntityManager.Instance.findComponentById('im3tsuzwrp');
|
||||||
this.materialBreadBacon = GameLib.EntityManager.Instance.findComponentById('wn31yqi6lc');
|
this.materialBreadBacon = GameLib.EntityManager.Instance.findComponentById('wn31yqi6lc');
|
||||||
this.materialBreadCheese = GameLib.EntityManager.Instance.findComponentById('i22ixqizge');
|
this.materialBreadCheese = GameLib.EntityManager.Instance.findComponentById('i22ixqizge');
|
||||||
this.materialBreadOnion = GameLib.EntityManager.Instance.findComponentById('69sybcj08d');
|
this.materialBreadOnion = GameLib.EntityManager.Instance.findComponentById('69sybcj08d');
|
||||||
this.materialBreadOnionRing = GameLib.EntityManager.Instance.findComponentById('kvesyjtr2v');
|
this.materialBreadOnionRing = GameLib.EntityManager.Instance.findComponentById('kvesyjtr2v');
|
||||||
this.materialBreadPatty = GameLib.EntityManager.Instance.findComponentById('k6axym9bu5');
|
this.materialBreadPatty = GameLib.EntityManager.Instance.findComponentById('k6axym9bu5');
|
||||||
this.materialBreadHead = GameLib.EntityManager.Instance.findComponentById('heu4f7zzuh');
|
this.materialBreadTomato = GameLib.EntityManager.Instance.findComponentById('9wxuzzz5co');
|
||||||
this.materialBreadTail = GameLib.EntityManager.Instance.findComponentById('mm2yq9rmpf');
|
this.materialBreadHead = GameLib.EntityManager.Instance.findComponentById('heu4f7zzuh');
|
||||||
this.materialBreadCorner = GameLib.EntityManager.Instance.findComponentById('ju9r1bw6cb');
|
this.materialBreadTail = GameLib.EntityManager.Instance.findComponentById('mm2yq9rmpf');
|
||||||
this.materialPowerupSpeed = GameLib.EntityManager.Instance.findComponentById('fb32uutj9q');
|
this.materialBreadCorner = GameLib.EntityManager.Instance.findComponentById('ju9r1bw6cb');
|
||||||
this.materialPowerupLife = GameLib.EntityManager.Instance.findComponentById('6tld70a6zu');
|
this.materialPowerupSpeed = GameLib.EntityManager.Instance.findComponentById('fb32uutj9q');
|
||||||
this.materialPowerupSlow = GameLib.EntityManager.Instance.findComponentById('ulgntj8nta');
|
this.materialPowerupLife = GameLib.EntityManager.Instance.findComponentById('6tld70a6zu');
|
||||||
|
this.materialPowerupSlow = GameLib.EntityManager.Instance.findComponentById('ulgntj8nta');
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Other Objects (Scene)
|
* Other Objects (Scene)
|
||||||
*/
|
*/
|
||||||
this.scene = GameLib.EntityManager.Instance.findComponentById('pllp034hsj');
|
this.scene = GameLib.EntityManager.Instance.findComponentById('pllp034hsj');
|
||||||
this.animation = GameLib.EntityManager.Instance.findComponentById('8kb7utb2fn');
|
this.animation = GameLib.EntityManager.Instance.findComponentById('8kb7utb2fn');
|
||||||
this.animationRotation = GameLib.EntityManager.Instance.findComponentById('z628kythyn');
|
this.animationRotation = GameLib.EntityManager.Instance.findComponentById('z628kythyn');
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 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.food = [];
|
this.food = [];
|
||||||
|
|
||||||
this.powerupTime = 0;
|
this.powerupTime = 0;
|
||||||
this.nextPowerupTime = GameLib.Utils.GetRandomIntInclusive(
|
this.nextPowerupTime = GameLib.Utils.GetRandomIntInclusive(
|
||||||
GameLib.CustomCode.POWERUP_WAIT_TIME_MIN,
|
GameLib.CustomCode.POWERUP_WAIT_TIME_MIN,
|
||||||
GameLib.CustomCode.POWERUP_WAIT_TIME_MAX
|
GameLib.CustomCode.POWERUP_WAIT_TIME_MAX
|
||||||
);
|
);
|
||||||
this.powerups = [];
|
this.powerups = [];
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Orientation is 0, 1, 2 or 3, (up, left, down, right) -
|
* Orientation is 0, 1, 2 or 3, (up, left, down, right) -
|
||||||
* This is also the amount we need to multiply with PI to get the mesh rotation
|
* This is also the amount we need to multiply with PI to get the mesh rotation
|
||||||
* @type {{direction: {x: number, y: number}, orientation: number}}
|
* @type {{direction: {x: number, y: number}, orientation: number}}
|
||||||
*/
|
*/
|
||||||
this.state = {
|
this.state = {
|
||||||
orientation : 0,
|
orientation : 0,
|
||||||
turning : false,
|
turning : false,
|
||||||
flip : 0
|
flip : 0
|
||||||
};
|
};
|
||||||
|
|
||||||
GameLib.CustomCode.prototype.visualizeGrid = function () {
|
GameLib.CustomCode.prototype.visualizeGrid = function () {
|
||||||
|
|
||||||
if (this.noneMesh) {
|
if (this.noneMesh) {
|
||||||
this.scene.instance.remove(this.noneMesh);
|
this.scene.instance.remove(this.noneMesh);
|
||||||
|
@ -222,9 +224,9 @@
|
||||||
this.scene.instance.add(this.powerupMesh);
|
this.scene.instance.add(this.powerupMesh);
|
||||||
this.scene.instance.add(this.snakeMesh);
|
this.scene.instance.add(this.snakeMesh);
|
||||||
|
|
||||||
}.bind(this)
|
}.bind(this)
|
||||||
|
|
||||||
GameLib.CustomCode.prototype.createGameMesh = function(material, visible) {
|
GameLib.CustomCode.prototype.createGameMesh = function(material, visible) {
|
||||||
|
|
||||||
if (GameLib.Utils.UndefinedOrNull(visible)) {
|
if (GameLib.Utils.UndefinedOrNull(visible)) {
|
||||||
visible = true;
|
visible = true;
|
||||||
|
@ -244,9 +246,9 @@
|
||||||
|
|
||||||
return mesh;
|
return mesh;
|
||||||
|
|
||||||
}.bind(this)
|
}.bind(this)
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* GameLib.CustomCode.Object
|
* GameLib.CustomCode.Object
|
||||||
* @param objectType
|
* @param objectType
|
||||||
* @param type
|
* @param type
|
||||||
|
@ -254,12 +256,12 @@
|
||||||
* @param position
|
* @param position
|
||||||
* @constructor
|
* @constructor
|
||||||
*/
|
*/
|
||||||
GameLib.CustomCode.GameObject = function(
|
GameLib.CustomCode.GameObject = function(
|
||||||
objectType,
|
objectType,
|
||||||
type,
|
type,
|
||||||
mesh,
|
mesh,
|
||||||
position
|
position
|
||||||
) {
|
) {
|
||||||
if (GameLib.Utils.UndefinedOrNull(objectType)) {
|
if (GameLib.Utils.UndefinedOrNull(objectType)) {
|
||||||
objectType = GameLib.CustomCode.OBJECT_TYPE_NONE;
|
objectType = GameLib.CustomCode.OBJECT_TYPE_NONE;
|
||||||
}
|
}
|
||||||
|
@ -279,12 +281,12 @@
|
||||||
position = null;
|
position = null;
|
||||||
}
|
}
|
||||||
this.position = position;
|
this.position = position;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Disposes of the mesh object and resets this object to its defaults
|
* Disposes of the mesh object and resets this object to its defaults
|
||||||
*/
|
*/
|
||||||
GameLib.CustomCode.GameObject.prototype.dispose = function(removeMesh) {
|
GameLib.CustomCode.GameObject.prototype.dispose = function(removeMesh) {
|
||||||
|
|
||||||
if (GameLib.Utils.UndefinedOrNull(removeMesh)) {
|
if (GameLib.Utils.UndefinedOrNull(removeMesh)) {
|
||||||
removeMesh = true;
|
removeMesh = true;
|
||||||
|
@ -302,13 +304,13 @@
|
||||||
this.type = -1;
|
this.type = -1;
|
||||||
|
|
||||||
this.position = null;
|
this.position = null;
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Applies the object position to the mesh taking into account the offset and scale of the body
|
* Applies the object position to the mesh taking into account the offset and scale of the body
|
||||||
* @param updateInstance
|
* @param updateInstance
|
||||||
*/
|
*/
|
||||||
GameLib.CustomCode.GameObject.prototype.applyToMesh = function(updateInstance) {
|
GameLib.CustomCode.GameObject.prototype.applyToMesh = function(updateInstance) {
|
||||||
if (this.mesh) {
|
if (this.mesh) {
|
||||||
|
|
||||||
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;
|
||||||
|
@ -319,13 +321,13 @@
|
||||||
this.mesh.updateInstance('position');
|
this.mesh.updateInstance('position');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Scans through the grid, gets all empty positions, and chooses a random one
|
* Scans through the grid, gets all empty positions, and chooses a random one
|
||||||
* @type {function(this:snakeEntityLoaded)}
|
* @type {function(this:snakeEntityLoaded)}
|
||||||
*/
|
*/
|
||||||
GameLib.CustomCode.prototype.getFreeGridPosition = function() {
|
GameLib.CustomCode.prototype.getFreeGridPosition = function() {
|
||||||
|
|
||||||
var x = GameLib.Utils.GetRandomInt(0, GameLib.CustomCode.GRID_WIDTH);
|
var x = GameLib.Utils.GetRandomInt(0, GameLib.CustomCode.GRID_WIDTH);
|
||||||
var y = GameLib.Utils.GetRandomInt(0, GameLib.CustomCode.GRID_HEIGHT);
|
var y = GameLib.Utils.GetRandomInt(0, GameLib.CustomCode.GRID_HEIGHT);
|
||||||
|
@ -335,18 +337,18 @@
|
||||||
y : y
|
y : y
|
||||||
};
|
};
|
||||||
|
|
||||||
}.bind(this);
|
}.bind(this);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* @type {function(this:snakeEntityLoaded)}
|
* @type {function(this:snakeEntityLoaded)}
|
||||||
*/
|
*/
|
||||||
GameLib.CustomCode.prototype.createGameObject = function(
|
GameLib.CustomCode.prototype.createGameObject = function(
|
||||||
objectType,
|
objectType,
|
||||||
type,
|
type,
|
||||||
position,
|
position,
|
||||||
orientation
|
orientation
|
||||||
) {
|
) {
|
||||||
|
|
||||||
if (GameLib.Utils.UndefinedOrNull(type)) {
|
if (GameLib.Utils.UndefinedOrNull(type)) {
|
||||||
type = null;
|
type = null;
|
||||||
|
@ -434,6 +436,9 @@
|
||||||
case GameLib.CustomCode.BODY_TYPE_BREAD_PATTY :
|
case GameLib.CustomCode.BODY_TYPE_BREAD_PATTY :
|
||||||
mesh = this.createGameMesh(this.materialBreadPatty);
|
mesh = this.createGameMesh(this.materialBreadPatty);
|
||||||
break;
|
break;
|
||||||
|
case GameLib.CustomCode.BODY_TYPE_BREAD_TOMATO :
|
||||||
|
mesh = this.createGameMesh(this.materialBreadTomato);
|
||||||
|
break;
|
||||||
case GameLib.CustomCode.BODY_TYPE_BREAD_HEAD :
|
case GameLib.CustomCode.BODY_TYPE_BREAD_HEAD :
|
||||||
mesh = this.createGameMesh(this.materialBreadHead);
|
mesh = this.createGameMesh(this.materialBreadHead);
|
||||||
break;
|
break;
|
||||||
|
@ -544,9 +549,9 @@
|
||||||
|
|
||||||
return gameObject;
|
return gameObject;
|
||||||
|
|
||||||
}.bind(this);
|
}.bind(this);
|
||||||
|
|
||||||
GameLib.CustomCode.prototype.createPowerup = function(delta) {
|
GameLib.CustomCode.prototype.createPowerup = function(delta) {
|
||||||
|
|
||||||
this.powerupTime += delta;
|
this.powerupTime += delta;
|
||||||
|
|
||||||
|
@ -562,9 +567,9 @@
|
||||||
this.getFreeGridPosition()
|
this.getFreeGridPosition()
|
||||||
);
|
);
|
||||||
|
|
||||||
}.bind(this);
|
}.bind(this);
|
||||||
|
|
||||||
GameLib.CustomCode.prototype.createFood = function(delta) {
|
GameLib.CustomCode.prototype.createFood = function(delta) {
|
||||||
|
|
||||||
this.foodTime += delta;
|
this.foodTime += delta;
|
||||||
|
|
||||||
|
@ -580,10 +585,10 @@
|
||||||
this.getFreeGridPosition()
|
this.getFreeGridPosition()
|
||||||
);
|
);
|
||||||
|
|
||||||
}.bind(this);
|
}.bind(this);
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* GameLib.CustomCode.SnakeBody
|
* GameLib.CustomCode.SnakeBody
|
||||||
* @param type
|
* @param type
|
||||||
* @param mesh
|
* @param mesh
|
||||||
|
@ -595,7 +600,7 @@
|
||||||
* @property animation
|
* @property animation
|
||||||
* @constructor
|
* @constructor
|
||||||
*/
|
*/
|
||||||
GameLib.CustomCode.SnakeBody = function(
|
GameLib.CustomCode.SnakeBody = function(
|
||||||
type,
|
type,
|
||||||
mesh,
|
mesh,
|
||||||
position,
|
position,
|
||||||
|
@ -603,7 +608,7 @@
|
||||||
flip,
|
flip,
|
||||||
backupMesh,
|
backupMesh,
|
||||||
isTail
|
isTail
|
||||||
) {
|
) {
|
||||||
|
|
||||||
GameLib.CustomCode.GameObject.call(
|
GameLib.CustomCode.GameObject.call(
|
||||||
this,
|
this,
|
||||||
|
@ -638,12 +643,12 @@
|
||||||
var animation = GameLib.EntityManager.Instance.findComponentById('8kb7utb2fn');
|
var animation = GameLib.EntityManager.Instance.findComponentById('8kb7utb2fn');
|
||||||
|
|
||||||
animation.meshes.push(this.mesh);
|
animation.meshes.push(this.mesh);
|
||||||
};
|
};
|
||||||
|
|
||||||
GameLib.CustomCode.SnakeBody.prototype = Object.create(GameLib.CustomCode.GameObject.prototype);
|
GameLib.CustomCode.SnakeBody.prototype = Object.create(GameLib.CustomCode.GameObject.prototype);
|
||||||
GameLib.CustomCode.SnakeBody.prototype.constructor = GameLib.CustomCode.GameObject;
|
GameLib.CustomCode.SnakeBody.prototype.constructor = GameLib.CustomCode.GameObject;
|
||||||
|
|
||||||
GameLib.CustomCode.SnakeBody.prototype.applyToMesh = function(updateInstance) {
|
GameLib.CustomCode.SnakeBody.prototype.applyToMesh = function(updateInstance) {
|
||||||
|
|
||||||
GameLib.CustomCode.GameObject.prototype.applyToMesh.call(this, updateInstance);
|
GameLib.CustomCode.GameObject.prototype.applyToMesh.call(this, updateInstance);
|
||||||
|
|
||||||
|
@ -656,9 +661,9 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
this.mesh.updateInstance('rotation');
|
this.mesh.updateInstance('rotation');
|
||||||
}
|
}
|
||||||
|
|
||||||
GameLib.CustomCode.SnakeBody.prototype.advance = function(orientation, flip) {
|
GameLib.CustomCode.SnakeBody.prototype.advance = function(orientation, flip) {
|
||||||
|
|
||||||
var crash = false;
|
var crash = false;
|
||||||
|
|
||||||
|
@ -705,9 +710,9 @@
|
||||||
this.flip = flip;
|
this.flip = flip;
|
||||||
|
|
||||||
return !crash;
|
return !crash;
|
||||||
}
|
}
|
||||||
|
|
||||||
GameLib.CustomCode.prototype.initializeGrid = function() {
|
GameLib.CustomCode.prototype.initializeGrid = function() {
|
||||||
|
|
||||||
this.grid = [];
|
this.grid = [];
|
||||||
|
|
||||||
|
@ -718,7 +723,7 @@
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}.bind(this);
|
}.bind(this);
|
||||||
|
|
||||||
// GameLib.CustomCode.prototype.rebuildGrid = function() {
|
// GameLib.CustomCode.prototype.rebuildGrid = function() {
|
||||||
//
|
//
|
||||||
|
@ -766,25 +771,31 @@
|
||||||
// }.bind(this);
|
// }.bind(this);
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Explode the snake
|
* Explode the snake
|
||||||
* @param position
|
* @param position
|
||||||
*/
|
*/
|
||||||
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);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Extend the snake with information from gameObject
|
* Extend the snake with information from gameObject
|
||||||
* @param gameObject
|
* @param gameObject
|
||||||
*/
|
*/
|
||||||
GameLib.CustomCode.prototype.extend = function(gameObject, position, orientation) {
|
GameLib.CustomCode.prototype.extend = function(gameObject, position, orientation) {
|
||||||
|
|
||||||
if (gameObject.objectType !== GameLib.CustomCode.OBJECT_TYPE_FOOD) {
|
if (gameObject.objectType !== GameLib.CustomCode.OBJECT_TYPE_FOOD) {
|
||||||
throw new Error('wrong type of game object');
|
throw new Error('wrong type of game object');
|
||||||
}
|
}
|
||||||
|
|
||||||
var body = null;
|
var body = null;
|
||||||
|
GameLib.CustomCode.FOOD_BACON = 0;
|
||||||
|
GameLib.CustomCode.FOOD_CHEESE = 1;
|
||||||
|
GameLib.CustomCode.FOOD_ONION = 2;
|
||||||
|
GameLib.CustomCode.FOOD_ONION_RING = 3;
|
||||||
|
GameLib.CustomCode.FOOD_PATTY = 4;
|
||||||
|
GameLib.CustomCode.FOOD_TOMATO = 5;
|
||||||
|
|
||||||
switch (gameObject.type) {
|
switch (gameObject.type) {
|
||||||
case GameLib.CustomCode.FOOD_BACON :
|
case GameLib.CustomCode.FOOD_BACON :
|
||||||
|
@ -795,6 +806,46 @@
|
||||||
orientation
|
orientation
|
||||||
)
|
)
|
||||||
break;
|
break;
|
||||||
|
case GameLib.CustomCode.FOOD_CHEESE :
|
||||||
|
body = this.createGameObject(
|
||||||
|
GameLib.CustomCode.OBJECT_TYPE_SNAKE_BODY,
|
||||||
|
GameLib.CustomCode.BODY_TYPE_BREAD_CHEESE,
|
||||||
|
position,
|
||||||
|
orientation
|
||||||
|
)
|
||||||
|
break;
|
||||||
|
case GameLib.CustomCode.FOOD_ONION :
|
||||||
|
body = this.createGameObject(
|
||||||
|
GameLib.CustomCode.OBJECT_TYPE_SNAKE_BODY,
|
||||||
|
GameLib.CustomCode.BODY_TYPE_BREAD_ONION,
|
||||||
|
position,
|
||||||
|
orientation
|
||||||
|
)
|
||||||
|
break;
|
||||||
|
case GameLib.CustomCode.FOOD_ONION_RING :
|
||||||
|
body = this.createGameObject(
|
||||||
|
GameLib.CustomCode.OBJECT_TYPE_SNAKE_BODY,
|
||||||
|
GameLib.CustomCode.BODY_TYPE_BREAD_ONION_RING,
|
||||||
|
position,
|
||||||
|
orientation
|
||||||
|
)
|
||||||
|
break;
|
||||||
|
case GameLib.CustomCode.FOOD_PATTY :
|
||||||
|
body = this.createGameObject(
|
||||||
|
GameLib.CustomCode.OBJECT_TYPE_SNAKE_BODY,
|
||||||
|
GameLib.CustomCode.BODY_TYPE_BREAD_PATTY,
|
||||||
|
position,
|
||||||
|
orientation
|
||||||
|
)
|
||||||
|
break;
|
||||||
|
case GameLib.CustomCode.FOOD_TOMATO :
|
||||||
|
body = this.createGameObject(
|
||||||
|
GameLib.CustomCode.OBJECT_TYPE_SNAKE_BODY,
|
||||||
|
GameLib.CustomCode.BODY_TYPE_BREAD_TOMATO,
|
||||||
|
position,
|
||||||
|
orientation
|
||||||
|
)
|
||||||
|
break;
|
||||||
default :
|
default :
|
||||||
throw new Error('unhandled food type: ' + gameObject.type);
|
throw new Error('unhandled food type: ' + gameObject.type);
|
||||||
}
|
}
|
||||||
|
@ -803,21 +854,21 @@
|
||||||
|
|
||||||
this.snake.splice(1, 0, body);
|
this.snake.splice(1, 0, body);
|
||||||
|
|
||||||
}.bind(this);
|
}.bind(this);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Powerup the snake with information from gameObject
|
* Powerup the snake with information from gameObject
|
||||||
* @param gameObject
|
* @param gameObject
|
||||||
*/
|
*/
|
||||||
GameLib.CustomCode.prototype.powerup = function(gameObject) {
|
GameLib.CustomCode.prototype.powerup = function(gameObject) {
|
||||||
console.log('powerup');
|
console.log('powerup');
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Move the snake forward and do collision detection
|
* Move the snake forward and do collision detection
|
||||||
* @type {function(this:snakeEntityLoaded)}
|
* @type {function(this:snakeEntityLoaded)}
|
||||||
*/
|
*/
|
||||||
GameLib.CustomCode.prototype.advanceSnake = function(delta) {
|
GameLib.CustomCode.prototype.advanceSnake = function(delta) {
|
||||||
|
|
||||||
this.advanceTime += delta;
|
this.advanceTime += delta;
|
||||||
|
|
||||||
|
@ -863,7 +914,7 @@
|
||||||
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);
|
this.extend(gameObject, body.position, body.orientation);
|
||||||
break;
|
break;
|
||||||
case GameLib.CustomCode.OBJECT_TYPE_POWERUP:
|
case GameLib.CustomCode.OBJECT_TYPE_POWERUP:
|
||||||
this.powerup(gameObject);
|
this.powerup(gameObject);
|
||||||
|
@ -1020,9 +1071,9 @@
|
||||||
|
|
||||||
this.visualizeGrid();
|
this.visualizeGrid();
|
||||||
|
|
||||||
}.bind(this);
|
}.bind(this);
|
||||||
|
|
||||||
GameLib.Event.Subscribe(
|
GameLib.Event.Subscribe(
|
||||||
GameLib.Event.GAME_START,
|
GameLib.Event.GAME_START,
|
||||||
function() {
|
function() {
|
||||||
|
|
||||||
|
@ -1103,9 +1154,9 @@
|
||||||
|
|
||||||
console.log('starting game snake');
|
console.log('starting game snake');
|
||||||
}.bind(this)
|
}.bind(this)
|
||||||
);
|
);
|
||||||
|
|
||||||
GameLib.Event.Subscribe(
|
GameLib.Event.Subscribe(
|
||||||
GameLib.Event.GAME_OVER,
|
GameLib.Event.GAME_OVER,
|
||||||
function() {
|
function() {
|
||||||
|
|
||||||
|
@ -1117,8 +1168,8 @@
|
||||||
|
|
||||||
console.log('starting game snake');
|
console.log('starting game snake');
|
||||||
}.bind(this)
|
}.bind(this)
|
||||||
)
|
)
|
||||||
|
|
||||||
GameLib.Event.Emit(GameLib.Event.GAME_LOADED);
|
GameLib.Event.Emit(GameLib.Event.GAME_LOADED);
|
||||||
|
|
||||||
//@ sourceURL=entityLoaded.js
|
//@ sourceURL=entityLoaded.js
|
Loading…
Reference in New Issue