Skip to content

Commit eec2f4c

Browse files
committed
Single functions to handle the data
1 parent 780b0bc commit eec2f4c

2 files changed

Lines changed: 209 additions & 0 deletions

File tree

src/physics/arcade/CheckOverlap.js

Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
/**
2+
* @author Richard Davey <rich@photonstorm.com>
3+
* @copyright 2019 Photon Storm Ltd.
4+
* @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License}
5+
*/
6+
7+
var CollisionInfo = require('./CollisionInfo');
8+
var CONST = require('./const');
9+
10+
/**
11+
* Takes a CollisionInfo object and tests to see if the two bodies are still intersecting / touching.
12+
*
13+
* @function Phaser.Physics.Arcade.CheckOverlap
14+
* @since 3.17.0
15+
*
16+
* @param {Phaser.Physics.Arcade.Body} body1 - The first Body to separate.
17+
*
18+
* @return {boolean}
19+
*/
20+
var CheckOverlap = function (collisionInfo)
21+
{
22+
collisionInfo = CollisionInfo.update(collisionInfo);
23+
24+
var face = collisionInfo.face;
25+
var body1 = collisionInfo.body1;
26+
var body2 = collisionInfo.body2;
27+
28+
switch (face)
29+
{
30+
case CONST.FACING_LEFT:
31+
body1.setTouchingLeft();
32+
body2.setTouchingRight();
33+
body1.setBlockedLeft();
34+
body2.setBlockedRight();
35+
break;
36+
37+
case CONST.FACING_RIGHT:
38+
body1.setTouchingRight();
39+
body2.setTouchingLeft();
40+
body1.setBlockedRight();
41+
body2.setBlockedLeft();
42+
break;
43+
44+
case CONST.FACING_UP:
45+
body1.setTouchingUp();
46+
body2.setTouchingDown();
47+
body1.setBlockedUp();
48+
body2.setBlockedDown();
49+
break;
50+
51+
case CONST.FACING_DOWN:
52+
body1.setTouchingDown();
53+
body2.setTouchingUp();
54+
body1.setBlockedDown();
55+
body2.setBlockedUp();
56+
break;
57+
}
58+
59+
if (body1.isWorldBlockedLeft())
60+
{
61+
body2.setHardBlockedLeft();
62+
}
63+
else if (body2.isWorldBlockedLeft())
64+
{
65+
body1.setHardBlockedLeft();
66+
}
67+
68+
if (body1.isWorldBlockedRight())
69+
{
70+
body2.setHardBlockedRight();
71+
}
72+
else if (body2.isWorldBlockedRight())
73+
{
74+
body1.setHardBlockedRight();
75+
}
76+
77+
if (body1.isWorldBlockedUp())
78+
{
79+
body2.setHardBlockedUp();
80+
}
81+
else if (body2.isWorldBlockedUp())
82+
{
83+
body1.setHardBlockedUp();
84+
}
85+
86+
if (body1.isWorldBlockedDown())
87+
{
88+
body2.setHardBlockedDown();
89+
}
90+
else if (body2.isWorldBlockedDown())
91+
{
92+
body1.setHardBlockedDown();
93+
}
94+
95+
return collisionInfo.touching;
96+
};
97+
98+
module.exports = CheckOverlap;

src/physics/arcade/GetOverlap.js

Lines changed: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
1+
/**
2+
* @author Richard Davey <rich@photonstorm.com>
3+
* @copyright 2019 Photon Storm Ltd.
4+
* @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License}
5+
*/
6+
7+
var CollisionInfo = require('./CollisionInfo');
8+
var CONST = require('./const');
9+
10+
/**
11+
*
12+
*
13+
* @function Phaser.Physics.Arcade.GetOverlap
14+
* @since 3.17.0
15+
*
16+
* @param {Phaser.Physics.Arcade.Body} body1 - The first Body to separate.
17+
* @param {Phaser.Physics.Arcade.Body} body2 - The second Body to separate.
18+
* @param {boolean} [overlapOnly] - Is this an overlap only check, or part of separation?
19+
* @param {number} [bias] - A value added to the delta values during collision checks. Increase it to prevent sprite tunneling (sprites passing through each other instead of colliding).
20+
*
21+
* @return {CollisionInfo} A Collision Info object.
22+
*/
23+
var GetOverlap = function (body1, body2, overlapOnly, bias)
24+
{
25+
if (overlapOnly === undefined) { overlapOnly = false; }
26+
if (bias === undefined) { bias = 0; }
27+
28+
var collisionInfo = CollisionInfo.get(body1, body2, overlapOnly, bias);
29+
30+
if (overlapOnly)
31+
{
32+
return collisionInfo;
33+
}
34+
35+
if (collisionInfo.face === CONST.FACING_LEFT)
36+
{
37+
console.log('GetOverlapX leftFace');
38+
39+
if (collisionInfo.body1 === body1)
40+
{
41+
body1.setTouchingLeft();
42+
body2.setTouchingRight();
43+
44+
body1.setBlockedLeft(collisionInfo);
45+
body2.setBlockedRight(collisionInfo);
46+
47+
if (body2.isWorldBlockedLeft())
48+
{
49+
body1.setHardBlockedLeft();
50+
}
51+
}
52+
}
53+
else if (collisionInfo.face === CONST.FACING_RIGHT)
54+
{
55+
console.log('GetOverlapX rightFace');
56+
57+
if (collisionInfo.body1 === body1)
58+
{
59+
body1.setTouchingRight();
60+
body2.setTouchingLeft();
61+
62+
body1.setBlockedRight(collisionInfo);
63+
body2.setBlockedLeft(collisionInfo);
64+
65+
if (body2.isWorldBlockedRight())
66+
{
67+
body1.setHardBlockedRight();
68+
}
69+
}
70+
}
71+
else if (collisionInfo.face === CONST.FACING_UP)
72+
{
73+
console.log('GetOverlapY topFace');
74+
75+
if (collisionInfo.body1 === body1)
76+
{
77+
body1.setTouchingUp();
78+
body2.setTouchingDown();
79+
80+
body1.setBlockedUp(collisionInfo);
81+
body2.setBlockedDown(collisionInfo);
82+
83+
if (body2.isWorldBlockedUp())
84+
{
85+
body1.setHardBlockedUp();
86+
}
87+
}
88+
}
89+
else if (collisionInfo.face === CONST.FACING_DOWN)
90+
{
91+
console.log('GetOverlapY bottomFace');
92+
93+
if (collisionInfo.body1 === body1)
94+
{
95+
body1.setTouchingDown();
96+
body2.setTouchingUp();
97+
98+
body1.setBlockedDown(collisionInfo);
99+
body2.setBlockedUp(collisionInfo);
100+
101+
if (body2.isWorldBlockedDown())
102+
{
103+
body1.setHardBlockedDown();
104+
}
105+
}
106+
}
107+
108+
return collisionInfo;
109+
};
110+
111+
module.exports = GetOverlap;

0 commit comments

Comments
 (0)