forked from phaserjs/phaser
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSolver.js
More file actions
68 lines (59 loc) · 1.76 KB
/
Copy pathSolver.js
File metadata and controls
68 lines (59 loc) · 1.76 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
/**
* @author Richard Davey <rich@photonstorm.com>
* @copyright 2018 Photon Storm Ltd.
* @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License}
*/
var COLLIDES = require('./COLLIDES');
var SeperateX = require('./SeperateX');
var SeperateY = require('./SeperateY');
/**
* Impact Physics Solver
*
* @function Phaser.Physics.Impact.Solver
* @since 3.0.0
*
* @param {Phaser.Physics.Impact.World} world - [description]
* @param {Phaser.Physics.Impact.Body} bodyA - [description]
* @param {Phaser.Physics.Impact.Body} bodyB - [description]
*/
var Solver = function (world, bodyA, bodyB)
{
var weak = null;
if (bodyA.collides === COLLIDES.LITE || bodyB.collides === COLLIDES.FIXED)
{
weak = bodyA;
}
else if (bodyB.collides === COLLIDES.LITE || bodyA.collides === COLLIDES.FIXED)
{
weak = bodyB;
}
if (bodyA.last.x + bodyA.size.x > bodyB.last.x && bodyA.last.x < bodyB.last.x + bodyB.size.x)
{
if (bodyA.last.y < bodyB.last.y)
{
SeperateY(world, bodyA, bodyB, weak);
}
else
{
SeperateY(world, bodyB, bodyA, weak);
}
bodyA.collideWith(bodyB, 'y');
bodyB.collideWith(bodyA, 'y');
world.emit('collide', bodyA, bodyB, 'y');
}
else if (bodyA.last.y + bodyA.size.y > bodyB.last.y && bodyA.last.y < bodyB.last.y + bodyB.size.y)
{
if (bodyA.last.x < bodyB.last.x)
{
SeperateX(world, bodyA, bodyB, weak);
}
else
{
SeperateX(world, bodyB, bodyA, weak);
}
bodyA.collideWith(bodyB, 'x');
bodyB.collideWith(bodyA, 'x');
world.emit('collide', bodyA, bodyB, 'x');
}
};
module.exports = Solver;