melonjs 14.0.2 → 14.1.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/README.md +2 -0
- package/dist/melonjs.mjs/_virtual/_commonjsHelpers.js +10 -0
- package/dist/melonjs.mjs/_virtual/arraymultimap.js +10 -0
- package/dist/melonjs.mjs/_virtual/earcut.js +10 -0
- package/dist/melonjs.mjs/_virtual/howler.js +10 -0
- package/dist/melonjs.mjs/_virtual/index.js +10 -0
- package/dist/melonjs.mjs/_virtual/index2.js +10 -0
- package/dist/melonjs.mjs/_virtual/multimap.js +10 -0
- package/dist/melonjs.mjs/_virtual/setmultimap.js +10 -0
- package/dist/melonjs.mjs/application/application.js +240 -0
- package/dist/melonjs.mjs/audio/audio.js +536 -0
- package/dist/melonjs.mjs/camera/camera2d.js +732 -0
- package/dist/melonjs.mjs/entity/entity.js +248 -0
- package/dist/melonjs.mjs/game.js +29 -0
- package/dist/melonjs.mjs/geometries/ellipse.js +275 -0
- package/dist/melonjs.mjs/geometries/line.js +116 -0
- package/dist/melonjs.mjs/geometries/path2d.js +319 -0
- package/dist/melonjs.mjs/geometries/point.js +89 -0
- package/dist/melonjs.mjs/geometries/poly.js +500 -0
- package/dist/melonjs.mjs/geometries/rectangle.js +375 -0
- package/dist/melonjs.mjs/geometries/roundrect.js +168 -0
- package/dist/melonjs.mjs/index.js +248 -0
- package/dist/melonjs.mjs/input/gamepad.js +501 -0
- package/dist/melonjs.mjs/input/input.js +26 -0
- package/dist/melonjs.mjs/input/keyboard.js +470 -0
- package/dist/melonjs.mjs/input/pointer.js +393 -0
- package/dist/melonjs.mjs/input/pointerevent.js +818 -0
- package/dist/melonjs.mjs/lang/deprecated.js +157 -0
- package/dist/melonjs.mjs/level/level.js +297 -0
- package/dist/melonjs.mjs/level/tiled/TMXGroup.js +141 -0
- package/dist/melonjs.mjs/level/tiled/TMXLayer.js +448 -0
- package/dist/melonjs.mjs/level/tiled/TMXObject.js +355 -0
- package/dist/melonjs.mjs/level/tiled/TMXTile.js +194 -0
- package/dist/melonjs.mjs/level/tiled/TMXTileMap.js +639 -0
- package/dist/melonjs.mjs/level/tiled/TMXTileset.js +311 -0
- package/dist/melonjs.mjs/level/tiled/TMXTilesetGroup.js +83 -0
- package/dist/melonjs.mjs/level/tiled/TMXUtils.js +367 -0
- package/dist/melonjs.mjs/level/tiled/renderer/TMXHexagonalRenderer.js +506 -0
- package/dist/melonjs.mjs/level/tiled/renderer/TMXIsometricRenderer.js +220 -0
- package/dist/melonjs.mjs/level/tiled/renderer/TMXOrthogonalRenderer.js +157 -0
- package/dist/melonjs.mjs/level/tiled/renderer/TMXRenderer.js +125 -0
- package/dist/melonjs.mjs/level/tiled/renderer/TMXStaggeredRenderer.js +109 -0
- package/dist/melonjs.mjs/loader/loader.js +801 -0
- package/dist/melonjs.mjs/loader/loadingscreen.js +120 -0
- package/dist/melonjs.mjs/loader/melonjs_logo.png.js +11 -0
- package/dist/melonjs.mjs/math/color.js +618 -0
- package/dist/melonjs.mjs/math/math.js +218 -0
- package/dist/melonjs.mjs/math/matrix2.js +503 -0
- package/dist/melonjs.mjs/math/matrix3.js +681 -0
- package/dist/melonjs.mjs/math/observable_vector2.js +471 -0
- package/dist/melonjs.mjs/math/observable_vector3.js +561 -0
- package/dist/melonjs.mjs/math/vector2.js +528 -0
- package/dist/melonjs.mjs/math/vector3.js +569 -0
- package/dist/melonjs.mjs/node_modules/@teppeis/multimaps/dist/src/arraymultimap.js +73 -0
- package/dist/melonjs.mjs/node_modules/@teppeis/multimaps/dist/src/index.js +21 -0
- package/dist/melonjs.mjs/node_modules/@teppeis/multimaps/dist/src/multimap.js +324 -0
- package/dist/melonjs.mjs/node_modules/@teppeis/multimaps/dist/src/setmultimap.js +69 -0
- package/dist/melonjs.mjs/node_modules/earcut/src/earcut.js +691 -0
- package/dist/melonjs.mjs/node_modules/eventemitter3/index.js +350 -0
- package/dist/melonjs.mjs/node_modules/howler/dist/howler.js +3241 -0
- package/dist/melonjs.mjs/particles/emitter.js +267 -0
- package/dist/melonjs.mjs/particles/particle.js +188 -0
- package/dist/melonjs.mjs/particles/settings.js +319 -0
- package/dist/melonjs.mjs/physics/body.js +704 -0
- package/dist/melonjs.mjs/physics/bounds.js +460 -0
- package/dist/melonjs.mjs/physics/collision.js +132 -0
- package/dist/melonjs.mjs/physics/detector.js +194 -0
- package/dist/melonjs.mjs/physics/quadtree.js +391 -0
- package/dist/melonjs.mjs/physics/response.js +57 -0
- package/dist/melonjs.mjs/physics/sat.js +483 -0
- package/dist/melonjs.mjs/physics/world.js +221 -0
- package/dist/melonjs.mjs/plugin/plugin.js +141 -0
- package/dist/melonjs.mjs/renderable/collectable.js +62 -0
- package/dist/melonjs.mjs/renderable/colorlayer.js +80 -0
- package/dist/melonjs.mjs/renderable/container.js +1018 -0
- package/dist/melonjs.mjs/renderable/dragndrop.js +224 -0
- package/dist/melonjs.mjs/renderable/imagelayer.js +306 -0
- package/dist/melonjs.mjs/renderable/light2d.js +156 -0
- package/dist/melonjs.mjs/renderable/nineslicesprite.js +247 -0
- package/dist/melonjs.mjs/renderable/renderable.js +783 -0
- package/dist/melonjs.mjs/renderable/sprite.js +654 -0
- package/dist/melonjs.mjs/renderable/trigger.js +157 -0
- package/dist/melonjs.mjs/renderable/ui/uibaseelement.js +213 -0
- package/dist/melonjs.mjs/renderable/ui/uispriteelement.js +226 -0
- package/dist/melonjs.mjs/renderable/ui/uitextbutton.js +128 -0
- package/dist/melonjs.mjs/state/stage.js +237 -0
- package/dist/melonjs.mjs/state/state.js +596 -0
- package/dist/melonjs.mjs/system/device.js +909 -0
- package/dist/melonjs.mjs/system/dom.js +78 -0
- package/dist/melonjs.mjs/system/event.js +537 -0
- package/dist/melonjs.mjs/system/platform.js +41 -0
- package/dist/melonjs.mjs/system/pooling.js +209 -0
- package/dist/melonjs.mjs/system/save.js +157 -0
- package/dist/melonjs.mjs/system/timer.js +286 -0
- package/dist/melonjs.mjs/text/bitmaptext.js +364 -0
- package/dist/melonjs.mjs/text/bitmaptextdata.js +199 -0
- package/dist/melonjs.mjs/text/glyph.js +66 -0
- package/dist/melonjs.mjs/text/text.js +453 -0
- package/dist/melonjs.mjs/text/textmetrics.js +176 -0
- package/dist/melonjs.mjs/text/textstyle.js +23 -0
- package/dist/melonjs.mjs/tweens/easing.js +336 -0
- package/dist/melonjs.mjs/tweens/interpolation.js +112 -0
- package/dist/melonjs.mjs/tweens/tween.js +480 -0
- package/dist/melonjs.mjs/utils/agent.js +76 -0
- package/dist/melonjs.mjs/utils/array.js +63 -0
- package/dist/melonjs.mjs/utils/file.js +42 -0
- package/dist/melonjs.mjs/utils/function.js +70 -0
- package/dist/melonjs.mjs/utils/string.js +82 -0
- package/dist/melonjs.mjs/utils/utils.js +173 -0
- package/dist/melonjs.mjs/video/canvas/canvas_renderer.js +807 -0
- package/dist/melonjs.mjs/video/renderer.js +411 -0
- package/dist/melonjs.mjs/video/texture/atlas.js +519 -0
- package/dist/melonjs.mjs/video/texture/cache.js +143 -0
- package/dist/melonjs.mjs/video/texture/canvas_texture.js +144 -0
- package/dist/melonjs.mjs/video/video.js +462 -0
- package/dist/melonjs.mjs/video/webgl/buffer/vertex.js +143 -0
- package/dist/melonjs.mjs/video/webgl/glshader.js +168 -0
- package/dist/melonjs.mjs/video/webgl/shaders/primitive.frag.js +10 -0
- package/dist/melonjs.mjs/video/webgl/shaders/primitive.vert.js +10 -0
- package/dist/melonjs.mjs/video/webgl/shaders/quad.frag.js +10 -0
- package/dist/melonjs.mjs/video/webgl/shaders/quad.vert.js +10 -0
- package/dist/melonjs.mjs/video/webgl/utils/attributes.js +25 -0
- package/dist/melonjs.mjs/video/webgl/utils/precision.js +20 -0
- package/dist/melonjs.mjs/video/webgl/utils/program.js +67 -0
- package/dist/melonjs.mjs/video/webgl/utils/string.js +25 -0
- package/dist/melonjs.mjs/video/webgl/utils/uniforms.js +92 -0
- package/dist/melonjs.mjs/video/webgl/webgl_compositor.js +495 -0
- package/dist/melonjs.mjs/video/webgl/webgl_renderer.js +1036 -0
- package/dist/melonjs.module.d.ts +1163 -1163
- package/dist/melonjs.module.js +1903 -3274
- package/package.json +22 -17
- package/src/application/application.js +3 -3
- package/src/audio/audio.js +32 -32
- package/src/camera/camera2d.js +31 -31
- package/src/entity/entity.js +17 -17
- package/src/geometries/ellipse.js +16 -16
- package/src/geometries/line.js +5 -5
- package/src/geometries/path2d.js +32 -32
- package/src/geometries/poly.js +15 -15
- package/src/geometries/rectangle.js +18 -18
- package/src/geometries/roundrect.js +8 -8
- package/src/input/gamepad.js +15 -15
- package/src/input/keyboard.js +12 -12
- package/src/input/pointer.js +6 -6
- package/src/input/pointerevent.js +12 -12
- package/src/lang/deprecated.js +12 -12
- package/src/level/level.js +25 -25
- package/src/level/tiled/TMXLayer.js +22 -22
- package/src/level/tiled/TMXTile.js +5 -5
- package/src/level/tiled/TMXTileMap.js +6 -6
- package/src/level/tiled/TMXTileset.js +2 -2
- package/src/level/tiled/TMXUtils.js +5 -5
- package/src/level/tiled/renderer/TMXHexagonalRenderer.js +2 -2
- package/src/level/tiled/renderer/TMXIsometricRenderer.js +2 -2
- package/src/level/tiled/renderer/TMXOrthogonalRenderer.js +1 -1
- package/src/level/tiled/renderer/TMXRenderer.js +19 -19
- package/src/loader/loader.js +20 -20
- package/src/math/color.js +20 -20
- package/src/math/math.js +16 -16
- package/src/math/matrix2.js +16 -16
- package/src/math/matrix3.js +25 -25
- package/src/math/observable_vector2.js +14 -14
- package/src/math/observable_vector3.js +16 -16
- package/src/math/vector2.js +9 -9
- package/src/math/vector3.js +10 -10
- package/src/particles/emitter.js +6 -6
- package/src/particles/particle.js +2 -2
- package/src/physics/body.js +28 -28
- package/src/physics/bounds.js +8 -8
- package/src/physics/collision.js +2 -2
- package/src/physics/detector.js +6 -6
- package/src/physics/quadtree.js +11 -11
- package/src/physics/sat.js +31 -31
- package/src/physics/world.js +5 -5
- package/src/plugin/plugin.js +5 -5
- package/src/renderable/collectable.js +3 -3
- package/src/renderable/colorlayer.js +5 -5
- package/src/renderable/container.js +21 -21
- package/src/renderable/dragndrop.js +14 -14
- package/src/renderable/imagelayer.js +13 -13
- package/src/renderable/light2d.js +3 -3
- package/src/renderable/nineslicesprite.js +16 -16
- package/src/renderable/renderable.js +23 -23
- package/src/renderable/sprite.js +28 -28
- package/src/renderable/trigger.js +15 -15
- package/src/renderable/ui/uibaseelement.js +7 -7
- package/src/renderable/ui/uispriteelement.js +6 -6
- package/src/renderable/ui/uitextbutton.js +13 -13
- package/src/state/stage.js +7 -7
- package/src/state/state.js +17 -17
- package/src/system/device.js +11 -11
- package/src/system/event.js +10 -10
- package/src/system/pooling.js +9 -9
- package/src/system/save.js +2 -2
- package/src/system/timer.js +10 -10
- package/src/text/bitmaptext.js +18 -18
- package/src/text/bitmaptextdata.js +2 -2
- package/src/text/text.js +23 -23
- package/src/text/textmetrics.js +8 -8
- package/src/tweens/tween.js +19 -19
- package/src/utils/agent.js +5 -5
- package/src/utils/array.js +4 -4
- package/src/utils/file.js +2 -2
- package/src/utils/function.js +6 -6
- package/src/utils/string.js +5 -5
- package/src/utils/utils.js +4 -4
- package/src/video/canvas/canvas_renderer.js +70 -70
- package/src/video/renderer.js +26 -26
- package/src/video/texture/atlas.js +22 -22
- package/src/video/texture/canvas_texture.js +9 -9
- package/src/video/video.js +17 -17
- package/src/video/webgl/glshader.js +10 -10
- package/src/video/webgl/webgl_compositor.js +41 -41
- package/src/video/webgl/webgl_renderer.js +75 -75
|
@@ -0,0 +1,460 @@
|
|
|
1
|
+
/*!
|
|
2
|
+
* melonJS Game Engine - v14.1.0
|
|
3
|
+
* http://www.melonjs.org
|
|
4
|
+
* melonjs is licensed under the MIT License.
|
|
5
|
+
* http://www.opensource.org/licenses/mit-license
|
|
6
|
+
* @copyright (C) 2011 - 2022 Olivier Biot (AltByte Pte Ltd)
|
|
7
|
+
*/
|
|
8
|
+
import pool from '../system/pooling.js';
|
|
9
|
+
import Vector2d from '../math/vector2.js';
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* @classdesc
|
|
13
|
+
* a bound object contains methods for creating and manipulating axis-aligned bounding boxes (AABB).
|
|
14
|
+
*/
|
|
15
|
+
class Bounds {
|
|
16
|
+
/**
|
|
17
|
+
* @param {Vector2d[]} [vertices] - an array of me.Vector2d points
|
|
18
|
+
*/
|
|
19
|
+
constructor(vertices) {
|
|
20
|
+
// @ignore
|
|
21
|
+
this._center = new Vector2d();
|
|
22
|
+
this.onResetEvent(vertices);
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* @ignore
|
|
27
|
+
*/
|
|
28
|
+
onResetEvent(vertices) {
|
|
29
|
+
if (typeof this.min === "undefined") {
|
|
30
|
+
this.min = { x: Infinity, y: Infinity };
|
|
31
|
+
this.max = { x: -Infinity, y: -Infinity };
|
|
32
|
+
} else {
|
|
33
|
+
this.clear();
|
|
34
|
+
}
|
|
35
|
+
if (typeof vertices !== "undefined") {
|
|
36
|
+
this.update(vertices);
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* reset the bound
|
|
42
|
+
* @name clear
|
|
43
|
+
* @memberof Bounds
|
|
44
|
+
*/
|
|
45
|
+
clear() {
|
|
46
|
+
this.setMinMax(Infinity, Infinity, -Infinity, -Infinity);
|
|
47
|
+
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* sets the bounds to the given min and max value
|
|
52
|
+
* @name setMinMax
|
|
53
|
+
* @memberof Bounds
|
|
54
|
+
* @param {number} minX
|
|
55
|
+
* @param {number} minY
|
|
56
|
+
* @param {number} maxX
|
|
57
|
+
* @param {number} maxY
|
|
58
|
+
*/
|
|
59
|
+
setMinMax(minX, minY, maxX, maxY) {
|
|
60
|
+
this.min.x = minX;
|
|
61
|
+
this.min.y = minY;
|
|
62
|
+
|
|
63
|
+
this.max.x = maxX;
|
|
64
|
+
this.max.y = maxY;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
/**
|
|
68
|
+
* x position of the bound
|
|
69
|
+
* @public
|
|
70
|
+
* @type {number}
|
|
71
|
+
* @name x
|
|
72
|
+
* @memberof Bounds
|
|
73
|
+
*/
|
|
74
|
+
get x() {
|
|
75
|
+
return this.min.x;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
set x(value) {
|
|
79
|
+
var deltaX = this.max.x - this.min.x;
|
|
80
|
+
this.min.x = value;
|
|
81
|
+
this.max.x = value + deltaX;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
/**
|
|
85
|
+
* y position of the bounds
|
|
86
|
+
* @public
|
|
87
|
+
* @type {number}
|
|
88
|
+
* @name y
|
|
89
|
+
* @memberof Bounds
|
|
90
|
+
*/
|
|
91
|
+
get y() {
|
|
92
|
+
return this.min.y;
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
set y(value) {
|
|
96
|
+
var deltaY = this.max.y - this.min.y;
|
|
97
|
+
|
|
98
|
+
this.min.y = value;
|
|
99
|
+
this.max.y = value + deltaY;
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
/**
|
|
103
|
+
* width of the bounds
|
|
104
|
+
* @public
|
|
105
|
+
* @type {number}
|
|
106
|
+
* @name width
|
|
107
|
+
* @memberof Bounds
|
|
108
|
+
*/
|
|
109
|
+
get width() {
|
|
110
|
+
return this.max.x - this.min.x;
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
set width(value) {
|
|
114
|
+
this.max.x = this.min.x + value;
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
/**
|
|
118
|
+
* width of the bounds
|
|
119
|
+
* @public
|
|
120
|
+
* @type {number}
|
|
121
|
+
* @name width
|
|
122
|
+
* @memberof Bounds
|
|
123
|
+
*/
|
|
124
|
+
get height() {
|
|
125
|
+
return this.max.y - this.min.y;
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
set height(value) {
|
|
129
|
+
this.max.y = this.min.y + value;
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
/**
|
|
133
|
+
* left coordinate of the bound
|
|
134
|
+
* @public
|
|
135
|
+
* @type {number}
|
|
136
|
+
* @name left
|
|
137
|
+
* @memberof Bounds
|
|
138
|
+
*/
|
|
139
|
+
get left() {
|
|
140
|
+
return this.min.x;
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
/**
|
|
144
|
+
* right coordinate of the bound
|
|
145
|
+
* @public
|
|
146
|
+
* @type {number}
|
|
147
|
+
* @name right
|
|
148
|
+
* @memberof Bounds
|
|
149
|
+
*/
|
|
150
|
+
get right() {
|
|
151
|
+
return this.max.x;
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
/**
|
|
155
|
+
* top coordinate of the bound
|
|
156
|
+
* @public
|
|
157
|
+
* @type {number}
|
|
158
|
+
* @name top
|
|
159
|
+
* @memberof Bounds
|
|
160
|
+
*/
|
|
161
|
+
get top() {
|
|
162
|
+
return this.min.y;
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
/**
|
|
166
|
+
* bottom coordinate of the bound
|
|
167
|
+
* @public
|
|
168
|
+
* @type {number}
|
|
169
|
+
* @name bottom
|
|
170
|
+
* @memberof Bounds
|
|
171
|
+
*/
|
|
172
|
+
get bottom() {
|
|
173
|
+
return this.max.y;
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
/**
|
|
177
|
+
* center position of the bound on the x axis
|
|
178
|
+
* @public
|
|
179
|
+
* @type {number}
|
|
180
|
+
* @name centerX
|
|
181
|
+
* @memberof Bounds
|
|
182
|
+
*/
|
|
183
|
+
get centerX() {
|
|
184
|
+
return this.min.x + (this.width / 2);
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
/**
|
|
188
|
+
* center position of the bound on the y axis
|
|
189
|
+
* @public
|
|
190
|
+
* @type {number}
|
|
191
|
+
* @name centerY
|
|
192
|
+
* @memberof Bounds
|
|
193
|
+
*/
|
|
194
|
+
get centerY() {
|
|
195
|
+
return this.min.y + (this.height / 2);
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
/**
|
|
199
|
+
* return the center position of the bound
|
|
200
|
+
* @public
|
|
201
|
+
* @type {Vector2d}
|
|
202
|
+
* @name center
|
|
203
|
+
* @memberof Bounds
|
|
204
|
+
*/
|
|
205
|
+
get center() {
|
|
206
|
+
return this._center.set(this.centerX, this.centerY);
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
/**
|
|
210
|
+
* Updates bounds using the given vertices
|
|
211
|
+
* @name update
|
|
212
|
+
* @memberof Bounds
|
|
213
|
+
* @param {Vector2d[]} vertices - an array of me.Vector2d points
|
|
214
|
+
*/
|
|
215
|
+
update(vertices) {
|
|
216
|
+
this.add(vertices, true);
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
/**
|
|
220
|
+
* add the given vertices to the bounds definition.
|
|
221
|
+
* @name add
|
|
222
|
+
* @memberof Bounds
|
|
223
|
+
* @param {Vector2d[]} vertices - an array of me.Vector2d points
|
|
224
|
+
* @param {boolean} [clear=false] - either to reset the bounds before adding the new vertices
|
|
225
|
+
*/
|
|
226
|
+
add(vertices, clear = false) {
|
|
227
|
+
if (clear === true) {
|
|
228
|
+
this.clear();
|
|
229
|
+
}
|
|
230
|
+
for (var i = 0; i < vertices.length; i++) {
|
|
231
|
+
var vertex = vertices[i];
|
|
232
|
+
if (vertex.x > this.max.x) this.max.x = vertex.x;
|
|
233
|
+
if (vertex.x < this.min.x) this.min.x = vertex.x;
|
|
234
|
+
if (vertex.y > this.max.y) this.max.y = vertex.y;
|
|
235
|
+
if (vertex.y < this.min.y) this.min.y = vertex.y;
|
|
236
|
+
}
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
/**
|
|
240
|
+
* add the given bounds to the bounds definition.
|
|
241
|
+
* @name addBounds
|
|
242
|
+
* @memberof Bounds
|
|
243
|
+
* @param {Bounds} bounds
|
|
244
|
+
* @param {boolean} [clear=false] - either to reset the bounds before adding the new vertices
|
|
245
|
+
*/
|
|
246
|
+
addBounds(bounds, clear = false) {
|
|
247
|
+
if (clear === true) {
|
|
248
|
+
this.max.x = bounds.max.x;
|
|
249
|
+
this.min.x = bounds.min.x;
|
|
250
|
+
this.max.y = bounds.max.y;
|
|
251
|
+
this.min.y = bounds.min.y;
|
|
252
|
+
} else {
|
|
253
|
+
if (bounds.max.x > this.max.x) this.max.x = bounds.max.x;
|
|
254
|
+
if (bounds.min.x < this.min.x) this.min.x = bounds.min.x;
|
|
255
|
+
if (bounds.max.y > this.max.y) this.max.y = bounds.max.y;
|
|
256
|
+
if (bounds.min.y < this.min.y) this.min.y = bounds.min.y;
|
|
257
|
+
}
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
/**
|
|
261
|
+
* add the given point to the bounds definition.
|
|
262
|
+
* @name addPoint
|
|
263
|
+
* @memberof Bounds
|
|
264
|
+
* @param {Vector2d|Point} point - the point to be added to the bounds
|
|
265
|
+
* @param {Matrix2d} [m] - an optional transform to apply to the given point (only if the given point is a vector)
|
|
266
|
+
*/
|
|
267
|
+
addPoint(point, m) {
|
|
268
|
+
if ((typeof m !== "undefined") && (typeof point.rotate === "function")) {
|
|
269
|
+
// only Vectors object have a rotate function
|
|
270
|
+
point = m.apply(point);
|
|
271
|
+
}
|
|
272
|
+
this.min.x = Math.min(this.min.x, point.x);
|
|
273
|
+
this.max.x = Math.max(this.max.x, point.x);
|
|
274
|
+
this.min.y = Math.min(this.min.y, point.y);
|
|
275
|
+
this.max.y = Math.max(this.max.y, point.y);
|
|
276
|
+
}
|
|
277
|
+
|
|
278
|
+
/**
|
|
279
|
+
* add the given quad coordinates to this bound definition, multiplied by the given matrix
|
|
280
|
+
* @name addFrame
|
|
281
|
+
* @memberof Bounds
|
|
282
|
+
* @param {number} x0 - left X coordinates of the quad
|
|
283
|
+
* @param {number} y0 - top Y coordinates of the quad
|
|
284
|
+
* @param {number} x1 - right X coordinates of the quad
|
|
285
|
+
* @param {number} y1 - bottom y coordinates of the quad
|
|
286
|
+
* @param {Matrix2d} [m] - an optional transform to apply to the given frame coordinates
|
|
287
|
+
*/
|
|
288
|
+
addFrame(x0, y0, x1, y1, m) {
|
|
289
|
+
var v = pool.pull("Vector2d");
|
|
290
|
+
|
|
291
|
+
// transform all points and add to the bound definition
|
|
292
|
+
this.addPoint(v.set(x0, y0), m);
|
|
293
|
+
this.addPoint(v.set(x1, y0), m);
|
|
294
|
+
this.addPoint(v.set(x0, y1), m);
|
|
295
|
+
this.addPoint(v.set(x1, y1), m);
|
|
296
|
+
|
|
297
|
+
pool.push(v);
|
|
298
|
+
}
|
|
299
|
+
|
|
300
|
+
/**
|
|
301
|
+
* Returns true if the bounds contains the given point.
|
|
302
|
+
* @name contains
|
|
303
|
+
* @memberof Bounds
|
|
304
|
+
* @method
|
|
305
|
+
* @param {Vector2d} point
|
|
306
|
+
* @returns {boolean} True if the bounds contain the point, otherwise false
|
|
307
|
+
*/
|
|
308
|
+
/**
|
|
309
|
+
* Returns true if the bounds contains the given point.
|
|
310
|
+
* @name contains
|
|
311
|
+
* @memberof Bounds
|
|
312
|
+
* @param {number} x
|
|
313
|
+
* @param {number} y
|
|
314
|
+
* @returns {boolean} True if the bounds contain the point, otherwise false
|
|
315
|
+
*/
|
|
316
|
+
contains() {
|
|
317
|
+
var arg0 = arguments[0];
|
|
318
|
+
var _x1, _x2, _y1, _y2;
|
|
319
|
+
if (arguments.length === 2) {
|
|
320
|
+
// x, y
|
|
321
|
+
_x1 = _x2 = arg0;
|
|
322
|
+
_y1 = _y2 = arguments[1];
|
|
323
|
+
} else {
|
|
324
|
+
if (arg0 instanceof Bounds) {
|
|
325
|
+
// bounds
|
|
326
|
+
_x1 = arg0.min.x;
|
|
327
|
+
_x2 = arg0.max.x;
|
|
328
|
+
_y1 = arg0.min.y;
|
|
329
|
+
_y2 = arg0.max.y;
|
|
330
|
+
} else {
|
|
331
|
+
// vector
|
|
332
|
+
_x1 = _x2 = arg0.x;
|
|
333
|
+
_y1 = _y2 = arg0.y;
|
|
334
|
+
}
|
|
335
|
+
}
|
|
336
|
+
|
|
337
|
+
return _x1 >= this.min.x && _x2 <= this.max.x
|
|
338
|
+
&& _y1 >= this.min.y && _y2 <= this.max.y;
|
|
339
|
+
}
|
|
340
|
+
|
|
341
|
+
/**
|
|
342
|
+
* Returns true if the two bounds intersect.
|
|
343
|
+
* @name overlaps
|
|
344
|
+
* @memberof Bounds
|
|
345
|
+
* @param {Bounds|Rect} bounds
|
|
346
|
+
* @returns {boolean} True if the bounds overlap, otherwise false
|
|
347
|
+
*/
|
|
348
|
+
overlaps(bounds) {
|
|
349
|
+
return !(this.right < bounds.left || this.left > bounds.right ||
|
|
350
|
+
this.bottom < bounds.top || this.top > bounds.bottom);
|
|
351
|
+
}
|
|
352
|
+
|
|
353
|
+
/**
|
|
354
|
+
* determines whether all coordinates of this bounds are finite numbers.
|
|
355
|
+
* @name isFinite
|
|
356
|
+
* @memberof Bounds
|
|
357
|
+
* @returns {boolean} false if all coordinates are positive or negative Infinity or NaN; otherwise, true.
|
|
358
|
+
*/
|
|
359
|
+
isFinite() {
|
|
360
|
+
return (isFinite(this.min.x) && isFinite(this.max.x) && isFinite(this.min.y) && isFinite(this.max.y));
|
|
361
|
+
}
|
|
362
|
+
|
|
363
|
+
/**
|
|
364
|
+
* Translates the bounds by the given vector.
|
|
365
|
+
* @name translate
|
|
366
|
+
* @memberof Bounds
|
|
367
|
+
* @method
|
|
368
|
+
* @param {Vector2d} vector
|
|
369
|
+
*/
|
|
370
|
+
/**
|
|
371
|
+
* Translates the bounds by x on the x axis, and y on the y axis
|
|
372
|
+
* @name translate
|
|
373
|
+
* @memberof Bounds
|
|
374
|
+
* @param {number} x
|
|
375
|
+
* @param {number} y
|
|
376
|
+
*/
|
|
377
|
+
translate() {
|
|
378
|
+
var _x, _y;
|
|
379
|
+
if (arguments.length === 2) {
|
|
380
|
+
// x, y
|
|
381
|
+
_x = arguments[0];
|
|
382
|
+
_y = arguments[1];
|
|
383
|
+
} else {
|
|
384
|
+
// vector
|
|
385
|
+
_x = arguments[0].x;
|
|
386
|
+
_y = arguments[0].y;
|
|
387
|
+
}
|
|
388
|
+
this.min.x += _x;
|
|
389
|
+
this.max.x += _x;
|
|
390
|
+
this.min.y += _y;
|
|
391
|
+
this.max.y += _y;
|
|
392
|
+
}
|
|
393
|
+
|
|
394
|
+
/**
|
|
395
|
+
* Shifts the bounds to the given position vector.
|
|
396
|
+
* @name shift
|
|
397
|
+
* @memberof Bounds
|
|
398
|
+
* @method
|
|
399
|
+
* @param {Vector2d} position
|
|
400
|
+
*/
|
|
401
|
+
/**
|
|
402
|
+
* Shifts the bounds to the given x, y position.
|
|
403
|
+
* @name shift
|
|
404
|
+
* @memberof Bounds
|
|
405
|
+
* @param {number} x
|
|
406
|
+
* @param {number} y
|
|
407
|
+
*/
|
|
408
|
+
shift() {
|
|
409
|
+
var _x, _y;
|
|
410
|
+
|
|
411
|
+
if (arguments.length === 2) {
|
|
412
|
+
// x, y
|
|
413
|
+
_x = arguments[0];
|
|
414
|
+
_y = arguments[1];
|
|
415
|
+
} else {
|
|
416
|
+
// vector
|
|
417
|
+
_x = arguments[0].x;
|
|
418
|
+
_y = arguments[0].y;
|
|
419
|
+
}
|
|
420
|
+
|
|
421
|
+
var deltaX = this.max.x - this.min.x,
|
|
422
|
+
deltaY = this.max.y - this.min.y;
|
|
423
|
+
|
|
424
|
+
this.min.x = _x;
|
|
425
|
+
this.max.x = _x + deltaX;
|
|
426
|
+
this.min.y = _y;
|
|
427
|
+
this.max.y = _y + deltaY;
|
|
428
|
+
}
|
|
429
|
+
|
|
430
|
+
/**
|
|
431
|
+
* clone this bounds
|
|
432
|
+
* @name clone
|
|
433
|
+
* @memberof Bounds
|
|
434
|
+
* @returns {Bounds}
|
|
435
|
+
*/
|
|
436
|
+
clone() {
|
|
437
|
+
var bounds = new Bounds();
|
|
438
|
+
bounds.addBounds(this);
|
|
439
|
+
return bounds;
|
|
440
|
+
}
|
|
441
|
+
|
|
442
|
+
/**
|
|
443
|
+
* Returns a polygon whose edges are the same as this bounds.
|
|
444
|
+
* @name toPolygon
|
|
445
|
+
* @memberof Bounds
|
|
446
|
+
* @returns {Polygon} a new Polygon that represents this bounds.
|
|
447
|
+
*/
|
|
448
|
+
toPolygon () {
|
|
449
|
+
return pool.pull("Polygon", this.x, this.y, [
|
|
450
|
+
pool.pull("Vector2d", 0, 0),
|
|
451
|
+
pool.pull("Vector2d", this.width, 0),
|
|
452
|
+
pool.pull("Vector2d", this.width, this.height),
|
|
453
|
+
pool.pull("Vector2d", 0, this.height)
|
|
454
|
+
]);
|
|
455
|
+
}
|
|
456
|
+
|
|
457
|
+
}
|
|
458
|
+
var Bounds$1 = Bounds;
|
|
459
|
+
|
|
460
|
+
export { Bounds$1 as default };
|
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
/*!
|
|
2
|
+
* melonJS Game Engine - v14.1.0
|
|
3
|
+
* http://www.melonjs.org
|
|
4
|
+
* melonjs is licensed under the MIT License.
|
|
5
|
+
* http://www.opensource.org/licenses/mit-license
|
|
6
|
+
* @copyright (C) 2011 - 2022 Olivier Biot (AltByte Pte Ltd)
|
|
7
|
+
*/
|
|
8
|
+
import { rayCast } from './detector.js';
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Collision detection (and projection-based collision response) of 2D shapes.<br>
|
|
12
|
+
* Based on the Separating Axis Theorem and supports detecting collisions between simple Axis-Aligned Boxes, convex polygons and circles based shapes.
|
|
13
|
+
* @namespace collision
|
|
14
|
+
*/
|
|
15
|
+
|
|
16
|
+
var collision = {
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* The maximum number of children that a quadtree node can contain before it is split into sub-nodes.
|
|
20
|
+
* @name maxChildren
|
|
21
|
+
* @memberof collision
|
|
22
|
+
* @public
|
|
23
|
+
* @type {number}
|
|
24
|
+
* @default 8
|
|
25
|
+
* @see game.world.broadphase
|
|
26
|
+
*/
|
|
27
|
+
maxChildren : 8,
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* The maximum number of levels that the quadtree will create.
|
|
31
|
+
* @name maxDepth
|
|
32
|
+
* @memberof collision
|
|
33
|
+
* @public
|
|
34
|
+
* @type {number}
|
|
35
|
+
* @default 4
|
|
36
|
+
* @see game.world.broadphase
|
|
37
|
+
*/
|
|
38
|
+
maxDepth : 4,
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* Enum for collision type values.
|
|
42
|
+
* @property {number} NO_OBJECT to disable collision check
|
|
43
|
+
* @property {number} PLAYER_OBJECT playbable characters
|
|
44
|
+
* @property {number} NPC_OBJECT non playable characters
|
|
45
|
+
* @property {number} ENEMY_OBJECT enemies objects
|
|
46
|
+
* @property {number} COLLECTABLE_OBJECT collectable objects
|
|
47
|
+
* @property {number} ACTION_OBJECT e.g. doors
|
|
48
|
+
* @property {number} PROJECTILE_OBJECT e.g. missiles
|
|
49
|
+
* @property {number} WORLD_SHAPE e.g. walls; for map collision shapes
|
|
50
|
+
* @property {number} USER user-defined collision types (see example)
|
|
51
|
+
* @property {number} ALL_OBJECT all of the above (including user-defined types)
|
|
52
|
+
* @readonly
|
|
53
|
+
* @enum {number}
|
|
54
|
+
* @name types
|
|
55
|
+
* @memberof collision
|
|
56
|
+
* @see Body.setCollisionMask
|
|
57
|
+
* @see Body.collisionType
|
|
58
|
+
* @example
|
|
59
|
+
* // set the body collision type
|
|
60
|
+
* myEntity.body.collisionType = me.collision.types.PLAYER_OBJECT;
|
|
61
|
+
*
|
|
62
|
+
* // filter collision detection with collision shapes, enemies and collectables
|
|
63
|
+
* myEntity.body.setCollisionMask(
|
|
64
|
+
* me.collision.types.WORLD_SHAPE |
|
|
65
|
+
* me.collision.types.ENEMY_OBJECT |
|
|
66
|
+
* me.collision.types.COLLECTABLE_OBJECT
|
|
67
|
+
* );
|
|
68
|
+
*
|
|
69
|
+
* // User-defined collision types are defined using BITWISE LEFT-SHIFT:
|
|
70
|
+
* game.collisionTypes = {
|
|
71
|
+
* LOCKED_DOOR : me.collision.types.USER << 0,
|
|
72
|
+
* OPEN_DOOR : me.collision.types.USER << 1,
|
|
73
|
+
* LOOT : me.collision.types.USER << 2,
|
|
74
|
+
* };
|
|
75
|
+
*
|
|
76
|
+
* // Set collision type for a door entity
|
|
77
|
+
* myDoorEntity.body.collisionType = game.collisionTypes.LOCKED_DOOR;
|
|
78
|
+
*
|
|
79
|
+
* // Set collision mask for the player entity, so it collides with locked doors and loot
|
|
80
|
+
* myPlayerEntity.body.setCollisionMask(
|
|
81
|
+
* me.collision.types.ENEMY_OBJECT |
|
|
82
|
+
* me.collision.types.WORLD_SHAPE |
|
|
83
|
+
* game.collisionTypes.LOCKED_DOOR |
|
|
84
|
+
* game.collisionTypes.LOOT
|
|
85
|
+
* );
|
|
86
|
+
*/
|
|
87
|
+
types : {
|
|
88
|
+
/** to disable collision check */
|
|
89
|
+
NO_OBJECT : 0,
|
|
90
|
+
PLAYER_OBJECT : 1 << 0,
|
|
91
|
+
NPC_OBJECT : 1 << 1,
|
|
92
|
+
ENEMY_OBJECT : 1 << 2,
|
|
93
|
+
COLLECTABLE_OBJECT : 1 << 3,
|
|
94
|
+
ACTION_OBJECT : 1 << 4, // door, etc...
|
|
95
|
+
PROJECTILE_OBJECT : 1 << 5, // missiles, etc...
|
|
96
|
+
WORLD_SHAPE : 1 << 6, // walls, etc...
|
|
97
|
+
USER : 1 << 7, // user-defined types start here...
|
|
98
|
+
ALL_OBJECT : 0xFFFFFFFF // all objects
|
|
99
|
+
},
|
|
100
|
+
|
|
101
|
+
/**
|
|
102
|
+
* Checks for object colliding with the given line
|
|
103
|
+
* @name rayCast
|
|
104
|
+
* @memberof collision
|
|
105
|
+
* @public
|
|
106
|
+
* @param {Line} line - line to be tested for collision
|
|
107
|
+
* @param {Array.<Renderable>} [result] - a user defined array that will be populated with intersecting physic objects.
|
|
108
|
+
* @returns {Array.<Renderable>} an array of intersecting physic objects
|
|
109
|
+
* @example
|
|
110
|
+
* // define a line accross the viewport
|
|
111
|
+
* var ray = new me.Line(
|
|
112
|
+
* // absolute position of the line
|
|
113
|
+
* 0, 0, [
|
|
114
|
+
* // starting point relative to the initial position
|
|
115
|
+
* new me.Vector2d(0, 0),
|
|
116
|
+
* // ending point
|
|
117
|
+
* new me.Vector2d(me.game.viewport.width, me.game.viewport.height)
|
|
118
|
+
* ]);
|
|
119
|
+
*
|
|
120
|
+
* // check for collition
|
|
121
|
+
* result = me.collision.rayCast(ray);
|
|
122
|
+
*
|
|
123
|
+
* if (result.length > 0) {
|
|
124
|
+
* // ...
|
|
125
|
+
* }
|
|
126
|
+
*/
|
|
127
|
+
rayCast(line, result) { return rayCast(line, result); }
|
|
128
|
+
};
|
|
129
|
+
|
|
130
|
+
var collision$1 = collision;
|
|
131
|
+
|
|
132
|
+
export { collision$1 as default };
|