littlejsengine 1.13.1 → 1.14.2

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/README.md +15 -11
  2. package/copyToGithub.bat +28 -0
  3. package/dist/littlejs.d.ts +430 -304
  4. package/dist/littlejs.esm.js +1745 -982
  5. package/dist/littlejs.esm.min.js +1 -1
  6. package/dist/littlejs.js +1716 -965
  7. package/dist/littlejs.min.js +1 -1
  8. package/dist/littlejs.release.js +1673 -922
  9. package/examples/box2d/game.js +2 -2
  10. package/examples/box2d/gameObjects.js +2 -2
  11. package/examples/box2d/scenes.js +1 -1
  12. package/examples/breakout/game.js +30 -25
  13. package/examples/breakoutTutorial/README.md +44 -41
  14. package/examples/breakoutTutorial/game.js +2 -2
  15. package/examples/electron/build.bat +7 -0
  16. package/examples/electron/build.js +124 -0
  17. package/examples/electron/electron.js +35 -0
  18. package/examples/electron/game.js +140 -0
  19. package/examples/electron/index.html +13 -0
  20. package/examples/electron/package.json +12 -0
  21. package/examples/electron/tiles.png +0 -0
  22. package/examples/empty/game.js +1 -0
  23. package/examples/htmlMenu/game.js +1 -1
  24. package/examples/index.html +332 -160
  25. package/examples/module/game.js +5 -2
  26. package/examples/particles/index.html +12 -3
  27. package/examples/platformer/gameEffects.js +20 -19
  28. package/examples/platformer/gameLevel.js +6 -1
  29. package/examples/shorts/base.html +1 -1
  30. package/examples/shorts/blending.js +9 -5
  31. package/examples/shorts/box2d.js +1 -1
  32. package/examples/shorts/box2dCar.js +1 -1
  33. package/examples/shorts/clock.js +1 -1
  34. package/examples/shorts/colors.js +2 -2
  35. package/examples/shorts/flappyGame.js +2 -1
  36. package/examples/shorts/helloWorld.js +1 -1
  37. package/examples/shorts/maze.js +1 -1
  38. package/examples/shorts/music.js +106 -0
  39. package/examples/shorts/nineSlice.js +9 -9
  40. package/examples/shorts/parallax.js +71 -0
  41. package/examples/shorts/piano.js +9 -10
  42. package/examples/shorts/postProcess.js +25 -8
  43. package/examples/shorts/raycasting.js +2 -2
  44. package/examples/shorts/shapes.js +7 -15
  45. package/examples/shorts/slidingPuzzle.js +2 -2
  46. package/examples/shorts/song.mp3 +0 -0
  47. package/examples/shorts/starfield.js +5 -7
  48. package/examples/shorts/systemFont.js +1 -1
  49. package/examples/shorts/uiSystem.js +16 -8
  50. package/examples/starter/build.js +9 -8
  51. package/examples/starter/game.js +5 -2
  52. package/examples/starter/index.html +2 -2
  53. package/examples/stress/index.html +13 -8
  54. package/examples/style.css +19 -6
  55. package/examples/typescript/build.js +1 -1
  56. package/examples/typescript/game.js +2 -2
  57. package/examples/typescript/game.ts +5 -2
  58. package/examples/uiSystem/game.js +13 -12
  59. package/package.json +2 -2
  60. package/plugins/box2d.js +24 -97
  61. package/plugins/drawUtilities.js +29 -23
  62. package/plugins/newgrounds.js +6 -6
  63. package/plugins/pluginExport.js +1 -1
  64. package/plugins/postProcess.js +7 -0
  65. package/plugins/uiSystem.js +106 -82
  66. package/plugins/zzfxm.js +10 -10
  67. package/reference.md +90 -54
  68. package/src/engine.js +28 -23
  69. package/src/engineAudio.js +285 -110
  70. package/src/engineBuild.js +9 -9
  71. package/src/engineDebug.js +28 -28
  72. package/src/engineDraw.js +346 -202
  73. package/src/engineExport.js +28 -16
  74. package/src/engineInput.js +58 -68
  75. package/src/engineMedals.js +29 -29
  76. package/src/engineObject.js +28 -25
  77. package/src/engineParticles.js +67 -60
  78. package/src/engineRelease.js +1 -1
  79. package/src/engineSettings.js +70 -16
  80. package/src/engineTileLayer.js +34 -34
  81. package/src/engineUtilities.js +69 -62
  82. package/src/engineWebGL.js +467 -65
  83. /package/examples/shorts/{playSound.js → sound.js} +0 -0
