melonjs 14.2.0 → 14.3.0
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.mjs/_virtual/_commonjsHelpers.js +1 -1
- package/dist/melonjs.mjs/_virtual/arraymultimap.js +1 -1
- package/dist/melonjs.mjs/_virtual/earcut.js +1 -1
- package/dist/melonjs.mjs/_virtual/howler.js +1 -1
- package/dist/melonjs.mjs/_virtual/index.js +1 -1
- package/dist/melonjs.mjs/_virtual/index2.js +1 -1
- package/dist/melonjs.mjs/_virtual/multimap.js +1 -1
- package/dist/melonjs.mjs/_virtual/setmultimap.js +1 -1
- package/dist/melonjs.mjs/application/application.js +153 -9
- package/dist/melonjs.mjs/application/header.js +34 -0
- package/dist/melonjs.mjs/application/resize.js +1 -1
- package/dist/melonjs.mjs/application/settings.js +28 -0
- package/dist/melonjs.mjs/audio/audio.js +1 -1
- package/dist/melonjs.mjs/camera/camera2d.js +2 -2
- package/dist/melonjs.mjs/entity/entity.js +1 -1
- package/dist/melonjs.mjs/game.js +1 -1
- package/dist/melonjs.mjs/geometries/ellipse.js +1 -1
- package/dist/melonjs.mjs/geometries/line.js +1 -1
- package/dist/melonjs.mjs/geometries/path2d.js +1 -1
- package/dist/melonjs.mjs/geometries/point.js +1 -1
- package/dist/melonjs.mjs/geometries/poly.js +1 -1
- package/dist/melonjs.mjs/geometries/rectangle.js +1 -1
- package/dist/melonjs.mjs/geometries/roundrect.js +1 -1
- package/dist/melonjs.mjs/index.js +41 -30
- package/dist/melonjs.mjs/input/gamepad.js +1 -1
- package/dist/melonjs.mjs/input/input.js +1 -1
- package/dist/melonjs.mjs/input/keyboard.js +1 -1
- package/dist/melonjs.mjs/input/pointer.js +2 -2
- package/dist/melonjs.mjs/input/pointerevent.js +2 -2
- package/dist/melonjs.mjs/lang/deprecated.js +1 -1
- package/dist/melonjs.mjs/level/level.js +2 -2
- package/dist/melonjs.mjs/level/tiled/TMXGroup.js +1 -1
- package/dist/melonjs.mjs/level/tiled/TMXLayer.js +2 -2
- package/dist/melonjs.mjs/level/tiled/TMXObject.js +1 -1
- package/dist/melonjs.mjs/level/tiled/TMXTile.js +1 -1
- package/dist/melonjs.mjs/level/tiled/TMXTileMap.js +2 -2
- package/dist/melonjs.mjs/level/tiled/TMXTileset.js +1 -1
- package/dist/melonjs.mjs/level/tiled/TMXTilesetGroup.js +1 -1
- package/dist/melonjs.mjs/level/tiled/TMXUtils.js +1 -1
- package/dist/melonjs.mjs/level/tiled/renderer/TMXHexagonalRenderer.js +1 -1
- package/dist/melonjs.mjs/level/tiled/renderer/TMXIsometricRenderer.js +1 -1
- package/dist/melonjs.mjs/level/tiled/renderer/TMXOrthogonalRenderer.js +1 -1
- package/dist/melonjs.mjs/level/tiled/renderer/TMXRenderer.js +1 -1
- package/dist/melonjs.mjs/level/tiled/renderer/TMXStaggeredRenderer.js +1 -1
- package/dist/melonjs.mjs/loader/loader.js +1 -1
- package/dist/melonjs.mjs/loader/loadingscreen.js +2 -2
- package/dist/melonjs.mjs/loader/melonjs_logo.png.js +1 -1
- package/dist/melonjs.mjs/math/color.js +1 -1
- package/dist/melonjs.mjs/math/math.js +1 -1
- package/dist/melonjs.mjs/math/matrix2.js +1 -1
- package/dist/melonjs.mjs/math/matrix3.js +1 -1
- package/dist/melonjs.mjs/math/observable_vector2.js +1 -1
- package/dist/melonjs.mjs/math/observable_vector3.js +1 -1
- package/dist/melonjs.mjs/math/vector2.js +1 -1
- package/dist/melonjs.mjs/math/vector3.js +1 -1
- package/dist/melonjs.mjs/node_modules/@teppeis/multimaps/dist/src/arraymultimap.js +1 -1
- package/dist/melonjs.mjs/node_modules/@teppeis/multimaps/dist/src/index.js +1 -1
- package/dist/melonjs.mjs/node_modules/@teppeis/multimaps/dist/src/multimap.js +1 -1
- package/dist/melonjs.mjs/node_modules/@teppeis/multimaps/dist/src/setmultimap.js +1 -1
- package/dist/melonjs.mjs/node_modules/earcut/src/earcut.js +1 -1
- package/dist/melonjs.mjs/node_modules/eventemitter3/index.js +1 -1
- package/dist/melonjs.mjs/node_modules/eventemitter3/index2.js +1 -1
- package/dist/melonjs.mjs/node_modules/howler/dist/howler.js +1 -1
- package/dist/melonjs.mjs/particles/emitter.js +1 -1
- package/dist/melonjs.mjs/particles/particle.js +1 -1
- package/dist/melonjs.mjs/particles/settings.js +1 -1
- package/dist/melonjs.mjs/physics/body.js +1 -1
- package/dist/melonjs.mjs/physics/bounds.js +1 -1
- package/dist/melonjs.mjs/physics/collision.js +3 -3
- package/dist/melonjs.mjs/physics/detector.js +174 -146
- package/dist/melonjs.mjs/physics/quadtree.js +1 -1
- package/dist/melonjs.mjs/physics/response.js +1 -1
- package/dist/melonjs.mjs/physics/sat.js +1 -1
- package/dist/melonjs.mjs/physics/world.js +10 -30
- package/dist/melonjs.mjs/plugin/plugin.js +3 -3
- package/dist/melonjs.mjs/renderable/collectable.js +1 -1
- package/dist/melonjs.mjs/renderable/colorlayer.js +1 -1
- package/dist/melonjs.mjs/renderable/container.js +3 -87
- package/dist/melonjs.mjs/renderable/dragndrop.js +1 -1
- package/dist/melonjs.mjs/renderable/imagelayer.js +2 -2
- package/dist/melonjs.mjs/renderable/light2d.js +1 -1
- package/dist/melonjs.mjs/renderable/nineslicesprite.js +1 -1
- package/dist/melonjs.mjs/renderable/renderable.js +1 -1
- package/dist/melonjs.mjs/renderable/sprite.js +1 -1
- package/dist/melonjs.mjs/renderable/trigger.js +2 -2
- package/dist/melonjs.mjs/renderable/ui/uibaseelement.js +1 -1
- package/dist/melonjs.mjs/renderable/ui/uispriteelement.js +1 -1
- package/dist/melonjs.mjs/renderable/ui/uitextbutton.js +1 -1
- package/dist/melonjs.mjs/state/stage.js +2 -2
- package/dist/melonjs.mjs/state/state.js +2 -2
- package/dist/melonjs.mjs/system/device.js +2 -22
- package/dist/melonjs.mjs/system/dom.js +1 -1
- package/dist/melonjs.mjs/system/event.js +1 -1
- package/dist/melonjs.mjs/system/platform.js +1 -1
- package/dist/melonjs.mjs/system/pooling.js +1 -1
- package/dist/melonjs.mjs/system/save.js +1 -1
- package/dist/melonjs.mjs/system/timer.js +1 -1
- package/dist/melonjs.mjs/text/bitmaptext.js +1 -1
- package/dist/melonjs.mjs/text/bitmaptextdata.js +1 -1
- package/dist/melonjs.mjs/text/glyph.js +1 -1
- package/dist/melonjs.mjs/text/text.js +1 -1
- package/dist/melonjs.mjs/text/textmetrics.js +1 -1
- package/dist/melonjs.mjs/text/textstyle.js +1 -1
- package/dist/melonjs.mjs/tweens/easing.js +1 -1
- package/dist/melonjs.mjs/tweens/interpolation.js +1 -1
- package/dist/melonjs.mjs/tweens/tween.js +2 -2
- package/dist/melonjs.mjs/utils/agent.js +1 -1
- package/dist/melonjs.mjs/utils/array.js +1 -1
- package/dist/melonjs.mjs/utils/file.js +1 -1
- package/dist/melonjs.mjs/utils/function.js +1 -1
- package/dist/melonjs.mjs/utils/string.js +1 -1
- package/dist/melonjs.mjs/utils/utils.js +1 -1
- package/dist/melonjs.mjs/video/canvas/canvas_renderer.js +4 -1
- package/dist/melonjs.mjs/video/renderer.js +8 -1
- package/dist/melonjs.mjs/video/texture/atlas.js +1 -1
- package/dist/melonjs.mjs/video/texture/cache.js +1 -1
- package/dist/melonjs.mjs/video/texture/canvas_texture.js +3 -2
- package/dist/melonjs.mjs/video/utils/autodetect.js +27 -0
- package/dist/melonjs.mjs/video/utils/resize.js +1 -1
- package/dist/melonjs.mjs/video/video.js +15 -147
- package/dist/melonjs.mjs/video/webgl/buffer/vertex.js +1 -1
- package/dist/melonjs.mjs/video/webgl/glshader.js +2 -3
- package/dist/melonjs.mjs/video/webgl/shaders/primitive.frag.js +1 -1
- package/dist/melonjs.mjs/video/webgl/shaders/primitive.vert.js +1 -1
- package/dist/melonjs.mjs/video/webgl/shaders/quad.frag.js +1 -1
- package/dist/melonjs.mjs/video/webgl/shaders/quad.vert.js +1 -1
- package/dist/melonjs.mjs/video/webgl/utils/attributes.js +1 -1
- package/dist/melonjs.mjs/video/webgl/utils/precision.js +20 -2
- package/dist/melonjs.mjs/video/webgl/utils/program.js +1 -1
- package/dist/melonjs.mjs/video/webgl/utils/string.js +1 -1
- package/dist/melonjs.mjs/video/webgl/utils/uniforms.js +1 -1
- package/dist/melonjs.mjs/video/webgl/webgl_compositor.js +1 -1
- package/dist/melonjs.mjs/video/webgl/webgl_renderer.js +4 -1
- package/dist/melonjs.module.js +20922 -20921
- package/dist/types/application/application.d.ts +144 -0
- package/dist/types/application/header.d.ts +5 -0
- package/dist/types/application/resize.d.ts +5 -0
- package/dist/types/application/settings.d.ts +18 -0
- package/dist/types/audio/audio.d.ts +267 -0
- package/dist/types/camera/camera2d.d.ts +289 -0
- package/dist/types/entity/entity.d.ts +98 -0
- package/{src/game.js → dist/types/game.d.ts} +3 -14
- package/dist/types/geometries/ellipse.d.ts +154 -0
- package/dist/types/geometries/line.d.ts +11 -0
- package/dist/types/geometries/path2d.d.ts +121 -0
- package/dist/types/geometries/point.d.ts +53 -0
- package/dist/types/geometries/poly.d.ts +222 -0
- package/dist/types/geometries/rectangle.d.ts +176 -0
- package/dist/types/geometries/roundrect.d.ts +52 -0
- package/dist/types/index.d.ts +3 -2
- package/dist/types/input/gamepad.d.ts +95 -0
- package/dist/types/input/input.d.ts +15 -0
- package/dist/types/input/keyboard.d.ts +205 -0
- package/dist/types/input/pointer.d.ts +270 -0
- package/dist/types/input/pointerevent.d.ts +181 -0
- package/dist/types/lang/deprecated.d.ts +53 -0
- package/dist/types/level/level.d.ts +134 -0
- package/dist/types/level/tiled/TMXGroup.d.ts +82 -0
- package/dist/types/level/tiled/TMXLayer.d.ts +180 -0
- package/dist/types/level/tiled/TMXObject.d.ts +195 -0
- package/dist/types/level/tiled/TMXTile.d.ts +78 -0
- package/dist/types/level/tiled/TMXTileMap.d.ts +180 -0
- package/dist/types/level/tiled/TMXTileset.d.ts +94 -0
- package/dist/types/level/tiled/TMXTilesetGroup.d.ts +32 -0
- package/dist/types/level/tiled/TMXUtils.d.ts +47 -0
- package/dist/types/level/tiled/renderer/TMXHexagonalRenderer.d.ts +87 -0
- package/dist/types/level/tiled/renderer/TMXIsometricRenderer.d.ts +55 -0
- package/dist/types/level/tiled/renderer/TMXOrthogonalRenderer.d.ts +43 -0
- package/dist/types/level/tiled/renderer/TMXRenderer.d.ts +75 -0
- package/dist/types/level/tiled/renderer/TMXStaggeredRenderer.d.ts +8 -0
- package/dist/types/loader/loader.d.ts +181 -0
- package/dist/types/loader/loadingscreen.d.ts +18 -0
- package/dist/types/math/color.d.ts +170 -0
- package/dist/types/math/math.d.ts +165 -0
- package/dist/types/math/matrix2.d.ts +209 -0
- package/dist/types/math/matrix3.d.ts +236 -0
- package/dist/types/math/observable_vector2.d.ts +278 -0
- package/dist/types/math/observable_vector3.d.ts +277 -0
- package/dist/types/math/vector2.d.ts +327 -0
- package/dist/types/math/vector3.d.ts +332 -0
- package/dist/types/particles/emitter.d.ts +188 -0
- package/dist/types/particles/particle.d.ts +32 -0
- package/dist/types/particles/settings.d.ts +32 -0
- package/dist/types/physics/body.d.ts +330 -0
- package/dist/types/physics/bounds.d.ts +250 -0
- package/dist/types/physics/collision.d.ts +44 -0
- package/dist/types/physics/detector.d.ts +64 -0
- package/dist/types/physics/quadtree.d.ts +79 -0
- package/dist/types/physics/response.d.ts +37 -0
- package/dist/types/physics/sat.d.ts +48 -0
- package/dist/types/physics/world.d.ts +83 -0
- package/dist/types/plugin/plugin.d.ts +10 -0
- package/dist/types/polyfill/console.d.ts +0 -0
- package/dist/types/polyfill/index.d.ts +1 -0
- package/dist/types/polyfill/performance.d.ts +0 -0
- package/dist/types/polyfill/requestAnimationFrame.d.ts +1 -0
- package/dist/types/polyfill/roundrect.d.ts +0 -0
- package/dist/types/renderable/collectable.d.ts +19 -0
- package/dist/types/renderable/colorlayer.d.ts +28 -0
- package/dist/types/renderable/container.d.ts +302 -0
- package/dist/types/renderable/dragndrop.d.ts +118 -0
- package/dist/types/renderable/imagelayer.d.ts +106 -0
- package/dist/types/renderable/light2d.d.ts +58 -0
- package/dist/types/renderable/nineslicesprite.d.ts +59 -0
- package/dist/types/renderable/renderable.d.ts +402 -0
- package/dist/types/renderable/sprite.d.ts +268 -0
- package/dist/types/renderable/trigger.d.ts +61 -0
- package/dist/types/renderable/ui/uibaseelement.d.ts +95 -0
- package/dist/types/renderable/ui/uispriteelement.d.ts +127 -0
- package/dist/types/renderable/ui/uitextbutton.d.ts +54 -0
- package/dist/types/state/stage.d.ts +116 -0
- package/dist/types/state/state.d.ts +170 -0
- package/dist/types/system/device.d.ts +579 -0
- package/dist/types/system/dom.d.ts +1 -0
- package/dist/types/system/event.d.ts +473 -0
- package/dist/types/system/platform.d.ts +31 -0
- package/dist/types/system/pooling.d.ts +101 -0
- package/dist/types/system/save.d.ts +25 -0
- package/dist/types/system/timer.d.ts +126 -0
- package/dist/types/text/bitmaptext.d.ts +151 -0
- package/dist/types/text/bitmaptextdata.d.ts +35 -0
- package/dist/types/text/glyph.d.ts +28 -0
- package/dist/types/text/text.d.ts +173 -0
- package/dist/types/text/textmetrics.d.ts +47 -0
- package/dist/types/text/textstyle.d.ts +5 -0
- package/dist/types/tweens/easing.d.ts +46 -0
- package/dist/types/tweens/interpolation.d.ts +18 -0
- package/dist/types/tweens/tween.d.ts +195 -0
- package/dist/types/utils/agent.d.ts +21 -0
- package/dist/types/utils/array.d.ts +39 -0
- package/dist/types/utils/file.d.ts +18 -0
- package/dist/types/utils/function.d.ts +32 -0
- package/dist/types/utils/string.d.ts +50 -0
- package/dist/types/utils/utils.d.ts +17 -0
- package/dist/types/video/canvas/canvas_renderer.d.ts +380 -0
- package/dist/types/video/renderer.d.ts +222 -0
- package/dist/types/video/texture/atlas.d.ts +201 -0
- package/dist/types/video/texture/cache.d.ts +45 -0
- package/dist/types/video/texture/canvas_texture.d.ts +78 -0
- package/dist/types/video/utils/autodetect.d.ts +7 -0
- package/dist/types/video/utils/resize.d.ts +4 -0
- package/dist/types/video/video.d.ts +92 -0
- package/dist/types/video/webgl/buffer/vertex.d.ts +56 -0
- package/dist/types/video/webgl/glshader.d.ts +93 -0
- package/dist/types/video/webgl/utils/attributes.d.ts +4 -0
- package/dist/types/video/webgl/utils/precision.d.ts +13 -0
- package/dist/types/video/webgl/utils/program.d.ts +5 -0
- package/dist/types/video/webgl/utils/string.d.ts +5 -0
- package/dist/types/video/webgl/utils/uniforms.d.ts +4 -0
- package/dist/types/video/webgl/webgl_compositor.d.ts +174 -0
- package/dist/types/video/webgl/webgl_renderer.d.ts +429 -0
- package/package.json +4 -4
- package/src/application/application.js +151 -7
- package/src/application/header.js +25 -0
- package/src/{video/utils → application}/resize.js +9 -6
- package/src/application/settings.js +19 -0
- package/src/camera/camera2d.js +1 -1
- package/src/index.js +34 -23
- package/src/input/pointer.js +1 -1
- package/src/input/pointerevent.js +1 -1
- package/src/level/level.js +1 -1
- package/src/level/tiled/TMXLayer.js +1 -1
- package/src/level/tiled/TMXTileMap.js +2 -2
- package/src/loader/loadingscreen.js +1 -1
- package/src/physics/collision.js +2 -2
- package/src/physics/detector.js +172 -145
- package/src/physics/world.js +10 -30
- package/src/renderable/container.js +7 -91
- package/src/renderable/imagelayer.js +1 -1
- package/src/renderable/trigger.js +1 -1
- package/src/renderable/ui/uibaseelement.js +1 -1
- package/src/state/stage.js +1 -1
- package/src/state/state.js +1 -1
- package/src/system/device.js +0 -20
- package/src/tweens/tween.js +1 -1
- package/src/video/canvas/canvas_renderer.js +3 -0
- package/src/video/renderer.js +7 -0
- package/src/video/texture/canvas_texture.js +2 -1
- package/src/video/utils/autodetect.js +18 -0
- package/src/video/video.js +13 -145
- package/src/video/webgl/glshader.js +3 -4
- package/src/video/webgl/utils/precision.js +18 -0
- package/src/video/webgl/webgl_renderer.js +3 -0
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/*!
|
|
2
|
-
* melonJS Game Engine - v14.
|
|
2
|
+
* melonJS Game Engine - v14.3.0
|
|
3
3
|
* http://www.melonjs.org
|
|
4
4
|
* melonjs is licensed under the MIT License.
|
|
5
5
|
* http://www.opensource.org/licenses/mit-license
|
|
@@ -8,7 +8,6 @@
|
|
|
8
8
|
import * as sat from './sat.js';
|
|
9
9
|
import ResponseObject from './response.js';
|
|
10
10
|
import Vector2d from '../math/vector2.js';
|
|
11
|
-
import game from '../game.js';
|
|
12
11
|
import Bounds from './bounds.js';
|
|
13
12
|
|
|
14
13
|
// a dummy object when using Line for raycasting
|
|
@@ -22,169 +21,198 @@ let dummyObj = {
|
|
|
22
21
|
}
|
|
23
22
|
};
|
|
24
23
|
|
|
24
|
+
// some cache bounds object used for collision detection
|
|
25
25
|
let boundsA = new Bounds();
|
|
26
26
|
let boundsB = new Bounds();
|
|
27
27
|
|
|
28
|
-
// the global response object used for collisions
|
|
29
|
-
let globalResponse = new ResponseObject();
|
|
30
|
-
|
|
31
28
|
/**
|
|
32
|
-
*
|
|
33
|
-
* you can redefine this function if you need any specific rules over what should collide with what.
|
|
34
|
-
* @ignore
|
|
35
|
-
* @param {Renderable} a - a reference to the object A.
|
|
36
|
-
* @param {Renderable} b - a reference to the object B.
|
|
37
|
-
* @returns {boolean} true if they should collide, false otherwise
|
|
29
|
+
* the Detector class contains methods for detecting collisions between bodies using a broadphase algorithm.
|
|
38
30
|
*/
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
/**
|
|
56
|
-
* find all the collisions for the specified object
|
|
57
|
-
* @ignore
|
|
58
|
-
* @param {Renderable} objA - object to be tested for collision
|
|
59
|
-
* @param {ResponseObject} [response] - a user defined response object that will be populated if they intersect.
|
|
60
|
-
* @returns {boolean} in case of collision, false otherwise
|
|
61
|
-
*/
|
|
62
|
-
function collisionCheck(objA, response = globalResponse) {
|
|
63
|
-
var collisionCounter = 0;
|
|
64
|
-
// retreive a list of potential colliding objects from the game world
|
|
65
|
-
var candidates = game.world.broadphase.retrieve(objA);
|
|
31
|
+
class Detector {
|
|
32
|
+
/**
|
|
33
|
+
* @param {Container} world - the physic world this detector is bind to
|
|
34
|
+
*/
|
|
35
|
+
constructor(world) {
|
|
36
|
+
// @ignore
|
|
37
|
+
this.world = world;
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* the default response object used for collisions
|
|
41
|
+
* (will be automatically populated by the collides functions)
|
|
42
|
+
* @type {ResponseObject}
|
|
43
|
+
*/
|
|
44
|
+
this.response = new ResponseObject();
|
|
45
|
+
}
|
|
66
46
|
|
|
67
|
-
|
|
68
|
-
|
|
47
|
+
/**
|
|
48
|
+
* determine if two objects should collide (based on both respective objects body collision mask and type).<br>
|
|
49
|
+
* you can redefine this function if you need any specific rules over what should collide with what.
|
|
50
|
+
* @param {Renderable} a - a reference to the object A.
|
|
51
|
+
* @param {Renderable} b - a reference to the object B.
|
|
52
|
+
* @returns {boolean} true if they should collide, false otherwise
|
|
53
|
+
*/
|
|
54
|
+
shouldCollide(a, b) {
|
|
55
|
+
var bodyA = a.body,
|
|
56
|
+
bodyB = b.body;
|
|
57
|
+
return (
|
|
58
|
+
(typeof bodyA === "object" && typeof bodyB === "object") &&
|
|
59
|
+
a !== b &&
|
|
60
|
+
a.isKinematic !== true && b.isKinematic !== true &&
|
|
61
|
+
bodyA.shapes.length > 0 && bodyB.shapes.length > 0 &&
|
|
62
|
+
!(bodyA.isStatic === true && bodyB.isStatic === true) &&
|
|
63
|
+
(bodyA.collisionMask & bodyB.collisionType) !== 0 &&
|
|
64
|
+
(bodyA.collisionType & bodyB.collisionMask) !== 0
|
|
65
|
+
);
|
|
66
|
+
}
|
|
69
67
|
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
68
|
+
/**
|
|
69
|
+
* detect collision between two bodies.
|
|
70
|
+
* @param {Body} bodyA - a reference to body A.
|
|
71
|
+
* @param {Body} bodyB - a reference to body B.
|
|
72
|
+
* @returns {Boolean} true if colliding
|
|
73
|
+
*/
|
|
74
|
+
collides(bodyA, bodyB, response = this.response) {
|
|
75
|
+
// for each shape in body A
|
|
76
|
+
for (var indexA = bodyA.shapes.length, shapeA; indexA--, (shapeA = bodyA.shapes[indexA]);) {
|
|
77
|
+
// for each shape in body B
|
|
78
|
+
for (var indexB = bodyB.shapes.length, shapeB; indexB--, (shapeB = bodyB.shapes[indexB]);) {
|
|
79
|
+
// full SAT collision check
|
|
80
|
+
if (sat["test" + shapeA.shapeType + shapeB.shapeType].call(
|
|
81
|
+
this,
|
|
82
|
+
bodyA.ancestor, // a reference to the object A
|
|
83
|
+
shapeA,
|
|
84
|
+
bodyB.ancestor, // a reference to the object B
|
|
85
|
+
shapeB,
|
|
86
|
+
// clear response object before reusing
|
|
87
|
+
response.clear()) === true
|
|
88
|
+
) {
|
|
73
89
|
|
|
74
|
-
|
|
75
|
-
|
|
90
|
+
// set the shape index
|
|
91
|
+
response.indexShapeA = indexA;
|
|
92
|
+
response.indexShapeB = indexB;
|
|
76
93
|
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
// for each shape in body A
|
|
80
|
-
objA.body.shapes.forEach((shapeA, indexA) => {
|
|
81
|
-
// for each shape in body B
|
|
82
|
-
objB.body.shapes.forEach((shapeB, indexB) => {
|
|
83
|
-
// full SAT collision check
|
|
84
|
-
if (sat["test" + shapeA.shapeType + shapeB.shapeType].call(
|
|
85
|
-
this,
|
|
86
|
-
objA, // a reference to the object A
|
|
87
|
-
shapeA,
|
|
88
|
-
objB, // a reference to the object B
|
|
89
|
-
shapeB,
|
|
90
|
-
// clear response object before reusing
|
|
91
|
-
response.clear()) === true
|
|
92
|
-
) {
|
|
93
|
-
// we touched something !
|
|
94
|
-
collisionCounter++;
|
|
95
|
-
|
|
96
|
-
// set the shape index
|
|
97
|
-
response.indexShapeA = indexA;
|
|
98
|
-
response.indexShapeB = indexB;
|
|
99
|
-
|
|
100
|
-
// execute the onCollision callback
|
|
101
|
-
if (objA.onCollision && objA.onCollision(response, objB) !== false && objA.body.isStatic === false) {
|
|
102
|
-
objA.body.respondToCollision.call(objA.body, response);
|
|
103
|
-
}
|
|
104
|
-
if (objB.onCollision && objB.onCollision(response, objA) !== false && objB.body.isStatic === false) {
|
|
105
|
-
objB.body.respondToCollision.call(objB.body, response);
|
|
106
|
-
}
|
|
107
|
-
}
|
|
108
|
-
});
|
|
109
|
-
});
|
|
94
|
+
return true;
|
|
95
|
+
}
|
|
110
96
|
}
|
|
111
97
|
}
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
return collisionCounter > 0;
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
/**
|
|
118
|
-
* Checks for object colliding with the given line
|
|
119
|
-
* @ignore
|
|
120
|
-
* @param {Line} line - line to be tested for collision
|
|
121
|
-
* @param {Array.<Renderable>} [result] - a user defined array that will be populated with intersecting physic objects.
|
|
122
|
-
* @returns {Array.<Renderable>} an array of intersecting physic objects
|
|
123
|
-
* @example
|
|
124
|
-
* // define a line accross the viewport
|
|
125
|
-
* var ray = new me.Line(
|
|
126
|
-
* // absolute position of the line
|
|
127
|
-
* 0, 0, [
|
|
128
|
-
* // starting point relative to the initial position
|
|
129
|
-
* new me.Vector2d(0, 0),
|
|
130
|
-
* // ending point
|
|
131
|
-
* new me.Vector2d(me.game.viewport.width, me.game.viewport.height)
|
|
132
|
-
* ]);
|
|
133
|
-
*
|
|
134
|
-
* // check for collition
|
|
135
|
-
* result = me.collision.rayCast(ray);
|
|
136
|
-
*
|
|
137
|
-
* if (result.length > 0) {
|
|
138
|
-
* // ...
|
|
139
|
-
* }
|
|
140
|
-
*/
|
|
141
|
-
function rayCast(line, result = []) {
|
|
142
|
-
var collisionCounter = 0;
|
|
143
|
-
|
|
144
|
-
// retrieve a list of potential colliding objects from the game world
|
|
145
|
-
var candidates = game.world.broadphase.retrieve(line);
|
|
146
|
-
|
|
147
|
-
for (var i = candidates.length, objB; i--, (objB = candidates[i]);) {
|
|
148
|
-
|
|
149
|
-
// fast AABB check if both bounding boxes are overlaping
|
|
150
|
-
if (objB.body && line.getBounds().overlaps(objB.getBounds())) {
|
|
98
|
+
return false;
|
|
99
|
+
}
|
|
151
100
|
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
101
|
+
/**
|
|
102
|
+
* find all the collisions for the specified object using a broadphase algorithm
|
|
103
|
+
* @ignore
|
|
104
|
+
* @param {Renderable} objA - object to be tested for collision
|
|
105
|
+
* @returns {boolean} in case of collision, false otherwise
|
|
106
|
+
*/
|
|
107
|
+
collisions(objA) {
|
|
108
|
+
var collisionCounter = 0;
|
|
109
|
+
// retreive a list of potential colliding objects from the game world
|
|
110
|
+
var candidates = this.world.broadphase.retrieve(objA);
|
|
111
|
+
|
|
112
|
+
boundsA.addBounds(objA.getBounds(), true);
|
|
113
|
+
boundsA.addBounds(objA.body.getBounds());
|
|
114
|
+
|
|
115
|
+
candidates.forEach((objB) => {
|
|
116
|
+
// check if both objects "should" collide
|
|
117
|
+
if (this.shouldCollide(objA, objB)) {
|
|
118
|
+
|
|
119
|
+
boundsB.addBounds(objB.getBounds(), true);
|
|
120
|
+
boundsB.addBounds(objB.body.getBounds());
|
|
121
|
+
|
|
122
|
+
// fast AABB check if both bounding boxes are overlaping
|
|
123
|
+
if (boundsA.overlaps(boundsB)) {
|
|
124
|
+
|
|
125
|
+
if (this.collides(objA.body, objB.body)) {
|
|
126
|
+
// we touched something !
|
|
127
|
+
collisionCounter++;
|
|
128
|
+
|
|
129
|
+
// execute the onCollision callback
|
|
130
|
+
if (objA.onCollision && objA.onCollision(this.response, objB) !== false && objA.body.isStatic === false) {
|
|
131
|
+
objA.body.respondToCollision.call(objA.body, this.response);
|
|
132
|
+
}
|
|
133
|
+
if (objB.onCollision && objB.onCollision(this.response, objA) !== false && objB.body.isStatic === false) {
|
|
134
|
+
objB.body.respondToCollision.call(objB.body, this.response);
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
}
|
|
156
138
|
}
|
|
139
|
+
});
|
|
140
|
+
// we could return the amount of objects we collided with ?
|
|
141
|
+
return collisionCounter > 0;
|
|
142
|
+
}
|
|
157
143
|
|
|
158
|
-
|
|
144
|
+
/**
|
|
145
|
+
* Checks for object colliding with the given line
|
|
146
|
+
* @ignore
|
|
147
|
+
* @param {Line} line - line to be tested for collision
|
|
148
|
+
* @param {Array.<Renderable>} [result] - a user defined array that will be populated with intersecting physic objects.
|
|
149
|
+
* @returns {Array.<Renderable>} an array of intersecting physic objects
|
|
150
|
+
* @example
|
|
151
|
+
* // define a line accross the viewport
|
|
152
|
+
* var ray = new me.Line(
|
|
153
|
+
* // absolute position of the line
|
|
154
|
+
* 0, 0, [
|
|
155
|
+
* // starting point relative to the initial position
|
|
156
|
+
* new me.Vector2d(0, 0),
|
|
157
|
+
* // ending point
|
|
158
|
+
* new me.Vector2d(me.game.viewport.width, me.game.viewport.height)
|
|
159
|
+
* ]);
|
|
160
|
+
*
|
|
161
|
+
* // check for collition
|
|
162
|
+
* result = me.collision.rayCast(ray);
|
|
163
|
+
*
|
|
164
|
+
* if (result.length > 0) {
|
|
165
|
+
* // ...
|
|
166
|
+
* }
|
|
167
|
+
*/
|
|
168
|
+
rayCast(line, result = []) {
|
|
169
|
+
var collisionCounter = 0;
|
|
170
|
+
|
|
171
|
+
// retrieve a list of potential colliding objects from the game world
|
|
172
|
+
var candidates = this.world.broadphase.retrieve(line);
|
|
173
|
+
|
|
174
|
+
for (var i = candidates.length, objB; i--, (objB = candidates[i]);) {
|
|
159
175
|
|
|
160
|
-
//
|
|
161
|
-
|
|
162
|
-
do {
|
|
163
|
-
var shapeB = objB.body.getShape(indexB);
|
|
176
|
+
// fast AABB check if both bounding boxes are overlaping
|
|
177
|
+
if (objB.body && line.getBounds().overlaps(objB.getBounds())) {
|
|
164
178
|
|
|
165
|
-
//
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
dummyObj, // a reference to the object A
|
|
170
|
-
shapeA,
|
|
171
|
-
objB, // a reference to the object B
|
|
172
|
-
shapeB
|
|
173
|
-
)) {
|
|
174
|
-
// we touched something !
|
|
175
|
-
result[collisionCounter] = objB;
|
|
176
|
-
collisionCounter++;
|
|
179
|
+
// go trough all defined shapes in B (if any)
|
|
180
|
+
var bLen = objB.body.shapes.length;
|
|
181
|
+
if ( objB.body.shapes.length === 0) {
|
|
182
|
+
continue;
|
|
177
183
|
}
|
|
178
|
-
|
|
179
|
-
|
|
184
|
+
|
|
185
|
+
var shapeA = line;
|
|
186
|
+
|
|
187
|
+
// go through all defined shapes in B
|
|
188
|
+
var indexB = 0;
|
|
189
|
+
do {
|
|
190
|
+
var shapeB = objB.body.getShape(indexB);
|
|
191
|
+
|
|
192
|
+
// full SAT collision check
|
|
193
|
+
if (sat["test" + shapeA.shapeType + shapeB.shapeType]
|
|
194
|
+
.call(
|
|
195
|
+
this,
|
|
196
|
+
dummyObj, // a reference to the object A
|
|
197
|
+
shapeA,
|
|
198
|
+
objB, // a reference to the object B
|
|
199
|
+
shapeB
|
|
200
|
+
)) {
|
|
201
|
+
// we touched something !
|
|
202
|
+
result[collisionCounter] = objB;
|
|
203
|
+
collisionCounter++;
|
|
204
|
+
}
|
|
205
|
+
indexB++;
|
|
206
|
+
} while (indexB < bLen);
|
|
207
|
+
}
|
|
180
208
|
}
|
|
181
|
-
}
|
|
182
209
|
|
|
183
|
-
|
|
184
|
-
|
|
210
|
+
// cap result in case it was not empty
|
|
211
|
+
result.length = collisionCounter;
|
|
185
212
|
|
|
186
|
-
|
|
187
|
-
|
|
213
|
+
// return the list of colliding objects
|
|
214
|
+
return result;
|
|
215
|
+
}
|
|
188
216
|
}
|
|
189
217
|
|
|
190
|
-
export {
|
|
218
|
+
export { Detector as default };
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/*!
|
|
2
|
-
* melonJS Game Engine - v14.
|
|
2
|
+
* melonJS Game Engine - v14.3.0
|
|
3
3
|
* http://www.melonjs.org
|
|
4
4
|
* melonjs is licensed under the MIT License.
|
|
5
5
|
* http://www.opensource.org/licenses/mit-license
|
|
@@ -10,7 +10,7 @@ import { on, GAME_RESET, LEVEL_LOADED } from '../system/event.js';
|
|
|
10
10
|
import QuadTree from './quadtree.js';
|
|
11
11
|
import Container from '../renderable/container.js';
|
|
12
12
|
import collision from './collision.js';
|
|
13
|
-
import
|
|
13
|
+
import Detector from './detector.js';
|
|
14
14
|
import state from '../state/state.js';
|
|
15
15
|
|
|
16
16
|
/**
|
|
@@ -37,30 +37,22 @@ import state from '../state/state.js';
|
|
|
37
37
|
|
|
38
38
|
/**
|
|
39
39
|
* the application (game) this physic world belong to
|
|
40
|
-
* @public
|
|
41
40
|
* @type {Application}
|
|
42
41
|
*/
|
|
43
|
-
this.app =
|
|
42
|
+
this.app = undefined;
|
|
44
43
|
|
|
45
44
|
/**
|
|
46
45
|
* the rate at which the game world is updated,
|
|
47
46
|
* may be greater than or lower than the display fps
|
|
48
|
-
* @public
|
|
49
|
-
* @type {Vector2d}
|
|
50
47
|
* @default 60
|
|
51
|
-
* @name fps
|
|
52
|
-
* @memberof World
|
|
53
48
|
* @see timer.maxfps
|
|
54
49
|
*/
|
|
55
50
|
this.fps = 60;
|
|
56
51
|
|
|
57
52
|
/**
|
|
58
53
|
* world gravity
|
|
59
|
-
* @public
|
|
60
54
|
* @type {Vector2d}
|
|
61
55
|
* @default <0,0.98>
|
|
62
|
-
* @name gravity
|
|
63
|
-
* @memberof World
|
|
64
56
|
*/
|
|
65
57
|
this.gravity = new Vector2d(0, 0.98);
|
|
66
58
|
|
|
@@ -74,28 +66,27 @@ import state from '../state/state.js';
|
|
|
74
66
|
* property to your layer (in Tiled).
|
|
75
67
|
* @type {boolean}
|
|
76
68
|
* @default false
|
|
77
|
-
* @memberof World
|
|
78
69
|
*/
|
|
79
70
|
this.preRender = false;
|
|
80
71
|
|
|
81
72
|
/**
|
|
82
73
|
* the active physic bodies in this simulation
|
|
83
|
-
* @name bodies
|
|
84
|
-
* @memberof World
|
|
85
|
-
* @public
|
|
86
74
|
* @type {Set<Body>}
|
|
87
75
|
*/
|
|
88
76
|
this.bodies = new Set();
|
|
89
77
|
|
|
90
78
|
/**
|
|
91
79
|
* the instance of the game world quadtree used for broadphase
|
|
92
|
-
* @name broadphase
|
|
93
|
-
* @memberof World
|
|
94
|
-
* @public
|
|
95
80
|
* @type {QuadTree}
|
|
96
81
|
*/
|
|
97
82
|
this.broadphase = new QuadTree(this, this.getBounds().clone(), collision.maxChildren, collision.maxDepth);
|
|
98
83
|
|
|
84
|
+
/**
|
|
85
|
+
* the collision detector instance used by this world instance
|
|
86
|
+
* @type {Detector}
|
|
87
|
+
*/
|
|
88
|
+
this.detector = new Detector(this);
|
|
89
|
+
|
|
99
90
|
// reset the world container on the game reset signal
|
|
100
91
|
on(GAME_RESET, this.reset, this);
|
|
101
92
|
|
|
@@ -108,8 +99,6 @@ import state from '../state/state.js';
|
|
|
108
99
|
|
|
109
100
|
/**
|
|
110
101
|
* reset the game world
|
|
111
|
-
* @name reset
|
|
112
|
-
* @memberof World
|
|
113
102
|
*/
|
|
114
103
|
reset() {
|
|
115
104
|
// clear the quadtree
|
|
@@ -128,8 +117,6 @@ import state from '../state/state.js';
|
|
|
128
117
|
|
|
129
118
|
/**
|
|
130
119
|
* Add a physic body to the game world
|
|
131
|
-
* @name addBody
|
|
132
|
-
* @memberof World
|
|
133
120
|
* @see Container.addChild
|
|
134
121
|
* @param {Body} body
|
|
135
122
|
* @returns {World} this game world
|
|
@@ -142,8 +129,6 @@ import state from '../state/state.js';
|
|
|
142
129
|
|
|
143
130
|
/**
|
|
144
131
|
* Remove a physic body from the game world
|
|
145
|
-
* @name removeBody
|
|
146
|
-
* @memberof World
|
|
147
132
|
* @see Container.removeChild
|
|
148
133
|
* @param {Body} body
|
|
149
134
|
* @returns {World} this game world
|
|
@@ -156,8 +141,6 @@ import state from '../state/state.js';
|
|
|
156
141
|
|
|
157
142
|
/**
|
|
158
143
|
* Apply gravity to the given body
|
|
159
|
-
* @name bodyApplyVelocity
|
|
160
|
-
* @memberof World
|
|
161
144
|
* @private
|
|
162
145
|
* @param {Body} body
|
|
163
146
|
*/
|
|
@@ -174,8 +157,6 @@ import state from '../state/state.js';
|
|
|
174
157
|
|
|
175
158
|
/**
|
|
176
159
|
* update the game world
|
|
177
|
-
* @name reset
|
|
178
|
-
* @memberof World
|
|
179
160
|
* @param {number} dt - the time passed since the last frame update
|
|
180
161
|
* @returns {boolean} true if the word is dirty
|
|
181
162
|
*/
|
|
@@ -203,7 +184,7 @@ import state from '../state/state.js';
|
|
|
203
184
|
ancestor.isDirty = true;
|
|
204
185
|
}
|
|
205
186
|
// handle collisions against other objects
|
|
206
|
-
|
|
187
|
+
this.detector.collisions(ancestor);
|
|
207
188
|
// clear body force
|
|
208
189
|
body.force.set(0, 0);
|
|
209
190
|
}
|
|
@@ -213,7 +194,6 @@ import state from '../state/state.js';
|
|
|
213
194
|
// call the super constructor
|
|
214
195
|
return super.update(dt);
|
|
215
196
|
}
|
|
216
|
-
|
|
217
197
|
}
|
|
218
198
|
|
|
219
199
|
export { World as default };
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/*!
|
|
2
|
-
* melonJS Game Engine - v14.
|
|
2
|
+
* melonJS Game Engine - v14.3.0
|
|
3
3
|
* http://www.melonjs.org
|
|
4
4
|
* melonjs is licensed under the MIT License.
|
|
5
5
|
* http://www.opensource.org/licenses/mit-license
|
|
@@ -24,10 +24,10 @@ class BasePlugin {
|
|
|
24
24
|
* this can be overridden by the plugin
|
|
25
25
|
* @public
|
|
26
26
|
* @type {string}
|
|
27
|
-
* @default "14.
|
|
27
|
+
* @default "14.3.0"
|
|
28
28
|
* @name plugin.Base#version
|
|
29
29
|
*/
|
|
30
|
-
this.version = "14.
|
|
30
|
+
this.version = "14.3.0";
|
|
31
31
|
}
|
|
32
32
|
}
|
|
33
33
|
|