melonjs 12.0.0 → 13.1.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 (54) hide show
  1. package/LICENSE.md +1 -1
  2. package/README.md +4 -6
  3. package/dist/melonjs.js +22648 -22478
  4. package/dist/melonjs.min.js +5 -6
  5. package/dist/melonjs.module.d.ts +289 -264
  6. package/dist/melonjs.module.js +21979 -21804
  7. package/package.json +15 -16
  8. package/src/application/application.js +231 -0
  9. package/src/audio/audio.js +8 -2
  10. package/src/camera/camera2d.js +6 -6
  11. package/src/game.js +9 -232
  12. package/src/index.js +3 -3
  13. package/src/input/keyboard.js +2 -2
  14. package/src/input/pointer.js +4 -5
  15. package/src/input/pointerevent.js +10 -10
  16. package/src/lang/deprecated.js +27 -30
  17. package/src/level/level.js +2 -2
  18. package/src/level/tiled/TMXGroup.js +10 -0
  19. package/src/level/tiled/TMXLayer.js +11 -2
  20. package/src/level/tiled/TMXObject.js +13 -2
  21. package/src/level/tiled/TMXTileMap.js +15 -3
  22. package/src/level/tiled/TMXTileset.js +8 -0
  23. package/src/loader/loader.js +64 -28
  24. package/src/loader/loadingscreen.js +27 -28
  25. package/src/math/color.js +62 -42
  26. package/src/math/observable_vector2.js +26 -2
  27. package/src/math/observable_vector3.js +32 -4
  28. package/src/math/vector2.js +23 -0
  29. package/src/math/vector3.js +26 -0
  30. package/src/physics/body.js +27 -51
  31. package/src/physics/detector.js +3 -3
  32. package/src/physics/quadtree.js +58 -29
  33. package/src/physics/world.js +32 -3
  34. package/src/renderable/container.js +2 -2
  35. package/src/renderable/imagelayer.js +8 -8
  36. package/src/renderable/nineslicesprite.js +27 -1
  37. package/src/renderable/trigger.js +4 -4
  38. package/src/state/stage.js +1 -1
  39. package/src/state/state.js +50 -3
  40. package/src/system/device.js +814 -981
  41. package/src/system/event.js +2 -1
  42. package/src/system/platform.js +32 -0
  43. package/src/system/save.js +23 -14
  44. package/src/system/timer.js +12 -35
  45. package/src/text/text.js +9 -12
  46. package/src/tweens/tween.js +6 -6
  47. package/src/utils/string.js +13 -0
  48. package/src/video/canvas/canvas_renderer.js +30 -65
  49. package/src/video/renderer.js +23 -30
  50. package/src/video/texture/canvas_texture.js +39 -3
  51. package/src/video/video.js +27 -25
  52. package/src/video/webgl/glshader.js +1 -1
  53. package/src/video/webgl/webgl_compositor.js +2 -2
  54. package/src/video/webgl/webgl_renderer.js +8 -20
package/src/math/color.js CHANGED
@@ -2,10 +2,19 @@ import { clamp, random } from "./math.js";
2
2
  import pool from "./../system/pooling.js";
3
3
 
4
4
  // convert a give color component to it hexadecimal value