@@ -1,4 +1,4 @@
1
- /**
1
+ /**
2
2
  * LittleJS Debug System
3
3
  * - Press Esc to show debug overlay with mouse pick
4
4
  * - Number keys toggle debug functions
@@ -53,10 +53,10 @@ let debugPrimitives = [], debugPhysics = false, debugRaycast = false, debugParti
53
53
  // Debug helper functions
54
54
 
55
55
  /** Asserts if the expression is false, does not do anything in release builds
56
- * @param {boolean} assert
56
+ * @param {boolean} assert
57
57
  * @param {...Object} [output] - error message output
58
58
  * @memberof Debug */
59
- function ASSERT(assert, ...output)
59
+ function ASSERT(assert, ...output)
60
60
  {
61
61
  if (enableAsserts)
62
62
  console.assert(assert, ...output);
@@ -72,9 +72,9 @@ function ASSERT(assert, ...output)
72
72
  * @memberof Debug */
73
73
  function debugRect(pos, size=vec2(), color='#fff', time=0, angle=0, fill=false)
74
74
  {
75
- if (typeof size == 'number')
75
+ if (typeof size === 'number')
76
76
  size = vec2(size); // allow passing in floats
77
- ASSERT(typeof color == 'string', 'pass in css color strings');
77
+ ASSERT(typeof color === 'string', 'pass in css color strings');
78
78
  debugPrimitives.push({pos, size, color, time:new Timer(time), angle, fill});
79
79
  }
80
80
 
@@ -88,7 +88,7 @@ function debugRect(pos, size=vec2(), color='#fff', time=0, angle=0, fill=false)
88
88
  * @memberof Debug */
89
89
  function debugPoly(pos, points, color='#fff', time=0, angle=0, fill=false)
90
90
  {
91
- ASSERT(typeof color == 'string', 'pass in css color strings');
91
+ ASSERT(typeof color === 'string', 'pass in css color strings');
92
92
  debugPrimitives.push({pos, points, color, time:new Timer(time), angle, fill});
93
93
  }
94
94
 
@@ -101,7 +101,7 @@ function debugPoly(pos, points, color='#fff', time=0, angle=0, fill=false)
101
101
  * @memberof Debug */
102
102
  function debugCircle(pos, radius=0, color='#fff', time=0, fill=false)
103
103
  {
104
- ASSERT(typeof color == 'string', 'pass in css color strings');
104
+ ASSERT(typeof color === 'string', 'pass in css color strings');
105
105
  debugPrimitives.push({pos, size:radius, color, time:new Timer(time), angle:0, fill});
106
106
  }
107
107
 
@@ -113,7 +113,7 @@ function debugCircle(pos, radius=0, color='#fff', time=0, fill=false)
113
113
  * @memberof Debug */
114
114
  function debugPoint(pos, color, time, angle)
115
115
  {
116
- ASSERT(typeof color == 'string', 'pass in css color strings');
116
+ ASSERT(typeof color === 'string', 'pass in css color strings');
117
117
  debugRect(pos, undefined, color, time, angle);
118
118
  }
119
119
 
@@ -141,11 +141,11 @@ function debugLine(posA, posB, color, thickness=.1, time)
141
141
  function debugOverlap(posA, sizeA, posB, sizeB, color)
142
142
  {
143
143
  const minPos = vec2(
144
- min(posA.x - sizeA.x/2, posB.x - sizeB.x/2),
144
+ min(posA.x - sizeA.x/2, posB.x - sizeB.x/2),
145
145
  min(posA.y - sizeA.y/2, posB.y - sizeB.y/2)
146
146
  );
147
147
  const maxPos = vec2(
148
- max(posA.x + sizeA.x/2, posB.x + sizeB.x/2),
148
+ max(posA.x + sizeA.x/2, posB.x + sizeB.x/2),
149
149
  max(posA.y + sizeA.y/2, posB.y + sizeB.y/2)
150
150
  );
151
151
  debugRect(minPos.lerp(maxPos,.5), maxPos.subtract(minPos), color);
@@ -162,7 +162,7 @@ function debugOverlap(posA, sizeA, posB, sizeB, color)
162
162
  * @memberof Debug */
163
163
  function debugText(text, pos, size=1, color='#fff', time=0, angle=0, font='monospace')
164
164
  {
165
- ASSERT(typeof color == 'string', 'pass in css color strings');
165
+ ASSERT(typeof color === 'string', 'pass in css color strings');
166
166
  debugPrimitives.push({text, pos, size, color, time:new Timer(time), angle, font});
167
167
  }
168
168
 
@@ -174,7 +174,7 @@ function debugClear() { debugPrimitives = []; }
174
174
  * @memberof Debug */
175
175
  function debugScreenshot() { debugTakeScreenshot = 1; }
176
176
 
177
- /** Save a canvas to disk
177
+ /** Save a canvas to disk
178
178
  * @param {HTMLCanvasElement|OffscreenCanvas} canvas
179
179
  * @param {string} [filename]
180
180
  * @param {string} [type]
@@ -195,7 +195,7 @@ function debugSaveCanvas(canvas, filename='screenshot', type='image/png')
195
195
  debugSaveDataURL(canvas.toDataURL(type), filename);
196
196
  }
197
197
 
198
- /** Save a text file to disk
198
+ /** Save a text file to disk
199
199
  * @param {string} text
200
200
  * @param {string} [filename]
201
201
  * @param {string} [type]
@@ -203,7 +203,7 @@ function debugSaveCanvas(canvas, filename='screenshot', type='image/png')
203
203
  function debugSaveText(text, filename='text', type='text/plain')
204
204
  { debugSaveDataURL(URL.createObjectURL(new Blob([text], {'type':type})), filename); }
205
205
 
206
- /** Save a data url to disk
206
+ /** Save a data url to disk
207
207
  * @param {string} dataURL
208
208
  * @param {string} filename
209
209
  * @memberof Debug */
@@ -322,7 +322,7 @@ function debugRender()
322
322
  {
323
323
  const saveContext = mainContext;
324
324
  mainContext = overlayContext;
325
-
325
+
326
326
  // draw red rectangle around screen
327
327
  const cameraSize = getCameraSize();
328
328
  debugRect(cameraPos, cameraSize.subtract(vec2(.1)), '#f008');
@@ -372,14 +372,14 @@ function debugRender()
372
372
  overlayContext.scale(1, p.text ? 1 : -1);
373
373
  overlayContext.fillStyle = overlayContext.strokeStyle = p.color;
374
374
 
375
- if (p.text != undefined)
375
+ if (p.text !== undefined)
376
376
  {
377
377
  overlayContext.font = p.size*cameraScale + 'px '+ p.font;
378
378
  overlayContext.textAlign = 'center';
379
379
  overlayContext.textBaseline = 'middle';
380
380
  overlayContext.fillText(p.text, 0, 0);
381
381
  }
382
- else if (p.points != undefined)
382
+ else if (p.points !== undefined)
383
383
  {
384
384
  // poly
385
385
  overlayContext.beginPath();
@@ -392,13 +392,13 @@ function debugRender()
392
392
  p.fill && overlayContext.fill();
393
393
  overlayContext.stroke();
394
394
  }
395
- else if (p.size == 0 || p.size.x === 0 && p.size.y === 0)
395
+ else if (p.size === 0 || p.size.x === 0 && p.size.y === 0)
396
396
  {
397
397
  // point
398
398
  overlayContext.fillRect(-pointSize/2, -1, pointSize, 3);
399
399
  overlayContext.fillRect(-1, -pointSize/2, 3, pointSize);
400
400
  }
401
- else if (p.size.x != undefined)
401
+ else if (p.size.x !== undefined)
402
402
  {
403
403
  // rect
404
404
  const s = p.size.scale(cameraScale).floor();
@@ -414,14 +414,14 @@ function debugRender()
414
414
  p.fill && overlayContext.fill();
415
415
  overlayContext.stroke();
416
416
  }
417
-
417
+
418
418
  overlayContext.restore();
419
419
  });
420
420
 
421
421
  // remove expired primitives
422
422
  debugPrimitives = debugPrimitives.filter(r=>r.time<0);
423
423
  }
