2018-03-12 14:11:01 +01:00
|
|
|
if (this.parentEntity === data.entity) {
|
|
|
|
console.log('snake entity loaded');
|
|
|
|
} else {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
this.runtime = GameLib.Utils.GetRuntime();
|
|
|
|
|
2018-03-12 14:28:27 +01:00
|
|
|
/**
|
|
|
|
* Custom Code Components
|
|
|
|
*/
|
|
|
|
this.beforeRender = GameLib.EntityManager.Instance.findComponentById('zjq6ach3jt');
|
|
|
|
|
2018-03-12 14:11:01 +01:00
|
|
|
/**
|
|
|
|
* Geometries
|
|
|
|
*/
|
2018-03-12 14:12:20 +01:00
|
|
|
this.geometryBody = GameLib.EntityManager.Instance.findComponentById('8f5q7k5ozp');
|
2018-03-12 14:11:01 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Images
|
|
|
|
*/
|
|
|
|
this.imageEnd = GameLib.EntityManager.Instance.findComponentById('swkla3wpp');
|
|
|
|
this.imageBodyPatty = GameLib.EntityManager.Instance.findComponentById('01r51k9ptr');
|
|
|
|
this.imagePatty = GameLib.EntityManager.Instance.findComponentById('4lf0fw24su');
|
|
|
|
|
2018-03-12 14:19:14 +01:00
|
|
|
/**
|
|
|
|
* Other Objects (Scene)
|
|
|
|
*/
|
|
|
|
this.scene = GameLib.EntityManager.Instance.findComponentById('pllp034hsj');
|
|
|
|
|
2018-03-12 14:24:45 +01:00
|
|
|
/**
|
|
|
|
* Game objects
|
|
|
|
*/
|
|
|
|
this.snake = [];
|
|
|
|
|
2018-03-12 14:40:09 +01:00
|
|
|
GameLib.CustomCode.BODY_TYPE_HEAD = 0x1;
|
|
|
|
GameLib.CustomCode.BODY_TYPE_TAIL = 0x2;
|
|
|
|
|
2018-03-12 14:24:45 +01:00
|
|
|
GameLib.CustomCode.prototype.advanceSnake = function(delta) {
|
|
|
|
|
|
|
|
}.bind(this);
|
|
|
|
|
2018-03-12 14:40:09 +01:00
|
|
|
GameLib.CustomCode.prototype.cloneBody = function(bodyType) {
|
|
|
|
|
|
|
|
var body = null;
|
|
|
|
|
|
|
|
switch (bodyType) {
|
|
|
|
case (GameLib.CustomCode.BODY_TYPE_HEAD) :
|
|
|
|
body = this.meshEnd.clone();
|
|
|
|
break;
|
|
|
|
case (GameLib.CustomCode.BODY_TYPE_TAIL) :
|
|
|
|
body = this.meshEnd.clone();
|
|
|
|
body.rotation.z = Math.PI;
|
|
|
|
body.updateInstance('rotation');
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
console.warn('unhandled body type : ' + bodyType);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return body;
|
|
|
|
|
|
|
|
}.bind(this);
|
|
|
|
|
2018-03-12 14:11:01 +01:00
|
|
|
GameLib.CustomCode.prototype.createMaterial = function(image) {
|
|
|
|
var diffuseMap = new GameLib.D3.Texture.Image(
|
|
|
|
this.runtime.graphics,
|
|
|
|
{
|
|
|
|
image : image
|
|
|
|
}
|
|
|
|
)
|
|
|
|
|
|
|
|
return new GameLib.D3.Material.Phong(
|
|
|
|
this.runtime.graphics,
|
|
|
|
{
|
|
|
|
diffuseMap : diffuseMap
|
|
|
|
}
|
|
|
|
);
|
|
|
|
}.bind(this);
|
|
|
|
|
|
|
|
GameLib.CustomCode.prototype.createGameMesh = function(image) {
|
2018-03-12 14:16:02 +01:00
|
|
|
|
|
|
|
var mesh = new GameLib.D3.Mesh(
|
2018-03-12 14:13:06 +01:00
|
|
|
this.runtime.graphics,
|
2018-03-12 14:11:01 +01:00
|
|
|
{
|
|
|
|
geometry : this.geometryBody,
|
2018-03-12 14:13:30 +01:00
|
|
|
materials : [this.createMaterial(image)]
|
2018-03-12 14:11:01 +01:00
|
|
|
}
|
|
|
|
)
|
|
|
|
|
2018-03-12 14:19:14 +01:00
|
|
|
this.scene.addClone(mesh);
|
2018-03-12 14:16:02 +01:00
|
|
|
|
2018-03-12 14:11:01 +01:00
|
|
|
}.bind(this)
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Create our objects
|
|
|
|
*/
|
2018-03-12 14:40:09 +01:00
|
|
|
this.meshEnd = this.createGameMesh(this.imageEnd);
|
2018-03-12 14:19:14 +01:00
|
|
|
this.meshPatty = this.createGameMesh(this.imagePatty);
|
|
|
|
this.meshBodyPatty = this.createGameMesh(this.imageBodyPatty);
|
2018-03-12 14:11:01 +01:00
|
|
|
|
|
|
|
GameLib.Event.Subscribe(
|
|
|
|
GameLib.Event.GAME_START,
|
|
|
|
function() {
|
2018-03-12 14:24:45 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Remove all existing snake parts
|
|
|
|
*/
|
|
|
|
this.snake.map(
|
|
|
|
function(body) {
|
|
|
|
body.geometry = null;
|
|
|
|
body.materials = null;
|
|
|
|
body.remove();
|
|
|
|
}
|
|
|
|
)
|
|
|
|
|
2018-03-12 14:40:59 +01:00
|
|
|
this.snake = [
|
|
|
|
this.cloneBody(GameLib.CustomCode.BODY_TYPE_HEAD),
|
|
|
|
this.cloneBody(GameLib.CustomCode.BODY_TYPE_TAIL)
|
|
|
|
];
|
2018-03-12 14:24:45 +01:00
|
|
|
|
2018-03-12 14:28:27 +01:00
|
|
|
this.beforeRender.initialized = false;
|
|
|
|
this.beforeRender.entityLoaded = this;
|
2018-03-12 14:25:46 +01:00
|
|
|
|
2018-03-12 14:28:27 +01:00
|
|
|
console.log('starting game snake');
|
|
|
|
}.bind(this)
|
|
|
|
);
|
|
|
|
|
|
|
|
GameLib.Event.Subscribe(
|
|
|
|
GameLib.Event.GAME_OVER,
|
|
|
|
function() {
|
|
|
|
|
|
|
|
this.beforeRender.entityLoaded = null;
|
|
|
|
this.beforeRender.initialized = false;
|
2018-03-12 14:25:46 +01:00
|
|
|
|
2018-03-12 14:11:01 +01:00
|
|
|
console.log('starting game snake');
|
2018-03-12 14:25:46 +01:00
|
|
|
}.bind(this)
|
2018-03-12 14:11:01 +01:00
|
|
|
)
|
|
|
|
|
|
|
|
GameLib.Event.Emit(GameLib.Event.GAME_LOADED);
|
|
|
|
|
|
|
|
//@ sourceURL=entityLoaded.js
|