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