Update: CC - Snake FS - Entity Loaded (21g30t1e75.js) 1442 bytes modified

beta.r3js.org
-=yb4f310 2018-03-22 12:39:19 +01:00
parent 1f0b599d61
commit b02a42f6e2
1 changed files with 1038 additions and 987 deletions

View File

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