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);