melonjs 9.1.0 → 10.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/{LICENSE → LICENSE.md} +0 -0
- package/README.md +93 -57
- package/dist/melonjs.js +10334 -11179
- package/dist/melonjs.min.js +4 -10
- package/dist/melonjs.module.d.ts +13206 -0
- package/dist/melonjs.module.js +9913 -10872
- package/package.json +19 -14
- package/src/audio/audio.js +477 -553
- package/src/camera/camera2d.js +67 -65
- package/src/entity/draggable.js +26 -35
- package/src/entity/droptarget.js +17 -14
- package/src/entity/entity.js +59 -79
- package/src/game.js +194 -204
- package/src/index.js +12 -30
- package/src/input/gamepad.js +8 -19
- package/src/input/keyboard.js +4 -4
- package/src/input/pointer.js +14 -12
- package/src/input/pointerevent.js +15 -13
- package/src/lang/deprecated.js +2 -887
- package/src/level/level.js +3 -3
- package/src/level/tiled/TMXGroup.js +7 -11
- package/src/level/tiled/TMXLayer.js +33 -32
- package/src/level/tiled/TMXTileMap.js +15 -19
- package/src/level/tiled/TMXTileset.js +5 -5
- package/src/level/tiled/TMXUtils.js +3 -3
- package/src/level/tiled/renderer/TMXRenderer.js +4 -0
- package/src/loader/loader.js +8 -23
- package/src/loader/loadingscreen.js +51 -60
- package/src/math/matrix3.js +1 -1
- package/src/particles/emitter.js +36 -39
- package/src/particles/particle.js +27 -12
- package/src/particles/particlecontainer.js +17 -16
- package/src/physics/body.js +80 -118
- package/src/physics/collision.js +5 -235
- package/src/physics/detector.js +235 -0
- package/src/physics/quadtree.js +14 -14
- package/src/physics/world.js +84 -18
- package/src/plugin/plugin.js +26 -24
- package/src/polyfill/console.js +9 -14
- package/src/renderable/GUI.js +48 -62
- package/src/renderable/collectable.js +11 -4
- package/src/renderable/colorlayer.js +28 -26
- package/src/renderable/container.js +120 -96
- package/src/renderable/imagelayer.js +94 -93
- package/src/renderable/renderable.js +164 -138
- package/src/renderable/sprite.js +42 -44
- package/src/renderable/trigger.js +24 -17
- package/src/shapes/ellipse.js +27 -27
- package/src/shapes/line.js +12 -8
- package/src/shapes/poly.js +77 -49
- package/src/shapes/rectangle.js +193 -268
- package/src/state/stage.js +23 -25
- package/src/state/state.js +35 -86
- package/src/system/device.js +233 -285
- package/src/system/event.js +485 -432
- package/src/system/pooling.js +61 -54
- package/src/system/save.js +17 -16
- package/src/system/timer.js +34 -38
- package/src/text/bitmaptext.js +44 -46
- package/src/text/text.js +39 -34
- package/src/tweens/easing.js +0 -2
- package/src/tweens/interpolation.js +3 -8
- package/src/tweens/tween.js +332 -351
- package/src/utils/function.js +6 -8
- package/src/utils/utils.js +34 -30
- package/src/video/canvas/canvas_renderer.js +13 -8
- package/src/video/renderer.js +8 -7
- package/src/video/texture.js +8 -8
- package/src/video/texture_cache.js +5 -5
- package/src/video/video.js +373 -403
- package/src/video/webgl/glshader.js +2 -2
- package/src/video/webgl/webgl_compositor.js +14 -8
- package/src/video/webgl/webgl_renderer.js +21 -19
- package/plugins/debug/debugPanel.js +0 -770
- package/plugins/debug/font/PressStart2P.fnt +0 -100
- package/plugins/debug/font/PressStart2P.ltr +0 -1
- package/plugins/debug/font/PressStart2P.png +0 -0
- package/plugins/debug/particleDebugPanel.js +0 -303
package/src/shapes/poly.js
CHANGED
|
@@ -1,28 +1,26 @@
|
|
|
1
1
|
import earcut from "earcut";
|
|
2
2
|
import Vector2d from "./../math/vector2.js";
|
|
3
3
|
import pool from "./../system/pooling.js";
|
|
4
|
-
import "jay-extend";
|
|
5
4
|
|
|
6
5
|
/**
|
|
6
|
+
* @classdesc
|
|
7
7
|
* a polygon Object.<br>
|
|
8
8
|
* Please do note that melonJS implements a simple Axis-Aligned Boxes collision algorithm, which requires all polygons used for collision to be convex with all vertices defined with clockwise winding.
|
|
9
9
|
* A polygon is convex when all line segments connecting two points in the interior do not cross any edge of the polygon
|
|
10
10
|
* (which means that all angles are less than 180 degrees), as described here below : <br>
|
|
11
11
|
* <center><img src="images/convex_polygon.png"/></center><br>
|
|
12
12
|
* A polygon's `winding` is clockwise iff its vertices (points) are declared turning to the right. The image above shows COUNTERCLOCKWISE winding.
|
|
13
|
-
* @class
|
|
14
|
-
* @extends me.Object
|
|
13
|
+
* @class Polygon
|
|
15
14
|
* @memberOf me
|
|
16
15
|
* @constructor
|
|
17
16
|
* @param {Number} x origin point of the Polygon
|
|
18
17
|
* @param {Number} y origin point of the Polygon
|
|
19
18
|
* @param {me.Vector2d[]} points array of vector defining the Polygon
|
|
20
19
|
*/
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
init : function (x, y, points) {
|
|
20
|
+
|
|
21
|
+
class Polygon {
|
|
22
|
+
|
|
23
|
+
constructor(x, y, points) {
|
|
26
24
|
/**
|
|
27
25
|
* origin point of the Polygon
|
|
28
26
|
* @public
|
|
@@ -49,7 +47,7 @@ var Polygon = window.Jay.extend({
|
|
|
49
47
|
* @name points
|
|
50
48
|
* @memberOf me.Polygon#
|
|
51
49
|
*/
|
|
52
|
-
this.points =
|
|
50
|
+
this.points = [];
|
|
53
51
|
|
|
54
52
|
/**
|
|
55
53
|
* The edges here are the direction of the `n`th edge of the polygon, relative to
|
|
@@ -76,12 +74,12 @@ var Polygon = window.Jay.extend({
|
|
|
76
74
|
// the shape type
|
|
77
75
|
this.shapeType = "Polygon";
|
|
78
76
|
this.setShape(x, y, points);
|
|
79
|
-
}
|
|
77
|
+
}
|
|
80
78
|
|
|
81
79
|
/** @ignore */
|
|
82
|
-
onResetEvent
|
|
80
|
+
onResetEvent(x, y, points) {
|
|
83
81
|
this.setShape(x, y, points);
|
|
84
|
-
}
|
|
82
|
+
}
|
|
85
83
|
|
|
86
84
|
/**
|
|
87
85
|
* set new value to the Polygon
|
|
@@ -92,11 +90,11 @@ var Polygon = window.Jay.extend({
|
|
|
92
90
|
* @param {Number} y position of the Polygon
|
|
93
91
|
* @param {me.Vector2d[]|Number[]} points array of vector or vertice defining the Polygon
|
|
94
92
|
*/
|
|
95
|
-
setShape
|
|
93
|
+
setShape(x, y, points) {
|
|
96
94
|
this.pos.set(x, y);
|
|
97
95
|
this.setVertices(points);
|
|
98
96
|
return this;
|
|
99
|
-
}
|
|
97
|
+
}
|
|
100
98
|
|
|
101
99
|
/**
|
|
102
100
|
* set the vertices defining this Polygon
|
|
@@ -105,7 +103,7 @@ var Polygon = window.Jay.extend({
|
|
|
105
103
|
* @function
|
|
106
104
|
* @param {me.Vector2d[]} points array of vector or vertice defining the Polygon
|
|
107
105
|
*/
|
|
108
|
-
setVertices
|
|
106
|
+
setVertices(vertices) {
|
|
109
107
|
|
|
110
108
|
if (!Array.isArray(vertices)) {
|
|
111
109
|
return this;
|
|
@@ -113,18 +111,18 @@ var Polygon = window.Jay.extend({
|
|
|
113
111
|
|
|
114
112
|
// convert given points to me.Vector2d if required
|
|
115
113
|
if (!(vertices[0] instanceof Vector2d)) {
|
|
116
|
-
|
|
114
|
+
this.points.length = 0;
|
|
117
115
|
|
|
118
116
|
if (typeof vertices[0] === "object") {
|
|
119
117
|
// array of {x,y} object
|
|
120
|
-
vertices.forEach(
|
|
121
|
-
|
|
118
|
+
vertices.forEach((vertice) => {
|
|
119
|
+
this.points.push(new Vector2d(vertice.x, vertice.y));
|
|
122
120
|
});
|
|
123
121
|
|
|
124
122
|
} else {
|
|
125
123
|
// it's a flat array
|
|
126
124
|
for (var p = 0; p < vertices.length; p += 2) {
|
|
127
|
-
|
|
125
|
+
this.points.push(new Vector2d(vertices[p], vertices[p + 1]));
|
|
128
126
|
}
|
|
129
127
|
}
|
|
130
128
|
} else {
|
|
@@ -135,7 +133,7 @@ var Polygon = window.Jay.extend({
|
|
|
135
133
|
this.recalc();
|
|
136
134
|
this.updateBounds();
|
|
137
135
|
return this;
|
|
138
|
-
}
|
|
136
|
+
}
|
|
139
137
|
|
|
140
138
|
/**
|
|
141
139
|
* apply the given transformation matrix to this Polygon
|
|
@@ -145,7 +143,7 @@ var Polygon = window.Jay.extend({
|
|
|
145
143
|
* @param {me.Matrix2d} matrix the transformation matrix
|
|
146
144
|
* @return {me.Polygon} Reference to this object for method chaining
|
|
147
145
|
*/
|
|
148
|
-
transform
|
|
146
|
+
transform(m) {
|
|
149
147
|
var points = this.points;
|
|
150
148
|
var len = points.length;
|
|
151
149
|
for (var i = 0; i < len; i++) {
|
|
@@ -154,7 +152,7 @@ var Polygon = window.Jay.extend({
|
|
|
154
152
|
this.recalc();
|
|
155
153
|
this.updateBounds();
|
|
156
154
|
return this;
|
|
157
|
-
}
|
|
155
|
+
}
|
|
158
156
|
|
|
159
157
|
/**
|
|
160
158
|
* apply an isometric projection to this shape
|
|
@@ -163,9 +161,9 @@ var Polygon = window.Jay.extend({
|
|
|
163
161
|
* @function
|
|
164
162
|
* @return {me.Polygon} Reference to this object for method chaining
|
|
165
163
|
*/
|
|
166
|
-
toIso
|
|
164
|
+
toIso() {
|
|
167
165
|
return this.rotate(Math.PI / 4).scale(Math.SQRT2, Math.SQRT1_2);
|
|
168
|
-
}
|
|
166
|
+
}
|
|
169
167
|
|
|
170
168
|
/**
|
|
171
169
|
* apply a 2d projection to this shape
|
|
@@ -174,9 +172,9 @@ var Polygon = window.Jay.extend({
|
|
|
174
172
|
* @function
|
|
175
173
|
* @return {me.Polygon} Reference to this object for method chaining
|
|
176
174
|
*/
|
|
177
|
-
to2d
|
|
175
|
+
to2d() {
|
|
178
176
|
return this.scale(Math.SQRT1_2, Math.SQRT2).rotate(-Math.PI / 4);
|
|
179
|
-
}
|
|
177
|
+
}
|
|
180
178
|
|
|
181
179
|
/**
|
|
182
180
|
* Rotate this Polygon (counter-clockwise) by the specified angle (in radians).
|
|
@@ -187,7 +185,7 @@ var Polygon = window.Jay.extend({
|
|
|
187
185
|
* @param {me.Vector2d|me.ObservableVector2d} [v] an optional point to rotate around
|
|
188
186
|
* @return {me.Polygon} Reference to this object for method chaining
|
|
189
187
|
*/
|
|
190
|
-
rotate
|
|
188
|
+
rotate(angle, v) {
|
|
191
189
|
if (angle !== 0) {
|
|
192
190
|
var points = this.points;
|
|
193
191
|
var len = points.length;
|
|
@@ -198,7 +196,7 @@ var Polygon = window.Jay.extend({
|
|
|
198
196
|
this.updateBounds();
|
|
199
197
|
}
|
|
200
198
|
return this;
|
|
201
|
-
}
|
|
199
|
+
}
|
|
202
200
|
|
|
203
201
|
/**
|
|
204
202
|
* Scale this Polygon by the given scalar.
|
|
@@ -209,7 +207,7 @@ var Polygon = window.Jay.extend({
|
|
|
209
207
|
* @param {Number} [y=x]
|
|
210
208
|
* @return {me.Polygon} Reference to this object for method chaining
|
|
211
209
|
*/
|
|
212
|
-
scale
|
|
210
|
+
scale(x, y) {
|
|
213
211
|
y = typeof (y) !== "undefined" ? y : x;
|
|
214
212
|
|
|
215
213
|
var points = this.points;
|
|
@@ -220,7 +218,7 @@ var Polygon = window.Jay.extend({
|
|
|
220
218
|
this.recalc();
|
|
221
219
|
this.updateBounds();
|
|
222
220
|
return this;
|
|
223
|
-
}
|
|
221
|
+
}
|
|
224
222
|
|
|
225
223
|
/**
|
|
226
224
|
* Scale this Polygon by the given vector
|
|
@@ -230,9 +228,9 @@ var Polygon = window.Jay.extend({
|
|
|
230
228
|
* @param {me.Vector2d} v
|
|
231
229
|
* @return {me.Polygon} Reference to this object for method chaining
|
|
232
230
|
*/
|
|
233
|
-
scaleV
|
|
231
|
+
scaleV(v) {
|
|
234
232
|
return this.scale(v.x, v.y);
|
|
235
|
-
}
|
|
233
|
+
}
|
|
236
234
|
|
|
237
235
|
/**
|
|
238
236
|
* Computes the calculated collision polygon.
|
|
@@ -242,7 +240,7 @@ var Polygon = window.Jay.extend({
|
|
|
242
240
|
* @function
|
|
243
241
|
* @return {me.Polygon} Reference to this object for method chaining
|
|
244
242
|
*/
|
|
245
|
-
recalc
|
|
243
|
+
recalc() {
|
|
246
244
|
var i;
|
|
247
245
|
var edges = this.edges;
|
|
248
246
|
var normals = this.normals;
|
|
@@ -272,26 +270,25 @@ var Polygon = window.Jay.extend({
|
|
|
272
270
|
edges.length = len;
|
|
273
271
|
normals.length = len;
|
|
274
272
|
// do not do anything here, indices will be computed by
|
|
275
|
-
//
|
|
273
|
+
// getIndices if array is empty upon function call
|
|
276
274
|
indices.length = 0;
|
|
277
275
|
|
|
278
276
|
return this;
|
|
279
|
-
}
|
|
277
|
+
}
|
|
280
278
|
|
|
281
279
|
/**
|
|
282
280
|
* returns a list of indices for all triangles defined in this polygon
|
|
283
281
|
* @name getIndices
|
|
284
282
|
* @memberOf me.Polygon.prototype
|
|
285
283
|
* @function
|
|
286
|
-
* @
|
|
287
|
-
* @return {me.Polygon} this Polygon
|
|
284
|
+
* @return {Array} an array of vertex indices for all triangles forming this polygon.
|
|
288
285
|
*/
|
|
289
|
-
getIndices
|
|
286
|
+
getIndices() {
|
|
290
287
|
if (this.indices.length === 0) {
|
|
291
288
|
this.indices = earcut(this.points.flatMap(p => [p.x, p.y]));
|
|
292
289
|
}
|
|
293
290
|
return this.indices;
|
|
294
|
-
}
|
|
291
|
+
}
|
|
295
292
|
|
|
296
293
|
/**
|
|
297
294
|
* translate the Polygon by the specified offset
|
|
@@ -310,7 +307,7 @@ var Polygon = window.Jay.extend({
|
|
|
310
307
|
* @param {me.Vector2d} v vector offset
|
|
311
308
|
* @return {me.Polygon} Reference to this object for method chaining
|
|
312
309
|
*/
|
|
313
|
-
translate
|
|
310
|
+
translate() {
|
|
314
311
|
var _x, _y;
|
|
315
312
|
|
|
316
313
|
if (arguments.length === 2) {
|
|
@@ -328,7 +325,38 @@ var Polygon = window.Jay.extend({
|
|
|
328
325
|
this.getBounds().translate(_x, _y);
|
|
329
326
|
|
|
330
327
|
return this;
|
|
331
|
-
}
|
|
328
|
+
}
|
|
329
|
+
|
|
330
|
+
/**
|
|
331
|
+
* Shifts the Polygon to the given position vector.
|
|
332
|
+
* @name shift
|
|
333
|
+
* @memberOf me.Polygon
|
|
334
|
+
* @function
|
|
335
|
+
* @param {me.Vector2d} position
|
|
336
|
+
*/
|
|
337
|
+
/**
|
|
338
|
+
* Shifts the Polygon to the given x, y position.
|
|
339
|
+
* @name shift
|
|
340
|
+
* @memberOf me.Polygon
|
|
341
|
+
* @function
|
|
342
|
+
* @param {Number} x
|
|
343
|
+
* @param {Number} y
|
|
344
|
+
*/
|
|
345
|
+
shift() {
|
|
346
|
+
var _x, _y;
|
|
347
|
+
if (arguments.length === 2) {
|
|
348
|
+
// x, y
|
|
349
|
+
_x = arguments[0];
|
|
350
|
+
_y = arguments[1];
|
|
351
|
+
} else {
|
|
352
|
+
// vector
|
|
353
|
+
_x = arguments[0].x;
|
|
354
|
+
_y = arguments[0].y;
|
|
355
|
+
}
|
|
356
|
+
this.pos.x = _x;
|
|
357
|
+
this.pos.y = _y;
|
|
358
|
+
this.updateBounds();
|
|
359
|
+
}
|
|
332
360
|
|
|
333
361
|
/**
|
|
334
362
|
* Returns true if the polygon contains the given point.
|
|
@@ -352,7 +380,7 @@ var Polygon = window.Jay.extend({
|
|
|
352
380
|
* @param {Number} y y coordinate
|
|
353
381
|
* @return {boolean} true if contains
|
|
354
382
|
*/
|
|
355
|
-
contains
|
|
383
|
+
contains() {
|
|
356
384
|
var _x, _y;
|
|
357
385
|
|
|
358
386
|
if (arguments.length === 2) {
|
|
@@ -379,7 +407,7 @@ var Polygon = window.Jay.extend({
|
|
|
379
407
|
}
|
|
380
408
|
}
|
|
381
409
|
return intersects;
|
|
382
|
-
}
|
|
410
|
+
}
|
|
383
411
|
|
|
384
412
|
/**
|
|
385
413
|
* returns the bounding box for this shape, the smallest Rectangle object completely containing this shape.
|
|
@@ -388,12 +416,12 @@ var Polygon = window.Jay.extend({
|
|
|
388
416
|
* @function
|
|
389
417
|
* @return {me.Bounds} this shape bounding box Rectangle object
|
|
390
418
|
*/
|
|
391
|
-
getBounds
|
|
419
|
+
getBounds() {
|
|
392
420
|
if (typeof this._bounds === "undefined") {
|
|
393
421
|
this._bounds = pool.pull("Bounds");
|
|
394
422
|
}
|
|
395
423
|
return this._bounds;
|
|
396
|
-
}
|
|
424
|
+
}
|
|
397
425
|
|
|
398
426
|
/**
|
|
399
427
|
* update the bounding box for this shape.
|
|
@@ -403,14 +431,14 @@ var Polygon = window.Jay.extend({
|
|
|
403
431
|
* @function
|
|
404
432
|
* @return {me.Bounds} this shape bounding box Rectangle object
|
|
405
433
|
*/
|
|
406
|
-
updateBounds
|
|
434
|
+
updateBounds() {
|
|
407
435
|
var bounds = this.getBounds();
|
|
408
436
|
|
|
409
437
|
bounds.update(this.points);
|
|
410
438
|
bounds.translate(this.pos);
|
|
411
439
|
|
|
412
440
|
return bounds;
|
|
413
|
-
}
|
|
441
|
+
}
|
|
414
442
|
|
|
415
443
|
/**
|
|
416
444
|
* clone this Polygon
|
|
@@ -419,13 +447,13 @@ var Polygon = window.Jay.extend({
|
|
|
419
447
|
* @function
|
|
420
448
|
* @return {me.Polygon} new Polygon
|
|
421
449
|
*/
|
|
422
|
-
clone
|
|
450
|
+
clone() {
|
|
423
451
|
var copy = [];
|
|
424
452
|
this.points.forEach(function (point) {
|
|
425
453
|
copy.push(point.clone());
|
|
426
454
|
});
|
|
427
455
|
return new Polygon(this.pos.x, this.pos.y, copy);
|
|
428
456
|
}
|
|
429
|
-
}
|
|
457
|
+
};
|
|
430
458
|
|
|
431
459
|
export default Polygon;
|