Created
January 1, 2018 04:59
-
-
Save ManasJayanth/2ae92469a61de70822e3c013453a10bc to your computer and use it in GitHub Desktop.
Prepack output for issue #1303
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(function () { | |
"use strict"; | |
var _$0 = this; | |
var _2 = function (i) { | |
return _$0.Math.cos(i * 0.19634954084936207); | |
}; | |
var _5 = function (value, min, max) { | |
/* return a value that is in between min and max and | |
as close as possible to value | |
advantages over using if else to clamp a value: | |
it goes as close as possible to the limit */return _$0.Math.max(min, _$0.Math.min(max, value)); | |
}; | |
var _4 = function (x, y, angleOffSet = 0) { | |
return _$0.Math.atan2(y, x) + angleOffSet; | |
}; | |
var _g = function (size, margin, max) { | |
const maxSafe = max - size; | |
const space = margin + size; | |
const grid = []; | |
const used = []; // initially empty | |
const unused = []; // initially full | |
let position = margin; | |
let i; | |
for (i = 0; position < maxSafe; position += space) { | |
grid.push(position); | |
unused.push(i); | |
i += 1; | |
} // having 2 more grids makes it very convenient to get a random spawn | |
// without having to check if it is already used in a while loop | |
// and repeat random ... | |
return { | |
grid, | |
used, | |
unused, | |
size: i | |
}; | |
}; | |
var _7 = function (multiplier, max) { | |
const marginScaled = _$0.Math.round(1 * multiplier); | |
const grids = {}; | |
_9.forEach(function (size) { | |
grids[size] = _g(size, marginScaled, max); | |
}); | |
return grids; | |
}; | |
var _i = function (spawnGrid, index) { | |
// index here is a value | |
// but it is also the index for .grid that points to a position | |
const indexIndex = spawnGrid.unused.indexOf(index); | |
spawnGrid.unused.splice(indexIndex, 1); | |
spawnGrid.used.push(index); | |
const position = spawnGrid.grid[index]; | |
return position; | |
}; | |
var _j = function (spawnGrid, position) { | |
const index = spawnGrid.grid.indexOf(position); | |
const indexIndex = spawnGrid.used.indexOf(index); | |
spawnGrid.used.splice(indexIndex, 1); | |
spawnGrid.unused.push(index); | |
return position; | |
}; | |
var _h = function (spawnGrid) { | |
const possibilities = spawnGrid.unused.length; | |
const randomIndexIndex = _$0.Math.floor(_$0.Math.random() * possibilities); | |
const randomIndex = spawnGrid.unused[randomIndexIndex]; | |
return _i(spawnGrid, randomIndex); | |
}; | |
var _k = function (spawnGrid) { | |
// like useRandomSpawn but | |
// does not remember that the position is used | |
// for moving targets | |
const possibilities = spawnGrid.unused.length; | |
const randomIndexIndex = _$0.Math.floor(_$0.Math.random() * possibilities); | |
const randomIndex = spawnGrid.unused[randomIndexIndex]; | |
return spawnGrid.grid[randomIndex]; | |
}; | |
var _6 = function (start1, length1, start2, length2) { | |
/* start1: a point in a 1D space, length1 | |
returns true if both vectors collide | |
*/const end1 = start1 + length1; | |
const end2 = start2 + length2; | |
return start1 <= end2 && end1 >= start2; | |
}; | |
var _9 = [15, 20, 25, 50, 40, 130]; | |
var _1 = { | |
rotatingValue: _2, | |
angleFromVector: _4, | |
clampValue: _5, | |
insideAxis: _6, | |
createSpawnGrids: _7, | |
useRandomSpawn: _h, | |
useSpawn: _i, | |
stopUseSpawn: _j, | |
randomSpawn: _k | |
}; | |
var _0 = { | |
js: _1 | |
}; | |
out = _0; | |
}).call(this); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment