littlejsengine 1.8.9 → 1.9.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 (48) hide show
  1. package/README.md +17 -17
  2. package/build/littlejs.d.ts +352 -288
  3. package/build/littlejs.esm.js +695 -658
  4. package/build/littlejs.esm.min.js +1 -1
  5. package/build/littlejs.js +694 -658
  6. package/build/littlejs.min.js +1 -1
  7. package/build/littlejs.release.js +629 -594
  8. package/examples/breakout/game.js +4 -4
  9. package/examples/breakout/index.html +3 -3
  10. package/examples/breakoutTutorial/index.html +2 -2
  11. package/examples/electron/game.js +1 -1
  12. package/examples/electron/index.html +2 -2
  13. package/examples/favicon.png +0 -0
  14. package/examples/js13k/build.js +1 -1
  15. package/examples/js13k/index.html +13 -13
  16. package/examples/module/game.js +1 -1
  17. package/examples/module/index.html +1 -1
  18. package/examples/particles/index.html +1 -1
  19. package/examples/platformer/game.js +6 -6
  20. package/examples/platformer/gameCharacter.js +293 -0
  21. package/examples/platformer/gameEffects.js +8 -5
  22. package/examples/platformer/gameObjects.js +13 -13
  23. package/examples/platformer/gamePlayer.js +9 -293
  24. package/examples/platformer/index.html +7 -6
  25. package/examples/puzzle/game.js +3 -2
  26. package/examples/puzzle/index.html +2 -2
  27. package/examples/starter/build.js +1 -1
  28. package/examples/starter/game.js +2 -2
  29. package/examples/starter/index.html +13 -13
  30. package/examples/stress/index.html +35 -27
  31. package/examples/typescript/index.html +1 -1
  32. package/index.d.ts +2094 -0
  33. package/package.json +1 -1
  34. package/src/engine.js +28 -28
  35. package/src/engineAudio.js +57 -57
  36. package/src/engineDebug.js +66 -65
  37. package/src/engineDraw.js +64 -73
  38. package/src/engineExport.js +1 -0
  39. package/src/engineInput.js +57 -40
  40. package/src/engineMedals.js +32 -29
  41. package/src/engineObject.js +42 -27
  42. package/src/engineParticles.js +98 -72
  43. package/src/engineRelease.js +1 -1
  44. package/src/engineSettings.js +22 -22
  45. package/src/engineTileLayer.js +66 -60
  46. package/src/engineUtilities.js +49 -49
  47. package/src/engineWebGL.js +112 -135
  48. package/src/jsconfig.json +10 -0
@@ -44,15 +44,15 @@ function sign(value) { return Math.sign(value); }
44
44
 
45
45
  /** Returns first parm modulo the second param, but adjusted so negative numbers work as expected
46
46
  * @param {Number} dividend
47
- * @param {Number} [divisor=1]
47
+ * @param {Number} [divisor]
48
48
  * @return {Number}
49
49
  * @memberof Utilities */
50
50
  function mod(dividend, divisor=1) { return ((dividend % divisor) + divisor) % divisor; }
51
51
 
52
52
  /** Clamps the value beween max and min
53
53
  * @param {Number} value
54
- * @param {Number} [min=0]
55
- * @param {Number} [max=1]
54
+ * @param {Number} [min]
55
+ * @param {Number} [max]
56
56
  * @return {Number}
57
57
  * @memberof Utilities */
58
58
  function clamp(value, min=0, max=1) { return value < min ? min : value > max ? max : value; }
