littlejsengine 1.3.0 → 1.3.3

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 (88) hide show
  1. package/README.md +4 -3
  2. package/build.bat +1 -1
  3. package/docs/Audio.html +2268 -0
  4. package/docs/Color.html +3376 -0
  5. package/docs/Debug.html +2933 -0
  6. package/docs/Draw.html +4480 -0
  7. package/docs/EngineObject.html +4734 -0
  8. package/docs/FontImage.html +1055 -0
  9. package/docs/Input.html +2806 -0
  10. package/docs/Medal.html +1007 -0
  11. package/docs/Medals.html +628 -0
  12. package/docs/Music.html +584 -0
  13. package/docs/Newgrounds.html +1399 -0
  14. package/docs/Particle.html +4825 -0
  15. package/docs/ParticleEmitter.html +8099 -0
  16. package/docs/Random.html +1774 -0
  17. package/docs/Settings.html +3140 -0
  18. package/docs/Sound.html +1249 -0
  19. package/docs/TileCollision.html +1409 -0
  20. package/docs/TileLayer.html +7310 -0
  21. package/docs/TileLayerData.html +1052 -0
  22. package/docs/Timer.html +1295 -0
  23. package/docs/Utilities.html +3278 -0
  24. package/docs/Vector2.html +4266 -0
  25. package/docs/WebGL.html +2307 -0
  26. package/docs/engine.js.html +443 -0
  27. package/docs/engineAudio.js.html +627 -0
  28. package/docs/engineDebug.js.html +554 -0
  29. package/docs/engineDraw.js.html +539 -0
  30. package/docs/engineInput.js.html +571 -0
  31. package/docs/engineMedals.js.html +460 -0
  32. package/docs/engineObject.js.html +533 -0
  33. package/docs/engineParticles.js.html +443 -0
  34. package/docs/engineSettings.js.html +381 -0
  35. package/docs/engineTileLayer.js.html +503 -0
  36. package/docs/engineUtilities.js.html +700 -0
  37. package/docs/engineWebGL.js.html +511 -0
  38. package/docs/fonts/MavenPro-Regular.ttf +0 -0
  39. package/docs/fonts/Montserrat-Regular.ttf +0 -0
  40. package/docs/fonts/Muli-Black.ttf +0 -0
  41. package/docs/fonts/OFL-hind.txt +93 -0
  42. package/docs/fonts/OFL-montserrat.txt +93 -0
  43. package/docs/global.html +1771 -0
  44. package/docs/index.css +6 -0
  45. package/docs/index.html +267 -0
  46. package/docs/scripts/fix-code-block.js +53 -0
  47. package/docs/scripts/fix-navbar.js +25 -0
  48. package/docs/scripts/linenumber.js +25 -0
  49. package/docs/scripts/misc.js +217 -0
  50. package/docs/scripts/resize.js +85 -0
  51. package/docs/scripts/search.js +83 -0
  52. package/docs/scripts/third-party/Apache-License-2.0.txt +202 -0
  53. package/docs/scripts/third-party/fuse.js +9 -0
  54. package/docs/scripts/third-party/lang-css.js +2 -0
  55. package/docs/scripts/third-party/prettify.js +28 -0
  56. package/docs/static/favicon.png +0 -0
  57. package/docs/static/index.css +4 -0
  58. package/docs/styles/clean-jsdoc-theme-base.css +393 -0
  59. package/docs/styles/clean-jsdoc-theme-dark.css +324 -0
  60. package/docs/styles/clean-jsdoc-theme-light.css +319 -0
  61. package/docs/styles/reset.css +346 -0
  62. package/docs/styles/third-party/ionicons.min.css +11 -0
  63. package/docs/styles/third-party/prettify-jsdoc.css +111 -0
  64. package/docs/styles/third-party/prettify-tomorrow.css +5 -0
  65. package/engine/engine.all.js +72 -33
  66. package/engine/engine.all.min.js +1 -1
  67. package/engine/engine.all.release.js +72 -33
  68. package/engine/engine.js +1 -1
  69. package/engine/engineAudio.js +5 -7
  70. package/engine/engineBuild.bat +0 -1
  71. package/engine/engineDraw.js +4 -3
  72. package/engine/engineInput.js +5 -1
  73. package/engine/engineMedals.js +1 -1
  74. package/engine/engineObject.js +19 -16
  75. package/engine/engineParticles.js +1 -1
  76. package/engine/engineSettings.js +5 -0
  77. package/engine/engineUtilities.js +30 -2
  78. package/engine/engineWebGL.js +1 -1
  79. package/engine/index.d.ts +15 -5
  80. package/examples/breakout/index.html +3 -3
  81. package/examples/particles/index.html +62 -62
  82. package/examples/platformer/index.html +5 -5
  83. package/examples/puzzle/game.js +3 -1
  84. package/examples/puzzle/index.html +2 -2
  85. package/examples/stress/index.html +1 -1
  86. package/game.js +3 -14
  87. package/index.html +13 -13
  88. package/package.json +1 -1
