littlejsengine 1.12.6 → 1.13.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 (83) hide show
  1. package/dist/littlejs.d.ts +387 -177
  2. package/dist/littlejs.esm.js +5934 -5294
  3. package/dist/littlejs.esm.min.js +4 -1
  4. package/dist/littlejs.js +5887 -5263
  5. package/dist/littlejs.min.js +4 -1
  6. package/dist/littlejs.release.js +5426 -4829
  7. package/examples/box2d/game.js +1 -1
  8. package/examples/box2d/gameObjects.js +7 -6
  9. package/examples/box2d/index.html +1 -1
  10. package/examples/box2d/scenes.js +7 -7
  11. package/examples/breakout/game.js +1 -1
  12. package/examples/breakout/gameObjects.js +2 -2
  13. package/examples/breakout/index.html +1 -1
  14. package/examples/breakoutTutorial/README.md +2 -2
  15. package/examples/breakoutTutorial/game.js +1 -1
  16. package/examples/breakoutTutorial/index.html +1 -1
  17. package/examples/empty/index.html +1 -1
  18. package/examples/htmlMenu/index.html +1 -1
  19. package/examples/index.html +396 -153
  20. package/examples/module/game.js +1 -1
  21. package/examples/module/index.html +1 -1
  22. package/examples/platformer/game.js +4 -4
  23. package/examples/platformer/gameCharacter.js +6 -6
  24. package/examples/platformer/gameEffects.js +74 -57
  25. package/examples/platformer/gameLevel.js +61 -70
  26. package/examples/platformer/gameObjects.js +4 -4
  27. package/examples/platformer/index.html +1 -1
  28. package/examples/puzzle/index.html +1 -1
  29. package/examples/shorts/base.html +23 -3
  30. package/examples/shorts/box2dCar.js +8 -12
  31. package/examples/shorts/flappyGame.js +52 -0
  32. package/examples/shorts/helloWorld.js +6 -3
  33. package/examples/shorts/hillGlideGame.js +56 -0
  34. package/examples/shorts/landerGame.js +32 -0
  35. package/examples/shorts/maze.js +47 -0
  36. package/examples/shorts/medals.js +42 -0
  37. package/examples/shorts/nineSlice.js +21 -0
  38. package/examples/shorts/piano.js +52 -0
  39. package/examples/shorts/platformer.js +24 -20
  40. package/examples/shorts/{pong.js → pongGame.js} +1 -1
  41. package/examples/shorts/raycasting.js +71 -0
  42. package/examples/shorts/slidingPuzzle.js +42 -0
  43. package/examples/shorts/spaceGame.js +56 -0
  44. package/examples/shorts/starfield.js +17 -0
  45. package/examples/shorts/tileLayer.js +3 -5
  46. package/examples/shorts/tiles.png +0 -0
  47. package/examples/shorts/tiltedView.js +8 -7
  48. package/examples/shorts/topDown.js +18 -26
  49. package/examples/shorts/uiSystem.js +4 -7
  50. package/examples/starter/build.bat +6 -1
  51. package/examples/starter/game.js +2 -2
  52. package/examples/starter/index.html +23 -13
  53. package/examples/stress/index.html +2 -3
  54. package/examples/style.css +136 -0
  55. package/examples/typescript/build.js +1 -2
  56. package/examples/typescript/game.js +2 -2
  57. package/examples/typescript/game.ts +1 -1
  58. package/examples/typescript/index.html +1 -1
  59. package/examples/uiSystem/game.js +8 -24
  60. package/examples/uiSystem/index.html +1 -1
  61. package/package.json +1 -1
  62. package/plugins/box2d.js +8 -8
  63. package/plugins/drawUtilities.js +126 -0
  64. package/plugins/newgrounds.js +1 -1
  65. package/plugins/pluginExport.js +7 -1
  66. package/plugins/postProcess.js +2 -2
  67. package/plugins/uiSystem.js +153 -65
  68. package/plugins/zzfxm.js +1 -1
  69. package/reference.md +10 -10
  70. package/src/engine.js +50 -29
  71. package/src/engineAudio.js +14 -5
  72. package/src/engineBuild.bat +6 -1
  73. package/src/engineBuild.js +20 -5
  74. package/src/engineDebug.js +53 -26
  75. package/src/engineDraw.js +108 -57
  76. package/src/engineExport.js +21 -9
  77. package/src/engineInput.js +109 -37
  78. package/src/engineObject.js +68 -67
  79. package/src/engineParticles.js +26 -9
  80. package/src/engineSettings.js +15 -16
  81. package/src/engineTileLayer.js +312 -153
  82. package/src/engineUtilities.js +182 -130
  83. package/src/engineWebGL.js +47 -36
@@ -14,7 +14,7 @@
14
14
  * (
15
15
  * pos, 0, 1, 0, 500, PI, // pos, angle, emitSize, emitTime, emitRate, emitCone
16
16
  * tile(0, 16), // tileInfo
17
- * rgb(1,1,1), rgb(0,0,0), // colorStartA, colorStartB
17
+ * rgb(1,1,1,1), rgb(0,0,0,1), // colorStartA, colorStartB
18
18
  * rgb(1,1,1,0), rgb(0,0,0,0), // colorEndA, colorEndB
19
19
  * 2, .2, .2, .1, .05, // particleTime, sizeStart, sizeEnd, particleSpeed, particleAngleSpeed
20
20
  * .99, 1, 1, PI, .05, // damping, angleDamping, gravityScale, particleCone, fadeRate,
@@ -169,7 +169,7 @@ class ParticleEmitter extends EngineObject
169
169
  if (debugParticles)
170
170
  {
171
171
  // show emitter bounds
172
- const emitSize = typeof this.emitSize === 'number' ? vec2(this.emitSize) : this.emitSize;
172
+ const emitSize = typeof this.emitSize == 'number' ? vec2(this.emitSize) : this.emitSize;
173
173
  debugRect(this.pos, emitSize, '#0f0', 0, this.angle);
174
174
  }
175
175
  }
@@ -179,9 +179,9 @@ class ParticleEmitter extends EngineObject
179
179
  emitParticle()
180
180
  {
181
181
  // spawn a particle
182
- let pos = typeof this.emitSize === 'number' ? // check if number was used
183
- randInCircle(this.emitSize/2) // circle emitter
184
- : vec2(rand(-.5,.5), rand(-.5,.5)) // box emitter
182
+ let pos = typeof this.emitSize == 'number' ? // check if number was used
183
+ randInCircle(this.emitSize/2) // circle emitter
184
+ : vec2(rand(-.5,.5), rand(-.5,.5)) // box emitter
185
185
  .multiply(this.emitSize).rotate(this.angle)
186
186
  let angle = rand(this.particleConeAngle, -this.particleConeAngle);
187
187
  if (!this.localSpace)
@@ -212,12 +212,12 @@ class ParticleEmitter extends EngineObject
212
212
  particle.fadeRate = this.fadeRate;
213
213
  particle.damping = this.damping;
214
214
  particle.angleDamping = this.angleDamping;
215
- particle.elasticity = this.elasticity;
215
+ particle.restitution = this.restitution;
216
216
  particle.friction = this.friction;
217
217
  particle.gravityScale = this.gravityScale;
218
218
  particle.collideTiles = this.collideTiles;
219
219
  particle.renderOrder = this.renderOrder;
220
- particle.mirror = !!randInt(2);
220
+ particle.mirror = randBool();
221
221
 
222
222
  // call particle create callback
223
223
  this.particleCreateCallback && this.particleCreateCallback(particle);
@@ -279,9 +279,26 @@ class Particle extends EngineObject
279
279
  this.localSpaceEmitter = localSpaceEmitter;
280
280
  /** @property {Function} - Called when particle dies */
281
281
  this.destroyCallback = destroyCallback;
282
+ // particles do not clamp speed by default
283
+ this.clampSpeed = false;
284
+ }
285
+
286
+ /** Update the object physics, called automatically by engine once each frame */
287
+ update()
288
+ {
289
+ super.update();
282
290
 
283
- // particles use circular clamped speed
284
- this.clampSpeedLinear = false;
291
+ if (this.collideTiles || this.collideSolidObjects)
292
+ {
293
+ // only apply max circular speed if particle can collide
294
+ const length2 = this.velocity.lengthSquared();
295
+ if (length2 > objectMaxSpeed*objectMaxSpeed)
296
+ {
297
+ const s = objectMaxSpeed / length2**.5;
298
+ this.velocity.x *= s;
299
+ this.velocity.y *= s;
300
+ }
301
+ }
285
302
  }
286
303
 
287
304
  /** Render the particle, automatically called each frame, sorted by renderOrder */
@@ -15,6 +15,12 @@
15
15
  * @memberof Settings */
16
16
  let cameraPos = vec2();
17
17
 
18
+ /** Rotation angle of camera in world space
19
+ * @type {number}
20
+ * @default
21
+ * @memberof Settings */
22
+ let cameraAngle = 0;
23
+
18
24
  /** Scale of camera in world space
19
25
  * @type {number}
20
26
  * @default
@@ -80,13 +86,6 @@ let headlessMode = false;
80
86
  * @memberof Settings */
81
87
  let glEnable = true;
82
88
 
83
- /** Fixes slow rendering in some browsers by not compositing the WebGL canvas
84
- * - Must be set before startup to take effect
85
- * @type {boolean}
86
- * @default
87
- * @memberof Settings */
88
- let glOverlay = true;
89
-
90
89
  ///////////////////////////////////////////////////////////////////////////////
91
90
  // Tile sheet settings
92
91
 
@@ -133,7 +132,7 @@ let objectDefaultAngleDamping = 1;
133
132
  * @type {number}
134
133
  * @default
135
134
  * @memberof Settings */
136
- let objectDefaultElasticity = 0;
135
+ let objectDefaultRestitution = 0;
137
136
 
138
137
  /** How much to slow when touching (0-1)
139
138
  * @type {number}
@@ -282,6 +281,11 @@ let medalsPreventUnlock = false;
282
281
  * @memberof Settings */
283
282
  function setCameraPos(pos) { cameraPos = pos; }
284
283
 
284
+ /** Set angle of camera in world space
285
+ * @param {number} angle
286
+ * @memberof Settings */
287
+ function setCameraAngle(angle) { cameraAngle = angle; }
288
+
285
289
  /** Set scale of camera in world space
286
290
  * @param {number} scale
287
291
  * @memberof Settings */
@@ -325,12 +329,7 @@ function setHeadlessMode(headless) { headlessMode = headless; }
325
329
  /** Set if webgl rendering is enabled
326
330
  * @param {boolean} enable
327
331
  * @memberof Settings */
328
- function setGlEnable(enable) { glEnable = enable; }
329
-
330
- /** Set to not composite the WebGL canvas
331
- * @param {boolean} overlay
332
- * @memberof Settings */
333
- function setGlOverlay(overlay) { glOverlay = overlay; }
332
+ function setGLEnable(enable) { glEnable = enable; }
334
333
 
335
334
  /** Set default size of tiles in pixels
336
335
  * @param {Vector2} size
@@ -363,9 +362,9 @@ function setObjectDefaultDamping(damp) { objectDefaultDamping = damp; }
363
362
  function setObjectDefaultAngleDamping(damp) { objectDefaultAngleDamping = damp; }
364
363
 
365
364
  /** Set how much to bounce when a collision occur
366
- * @param {number} elasticity
365
+ * @param {number} restitution
367
366
  * @memberof Settings */
368
- function setObjectDefaultElasticity(elasticity) { objectDefaultElasticity = elasticity; }
367
+ function setObjectDefaultRestitution(restitution) { objectDefaultRestitution = restitution; }
369
368
 
370
369
  /** Set how much to slow when touching
371
370
  * @param {number} friction