@@ -77,7 +77,7 @@ function lerp(percent, valueA, valueB) { return valueA + clamp(percent) * (value
77
77
  /** Returns signed wrapped distance between the two values passed in
78
78
  * @param {Number} valueA
79
79
  * @param {Number} valueB
80
- * @param {Number} [wrapSize=1]
80
+ * @param {Number} [wrapSize]
81
81
  * @returns {Number}
82
82
  * @memberof Utilities */
83
83
  function distanceWrap(valueA, valueB, wrapSize=1)
@@ -87,7 +87,7 @@ function distanceWrap(valueA, valueB, wrapSize=1)
87
87
  * @param {Number} percent
88
88
  * @param {Number} valueA
89
89
  * @param {Number} valueB
90
- * @param {Number} [wrapSize=1]
90
+ * @param {Number} [wrapSize]
91
91
  * @returns {Number}
92
92
  * @memberof Utilities */
93
93
  function lerpWrap(percent, valueA, valueB, wrapSize=1)
@@ -98,7 +98,7 @@ function lerpWrap(percent, valueA, valueB, wrapSize=1)
98
98
  * @param {Number} angleB
99
99
  * @returns {Number}
100
100
  * @memberof Utilities */
101
- function distanceAngle(angleA, angleB) { distanceWrap(angleA, angleB, 2*PI); }
101
+ function distanceAngle(angleA, angleB) { return distanceWrap(angleA, angleB, 2*PI); }
102
102
 
103
103
  /** Linearly interpolates between the angles passed in with wrappping
104
104
  * @param {Number} percent
@@ -121,11 +121,11 @@ function smoothStep(percent) { return percent * percent * (3 - 2 * percent); }
121
121
  function nearestPowerOfTwo(value) { return 2**Math.ceil(Math.log2(value)); }
122
122
 
123
123
  /** Returns true if two axis aligned bounding boxes are overlapping
124
- * @param {Vector2} pointA - Center of box A
125
- * @param {Vector2} sizeA - Size of box A
126
- * @param {Vector2} pointB - Center of box B
127
- * @param {Vector2} sizeB - Size of box B
128
- * @return {Boolean} - True if overlapping
124
+ * @param {Vector2} pointA - Center of box A
125
+ * @param {Vector2} sizeA - Size of box A
126
+ * @param {Vector2} pointB - Center of box B
127
+ * @param {Vector2} sizeB - Size of box B
128
+ * @return {Boolean} - True if overlapping
129
129
  * @memberof Utilities */
130
130
  function isOverlapping(pointA, sizeA, pointB, sizeB)
131
131
  {
@@ -134,10 +134,10 @@ function isOverlapping(pointA, sizeA, pointB, sizeB)
134
134
  }
135
135
 
136
136
  /** Returns an oscillating wave between 0 and amplitude with frequency of 1 Hz by default
137
- * @param {Number} [frequency=1] - Frequency of the wave in Hz
138
- * @param {Number} [amplitude=1] - Amplitude (max height) of the wave
139
- * @param {Number} [t=time] - Value to use for time of the wave
140
- * @return {Number} - Value waving between 0 and amplitude
137
+ * @param {Number} [frequency] - Frequency of the wave in Hz
138
+ * @param {Number} [amplitude] - Amplitude (max height) of the wave
139
+ * @param {Number} [t=time] - Value to use for time of the wave
140
+ * @return {Number} - Value waving between 0 and amplitude
141
141
  * @memberof Utilities */
142
142
  function wave(frequency=1, amplitude=1, t=time)
143
143
  { return amplitude/2 * (1 - Math.cos(t*frequency*2*PI)); }
@@ -154,15 +154,15 @@ function formatTime(t) { return (t/60|0) + ':' + (t%60<10?'0':'') + (t%60|0); }
154
154
  * @namespace Random */
155
155
 
156
156
  /** Returns a random value between the two values passed in
157
- * @param {Number} [valueA=1]
158
- * @param {Number} [valueB=0]
157
+ * @param {Number} [valueA]
158
+ * @param {Number} [valueB]
159
159
  * @return {Number}
160
160
  * @memberof Random */
161
161
  function rand(valueA=1, valueB=0) { return valueB + Math.random() * (valueA-valueB); }
162
162
 
163
163
  /** Returns a floored random value the two values passed in
164
164
  * @param {Number} valueA
165
- * @param {Number} [valueB=0]
165
+ * @param {Number} [valueB]
166
166
  * @return {Number}
167
167
  * @memberof Random */
168
168
  function randInt(valueA, valueB=0) { return Math.floor(rand(valueA,valueB)); }
@@ -173,14 +173,14 @@ function randInt(valueA, valueB=0) { return Math.floor(rand(valueA,valueB)); }
173
173
  function randSign() { return randInt(2) * 2 - 1; }
174
174
 
175
175
  /** Returns a random Vector2 with the passed in length
176
- * @param {Number} [length=1]
176
+ * @param {Number} [length]
177
177
  * @return {Vector2}
178
178
  * @memberof Random */
179
179
  function randVector(length=1) { return new Vector2().setAngle(rand(2*PI), length); }
180
180
 
181
181
  /** Returns a random Vector2 within a circular shape
182
- * @param {Number} [radius=1]
183
- * @param {Number} [minRadius=0]
182
+ * @param {Number} [radius]
183
+ * @param {Number} [minRadius]
184
184
  * @return {Vector2}
185
185
  * @memberof Random */
186
186
  function randInCircle(radius=1, minRadius=0)
@@ -192,7 +192,7 @@ function randInCircle(radius=1, minRadius=0)
192
192
  * @param {Boolean} [linear]
193
193
  * @return {Color}
194
194
  * @memberof Random */
195
- function randColor(colorA=new Color, colorB=new Color(0,0,0,1), linear)
195
+ function randColor(colorA=new Color, colorB=new Color(0,0,0,1), linear=false)
196
196
  {
197
197
  return linear ? colorA.lerp(colorB, rand()) :
198
198
  new Color(rand(colorA.r,colorB.r), rand(colorA.g,colorB.g), rand(colorA.b,colorB.b), rand(colorA.a,colorB.a));
@@ -221,8 +221,8 @@ class RandomGenerator
221
221
  }
222
222
 
223
223
  /** Returns a seeded random value between the two values passed in
224
- * @param {Number} [valueA=1]
225
- * @param {Number} [valueB=0]
224
+ * @param {Number} [valueA]
225
+ * @param {Number} [valueB]
226
226
  * @return {Number} */
227
227
  float(valueA=1, valueB=0)
228
228
  {
@@ -235,7 +235,7 @@ class RandomGenerator
235
235
 
236
236
  /** Returns a floored seeded random value the two values passed in
237
237
  * @param {Number} valueA
238
- * @param {Number} [valueB=0]
238
+ * @param {Number} [valueB]
239
239
  * @return {Number} */
240
240
  int(valueA, valueB=0) { return Math.floor(this.float(valueA, valueB)); }
241
241
 
@@ -248,8 +248,8 @@ class RandomGenerator
248
248
 
249
249
  /**
250
250
  * Create a 2d vector, can take another Vector2 to copy, 2 scalars, or 1 scalar
251
- * @param {(Number|Vector2)} [x=0]
252
- * @param {Number} [y=0]
251
+ * @param {(Number|Vector2)} [x]
252
+ * @param {Number} [y]
253
253
  * @return {Vector2}
254
254
  * @example
255
255
  * let a = vec2(0, 1); // vector with coordinates (0, 1)
@@ -259,15 +259,15 @@ class RandomGenerator
259
259
  * @memberof Utilities
260
260
  */
261
261
  function vec2(x=0, y)
262
- { return x.x == undefined ? new Vector2(x, y == undefined? x : y) : new Vector2(x.x, x.y); }
262
+ { return typeof x === 'number'? new Vector2(x, y == undefined? x : y) : new Vector2(x.x, x.y); }
263
263
 
264
264
  /**
265
265
  * Check if object is a valid Vector2
266
- * @param {Vector2} v
266
+ * @param {any} v
267
267
  * @return {Boolean}
268
268
  * @memberof Utilities
269
269
  */
270
- function isVector2(v) { return !isNaN(v.x) && !isNaN(v.y); }
270
+ function isVector2(v) { return typeof v === 'object' && typeof v.x === 'number' && typeof v.y === 'number'; }
271
271
 
272
272
  /**
273
273
  * 2D Vector object with vector math library
@@ -281,8 +281,8 @@ function isVector2(v) { return !isNaN(v.x) && !isNaN(v.y); }
281
281
  class Vector2
282
282
  {
283
283
  /** Create a 2D vector with the x and y passed in, can also be created with vec2()
284
- * @param {Number} [x=0] - X axis location
285
- * @param {Number} [y=0] - Y axis location */
284
+ * @param {Number} [x] - X axis location
285
+ * @param {Number} [y] - Y axis location */
286
286
  constructor(x=0, y=0)
287
287
  {
288
288
  /** @property {Number} - X axis location */
@@ -339,12 +339,12 @@ class Vector2
339
339
  distanceSquared(v) { return (this.x - v.x)**2 + (this.y - v.y)**2; }
340
340
 
341
341
  /** Returns a new vector in same direction as this one with the length passed in
342
- * @param {Number} [length=1]
342
+ * @param {Number} [length]
343
343
  * @return {Vector2} */
344
344
  normalize(length=1) { const l = this.length(); return l ? this.scale(length/l) : new Vector2(0, length); }
345
345
 
346
346
  /** Returns a new vector clamped to length passed in
347
- * @param {Number} [length=1]
347
+ * @param {Number} [length]
348
348
  * @return {Vector2} */
349
349
  clampLength(length=1) { const l = this.length(); return l > length ? this.scale(length/l) : this; }
350
350
 
@@ -363,8 +363,8 @@ class Vector2
363
363
  angle() { return Math.atan2(this.x, this.y); }
364
364
 
365
365
  /** Sets this vector with angle and length passed in
366
- * @param {Number} [angle=0]
367
- * @param {Number} [length=1]
366
+ * @param {Number} [angle]
367
+ * @param {Number} [length]
368
368
  * @return {Vector2} */
369
369
  setAngle(angle=0, length=1)
370
370
  { this.x = length*Math.sin(angle); this.y = length*Math.cos(angle); return this; }
@@ -449,10 +449,10 @@ function hsl(h, s, l, a) { return new Color().setHSLA(h, s, l, a); }
449
449
  class Color
450
450
  {
451
451
  /** Create a color with the rgba components passed in, white by default
452
- * @param {Number} [r=1] - red
453
- * @param {Number} [g=1] - green
454
- * @param {Number} [b=1] - blue
455
- * @param {Number} [a=1] - alpha*/
452
+ * @param {Number} [r] - red
453
+ * @param {Number} [g] - green
454
+ * @param {Number} [b] - blue
455
+ * @param {Number} [a] - alpha*/
456
456
  constructor(r=1, g=1, b=1, a=1)
457
457
  {
458
458
  /** @property {Number} - Red */
@@ -507,10 +507,10 @@ class Color
507
507
  lerp(c, percent) { return this.add(c.subtract(this).scale(clamp(percent))); }
508
508
 
509
509
  /** Sets this color given a hue, saturation, lightness, and alpha
510
- * @param {Number} [h=0] - hue
511
- * @param {Number} [s=0] - saturation
512
- * @param {Number} [l=1] - lightness
513
- * @param {Number} [a=1] - alpha
510
+ * @param {Number} [h] - hue
511
+ * @param {Number} [s] - saturation
512
+ * @param {Number} [l] - lightness
513
+ * @param {Number} [a] - alpha
514
514
  * @return {Color} */
515
515
  setHSLA(h=0, s=0, l=1, a=1)
516
516
  {
@@ -556,8 +556,8 @@ class Color
556
556
  }
557
557
 
558
558
  /** Returns a new color that has each component randomly adjusted
559
- * @param {Number} [amount=.05]
560
- * @param {Number} [alphaAmount=0]
559
+ * @param {Number} [amount]
560
+ * @param {Number} [alphaAmount]
561
561
  * @return {Color} */
562
562
  mutate(amount=.05, alphaAmount=0)
563
563
  {
@@ -571,9 +571,9 @@ class Color
571
571
  }
572
572
 
573
573
  /** Returns this color expressed as a hex color code
574
- * @param {Boolean} [useAlpha=1] - if alpha should be included in result
574
+ * @param {Boolean} [useAlpha] - if alpha should be included in result
575
575
  * @return {String} */
576
- toString(useAlpha = 1)
576
+ toString(useAlpha = true)
577
577
  {
578
578
  const toHex = (c)=> ((c=c*255|0)<16 ? '0' : '') + c.toString(16);
579
579
  return '#' + toHex(this.r) + toHex(this.g) + toHex(this.b) + (useAlpha ? toHex(this.a) : '');
@@ -622,7 +622,7 @@ class Timer
622
622
  constructor(timeLeft) { this.time = timeLeft == undefined ? undefined : time + timeLeft; this.setTime = timeLeft; }
623
623
 
624
624
  /** Set the timer with seconds passed in
625
- * @param {Number} [timeLeft=0] - How much time left before the timer is elapsed in seconds */
625
+ * @param {Number} [timeLeft] - How much time left before the timer is elapsed in seconds */
626
626
  set(timeLeft=0) { this.time = time + timeLeft; this.setTime = timeLeft; }
627
627
 
628
628
  /** Unset the timer */