melonjs 14.0.0 → 14.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/melonjs.module.js +65 -63
- package/package.json +5 -5
- package/src/physics/bounds.js +9 -6
- package/src/physics/detector.js +53 -52
- package/src/physics/quadtree.js +1 -1
package/dist/melonjs.module.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/*!
|
|
2
|
-
* melonJS Game Engine - v14.0.
|
|
2
|
+
* melonJS Game Engine - v14.0.1
|
|
3
3
|
* http://www.melonjs.org
|
|
4
4
|
* melonjs is licensed under the MIT License.
|
|
5
5
|
* http://www.opensource.org/licenses/mit-license
|
|
@@ -9636,13 +9636,16 @@ class Bounds {
|
|
|
9636
9636
|
*/
|
|
9637
9637
|
addBounds(bounds, clear = false) {
|
|
9638
9638
|
if (clear === true) {
|
|
9639
|
-
this.
|
|
9639
|
+
this.max.x = bounds.max.x;
|
|
9640
|
+
this.min.x = bounds.min.x;
|
|
9641
|
+
this.max.y = bounds.max.y;
|
|
9642
|
+
this.min.y = bounds.min.y;
|
|
9643
|
+
} else {
|
|
9644
|
+
if (bounds.max.x > this.max.x) this.max.x = bounds.max.x;
|
|
9645
|
+
if (bounds.min.x < this.min.x) this.min.x = bounds.min.x;
|
|
9646
|
+
if (bounds.max.y > this.max.y) this.max.y = bounds.max.y;
|
|
9647
|
+
if (bounds.min.y < this.min.y) this.min.y = bounds.min.y;
|
|
9640
9648
|
}
|
|
9641
|
-
|
|
9642
|
-
if (bounds.max.x > this.max.x) this.max.x = bounds.max.x;
|
|
9643
|
-
if (bounds.min.x < this.min.x) this.min.x = bounds.min.x;
|
|
9644
|
-
if (bounds.max.y > this.max.y) this.max.y = bounds.max.y;
|
|
9645
|
-
if (bounds.min.y < this.min.y) this.min.y = bounds.min.y;
|
|
9646
9649
|
}
|
|
9647
9650
|
|
|
9648
9651
|
/**
|
|
@@ -19436,6 +19439,9 @@ let dummyObj = {
|
|
|
19436
19439
|
}
|
|
19437
19440
|
};
|
|
19438
19441
|
|
|
19442
|
+
let boundsA = new Bounds();
|
|
19443
|
+
let boundsB = new Bounds();
|
|
19444
|
+
|
|
19439
19445
|
// the global response object used for collisions
|
|
19440
19446
|
let globalResponse = new ResponseObject();
|
|
19441
19447
|
|
|
@@ -19450,12 +19456,16 @@ let globalResponse = new ResponseObject();
|
|
|
19450
19456
|
* @returns {boolean} true if they should collide, false otherwise
|
|
19451
19457
|
*/
|
|
19452
19458
|
function shouldCollide(a, b) {
|
|
19459
|
+
var bodyA = a.body,
|
|
19460
|
+
bodyB = b.body;
|
|
19453
19461
|
return (
|
|
19462
|
+
a !== b &&
|
|
19454
19463
|
a.isKinematic !== true && b.isKinematic !== true &&
|
|
19455
|
-
typeof
|
|
19456
|
-
|
|
19457
|
-
(
|
|
19458
|
-
(
|
|
19464
|
+
typeof bodyA === "object" && typeof bodyB === "object" &&
|
|
19465
|
+
bodyA.shapes.length > 0 && bodyB.shapes.length > 0 &&
|
|
19466
|
+
!(bodyA.isStatic === true && bodyB.isStatic === true) &&
|
|
19467
|
+
(bodyA.collisionMask & bodyB.collisionType) !== 0 &&
|
|
19468
|
+
(bodyA.collisionType & bodyB.collisionMask) !== 0
|
|
19459
19469
|
);
|
|
19460
19470
|
}
|
|
19461
19471
|
|
|
@@ -19474,60 +19484,52 @@ function collisionCheck(objA, response = globalResponse) {
|
|
|
19474
19484
|
// retreive a list of potential colliding objects from the game world
|
|
19475
19485
|
var candidates = game.world.broadphase.retrieve(objA);
|
|
19476
19486
|
|
|
19477
|
-
|
|
19487
|
+
boundsA.addBounds(objA.getBounds(), true);
|
|
19488
|
+
boundsA.addBounds(objA.body.getBounds());
|
|
19478
19489
|
|
|
19490
|
+
candidates.forEach((objB) => {
|
|
19479
19491
|
// check if both objects "should" collide
|
|
19480
|
-
if (
|
|
19481
|
-
// fast AABB check if both bounding boxes are overlaping
|
|
19482
|
-
objA.body.getBounds().overlaps(objB.body.getBounds())) {
|
|
19492
|
+
if (shouldCollide(objA, objB)) {
|
|
19483
19493
|
|
|
19484
|
-
|
|
19485
|
-
|
|
19486
|
-
var bLen = objB.body.shapes.length;
|
|
19487
|
-
if (aLen === 0 || bLen === 0) {
|
|
19488
|
-
continue;
|
|
19489
|
-
}
|
|
19494
|
+
boundsB.addBounds(objB.getBounds(), true);
|
|
19495
|
+
boundsB.addBounds(objB.body.getBounds());
|
|
19490
19496
|
|
|
19491
|
-
|
|
19492
|
-
|
|
19493
|
-
|
|
19494
|
-
|
|
19495
|
-
|
|
19496
|
-
|
|
19497
|
-
|
|
19498
|
-
|
|
19499
|
-
|
|
19500
|
-
|
|
19501
|
-
|
|
19502
|
-
|
|
19503
|
-
|
|
19504
|
-
|
|
19505
|
-
|
|
19506
|
-
|
|
19507
|
-
|
|
19508
|
-
|
|
19509
|
-
|
|
19510
|
-
|
|
19511
|
-
|
|
19512
|
-
|
|
19513
|
-
|
|
19514
|
-
|
|
19515
|
-
|
|
19516
|
-
|
|
19517
|
-
|
|
19518
|
-
|
|
19519
|
-
|
|
19520
|
-
|
|
19521
|
-
if (objB.onCollision && objB.onCollision(response, objA) !== false && objB.body.isStatic === false) {
|
|
19522
|
-
objB.body.respondToCollision.call(objB.body, response);
|
|
19497
|
+
// fast AABB check if both bounding boxes are overlaping
|
|
19498
|
+
if (boundsA.overlaps(boundsB)) {
|
|
19499
|
+
// for each shape in body A
|
|
19500
|
+
objA.body.shapes.forEach((shapeA, indexA) => {
|
|
19501
|
+
// for each shape in body B
|
|
19502
|
+
objB.body.shapes.forEach((shapeB, indexB) => {
|
|
19503
|
+
// full SAT collision check
|
|
19504
|
+
if (SAT["test" + shapeA.shapeType + shapeB.shapeType].call(
|
|
19505
|
+
this,
|
|
19506
|
+
objA, // a reference to the object A
|
|
19507
|
+
shapeA,
|
|
19508
|
+
objB, // a reference to the object B
|
|
19509
|
+
shapeB,
|
|
19510
|
+
// clear response object before reusing
|
|
19511
|
+
response.clear()) === true
|
|
19512
|
+
) {
|
|
19513
|
+
// we touched something !
|
|
19514
|
+
collisionCounter++;
|
|
19515
|
+
|
|
19516
|
+
// set the shape index
|
|
19517
|
+
response.indexShapeA = indexA;
|
|
19518
|
+
response.indexShapeB = indexB;
|
|
19519
|
+
|
|
19520
|
+
// execute the onCollision callback
|
|
19521
|
+
if (objA.onCollision && objA.onCollision(response, objB) !== false && objA.body.isStatic === false) {
|
|
19522
|
+
objA.body.respondToCollision.call(objA.body, response);
|
|
19523
|
+
}
|
|
19524
|
+
if (objB.onCollision && objB.onCollision(response, objA) !== false && objB.body.isStatic === false) {
|
|
19525
|
+
objB.body.respondToCollision.call(objB.body, response);
|
|
19526
|
+
}
|
|
19523
19527
|
}
|
|
19524
|
-
}
|
|
19525
|
-
|
|
19526
|
-
|
|
19527
|
-
indexA++;
|
|
19528
|
-
} while (indexA < aLen);
|
|
19528
|
+
});
|
|
19529
|
+
});
|
|
19530
|
+
}
|
|
19529
19531
|
}
|
|
19530
|
-
}
|
|
19532
|
+
});
|
|
19531
19533
|
// we could return the amount of objects we collided with ?
|
|
19532
19534
|
return collisionCounter > 0;
|
|
19533
19535
|
}
|
|
@@ -21555,7 +21557,7 @@ class QuadTree {
|
|
|
21555
21557
|
if (item.isFloating === true) {
|
|
21556
21558
|
pos = this.world.app.viewport.localToWorld(bounds.left, bounds.top, QT_VECTOR);
|
|
21557
21559
|
} else {
|
|
21558
|
-
pos = QT_VECTOR.set(
|
|
21560
|
+
pos = QT_VECTOR.set(bounds.left, bounds.top);
|
|
21559
21561
|
}
|
|
21560
21562
|
|
|
21561
21563
|
var index = -1,
|
|
@@ -33047,10 +33049,10 @@ class BasePlugin {
|
|
|
33047
33049
|
* this can be overridden by the plugin
|
|
33048
33050
|
* @public
|
|
33049
33051
|
* @type {string}
|
|
33050
|
-
* @default "14.0.
|
|
33052
|
+
* @default "14.0.1"
|
|
33051
33053
|
* @name plugin.Base#version
|
|
33052
33054
|
*/
|
|
33053
|
-
this.version = "14.0.
|
|
33055
|
+
this.version = "14.0.1";
|
|
33054
33056
|
}
|
|
33055
33057
|
}
|
|
33056
33058
|
|
|
@@ -38181,7 +38183,7 @@ Renderer.prototype.getScreenContext = function() {
|
|
|
38181
38183
|
* @name version
|
|
38182
38184
|
* @type {string}
|
|
38183
38185
|
*/
|
|
38184
|
-
const version = "14.0.
|
|
38186
|
+
const version = "14.0.1";
|
|
38185
38187
|
|
|
38186
38188
|
|
|
38187
38189
|
/**
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "melonjs",
|
|
3
|
-
"version": "14.0.
|
|
3
|
+
"version": "14.0.1",
|
|
4
4
|
"description": "melonJS Game Engine",
|
|
5
5
|
"homepage": "http://www.melonjs.org/",
|
|
6
6
|
"type": "module",
|
|
@@ -69,12 +69,12 @@
|
|
|
69
69
|
"cross-env": "^7.0.3",
|
|
70
70
|
"del-cli": "^5.0.0",
|
|
71
71
|
"eslint": "^8.25.0",
|
|
72
|
-
"expect": "^29.
|
|
72
|
+
"expect": "^29.2.0",
|
|
73
73
|
"expect-mocha-image-snapshot": "^2.0.14",
|
|
74
|
-
"fastify": "^4.
|
|
75
|
-
"mocha": "^10.
|
|
74
|
+
"fastify": "^4.9.1",
|
|
75
|
+
"mocha": "^10.1.0",
|
|
76
76
|
"npm-self-link": "^1.1.7",
|
|
77
|
-
"puppeteer": "^
|
|
77
|
+
"puppeteer": "^19.0.0",
|
|
78
78
|
"rollup": "^2.79.1",
|
|
79
79
|
"rollup-plugin-bundle-size": "^1.0.3",
|
|
80
80
|
"rollup-plugin-string": "^3.0.0",
|
package/src/physics/bounds.js
CHANGED
|
@@ -238,13 +238,16 @@ class Bounds {
|
|
|
238
238
|
*/
|
|
239
239
|
addBounds(bounds, clear = false) {
|
|
240
240
|
if (clear === true) {
|
|
241
|
-
this.
|
|
241
|
+
this.max.x = bounds.max.x;
|
|
242
|
+
this.min.x = bounds.min.x;
|
|
243
|
+
this.max.y = bounds.max.y;
|
|
244
|
+
this.min.y = bounds.min.y;
|
|
245
|
+
} else {
|
|
246
|
+
if (bounds.max.x > this.max.x) this.max.x = bounds.max.x;
|
|
247
|
+
if (bounds.min.x < this.min.x) this.min.x = bounds.min.x;
|
|
248
|
+
if (bounds.max.y > this.max.y) this.max.y = bounds.max.y;
|
|
249
|
+
if (bounds.min.y < this.min.y) this.min.y = bounds.min.y;
|
|
242
250
|
}
|
|
243
|
-
|
|
244
|
-
if (bounds.max.x > this.max.x) this.max.x = bounds.max.x;
|
|
245
|
-
if (bounds.min.x < this.min.x) this.min.x = bounds.min.x;
|
|
246
|
-
if (bounds.max.y > this.max.y) this.max.y = bounds.max.y;
|
|
247
|
-
if (bounds.min.y < this.min.y) this.min.y = bounds.min.y;
|
|
248
251
|
}
|
|
249
252
|
|
|
250
253
|
/**
|
package/src/physics/detector.js
CHANGED
|
@@ -2,6 +2,8 @@ import * as SAT from "./sat.js";
|
|
|
2
2
|
import ResponseObject from "./response.js";
|
|
3
3
|
import Vector2d from "./../math/vector2.js";
|
|
4
4
|
import game from "./../game.js";
|
|
5
|
+
import Bounds from "./bounds.js";
|
|
6
|
+
|
|
5
7
|
|
|
6
8
|
// a dummy object when using Line for raycasting
|
|
7
9
|
let dummyObj = {
|
|
@@ -14,6 +16,9 @@ let dummyObj = {
|
|
|
14
16
|
}
|
|
15
17
|
};
|
|
16
18
|
|
|
19
|
+
let boundsA = new Bounds();
|
|
20
|
+
let boundsB = new Bounds();
|
|
21
|
+
|
|
17
22
|
// the global response object used for collisions
|
|
18
23
|
let globalResponse = new ResponseObject();
|
|
19
24
|
|
|
@@ -28,12 +33,16 @@ let globalResponse = new ResponseObject();
|
|
|
28
33
|
* @returns {boolean} true if they should collide, false otherwise
|
|
29
34
|
*/
|
|
30
35
|
function shouldCollide(a, b) {
|
|
36
|
+
var bodyA = a.body,
|
|
37
|
+
bodyB = b.body;
|
|
31
38
|
return (
|
|
39
|
+
a !== b &&
|
|
32
40
|
a.isKinematic !== true && b.isKinematic !== true &&
|
|
33
|
-
typeof
|
|
34
|
-
|
|
35
|
-
(
|
|
36
|
-
(
|
|
41
|
+
typeof bodyA === "object" && typeof bodyB === "object" &&
|
|
42
|
+
bodyA.shapes.length > 0 && bodyB.shapes.length > 0 &&
|
|
43
|
+
!(bodyA.isStatic === true && bodyB.isStatic === true) &&
|
|
44
|
+
(bodyA.collisionMask & bodyB.collisionType) !== 0 &&
|
|
45
|
+
(bodyA.collisionType & bodyB.collisionMask) !== 0
|
|
37
46
|
);
|
|
38
47
|
}
|
|
39
48
|
|
|
@@ -52,60 +61,52 @@ export function collisionCheck(objA, response = globalResponse) {
|
|
|
52
61
|
// retreive a list of potential colliding objects from the game world
|
|
53
62
|
var candidates = game.world.broadphase.retrieve(objA);
|
|
54
63
|
|
|
55
|
-
|
|
64
|
+
boundsA.addBounds(objA.getBounds(), true);
|
|
65
|
+
boundsA.addBounds(objA.body.getBounds());
|
|
56
66
|
|
|
67
|
+
candidates.forEach((objB) => {
|
|
57
68
|
// check if both objects "should" collide
|
|
58
|
-
if (
|
|
59
|
-
// fast AABB check if both bounding boxes are overlaping
|
|
60
|
-
objA.body.getBounds().overlaps(objB.body.getBounds())) {
|
|
69
|
+
if (shouldCollide(objA, objB)) {
|
|
61
70
|
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
var bLen = objB.body.shapes.length;
|
|
65
|
-
if (aLen === 0 || bLen === 0) {
|
|
66
|
-
continue;
|
|
67
|
-
}
|
|
71
|
+
boundsB.addBounds(objB.getBounds(), true);
|
|
72
|
+
boundsB.addBounds(objB.body.getBounds());
|
|
68
73
|
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
if (objB.onCollision && objB.onCollision(response, objA) !== false && objB.body.isStatic === false) {
|
|
100
|
-
objB.body.respondToCollision.call(objB.body, response);
|
|
74
|
+
// fast AABB check if both bounding boxes are overlaping
|
|
75
|
+
if (boundsA.overlaps(boundsB)) {
|
|
76
|
+
// for each shape in body A
|
|
77
|
+
objA.body.shapes.forEach((shapeA, indexA) => {
|
|
78
|
+
// for each shape in body B
|
|
79
|
+
objB.body.shapes.forEach((shapeB, indexB) => {
|
|
80
|
+
// full SAT collision check
|
|
81
|
+
if (SAT["test" + shapeA.shapeType + shapeB.shapeType].call(
|
|
82
|
+
this,
|
|
83
|
+
objA, // a reference to the object A
|
|
84
|
+
shapeA,
|
|
85
|
+
objB, // a reference to the object B
|
|
86
|
+
shapeB,
|
|
87
|
+
// clear response object before reusing
|
|
88
|
+
response.clear()) === true
|
|
89
|
+
) {
|
|
90
|
+
// we touched something !
|
|
91
|
+
collisionCounter++;
|
|
92
|
+
|
|
93
|
+
// set the shape index
|
|
94
|
+
response.indexShapeA = indexA;
|
|
95
|
+
response.indexShapeB = indexB;
|
|
96
|
+
|
|
97
|
+
// execute the onCollision callback
|
|
98
|
+
if (objA.onCollision && objA.onCollision(response, objB) !== false && objA.body.isStatic === false) {
|
|
99
|
+
objA.body.respondToCollision.call(objA.body, response);
|
|
100
|
+
}
|
|
101
|
+
if (objB.onCollision && objB.onCollision(response, objA) !== false && objB.body.isStatic === false) {
|
|
102
|
+
objB.body.respondToCollision.call(objB.body, response);
|
|
103
|
+
}
|
|
101
104
|
}
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
indexA++;
|
|
106
|
-
} while (indexA < aLen);
|
|
105
|
+
});
|
|
106
|
+
});
|
|
107
|
+
}
|
|
107
108
|
}
|
|
108
|
-
}
|
|
109
|
+
});
|
|
109
110
|
// we could return the amount of objects we collided with ?
|
|
110
111
|
return collisionCounter > 0;
|
|
111
112
|
}
|
package/src/physics/quadtree.js
CHANGED
|
@@ -156,7 +156,7 @@ class QuadTree {
|
|
|
156
156
|
if (item.isFloating === true) {
|
|
157
157
|
pos = this.world.app.viewport.localToWorld(bounds.left, bounds.top, QT_VECTOR);
|
|
158
158
|
} else {
|
|
159
|
-
pos = QT_VECTOR.set(
|
|
159
|
+
pos = QT_VECTOR.set(bounds.left, bounds.top);
|
|
160
160
|
}
|
|
161
161
|
|
|
162
162
|
var index = -1,
|