Update: CC - Snake FS - Entity Loaded (21g30t1e75.js) 1387 bytes modified
parent
4956323ad7
commit
40311bb233
274
21g30t1e75.js
274
21g30t1e75.js
|
@ -157,8 +157,7 @@ this.state = {
|
||||||
exploding : false,
|
exploding : false,
|
||||||
lives : 3,
|
lives : 3,
|
||||||
getReady : false,
|
getReady : false,
|
||||||
message : null,
|
message : null
|
||||||
overrideOrientation : false
|
|
||||||
};
|
};
|
||||||
|
|
||||||
GameLib.CustomCode.prototype.displayHUD = function() {
|
GameLib.CustomCode.prototype.displayHUD = function() {
|
||||||
|
@ -204,9 +203,9 @@ GameLib.CustomCode.prototype.displayHUD = function() {
|
||||||
this.canvasHUD.text('xtra', 420, 480, '12px Pixeled', '#ffffff');
|
this.canvasHUD.text('xtra', 420, 480, '12px Pixeled', '#ffffff');
|
||||||
this.canvasHUD.text('slow', 420, 500, '12px Pixeled', '#ffffff');
|
this.canvasHUD.text('slow', 420, 500, '12px Pixeled', '#ffffff');
|
||||||
|
|
||||||
if (this.state.message) {
|
if (this.state.message) {
|
||||||
this.canvasHUD.text(this.state.message, 220, 250, '30px Pixeled', '#ffffff');
|
this.canvasHUD.text(this.state.message, 220, 250, '30px Pixeled', '#ffffff');
|
||||||
}
|
}
|
||||||
|
|
||||||
this.canvasHUD.image(this.imagePowerupSpeed.instance, 50, 460, 48, 48);
|
this.canvasHUD.image(this.imagePowerupSpeed.instance, 50, 460, 48, 48);
|
||||||
this.canvasHUD.image(this.imagePowerupLife.instance, 205, 460, 48, 48);
|
this.canvasHUD.image(this.imagePowerupLife.instance, 205, 460, 48, 48);
|
||||||
|
@ -235,11 +234,9 @@ GameLib.CustomCode.prototype.waitReload = function(delta) {
|
||||||
|
|
||||||
this.state.exploding = false;
|
this.state.exploding = false;
|
||||||
|
|
||||||
this.state.getReady = true;
|
this.state.getReady = true;
|
||||||
|
|
||||||
this.advanceSnake(this.speed * 2);
|
window.setTimeout(
|
||||||
|
|
||||||
window.setTimeout(
|
|
||||||
function(){
|
function(){
|
||||||
this.state.message = null;
|
this.state.message = null;
|
||||||
this.displayHUD();
|
this.displayHUD();
|
||||||
|
@ -247,7 +244,6 @@ GameLib.CustomCode.prototype.waitReload = function(delta) {
|
||||||
5000
|
5000
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
||||||
window.setTimeout(
|
window.setTimeout(
|
||||||
function(){
|
function(){
|
||||||
this.state.message = "GO!";
|
this.state.message = "GO!";
|
||||||
|
@ -289,8 +285,6 @@ GameLib.CustomCode.prototype.waitReload = function(delta) {
|
||||||
|
|
||||||
GameLib.CustomCode.prototype.visualizeGrid = function () {
|
GameLib.CustomCode.prototype.visualizeGrid = function () {
|
||||||
|
|
||||||
return;
|
|
||||||
|
|
||||||
if (this.noneMesh) {
|
if (this.noneMesh) {
|
||||||
this.scene.instance.remove(this.noneMesh);
|
this.scene.instance.remove(this.noneMesh);
|
||||||
}
|
}
|
||||||
|
@ -651,7 +645,7 @@ GameLib.CustomCode.prototype.createGameObject = function(
|
||||||
break;
|
break;
|
||||||
case GameLib.CustomCode.OBJECT_TYPE_SNAKE_BODY:
|
case GameLib.CustomCode.OBJECT_TYPE_SNAKE_BODY:
|
||||||
|
|
||||||
gameObject = new GameLib.CustomCode.SnakeBody(
|
gameObject = new GameLib.CustomCode.SnakeBody(
|
||||||
type,
|
type,
|
||||||
mesh,
|
mesh,
|
||||||
position,
|
position,
|
||||||
|
@ -662,7 +656,7 @@ GameLib.CustomCode.prototype.createGameObject = function(
|
||||||
)
|
)
|
||||||
gameObject.applyToMesh(true);
|
gameObject.applyToMesh(true);
|
||||||
|
|
||||||
this.animation.meshes.push(gameObject.mesh);
|
this.animation.meshes.push(gameObject.mesh);
|
||||||
|
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
|
@ -839,27 +833,27 @@ GameLib.CustomCode.SnakeBody.prototype = Object.create(GameLib.CustomCode.GameOb
|
||||||
GameLib.CustomCode.SnakeBody.prototype.constructor = GameLib.CustomCode.GameObject;
|
GameLib.CustomCode.SnakeBody.prototype.constructor = GameLib.CustomCode.GameObject;
|
||||||
|
|
||||||
GameLib.CustomCode.SnakeBody.prototype.dispose = function() {
|
GameLib.CustomCode.SnakeBody.prototype.dispose = function() {
|
||||||
GameLib.CustomCode.GameObject.prototype.dispose.call(this);
|
GameLib.CustomCode.GameObject.prototype.dispose.call(this);
|
||||||
if (this.backupMesh) {
|
if (this.backupMesh) {
|
||||||
this.backupMesh.geometry = null;
|
this.backupMesh.geometry = null;
|
||||||
this.backupMesh.materials = null;
|
this.backupMesh.materials = null;
|
||||||
this.backupMesh.remove();
|
this.backupMesh.remove();
|
||||||
this.backupMesh = null;
|
this.backupMesh = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
this.flip = 0;
|
this.flip = 0;
|
||||||
this.orientaiton = 0;
|
this.orientaiton = 0;
|
||||||
this.isTail = false;
|
this.isTail = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
GameLib.CustomCode.SnakeBody.prototype.clone = function() {
|
GameLib.CustomCode.SnakeBody.prototype.clone = function() {
|
||||||
return new GameLib.CustomCode.SnakeBody(
|
return new GameLib.CustomCode.SnakeBody(
|
||||||
this.type,
|
this.type,
|
||||||
this.mesh,
|
this.mesh,
|
||||||
{
|
{
|
||||||
x : this.position.x,
|
x : this.position.x,
|
||||||
y : this.position.y
|
y : this.position.y
|
||||||
},
|
},
|
||||||
this.orientation,
|
this.orientation,
|
||||||
this.flip,
|
this.flip,
|
||||||
this.backupMesh,
|
this.backupMesh,
|
||||||
|
@ -937,9 +931,9 @@ GameLib.CustomCode.prototype.initializeGrid = function() {
|
||||||
function(x) {
|
function(x) {
|
||||||
x.map(
|
x.map(
|
||||||
function(y) {
|
function(y) {
|
||||||
if (y) {
|
if (y) {
|
||||||
y.dispose();
|
y.dispose();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -1158,34 +1152,15 @@ GameLib.CustomCode.prototype.createCorner = function(body, temp) {
|
||||||
|
|
||||||
GameLib.CustomCode.prototype.backup = function() {
|
GameLib.CustomCode.prototype.backup = function() {
|
||||||
|
|
||||||
if (GameLib.Utils.UndefinedOrNull(this.backupSnake)) {
|
this.backup = {
|
||||||
|
snake : this.snake.map(
|
||||||
this.backupSnake = this.snake.map(
|
function(body) {
|
||||||
function(body) {
|
return body.clone();
|
||||||
return body.clone();
|
}
|
||||||
}
|
),
|
||||||
);
|
orientation : this.state.orientation,
|
||||||
|
flip : this.state.flip
|
||||||
this.backupOrientation = this.state.orientation;
|
};
|
||||||
}
|
|
||||||
|
|
||||||
this.backupPrevious = this.backupSnake.map(
|
|
||||||
function(body) {
|
|
||||||
return body.clone();
|
|
||||||
}
|
|
||||||
);
|
|
||||||
|
|
||||||
this.backupSnake = this.snake.map(
|
|
||||||
function(body) {
|
|
||||||
return body.clone();
|
|
||||||
}
|
|
||||||
);
|
|
||||||
|
|
||||||
this.backupPreviousOrientation = this.backupOrientation;
|
|
||||||
|
|
||||||
this.backupOrientation = this.state.orientation;
|
|
||||||
|
|
||||||
this.state.overrideOrientation = true;
|
|
||||||
|
|
||||||
}.bind(this)
|
}.bind(this)
|
||||||
|
|
||||||
|
@ -1200,41 +1175,41 @@ GameLib.CustomCode.prototype.restore = function() {
|
||||||
*/
|
*/
|
||||||
this.grid[body.position.x][body.position.y] = null;
|
this.grid[body.position.x][body.position.y] = null;
|
||||||
|
|
||||||
var meshFound = false;
|
var meshFound = false;
|
||||||
var backupMeshFound = false;
|
var backupMeshFound = false;
|
||||||
|
|
||||||
this.backupPrevious.map(
|
this.backup.snake.map(
|
||||||
function (backupBody) {
|
function (backupBody) {
|
||||||
if (
|
if (
|
||||||
body.mesh === backupBody.mesh ||
|
body.mesh === backupBody.mesh ||
|
||||||
body.mesh === backupBody.backupMesh
|
body.mesh === backupBody.backupMesh
|
||||||
) {
|
) {
|
||||||
meshFound = true;
|
meshFound = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (
|
if (
|
||||||
body.backupMesh === backupBody.mesh ||
|
body.backupMesh === backupBody.mesh ||
|
||||||
body.backupMesh === backupBody.backupMesh
|
body.backupMesh === backupBody.backupMesh
|
||||||
) {
|
) {
|
||||||
backupMeshFound = true;
|
backupMeshFound = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
}.bind(this)
|
}.bind(this)
|
||||||
);
|
);
|
||||||
|
|
||||||
if (!meshFound) {
|
if (!meshFound) {
|
||||||
body.mesh.geometry = null;
|
body.mesh.geometry = null;
|
||||||
body.mesh.materials = null;
|
body.mesh.materials = null;
|
||||||
body.mesh.remove();
|
body.mesh.remove();
|
||||||
body.mesh = null;
|
body.mesh = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!backupMeshFound) {
|
if (!backupMeshFound) {
|
||||||
body.backupMesh.geometry = null;
|
body.backupMesh.geometry = null;
|
||||||
body.backupMesh.materials = null;
|
body.backupMesh.materials = null;
|
||||||
body.backupMesh.remove();
|
body.backupMesh.remove();
|
||||||
body.backupMesh = null;
|
body.backupMesh = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
}.bind(this)
|
}.bind(this)
|
||||||
)
|
)
|
||||||
|
@ -1245,21 +1220,24 @@ GameLib.CustomCode.prototype.restore = function() {
|
||||||
this.initializeGrid();
|
this.initializeGrid();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Restore our backup snake
|
* Restore our backup
|
||||||
*/
|
*/
|
||||||
this.snake = this.backupPrevious.map(
|
this.state.orientation = this.backup.orientation;
|
||||||
|
this.state.flip = this.backup.flip;
|
||||||
|
this.snake = this.backup.snake.map(
|
||||||
function(body) {
|
function(body) {
|
||||||
return body.clone();
|
|
||||||
|
var clone = body.clone();
|
||||||
|
|
||||||
|
clone.applyToMesh();
|
||||||
|
|
||||||
|
return clone;
|
||||||
}.bind(this)
|
}.bind(this)
|
||||||
);
|
);
|
||||||
|
|
||||||
this.state.orientation = this.backupPreviousOrientation;
|
this.backup();
|
||||||
|
|
||||||
this.backupSnake = null;
|
this.visualizeGrid();
|
||||||
|
|
||||||
this.backup();
|
|
||||||
|
|
||||||
this.visualizeGrid();
|
|
||||||
|
|
||||||
}.bind(this)
|
}.bind(this)
|
||||||
|
|
||||||
|
@ -1288,30 +1266,30 @@ GameLib.CustomCode.prototype.advanceSnake = function(delta) {
|
||||||
this.snake.map(
|
this.snake.map(
|
||||||
function(body, index) {
|
function(body, index) {
|
||||||
|
|
||||||
|
if (body.backupMesh) {
|
||||||
|
/**
|
||||||
|
* We used to be a corner, change back
|
||||||
|
* @type {null}
|
||||||
|
*/
|
||||||
|
body.mesh.geometry = null;
|
||||||
|
|
||||||
|
body.mesh.materials = null;
|
||||||
|
|
||||||
|
body.mesh.remove();
|
||||||
|
|
||||||
|
body.mesh = body.backupMesh;
|
||||||
|
|
||||||
|
body.backupMesh = null;
|
||||||
|
|
||||||
|
body.mesh.visible = true;
|
||||||
|
|
||||||
|
body.mesh.updateInstance('visible');
|
||||||
|
|
||||||
|
body.mesh.updateInstance('position');
|
||||||
|
}
|
||||||
|
|
||||||
if (index === 0) {
|
if (index === 0) {
|
||||||
|
|
||||||
if (body.backupMesh) {
|
|
||||||
/**
|
|
||||||
* We used to be a corner, change back
|
|
||||||
* @type {null}
|
|
||||||
*/
|
|
||||||
body.mesh.geometry = null;
|
|
||||||
|
|
||||||
body.mesh.materials = null;
|
|
||||||
|
|
||||||
body.mesh.remove();
|
|
||||||
|
|
||||||
body.mesh = body.backupMesh;
|
|
||||||
|
|
||||||
body.backupMesh = null;
|
|
||||||
|
|
||||||
body.mesh.visible = true;
|
|
||||||
|
|
||||||
body.mesh.updateInstance('visible');
|
|
||||||
|
|
||||||
body.mesh.updateInstance('position');
|
|
||||||
}
|
|
||||||
|
|
||||||
backup = {
|
backup = {
|
||||||
position : {
|
position : {
|
||||||
x : body.position.x,
|
x : body.position.x,
|
||||||
|
@ -1331,41 +1309,15 @@ GameLib.CustomCode.prototype.advanceSnake = function(delta) {
|
||||||
|
|
||||||
if (!advanced) {
|
if (!advanced) {
|
||||||
|
|
||||||
if (this.state.getReady) {
|
|
||||||
|
|
||||||
body.position.x = backup.position.x;
|
|
||||||
body.position.y = backup.position.y;
|
|
||||||
body.orientation = backup.orientation;
|
|
||||||
body.flip = backup.flip;
|
|
||||||
|
|
||||||
body.applyToMesh();
|
|
||||||
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
this.explode(body.position);
|
this.explode(body.position);
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
if (this.state.overrideOrientation) {
|
|
||||||
this.backupPreviousOrientation = this.state.orientation;
|
|
||||||
this.backupOrientation = this.state.orientation;
|
|
||||||
this.state.overrideOrientation = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
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 :
|
||||||
|
|
||||||
//f (body.orientation !== backup.orientation) {
|
|
||||||
//body.orientation = backup.orientation;
|
|
||||||
//body.flip = backup.flip;
|
|
||||||
//backup.orientation = this.state.orientation;
|
|
||||||
//backup.flip = this.state.flip;
|
|
||||||
// this.createCorner(body, backup);
|
|
||||||
// body.applyToMesh();
|
|
||||||
//}
|
|
||||||
if (!gameObject.isTail) {
|
if (!gameObject.isTail) {
|
||||||
|
|
||||||
if (body.orientation !== backup.orientation) {
|
if (body.orientation !== backup.orientation) {
|
||||||
|
@ -1487,28 +1439,6 @@ GameLib.CustomCode.prototype.advanceSnake = function(delta) {
|
||||||
*/
|
*/
|
||||||
this.grid[body.position.x][body.position.y] = body;
|
this.grid[body.position.x][body.position.y] = body;
|
||||||
|
|
||||||
if (body.backupMesh) {
|
|
||||||
/**
|
|
||||||
* We used to be a corner, change back
|
|
||||||
* @type {null}
|
|
||||||
*/
|
|
||||||
body.mesh.geometry = null;
|
|
||||||
|
|
||||||
body.mesh.materials = null;
|
|
||||||
|
|
||||||
body.mesh.remove();
|
|
||||||
|
|
||||||
body.mesh = body.backupMesh;
|
|
||||||
|
|
||||||
body.backupMesh = null;
|
|
||||||
|
|
||||||
body.mesh.visible = true;
|
|
||||||
|
|
||||||
body.mesh.updateInstance('visible');
|
|
||||||
|
|
||||||
body.mesh.updateInstance('position');
|
|
||||||
}
|
|
||||||
|
|
||||||
if (body.orientation !== temp.orientation) {
|
if (body.orientation !== temp.orientation) {
|
||||||
this.createCorner(body, temp);
|
this.createCorner(body, temp);
|
||||||
}
|
}
|
||||||
|
@ -1523,9 +1453,9 @@ GameLib.CustomCode.prototype.advanceSnake = function(delta) {
|
||||||
|
|
||||||
this.state.turning = false;
|
this.state.turning = false;
|
||||||
|
|
||||||
if (this.state.eating) {
|
if (this.state.eating) {
|
||||||
this.backup();
|
this.backup();
|
||||||
}
|
}
|
||||||
|
|
||||||
this.state.eating = false;
|
this.state.eating = false;
|
||||||
|
|
||||||
|
@ -1546,7 +1476,7 @@ GameLib.Event.Subscribe(
|
||||||
lives : 3,
|
lives : 3,
|
||||||
getReady : false,
|
getReady : false,
|
||||||
message : null,
|
message : null,
|
||||||
overrideOrientation : false
|
overrideOrientation : false
|
||||||
};
|
};
|
||||||
|
|
||||||
this.initializeGrid();
|
this.initializeGrid();
|
||||||
|
|
Loading…
Reference in New Issue