@@ -333,7 +333,7 @@ class Vector2
333
333
 
334
334
  /** Returns the area this vector covers as a rectangle
335
335
  * @return {Number} */
336
- area() { return this.x * this.y; }
336
+ area() { return abs(this.x * this.y); }
337
337
 
338
338
  /** Returns a new vector that is p percent between this and the vector passed in
339
339
  * @param {Vector2} vector
@@ -481,6 +481,34 @@ class Color
481
481
  return '#' + toHex(this.r) + toHex(this.g) + toHex(this.b);
482
482
  }
483
483
 
484
+ /** Returns this color expressed in hsla format
485
+ * @return {Array} */
486
+ getHSLA()
487
+ {
488
+ const r = this.r;
489
+ const g = this.g;
490
+ const b = this.b;
491
+ const a = this.a;
492
+ const max = Math.max(r, g, b);
493
+ const min = Math.min(r, g, b);
494
+ const l = (max + min) / 2;
495
+
496
+ let h = 0, s = 0;
497
+ if (max != min)
498
+ {
499
+ let d = max - min;
500
+ s = l > .5 ? d / (2 - max - min) : d / (max + min);
501
+ if (r == max)
502
+ h = (g - b) / d + (g < b ? 6 : 0);
503
+ else if (g == max)
504
+ h = (b - r) / d + 2;
505
+ else if (b == max)
506
+ h = (r - g) / d + 4;
507
+ }
508
+
509
+ return [h / 6, s, l, a];
510
+ }
511
+
484
512
  /** Set this color from a hex code
485
513
  * @param {String} hex - html hex code
486
514
  * @return {Color} */
@@ -542,7 +570,7 @@ class Timer
542
570
 
543
571
  /** Returns this timer expressed as a string
544
572
  * @return {String} */
545
- toString() { return this.unset() ? 'unset' : Math.abs(this.get()) + ' seconds ' + (this.get()<0 ? 'before' : 'after' ); }
573
+ toString() { if (debug) { return this.unset() ? 'unset' : Math.abs(this.get()) + ' seconds ' + (this.get()<0 ? 'before' : 'after' ); } }
546
574
  }
547
575
  /**
548
576
  * LittleJS Engine Settings
@@ -599,6 +627,11 @@ let tileFixBleedScale = .3;
599
627
  * @memberof Settings */
600
628
  let objectDefaultSize = vec2(1);
601
629
 
630
+ /** Enable physics solver for collisions between objects
631
+ * @default
632
+ * @memberof Settings */
633
+ let enablePhysicsSolver = 1;
634
+
602
635
  /** Default object mass for collison calcuations (how heavy objects are)
603
636
  * @default
604
637
  * @memberof Settings */
@@ -785,7 +818,7 @@ let medalDisplayIconSize = 50;
785
818
  const engineName = 'LittleJS';
786
819
 
787
820
  /** Version of engine */
788
- const engineVersion = '1.3.0';
821
+ const engineVersion = '1.3.3';
789
822
 
790
823
  /** Frames per second to update objects
791
824
  * @default */
@@ -1081,7 +1114,7 @@ class EngineObject
1081
1114
  /** Create an engine object and adds it to the list of objects
1082
1115
  * @param {Vector2} [position=new Vector2()] - World space position of the object
1083
1116
  * @param {Vector2} [size=objectDefaultSize] - World space size of the object
1084
- * @param {Number} [tileIndex=-1] - Tile to use to render object, untextured if -1
1117
+ * @param {Number} [tileIndex=-1] - Tile to use to render object (-1 is untextured)
1085
1118
  * @param {Vector2} [tileSize=tileSizeDefault] - Size of tile in source pixels
1086
1119
  * @param {Number} [angle=0] - Angle the object is rotated by
1087
1120
  * @param {Color} [color] - Color to apply to tile when rendered
@@ -1098,7 +1131,7 @@ class EngineObject
1098
1131
  this.size = size;
1099
1132
  /** @property {Vector2} - Size of object used for drawing, uses size if not set */
1100
1133
  this.drawSize;
1101
- /** @property {Number} - Tile to use to render object, untextured if -1 */
1134
+ /** @property {Number} - Tile to use to render object (-1 is untextured) */
1102
1135
  this.tileIndex = tileIndex;
1103
1136
  /** @property {Vector2} - Size of tile in source pixels */
1104
1137
  this.tileSize = tileSize;
@@ -1110,7 +1143,7 @@ class EngineObject
1110
1143
  this.additiveColor;
1111
1144
 
1112
1145
  // set object defaults
