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.
Files changed (78) hide show
  1. package/{LICENSE → LICENSE.md} +0 -0
  2. package/README.md +93 -57
  3. package/dist/melonjs.js +10334 -11179
  4. package/dist/melonjs.min.js +4 -10
  5. package/dist/melonjs.module.d.ts +13206 -0
  6. package/dist/melonjs.module.js +9913 -10872
  7. package/package.json +19 -14
  8. package/src/audio/audio.js +477 -553
  9. package/src/camera/camera2d.js +67 -65
  10. package/src/entity/draggable.js +26 -35
  11. package/src/entity/droptarget.js +17 -14
  12. package/src/entity/entity.js +59 -79
  13. package/src/game.js +194 -204
  14. package/src/index.js +12 -30
  15. package/src/input/gamepad.js +8 -19
  16. package/src/input/keyboard.js +4 -4
  17. package/src/input/pointer.js +14 -12
  18. package/src/input/pointerevent.js +15 -13
  19. package/src/lang/deprecated.js +2 -887
  20. package/src/level/level.js +3 -3
  21. package/src/level/tiled/TMXGroup.js +7 -11
  22. package/src/level/tiled/TMXLayer.js +33 -32
  23. package/src/level/tiled/TMXTileMap.js +15 -19
  24. package/src/level/tiled/TMXTileset.js +5 -5
  25. package/src/level/tiled/TMXUtils.js +3 -3
  26. package/src/level/tiled/renderer/TMXRenderer.js +4 -0
  27. package/src/loader/loader.js +8 -23
  28. package/src/loader/loadingscreen.js +51 -60
  29. package/src/math/matrix3.js +1 -1
  30. package/src/particles/emitter.js +36 -39
  31. package/src/particles/particle.js +27 -12
  32. package/src/particles/particlecontainer.js +17 -16
  33. package/src/physics/body.js +80 -118
  34. package/src/physics/collision.js +5 -235
  35. package/src/physics/detector.js +235 -0
  36. package/src/physics/quadtree.js +14 -14
  37. package/src/physics/world.js +84 -18
  38. package/src/plugin/plugin.js +26 -24
  39. package/src/polyfill/console.js +9 -14
  40. package/src/renderable/GUI.js +48 -62
  41. package/src/renderable/collectable.js +11 -4
  42. package/src/renderable/colorlayer.js +28 -26
  43. package/src/renderable/container.js +120 -96
  44. package/src/renderable/imagelayer.js +94 -93
  45. package/src/renderable/renderable.js +164 -138
  46. package/src/renderable/sprite.js +42 -44
  47. package/src/renderable/trigger.js +24 -17
  48. package/src/shapes/ellipse.js +27 -27
  49. package/src/shapes/line.js +12 -8
  50. package/src/shapes/poly.js +77 -49
  51. package/src/shapes/rectangle.js +193 -268
  52. package/src/state/stage.js +23 -25
  53. package/src/state/state.js +35 -86
  54. package/src/system/device.js +233 -285
  55. package/src/system/event.js +485 -432
  56. package/src/system/pooling.js +61 -54
  57. package/src/system/save.js +17 -16
  58. package/src/system/timer.js +34 -38
  59. package/src/text/bitmaptext.js +44 -46
  60. package/src/text/text.js +39 -34
  61. package/src/tweens/easing.js +0 -2
  62. package/src/tweens/interpolation.js +3 -8
  63. package/src/tweens/tween.js +332 -351
  64. package/src/utils/function.js +6 -8
  65. package/src/utils/utils.js +34 -30
  66. package/src/video/canvas/canvas_renderer.js +13 -8
  67. package/src/video/renderer.js +8 -7
  68. package/src/video/texture.js +8 -8
  69. package/src/video/texture_cache.js +5 -5
  70. package/src/video/video.js +373 -403
  71. package/src/video/webgl/glshader.js +2 -2
  72. package/src/video/webgl/webgl_compositor.js +14 -8
  73. package/src/video/webgl/webgl_renderer.js +21 -19
  74. package/plugins/debug/debugPanel.js +0 -770
  75. package/plugins/debug/font/PressStart2P.fnt +0 -100
  76. package/plugins/debug/font/PressStart2P.ltr +0 -1
  77. package/plugins/debug/font/PressStart2P.png +0 -0
  78. package/plugins/debug/particleDebugPanel.js +0 -303
@@ -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
- var Polygon = window.Jay.extend({
22
- /**
23
- * @ignore
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 = null;
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 : function (x, y, points) {
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 : function (x, y, points) {
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 : function (vertices) {
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
- var _points = this.points = [];
114
+ this.points.length = 0;
117
115
 
118
116
  if (typeof vertices[0] === "object") {
119
117
  // array of {x,y} object
120
- vertices.forEach(function (vertice) {
121
- _points.push(new Vector2d(vertice.x, vertice.y));
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
- _points.push(new Vector2d(vertices[p], vertices[p + 1]));
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 : function (m) {
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 : function () {
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 : function () {
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 : function (angle, v) {
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 : function (x, y) {
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 : function (v) {
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 : function () {
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
- // toIndices if array is empty upon function call
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
- * @param {Vector2d[]} a list of vector
287
- * @return {me.Polygon} this Polygon
284
+ * @return {Array} an array of vertex indices for all triangles forming this polygon.
288
285
  */
289
- getIndices : function (x, y) {
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 : function () {
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: function () {
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 : function () {
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 : function () {
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 : function () {
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;