littlejsengine 1.16.1 → 1.17.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 (52) hide show
  1. package/dist/littlejs.d.ts +287 -240
  2. package/dist/littlejs.esm.js +1419 -1259
  3. package/dist/littlejs.esm.min.js +1 -1
  4. package/dist/littlejs.js +1076 -910
  5. package/dist/littlejs.min.js +1 -1
  6. package/dist/littlejs.release.js +977 -815
  7. package/examples/box2d/gameObjects.js +6 -6
  8. package/examples/breakout/game.js +5 -6
  9. package/examples/electron/index.html +2 -2
  10. package/examples/electron/tiles.png +0 -0
  11. package/examples/htmlMenu/tiles.png +0 -0
  12. package/examples/index.html +1 -1
  13. package/examples/logo.png +0 -0
  14. package/examples/logo2.png +0 -0
  15. package/examples/module/tiles.png +0 -0
  16. package/examples/platformer/gameEffects.js +24 -23
  17. package/examples/platformer/gameLevel.js +24 -25
  18. package/examples/shorts/base.html +2 -1
  19. package/examples/shorts/clock.js +3 -3
  20. package/examples/shorts/fontImage.js +4 -3
  21. package/examples/shorts/parallax.js +1 -1
  22. package/examples/shorts/sequencer.js +1 -1
  23. package/examples/shorts/shapes.js +1 -1
  24. package/examples/shorts/texture.js +10 -6
  25. package/examples/shorts/tiles.png +0 -0
  26. package/examples/shorts/tiltedView.js +2 -0
  27. package/examples/starter/index.html +3 -2
  28. package/examples/starter/tiles.png +0 -0
  29. package/examples/typescript/tiles.png +0 -0
  30. package/examples/uiSystem/game.js +1 -1
  31. package/examples/uiSystem/tiles.png +0 -0
  32. package/package.json +1 -1
  33. package/plugins/postProcess.js +47 -28
  34. package/plugins/uiSystem.js +16 -16
  35. package/reference.md +6 -6
  36. package/src/engine.js +186 -198
  37. package/src/engineAudio.js +6 -10
  38. package/src/engineBuild.js +1 -0
  39. package/src/engineDebug.js +100 -98
  40. package/src/engineDraw.js +185 -148
  41. package/src/engineExport.js +327 -333
  42. package/src/engineFont.png +0 -0
  43. package/src/engineInput.js +17 -26
  44. package/src/engineMath.js +1112 -0
  45. package/src/engineMedals.js +4 -4
  46. package/src/engineObject.js +27 -27
  47. package/src/engineParticles.js +2 -2
  48. package/src/engineRelease.js +1 -3
  49. package/src/engineSettings.js +2 -2
  50. package/src/engineTileLayer.js +200 -176
  51. package/src/engineUtilities.js +48 -1097
  52. package/src/engineWebGL.js +127 -79
@@ -55,6 +55,10 @@ let inputPreventDefault = true;
55
55
  * @memberof Input */
56
56
  let gamepadPrimary = 0;
57
57
 
58
+ /** True if a touch device has been detected
59
+ * @memberof Input */
60
+ const isTouchDevice = !headlessMode && window.ontouchstart !== undefined;
61
+
58
62
  /** Prevents input continuing to the default browser handling
59
63
  * This is useful to disable for html menus so the browser can handle input normally
60
64
  * @param {boolean} preventDefault
@@ -253,10 +257,6 @@ function gamepadStickCount(gamepad=gamepadPrimary)
253
257
  return gamepadStickData[gamepad]?.length ?? 0;
254
258
  }
255
259
 
256
- /** True if a touch device has been detected
257
- * @memberof Input */
258
- const isTouchDevice = !headlessMode && window.ontouchstart !== undefined;
259
-
260
260
  ///////////////////////////////////////////////////////////////////////////////
261
261
 
