melonjs 13.1.0 → 13.2.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "melonjs",
3
- "version": "13.1.0",
3
+ "version": "13.2.1",
4
4
  "description": "melonJS Game Engine",
5
5
  "homepage": "http://www.melonjs.org/",
6
6
  "keywords": [
@@ -67,7 +67,7 @@
67
67
  "@types/offscreencanvas": "^2019.7.0",
68
68
  "@webdoc/cli": "^2.0.0",
69
69
  "del-cli": "^5.0.0",
70
- "eslint": "^8.21.0",
70
+ "eslint": "^8.22.0",
71
71
  "jasmine-core": "^4.3.0",
72
72
  "karma": "^6.4.0",
73
73
  "karma-chrome-launcher": "^3.1.1",
@@ -75,7 +75,7 @@
75
75
  "karma-html-detailed-reporter": "^2.1.0",
76
76
  "karma-jasmine": "^5.1.0",
77
77
  "karma-nyan-reporter": "0.2.5",
78
- "rollup": "^2.77.2",
78
+ "rollup": "^2.78.1",
79
79
  "rollup-plugin-bundle-size": "^1.0.3",
80
80
  "rollup-plugin-string": "^3.0.0",
81
81
  "terser": "^5.14.2",
@@ -0,0 +1,80 @@
1
+ /**
2
+ * @classdesc
3
+ * represents a point in a 2d space
4
+ */
5
+ class Point {
6
+ constructor(x = 0, y = 0) {
7
+ /**
8
+ * the position of the point on the horizontal axis
9
+ * @public
10
+ * @type {Number}
11
+ * @default 0
12
+ */
13
+ this.x = x;
14
+
15
+ /**
16
+ * the position of the point on the vertical axis
17
+ * @public
18
+ * @type {Number}
19
+ * @default 0
20
+ */
21
+ this.y = y;
22
+ }
23
+
24
+ /** @ignore */
25
+ onResetEvent(x = 0, y = 0) {
26
+ this.set(x, y);
27
+ }
28
+
29
+ /**
30
+ * set the Point x and y properties to the given values
31
+ * @param {number} x
32
+ * @param {number} y
33
+ * @returns {Point} Reference to this object for method chaining
34
+ */
35
+ set(x = 0, y = 0) {
36
+ this.x = x;
37
+ this.y = y;
38
+ return this;
39
+ }
40
+
41
+ /**
42
+ * return true if the two points are the same
43
+ * @name equals
44
+ * @memberof Point
45
+ * @method
46
+ * @param {Point} point
47
+ * @returns {boolean}
48
+ */
49
+ /**
50
+ * return true if this point is equal to the given values
51
+ * @name equals
52
+ * @memberof Point
53
+ * @param {number} x
54
+ * @param {number} y
55
+ * @returns {boolean}
56
+ */
57
+ equals() {
58
+ var _x, _y;
59
+ if (arguments.length === 2) {
60
+ // x, y
61
+ _x = arguments[0];
62
+ _y = arguments[1];
63
+ } else {
64
+ // point
65
+ _x = arguments[0].x;
66
+ _y = arguments[0].y;
67
+ }
68
+ return ((this.x === _x) && (this.y === _y));
69
+ }
70
+
71
+ /**
72
+ * clone this Point
73
+ * @name clone
74
+ * @returns {Point} new Point
75
+ */
76
+ clone() {
77
+ return new Point(this.x, this.y);
78
+ }
79
+ }
80
+ export default Point;
package/src/index.js CHANGED
@@ -30,6 +30,7 @@ import Matrix3d from "./math/matrix3.js";
30
30
  import Polygon from "./geometries/poly.js";
31
31
  import Line from "./geometries/line.js";
32
32
  import Ellipse from "./geometries/ellipse.js";
33
+ import Point from "./geometries/point.js";
33
34
  import Rect from "./geometries/rectangle.js";
34
35
  import RoundRect from "./geometries/roundrect.js";
35
36
  import QuadTree from "./physics/quadtree.js";
@@ -119,6 +120,7 @@ export {
119
120
  Polygon,
120
121
  Line,
121
122
  Ellipse,
123
+ Point,
122
124
  Rect,
123
125
  RoundRect,
124
126
  Tween,
@@ -226,6 +228,7 @@ export function boot() {
226
228
  pool.register("me.RoundRect", RoundRect, true);
227
229
  pool.register("me.Polygon", Polygon, true);
228
230
  pool.register("me.Line", Line, true);
231
+ pool.register("me.Point", Point, true);
229
232
  pool.register("me.Ellipse", Ellipse, true);
230
233
  pool.register("me.Bounds", Bounds, true);
231
234
 
@@ -255,6 +258,7 @@ export function boot() {
255
258
  pool.register("RoundRect", RoundRect, true);
256
259
  pool.register("Polygon", Polygon, true);
257
260
  pool.register("Line", Line, true);
261
+ pool.register("Point", Point, true);
258
262
  pool.register("Ellipse", Ellipse, true);
259
263
  pool.register("Bounds", Bounds, true);
260
264
  pool.register("CanvasTexture", CanvasTexture, true);
@@ -107,7 +107,7 @@ export default class TMXObject {
107
107
  this.type = settings.type;
108
108
 
109
109
  /**
110
- * the åobject class
110
+ * the object class
111
111
  * @public
112
112
  * @type {string}
113
113
  * @name class
@@ -170,6 +170,15 @@ export default class TMXObject {
170
170
  */
171
171
  this.isEllipse = false;
172
172
 
173
+ /**
174
+ * if true, the object is a Point
175
+ * @public
176
+ * @type {boolean}
177
+ * @name isPoint
178
+ * @memberof TMXObject
179
+ */
180
+ this.isPoint = false;
181
+
173
182
  /**
174
183
  * if true, the object is a Polygon
175
184
  * @public
@@ -193,12 +202,14 @@ export default class TMXObject {
193
202
  this.setTile(map.tilesets);
194
203
  }
195
204
  else {
196
- if (typeof(settings.ellipse) !== "undefined") {
205
+ if (typeof settings.ellipse !== "undefined") {
197
206
  this.isEllipse = true;
198
- } else if (typeof(settings.polygon) !== "undefined") {
207
+ } else if (typeof settings.point !== "undefined") {
208
+ this.isPoint = true;
209
+ } else if (typeof settings.polygon !== "undefined") {
199
210
  this.points = settings.polygon;
200
211
  this.isPolygon = true;
201
- } else if (typeof(settings.polyline) !== "undefined") {
212
+ } else if (typeof settings.polyline !== "undefined") {
202
213
  this.points = settings.polyline;
203
214
  this.isPolyLine = true;
204
215
  }
@@ -272,8 +283,9 @@ export default class TMXObject {
272
283
  this.width,
273
284
  this.height
274
285
  )).rotate(this.rotation));
286
+ } else if (this.isPoint === true) {
287
+ shapes.push(pool.pull("Point", this.x, this.y));
275
288
  } else {
276
-
277
289
  // add a polygon
278
290
  if (this.isPolygon === true) {
279
291
  var _polygon = pool.pull("Polygon", 0, 0, this.points);
@@ -282,10 +294,8 @@ export default class TMXObject {
282
294
  throw new Error("collision polygones in Tiled should be defined as Convex");
283
295
  }
284
296
  shapes.push(_polygon.rotate(this.rotation));
285
- }
286
297
 
287
- // add a polyline
288
- else if (this.isPolyLine === true) {
298
+ } else if (this.isPolyLine === true) {
289
299
  var p = this.points;
290
300
  var p1, p2;
291
301
  var segments = p.length - 1;
@@ -317,7 +327,9 @@ export default class TMXObject {
317
327
  // Apply isometric projection
318
328
  if (this.orientation === "isometric") {
319
329
  for (i = 0; i < shapes.length; i++) {
320
- shapes[i].toIso();
330
+ if (typeof shapes[i].toIso === "function") {
331
+ shapes[i].toIso();
332
+ }
321
333
  }
322
334
  }
323
335
 
package/src/math/color.js CHANGED
@@ -533,7 +533,7 @@ class Color {
533
533
  * @param {number} [alpha=1.0] alpha value [0.0 .. 1.0]
534
534
  * @returns {number}
535
535
  */
536
- toUint32(alpha = this.alpha) {
536
+ toUint32(alpha = 1.0) {
537
537
  var ur = this.r & 0xff;
538
538
  var ug = this.g & 0xff;
539
539
  var ub = this.b & 0xff;
@@ -7,6 +7,7 @@ import collision from "./collision.js";
7
7
  import * as arrayUtil from "./../utils/array.js";
8
8
  import timer from "./../system/timer.js";
9
9
  import { clamp } from "./../math/math.js";
10
+ import Point from "../geometries/point.js";
10
11
 
11
12
  /**
12
13
  * @classdesc
@@ -16,7 +17,7 @@ import { clamp } from "./../math/math.js";
16
17
  class Body {
17
18
  /**
18
19
  * @param {Renderable} ancestor the parent object this body is attached to
19
- * @param {Rect|Rect[]|Polygon|Polygon[]|Line|Line[]|Ellipse|Ellipse[]|Bounds|Bounds[]|object} [shapes] a initial shape, list of shapes, or JSON object defining the body
20
+ * @param {Rect|Rect[]|Polygon|Polygon[]|Line|Line[]|Ellipse|Ellipse[]|Point|Point[]|Bounds|Bounds[]|object} [shapes] a initial shape, list of shapes, or JSON object defining the body
20
21
  * @param {Function} [onBodyUpdate] callback for when the body is updated (e.g. add/remove shapes)
21
22
  */
22
23
  constructor(ancestor, shapes, onBodyUpdate) {
@@ -43,7 +44,7 @@ class Body {
43
44
  /**
44
45
  * The collision shapes of the body
45
46
  * @ignore
46
- * @type {Polygon[]|Line[]|Ellipse[]}
47
+ * @type {Polygon[]|Line[]|Ellipse[]|Point|Point[]}
47
48
  */
48
49
  this.shapes = [];
49
50
  }
@@ -235,7 +236,7 @@ class Body {
235
236
  /**
236
237
  * add a collision shape to this body <br>
237
238
  * (note: me.Rect objects will be converted to me.Polygon before being added)
238
- * @param {Rect|Polygon|Line|Ellipse|Bounds|object} shape a shape or JSON object
239
+ * @param {Rect|Polygon|Line|Ellipse|Point|Point[]|Bounds|object} shape a shape or JSON object
239
240
  * @returns {number} the shape array length
240
241
  * @example
241
242
  * // add a rectangle shape
@@ -270,6 +271,12 @@ class Body {
270
271
  // update the body bounds
271
272
  this.bounds.add(shape.points);
272
273
  this.bounds.translate(shape.pos);
274
+ } else if (shape instanceof Point) {
275
+ if (!this.shapes.includes(shape)) {
276
+ // see removeShape
277
+ this.shapes.push(shape);
278
+ }
279
+ this.bounds.addPoint(shape);
273
280
  } else {
274
281
  // JSON object
275
282
  this.fromJSON(shape);
@@ -251,17 +251,18 @@ class Bounds {
251
251
  * add the given point to the bounds definition.
252
252
  * @name addPoint
253
253
  * @memberof Bounds
254
- * @param {Vector2d} v
255
- * @param {Matrix2d} [m] an optional transform to apply to the given point
254
+ * @param {Vector2d|Point} point the point to be added to the bounds
255
+ * @param {Matrix2d} [m] an optional transform to apply to the given point (only if the given point is a vector)
256
256
  */
257
- addPoint(v, m) {
258
- if (typeof m !== "undefined") {
259
- v = m.apply(v);
257
+ addPoint(point, m) {
258
+ if ((typeof m !== "undefined") && (typeof point.rotate === "function")) {
259
+ // only Vectors object have a rotate function
260
+ point = m.apply(point);
260
261
  }
261
- this.min.x = Math.min(this.min.x, v.x);
262
- this.max.x = Math.max(this.max.x, v.x);
263
- this.min.y = Math.min(this.min.y, v.y);
264
- this.max.y = Math.max(this.max.y, v.y);
262
+ this.min.x = Math.min(this.min.x, point.x);
263
+ this.max.x = Math.max(this.max.x, point.x);
264
+ this.min.y = Math.min(this.min.y, point.y);
265
+ this.max.y = Math.max(this.max.y, point.y);
265
266
  }
266
267
 
267
268
  /**
@@ -2,8 +2,8 @@
2
2
  import "core-js/proposals/global-this";
3
3
 
4
4
  // es10 string trim functions
5
- import "core-js/es/string/trim-left";
6
- import "core-js/es/string/trim-right";
5
+ import "core-js/es/string/trim-start";
6
+ import "core-js/es/string/trim-end";
7
7
 
8
8
  // "built-in" polyfills
9
9
  import "./console.js";