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

beta.r3js.org
-=yb4f310 2018-03-24 11:10:06 +01:00
parent 4956323ad7
commit 40311bb233
1 changed files with 123 additions and 193 deletions

View File

@ -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() {
@ -237,8 +236,6 @@ GameLib.CustomCode.prototype.waitReload = function(delta) {
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;
@ -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);
} }
@ -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,
this.backupOrientation = this.state.orientation; flip : this.state.flip
} };
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)
@ -1203,7 +1178,7 @@ GameLib.CustomCode.prototype.restore = function() {
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 ||
@ -1245,18 +1220,21 @@ 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.backupSnake = null;
this.backup(); this.backup();
this.visualizeGrid(); this.visualizeGrid();
@ -1288,8 +1266,6 @@ GameLib.CustomCode.prototype.advanceSnake = function(delta) {
this.snake.map( this.snake.map(
function(body, index) { function(body, index) {
if (index === 0) {
if (body.backupMesh) { if (body.backupMesh) {
/** /**
* We used to be a corner, change back * We used to be a corner, change back
@ -1312,6 +1288,8 @@ GameLib.CustomCode.prototype.advanceSnake = function(delta) {
body.mesh.updateInstance('position'); body.mesh.updateInstance('position');
} }
if (index === 0) {
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);
} }