From 42e335fc2cc11d7afb1e889c152caa884d6409e0 Mon Sep 17 00:00:00 2001 From: -=yb4f310 Date: Mon, 12 Mar 2018 14:51:24 +0100 Subject: [PATCH] Update: CC - Snake FS - Entity Loaded (21g30t1e75.js) 318 bytes modified --- 21g30t1e75.js | 31 +++++++++++++++++++++++++------ 1 file changed, 25 insertions(+), 6 deletions(-) diff --git a/21g30t1e75.js b/21g30t1e75.js index 76eceff..17bb469 100644 --- a/21g30t1e75.js +++ b/21g30t1e75.js @@ -44,12 +44,31 @@ this.scene = GameLib.EntityManager.Instance.findComponentById('pllp034hsj'); * Game objects */ this.snake = []; -this.grid = [[]]; +this.grid = []; GameLib.CustomCode.prototype.advanceSnake = function(delta) { }.bind(this); +GameLib.CustomCode.prototype.initializeGrid = function() { + + this.grid = []; + + for (var x = 0; x < GameLib.CustomCode.GRID_WIDTH; x++) { + this.grid[x] = []; + for (var y = 0; y < GameLib.CustomCode.GRID_HEIGHT; y++) { + this.grid[x][y] = { + mesh : null, + direction : { + x : 0, + y : 0 + } + } + } + } + +}.bind(this); + GameLib.CustomCode.prototype.cloneBody = function(bodyType) { var body = null; @@ -131,6 +150,9 @@ GameLib.Event.Subscribe( this.cloneBody(GameLib.CustomCode.BODY_TYPE_TAIL) ]; + /** + * Cleanup grid + */ this.grid.map( function(x) { x.map( @@ -138,16 +160,13 @@ GameLib.Event.Subscribe( y.mesh.geometry = null; y.mesh.materials = null; y.mesh.remove(); - y.taken = false; - y.direction = { - x:0, - y:0 - } } ); } ); + this.initializeGrid(); + this.beforeRender.initialized = false; this.beforeRender.entityLoaded = this;