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

beta.r3js.org
-=yb4f310 2018-03-22 11:42:43 +01:00
parent d911d08872
commit 9ab9bf503b
1 changed files with 29 additions and 76 deletions

View File

@ -191,15 +191,13 @@ GameLib.CustomCode.prototype.createGameMesh = function(material, visible) {
* @param type * @param type
* @param mesh * @param mesh
* @param position * @param position
* @param index
* @constructor * @constructor
*/ */
GameLib.CustomCode.GameObject = function( GameLib.CustomCode.GameObject = function(
objectType, objectType,
type, type,
mesh, mesh,
position, position
index
) { ) {
if (GameLib.Utils.UndefinedOrNull(objectType)) { if (GameLib.Utils.UndefinedOrNull(objectType)) {
objectType = GameLib.CustomCode.OBJECT_TYPE_NONE; objectType = GameLib.CustomCode.OBJECT_TYPE_NONE;
@ -220,11 +218,6 @@ GameLib.CustomCode.GameObject = function(
position = null; position = null;
} }
this.position = position; this.position = position;
if (GameLib.Utils.UndefinedOrNull(index)) {
index = -1;
}
this.index = index;
} }
/** /**
@ -235,7 +228,7 @@ GameLib.CustomCode.GameObject.prototype.dispose = function(removeMesh) {
if (GameLib.Utils.UndefinedOrNull(removeMesh)) { if (GameLib.Utils.UndefinedOrNull(removeMesh)) {
removeMesh = true; removeMesh = true;
} }
if (this.mesh && removeMesh) { if (this.mesh && removeMesh) {
this.mesh.geometry = null; this.mesh.geometry = null;
this.mesh.materials = null; this.mesh.materials = null;
@ -248,8 +241,6 @@ GameLib.CustomCode.GameObject.prototype.dispose = function(removeMesh) {
this.type = -1; this.type = -1;
this.position = null; this.position = null;
this.index = -1;
}; };
/** /**
@ -400,8 +391,7 @@ GameLib.CustomCode.prototype.createGameObject = function(
objectType, objectType,
type, type,
mesh, mesh,
position, position
array.length
) )
gameObject.applyToMesh(true); gameObject.applyToMesh(true);
break; break;
@ -410,7 +400,6 @@ GameLib.CustomCode.prototype.createGameObject = function(
type, type,
mesh, mesh,
position, position,
array.length,
orientation orientation
) )
gameObject.applyToMesh(true); gameObject.applyToMesh(true);
@ -518,18 +507,17 @@ GameLib.CustomCode.prototype.createFood = function(delta) {
* @param type * @param type
* @param mesh * @param mesh
* @param position * @param position
* @param index
* @param orientation * @param orientation
* @param flip * @param flip
* @param backupMesh * @param backupMesh
* @param isTail * @param isTail
* @property animation
* @constructor * @constructor
*/ */
GameLib.CustomCode.SnakeBody = function( GameLib.CustomCode.SnakeBody = function(
type, type,
mesh, mesh,
position, position,
index,
orientation, orientation,
flip, flip,
backupMesh, backupMesh,
@ -541,10 +529,9 @@ GameLib.CustomCode.SnakeBody = function(
GameLib.Object.OBJECT_TYPE_SNAKE_BODY, GameLib.Object.OBJECT_TYPE_SNAKE_BODY,
type, type,
mesh, mesh,
position, position
index
); );
if (GameLib.Utils.UndefinedOrNull(orientation)) { if (GameLib.Utils.UndefinedOrNull(orientation)) {
orientation = GameLib.CustomCode.ORIENTATION_UP; orientation = GameLib.CustomCode.ORIENTATION_UP;
} }
@ -566,6 +553,10 @@ GameLib.CustomCode.SnakeBody = function(
this.isTail = isTail; this.isTail = isTail;
this.applyToMesh(); this.applyToMesh();
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 = Object.create(GameLib.CustomCode.GameObject.prototype);
@ -756,13 +747,13 @@ GameLib.CustomCode.prototype.advanceSnake = function(delta) {
); );
if (!advanced) { if (!advanced) {
this.explode(body.position); this.explode(body.position);
} else { } else {
var gameObject = this.grid[body.position.x][body.position.y]; var gameObject = this.grid[body.position.x][body.position.y];
switch (gameObject.objectType) { switch (gameObject.objectType) {
case GameLib.CustomCode.OBJECT_TYPE_SNAKE_BODY : case GameLib.CustomCode.OBJECT_TYPE_SNAKE_BODY :
this.explode(body.position); this.explode(body.position);
@ -780,15 +771,15 @@ GameLib.CustomCode.prototype.advanceSnake = function(delta) {
this.grid[body.position.x][body.position.y] = body; this.grid[body.position.x][body.position.y] = body;
break; break;
} }
/** /**
* Food or powerup objects need to be destroyed before being replaced with a body object * Food or powerup objects need to be destroyed before being replaced with a body object
*/ */
if ( if (
gameObject.objectType === GameLib.CustomCode.OBJECT_TYPE_FOOD || gameObject.objectType === GameLib.CustomCode.OBJECT_TYPE_FOOD ||
gameObject.objectType === GameLib.CustomCode.OBJECT_TYPE_POWERUP gameObject.objectType === GameLib.CustomCode.OBJECT_TYPE_POWERUP
) { ) {
if (gameObject.objectType === GameLib.CustomCode.OBJECT_TYPE_FOOD) { if (gameObject.objectType === GameLib.CustomCode.OBJECT_TYPE_FOOD) {
this.food.splice( this.food.splice(
this.food.indexOf(gameObject), this.food.indexOf(gameObject),
@ -802,7 +793,7 @@ GameLib.CustomCode.prototype.advanceSnake = function(delta) {
} }
gameObject.dispose(); gameObject.dispose();
this.grid[body.position.x][body.position.y] = body; this.grid[body.position.x][body.position.y] = body;
} }
@ -840,7 +831,7 @@ GameLib.CustomCode.prototype.advanceSnake = function(delta) {
* Update the grid with our new body * Update the grid with our new body
*/ */
this.grid[body.position.x][body.position.y] = body; this.grid[body.position.x][body.position.y] = body;
if (body.backupMesh) { if (body.backupMesh) {
/** /**
* We used to be a corner, change back * We used to be a corner, change back
@ -895,7 +886,7 @@ GameLib.CustomCode.prototype.advanceSnake = function(delta) {
//body.backupMesh.visible = false; //body.backupMesh.visible = false;
//body.backupMesh.updateInstance('visible'); //body.backupMesh.updateInstance('visible');
body.mesh = this.createGameMesh(this.materialBreadCorner); body.mesh = this.createGameMesh(this.materialBreadCorner);
@ -934,25 +925,19 @@ GameLib.Event.Subscribe(
*/ */
this.snake.map( this.snake.map(
function(body) { function(body) {
body.mesh.geometry = null; body.dispose();
body.mesh.materials = null;
body.mesh.remove();
} }
) )
this.food.map( this.food.map(
function(food) { function(food) {
food.mesh.geometry = null; food.dispose();
food.mesh.materials = null;
food.mesh.remove();
} }
) )
this.powerups.map( this.powerups.map(
function(powerup) { function(powerup) {
powerup.mesh.geometry = null; powerup.dispose();
powerup.mesh.materials = null;
powerup.mesh.remove();
} }
); );
@ -962,57 +947,25 @@ GameLib.Event.Subscribe(
this.snake = [ this.snake = [
new GameLib.CustomCode.SnakeBody( new GameLib.CustomCode.SnakeBody(
this.createGameMesh(this.materialBreadHead), GameLib.CustomCode.BODY_TYPE_BREAD_HEAD,
{ {
x : 4, x : 4,
y : 4 y : 4
}, },
0 GameLib.CustomCode.ORIENTATION_UP
), ),
new GameLib.CustomCode.SnakeBody( new GameLib.CustomCode.SnakeBody(
this.createGameMesh(this.materialBreadPatty), GameLib.CustomCode.BODY_TYPE_BREAD_TAIL,
{ {
x : 4, x : 4,
y : 3 y : 3
}, },
0 GameLib.CustomCode.ORIENTATION_UP
),
new GameLib.CustomCode.SnakeBody(
this.createGameMesh(this.materialBreadPatty),
{
x : 4,
y : 2
},
0
),
new GameLib.CustomCode.SnakeBody(
this.createGameMesh(this.materialBreadTail),
{
x : 4,
y : 1
},
0,
0,
null,
true
) )
]; ];
this.snake[0].mesh.updateInstance('position');
this.snake[1].mesh.updateInstance('position');
this.snake[2].mesh.updateInstance('position');
this.snake[3].mesh.updateInstance('position');
this.animation.meshes.push(this.snake[0].mesh);
this.animation.meshes.push(this.snake[1].mesh);
this.animation.meshes.push(this.snake[2].mesh);
this.animation.meshes.push(this.snake[3].mesh);
//this.snake[2].mesh.instance.add(this.snake[3].mesh.instance);
//this.animationRotation.meshes.push(this.snake[3].mesh);
this.initializeGrid(); this.initializeGrid();
//this.visualizeGrid(); //this.visualizeGrid();
/** /**
* Other Settings * Other Settings