424
-
424
+
425
425
  if (debugObject)
426
426
  {
427
427
  const saveContext = mainContext;
@@ -430,8 +430,8 @@ function debugRender()
430
430
  raycastHitPos && drawRect(raycastHitPos.floor().add(vec2(.5)), vec2(1), rgb(0,1,1,.3));
431
431
  drawLine(mousePos, debugObject.pos, .1, raycastHitPos ? rgb(1,0,0,.5) : rgb(0,1,0,.5));
432
432
 
433
- const debugText = 'mouse pos = ' + mousePos +
434
- '\nmouse collision = ' + tileCollisionGetData(mousePos) +
433
+ const debugText = 'mouse pos = ' + mousePos +
434
+ '\nmouse collision = ' + tileCollisionGetData(mousePos) +
435
435
  '\n\n--- object info ---\n' +
436
436
  debugObject.toString();
437
437
  drawTextScreen(debugText, mousePosScreen, 24, rgb(), .05, undefined, 'center', 'monospace');
@@ -453,7 +453,7 @@ function debugRender()
453
453
  let x = 9, y = 0, h = lineHeight;
454
454
  if (debugOverlay)
455
455
  {
456
- overlayContext.fillText(engineName, x, y += h/2 );
456
+ overlayContext.fillText(`${engineName} v${engineVersion}`, x, y += h/2 );
457
457
  overlayContext.fillText('Time: ' + formatTime(time), x, y += h);
458
458
  overlayContext.fillText('FPS: ' + averageFPS.toFixed(1), x, y += h);
459
459
  overlayContext.fillText('Objects: ' + engineObjects.length, x, y += h);
@@ -474,7 +474,7 @@ function debugRender()
474
474
  overlayContext.fillText('6: Toggle Video Capture', x, y += h);
475
475
 
476
476
  let keysPressed = '';
477
- for(const i in inputData[0])
477
+ for (const i in inputData[0])
478
478
  {
479
479
  if (keyIsDown(i, 0))
480
480
  keysPressed += i + ' ' ;
@@ -483,7 +483,7 @@ function debugRender()
483
483
 
484
484
  let buttonsPressed = '';
485
485
  if (inputData[1])
486
- for(const i in inputData[1])
486
+ for (const i in inputData[1])
487
487
  {
488
488
  if (keyIsDown(i, 1))
489
489
  buttonsPressed += i + ' ' ;
@@ -497,7 +497,7 @@ function debugRender()
497
497
  overlayContext.fillText(debugRaycast ? 'Debug Raycasts' : '', x, y += h);
498
498
  overlayContext.fillText(debugGamepads ? 'Debug Gamepads' : '', x, y += h);
499
499
  }
500
-
500
+
501
501
  overlayContext.restore();
502
502
  }
503
503
  }
@@ -585,7 +585,7 @@ function debugVideoCaptureUpdate()
585
585
  {
586
586
  if (!debugVideoCaptureIsActive())
587
587
  return; // not recording
588
-
588
+
589
589
  // save the video frame
590
590
  combineCanvases();
591
591
  debugVideoCaptureTrack.requestFrame();