1113
- /** @property {Number} [mass=objectDefaultMass] - How heavy the object is */
1146
+ /** @property {Number} [mass=objectDefaultMass] - How heavy the object is, static if 0 */
1114
1147
  this.mass = objectDefaultMass;
1115
1148
  /** @property {Number} [damping=objectDefaultDamping] - How much to slow down velocity each frame (0-1) */
1116
1149
  this.damping = objectDefaultDamping;
@@ -1164,7 +1197,7 @@ class EngineObject
1164
1197
  ASSERT(this.angleDamping >= 0 && this.angleDamping <= 1);
1165
1198
  ASSERT(this.damping >= 0 && this.damping <= 1);
1166
1199
 
1167
- if (!this.mass) // do not update collision for fixed objects
1200
+ if (!enablePhysicsSolver || !this.mass) // do not update collision for fixed objects
1168
1201
  return;
1169
1202
 
1170
1203
  const wasMovingDown = this.velocity.y < 0;
@@ -1402,18 +1435,21 @@ class EngineObject
1402
1435
 
1403
1436
  toString()
1404
1437
  {
1405
- let text = 'type = ' + this.constructor.name;
1406
- if (this.pos.x || this.pos.y)
1407
- text += '\npos = ' + this.pos;
1408
- if (this.velocity.x || this.velocity.y)
1409
- text += '\nvelocity = ' + this.velocity;
1410
- if (this.size.x || this.size.y)
1411
- text += '\nsize = ' + this.size;
1412
- if (this.angle)
1413
- text += '\nangle = ' + this.angle.toFixed(3);
1414
- if (this.color)
1415
- text += '\ncolor = ' + this.color;
1416
- return text;
1438
+ if (debug)
1439
+ {
1440
+ let text = 'type = ' + this.constructor.name;
1441
+ if (this.pos.x || this.pos.y)
1442
+ text += '\npos = ' + this.pos;
1443
+ if (this.velocity.x || this.velocity.y)
1444
+ text += '\nvelocity = ' + this.velocity;
1445
+ if (this.size.x || this.size.y)
1446
+ text += '\nsize = ' + this.size;
1447
+ if (this.angle)
1448
+ text += '\nangle = ' + this.angle.toFixed(3);
1449
+ if (this.color)
1450
+ text += '\ncolor = ' + this.color;
1451
+ return text;
1452
+ }
1417
1453
  }
1418
1454
  }
1419
1455
  /**
@@ -1583,7 +1619,7 @@ function drawTileScreenSpace(pos, size=vec2(1), tileIndex, tileSize, color, angl
1583
1619
  * @memberof Draw */
1584
1620
  function drawRectScreenSpace(pos, size, color, angle, useWebGL)
1585
1621
  {
1586
- drawTileSrceenSpace(pos, size, -1, tileSizeDefault, color, angle, 0, 0, useWebGL);
1622
+ drawTileScreenSpace(pos, size, -1, tileSizeDefault, color, angle, 0, 0, useWebGL);
1587
1623
  }
1588
1624
 
1589
1625
  /** Draw colored line between two points
@@ -1646,11 +1682,12 @@ function setBlendMode(additive, useWebGL=glEnable)
1646
1682
  function drawTextScreen(text, pos, size=1, color=new Color, lineWidth=0, lineColor=new Color(0,0,0), textAlign='center', font=fontDefault)
1647
1683
  {
1648
1684
  overlayContext.fillStyle = color;
1649
- overlayContext.lineWidth = lineWidth *= cameraScale;
1685
+ overlayContext.lineWidth = lineWidth;
1650
1686
  overlayContext.strokeStyle = lineColor;
1651
1687
  overlayContext.textAlign = textAlign;
1652
1688
  overlayContext.font = size + 'px '+ font;
1653
1689
  overlayContext.textBaseline = 'middle';
1690
+ overlayContext.lineJoin = 'round';
1654
1691
 
1655
1692
  pos = pos.copy();
1656
1693
  text.split('\n').forEach(line=>
@@ -1673,7 +1710,7 @@ function drawTextScreen(text, pos, size=1, color=new Color, lineWidth=0, lineCol
1673
1710
  * @memberof Draw */
1674
1711
  function drawText(text, pos, size=1, color, lineWidth, lineColor, textAlign, font)
1675
1712
  {
1676
- drawTextScreen(text, worldToScreen(pos), size*cameraScale, color, lineWidth, lineColor, textAlign, font);
1713
+ drawTextScreen(text, worldToScreen(pos), size*cameraScale, color, lineWidth*cameraScale, lineColor, textAlign, font);
1677
1714
  }
1678
1715
 
1679
1716
  ///////////////////////////////////////////////////////////////////////////////
@@ -1867,6 +1904,10 @@ let mouseWheel = 0;
1867
1904
  * @memberof Input */
