littlejsengine 1.17.1 → 1.17.10

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 (49) hide show
  1. package/LICENSE +10 -10
  2. package/dist/littlejs.d.ts +254 -171
  3. package/dist/littlejs.esm.js +892 -628
  4. package/dist/littlejs.esm.min.js +1 -1
  5. package/dist/littlejs.js +889 -626
  6. package/dist/littlejs.min.js +1 -1
  7. package/dist/littlejs.release.js +885 -622
  8. package/examples/box2d/gameObjects.js +3 -3
  9. package/examples/electron/index.html +2 -2
  10. package/examples/index.html +10 -9
  11. package/examples/logo.png +0 -0
  12. package/examples/logo2.png +0 -0
  13. package/examples/module/build.bat +7 -0
  14. package/examples/module/build.js +121 -0
  15. package/examples/particles/index.html +1 -1
  16. package/examples/platformer/game.js +1 -1
  17. package/examples/platformer/gameEffects.js +5 -10
  18. package/examples/platformer/gameLevel.js +3 -3
  19. package/examples/puzzle/game.js +2 -2
  20. package/examples/shorts/base.html +4 -1
  21. package/examples/shorts/box2dPool.js +2 -2
  22. package/examples/shorts/box2dTileLayer.js +48 -0
  23. package/examples/shorts/colors.js +1 -1
  24. package/examples/shorts/fps.js +1 -1
  25. package/examples/shorts/music.js +5 -4
  26. package/examples/shorts/musicPlayer.js +4 -3
  27. package/examples/shorts/parallax.js +2 -2
  28. package/examples/shorts/tiltedView.js +1 -1
  29. package/examples/starter/index.html +2 -2
  30. package/package.json +5 -5
  31. package/plugins/box2d.js +166 -63
  32. package/plugins/pluginExport.js +1 -1
  33. package/plugins/postProcess.js +1 -1
  34. package/plugins/uiSystem.js +33 -20
  35. package/plugins/zzfxm.js +2 -2
  36. package/reference.md +9 -8
  37. package/src/engine.js +111 -134
  38. package/src/engineAudio.js +44 -58
  39. package/src/engineDebug.js +4 -4
  40. package/src/engineDraw.js +7 -4
  41. package/src/engineExport.js +2 -1
  42. package/src/engineInput.js +5 -5
  43. package/src/engineMath.js +9 -9
  44. package/src/engineObject.js +25 -25
  45. package/src/engineParticles.js +241 -118
  46. package/src/engineTileLayer.js +117 -88
  47. package/src/engineUtilities.js +105 -78
  48. package/src/engineWebGL.js +2 -2
  49. package/plugins/Box2D_License.txt +0 -17
package/src/engineMath.js CHANGED
@@ -16,25 +16,25 @@
16
16
  const PI = Math.PI;
17
17
 
18
18
  /** Returns absolute value of value passed in
19
- * @param {number} value
19
+ * @param {number} x
20
20
  * @return {number}
21
21
  * @memberof Math */
22
22
  const abs = Math.abs;
23
23
 
24
24
  /** Returns floored value of value passed in
25
- * @param {number} value
25
+ * @param {number} x
26
26
  * @return {number}
27
27
  * @memberof Math */
28
28
  const floor = Math.floor;
29
29
 
30
30
  /** Returns ceiled value of value passed in
31
- * @param {number} value
31
+ * @param {number} x
32
32
  * @return {number}
33
33
  * @memberof Math */
34
34
  const ceil = Math.ceil;
35
35
 
36
36
  /** Returns rounded value passed in
37
- * @param {number} value
37
+ * @param {number} x
38
38
  * @return {number}
39
39
  * @memberof Math */
40
40
  const round = Math.round;
@@ -52,7 +52,7 @@ const min = Math.min;
52
52
  const max = Math.max;
53
53
 
54
54
  /** Returns the sign of value passed in
55
- * @param {number} value
55
+ * @param {number} x
56
56
  * @return {number}
57
57
  * @memberof Math */
58
58
  const sign = Math.sign;
@@ -64,25 +64,25 @@ const sign = Math.sign;
64
64
  const hypot = Math.hypot;
65
65
 
66
66
  /** Returns log2 of value passed in
67
- * @param {number} value
67
+ * @param {number} x
68
68
  * @return {number}
69
69
  * @memberof Math */
70
70
  const log2 = Math.log2;
71
71
 
72
72
  /** Returns sin of value passed in
73
- * @param {number} value
73
+ * @param {number} x
74
74
  * @return {number}
75
75
  * @memberof Math */
76
76
  const sin = Math.sin;
77
77
 
78
78
  /** Returns cos of value passed in
79
- * @param {number} value
79
+ * @param {number} x
80
80
  * @return {number}
81
81
  * @memberof Math */
82
82
  const cos = Math.cos;
83
83
 
84
84
  /** Returns tan of value passed in
85
- * @param {number} value
85
+ * @param {number} x
86
86
  * @return {number}
87
87
  * @memberof Math */
88
88
  const tan = Math.tan;
@@ -66,17 +66,19 @@ class EngineObject
66
66
  this.additiveColor = undefined;
67
67
  /** @property {boolean} - Should it flip along y axis when rendered */
68
68
  this.mirror = false;
69
+ /** @property {boolean} - Has object been destroyed? */
70
+ this.destroyed = false;
69
71
 
