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
@@ -2,6 +2,7 @@ import Vector2d from "./../math/vector2.js";
2
2
  import Polygon from "./poly.js";
3
3
 
4
4
  /**
5
+ * @classdesc
5
6
  * a rectangle Object
6
7
  * @class
7
8
  * @extends me.Polygon
@@ -12,25 +13,24 @@ import Polygon from "./poly.js";
12
13
  * @param {Number} w width of the rectangle
13
14
  * @param {Number} h height of the rectangle
14
15
  */
15
- var Rect = Polygon.extend({
16
- /**
17
- * @ignore
18
- */
19
- init : function (x, y, w, h) {
16
+
17
+ class Rect extends Polygon {
18
+
19
+ constructor(x, y, w, h) {
20
20
  // parent constructor
21
- this._super(Polygon, "init", [x, y, [
21
+ super(x, y, [
22
22
  new Vector2d(0, 0), // 0, 0
23
23
  new Vector2d(w, 0), // 1, 0
24
24
  new Vector2d(w, h), // 1, 1
25
25
  new Vector2d(0, h) // 0, 1
26
- ]]);
26
+ ]);
27
27
  this.shapeType = "Rectangle";
28
- },
28
+ }
29
29
 
30
30
  /** @ignore */
31
- onResetEvent : function (x, y, w, h) {
31
+ onResetEvent(x, y, w, h) {
32
32
  this.setShape(x, y, w, h);
33
- },
33
+ }
34
34
 
35
35
  /**
36
36
  * set new value to the rectangle shape
@@ -43,7 +43,7 @@ var Rect = Polygon.extend({
43
43
  * @param {Number} [h] height of the rectangle, if a numeral width parameter is specified
44
44
  * @return {me.Rect} this rectangle
45
45
  */
46
- setShape : function (x, y, w, h) {
46
+ setShape(x, y, w, h) {
47
47
  var points = w; // assume w is an array by default
48
48
 
49
49
  this.pos.set(x, y);
@@ -58,7 +58,168 @@ var Rect = Polygon.extend({
58
58
 
59
59
  this.setVertices(points);
60
60
  return this;
61
- },
61
+ }
62
+
63
+
64
+ /**
65
+ * left coordinate of the Rectangle
66
+ * @public
67
+ * @type {Number}
68
+ * @name left
69
+ * @memberOf me.Rect
70
+ */
71
+
72
+ /**
73
+ * @ignore
74
+ */
75
+ get left() {
76
+ return this.pos.x;
77
+ }
78
+
79
+ /**
80
+ * right coordinate of the Rectangle
81
+ * @public
82
+ * @type {Number}
83
+ * @name right
84
+ * @memberOf me.Rect
85
+ */
86
+
87
+ /**
88
+ * @ignore
89
+ */
90
+ get right() {
91
+ var w = this.width;
92
+ return (this.pos.x + w) || w;
93
+ }
94
+
95
+ /**
96
+ * top coordinate of the Rectangle
97
+ * @public
98
+ * @type {Number}
99
+ * @name top
100
+ * @memberOf me.Rect
101
+ */
102
+
103
+ /**
104
+ * @ignore
105
+ */
106
+ get top() {
107
+ return this.pos.y;
108
+ }
109
+
110
+ /**
111
+ * bottom coordinate of the Rectangle
112
+ * @public
113
+ * @type {Number}
114
+ * @name bottom
115
+ * @memberOf me.Rect
116
+ */
117
+
118
+ /**
119
+ * @ignore
120
+ */
121
+ get bottom() {
122
+ var h = this.height;
123
+ return (this.pos.y + h) || h;
124
+ }
125
+
126
+ /**
127
+ * width of the Rectangle
128
+ * @public
129
+ * @type {Number}
130
+ * @name width
131
+ * @memberOf me.Rect
132
+ */
133
+
134
+ /**
135
+ * @ignore
136
+ */
137
+ get width() {
138
+ return this.points[2].x;
139
+ }
140
+ /**
141
+ * @ignore
142
+ */
143
+ set width(value) {
144
+ this.points[1].x = this.points[2].x = value;
145
+ this.recalc();
146
+ this.updateBounds();
147
+ }
148
+
149
+ /**
150
+ * height of the Rectangle
151
+ * @public
152
+ * @type {Number}
153
+ * @name height
154
+ * @memberOf me.Rect
155
+ */
156
+
157
+ /**
158
+ * @ignore
159
+ */
160
+ get height() {
161
+ return this.points[2].y;
162
+ }
163
+ /**
164
+ * @ignore
165
+ */
166
+ set height(value) {
167
+ this.points[2].y = this.points[3].y = value;
168
+ this.recalc();
169
+ this.updateBounds();
170
+ }
171
+
172
+ /**
173
+ * absolute center of this rectangle on the horizontal axis
174
+ * @public
175
+ * @type {Number}
176
+ * @name centerX
177
+ * @memberOf me.Rect
178
+ */
179
+
180
+ /**
181
+ * @ignore
182
+ */
183
+ get centerX() {
184
+ if (isFinite(this.width)) {
185
+ return this.pos.x + (this.width / 2);
186
+ } else {
187
+ return this.width;
188
+ }
189
+ }
190
+
191
+ /**
192
+ * @ignore
193
+ */
194
+ set centerX (value) {
195
+ this.pos.x = value - (this.width / 2);
196
+ }
197
+
198
+ /**
199
+ * absolute center of this rectangle on the vertical axis
200
+ * @public
201
+ * @type {Number}
202
+ * @name centerY
203
+ * @memberOf me.Rect
204
+ */
205
+
206
+ /**
207
+ * @ignore
208
+ */
209
+ get centerY() {
210
+ if (isFinite(this.height)) {
211
+ return this.pos.y + (this.height / 2);
212
+ } else {
213
+ return this.height;
214
+ }
215
+ }
216
+
217
+ /**
218
+ * @ignore
219
+ */
220
+ set centerY(value) {
221
+ this.pos.y = value - (this.height / 2);
222
+ }
62
223
 
63
224
  /**
64
225
  * resize the rectangle
@@ -69,11 +230,11 @@ var Rect = Polygon.extend({
69
230
  * @param {Number} h new height of the rectangle
70
231
  * @return {me.Rect} this rectangle
71
232
  */
72
- resize : function (w, h) {
233
+ resize(w, h) {
73
234
  this.width = w;
74
235
  this.height = h;
75
236
  return this;
76
- },
237
+ }
77
238
 
78
239
  /**
79
240
  * scale the rectangle
@@ -84,11 +245,11 @@ var Rect = Polygon.extend({
84
245
  * @param {Number} [y=x] a number representing the ordinate of the scaling vector.
85
246
  * @return {me.Rect} this rectangle
86
247
  */
87
- scale : function (x, y = x) {
248
+ scale(x, y = x) {
88
249
  this.width *= x;
89
250
  this.height *= y;
90
251
  return this;
91
- },
252
+ }
92
253
 
93
254
  /**
94
255
  * clone this rectangle
@@ -97,9 +258,9 @@ var Rect = Polygon.extend({
97
258
  * @function
98
259
  * @return {me.Rect} new rectangle
99
260
  */
100
- clone : function () {
261
+ clone() {
101
262
  return new Rect(this.pos.x, this.pos.y, this.width, this.height);
102
- },
263
+ }
103
264
 
104
265
  /**
105
266
  * copy the position and size of the given rectangle into this one
@@ -109,70 +270,9 @@ var Rect = Polygon.extend({
109
270
  * @param {me.Rect} rect Source rectangle
110
271
  * @return {me.Rect} new rectangle
111
272
  */
112
- copy : function (rect) {
273
+ copy(rect) {
113
274
  return this.setShape(rect.pos.x, rect.pos.y, rect.width, rect.height);
114
- },
115
-
116
- /**
117
- * translate the rect by the specified offset
118
- * @name translate
119
- * @memberOf me.Rect.prototype
120
- * @function
121
- * @param {Number} x x offset
122
- * @param {Number} y y offset
123
- * @return {me.Rect} this rectangle
124
- */
125
- /**
126
- * translate the rect by the specified vector
127
- * @name translate
128
- * @memberOf me.Rect.prototype
129
- * @function
130
- * @param {me.Vector2d} v vector offset
131
- * @return {me.Rect} this rectangle
132
- */
133
- translate : function () {
134
- var _x, _y;
135
-
136
- if (arguments.length === 2) {
137
- // x, y
138
- _x = arguments[0];
139
- _y = arguments[1];
140
- } else {
141
- // vector
142
- _x = arguments[0].x;
143
- _y = arguments[0].y;
144
- }
145
-
146
- this.pos.x += _x;
147
- this.pos.y += _y;
148
-
149
- return this;
150
- },
151
-
152
- /**
153
- * Shifts the rect to the given position vector.
154
- * @name shift
155
- * @memberOf me.Rect
156
- * @function
157
- * @param {me.Vector2d} position
158
- */
159
- /**
160
- * Shifts the rect to the given x, y position.
161
- * @name shift
162
- * @memberOf me.Rect
163
- * @function
164
- * @param {Number} x
165
- * @param {Number} y
166
- */
167
- shift : function () {
168
- if (arguments.length === 2) {
169
- // x, y
170
- this.pos.set(arguments[0], arguments[1]);
171
- } else {
172
- // vector
173
- this.pos.setV(arguments[0]);
174
- }
175
- },
275
+ }
176
276
 
177
277
  /**
178
278
  * merge this rectangle with another one
@@ -182,7 +282,7 @@ var Rect = Polygon.extend({
182
282
  * @param {me.Rect} rect other rectangle to union with
183
283
  * @return {me.Rect} the union(ed) rectangle
184
284
  */
185
- union : function (/** {me.Rect} */ r) {
285
+ union(/** {me.Rect} */ r) {
186
286
  var x1 = Math.min(this.left, r.left);
187
287
  var y1 = Math.min(this.top, r.top);
188
288
 
@@ -194,7 +294,7 @@ var Rect = Polygon.extend({
194
294
  this.pos.set(x1, y1);
195
295
 
196
296
  return this;
197
- },
297
+ }
198
298
 
199
299
  /**
200
300
  * check if this rectangle is intersecting with the specified one
@@ -204,14 +304,14 @@ var Rect = Polygon.extend({
204
304
  * @param {me.Rect} rect
205
305
  * @return {boolean} true if overlaps
206
306
  */
207
- overlaps : function (r) {
307
+ overlaps(r) {
208
308
  return (
209
309
  this.left < r.right &&
210
310
  r.left < this.right &&
211
311
  this.top < r.bottom &&
212
312
  r.top < this.bottom
213
313
  );
214
- },
314
+ }
215
315
 
216
316
  /**
217
317
  * Returns true if the rectangle contains the given rectangle
@@ -240,7 +340,7 @@ var Rect = Polygon.extend({
240
340
  * @param {me.Vector2d} point
241
341
  * @return {boolean} true if contains
242
342
  */
243
- contains: function () {
343
+ contains() {
244
344
  var arg0 = arguments[0];
245
345
  var _x1, _x2, _y1, _y2;
246
346
  if (arguments.length === 2) {
@@ -266,7 +366,7 @@ var Rect = Polygon.extend({
266
366
  _y1 >= this.top &&
267
367
  _y2 <= this.bottom
268
368
  );
269
- },
369
+ }
270
370
 
271
371
  /**
272
372
  * check if this rectangle is identical to the specified one
@@ -276,14 +376,14 @@ var Rect = Polygon.extend({
276
376
  * @param {me.Rect} rect
277
377
  * @return {boolean} true if equals
278
378
  */
279
- equals: function (r) {
379
+ equals(r) {
280
380
  return (
281
381
  r.left === this.left &&
282
382
  r.right === this.right &&
283
383
  r.top === this.top &&
284
384
  r.bottom === this.bottom
285
385
  );
286
- },
386
+ }
287
387
 
288
388
  /**
289
389
  * determines whether all coordinates of this rectangle are finite numbers.
@@ -292,9 +392,9 @@ var Rect = Polygon.extend({
292
392
  * @function
293
393
  * @return {boolean} false if all coordinates are positive or negative Infinity or NaN; otherwise, true.
294
394
  */
295
- isFinite: function () {
395
+ isFinite() {
296
396
  return (isFinite(this.pos.x) && isFinite(this.pos.y) && isFinite(this.width) && isFinite(this.height));
297
- },
397
+ }
298
398
 
299
399
  /**
300
400
  * Returns a polygon whose edges are the same as this box.
@@ -303,187 +403,12 @@ var Rect = Polygon.extend({
303
403
  * @function
304
404
  * @return {me.Polygon} a new Polygon that represents this rectangle.
305
405
  */
306
- toPolygon: function () {
406
+ toPolygon() {
307
407
  return new Polygon(
308
408
  this.pos.x, this.pos.y, this.points
309
409
  );
310
410
  }
311
- });
312
-
313
- // redefine some properties to ease our life when getting the rectangle coordinates
411
+ };
314
412
 
315
- /**
316
- * left coordinate of the Rectangle
317
- * @public
318
- * @type {Number}
319
- * @name left
320
- * @memberOf me.Rect
321
- */
322
- Object.defineProperty(Rect.prototype, "left", {
323
- /**
324
- * @ignore
325
- */
326
- get : function () {
327
- return this.pos.x;
328
- },
329
- configurable : true
330
- });
331
-
332
- /**
333
- * right coordinate of the Rectangle
334
- * @public
335
- * @type {Number}
336
- * @name right
337
- * @memberOf me.Rect
338
- */
339
- Object.defineProperty(Rect.prototype, "right", {
340
- /**
341
- * @ignore
342
- */
343
- get : function () {
344
- var w = this.width;
345
- return (this.pos.x + w) || w;
346
- },
347
- configurable : true
348
- });
349
-
350
- /**
351
- * top coordinate of the Rectangle
352
- * @public
353
- * @type {Number}
354
- * @name top
355
- * @memberOf me.Rect
356
- */
357
- Object.defineProperty(Rect.prototype, "top", {
358
- /**
359
- * @ignore
360
- */
361
- get : function () {
362
- return this.pos.y;
363
- },
364
- configurable : true
365
- });
366
-
367
- /**
368
- * bottom coordinate of the Rectangle
369
- * @public
370
- * @type {Number}
371
- * @name bottom
372
- * @memberOf me.Rect
373
- */
374
- Object.defineProperty(Rect.prototype, "bottom", {
375
- /**
376
- * @ignore
377
- */
378
- get : function () {
379
- var h = this.height;
380
- return (this.pos.y + h) || h;
381
- },
382
- configurable : true
383
- });
384
-
385
- /**
386
- * width of the Rectangle
387
- * @public
388
- * @type {Number}
389
- * @name width
390
- * @memberOf me.Rect
391
- */
392
- Object.defineProperty(Rect.prototype, "width", {
393
- /**
394
- * @ignore
395
- */
396
- get : function () {
397
- return this.points[2].x;
398
- },
399
- /**
400
- * @ignore
401
- */
402
- set : function (value) {
403
- this.points[1].x = this.points[2].x = value;
404
- this.recalc();
405
- this.updateBounds();
406
- },
407
- configurable : true
408
- });
409
-
410
- /**
411
- * height of the Rectangle
412
- * @public
413
- * @type {Number}
414
- * @name height
415
- * @memberOf me.Rect
416
- */
417
- Object.defineProperty(Rect.prototype, "height", {
418
- /**
419
- * @ignore
420
- */
421
- get : function () {
422
- return this.points[2].y;
423
- },
424
- /**
425
- * @ignore
426
- */
427
- set : function (value) {
428
- this.points[2].y = this.points[3].y = value;
429
- this.recalc();
430
- this.updateBounds();
431
- },
432
- configurable : true
433
- });
434
-
435
- /**
436
- * absolute center of this rectangle on the horizontal axis
437
- * @public
438
- * @type {Number}
439
- * @name centerX
440
- * @memberOf me.Rect
441
- */
442
- Object.defineProperty(Rect.prototype, "centerX", {
443
- /**
444
- * @ignore
445
- */
446
- get : function () {
447
- if (isFinite(this.width)) {
448
- return this.pos.x + (this.width / 2);
449
- } else {
450
- return this.width;
451
- }
452
- },
453
- /**
454
- * @ignore
455
- */
456
- set : function (value) {
457
- this.pos.x = value - (this.width / 2);
458
- },
459
- configurable : true
460
- });
461
-
462
- /**
463
- * absolute center of this rectangle on the vertical axis
464
- * @public
465
- * @type {Number}
466
- * @name centerY
467
- * @memberOf me.Rect
468
- */
469
- Object.defineProperty(Rect.prototype, "centerY", {
470
- /**
471
- * @ignore
472
- */
473
- get : function () {
474
- if (isFinite(this.height)) {
475
- return this.pos.y + (this.height / 2);
476
- } else {
477
- return this.height;
478
- }
479
- },
480
- /**
481
- * @ignore
482
- */
483
- set : function (value) {
484
- this.pos.y = value - (this.height / 2);
485
- },
486
- configurable : true
487
- });
488
413
 
489
414
  export default Rect;