5
- var toHex = function (component) {
5
+ function toHex(component) {
6
6
  return "0123456789ABCDEF".charAt((component - (component % 16)) >> 4) + "0123456789ABCDEF".charAt(component % 16);
7
7
  };
8
8
 
9
+ function hue2rgb(p, q, t) {
10
+ if (t < 0) t += 1;
11
+ if (t > 1) t -= 1;
12
+ if (t < 1/6) return p + (q - p) * 6 * t;
13
+ if (t < 1/2) return q;
14
+ if (t < 2/3) return p + (q - p) * (2/3 - t) * 6;
15
+ return p;
16
+ }
17
+
9
18
  const rgbaRx = /^rgba?\((\d+), ?(\d+), ?(\d+)(, ?([\d\.]+))?\)$/;
10
19
  const hex3Rx = /^#([\da-fA-F])([\da-fA-F])([\da-fA-F])$/;
11
20
  const hex4Rx = /^#([\da-fA-F])([\da-fA-F])([\da-fA-F])([\da-fA-F])$/;
@@ -199,7 +208,6 @@ class Color {
199
208
  /**
200
209
  * Color Red Component [0 .. 255]
201
210
  * @type {number}
202
- * @memberof Color
203
211
  */
204
212
  get r() {
205
213
  return ~~(this.glArray[0] * 255);
@@ -213,7 +221,6 @@ class Color {
213
221
  /**
214
222
  * Color Green Component [0 .. 255]
215
223
  * @type {number}
216
- * @memberof Color
217
224
  */
218
225
  get g() {
219
226
  return ~~(this.glArray[1] * 255);
@@ -227,7 +234,6 @@ class Color {
227
234
  /**
228
235
  * Color Blue Component [0 .. 255]
229
236
  * @type {number}
230
- * @memberof Color
231
237
  */
232
238
  get b() {
233
239
  return ~~(this.glArray[2] * 255);
@@ -239,7 +245,6 @@ class Color {
239
245
  /**
240
246
  * Color Alpha Component [0.0 .. 1.0]
241
247
  * @type {number}
242
- * @memberof Color
243
248
  */
244
249
  get alpha() {
245
250
  return this.glArray[3];
@@ -252,8 +257,6 @@ class Color {
252
257
 
253
258
  /**
254
259
  * Set this color to the specified value.
255
- * @name setColor
256
- * @memberof Color
257
260
  * @param {number} r red component [0 .. 255]
258
261
  * @param {number} g green component [0 .. 255]
259
262
  * @param {number} b blue component [0 .. 255]
@@ -268,10 +271,59 @@ class Color {
268
271
  return this;
269
272
  }
270
273
 
274
+ /**
275
+ * set this color to the specified HSV value
276
+ * @param {number} h hue (a value from 0 to 1)
277
+ * @param {number} s saturation (a value from 0 to 1)
278
+ * @param {number} v value (a value from 0 to 1)
279
+ * @returns {Color} Reference to this object for method chaining
280
+ */
281
+ setHSV(h, s, v) {
282
+ var r, g, b;
283
+
284
+ var i = Math.floor(h * 6);
285
+ var f = h * 6 - i;
286
+ var p = v * (1 - s);
287
+ var q = v * (1 - f * s);
288
+ var t = v * (1 - (1 - f) * s);
289
+
290
+ switch (i % 6) {
291
+ case 0: r = v, g = t, b = p; break;
292
+ case 1: r = q, g = v, b = p; break;
293
+ case 2: r = p, g = v, b = t; break;
294
+ case 3: r = p, g = q, b = v; break;
295
+ case 4: r = t, g = p, b = v; break;
296
+ case 5: r = v, g = p, b = q; break;
297
+ }
298
+ return this.setColor(r * 255, g * 255, b * 255);
299
+ }
300
+
301
+ /**
302
+ * set this color to the specified HSL value
303
+ * @param {number} h hue (a value from 0 to 1)
304
+ * @param {number} s saturation (a value from 0 to 1)
305
+ * @param {number} l lightness (a value from 0 to 1)
306
+ * @returns {Color} Reference to this object for method chaining
307
+ */
308
+ setHSL(h, s, l) {
309
+ var r, g, b;
310
+
311
+ if (s === 0) {
312
+ r = g = b = l; // achromatic
313
+ } else {
314
+ var q = l < 0.5 ? l * (1 + s) : l + s - l * s;
315
+ var p = 2 * l - q;
316
+
317
+ r = hue2rgb(p, q, h + 1/3);
318
+ g = hue2rgb(p, q, h);
319
+ b = hue2rgb(p, q, h - 1/3);
320
+ }
321
+
322
+ return this.setColor(r * 255, g * 255, b * 255);
323
+ }
324
+
271
325
  /**
272
326
  * Create a new copy of this color object.
273
- * @name clone
274
- * @memberof Color
275
327
  * @returns {Color} Reference to the newly cloned object
276
328
  */
277
329
  clone() {
@@ -280,8 +332,6 @@ class Color {
280
332
 
281
333
  /**
282
334
  * Copy a color object or CSS color into this one.
283
- * @name copy
284
- * @memberof Color
285
335
  * @param {Color|string} color
286
336
  * @returns {Color} Reference to this object for method chaining
287
337
  */
@@ -296,8 +346,6 @@ class Color {
296
346
 
297
347
  /**
298
348
  * Blend this color with the given one using addition.
299
- * @name add
300
- * @memberof Color
301
349
  * @param {Color} color
302
350
  * @returns {Color} Reference to this object for method chaining
303
351
  */
@@ -312,8 +360,6 @@ class Color {
312
360
 
313
361
  /**
314
362
  * Darken this color value by 0..1
315
- * @name darken
316
- * @memberof Color
317
363
  * @param {number} scale
318
364
  * @returns {Color} Reference to this object for method chaining
319
365
  */
@@ -328,8 +374,6 @@ class Color {
328
374
 
329
375
  /**
330
376
  * Linearly interpolate between this color and the given one.
331
- * @name lerp
332
- * @memberof Color
333
377
  * @param {Color} color
334
378
  * @param {number} alpha with alpha = 0 being this color, and alpha = 1 being the given one.
335
379
  * @returns {Color} Reference to this object for method chaining
@@ -345,8 +389,6 @@ class Color {
345
389
 
346
390
  /**
347
391
  * Lighten this color value by 0..1
348
- * @name lighten
349
- * @memberof Color
350
392
  * @param {number} scale
351
393
  * @returns {Color} Reference to this object for method chaining
352
394
  */
@@ -361,8 +403,6 @@ class Color {
361
403
 
362
404
  /**
363
405
  * Generate random r,g,b values for this color object
364
- * @name random
365
- * @memberof Color
366
406
  * @param {number} [min=0] minimum value for the random range
367
407
  * @param {number} [max=255] maxmium value for the random range
368
408
  * @returns {Color} Reference to this object for method chaining
@@ -386,8 +426,6 @@ class Color {
386
426
  /**
387
427
  * Return true if the r,g,b,a values of this color are equal with the
388
428
  * given one.
389
- * @name equals
390
- * @memberof Color
391
429
  * @param {Color} color
392
430
  * @returns {boolean}
393
431
  */
@@ -403,8 +441,6 @@ class Color {
403
441
  /**
404
442
  * Parse a CSS color string and set this color to the corresponding
405
443
  * r,g,b values
406
- * @name parseCSS
407
- * @memberof Color
408
444
  * @param {string} cssColor
409
445
  * @returns {Color} Reference to this object for method chaining
410
446
  */
@@ -420,8 +456,6 @@ class Color {
420
456
 
421
457
  /**
422
458
  * Parse an RGB or RGBA CSS color string
423
- * @name parseRGB
424
- * @memberof Color
425
459
  * @param {string} rgbColor
426
460
  * @returns {Color} Reference to this object for method chaining
427
461
  */
@@ -439,8 +473,6 @@ class Color {
439
473
  /**
440
474
  * Parse a Hex color ("#RGB", "#RGBA" or "#RRGGBB", "#RRGGBBAA" format) and set this color to
441
475
  * the corresponding r,g,b,a values
442
- * @name parseHex
443
- * @memberof Color
444
476
  * @param {string} hexColor
445
477
  * @param {boolean} [argb = false] true if format is #ARGB, or #AARRGGBB (as opposed to #RGBA or #RGGBBAA)
446
478
  * @returns {Color} Reference to this object for method chaining
@@ -498,8 +530,6 @@ class Color {
498
530
 
499
531
  /**
500
532
  * Pack this color into a Uint32 ARGB representation
501
- * @name toUint32
502
- * @memberof Color
503
533
  * @param {number} [alpha=1.0] alpha value [0.0 .. 1.0]
504
534
  * @returns {number}
505
535
  */
@@ -514,8 +544,6 @@ class Color {
514
544
 
515
545
  /**
516
546
  * return an array representation of this object
517
- * @name toArray
518
- * @memberof Color
519
547
  * @returns {Float32Array}
520
548
  */
521
549
  toArray() {
@@ -524,9 +552,7 @@ class Color {
524
552
 
525
553
 
526
554
  /**
527
- * Get the color in "#RRGGBB" format
528
- * @name toHex
529
- * @memberof Color
555
+ * return the color in "#RRGGBB" format
530
556
  * @returns {string}
531
557
  */
532
558
  toHex() {
@@ -538,8 +564,6 @@ class Color {
538
564
 
539
565
  /**
540
566
  * Get the color in "#RRGGBBAA" format
541
- * @name toHex8
542
- * @memberof Color
543
567
  * @returns {string}
544
568
  */
545
569
  toHex8(alpha = this.alpha) {
@@ -551,8 +575,6 @@ class Color {
551
575
 
552
576
  /**
553
577
  * Get the color in "rgb(R,G,B)" format
554
- * @name toRGB
555
- * @memberof Color
556
578
  * @returns {string}
557
579
  */
558
580
  toRGB() {
@@ -568,8 +590,6 @@ class Color {
568
590
 
569
591
  /**
570
592
  * Get the color in "rgba(R,G,B,A)" format
571
- * @name toRGBA
572
- * @memberof Color
573
593
  * @param {number} [alpha=1.0] alpha value [0.0 .. 1.0]
574
594
  * @returns {string}
575
595
  */
@@ -388,8 +388,32 @@ class ObservableVector2d extends Vector2d {
388
388
  * @returns {ObservableVector2d} Reference to this object for method chaining
389
389
  */
390
390
  lerp(v, alpha) {
391
- this._x += ( v.x - this._x ) * alpha;
392
- this._y += ( v.y - this._y ) * alpha;
391
+ return this._set(
392
+ this._x + ( v.x - this._x ) * alpha,
393
+ this._y + ( v.y - this._y ) * alpha
394
+ );
395
+ }
396
+
397
+ /**
398
+ * interpolate the position of this vector towards the given one while nsure that the distance never exceeds the given step.
399
+ * @name moveTowards
400
+ * @memberof ObservableVector2d
401
+ * @param {Vector2d|ObservableVector2d} target
402
+ * @param {number} step the maximum step per iteration (Negative values will push the vector away from the target)
403
+ * @returns {ObservableVector2d} Reference to this object for method chaining
404
+ */
405
+ moveTowards(target, step) {
406
+ var angle = Math.atan2(target.y - this._y, target.x - this._x);
407
+
408
+ var distance = this.distance(target);
409
+
410
+ if (distance === 0 || (step >= 0 && distance <= step * step)) {
411
+ return target;
412
+ }
413
+
414
+ this._x += Math.cos(angle) * step;
415
+ this._y += Math.sin(angle) * step;
416
+
393
417
  return this;
394
418
  }
395
419
 
@@ -465,10 +465,38 @@ class ObservableVector3d extends Vector3d {
465
465
  * @returns {ObservableVector3d} Reference to this object for method chaining
466
466
  */
467
467
  lerp(v, alpha) {
468
- this._x += ( v.x - this._x ) * alpha;
469
- this._y += ( v.y - this._y ) * alpha;
470
- this._z += ( v.z - this._z ) * alpha;
471
- return this;
468
+ return this._set(
469
+ this._x + ( v.x - this._x ) * alpha,
470
+ this._y + ( v.y - this._y ) * alpha,
471
+ this._z + ( v.z - this._z ) * alpha
472
+ );
473
+ }
474
+
475
+ /**
476
+ * interpolate the position of this vector on the x and y axis towards the given one while ensure that the distance never exceeds the given step.
477
+ * @name moveTowards
478
+ * @memberof ObservableVector3d
479
+ * @param {Vector2d|ObservableVector2d|Vector3d|ObservableVector3d} target
480
+ * @param {number} step the maximum step per iteration (Negative values will push the vector away from the target)
481
+ * @returns {ObservableVector3d} Reference to this object for method chaining
482
+ */
483
+ moveTowards(target, step) {
484
+ var angle = Math.atan2(target.y - this._y, target.x - this._x);
485
+
486
+ var dx = this._x - target.x;
487
+ var dy = this._y - target.y;
488
+
489
+ var distance = Math.sqrt(dx * dx + dy * dy);
490
+
491
+ if (distance === 0 || (step >= 0 && distance <= step * step)) {
492
+ return target;
493
+ }
494
+
495
+ return this._set(
496
+ this._x + Math.cos(angle) * step,
497
+ this._y + Math.sin(angle) * step,
498
+ this._z
499
+ );
472
500
  }
473
501
 
474
502
  /**
@@ -426,6 +426,29 @@ class Vector2d {
426
426
  return this;
427
427
  }
428
428
 
429
+ /**
430
+ * interpolate the position of this vector towards the given one by the given maximum step.
431
+ * @name moveTowards
432
+ * @memberof Vector2d
433
+ * @param {Vector2d} target
434
+ * @param {number} step the maximum step per iteration (Negative values will push the vector away from the target)
435
+ * @returns {Vector2d} Reference to this object for method chaining
436
+ */
437
+ moveTowards(target, step) {
438
+ var angle = Math.atan2(target.y - this.y, target.x - this.x);
439
+
440
+ var distance = this.distance(target);
441
+
442
+ if (distance === 0 || (step >= 0 && distance <= step * step)) {
443
+ return target;
444
+ }
445
+
446
+ this.x += Math.cos(angle) * step;
447
+ this.y += Math.sin(angle) * step;
448
+
449
+ return this;
450
+ }
451
+
429
452
  /**
430
453
  * return the distance between this vector and the passed one
431
454
  * @name distance
@@ -460,6 +460,32 @@ class Vector3d {
460
460
  return this;
461
461
  }
462
462
 
463
+ /**
464
+ * interpolate the position of this vector on the x and y axis towards the given one by the given maximum step.
465
+ * @name moveTowards
466
+ * @memberof Vector3d
467
+ * @param {Vector2d|Vector3d} target
468
+ * @param {number} step the maximum step per iteration (Negative values will push the vector away from the target)
469
+ * @returns {Vector3d} Reference to this object for method chaining
470
+ */
471
+ moveTowards(target, step) {
472
+ var angle = Math.atan2(target.y - this.y, target.x - this.x);
473
+
474
+ var dx = this.x - target.x;
475
+ var dy = this.y - target.y;
476
+
477
+ var distance = Math.sqrt(dx * dx + dy * dy);
478
+
479
+ if (distance === 0 || (step >= 0 && distance <= step * step)) {
480
+ return target;
481
+ }
482
+
483
+ this.x += Math.cos(angle) * step;
484
+ this.y += Math.sin(angle) * step;
485
+
486
+ return this;
487
+ }
488
+
463
489
  /**
464
490
  * return the distance between this vector and the passed one
465
491
  * @name distance
@@ -7,8 +7,6 @@ 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 { world } from "./../game.js";
11
-
12
10
 
13
11
  /**
14
12
  * @classdesc
@@ -74,7 +72,9 @@ class Body {
74
72
 
75
73
  if (typeof this.vel === "undefined") {
76
74
  /**
77
- * body velocity
75
+ * The current velocity of the body.
76
+ * See to apply a force if you need to modify a body velocity
77
+ * @see Body.force
78
78
  * @public
79
79
  * @type {Vector2d}
80
80
  * @default <0,0>
@@ -85,15 +85,15 @@ class Body {
85
85
 
86
86
  if (typeof this.force === "undefined") {
87
87
  /**
88
- * body force or acceleration (automatically) applied to the body.
89
- * when defining a force, user should also define a max velocity
88
+ * body force to apply to this the body in the current step.
89
+ * (any positive or negative force will be cancelled after every world/body update cycle)
90
90
  * @public
91
91
  * @type {Vector2d}
92
92
  * @default <0,0>
93
93
  * @see Body.setMaxVelocity
94
94
  * @example
95
95
  * // define a default maximum acceleration, initial force and friction
96
- * this.body.force.set(0, 0);
96
+ * this.body.force.set(1, 0);
97
97
  * this.body.friction.set(0.4, 0);
98
98
  * this.body.setMaxVelocity(3, 15);
99
99
  *
@@ -103,8 +103,6 @@ class Body {
103
103
  * this.body.force.x = -this.body.maxVel.x;
104
104
  * } else if (me.input.isKeyPressed("right")) {
105
105
  * this.body.force.x = this.body.maxVel.x;
106
- * } else {
107
- * this.body.force.x = 0;
108
106
  * }
109
107
  * }
110
108
  */
@@ -463,10 +461,12 @@ class Body {
463
461
  this.vel.y *= -this.bounce;
464
462
  }
465
463
 
466
- // cancel the falling an jumping flags if necessary
467
- var dir = Math.sign(world.gravity.y * this.gravityScale) || 1;
468
- this.falling = overlap.y >= dir;
469
- this.jumping = overlap.y <= -dir;
464
+ if (!this.ignoreGravity) {
465
+ // cancel the falling an jumping flags if necessary
466
+ var dir = this.falling === true ? 1 : this.jumping === true ? -1 : 0;
467
+ this.falling = overlap.y >= dir;
468
+ this.jumping = overlap.y <= -dir;
469
+ }
470
470
  }
471
471
  }
472
472
 
@@ -507,14 +507,12 @@ class Body {
507
507
  }
508
508
  }
509
509
 
510
-
511
510
  /**
512
511
  * Returns true if the any of the shape composing the body contains the given point.
513
512
  * @method Body#contains
514
513
  * @param {Vector2d} point
515
514
  * @returns {boolean} true if contains
516
515
  */
517
-
518
516
  /**
519
517
  * Returns true if the any of the shape composing the body contains the given point.
520
518
  * @param {number} x x coordinate
@@ -591,27 +589,23 @@ class Body {
591
589
  }
592
590
 
593
591
  /**
594
- * compute the new velocity value
595
- * @ignore
592
+ * Updates the parent's position as well as computes the new body's velocity based
593
+ * on the values of force/friction. Velocity chages are proportional to the
594
+ * me.timer.tick value (which can be used to scale velocities). The approach to moving the
595
+ * parent renderable is to compute new values of the Body.vel property then add them to
596
+ * the parent.pos value thus changing the postion the amount of Body.vel each time the
597
+ * update call is made. <br>
598
+ * Updates to Body.vel are bounded by maxVel (which defaults to viewport size if not set) <br>
599
+ * At this time a call to Body.Update does not call the onBodyUpdate callback that is listed in the constructor arguments.
600
+ * @protected
601
+ * @param {number} dt time since the last update in milliseconds.
602
+ * @returns {boolean} true if resulting velocity is different than 0
596
603
  */
597
- computeVelocity(/* dt */) {
604
+ update(dt) { // eslint-disable-line no-unused-vars
598
605
  // apply timer.tick to delta time for linear interpolation (when enabled)
599
606
  // #761 add delta time in body update
600
607
  var deltaTime = /* dt * */ timer.tick;
601
608
 
602
- // apply gravity to the current velocity
603
- if (!this.ignoreGravity) {
604
- var worldGravity = world.gravity;
605
-
606
- // apply gravity if defined
607
- this.vel.x += worldGravity.x * this.gravityScale * deltaTime;
608
- this.vel.y += worldGravity.y * this.gravityScale * deltaTime;
609
-
610
- // check if falling / jumping
611
- this.falling = (this.vel.y * Math.sign(worldGravity.y * this.gravityScale)) > 0;
612
- this.jumping = (this.falling ? false : this.jumping);
613
- }
614
-
615
609
  // apply force if defined
616
610
  if (this.force.x !== 0) {
617
611
  this.vel.x += this.force.x * deltaTime;
@@ -649,28 +643,10 @@ class Body {
649
643
  if (this.vel.x !== 0) {
650
644
  this.vel.x = clamp(this.vel.x, -this.maxVel.x, this.maxVel.x);
651
645
  }
652
- }
653
646
 
654
- /**
655
- * Updates the parent's position as well as computes the new body's velocity based
656
- * on the values of force/friction/gravity. Velocity chages are proportional to the
657
- * me.timer.tick value (which can be used to scale velocities). The approach to moving the
658
- * parent renderable is to compute new values of the Body.vel property then add them to
659
- * the parent.pos value thus changing the postion the amount of Body.vel each time the
660
- * update call is made. <br>
661
- * Updates to Body.vel are bounded by maxVel (which defaults to viewport size if not set) <br>
662
- *
663
- * In addition, when the gravity calcuation is made, if the Body.vel.y > 0 then the Body.falling
664
- * property is set to true and Body.jumping is set to !Body.falling.
665
- *
666
- * At this time a call to Body.Update does not call the onBodyUpdate callback that is listed in the constructor arguments.
667
- * @protected
668
- * @param {number} dt time since the last update in milliseconds.
669
- * @returns {boolean} true if resulting velocity is different than 0
670
- */
671
- update(dt) {
672
- // update the velocity
673
- this.computeVelocity(dt);
647
+ // check if falling / jumping
648
+ this.falling = (this.vel.y * Math.sign(this.force.y)) > 0;
649
+ this.jumping = (this.falling ? false : this.jumping);
674
650
 
675
651
  // update the body ancestor position
676
652
  this.ancestor.pos.add(this.vel);
@@ -1,7 +1,7 @@
1
1
  import * as SAT from "./sat.js";
2
2
  import ResponseObject from "./response.js";
3
3
  import Vector2d from "./../math/vector2.js";
4
- import { world } from "./../game.js";
4
+ import game from "./../game.js";
5
5
 
6
6
  // a dummy object when using Line for raycasting
7
7
  let dummyObj = {
@@ -50,7 +50,7 @@ function shouldCollide(a, b) {
50
50
  export function collisionCheck(objA, response = globalResponse) {
51
51
  var collisionCounter = 0;
52
52
  // retreive a list of potential colliding objects from the game world
53
- var candidates = world.broadphase.retrieve(objA);
53
+ var candidates = game.world.broadphase.retrieve(objA);
54
54
 
55
55
  for (var i = candidates.length, objB; i--, (objB = candidates[i]);) {
56
56
 
@@ -139,7 +139,7 @@ export function rayCast(line, result = []) {
139
139
  var collisionCounter = 0;
140
140
 
141
141
  // retrieve a list of potential colliding objects from the game world
142
- var candidates = world.broadphase.retrieve(line);
142
+ var candidates = game.world.broadphase.retrieve(line);
143
143
 
144
144
  for (var i = candidates.length, objB; i--, (objB = candidates[i]);) {
145
145