262
262
  /** Pulse the vibration hardware if it exists
@@ -265,7 +265,7 @@ const isTouchDevice = !headlessMode && window.ontouchstart !== undefined;
265
265
  function vibrate(pattern=100)
266
266
  {
267
267
  ASSERT(isNumber(pattern) || isArray(pattern), 'pattern must be a number or array');
268
- vibrateEnable && !headlessMode && navigator && navigator.vibrate && navigator.vibrate(pattern);
268
+ vibrateEnable && !headlessMode && navigator?.vibrate?.(pattern);
269
269
  }
270
270
 
271
271
  /** Cancel any ongoing vibration
@@ -365,8 +365,7 @@ function inputInit()
365
365
  }
366
366
  function onMouseDown(e)
367
367
  {
368
- if (isTouchDevice && touchInputEnable)
369
- return;
368
+ if (isTouchDevice && touchInputEnable) return;
370
369
 
371
370
  // fix stalled audio requiring user interaction
372
371
  if (soundEnable && !headlessMode && audioContext && !audioIsRunning())
@@ -384,8 +383,8 @@ function inputInit()
384
383
  }
385
384
  function onMouseUp(e)
386
385
  {
387
- if (isTouchDevice && touchInputEnable)
388
- return;
386
+ if (isTouchDevice && touchInputEnable) return;
387
+
389
388
  inputData[0][e.button] = (inputData[0][e.button]&2) | 4;
390
389
  }
391
390
  function onMouseMove(e)
@@ -417,8 +416,7 @@ function inputInit()
417
416
  let wasTouching;
418
417
  function handleTouch(e)
419
418
  {
420
- if (!touchInputEnable)
421
- return;
419
+ if (!touchInputEnable) return;
422
420
 
423
421
  // route touch to gamepad
424
422
  if (touchGamepadEnable)
@@ -482,8 +480,7 @@ function inputInit()
482
480
  }
483
481
 
484
482
  // don't process touch gamepad if paused
485
- if (paused)
486
- return;
483
+ if (paused) return;
487
484
 
488
485
  // get center of left and right sides
489
486
  const stickCenter = vec2(touchGamepadSize, mainCanvasSize.y-touchGamepadSize);
@@ -573,8 +570,7 @@ function inputUpdate()
573
570
  // update touch gamepad if enabled
574
571
  if (touchGamepadEnable && isTouchDevice)
575
572
  {
576
- if (!touchGamepadTimer.isSet())
577
- return;
573
+ if (!touchGamepadTimer.isSet()) return;
578
574
 
579
575
  // read virtual analog stick
580
576
  gamepadPrimary = 0; // touch gamepad uses index 0
@@ -612,12 +608,10 @@ function inputUpdate()
612
608
  }
613
609
 
614
610
  // return if gamepads are disabled or not supported
615
- if (!gamepadsEnable || !navigator || !navigator.getGamepads)
616
- return;
611
+ if (!gamepadsEnable || !navigator || !navigator.getGamepads) return;
617
612
 
618
613
  // only poll gamepads when focused or in debug mode
619
- if (!debug && !document.hasFocus())
620
- return;
614
+ if (!debug && !document.hasFocus()) return;
621
615
 
622
616
  // poll gamepads
623
617
  const maxGamepads = 8;
@@ -654,8 +648,7 @@ function inputUpdate()
654
648
  data[j] = button.pressed ? wasDown ? 1 : 3 : wasDown ? 4 : 0;
655
649
 
656
650
  // check for any input on this gamepad, analog must be full press
657
- if (button.pressed)
658
- if (!button.value || button.value > .9)
651
+ if (button.pressed && (!button.value || button.value > .9))
659
652
  hadInput = true;
660
653
  }
661
654
 
@@ -684,7 +677,7 @@ function inputUpdate()
684
677
  }
685
678
 
686
679
  // copy dpad to left analog stick when pressed
687
- if (gamepadDirectionEmulateStick && !dpad.isZero())
680
+ if (gamepadDirectionEmulateStick && (dpad.x || dpad.y))
688
681
  sticks[0] = dpad.clampLength();
689
682
  }
690
683
 
@@ -713,13 +706,11 @@ function inputRender()
713
706
  function touchGamepadRender()
714
707
  {
715
708
  if (!touchInputEnable || !isTouchDevice || headlessMode) return;
716
- if (!touchGamepadEnable || !touchGamepadTimer.isSet())
717
- return;
709
+ if (!touchGamepadEnable || !touchGamepadTimer.isSet()) return;
718
710
 
719
711
  // fade off when not touching or paused
720
712
  const alpha = percent(touchGamepadTimer.get(), 4, 3);
721
- if (!alpha || paused)
722
- return;
713
+ if (!alpha || paused) return;
723
714
 
724
715
  // setup the canvas
725
716
  const context = mainContext;