|
18 | 18 | * |
19 | 19 | * Phaser - http://www.phaser.io |
20 | 20 | * |
21 | | -* v1.1.5 - Built at: Wed Feb 12 2014 15:08:44 |
| 21 | +* v1.1.5 - Built at: Wed Feb 12 2014 15:20:51 |
22 | 22 | * |
23 | 23 | * By Richard Davey http://www.photonstorm.com @photonstorm |
24 | 24 | * |
@@ -29068,6 +29068,271 @@ Phaser.Polygon.prototype.constructor = Phaser.Polygon; |
29068 | 29068 | * @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License} |
29069 | 29069 | */ |
29070 | 29070 |
|
| 29071 | +/** |
| 29072 | +* Creates a new Line object with a start and an end point. |
| 29073 | +* @class Line |
| 29074 | +* @classdesc Phaser - Line |
| 29075 | +* @constructor |
| 29076 | +* @param {number} [x1=0] - The x coordinate of the start of the line. |
| 29077 | +* @param {number} [y1=0] - The y coordinate of the start of the line. |
| 29078 | +* @param {number} [x2=0] - The x coordinate of the end of the line. |
| 29079 | +* @param {number} [y2=0] - The y coordinate of the end of the line. |
| 29080 | +* @return {Phaser.Line} This line object |
| 29081 | +*/ |
| 29082 | +Phaser.Line = function (x1, y1, x2, y2) { |
| 29083 | + |
| 29084 | + x1 = x1 || 0; |
| 29085 | + y1 = y1 || 0; |
| 29086 | + x2 = x2 || 0; |
| 29087 | + y2 = y2 || 0; |
| 29088 | + |
| 29089 | + /** |
| 29090 | + * @property {Phaser.Point} start - The start point of the line. |
| 29091 | + */ |
| 29092 | + this.start = new Phaser.Point(x1, y1); |
| 29093 | + |
| 29094 | + /** |
| 29095 | + * @property {Phaser.Point} end - The end point of the line. |
| 29096 | + */ |
| 29097 | + this.end = new Phaser.Point(x2, y2); |
| 29098 | + |
| 29099 | +}; |
| 29100 | + |
| 29101 | +Phaser.Line.prototype = { |
| 29102 | + |
| 29103 | + /** |
| 29104 | + * Sets the components of the Line to the specified values. |
| 29105 | + * @method Phaser.Line#setTo |
| 29106 | + * @param {number} [x1=0] - The x coordinate of the start of the line. |
| 29107 | + * @param {number} [y1=0] - The y coordinate of the start of the line. |
| 29108 | + * @param {number} [x2=0] - The x coordinate of the end of the line. |
| 29109 | + * @param {number} [y2=0] - The y coordinate of the end of the line. |
| 29110 | + * @return {Phaser.Line} This line object |
| 29111 | + */ |
| 29112 | + setTo: function (x1, y1, x2, y2) { |
| 29113 | + |
| 29114 | + this.start.setTo(x1, y1); |
| 29115 | + this.end.setTo(x2, y2); |
| 29116 | + |
| 29117 | + return this; |
| 29118 | + |
| 29119 | + }, |
| 29120 | + |
| 29121 | + /** |
| 29122 | + * Sets the line to match the x/y coordinates of the two given sprites. |
| 29123 | + * Can optionally be calculated from their center coordinates. |
| 29124 | + * @method Phaser.Line#fromSprite |
| 29125 | + * @param {Phaser.Sprite} startSprite - The coordinates of this Sprite will be set to the Line.start point. |
| 29126 | + * @param {Phaser.Sprite} endSprite - The coordinates of this Sprite will be set to the Line.start point. |
| 29127 | + * @param {boolean} [useCenter=true] - If true it will use startSprite.center.x, if false startSprite.x. |
| 29128 | + * @return {Phaser.Line} This line object |
| 29129 | + */ |
| 29130 | + fromSprite: function (startSprite, endSprite, useCenter) { |
| 29131 | + |
| 29132 | + if (typeof useCenter === 'undefined') { useCenter = true; } |
| 29133 | + |
| 29134 | + if (useCenter) |
| 29135 | + { |
| 29136 | + return this.setTo(startSprite.center.x, startSprite.center.y, endSprite.center.x, endSprite.center.y); |
| 29137 | + } |
| 29138 | + else |
| 29139 | + { |
| 29140 | + return this.setTo(startSprite.x, startSprite.y, endSprite.x, endSprite.y); |
| 29141 | + } |
| 29142 | + |
| 29143 | + }, |
| 29144 | + |
| 29145 | + /** |
| 29146 | + * Checks for intersection between this line and another Line. |
| 29147 | + * If asSegment is true it will check for segment intersection. If asSegment is false it will check for line intersection. |
| 29148 | + * Returns the intersection segment of AB and EF as a Point, or null if there is no intersection. |
| 29149 | + * |
| 29150 | + * @method Phaser.Line#intersects |
| 29151 | + * @param {Phaser.Line} line - The line to check against this one. |
| 29152 | + * @param {boolean} [asSegment=true] - If true it will check for segment intersection, otherwise full line intersection. |
| 29153 | + * @param {Phaser.Point} [result] - A Point object to store the result in, if not given a new one will be created. |
| 29154 | + * @return {Phaser.Point} The intersection segment of the two lines as a Point, or null if there is no intersection. |
| 29155 | + */ |
| 29156 | + intersects: function (line, asSegment, result) { |
| 29157 | + |
| 29158 | + return Phaser.Line.intersectsPoints(this.start, this.end, line.start, line.end, asSegment, result); |
| 29159 | + |
| 29160 | + }, |
| 29161 | + |
| 29162 | + /** |
| 29163 | + * Tests if the given coordinates fall on this line. See pointOnSegment to test against just the line segment. |
| 29164 | + * @method Phaser.Line#pointOnLine |
| 29165 | + * @param {number} x - The line to check against this one. |
| 29166 | + * @param {number} y - The line to check against this one. |
| 29167 | + * @return {boolean} True if the point is on the line, false if not. |
| 29168 | + */ |
| 29169 | + pointOnLine: function (x, y) { |
| 29170 | + |
| 29171 | + return ((x - this.start.x) * (this.end.y - this.end.y) === (this.end.x - this.start.x) * (y - this.end.y)); |
| 29172 | + |
| 29173 | + }, |
| 29174 | + |
| 29175 | + /** |
| 29176 | + * Tests if the given coordinates fall on this line and within the segment. See pointOnLine to test against just the line. |
| 29177 | + * @method Phaser.Line#pointOnSegment |
| 29178 | + * @param {number} x - The line to check against this one. |
| 29179 | + * @param {number} y - The line to check against this one. |
| 29180 | + * @return {boolean} True if the point is on the line and segment, false if not. |
| 29181 | + */ |
| 29182 | + pointOnSegment: function (x, y) { |
| 29183 | + |
| 29184 | + var xMin = Math.min(this.start.x, this.end.x); |
| 29185 | + var xMax = Math.max(this.start.x, this.end.x); |
| 29186 | + var yMin = Math.min(this.start.y, this.end.y); |
| 29187 | + var yMax = Math.max(this.start.y, this.end.y); |
| 29188 | + |
| 29189 | + return (this.pointOnLine(x, y) && (x >= xMin && x <= xMax) && (y >= yMin && y <= yMax)); |
| 29190 | + |
| 29191 | + } |
| 29192 | + |
| 29193 | +}; |
| 29194 | + |
| 29195 | +/** |
| 29196 | +* @name Phaser.Line#length |
| 29197 | +* @property {number} length - Gets the length of the line segment. |
| 29198 | +* @readonly |
| 29199 | +*/ |
| 29200 | +Object.defineProperty(Phaser.Line.prototype, "length", { |
| 29201 | + |
| 29202 | + get: function () { |
| 29203 | + return Math.sqrt((this.end.x - this.start.x) * (this.end.x - this.start.x) + (this.end.y - this.start.y) * (this.end.y - this.start.y)); |
| 29204 | + } |
| 29205 | + |
| 29206 | +}); |
| 29207 | + |
| 29208 | +/** |
| 29209 | +* @name Phaser.Line#angle |
| 29210 | +* @property {number} angle - Gets the angle of the line. |
| 29211 | +* @readonly |
| 29212 | +*/ |
| 29213 | +Object.defineProperty(Phaser.Line.prototype, "angle", { |
| 29214 | + |
| 29215 | + get: function () { |
| 29216 | + return Math.atan2(this.end.x - this.start.x, this.end.y - this.start.y); |
| 29217 | + } |
| 29218 | + |
| 29219 | +}); |
| 29220 | + |
| 29221 | +/** |
| 29222 | +* @name Phaser.Line#slope |
| 29223 | +* @property {number} slope - Gets the slope of the line (y/x). |
| 29224 | +* @readonly |
| 29225 | +*/ |
| 29226 | +Object.defineProperty(Phaser.Line.prototype, "slope", { |
| 29227 | + |
| 29228 | + get: function () { |
| 29229 | + return (this.end.y - this.start.y) / (this.end.x - this.start.x); |
| 29230 | + } |
| 29231 | + |
| 29232 | +}); |
| 29233 | + |
| 29234 | +/** |
| 29235 | +* @name Phaser.Line#perpSlope |
| 29236 | +* @property {number} perpSlope - Gets the perpendicular slope of the line (x/y). |
| 29237 | +* @readonly |
| 29238 | +*/ |
| 29239 | +Object.defineProperty(Phaser.Line.prototype, "perpSlope", { |
| 29240 | + |
| 29241 | + get: function () { |
| 29242 | + return -((this.end.x - this.start.x) / (this.end.y - this.start.y)); |
| 29243 | + } |
| 29244 | + |
| 29245 | +}); |
| 29246 | + |
| 29247 | +/** |
| 29248 | +* Checks for intersection between two lines as defined by the given start and end points. |
| 29249 | +* If asSegment is true it will check for line segment intersection. If asSegment is false it will check for line intersection. |
| 29250 | +* Returns the intersection segment of AB and EF as a Point, or null if there is no intersection. |
| 29251 | +* Adapted from code by Keith Hair |
| 29252 | +* |
| 29253 | +* @method Phaser.Line.intersects |
| 29254 | +* @param {Phaser.Point} a - The start of the first Line to be checked. |
| 29255 | +* @param {Phaser.Point} b - The end of the first line to be checked. |
| 29256 | +* @param {Phaser.Point} e - The start of the second Line to be checked. |
| 29257 | +* @param {Phaser.Point} f - The end of the second line to be checked. |
| 29258 | +* @param {boolean} [asSegment=true] - If true it will check for segment intersection, otherwise full line intersection. |
| 29259 | +* @param {Phaser.Point} [result] - A Point object to store the result in, if not given a new one will be created. |
| 29260 | +* @return {Phaser.Point} The intersection segment of the two lines as a Point, or null if there is no intersection. |
| 29261 | +*/ |
| 29262 | +Phaser.Line.intersectsPoints = function (a, b, e, f, asSegment, result) { |
| 29263 | + |
| 29264 | + if (typeof asSegment === 'undefined') { asSegment = true; } |
| 29265 | + if (typeof result === 'undefined') { result = new Phaser.Point(); } |
| 29266 | + |
| 29267 | + var a1 = b.y - a.y; |
| 29268 | + var a2 = f.y - e.y; |
| 29269 | + var b1 = a.x - b.x; |
| 29270 | + var b2 = e.x - f.x; |
| 29271 | + var c1 = (b.x * a.y) - (a.x * b.y); |
| 29272 | + var c2 = (f.x * e.y) - (e.x * f.y); |
| 29273 | + var denom = (a1 * b2) - (a2 * b1); |
| 29274 | + |
| 29275 | + if (denom === 0) |
| 29276 | + { |
| 29277 | + return null; |
| 29278 | + } |
| 29279 | + |
| 29280 | + result.x = ((b1 * c2) - (b2 * c1)) / denom; |
| 29281 | + result.y = ((a2 * c1) - (a1 * c2)) / denom; |
| 29282 | + |
| 29283 | + if (asSegment) |
| 29284 | + { |
| 29285 | + if (Math.pow((result.x - b.x) + (result.y - b.y), 2) > Math.pow((a.x - b.x) + (a.y - b.y), 2)) |
| 29286 | + { |
| 29287 | + return null; |
| 29288 | + } |
| 29289 | + |
| 29290 | + if (Math.pow((result.x - a.x) + (result.y - a.y), 2) > Math.pow((a.x - b.x) + (a.y - b.y), 2)) |
| 29291 | + { |
| 29292 | + return null; |
| 29293 | + } |
| 29294 | + |
| 29295 | + if (Math.pow((result.x - f.x) + (result.y - f.y), 2) > Math.pow((e.x - f.x) + (e.y - f.y), 2)) |
| 29296 | + { |
| 29297 | + return null; |
| 29298 | + } |
| 29299 | + |
| 29300 | + if (Math.pow((result.x - e.x) + (result.y - e.y), 2) > Math.pow((e.x - f.x) + (e.y - f.y), 2)) |
| 29301 | + { |
| 29302 | + return null; |
| 29303 | + } |
| 29304 | + } |
| 29305 | + |
| 29306 | + return result; |
| 29307 | + |
| 29308 | +}; |
| 29309 | + |
| 29310 | +/** |
| 29311 | +* Checks for intersection between two lines. |
| 29312 | +* If asSegment is true it will check for segment intersection. |
| 29313 | +* If asSegment is false it will check for line intersection. |
| 29314 | +* Returns the intersection segment of AB and EF as a Point, or null if there is no intersection. |
| 29315 | +* Adapted from code by Keith Hair |
| 29316 | +* |
| 29317 | +* @method Phaser.Line.intersects |
| 29318 | +* @param {Phaser.Line} a - The first Line to be checked. |
| 29319 | +* @param {Phaser.Line} b - The second Line to be checked. |
| 29320 | +* @param {boolean} [asSegment=true] - If true it will check for segment intersection, otherwise full line intersection. |
| 29321 | +* @param {Phaser.Point} [result] - A Point object to store the result in, if not given a new one will be created. |
| 29322 | +* @return {Phaser.Point} The intersection segment of the two lines as a Point, or null if there is no intersection. |
| 29323 | +*/ |
| 29324 | +Phaser.Line.intersects = function (a, b, asSegment, result) { |
| 29325 | + |
| 29326 | + return Phaser.Line.intersectsPoints(a.start, a.end, b.start, b.end, asSegment, result); |
| 29327 | + |
| 29328 | +}; |
| 29329 | + |
| 29330 | +/** |
| 29331 | +* @author Richard Davey <rich@photonstorm.com> |
| 29332 | +* @copyright 2014 Photon Storm Ltd. |
| 29333 | +* @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License} |
| 29334 | +*/ |
| 29335 | + |
29071 | 29336 | /** |
29072 | 29337 | * Phaser.Net handles browser URL related tasks such as checking host names, domain names and query string manipulation. |
29073 | 29338 | * |
@@ -41133,10 +41398,10 @@ Phaser.Physics.Arcade.Body.prototype = { |
41133 | 41398 | */ |
41134 | 41399 | separate: function (body, response) { |
41135 | 41400 |
|
41136 | | - if (this.inContact(body)) |
41137 | | - { |
41138 | | - return false; |
41139 | | - } |
| 41401 | + // if (this.inContact(body)) |
| 41402 | + // { |
| 41403 | + // return false; |
| 41404 | + // } |
41140 | 41405 |
|
41141 | 41406 | this._distances[0] = body.right - this.x; // Distance of B to face on left side of A |
41142 | 41407 | this._distances[1] = this.right - body.x; // Distance of B to face on right side of A |
@@ -41195,10 +41460,10 @@ Phaser.Physics.Arcade.Body.prototype = { |
41195 | 41460 | else |
41196 | 41461 | { |
41197 | 41462 | // They can only contact like this if at least one of their sides is open, otherwise it's a separation |
41198 | | - // if (!this.checkCollision.up || !this.checkCollision.down || !this.checkCollision.left || !this.checkCollision.right || !body.checkCollision.up || !body.checkCollision.down || !body.checkCollision.left || !body.checkCollision.right) |
41199 | | - // { |
| 41463 | + if (!this.checkCollision.up || !this.checkCollision.down || !this.checkCollision.left || !this.checkCollision.right || !body.checkCollision.up || !body.checkCollision.down || !body.checkCollision.left || !body.checkCollision.right) |
| 41464 | + { |
41200 | 41465 | this.addContact(body); |
41201 | | - // } |
| 41466 | + } |
41202 | 41467 | } |
41203 | 41468 |
|
41204 | 41469 | return hasSeparated; |
@@ -43718,8 +43983,8 @@ Phaser.Tilemap.prototype = { |
43718 | 43983 | } |
43719 | 43984 |
|
43720 | 43985 | // Find out the difference between tileblock[1].x/y and x/y and use it as an offset, as it's the top left of the block to paste |
43721 | | - var diffX = tileblock[1].x - x; |
43722 | | - var diffY = tileblock[1].y - y; |
| 43986 | + var diffX = x - tileblock[1].x; |
| 43987 | + var diffY = y - tileblock[1].y; |
43723 | 43988 |
|
43724 | 43989 | for (var i = 1; i < tileblock.length; i++) |
43725 | 43990 | { |
|
0 commit comments