Skip to content

Commit 142348f

Browse files
committed
Updates
1 parent 7aa82a1 commit 142348f

15 files changed

Lines changed: 1594 additions & 184 deletions

Phaser/physics/AABB.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,15 @@ var Phaser;
1717
this.yw = Math.abs(yw);
1818

1919
this.aabbTileProjections = {};
20-
this.aabbTileProjections[Phaser.Physics.TileMapCell.CTYPE_FULL] = Phaser.Physics.Projection.AABBFull.Collide;
20+
this.aabbTileProjections[Phaser.Physics.TileMapCell.CTYPE_22DEGs] = Phaser.Physics.Projection.AABB22Deg.CollideS;
21+
this.aabbTileProjections[Phaser.Physics.TileMapCell.CTYPE_22DEGb] = Phaser.Physics.Projection.AABB22Deg.CollideB;
22+
this.aabbTileProjections[Phaser.Physics.TileMapCell.CTYPE_45DEG] = Phaser.Physics.Projection.AABB45Deg.Collide;
23+
this.aabbTileProjections[Phaser.Physics.TileMapCell.CTYPE_67DEGs] = Phaser.Physics.Projection.AABB67Deg.CollideS;
24+
this.aabbTileProjections[Phaser.Physics.TileMapCell.CTYPE_67DEGb] = Phaser.Physics.Projection.AABB67Deg.CollideB;
2125
this.aabbTileProjections[Phaser.Physics.TileMapCell.CTYPE_CONCAVE] = Phaser.Physics.Projection.AABBConcave.Collide;
2226
this.aabbTileProjections[Phaser.Physics.TileMapCell.CTYPE_CONVEX] = Phaser.Physics.Projection.AABBConvex.Collide;
27+
this.aabbTileProjections[Phaser.Physics.TileMapCell.CTYPE_FULL] = Phaser.Physics.Projection.AABBFull.Collide;
28+
this.aabbTileProjections[Phaser.Physics.TileMapCell.CTYPE_HALF] = Phaser.Physics.Projection.AABBHalf.Collide;
2329
}
2430
AABB.prototype.integrateVerlet = function () {
2531
var d = 1;
@@ -42,6 +48,7 @@ var Phaser;
4248
};
4349

4450
AABB.prototype.reportCollisionVsWorld = function (px, py, dx, dy, obj) {
51+
if (typeof obj === "undefined") { obj = null; }
4552
var p = this.pos;
4653
var o = this.oldpos;
4754

Phaser/physics/Circle.js

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,15 @@ var Phaser;
1515
this.radius = radius;
1616

1717
this.circleTileProjections = {};
18-
this.circleTileProjections[Phaser.Physics.TileMapCell.CTYPE_FULL] = Phaser.Physics.Projection.CircleFull.Collide;
18+
this.circleTileProjections[Phaser.Physics.TileMapCell.CTYPE_22DEGs] = Phaser.Physics.Projection.Circle22Deg.CollideS;
19+
this.circleTileProjections[Phaser.Physics.TileMapCell.CTYPE_22DEGb] = Phaser.Physics.Projection.Circle22Deg.CollideB;
1920
this.circleTileProjections[Phaser.Physics.TileMapCell.CTYPE_45DEG] = Phaser.Physics.Projection.Circle45Deg.Collide;
21+
this.circleTileProjections[Phaser.Physics.TileMapCell.CTYPE_67DEGs] = Phaser.Physics.Projection.Circle67Deg.CollideS;
22+
this.circleTileProjections[Phaser.Physics.TileMapCell.CTYPE_67DEGb] = Phaser.Physics.Projection.Circle67Deg.CollideB;
2023
this.circleTileProjections[Phaser.Physics.TileMapCell.CTYPE_CONCAVE] = Phaser.Physics.Projection.CircleConcave.Collide;
2124
this.circleTileProjections[Phaser.Physics.TileMapCell.CTYPE_CONVEX] = Phaser.Physics.Projection.CircleConvex.Collide;
25+
this.circleTileProjections[Phaser.Physics.TileMapCell.CTYPE_FULL] = Phaser.Physics.Projection.CircleFull.Collide;
26+
this.circleTileProjections[Phaser.Physics.TileMapCell.CTYPE_HALF] = Phaser.Physics.Projection.CircleHalf.Collide;
2227
}
2328
Circle.prototype.integrateVerlet = function () {
2429
var d = 1;
@@ -41,7 +46,10 @@ var Phaser;
4146
p.y += (d * py) - (d * oy) + g;
4247
};
4348