1868
1905
  let isUsingGamepad = 0;
1869
1906
 
1907
+ /** Prevents input continuing to the default browser handling (false by default)
1908
+ * @memberof Input */
1909
+ let preventDefaultInput = 0;
1910
+
1870
1911
  /** Returns true if gamepad button is down
1871
1912
  * @param {Number} button
1872
1913
  * @param {Number} [gamepad=0]
@@ -1930,7 +1971,7 @@ onkeydown = (e)=>
1930
1971
  {
1931
1972
  if (debug && e.target != document.body) return;
1932
1973
  e.repeat || (inputData[isUsingGamepad = 0][remapKeyCode(e.keyCode)] = 3);
1933
- debug || e.preventDefault();
1974
+ preventDefaultInput && e.preventDefault();
1934
1975
  }
1935
1976
  onkeyup = (e)=>
1936
1977
  {
@@ -2494,8 +2535,7 @@ function zzfxG
2494
2535
  )
2495
2536
  {
2496
2537
  // init parameters
2497
- let PI2 = PI*2, sign = v => v>0?1:-1,
2498
- startSlide = slide *= 500 * PI2 / zzfxR / zzfxR, b=[],
2538
+ let PI2 = PI*2, startSlide = slide *= 500 * PI2 / zzfxR / zzfxR, b=[],
2499
2539
  startFrequency = frequency *= (1 + randomness*rand(-1,1)) * PI2 / zzfxR,
2500
2540
  t=0, tm=0, i=0, j=1, r=0, c=0, s=0, f, length;
2501
2541
 
@@ -2519,15 +2559,15 @@ function zzfxG
2519
2559
  {
2520
2560
  s = shape? shape>1? shape>2? shape>3? // wave shape
2521
2561
  Math.sin((t%PI2)**3) : // 4 noise
2522
- Math.max(Math.min(Math.tan(t),1),-1): // 3 tan
2562
+ max(min(Math.tan(t),1),-1): // 3 tan
2523
2563
  1-(2*t/PI2%2+2)%2: // 2 saw
2524
- 1-4*abs(Math.round(t/PI2)-t/PI2): // 1 triangle
2564
+ 1-4*abs(Math.round(t/PI2)-t/PI2): // 1 triangle
2525
2565
  Math.sin(t); // 0 sin
2526
2566
 
2527
2567
  s = (repeatTime ?
2528
2568
  1 - tremolo + tremolo*Math.sin(PI2*i/repeatTime) // tremolo
2529
2569
  : 1) *
2530
- sign(s)*(abs(s)**shapeCurve) * // curve 0=square, 2=pointy
2570
+ sign(s)*(abs(s)**shapeCurve) * // curve 0=square, 2=pointy
2531
2571
  volume * soundVolume * ( // envelope
2532
2572
  i < attack ? i/attack : // attack
2533
2573
  i < attack + decay ? // decay
@@ -2588,7 +2628,6 @@ function zzfxM(instruments, patterns, sequence, BPM = 125)
2588
2628
  let notFirstBeat;
2589
2629
  let stop;
2590
2630
  let instrument;
2591
- let pitch;
2592
2631
  let attenuation;
2593
2632
  let outSampleOffset;
2594
2633
  let isSequenceEnd;
@@ -2607,7 +2646,7 @@ function zzfxM(instruments, patterns, sequence, BPM = 125)
2607
2646
  for (; hasMore; channelIndex++) {
2608
2647
 
2609
2648
  // reset current values
2610
- sampleBuffer = [hasMore = notFirstBeat = pitch = outSampleOffset = 0];
2649
+ sampleBuffer = [hasMore = notFirstBeat = outSampleOffset = 0];
2611
2650
 
2612
2651
  // for each pattern in sequence
2613
2652
  sequence.forEach((patternIndex, sequenceIndex) => {
@@ -3132,7 +3171,7 @@ class ParticleEmitter extends EngineObject
3132
3171
  // particle settings
3133
3172
  /** @property {Number} - How long particles live */
3134
3173
  this.particleTime = particleTime;
3135
- /** @property {Number} - How big are particles at start */
3174
+ /** @property {Number} - How big are particles at start */
3136
3175
  this.sizeStart = sizeStart;
3137
3176
  /** @property {Number} - How big are particles at end */
3138
3177
  this.sizeEnd = sizeEnd;
@@ -3495,7 +3534,7 @@ class Newgrounds
3495
3534
  cipher && (this.cryptoJS = CryptoJS());
3496
3535
 
3497
3536
  // get session id from url search params
3498
- const url = new URL(window.location.href);
3537
+ const url = new URL(location.href);
3499
3538
  this.session_id = url.searchParams.get('ngio_session_id') || 0;
3500
3539
 
3501
3540
  if (this.session_id == 0)