70
72
  // physical properties
71
- /** @property {number} [mass=objectDefaultMass] - How heavy the object is, static if 0 */
73
+ /** @property {number} - How heavy the object is, static if 0 */
72
74
  this.mass = objectDefaultMass;
73
- /** @property {number} [damping=objectDefaultDamping] - How much to slow down velocity each frame (0-1) */
75
+ /** @property {number} - How much to slow down velocity each frame (0-1) */
74
76
  this.damping = objectDefaultDamping;
75
- /** @property {number} [angleDamping=objectDefaultAngleDamping] - How much to slow down rotation each frame (0-1) */
77
+ /** @property {number} - How much to slow down rotation each frame (0-1) */
76
78
  this.angleDamping = objectDefaultAngleDamping;
77
- /** @property {number} [restitution=objectDefaultRestitution] - How bouncy the object is when colliding (0-1) */
79
+ /** @property {number} - How bouncy the object is when colliding (0-1) */
78
80
  this.restitution = objectDefaultRestitution;
79
- /** @property {number} [friction=objectDefaultFriction] - How much friction to apply when sliding (0-1) */
81
+ /** @property {number} - How much friction to apply when sliding (0-1) */
80
82
  this.friction = objectDefaultFriction;
81
83
  /** @property {number} - How much to scale gravity by for this object */
82
84
  this.gravityScale = 1;
@@ -277,7 +279,7 @@ class EngineObject
277
279
  if (this.collideTiles)
278
280
  {
279
281
  // check collision against tiles
280
- const hitLayer = tileCollisionTest(this.pos, this.size, this)
282
+ const hitLayer = tileCollisionTest(this.pos, this.size, this);
281
283
  if (hitLayer)
282
284
  {
283
285
  // if already was stuck in collision, don't do anything
@@ -285,10 +287,10 @@ class EngineObject
285
287
  if (!tileCollisionTest(oldPos, this.size, this))
286
288
  {
287
289
  // test which side we bounced off (or both if a corner)
288
- const blockedLayerY = tileCollisionTest(vec2(oldPos.x, this.pos.y), this.size, this);
289
- const blockedLayerX = tileCollisionTest(vec2(this.pos.x, oldPos.y), this.size, this);
290
-
291
- if (blockedLayerX)
290
+ const isBlockedX = tileCollisionTest(vec2(this.pos.x, oldPos.y), this.size, this);
291
+ const isBlockedY = tileCollisionTest(vec2(oldPos.x, this.pos.y), this.size, this);
292
+ const restitution = max(this.restitution, hitLayer.restitution);
293
+ if (isBlockedX)
292
294
  {
293
295
  // try to move up a tiny bit
294
296
  const epsilon = 1e-3;
@@ -304,16 +306,12 @@ class EngineObject
304
306
  return;
305
307
  }
306
308
 
307
- // move to previous position and bounce
309
+ // move to previous X position and bounce
308
310
  this.pos.x = oldPos.x;
309
- this.velocity.x *= -this.restitution;
311
+ this.velocity.x *= -restitution;
310
312
  }
311
- if (blockedLayerY || !blockedLayerX)
313
+ if (isBlockedY || !isBlockedX)
312
314
  {
313
- // bounce velocity
314
- const restitution = max(this.restitution, hitLayer.restitution);
315
- this.velocity.y *= -restitution;
316
-
317
315
  if (wasFalling)
318
316
  {
319
317
  // adjust position to slightly away from nearest tile
@@ -329,10 +327,12 @@ class EngineObject
329
327
  }
330
328
  else
331
329
  {
332
- // move to previous position
330
+ // move to previous Y position
333
331
  this.pos.y = oldPos.y;
334
332
  this.groundObject = undefined;
335
333
  }
334
+ // bounce velocity
335
+ this.velocity.y *= -restitution;
336
336
  }
337
337
  debugPhysics && debugRect(this.pos, this.size, '#f00');
338
338
  }
@@ -350,19 +350,19 @@ class EngineObject
350
350
  drawTile(this.pos, this.drawSize || this.size, this.tileInfo, this.color, this.angle, this.mirror, this.additiveColor);
351
351
  }
352
352
 
353
- /** Destroy this object, destroy its children, detach its parent, and mark it for removal */
354
- destroy()
353
+ /** Destroy this object, destroy its children, detach its parent, and mark it for removal
354
+ * @param {boolean} [immediate] - should attached effects be allowed to die off? */
355
+ destroy(immediate=false)
355
356
  {
356
- if (this.destroyed)
357
- return;
357
+ if (this.destroyed) return;
358
358
 
359
359
  // disconnect from parent and destroy children
360
- this.destroyed = 1;
360
+ this.destroyed = true;
361
361
  this.parent?.removeChild(this);
362
362
  for (const child of this.children)
363
363
  {
364
364
  child.parent = undefined;
365
- child.destroy();
365
+ child.destroy(immediate);
366
366
  }
367
367
  }
368
368
 
@@ -461,7 +461,7 @@ class EngineObject
461
461
  }
462
462
 
463
463
  /** Check if overlapping another engine object
464
- * Collisions are resoloved to prevent overlaps
464
+ * Collisions are resolved to prevent overlaps
465
465
  * @param {EngineObject} object
466
466
  * @return {boolean} */
467
467
  isOverlappingObject(object)