diff --git a/README.md b/README.md index 7a37845e..81322dc2 100644 --- a/README.md +++ b/README.md @@ -110,6 +110,8 @@ Version 1.0.7 (in progress in the dev branch) * New angle functions: angleBetween, angleToXY, angleToPointer * velocityFromAngle and velocityFromRotation added with examples created. * Fixed the RandomDataGenerator.sow method so if you give in the same seed you'll now get the same results (thanks Hsaka) +* World.randomX/Y now works with negative World.bounds values. + * TODO: look at Sprite.crop (http://www.html5gamedevs.com/topic/1617-error-in-spritecrop/) * TODO: d-pad example (http://www.html5gamedevs.com/topic/1574-gameinputondown-question/) diff --git a/examples/assets/games/tanks/enemy-tanks.png b/examples/assets/games/tanks/enemy-tanks.png new file mode 100644 index 00000000..825b417a Binary files /dev/null and b/examples/assets/games/tanks/enemy-tanks.png differ diff --git a/examples/assets/games/tanks/explosion.png b/examples/assets/games/tanks/explosion.png new file mode 100644 index 00000000..f57ee35c Binary files /dev/null and b/examples/assets/games/tanks/explosion.png differ diff --git a/examples/games/tanks.php b/examples/games/tanks.php index 18c2572a..42a7e74e 100644 --- a/examples/games/tanks.php +++ b/examples/games/tanks.php @@ -5,13 +5,92 @@ diff --git a/src/core/World.js b/src/core/World.js index d5b6c26e..61bc6692 100644 --- a/src/core/World.js +++ b/src/core/World.js @@ -223,7 +223,16 @@ Object.defineProperty(Phaser.World.prototype, "centerY", { Object.defineProperty(Phaser.World.prototype, "randomX", { get: function () { - return this.game.rnd.integerInRange(this.bounds.x, this.bounds.width); + + if (this.bounds.x < 0) + { + return this.game.rnd.integerInRange(this.bounds.x, (this.bounds.width - Math.abs(this.bounds.x))); + } + else + { + return this.game.rnd.integerInRange(this.bounds.x, this.bounds.width); + } + } }); @@ -236,7 +245,16 @@ Object.defineProperty(Phaser.World.prototype, "randomX", { Object.defineProperty(Phaser.World.prototype, "randomY", { get: function () { - return this.game.rnd.integerInRange(this.bounds.y, this.bounds.height); + + if (this.bounds.y < 0) + { + return this.game.rnd.integerInRange(this.bounds.y, (this.bounds.height - Math.abs(this.bounds.y))); + } + else + { + return this.game.rnd.integerInRange(this.bounds.y, this.bounds.height); + } + } }); diff --git a/src/math/RandomDataGenerator.js b/src/math/RandomDataGenerator.js index b393f0a1..7155902c 100644 --- a/src/math/RandomDataGenerator.js +++ b/src/math/RandomDataGenerator.js @@ -171,9 +171,6 @@ Phaser.RandomDataGenerator.prototype = { */ realInRange: function (min, max) { - min = min || 0; - max = max || 0; - return this.frac() * (max - min) + min; }, diff --git a/src/physics/arcade/ArcadePhysics.js b/src/physics/arcade/ArcadePhysics.js index e9da6706..d23a3d3a 100644 --- a/src/physics/arcade/ArcadePhysics.js +++ b/src/physics/arcade/ArcadePhysics.js @@ -984,7 +984,7 @@ Phaser.Physics.Arcade.prototype = { }, /** - * Move the given display object towards the pointer at a steady velocity. If no pointer is given it will use Phaser.Input.activePointer. + * Move the given display object towards the destination object at a steady velocity. * If you specify a maxTime then it will adjust the speed (over-writing what you set) so it arrives at the destination in that number of seconds. * Timings are approximate due to the way browser timers work. Allow for a variance of +- 50ms. * Note: The display object does not continuously track the target. If the target changes location during transit the display object will not modify its course. @@ -1003,7 +1003,7 @@ Phaser.Physics.Arcade.prototype = { speed = speed || 60; maxTime = maxTime || 0; - this._angle = Math.atan2(destination.y - displayObject.y, destination.x - displaxObject.x); + this._angle = Math.atan2(destination.y - displayObject.y, destination.x - displayObject.x); if (maxTime > 0) {