Update: CC - Snake FS - Entity Loaded (21g30t1e75.js) 1109 bytes modified
parent
ba85f03469
commit
5edc015d0d
145
21g30t1e75.js
145
21g30t1e75.js
|
@ -1,78 +1,76 @@
|
|||
function snakeEntityLoaded(data) {
|
||||
|
||||
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_NORMAL = 0x1;
|
||||
GameLib.CustomCode.BODY_TYPE_TAIL = 0x2;
|
||||
|
||||
GameLib.CustomCode.GRID_WIDTH = 11;
|
||||
GameLib.CustomCode.GRID_HEIGHT = 11;
|
||||
GameLib.CustomCode.GRID_WIDTH = 11;
|
||||
GameLib.CustomCode.GRID_HEIGHT = 11;
|
||||
|
||||
GameLib.CustomCode.GRID_OFFSET_X = 1;
|
||||
GameLib.CustomCode.GRID_OFFSET_Y = 5;
|
||||
GameLib.CustomCode.GRID_OFFSET_X = 1;
|
||||
GameLib.CustomCode.GRID_OFFSET_Y = 5;
|
||||
|
||||
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;
|
||||
|
||||
/**
|
||||
/**
|
||||
* 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');
|
||||
|
||||
/**
|
||||
/**
|
||||
* Images
|
||||
*/
|
||||
this.imageBreadHead = GameLib.EntityManager.Instance.findComponentById('swkla3wpp');
|
||||
this.imageBreadTail = GameLib.EntityManager.Instance.findComponentById('se6qlnmojd');
|
||||
this.imageBreadPatty = GameLib.EntityManager.Instance.findComponentById('01r51k9ptr');
|
||||
this.imageBreadCorner = GameLib.EntityManager.Instance.findComponentById('iljpuouaok');
|
||||
this.imagePatty = GameLib.EntityManager.Instance.findComponentById('4lf0fw24su');
|
||||
this.imageBreadHead = GameLib.EntityManager.Instance.findComponentById('swkla3wpp');
|
||||
this.imageBreadTail = GameLib.EntityManager.Instance.findComponentById('se6qlnmojd');
|
||||
this.imageBreadPatty = GameLib.EntityManager.Instance.findComponentById('01r51k9ptr');
|
||||
this.imageBreadCorner = GameLib.EntityManager.Instance.findComponentById('iljpuouaok');
|
||||
this.imagePatty = GameLib.EntityManager.Instance.findComponentById('4lf0fw24su');
|
||||
|
||||
/**
|
||||
/**
|
||||
* Other Objects (Scene)
|
||||
*/
|
||||
this.scene = GameLib.EntityManager.Instance.findComponentById('pllp034hsj');
|
||||
this.scene = GameLib.EntityManager.Instance.findComponentById('pllp034hsj');
|
||||
|
||||
/**
|
||||
/**
|
||||
* Game objects
|
||||
*/
|
||||
this.snake = [];
|
||||
this.grid = [];
|
||||
this.speed = GameLib.CustomCode.SPEED_INITIAL;
|
||||
this.advanceTime = 0;
|
||||
this.snake = [];
|
||||
this.grid = [];
|
||||
this.speed = GameLib.CustomCode.SPEED_INITIAL;
|
||||
this.advanceTime = 0;
|
||||
|
||||
/**
|
||||
/**
|
||||
* 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
|
||||
};
|
||||
};
|
||||
|
||||
GameLib.CustomCode.prototype.createMaterial = function(image) {
|
||||
GameLib.CustomCode.prototype.createMaterial = function(image) {
|
||||
var diffuseMap = new GameLib.D3.Texture.Image(
|
||||
this.runtime.graphics,
|
||||
{
|
||||
|
@ -86,9 +84,9 @@ function snakeEntityLoaded(data) {
|
|||
diffuseMap : diffuseMap
|
||||
}
|
||||
);
|
||||
}.bind(this);
|
||||
}.bind(this);
|
||||
|
||||
GameLib.CustomCode.prototype.createGameMesh = function(image) {
|
||||
GameLib.CustomCode.prototype.createGameMesh = function(image) {
|
||||
|
||||
var mesh = new GameLib.D3.Mesh(
|
||||
this.runtime.graphics,
|
||||
|
@ -102,37 +100,37 @@ function snakeEntityLoaded(data) {
|
|||
|
||||
return mesh;
|
||||
|
||||
}.bind(this)
|
||||
}.bind(this)
|
||||
|
||||
/**
|
||||
/**
|
||||
* Create our objects
|
||||
*/
|
||||
this.meshBreadHead = this.createGameMesh(this.imageBreadHead);
|
||||
this.meshBreadHead.useQuaternion = false;
|
||||
this.meshBreadHead = this.createGameMesh(this.imageBreadHead);
|
||||
this.meshBreadHead.useQuaternion = false;
|
||||
|
||||
this.meshBreadTail = this.createGameMesh(this.imageBreadTail);
|
||||
this.meshBreadTail.useQuaternion = false;
|
||||
this.meshBreadTail = this.createGameMesh(this.imageBreadTail);
|
||||
this.meshBreadTail.useQuaternion = false;
|
||||
|
||||
this.meshBreadPatty = this.createGameMesh(this.imageBreadPatty);
|
||||
this.meshBreadPatty.useQuaternion = false;
|
||||
this.meshBreadPatty = this.createGameMesh(this.imageBreadPatty);
|
||||
this.meshBreadPatty.useQuaternion = false;
|
||||
|
||||
this.meshBreadCorner = this.createGameMesh(this.imageBreadCorner);
|
||||
this.meshBreadCorner.useQuaternion = false;
|
||||
this.meshBreadCorner = this.createGameMesh(this.imageBreadCorner);
|
||||
this.meshBreadCorner.useQuaternion = false;
|
||||
|
||||
this.meshPatty = this.createGameMesh(this.imagePatty);
|
||||
this.meshPatty = this.createGameMesh(this.imagePatty);
|
||||
|
||||
/**
|
||||
/**
|
||||
* GameLib.CustomCode.SnakeBody
|
||||
* @param mesh
|
||||
* @param position
|
||||
* @param orientation
|
||||
* @constructor
|
||||
*/
|
||||
GameLib.CustomCode.SnakeBody = function(
|
||||
GameLib.CustomCode.SnakeBody = function(
|
||||
mesh,
|
||||
position,
|
||||
orientation
|
||||
) {
|
||||
) {
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(mesh)) {
|
||||
throw new Error('no mesh specified');
|
||||
|
@ -153,9 +151,9 @@ function snakeEntityLoaded(data) {
|
|||
this.orientation = orientation;
|
||||
|
||||
this.applyToMesh();
|
||||
};
|
||||
};
|
||||
|
||||
GameLib.CustomCode.SnakeBody.prototype.applyToMesh = function() {
|
||||
GameLib.CustomCode.SnakeBody.prototype.applyToMesh = function() {
|
||||
|
||||
this.mesh.position.x = this.position.x + GameLib.CustomCode.GRID_OFFSET_X;
|
||||
this.mesh.position.y = this.position.y + GameLib.CustomCode.GRID_OFFSET_Y;
|
||||
|
@ -167,9 +165,9 @@ function snakeEntityLoaded(data) {
|
|||
*/
|
||||
this.mesh.updateInstance('position');
|
||||
this.mesh.updateInstance('rotation');
|
||||
}
|
||||
}
|
||||
|
||||
GameLib.CustomCode.SnakeBody.prototype.advance = function(orientation) {
|
||||
GameLib.CustomCode.SnakeBody.prototype.advance = function(orientation) {
|
||||
|
||||
if (orientation === GameLib.CustomCode.ORIENTATION_UP) {
|
||||
this.position.y += 1;
|
||||
|
@ -188,9 +186,9 @@ function snakeEntityLoaded(data) {
|
|||
}
|
||||
|
||||
this.orientation = orientation;
|
||||
}
|
||||
}
|
||||
|
||||
GameLib.CustomCode.prototype.advanceSnake = function(delta) {
|
||||
GameLib.CustomCode.prototype.advanceSnake = function(delta) {
|
||||
|
||||
this.advanceTime += delta;
|
||||
|
||||
|
@ -240,10 +238,10 @@ function snakeEntityLoaded(data) {
|
|||
}.bind(this)
|
||||
);
|
||||
|
||||
}.bind(this);
|
||||
}.bind(this);
|
||||
|
||||
/*
|
||||
GameLib.CustomCode.prototype.initializeGrid = function() {
|
||||
/*
|
||||
GameLib.CustomCode.prototype.initializeGrid = function() {
|
||||
|
||||
this.grid = [];
|
||||
|
||||
|
@ -260,10 +258,10 @@ function snakeEntityLoaded(data) {
|
|||
}
|
||||
}
|
||||
|
||||
}.bind(this);
|
||||
*/
|
||||
}.bind(this);
|
||||
*/
|
||||
|
||||
GameLib.Event.Subscribe(
|
||||
GameLib.Event.Subscribe(
|
||||
GameLib.Event.GAME_START,
|
||||
function() {
|
||||
|
||||
|
@ -351,9 +349,9 @@ function snakeEntityLoaded(data) {
|
|||
|
||||
console.log('starting game snake');
|
||||
}.bind(this)
|
||||
);
|
||||
);
|
||||
|
||||
GameLib.Event.Subscribe(
|
||||
GameLib.Event.Subscribe(
|
||||
GameLib.Event.GAME_OVER,
|
||||
function() {
|
||||
|
||||
|
@ -365,9 +363,8 @@ function snakeEntityLoaded(data) {
|
|||
|
||||
console.log('starting game snake');
|
||||
}.bind(this)
|
||||
)
|
||||
)
|
||||
|
||||
GameLib.Event.Emit(GameLib.Event.GAME_LOADED);
|
||||
GameLib.Event.Emit(GameLib.Event.GAME_LOADED);
|
||||
|
||||
//@ sourceURL=entityLoaded.js
|
||||
}
|
Loading…
Reference in New Issue