49+
// px projection vector
50+
// dx surface normal
4451
Circle.prototype.reportCollisionVsWorld = function (px, py, dx, dy, obj) {
52+
if (typeof obj === "undefined") { obj = null; }
4553
var p = this.pos;
4654
var o = this.oldpos;
4755

Phaser/physics/Circle.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ module Phaser.Physics {
9797
fy = ty * f;
9898

9999
//b = 1 + BOUNCE;//this bounce constant should be elsewhere, i.e inside the object/tile/etc..
100-
b = 1 + 0.9;//this bounce constant should be elsewhere, i.e inside the object/tile/etc..
100+
b = 1 + 0.3;//this bounce constant should be elsewhere, i.e inside the object/tile/etc..
101101

102102
bx = (nx * b);
103103
by = (ny * b);
Lines changed: 110 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,110 @@
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 = {}));
Lines changed: 56 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,56 @@
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 AABB45Deg = (function () {
10+
function AABB45Deg() {
11+
}
12+
AABB45Deg.Collide = function (x, y, obj, t) {
13+
var signx = t.signx;
14+
var signy = t.signy;
15+
16+
var ox = (obj.pos.x - (signx * obj.xw)) - t.pos.x;
17+
var oy = (obj.pos.y - (signy * obj.yw)) - t.pos.y;
18+
19+
var sx = t.sx;
20+
var sy = t.sy;
21+
22+
//if the dotprod of (ox,oy) and (sx,sy) is negative, the corner is in the slope
23+
//and we need toproject it out by the magnitude of the projection of (ox,oy) onto (sx,sy)
24+
var dp = (ox * sx) + (oy * sy);
25+
26+
if (dp < 0) {
27+
//collision; project delta onto slope and use this to displace the object
28+
sx *= -dp;
29+
sy *= -dp;
30+
31+
var lenN = Math.sqrt(sx * sx + sy * sy);
32+
var lenP = Math.sqrt(x * x + y * y);
33+
34+
if (lenP < lenN) {
35+
//project along axis
36+
obj.reportCollisionVsWorld(x, y, x / lenP, y / lenP, t);
37+
38+
return Phaser.Physics.AABB.COL_AXIS;
39+
} else {
40+
//project along slope
41+
obj.reportCollisionVsWorld(sx, sy, t.sx, t.sy);
42+
43+
return Phaser.Physics.AABB.COL_OTHER;
44+
}
45+
}
46+
47+
return Phaser.Physics.AABB.COL_NONE;
48+
};
49+
return AABB45Deg;
50+
})();
51+
Projection.AABB45Deg = AABB45Deg;
52+
})(Physics.Projection || (Physics.Projection = {}));
53+
var Projection = Physics.Projection;
54+
})(Phaser.Physics || (Phaser.Physics = {}));
55+
var Physics = Phaser.Physics;
56+
})(Phaser || (Phaser = {}));
Lines changed: 108 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,108 @@
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 AABB67Deg = (function () {
10+
function AABB67Deg() {
11+
}
12+
AABB67Deg.CollideS = function (x, y, obj, t) {
13+
var signx = t.signx;
14+
var signy = t.signy;
15+
16+
var px = obj.pos.x - (signx * obj.xw);
17+
var penX = t.pos.x - px;
18+
19+
if (0 < (penX * signx)) {
20+
var ox = (obj.pos.x - (signx * obj.xw)) - (t.pos.x - (signx * t.xw));
21+
var oy = (obj.pos.y - (signy * obj.yw)) - (t.pos.y + (signy * t.yw));
22+
23+
var sx = t.sx;
24+
var sy = t.sy;
25+
26+
//if the dotprod of (ox,oy) and (sx,sy) is negative, the corner is in the slope
27+
//and we need to project it out by the magnitude of the projection of (ox,oy) onto (sx,sy)
28+
var dp = (ox * sx) + (oy * sy);
29+
if (dp < 0) {
30+
//collision; project delta onto slope and use this to displace the object
31+
sx *= -dp;
32+
sy *= -dp;
33+
34+
var lenN = Math.sqrt(sx * sx + sy * sy);
35+
var lenP = Math.sqrt(x * x + y * y);
36+
37+
var aX = Math.abs(penX);
38+
if (lenP < lenN) {
39+
if (aX < lenP) {
40+
obj.reportCollisionVsWorld(penX, 0, penX / aX, 0, t);
41+
42+
return Phaser.Physics.AABB.COL_OTHER;
43+
} else {
44+
obj.reportCollisionVsWorld(x, y, x / lenP, y / lenP, t);
45+
46+
return Phaser.Physics.AABB.COL_AXIS;
47+
}
48+
} else {
49+
if (aX < lenN) {
50+
obj.reportCollisionVsWorld(penX, 0, penX / aX, 0, t);
51+
52+
return Phaser.Physics.AABB.COL_OTHER;
53+
} else {
54+
obj.reportCollisionVsWorld(sx, sy, t.sx, t.sy, t);
55+
56+
return Phaser.Physics.AABB.COL_OTHER;
57+
}
58+
}
59+
}
60+
}
61+
62+
//if we've reached this point, no collision has occured
63+
return Phaser.Physics.AABB.COL_NONE;
64+
};
65+
66+
AABB67Deg.CollideB = function (x, y, obj, t) {
67+
var signx = t.signx;
68+
var signy = t.signy;
69+
70+
var ox = (obj.pos.x - (signx * obj.xw)) - (t.pos.x + (signx * t.xw));
71+
var oy = (obj.pos.y - (signy * obj.yw)) - (t.pos.y - (signy * t.yw));
72+
73+
var sx = t.sx;
74+
var sy = t.sy;
75+
76+
//if the dotprod of (ox,oy) and (sx,sy) is negative, the corner is in the slope
77+
//and we need toproject it out by the magnitude of the projection of (ox,oy) onto (sx,sy)
78+
var dp = (ox * sx) + (oy * sy);
79+
80+
if (dp < 0) {
81+
//collision; project delta onto slope and use this to displace the object
82+
sx *= -dp;
83+
sy *= -dp;
84+
85+
var lenN = Math.sqrt(sx * sx + sy * sy);
86+
var lenP = Math.sqrt(x * x + y * y);
87+
88+
if (lenP < lenN) {
89+
obj.reportCollisionVsWorld(x, y, x / lenP, y / lenP, t);
90+
91+
return Phaser.Physics.AABB.COL_AXIS;
92+
} else {
93+
obj.reportCollisionVsWorld(sx, sy, t.sx, t.sy, t);
94+
95+
return Phaser.Physics.AABB.COL_OTHER;
96+
}
97+
}
98+
99+
return Phaser.Physics.AABB.COL_NONE;
100+
};
101+
return AABB67Deg;
102+
})();
103+
Projection.AABB67Deg = AABB67Deg;
104+
})(Physics.Projection || (Physics.Projection = {}));
105+
var Projection = Physics.Projection;
106+
})(Phaser.Physics || (Phaser.Physics = {}));
107+
var Physics = Phaser.Physics;
108+
})(Phaser || (Phaser = {}));

0 commit comments

Comments
 (0)