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

beta.r3js.org
-=yb4f310 2018-03-22 12:31:24 +01:00
parent 02e5d40445
commit 1f0b599d61
1 changed files with 983 additions and 960 deletions

View File

@ -1,140 +1,140 @@
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_HEAD = 5;
GameLib.CustomCode.BODY_TYPE_BREAD_TAIL = 6;
GameLib.CustomCode.BODY_TYPE_BREAD_CORNER = 7;
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.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 +222,9 @@ GameLib.CustomCode.prototype.visualizeGrid = function () {
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 +244,9 @@ GameLib.CustomCode.prototype.createGameMesh = function(material, visible) {
return mesh;
}.bind(this)
}.bind(this)
/**
/**
* GameLib.CustomCode.Object
* @param objectType
* @param type
@ -254,12 +254,12 @@ GameLib.CustomCode.prototype.createGameMesh = function(material, visible) {
* @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 +279,12 @@ GameLib.CustomCode.GameObject = function(
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 +302,13 @@ GameLib.CustomCode.GameObject.prototype.dispose = function(removeMesh) {
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 +319,13 @@ GameLib.CustomCode.GameObject.prototype.applyToMesh = function(updateInstance) {
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 +335,18 @@ GameLib.CustomCode.prototype.getFreeGridPosition = function() {
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;
@ -544,9 +544,9 @@ GameLib.CustomCode.prototype.createGameObject = function(
return gameObject;
}.bind(this);
}.bind(this);
GameLib.CustomCode.prototype.createPowerup = function(delta) {
GameLib.CustomCode.prototype.createPowerup = function(delta) {
this.powerupTime += delta;
@ -562,9 +562,9 @@ GameLib.CustomCode.prototype.createPowerup = function(delta) {
this.getFreeGridPosition()
);
}.bind(this);
}.bind(this);
GameLib.CustomCode.prototype.createFood = function(delta) {
GameLib.CustomCode.prototype.createFood = function(delta) {
this.foodTime += delta;
@ -580,10 +580,10 @@ GameLib.CustomCode.prototype.createFood = function(delta) {
this.getFreeGridPosition()
);
}.bind(this);
}.bind(this);
/**
/**
* GameLib.CustomCode.SnakeBody
* @param type
* @param mesh
@ -595,7 +595,7 @@ GameLib.CustomCode.prototype.createFood = function(delta) {
* @property animation
* @constructor
*/
GameLib.CustomCode.SnakeBody = function(
GameLib.CustomCode.SnakeBody = function(
type,
mesh,
position,
@ -603,7 +603,7 @@ GameLib.CustomCode.SnakeBody = function(
flip,
backupMesh,
isTail
) {
) {
GameLib.CustomCode.GameObject.call(
this,
@ -638,12 +638,12 @@ GameLib.CustomCode.SnakeBody = function(
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 +656,9 @@ GameLib.CustomCode.SnakeBody.prototype.applyToMesh = function(updateInstance) {
}
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 +705,9 @@ GameLib.CustomCode.SnakeBody.prototype.advance = function(orientation, flip) {
this.flip = flip;
return !crash;
}
}
GameLib.CustomCode.prototype.initializeGrid = function() {
GameLib.CustomCode.prototype.initializeGrid = function() {
this.grid = [];
@ -718,7 +718,7 @@ GameLib.CustomCode.prototype.initializeGrid = function() {
}
}
}.bind(this);
}.bind(this);
// GameLib.CustomCode.prototype.rebuildGrid = function() {
//
@ -766,35 +766,58 @@ GameLib.CustomCode.prototype.initializeGrid = function() {
// }.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) {
console.log('extend');
};
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;
switch (gameObject.type) {
case GameLib.CustomCode.FOOD_BACON :
body = this.createGameObject(
GameLib.CustomCode.OBJECT_TYPE_SNAKE_BODY,
GameLib.CustomCode.BODY_TYPE_BREAD_BACON,
position,
orientation
)
break;
default :
throw new Error('unhandled food type: ' + gameObject.type);
}
this.state.eating = true;
this.snake.splice(1, 0, body);
}.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;
@ -997,9 +1020,9 @@ GameLib.CustomCode.prototype.advanceSnake = function(delta) {
this.visualizeGrid();
}.bind(this);
}.bind(this);
GameLib.Event.Subscribe(
GameLib.Event.Subscribe(
GameLib.Event.GAME_START,
function() {
@ -1080,9 +1103,9 @@ GameLib.Event.Subscribe(
console.log('starting game snake');
}.bind(this)
);
);
GameLib.Event.Subscribe(
GameLib.Event.Subscribe(
GameLib.Event.GAME_OVER,
function() {
@ -1094,8 +1117,8 @@ GameLib.Event.Subscribe(
console.log('starting game snake');
}.bind(this)
)
)
GameLib.Event.Emit(GameLib.Event.GAME_LOADED);
GameLib.Event.Emit(GameLib.Event.GAME_LOADED);
//@ sourceURL=entityLoaded.js