mirror of
https://github.com/wassname/phaser.git
synced 2026-07-23 13:00:41 +08:00
The entire Phaser library has been updated to match the new JSHint configuration.
This commit is contained in:
+422
-408
File diff suppressed because it is too large
Load Diff
+185
-184
@@ -58,207 +58,208 @@
|
||||
* @param {number} level - Description.
|
||||
*/
|
||||
Phaser.QuadTree = function (physicsManager, x, y, width, height, maxObjects, maxLevels, level) {
|
||||
|
||||
this.physicsManager = physicsManager;
|
||||
this.ID = physicsManager.quadTreeID;
|
||||
physicsManager.quadTreeID++;
|
||||
|
||||
this.physicsManager = physicsManager;
|
||||
this.ID = physicsManager.quadTreeID;
|
||||
physicsManager.quadTreeID++;
|
||||
|
||||
this.maxObjects = maxObjects || 10;
|
||||
this.maxLevels = maxLevels || 4;
|
||||
this.level = level || 0;
|
||||
this.maxObjects = maxObjects || 10;
|
||||
this.maxLevels = maxLevels || 4;
|
||||
this.level = level || 0;
|
||||
|
||||
this.bounds = {
|
||||
x: Math.round(x),
|
||||
y: Math.round(y),
|
||||
width: width,
|
||||
height: height,
|
||||
subWidth: Math.floor(width / 2),
|
||||
subHeight: Math.floor(height / 2),
|
||||
right: Math.round(x) + Math.floor(width / 2),
|
||||
bottom: Math.round(y) + Math.floor(height / 2)
|
||||
};
|
||||
|
||||
this.objects = [];
|
||||
this.nodes = [];
|
||||
this.bounds = {
|
||||
x: Math.round(x),
|
||||
y: Math.round(y),
|
||||
width: width,
|
||||
height: height,
|
||||
subWidth: Math.floor(width / 2),
|
||||
subHeight: Math.floor(height / 2),
|
||||
right: Math.round(x) + Math.floor(width / 2),
|
||||
bottom: Math.round(y) + Math.floor(height / 2)
|
||||
};
|
||||
|
||||
this.objects = [];
|
||||
this.nodes = [];
|
||||
|
||||
};
|
||||
|
||||
Phaser.QuadTree.prototype = {
|
||||
|
||||
/*
|
||||
* Split the node into 4 subnodes
|
||||
*
|
||||
* @method Phaser.QuadTree#split
|
||||
*/
|
||||
split: function() {
|
||||
/*
|
||||
* Split the node into 4 subnodes
|
||||
*
|
||||
* @method Phaser.QuadTree#split
|
||||
*/
|
||||
split: function() {
|
||||
|
||||
this.level++;
|
||||
|
||||
// top right node
|
||||
this.nodes[0] = new Phaser.QuadTree(this.physicsManager, this.bounds.right, this.bounds.y, this.bounds.subWidth, this.bounds.subHeight, this.maxObjects, this.maxLevels, this.level);
|
||||
|
||||
// top left node
|
||||
this.nodes[1] = new Phaser.QuadTree(this.physicsManager, this.bounds.x, this.bounds.y, this.bounds.subWidth, this.bounds.subHeight, this.maxObjects, this.maxLevels, this.level);
|
||||
|
||||
// bottom left node
|
||||
this.nodes[2] = new Phaser.QuadTree(this.physicsManager, this.bounds.x, this.bounds.bottom, this.bounds.subWidth, this.bounds.subHeight, this.maxObjects, this.maxLevels, this.level);
|
||||
|
||||
// bottom right node
|
||||
this.nodes[3] = new Phaser.QuadTree(this.physicsManager, this.bounds.right, this.bounds.bottom, this.bounds.subWidth, this.bounds.subHeight, this.maxObjects, this.maxLevels, this.level);
|
||||
this.level++;
|
||||
|
||||
// top right node
|
||||
this.nodes[0] = new Phaser.QuadTree(this.physicsManager, this.bounds.right, this.bounds.y, this.bounds.subWidth, this.bounds.subHeight, this.maxObjects, this.maxLevels, this.level);
|
||||
|
||||
// top left node
|
||||
this.nodes[1] = new Phaser.QuadTree(this.physicsManager, this.bounds.x, this.bounds.y, this.bounds.subWidth, this.bounds.subHeight, this.maxObjects, this.maxLevels, this.level);
|
||||
|
||||
// bottom left node
|
||||
this.nodes[2] = new Phaser.QuadTree(this.physicsManager, this.bounds.x, this.bounds.bottom, this.bounds.subWidth, this.bounds.subHeight, this.maxObjects, this.maxLevels, this.level);
|
||||
|
||||
// bottom right node
|
||||
this.nodes[3] = new Phaser.QuadTree(this.physicsManager, this.bounds.right, this.bounds.bottom, this.bounds.subWidth, this.bounds.subHeight, this.maxObjects, this.maxLevels, this.level);
|
||||
|
||||
},
|
||||
},
|
||||
|
||||
/*
|
||||
* Insert the object into the node. If the node
|
||||
* exceeds the capacity, it will split and add all
|
||||
* objects to their corresponding subnodes.
|
||||
*
|
||||
* @method Phaser.QuadTree#insert
|
||||
* @param {object} body - Description.
|
||||
*/
|
||||
insert: function (body) {
|
||||
|
||||
var i = 0;
|
||||
var index;
|
||||
|
||||
// if we have subnodes ...
|
||||
if (this.nodes[0] != null)
|
||||
{
|
||||
index = this.getIndex(body);
|
||||
|
||||
if (index !== -1)
|
||||
{
|
||||
this.nodes[index].insert(body);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
this.objects.push(body);
|
||||
|
||||
if (this.objects.length > this.maxObjects && this.level < this.maxLevels)
|
||||
{
|
||||
// Split if we don't already have subnodes
|
||||
if (this.nodes[0] == null)
|
||||
{
|
||||
this.split();
|
||||
}
|
||||
|
||||
// Add objects to subnodes
|
||||
while (i < this.objects.length)
|
||||
{
|
||||
index = this.getIndex(this.objects[i]);
|
||||
|
||||
if (index !== -1)
|
||||
{
|
||||
// this is expensive - see what we can do about it
|
||||
this.nodes[index].insert(this.objects.splice(i, 1)[0]);
|
||||
}
|
||||
else
|
||||
{
|
||||
i++;
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
/*
|
||||
* Determine which node the object belongs to.
|
||||
*
|
||||
* @method Phaser.QuadTree#getIndex
|
||||
* @param {object} rect - Description.
|
||||
* @return {number} index - Index of the subnode (0-3), or -1 if rect cannot completely fit within a subnode and is part of the parent node.
|
||||
*/
|
||||
getIndex: function (rect) {
|
||||
|
||||
// default is that rect doesn't fit, i.e. it straddles the internal quadrants
|
||||
var index = -1;
|
||||
/*
|
||||
* Insert the object into the node. If the node
|
||||
* exceeds the capacity, it will split and add all
|
||||
* objects to their corresponding subnodes.
|
||||
*
|
||||
* @method Phaser.QuadTree#insert
|
||||
* @param {object} body - Description.
|
||||
*/
|
||||
insert: function (body) {
|
||||
|
||||
var i = 0;
|
||||
var index;
|
||||
|
||||
// if we have subnodes ...
|
||||
if (this.nodes[0] != null)
|
||||
{
|
||||
index = this.getIndex(body);
|
||||
|
||||
if (index !== -1)
|
||||
{
|
||||
this.nodes[index].insert(body);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
this.objects.push(body);
|
||||
|
||||
if (this.objects.length > this.maxObjects && this.level < this.maxLevels)
|
||||
{
|
||||
// Split if we don't already have subnodes
|
||||
if (this.nodes[0] == null)
|
||||
{
|
||||
this.split();
|
||||
}
|
||||
|
||||
// Add objects to subnodes
|
||||
while (i < this.objects.length)
|
||||
{
|
||||
index = this.getIndex(this.objects[i]);
|
||||
|
||||
if (index !== -1)
|
||||
{
|
||||
// this is expensive - see what we can do about it
|
||||
this.nodes[index].insert(this.objects.splice(i, 1)[0]);
|
||||
}
|
||||
else
|
||||
{
|
||||
i++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (rect.x < this.bounds.right && rect.right < this.bounds.right)
|
||||
{
|
||||
if ((rect.y < this.bounds.bottom && rect.bottom < this.bounds.bottom))
|
||||
{
|
||||
// rect fits within the top-left quadrant of this quadtree
|
||||
index = 1;
|
||||
}
|
||||
else if ((rect.y > this.bounds.bottom))
|
||||
{
|
||||
// rect fits within the bottom-left quadrant of this quadtree
|
||||
index = 2;
|
||||
}
|
||||
}
|
||||
else if (rect.x > this.bounds.right)
|
||||
{
|
||||
// rect can completely fit within the right quadrants
|
||||
if ((rect.y < this.bounds.bottom && rect.bottom < this.bounds.bottom))
|
||||
{
|
||||
// rect fits within the top-right quadrant of this quadtree
|
||||
index = 0;
|
||||
}
|
||||
else if ((rect.y > this.bounds.bottom))
|
||||
{
|
||||
// rect fits within the bottom-right quadrant of this quadtree
|
||||
index = 3;
|
||||
}
|
||||
}
|
||||
|
||||
return index;
|
||||
},
|
||||
|
||||
/*
|
||||
* Determine which node the object belongs to.
|
||||
*
|
||||
* @method Phaser.QuadTree#getIndex
|
||||
* @param {object} rect - Description.
|
||||
* @return {number} index - Index of the subnode (0-3), or -1 if rect cannot completely fit within a subnode and is part of the parent node.
|
||||
*/
|
||||
getIndex: function (rect) {
|
||||
|
||||
// default is that rect doesn't fit, i.e. it straddles the internal quadrants
|
||||
var index = -1;
|
||||
|
||||
},
|
||||
if (rect.x < this.bounds.right && rect.right < this.bounds.right)
|
||||
{
|
||||
if ((rect.y < this.bounds.bottom && rect.bottom < this.bounds.bottom))
|
||||
{
|
||||
// rect fits within the top-left quadrant of this quadtree
|
||||
index = 1;
|
||||
}
|
||||
else if ((rect.y > this.bounds.bottom))
|
||||
{
|
||||
// rect fits within the bottom-left quadrant of this quadtree
|
||||
index = 2;
|
||||
}
|
||||
}
|
||||
else if (rect.x > this.bounds.right)
|
||||
{
|
||||
// rect can completely fit within the right quadrants
|
||||
if ((rect.y < this.bounds.bottom && rect.bottom < this.bounds.bottom))
|
||||
{
|
||||
// rect fits within the top-right quadrant of this quadtree
|
||||
index = 0;
|
||||
}
|
||||
else if ((rect.y > this.bounds.bottom))
|
||||
{
|
||||
// rect fits within the bottom-right quadrant of this quadtree
|
||||
index = 3;
|
||||
}
|
||||
}
|
||||
|
||||
return index;
|
||||
|
||||
/*
|
||||
* Return all objects that could collide with the given object.
|
||||
*
|
||||
* @method Phaser.QuadTree#retrieve
|
||||
* @param {object} rect - Description.
|
||||
* @Return {array} - Array with all detected objects.
|
||||
*/
|
||||
retrieve: function (sprite) {
|
||||
|
||||
var returnObjects = this.objects;
|
||||
},
|
||||
|
||||
sprite.body.quadTreeIndex = this.getIndex(sprite.body);
|
||||
/*
|
||||
* Return all objects that could collide with the given object.
|
||||
*
|
||||
* @method Phaser.QuadTree#retrieve
|
||||
* @param {object} rect - Description.
|
||||
* @Return {array} - Array with all detected objects.
|
||||
*/
|
||||
retrieve: function (sprite) {
|
||||
|
||||
var returnObjects = this.objects;
|
||||
|
||||
// Temp store for the node IDs this sprite is in, we can use this for fast elimination later
|
||||
sprite.body.quadTreeIDs.push(this.ID);
|
||||
sprite.body.quadTreeIndex = this.getIndex(sprite.body);
|
||||
|
||||
if (this.nodes[0])
|
||||
{
|
||||
// if rect fits into a subnode ..
|
||||
if (sprite.body.quadTreeIndex !== -1)
|
||||
{
|
||||
returnObjects = returnObjects.concat(this.nodes[sprite.body.quadTreeIndex].retrieve(sprite));
|
||||
}
|
||||
else
|
||||
{
|
||||
// if rect does not fit into a subnode, check it against all subnodes (unrolled for speed)
|
||||
returnObjects = returnObjects.concat(this.nodes[0].retrieve(sprite));
|
||||
returnObjects = returnObjects.concat(this.nodes[1].retrieve(sprite));
|
||||
returnObjects = returnObjects.concat(this.nodes[2].retrieve(sprite));
|
||||
returnObjects = returnObjects.concat(this.nodes[3].retrieve(sprite));
|
||||
}
|
||||
}
|
||||
|
||||
return returnObjects;
|
||||
// Temp store for the node IDs this sprite is in, we can use this for fast elimination later
|
||||
sprite.body.quadTreeIDs.push(this.ID);
|
||||
|
||||
},
|
||||
if (this.nodes[0])
|
||||
{
|
||||
// if rect fits into a subnode ..
|
||||
if (sprite.body.quadTreeIndex !== -1)
|
||||
{
|
||||
returnObjects = returnObjects.concat(this.nodes[sprite.body.quadTreeIndex].retrieve(sprite));
|
||||
}
|
||||
else
|
||||
{
|
||||
// if rect does not fit into a subnode, check it against all subnodes (unrolled for speed)
|
||||
returnObjects = returnObjects.concat(this.nodes[0].retrieve(sprite));
|
||||
returnObjects = returnObjects.concat(this.nodes[1].retrieve(sprite));
|
||||
returnObjects = returnObjects.concat(this.nodes[2].retrieve(sprite));
|
||||
returnObjects = returnObjects.concat(this.nodes[3].retrieve(sprite));
|
||||
}
|
||||
}
|
||||
|
||||
return returnObjects;
|
||||
|
||||
/*
|
||||
* Clear the quadtree.
|
||||
* @method Phaser.QuadTree#clear
|
||||
*/
|
||||
clear: function () {
|
||||
|
||||
this.objects = [];
|
||||
|
||||
for (var i = 0, len = this.nodes.length; i < len; i++)
|
||||
{
|
||||
// if (typeof this.nodes[i] !== 'undefined')
|
||||
if (this.nodes[i])
|
||||
{
|
||||
this.nodes[i].clear();
|
||||
delete this.nodes[i];
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
/*
|
||||
* Clear the quadtree.
|
||||
* @method Phaser.QuadTree#clear
|
||||
*/
|
||||
clear: function () {
|
||||
|
||||
this.objects = [];
|
||||
|
||||
for (var i = 0, len = this.nodes.length; i < len; i++)
|
||||
{
|
||||
// if (typeof this.nodes[i] !== 'undefined')
|
||||
if (this.nodes[i])
|
||||
{
|
||||
this.nodes[i].clear();
|
||||
delete this.nodes[i];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
+191
-190
@@ -1,3 +1,5 @@
|
||||
/* jshint noempty: false */
|
||||
|
||||
/**
|
||||
* @author Richard Davey <rich@photonstorm.com>
|
||||
* @copyright 2013 Photon Storm Ltd.
|
||||
@@ -16,231 +18,230 @@
|
||||
* @param {array} seeds
|
||||
*/
|
||||
Phaser.RandomDataGenerator = function (seeds) {
|
||||
|
||||
if (typeof seeds === "undefined") { seeds = []; }
|
||||
|
||||
if (typeof seeds === "undefined") { seeds = []; }
|
||||
|
||||
this.sow(seeds);
|
||||
/**
|
||||
* @property {number} c - Internal var.
|
||||
* @private
|
||||
*/
|
||||
this.c = 1;
|
||||
|
||||
/**
|
||||
* @property {number} s0 - Internal var.
|
||||
* @private
|
||||
*/
|
||||
this.s0 = 0;
|
||||
|
||||
/**
|
||||
* @property {number} s1 - Internal var.
|
||||
* @private
|
||||
*/
|
||||
this.s1 = 0;
|
||||
|
||||
/**
|
||||
* @property {number} s2 - Internal var.
|
||||
* @private
|
||||
*/
|
||||
this.s2 = 0;
|
||||
|
||||
this.sow(seeds);
|
||||
|
||||
};
|
||||
|
||||
Phaser.RandomDataGenerator.prototype = {
|
||||
|
||||
/**
|
||||
* @property {number} c
|
||||
* @private
|
||||
*/
|
||||
c: 1,
|
||||
/**
|
||||
* Private random helper.
|
||||
* @method Phaser.RandomDataGenerator#rnd
|
||||
* @private
|
||||
* @return {number}
|
||||
*/
|
||||
rnd: function () {
|
||||
|
||||
/**
|
||||
* @property {number} s0
|
||||
* @private
|
||||
*/
|
||||
s0: 0,
|
||||
var t = 2091639 * this.s0 + this.c * 2.3283064365386963e-10; // 2^-32
|
||||
|
||||
/**
|
||||
* @property {number} s1
|
||||
* @private
|
||||
*/
|
||||
s1: 0,
|
||||
this.c = t | 0;
|
||||
this.s0 = this.s1;
|
||||
this.s1 = this.s2;
|
||||
this.s2 = t - this.c;
|
||||
|
||||
/**
|
||||
* @property {number} s2
|
||||
* @private
|
||||
*/
|
||||
s2: 0,
|
||||
return this.s2;
|
||||
},
|
||||
|
||||
/**
|
||||
* Private random helper.
|
||||
* @method Phaser.RandomDataGenerator#rnd
|
||||
* @private
|
||||
* @return {number} Description.
|
||||
*/
|
||||
rnd: function () {
|
||||
/**
|
||||
* Reset the seed of the random data generator.
|
||||
*
|
||||
* @method Phaser.RandomDataGenerator#sow
|
||||
* @param {array} seeds
|
||||
*/
|
||||
sow: function (seeds) {
|
||||
|
||||
var t = 2091639 * this.s0 + this.c * 2.3283064365386963e-10; // 2^-32
|
||||
if (typeof seeds === "undefined") { seeds = []; }
|
||||
|
||||
this.c = t | 0;
|
||||
this.s0 = this.s1;
|
||||
this.s1 = this.s2;
|
||||
this.s2 = t - this.c;
|
||||
this.s0 = this.hash(' ');
|
||||
this.s1 = this.hash(this.s0);
|
||||
this.s2 = this.hash(this.s1);
|
||||
this.c = 1;
|
||||
|
||||
return this.s2;
|
||||
},
|
||||
var seed;
|
||||
|
||||
/**
|
||||
* Reset the seed of the random data generator.
|
||||
*
|
||||
* @method Phaser.RandomDataGenerator#sow
|
||||
* @param {array} seeds
|
||||
*/
|
||||
sow: function (seeds) {
|
||||
for (var i = 0; seed = seeds[i++]; )
|
||||
{
|
||||
this.s0 -= this.hash(seed);
|
||||
this.s0 += ~~(this.s0 < 0);
|
||||
this.s1 -= this.hash(seed);
|
||||
this.s1 += ~~(this.s1 < 0);
|
||||
this.s2 -= this.hash(seed);
|
||||
this.s2 += ~~(this.s2 < 0);
|
||||
}
|
||||
|
||||
},
|
||||
|
||||
if (typeof seeds === "undefined") { seeds = []; }
|
||||
/**
|
||||
* Internal method that creates a seed hash.
|
||||
* @method Phaser.RandomDataGenerator#hash
|
||||
* @param {Any} data
|
||||
* @private
|
||||
* @return {number} hashed value.
|
||||
*/
|
||||
hash: function (data) {
|
||||
|
||||
this.s0 = this.hash(' ');
|
||||
this.s1 = this.hash(this.s0);
|
||||
this.s2 = this.hash(this.s1);
|
||||
this.c = 1;
|
||||
var h, i, n;
|
||||
n = 0xefc8249d;
|
||||
data = data.toString();
|
||||
|
||||
var seed;
|
||||
for (i = 0; i < data.length; i++) {
|
||||
n += data.charCodeAt(i);
|
||||
h = 0.02519603282416938 * n;
|
||||
n = h >>> 0;
|
||||
h -= n;
|
||||
h *= n;
|
||||
n = h >>> 0;
|
||||
h -= n;
|
||||
n += h * 0x100000000;// 2^32
|
||||
}
|
||||
|
||||
for (var i = 0; seed = seeds[i++]; )
|
||||
{
|
||||
this.s0 -= this.hash(seed);
|
||||
this.s0 += ~~(this.s0 < 0);
|
||||
this.s1 -= this.hash(seed);
|
||||
this.s1 += ~~(this.s1 < 0);
|
||||
this.s2 -= this.hash(seed);
|
||||
this.s2 += ~~(this.s2 < 0);
|
||||
}
|
||||
|
||||
},
|
||||
return (n >>> 0) * 2.3283064365386963e-10;// 2^-32
|
||||
|
||||
/**
|
||||
* Description.
|
||||
* @method Phaser.RandomDataGenerator#hash
|
||||
* @param {Any} data
|
||||
* @private
|
||||
* @return {number} Description.
|
||||
*/
|
||||
hash: function (data) {
|
||||
},
|
||||
|
||||
var h, i, n;
|
||||
n = 0xefc8249d;
|
||||
data = data.toString();
|
||||
/**
|
||||
* Returns a random integer between 0 and 2^32.
|
||||
* @method Phaser.RandomDataGenerator#integer
|
||||
* @return {number} A random integer between 0 and 2^32.
|
||||
*/
|
||||
integer: function() {
|
||||
return this.rnd.apply(this) * 0x100000000;// 2^32
|
||||
},
|
||||
|
||||
for (i = 0; i < data.length; i++) {
|
||||
n += data.charCodeAt(i);
|
||||
h = 0.02519603282416938 * n;
|
||||
n = h >>> 0;
|
||||
h -= n;
|
||||
h *= n;
|
||||
n = h >>> 0;
|
||||
h -= n;
|
||||
n += h * 0x100000000;// 2^32
|
||||
}
|
||||
/**
|
||||
* Returns a random real number between 0 and 1.
|
||||
* @method Phaser.RandomDataGenerator#frac
|
||||
* @return {number} A random real number between 0 and 1.
|
||||
*/
|
||||
frac: function() {
|
||||
return this.rnd.apply(this) + (this.rnd.apply(this) * 0x200000 | 0) * 1.1102230246251565e-16;// 2^-53
|
||||
},
|
||||
|
||||
return (n >>> 0) * 2.3283064365386963e-10;// 2^-32
|
||||
/**
|
||||
* Returns a random real number between 0 and 2^32.
|
||||
* @method Phaser.RandomDataGenerator#real
|
||||
* @return {number} A random real number between 0 and 2^32.
|
||||
*/
|
||||
real: function() {
|
||||
return this.integer() + this.frac();
|
||||
},
|
||||
|
||||
},
|
||||
/**
|
||||
* Returns a random integer between min and max.
|
||||
* @method Phaser.RandomDataGenerator#integerInRange
|
||||
* @param {number} min - The minimum value in the range.
|
||||
* @param {number} max - The maximum value in the range.
|
||||
* @return {number} A random number between min and max.
|
||||
*/
|
||||
integerInRange: function (min, max) {
|
||||
return Math.floor(this.realInRange(min, max));
|
||||
},
|
||||
|
||||
/**
|
||||
* Returns a random integer between 0 and 2^32.
|
||||
* @method Phaser.RandomDataGenerator#integer
|
||||
* @return {number}
|
||||
*/
|
||||
integer: function() {
|
||||
return this.rnd.apply(this) * 0x100000000;// 2^32
|
||||
},
|
||||
/**
|
||||
* Returns a random real number between min and max.
|
||||
* @method Phaser.RandomDataGenerator#realInRange
|
||||
* @param {number} min - The minimum value in the range.
|
||||
* @param {number} max - The maximum value in the range.
|
||||
* @return {number} A random number between min and max.
|
||||
*/
|
||||
realInRange: function (min, max) {
|
||||
|
||||
/**
|
||||
* Returns a random real number between 0 and 1.
|
||||
* @method Phaser.RandomDataGenerator#frac
|
||||
* @return {number}
|
||||
*/
|
||||
frac: function() {
|
||||
return this.rnd.apply(this) + (this.rnd.apply(this) * 0x200000 | 0) * 1.1102230246251565e-16;// 2^-53
|
||||
},
|
||||
return this.frac() * (max - min) + min;
|
||||
|
||||
/**
|
||||
* Returns a random real number between 0 and 2^32.
|
||||
* @method Phaser.RandomDataGenerator#real
|
||||
* @return {number}
|
||||
*/
|
||||
real: function() {
|
||||
return this.integer() + this.frac();
|
||||
},
|
||||
},
|
||||
|
||||
/**
|
||||
* Returns a random integer between min and max.
|
||||
* @method Phaser.RandomDataGenerator#integerInRange
|
||||
* @param {number} min
|
||||
* @param {number} max
|
||||
* @return {number}
|
||||
*/
|
||||
integerInRange: function (min, max) {
|
||||
return Math.floor(this.realInRange(min, max));
|
||||
},
|
||||
/**
|
||||
* Returns a random real number between -1 and 1.
|
||||
* @method Phaser.RandomDataGenerator#normal
|
||||
* @return {number} A random real number between -1 and 1.
|
||||
*/
|
||||
normal: function () {
|
||||
return 1 - 2 * this.frac();
|
||||
},
|
||||
|
||||
/**
|
||||
* Returns a random real number between min and max.
|
||||
* @method Phaser.RandomDataGenerator#realInRange
|
||||
* @param {number} min
|
||||
* @param {number} max
|
||||
* @return {number}
|
||||
*/
|
||||
realInRange: function (min, max) {
|
||||
/**
|
||||
* Returns a valid RFC4122 version4 ID hex string from https://gist.github.com/1308368
|
||||
* @method Phaser.RandomDataGenerator#uuid
|
||||
* @return {string} A valid RFC4122 version4 ID hex string
|
||||
*/
|
||||
uuid: function () {
|
||||
|
||||
return this.frac() * (max - min) + min;
|
||||
var a = '';
|
||||
var b = '';
|
||||
|
||||
},
|
||||
for (b = a = ''; a++ < 36; b +=~a % 5 | a * 3&4 ? (a^15 ? 8^this.frac() * (a^20 ? 16 : 4) : 4).toString(16) : '-')
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a random real number between -1 and 1.
|
||||
* @method Phaser.RandomDataGenerator#normal
|
||||
* @return {number}
|
||||
*/
|
||||
normal: function () {
|
||||
return 1 - 2 * this.frac();
|
||||
},
|
||||
return b;
|
||||
|
||||
/**
|
||||
* Returns a valid RFC4122 version4 ID hex string from https://gist.github.com/1308368
|
||||
* @method Phaser.RandomDataGenerator#uuid
|
||||
* @return {string}
|
||||
*/
|
||||
uuid: function () {
|
||||
},
|
||||
|
||||
var a, b;
|
||||
/**
|
||||
* Returns a random member of `array`.
|
||||
* @method Phaser.RandomDataGenerator#pick
|
||||
* @param {Array} ary - An Array to pick a random member of.
|
||||
* @return {any} A random member of the array.
|
||||
*/
|
||||
pick: function (ary) {
|
||||
return ary[this.integerInRange(0, ary.length)];
|
||||
},
|
||||
|
||||
for (
|
||||
b=a='';
|
||||
a++<36;
|
||||
b+=~a%5|a*3&4?(a^15?8^this.frac()*(a^20?16:4):4).toString(16):'-'
|
||||
);
|
||||
/**
|
||||
* Returns a random member of `array`, favoring the earlier entries.
|
||||
* @method Phaser.RandomDataGenerator#weightedPick
|
||||
* @param {Array} ary - An Array to pick a random member of.
|
||||
* @return {any} A random member of the array.
|
||||
*/
|
||||
weightedPick: function (ary) {
|
||||
return ary[~~(Math.pow(this.frac(), 2) * ary.length)];
|
||||
},
|
||||
|
||||
return b;
|
||||
/**
|
||||
* Returns a random timestamp between min and max, or between the beginning of 2000 and the end of 2020 if min and max aren't specified.
|
||||
* @method Phaser.RandomDataGenerator#timestamp
|
||||
* @param {number} min - The minimum value in the range.
|
||||
* @param {number} max - The maximum value in the range.
|
||||
* @return {number} A random timestamp between min and max.
|
||||
*/
|
||||
timestamp: function (min, max) {
|
||||
return this.realInRange(min || 946684800000, max || 1577862000000);
|
||||
},
|
||||
|
||||
},
|
||||
|
||||
/**
|
||||
* Returns a random member of `array`.
|
||||
* @method Phaser.RandomDataGenerator#pick
|
||||
* @param {Any} ary
|
||||
* @return {number}
|
||||
*/
|
||||
pick: function (ary) {
|
||||
return ary[this.integerInRange(0, ary.length)];
|
||||
},
|
||||
|
||||
/**
|
||||
* Returns a random member of `array`, favoring the earlier entries.
|
||||
* @method Phaser.RandomDataGenerator#weightedPick
|
||||
* @param {Any} ary
|
||||
* @return {number}
|
||||
*/
|
||||
weightedPick: function (ary) {
|
||||
return ary[~~(Math.pow(this.frac(), 2) * ary.length)];
|
||||
},
|
||||
|
||||
/**
|
||||
* Returns a random timestamp between min and max, or between the beginning of 2000 and the end of 2020 if min and max aren't specified.
|
||||
* @method Phaser.RandomDataGenerator#timestamp
|
||||
* @param {number} min
|
||||
* @param {number} max
|
||||
* @return {number}
|
||||
*/
|
||||
timestamp: function (a, b) {
|
||||
return this.realInRange(a || 946684800000, b || 1577862000000);
|
||||
},
|
||||
|
||||
/**
|
||||
* Returns a random angle between -180 and 180.
|
||||
* @method Phaser.RandomDataGenerator#angle
|
||||
* @return {number}
|
||||
*/
|
||||
angle: function() {
|
||||
return this.integerInRange(-180, 180);
|
||||
}
|
||||
/**
|
||||
* Returns a random angle between -180 and 180.
|
||||
* @method Phaser.RandomDataGenerator#angle
|
||||
* @return {number} A random number between -180 and 180.
|
||||
*/
|
||||
angle: function() {
|
||||
return this.integerInRange(-180, 180);
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user