@@ -3848,7 +3887,7 @@ function glFlush()
3848
3887
  * @memberof WebGL */
3849
3888
  function glCopyToContext(context, forceDraw)
3850
3889
  {
3851
- if (!glEnable || !glBatchCount) return;
3890
+ if ((!glEnable || !glBatchCount) && !forceDraw) return;
3852
3891
 
3853
3892
  glFlush();
3854
3893
 
package/engine/engine.js CHANGED
@@ -22,7 +22,7 @@
22
22
  const engineName = 'LittleJS';
23
23
 
24
24
  /** Version of engine */
25
- const engineVersion = '1.3.0';
25
+ const engineVersion = '1.3.3';
26
26
 
27
27
  /** Frames per second to update objects
28
28
  * @default */
@@ -289,8 +289,7 @@ function zzfxG
289
289
  )
290
290
  {
291
291
  // init parameters
292
- let PI2 = PI*2, sign = v => v>0?1:-1,
293
- startSlide = slide *= 500 * PI2 / zzfxR / zzfxR, b=[],
292
+ let PI2 = PI*2, startSlide = slide *= 500 * PI2 / zzfxR / zzfxR, b=[],
294
293
  startFrequency = frequency *= (1 + randomness*rand(-1,1)) * PI2 / zzfxR,
295
294
  t=0, tm=0, i=0, j=1, r=0, c=0, s=0, f, length;
296
295
 
@@ -314,15 +313,15 @@ function zzfxG
314
313
  {
315
314
  s = shape? shape>1? shape>2? shape>3? // wave shape
316
315
  Math.sin((t%PI2)**3) : // 4 noise
317
- Math.max(Math.min(Math.tan(t),1),-1): // 3 tan
316
+ max(min(Math.tan(t),1),-1): // 3 tan
318
317
  1-(2*t/PI2%2+2)%2: // 2 saw
319
- 1-4*abs(Math.round(t/PI2)-t/PI2): // 1 triangle
318
+ 1-4*abs(Math.round(t/PI2)-t/PI2): // 1 triangle
320
319
  Math.sin(t); // 0 sin
321
320
 
322
321
  s = (repeatTime ?
323
322
  1 - tremolo + tremolo*Math.sin(PI2*i/repeatTime) // tremolo
324
323
  : 1) *
325
- sign(s)*(abs(s)**shapeCurve) * // curve 0=square, 2=pointy
324
+ sign(s)*(abs(s)**shapeCurve) * // curve 0=square, 2=pointy
326
325
  volume * soundVolume * ( // envelope
327
326
  i < attack ? i/attack : // attack
328
327
  i < attack + decay ? // decay
@@ -383,7 +382,6 @@ function zzfxM(instruments, patterns, sequence, BPM = 125)
383
382
  let notFirstBeat;
384
383
  let stop;
385
384
  let instrument;
386
- let pitch;
387
385
  let attenuation;
388
386
  let outSampleOffset;
389
387
  let isSequenceEnd;
@@ -402,7 +400,7 @@ function zzfxM(instruments, patterns, sequence, BPM = 125)
402
400
  for (; hasMore; channelIndex++) {
403
401
 
404
402
  // reset current values
405
- sampleBuffer = [hasMore = notFirstBeat = pitch = outSampleOffset = 0];
403
+ sampleBuffer = [hasMore = notFirstBeat = outSampleOffset = 0];
406
404
 
407
405
  // for each pattern in sequence
408
406
  sequence.forEach((patternIndex, sequenceIndex) => {
@@ -94,7 +94,6 @@ if %ERRORLEVEL% NEQ 0 (
94
94
  )
95
95
 
96
96
  rem --- BUILD TYPESCRIPT DEFINITIONS ---
97
-
98
97
  call npx tsc engine.all.js --declaration --allowJs --emitDeclarationOnly --outFile index.d.ts
99
98
  if %ERRORLEVEL% NEQ 0 (
100
99
  pause
@@ -165,7 +165,7 @@ function drawTileScreenSpace(pos, size=vec2(1), tileIndex, tileSize, color, angl
165
165
  * @memberof Draw */
166
166
  function drawRectScreenSpace(pos, size, color, angle, useWebGL)
167
167
  {
168
- drawTileSrceenSpace(pos, size, -1, tileSizeDefault, color, angle, 0, 0, useWebGL);
168
+ drawTileScreenSpace(pos, size, -1, tileSizeDefault, color, angle, 0, 0, useWebGL);
169
169
  }
170
170
 
171
171
  /** Draw colored line between two points
@@ -228,11 +228,12 @@ function setBlendMode(additive, useWebGL=glEnable)
228
228
  function drawTextScreen(text, pos, size=1, color=new Color, lineWidth=0, lineColor=new Color(0,0,0), textAlign='center', font=fontDefault)
229
229
  {
230
230
  overlayContext.fillStyle = color;
231
- overlayContext.lineWidth = lineWidth *= cameraScale;
231
+ overlayContext.lineWidth = lineWidth;
232
232
  overlayContext.strokeStyle = lineColor;
233
233
  overlayContext.textAlign = textAlign;
234
234
  overlayContext.font = size + 'px '+ font;
235
235
  overlayContext.textBaseline = 'middle';
236
+ overlayContext.lineJoin = 'round';
236
237
 
237
238
  pos = pos.copy();
238
239
  text.split('\n').forEach(line=>
@@ -255,7 +256,7 @@ function drawTextScreen(text, pos, size=1, color=new Color, lineWidth=0, lineCol
255
256
  * @memberof Draw */
256
257
  function drawText(text, pos, size=1, color, lineWidth, lineColor, textAlign, font)
257
258
  {
258
- drawTextScreen(text, worldToScreen(pos), size*cameraScale, color, lineWidth, lineColor, textAlign, font);
259
+ drawTextScreen(text, worldToScreen(pos), size*cameraScale, color, lineWidth*cameraScale, lineColor, textAlign, font);
259
260
  }
260
261
 
261
262
  ///////////////////////////////////////////////////////////////////////////////
@@ -70,6 +70,10 @@ let mouseWheel = 0;
70
70
  * @memberof Input */
71
71
  let isUsingGamepad = 0;
72
72
 
73
+ /** Prevents input continuing to the default browser handling (false by default)
74
+ * @memberof Input */
75
+ let preventDefaultInput = 0;
76
+
73
77
  /** Returns true if gamepad button is down
74
78
  * @param {Number} button
75
79
  * @param {Number} [gamepad=0]
@@ -133,7 +137,7 @@ onkeydown = (e)=>
133
137
  {
134
138
  if (debug && e.target != document.body) return;
135
139
  e.repeat || (inputData[isUsingGamepad = 0][remapKeyCode(e.keyCode)] = 3);
136
- debug || e.preventDefault();
140
+ preventDefaultInput && e.preventDefault();
137
141
  }
138
142
  onkeyup = (e)=>
139
143
  {
@@ -192,7 +192,7 @@ class Newgrounds
192
192
  cipher && (this.cryptoJS = CryptoJS());
193
193
 
194
194
  // get session id from url search params
195
- const url = new URL(window.location.href);
195
+ const url = new URL(location.href);
196
196
  this.session_id = url.searchParams.get('ngio_session_id') || 0;
197
197
 
198
198
  if (this.session_id == 0)
@@ -34,7 +34,7 @@ class EngineObject
34
34
  /** Create an engine object and adds it to the list of objects
35
35
  * @param {Vector2} [position=new Vector2()] - World space position of the object
36
36
  * @param {Vector2} [size=objectDefaultSize] - World space size of the object
37
- * @param {Number} [tileIndex=-1] - Tile to use to render object, untextured if -1
37
+ * @param {Number} [tileIndex=-1] - Tile to use to render object (-1 is untextured)
38
38
  * @param {Vector2} [tileSize=tileSizeDefault] - Size of tile in source pixels
39
39
  * @param {Number} [angle=0] - Angle the object is rotated by
40
40
  * @param {Color} [color] - Color to apply to tile when rendered
@@ -51,7 +51,7 @@ class EngineObject
51
51
  this.size = size;
52
52
  /** @property {Vector2} - Size of object used for drawing, uses size if not set */
53
53
  this.drawSize;
54
- /** @property {Number} - Tile to use to render object, untextured if -1 */
54
+ /** @property {Number} - Tile to use to render object (-1 is untextured) */
55
55
  this.tileIndex = tileIndex;
56
56
  /** @property {Vector2} - Size of tile in source pixels */
57
57
  this.tileSize = tileSize;
@@ -63,7 +63,7 @@ class EngineObject
63
63
  this.additiveColor;
64
64
 
65
65
  // set object defaults
66
- /** @property {Number} [mass=objectDefaultMass] - How heavy the object is */
66
+ /** @property {Number} [mass=objectDefaultMass] - How heavy the object is, static if 0 */
67
67
  this.mass = objectDefaultMass;
68
68
  /** @property {Number} [damping=objectDefaultDamping] - How much to slow down velocity each frame (0-1) */
69
69
  this.damping = objectDefaultDamping;
@@ -117,7 +117,7 @@ class EngineObject
117
117
  ASSERT(this.angleDamping >= 0 && this.angleDamping <= 1);
118
118
  ASSERT(this.damping >= 0 && this.damping <= 1);
119
119
 
120
- if (!this.mass) // do not update collision for fixed objects
120
+ if (!enablePhysicsSolver || !this.mass) // do not update collision for fixed objects
121
121
  return;
122
122
 
123
123
  const wasMovingDown = this.velocity.y < 0;
@@ -355,17 +355,20 @@ class EngineObject
355
355
 
356
356
  toString()
357
357
  {
358
- let text = 'type = ' + this.constructor.name;
359
- if (this.pos.x || this.pos.y)
360
- text += '\npos = ' + this.pos;
361
- if (this.velocity.x || this.velocity.y)
362
- text += '\nvelocity = ' + this.velocity;
363
- if (this.size.x || this.size.y)
364
- text += '\nsize = ' + this.size;
365
- if (this.angle)
366
- text += '\nangle = ' + this.angle.toFixed(3);
367
- if (this.color)
368
- text += '\ncolor = ' + this.color;
369
- return text;
358
+ if (debug)
359
+ {
360
+ let text = 'type = ' + this.constructor.name;
361
+ if (this.pos.x || this.pos.y)
362
+ text += '\npos = ' + this.pos;
363
+ if (this.velocity.x || this.velocity.y)
364
+ text += '\nvelocity = ' + this.velocity;
365
+ if (this.size.x || this.size.y)
366
+ text += '\nsize = ' + this.size;
367
+ if (this.angle)
368
+ text += '\nangle = ' + this.angle.toFixed(3);
369
+ if (this.color)
370
+ text += '\ncolor = ' + this.color;
371
+ return text;
372
+ }
370
373
  }
371
374
  }
@@ -113,7 +113,7 @@ class ParticleEmitter extends EngineObject
113
113
  // particle settings
114
114
  /** @property {Number} - How long particles live */
115
115
  this.particleTime = particleTime;
116
- /** @property {Number} - How big are particles at start */
116
+ /** @property {Number} - How big are particles at start */
117
117
  this.sizeStart = sizeStart;
118
118
  /** @property {Number} - How big are particles at end */
119
119
  this.sizeEnd = sizeEnd;
@@ -53,6 +53,11 @@ let tileFixBleedScale = .3;
53
53
  * @memberof Settings */
54
54
  let objectDefaultSize = vec2(1);
55
55
 
56
+ /** Enable physics solver for collisions between objects
57
+ * @default
58
+ * @memberof Settings */
59
+ let enablePhysicsSolver = 1;
60
+
56
61
  /** Default object mass for collison calcuations (how heavy objects are)
57
62
  * @default
58
63
  * @memberof Settings */
@@ -300,7 +300,7 @@ class Vector2
300
300
 
301
301
  /** Returns the area this vector covers as a rectangle
302
302
  * @return {Number} */
303
- area() { return this.x * this.y; }
303
+ area() { return abs(this.x * this.y); }
304
304
 
305
305
  /** Returns a new vector that is p percent between this and the vector passed in
306
306
  * @param {Vector2} vector
@@ -448,6 +448,34 @@ class Color
448
448
  return '#' + toHex(this.r) + toHex(this.g) + toHex(this.b);
449
449
  }
450
450
 
451
+ /** Returns this color expressed in hsla format
452
+ * @return {Array} */
453
+ getHSLA()
454
+ {
455
+ const r = this.r;
456
+ const g = this.g;
457
+ const b = this.b;
458
+ const a = this.a;
459
+ const max = Math.max(r, g, b);
460
+ const min = Math.min(r, g, b);
461
+ const l = (max + min) / 2;
462
+
463
+ let h = 0, s = 0;
464
+ if (max != min)
465
+ {
466
+ let d = max - min;
467
+ s = l > .5 ? d / (2 - max - min) : d / (max + min);
468
+ if (r == max)
469
+ h = (g - b) / d + (g < b ? 6 : 0);
470
+ else if (g == max)
471
+ h = (b - r) / d + 2;
472
+ else if (b == max)
473
+ h = (r - g) / d + 4;
474
+ }
475
+
476
+ return [h / 6, s, l, a];
477
+ }
478
+
451
479
  /** Set this color from a hex code
452
480
  * @param {String} hex - html hex code
453
481
  * @return {Color} */
@@ -509,5 +537,5 @@ class Timer
509
537
 
510
538
  /** Returns this timer expressed as a string
511
539
  * @return {String} */
512
- toString() { return this.unset() ? 'unset' : Math.abs(this.get()) + ' seconds ' + (this.get()<0 ? 'before' : 'after' ); }
540
+ toString() { if (debug) { return this.unset() ? 'unset' : Math.abs(this.get()) + ' seconds ' + (this.get()<0 ? 'before' : 'after' ); } }
513
541
  }
@@ -244,7 +244,7 @@ function glFlush()
244
244
  * @memberof WebGL */
245
245
  function glCopyToContext(context, forceDraw)
246
246
  {
247
- if (!glEnable || !glBatchCount) return;
247
+ if ((!glEnable || !glBatchCount) && !forceDraw) return;
248
248
 
249
249
  glFlush();
250
250
 
package/engine/index.d.ts CHANGED
@@ -643,6 +643,9 @@ declare class Color {
643
643
  /** Returns this color expressed as a hex code
644
644
  * @return {String} */
645
645
  hex(): string;
646
+ /** Returns this color expressed in hsla format
647
+ * @return {Array} */
648
+ getHSLA(): any[];
646
649
  /** Set this color from a hex code
647
650
  * @param {String} hex - html hex code
648
651
  * @return {Color} */
@@ -719,6 +722,10 @@ declare let tileFixBleedScale: number;
719
722
  * @default
720
723
  * @memberof Settings */
721
724
  declare let objectDefaultSize: Vector2;
725
+ /** Enable physics solver for collisions between objects
726
+ * @default
727
+ * @memberof Settings */
728
+ declare let enablePhysicsSolver: number;
722
729
  /** Default object mass for collison calcuations (how heavy objects are)
723
730
  * @default
724
731
  * @memberof Settings */
@@ -867,7 +874,7 @@ declare class EngineObject {
867
874
  /** Create an engine object and adds it to the list of objects
868
875
  * @param {Vector2} [position=new Vector2()] - World space position of the object
869
876
  * @param {Vector2} [size=objectDefaultSize] - World space size of the object
870
- * @param {Number} [tileIndex=-1] - Tile to use to render object, untextured if -1
877
+ * @param {Number} [tileIndex=-1] - Tile to use to render object (-1 is untextured)
871
878
  * @param {Vector2} [tileSize=tileSizeDefault] - Size of tile in source pixels
872
879
  * @param {Number} [angle=0] - Angle the object is rotated by
873
880
  * @param {Color} [color] - Color to apply to tile when rendered
@@ -878,7 +885,7 @@ declare class EngineObject {
878
885
  pos: Vector2;
879
886
  /** @property {Vector2} - World space width and height of the object */
880
887
  size: Vector2;
881
- /** @property {Number} - Tile to use to render object, untextured if -1 */
888
+ /** @property {Number} - Tile to use to render object (-1 is untextured) */
882
889
  tileIndex: number;
883
890
  /** @property {Vector2} - Size of tile in source pixels */
884
891
  tileSize: Vector2;
@@ -886,7 +893,7 @@ declare class EngineObject {
886
893
  angle: number;
887
894
  /** @property {Color} - Color to apply when rendered */
888
895
  color: Color;
889
- /** @property {Number} [mass=objectDefaultMass] - How heavy the object is */
896
+ /** @property {Number} [mass=objectDefaultMass] - How heavy the object is, static if 0 */
890
897
  mass: number;
891
898
  /** @property {Number} [damping=objectDefaultDamping] - How much to slow down velocity each frame (0-1) */
892
899
  damping: number;
@@ -1092,6 +1099,9 @@ declare let mouseWheel: number;
1092
1099
  /** Returns true if user is using gamepad (has more recently pressed a gamepad button)
1093
1100
  * @memberof Input */
1094
1101
  declare let isUsingGamepad: number;
1102
+ /** Prevents input continuing to the default browser handling (false by default)
1103
+ * @memberof Input */
1104
+ declare let preventDefaultInput: number;
1095
1105
  /** Returns true if gamepad button is down
1096
1106
  * @param {Number} button
1097
1107
  * @param {Number} [gamepad=0]
@@ -1428,7 +1438,7 @@ declare class ParticleEmitter extends EngineObject {
1428
1438
  randomColorLinear: boolean;
1429
1439
  /** @property {Number} - How long particles live */
1430
1440
  particleTime: number;
1431
- /** @property {Number} - How big are particles at start */
1441
+ /** @property {Number} - How big are particles at start */
1432
1442
  sizeStart: number;
1433
1443
  /** @property {Number} - How big are particles at end */
1434
1444
  sizeEnd: number;
@@ -1617,7 +1627,7 @@ declare const gl_VERTEX_BYTE_STRIDE: number;
1617
1627
  /** Name of engine */
1618
1628
  declare const engineName: "LittleJS";
1619
1629
  /** Version of engine */
1620
- declare const engineVersion: "1.3.0";
1630
+ declare const engineVersion: "1.3.3";
1621
1631
  /** Frames per second to update objects
1622
1632
  * @default */
1623
1633
  declare const frameRate: 60;
@@ -5,6 +5,6 @@
5
5
  <link rel=icon type=image/png href=../../favicon.png>
6
6
  </head><body>
7
7
 
8
- <script src=../../engine/engine.all.js?104></script>
9
- <script src=game.js?104></script>
10
- <script src=gameObjects.js?104></script>
8
+ <script src=../../engine/engine.all.js?108></script>
9
+ <script src=game.js?108></script>
10
+ <script src=gameObjects.js?108></script>