From 4d65e5c696519001a076f49262a72721d4f3cd01 Mon Sep 17 00:00:00 2001 From: -=yb4f310 Date: Thu, 22 Mar 2018 19:36:18 +0100 Subject: [PATCH] Update: CC - Snake FS - Entity Loaded (21g30t1e75.js) 170 bytes modified --- 21g30t1e75.js | 27 +++++++++++++++++++++------ 1 file changed, 21 insertions(+), 6 deletions(-) diff --git a/21g30t1e75.js b/21g30t1e75.js index 99cc781..6c4a84d 100644 --- a/21g30t1e75.js +++ b/21g30t1e75.js @@ -330,13 +330,28 @@ GameLib.CustomCode.GameObject.prototype.applyToMesh = function(updateInstance) { */ GameLib.CustomCode.prototype.getFreeGridPosition = function() { - var x = GameLib.Utils.GetRandomInt(0, GameLib.CustomCode.GRID_WIDTH); - var y = GameLib.Utils.GetRandomInt(0, GameLib.CustomCode.GRID_HEIGHT); + var positions = []; + + this.grid.map( + function(row, x) { + row.map( + function(object, y) { + if (object.objectType === GameLib.CustomCode.OBJECT_TYPE_NONE) { + positions.push( + { + x : x, + y : y + } + ) + } + } + ); + } + ); + + var index = GameLib.Utils.GetRandomInt(0, positions.length); - return { - x : x, - y : y - }; + return positions[index]; }.bind(this);