From 40311bb23312372eb26d96621545f512a4ddb4f2 Mon Sep 17 00:00:00 2001 From: -=yb4f310 Date: Sat, 24 Mar 2018 11:10:06 +0100 Subject: [PATCH] Update: CC - Snake FS - Entity Loaded (21g30t1e75.js) 1387 bytes modified --- 21g30t1e75.js | 316 ++++++++++++++++++++------------------------------ 1 file changed, 123 insertions(+), 193 deletions(-) diff --git a/21g30t1e75.js b/21g30t1e75.js index 47f4d25..c213fec 100644 --- a/21g30t1e75.js +++ b/21g30t1e75.js @@ -157,8 +157,7 @@ this.state = { exploding : false, lives : 3, getReady : false, - message : null, - overrideOrientation : false + message : null }; GameLib.CustomCode.prototype.displayHUD = function() { @@ -204,10 +203,10 @@ GameLib.CustomCode.prototype.displayHUD = function() { this.canvasHUD.text('xtra', 420, 480, '12px Pixeled', '#ffffff'); this.canvasHUD.text('slow', 420, 500, '12px Pixeled', '#ffffff'); - if (this.state.message) { - this.canvasHUD.text(this.state.message, 220, 250, '30px Pixeled', '#ffffff'); - } - + if (this.state.message) { + 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.imagePowerupLife.instance, 205, 460, 48, 48); this.canvasHUD.image(this.imagePowerupSlow.instance, 360, 460, 48, 48); @@ -235,19 +234,16 @@ GameLib.CustomCode.prototype.waitReload = function(delta) { this.state.exploding = false; - this.state.getReady = true; - - this.advanceSnake(this.speed * 2); - - window.setTimeout( + this.state.getReady = true; + + window.setTimeout( function(){ this.state.message = null; this.displayHUD(); }.bind(this), 5000 ); - - + window.setTimeout( function(){ this.state.message = "GO!"; @@ -289,8 +285,6 @@ GameLib.CustomCode.prototype.waitReload = function(delta) { GameLib.CustomCode.prototype.visualizeGrid = function () { - return; - if (this.noneMesh) { this.scene.instance.remove(this.noneMesh); } @@ -650,8 +644,8 @@ GameLib.CustomCode.prototype.createGameObject = function( gameObject.applyToMesh(true); break; case GameLib.CustomCode.OBJECT_TYPE_SNAKE_BODY: - - gameObject = new GameLib.CustomCode.SnakeBody( + + gameObject = new GameLib.CustomCode.SnakeBody( type, mesh, position, @@ -661,9 +655,9 @@ GameLib.CustomCode.prototype.createGameObject = function( isTail ) gameObject.applyToMesh(true); - - this.animation.meshes.push(gameObject.mesh); - + + this.animation.meshes.push(gameObject.mesh); + break; default: throw new Error('unhandled object type: ' + objectType); @@ -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.dispose = function() { - GameLib.CustomCode.GameObject.prototype.dispose.call(this); - if (this.backupMesh) { - this.backupMesh.geometry = null; - this.backupMesh.materials = null; - this.backupMesh.remove(); - this.backupMesh = null; - } - - this.flip = 0; - this.orientaiton = 0; - this.isTail = false; + GameLib.CustomCode.GameObject.prototype.dispose.call(this); + if (this.backupMesh) { + this.backupMesh.geometry = null; + this.backupMesh.materials = null; + this.backupMesh.remove(); + this.backupMesh = null; + } + + this.flip = 0; + this.orientaiton = 0; + this.isTail = false; } GameLib.CustomCode.SnakeBody.prototype.clone = function() { return new GameLib.CustomCode.SnakeBody( this.type, this.mesh, - { - x : this.position.x, - y : this.position.y - }, + { + x : this.position.x, + y : this.position.y + }, this.orientation, this.flip, this.backupMesh, @@ -937,9 +931,9 @@ GameLib.CustomCode.prototype.initializeGrid = function() { function(x) { x.map( function(y) { - if (y) { - y.dispose(); - } + if (y) { + y.dispose(); + } } ); } @@ -1157,40 +1151,21 @@ GameLib.CustomCode.prototype.createCorner = function(body, temp) { }.bind(this); GameLib.CustomCode.prototype.backup = function() { - - if (GameLib.Utils.UndefinedOrNull(this.backupSnake)) { - - this.backupSnake = this.snake.map( - function(body) { - return body.clone(); - } - ); - - 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; - + this.backup = { + snake : this.snake.map( + function(body) { + return body.clone(); + } + ), + orientation : this.state.orientation, + flip : this.state.flip + }; + }.bind(this) GameLib.CustomCode.prototype.restore = function() { - + this.snake.map( function(body) { @@ -1200,42 +1175,42 @@ GameLib.CustomCode.prototype.restore = function() { */ this.grid[body.position.x][body.position.y] = null; - var meshFound = false; - var backupMeshFound = false; - - this.backupPrevious.map( - function (backupBody) { - if ( - body.mesh === backupBody.mesh || - body.mesh === backupBody.backupMesh - ) { - meshFound = true; - } - - if ( - body.backupMesh === backupBody.mesh || - body.backupMesh === backupBody.backupMesh - ) { - backupMeshFound = true; - } - - }.bind(this) - ); - - if (!meshFound) { - body.mesh.geometry = null; - body.mesh.materials = null; - body.mesh.remove(); - body.mesh = null; - } - - if (!backupMeshFound) { - body.backupMesh.geometry = null; - body.backupMesh.materials = null; - body.backupMesh.remove(); - body.backupMesh = null; - } - + var meshFound = false; + var backupMeshFound = false; + + this.backup.snake.map( + function (backupBody) { + if ( + body.mesh === backupBody.mesh || + body.mesh === backupBody.backupMesh + ) { + meshFound = true; + } + + if ( + body.backupMesh === backupBody.mesh || + body.backupMesh === backupBody.backupMesh + ) { + backupMeshFound = true; + } + + }.bind(this) + ); + + if (!meshFound) { + body.mesh.geometry = null; + body.mesh.materials = null; + body.mesh.remove(); + body.mesh = null; + } + + if (!backupMeshFound) { + body.backupMesh.geometry = null; + body.backupMesh.materials = null; + body.backupMesh.remove(); + body.backupMesh = null; + } + }.bind(this) ) @@ -1245,22 +1220,25 @@ GameLib.CustomCode.prototype.restore = function() { this.initializeGrid(); /** - * Restore our backup snake + * Restore our backup */ - this.snake = this.backupPrevious.map( - function(body) { - return body.clone(); + this.state.orientation = this.backup.orientation; + this.state.flip = this.backup.flip; + this.snake = this.backup.snake.map( + function(body) { + + var clone = body.clone(); + + clone.applyToMesh(); + + return clone; }.bind(this) ); - this.state.orientation = this.backupPreviousOrientation; + this.backup(); + + this.visualizeGrid(); - this.backupSnake = null; - - this.backup(); - - this.visualizeGrid(); - }.bind(this) /** @@ -1284,34 +1262,34 @@ GameLib.CustomCode.prototype.advanceSnake = function(delta) { var backup = null; var temp = null; var advanced = false; - + this.snake.map( 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 (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 = { position : { x : body.position.x, @@ -1330,42 +1308,16 @@ GameLib.CustomCode.prototype.advanceSnake = function(delta) { this.grid[backup.position.x][backup.position.y] = new GameLib.CustomCode.GameObject(); 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); } 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]; switch (gameObject.objectType) { 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 (body.orientation !== backup.orientation) { @@ -1487,28 +1439,6 @@ GameLib.CustomCode.prototype.advanceSnake = function(delta) { */ 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) { this.createCorner(body, temp); } @@ -1523,10 +1453,10 @@ GameLib.CustomCode.prototype.advanceSnake = function(delta) { this.state.turning = false; - if (this.state.eating) { - this.backup(); - } - + if (this.state.eating) { + this.backup(); + } + this.state.eating = false; this.visualizeGrid(); @@ -1546,7 +1476,7 @@ GameLib.Event.Subscribe( lives : 3, getReady : false, message : null, - overrideOrientation : false + overrideOrientation : false }; this.initializeGrid();