|
1 | | -var Shapes; |
2 | | -(function (Shapes) { |
3 | | - |
4 | | - var Point = Shapes.Point = (function () { |
5 | | - function Point(x, y) { |
6 | | - this.x = x; |
7 | | - this.y = y; |
8 | | - } |
9 | | - Point.prototype.getDist = function () { |
10 | | - return Math.sqrt((this.x * this.x) + (this.y * this.y)); |
11 | | - }; |
12 | | - Point.origin = new Point(0, 0); |
13 | | - return Point; |
14 | | - })(); |
15 | | - |
16 | | -})(Shapes || (Shapes = {})); |
17 | | - |
18 | | -var p = new Shapes.Point(3, 4); |
19 | | -var dist = p.getDist(); |
| 1 | +var Phaser; |
| 2 | +(function (Phaser) { |
| 3 | + (function (Physics) { |
| 4 | + /// <reference path="../../_definitions.ts" /> |
| 5 | + /** |
| 6 | + * Phaser - Physics - Projection |
| 7 | + */ |
| 8 | + (function (Projection) { |
| 9 | + var AABB22Deg = (function () { |
| 10 | + function AABB22Deg() { |
| 11 | + } |
| 12 | + AABB22Deg.CollideS = function (x, y, obj, t) { |
| 13 | + var signx = t.signx; |
| 14 | + var signy = t.signy; |
| 15 | + |
| 16 | + //first we need to check to make sure we're colliding with the slope at all |
| 17 | + var py = obj.pos.y - (signy * obj.yw); |
| 18 | + var penY = t.pos.y - py; |
| 19 | + |
| 20 | + if (0 < (penY * signy)) { |
| 21 | + var ox = (obj.pos.x - (signx * obj.xw)) - (t.pos.x + (signx * t.xw)); |
| 22 | + var oy = (obj.pos.y - (signy * obj.yw)) - (t.pos.y - (signy * t.yw)); |
| 23 | + |
| 24 | + var sx = t.sx; |
| 25 | + var sy = t.sy; |
| 26 | + |
| 27 | + //if the dotprod of (ox,oy) and (sx,sy) is negative, the corner is in the slope |
| 28 | + //and we need toproject it out by the magnitude of the projection of (ox,oy) onto (sx,sy) |
| 29 | + var dp = (ox * sx) + (oy * sy); |
| 30 | + |
| 31 | + if (dp < 0) { |
| 32 | + //collision; project delta onto slope and use this to displace the object |
| 33 | + sx *= -dp; |
| 34 | + sy *= -dp; |
| 35 | + |
| 36 | + var lenN = Math.sqrt(sx * sx + sy * sy); |
| 37 | + var lenP = Math.sqrt(x * x + y * y); |
| 38 | + |
| 39 | + var aY = Math.abs(penY); |
| 40 | + if (lenP < lenN) { |
| 41 | + if (aY < lenP) { |
| 42 | + obj.reportCollisionVsWorld(0, penY, 0, penY / aY, t); |
| 43 | + |
| 44 | + return Phaser.Physics.AABB.COL_OTHER; |
| 45 | + } else { |
| 46 | + obj.reportCollisionVsWorld(x, y, x / lenP, y / lenP, t); |
| 47 | + |
| 48 | + return Phaser.Physics.AABB.COL_AXIS; |
| 49 | + } |
| 50 | + } else { |
| 51 | + if (aY < lenN) { |
| 52 | + obj.reportCollisionVsWorld(0, penY, 0, penY / aY, t); |
| 53 | + |
| 54 | + return Phaser.Physics.AABB.COL_OTHER; |
| 55 | + } else { |
| 56 | + obj.reportCollisionVsWorld(sx, sy, t.sx, t.sy, t); |
| 57 | + |
| 58 | + return Phaser.Physics.AABB.COL_OTHER; |
| 59 | + } |
| 60 | + } |
| 61 | + } |
| 62 | + } |
| 63 | + |
| 64 | + //if we've reached this point, no collision has occured |
| 65 | + return Phaser.Physics.AABB.COL_NONE; |
| 66 | + }; |
| 67 | + |
| 68 | + AABB22Deg.CollideB = function (x, y, obj, t) { |
| 69 | + var signx = t.signx; |
| 70 | + var signy = t.signy; |
| 71 | + |
| 72 | + var ox = (obj.pos.x - (signx * obj.xw)) - (t.pos.x - (signx * t.xw)); |
| 73 | + var oy = (obj.pos.y - (signy * obj.yw)) - (t.pos.y + (signy * t.yw)); |
| 74 | + |
| 75 | + var sx = t.sx; |
| 76 | + var sy = t.sy; |
| 77 | + |
| 78 | + //if the dotprod of (ox,oy) and (sx,sy) is negative, the corner is in the slope |
| 79 | + //and we need toproject it out by the magnitude of the projection of (ox,oy) onto (sx,sy) |
| 80 | + var dp = (ox * sx) + (oy * sy); |
| 81 | + |
| 82 | + if (dp < 0) { |
| 83 | + //collision; project delta onto slope and use this to displace the object |
| 84 | + sx *= -dp; |
| 85 | + sy *= -dp; |
| 86 | + |
| 87 | + var lenN = Math.sqrt(sx * sx + sy * sy); |
| 88 | + var lenP = Math.sqrt(x * x + y * y); |
| 89 | + |
| 90 | + if (lenP < lenN) { |
| 91 | + obj.reportCollisionVsWorld(x, y, x / lenP, y / lenP, t); |
| 92 | + |
| 93 | + return Phaser.Physics.AABB.COL_AXIS; |
| 94 | + } else { |
| 95 | + obj.reportCollisionVsWorld(sx, sy, t.sx, t.sy, t); |
| 96 | + |
| 97 | + return Phaser.Physics.AABB.COL_OTHER; |
| 98 | + } |
| 99 | + } |
| 100 | + |
| 101 | + return Phaser.Physics.AABB.COL_NONE; |
| 102 | + }; |
| 103 | + return AABB22Deg; |
| 104 | + })(); |
| 105 | + Projection.AABB22Deg = AABB22Deg; |
| 106 | + })(Physics.Projection || (Physics.Projection = {})); |
| 107 | + var Projection = Physics.Projection; |
| 108 | + })(Phaser.Physics || (Phaser.Physics = {})); |
| 109 | + var Physics = Phaser.Physics; |
| 110 | +})(Phaser || (Phaser = {})); |
0 commit comments