littlejsengine 1.6.4 → 1.6.92

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 (61) hide show
  1. package/README.md +61 -41
  2. package/build/littlejs.d.ts +160 -165
  3. package/build/littlejs.esm.js +451 -367
  4. package/build/littlejs.esm.min.js +1 -1
  5. package/build/littlejs.js +408 -314
  6. package/build/littlejs.min.js +1 -1
  7. package/build/littlejs.release.js +2573 -2470
  8. package/examples/breakout/game.js +5 -1
  9. package/examples/breakout/index.html +5 -5
  10. package/examples/breakoutTutorial/README.md +6 -6
  11. package/examples/breakoutTutorial/game.js +3 -0
  12. package/examples/breakoutTutorial/index.html +3 -3
  13. package/examples/electron/build.js +105 -0
  14. package/examples/electron/game.js +4 -2
  15. package/examples/electron/index.html +13 -2
  16. package/examples/electron/package.json +5 -3
  17. package/examples/empty/game.js +3 -1
  18. package/examples/empty/index.html +1 -1
  19. package/examples/favicon.png +0 -0
  20. package/examples/js13k/build.bat +2 -0
  21. package/examples/js13k/build.js +110 -0
  22. package/examples/js13k/game.js +109 -0
  23. package/examples/js13k/index.html +18 -0
  24. package/examples/js13k/tiles.png +0 -0
  25. package/examples/module/game.js +9 -3
  26. package/examples/module/index.html +2 -2
  27. package/examples/particles/index.html +7 -13
  28. package/examples/platformer/game.js +5 -2
  29. package/examples/platformer/gameEffects.js +1 -2
  30. package/examples/platformer/gamePlayer.js +2 -2
  31. package/examples/platformer/index.html +8 -8
  32. package/examples/puzzle/game.js +6 -4
  33. package/examples/puzzle/index.html +4 -4
  34. package/examples/starter/build.bat +2 -78
  35. package/examples/starter/build.js +109 -0
  36. package/examples/starter/game.js +4 -1
  37. package/examples/starter/index.html +15 -18
  38. package/examples/stress/index.html +2 -4
  39. package/examples/typescript/build.bat +2 -14
  40. package/examples/typescript/build.js +31 -0
  41. package/examples/typescript/game.js +94 -89
  42. package/examples/typescript/game.ts +9 -3
  43. package/examples/typescript/index.html +2 -2
  44. package/package.json +3 -3
  45. package/src/engine.js +30 -31
  46. package/src/engineAudio.js +44 -20
  47. package/src/engineBuild.bat +2 -132
  48. package/src/engineBuild.js +143 -0
  49. package/src/engineDebug.js +21 -32
  50. package/src/engineDraw.js +36 -28
  51. package/src/engineExport.js +41 -51
  52. package/src/engineInput.js +33 -20
  53. package/src/engineMedals.js +31 -8
  54. package/src/engineObject.js +34 -32
  55. package/src/engineParticles.js +9 -12
  56. package/src/engineRelease.js +18 -20
  57. package/src/engineSettings.js +4 -4
  58. package/src/engineTileLayer.js +49 -32
  59. package/src/engineUtilities.js +96 -74
  60. package/src/engineWebGL.js +8 -8
  61. package/examples/electron/build.bat +0 -52
@@ -1,9 +1,9 @@
1
1
  /**
2
2
  * LittleJS Utility Classes and Functions
3
- * <br> - General purpose math library
4
- * <br> - Vector2 - fast, simple, easy 2D vector class
5
- * <br> - Color - holds a rgba color with some math functions
6
- * <br> - Timer - tracks time automatically
3
+ * - General purpose math library
4
+ * - Vector2 - fast, simple, easy 2D vector class
5
+ * - Color - holds a rgba color with some math functions
6
+ * - Timer - tracks time automatically
7
7
  * @namespace Utilities
8
8
  */
9
9
 
@@ -19,34 +19,34 @@ const PI = Math.PI;
19
19
  * @param {Number} value
20
20
  * @return {Number}
21
21
  * @memberof Utilities */
22
- const abs = (a)=> a < 0 ? -a : a;
22
+ function abs(value) { return Math.abs(value); }
23
23
 
24
24
  /** Returns lowest of two values passed in
25
25
  * @param {Number} valueA
26
26
  * @param {Number} valueB
27
27
  * @return {Number}
28
28
  * @memberof Utilities */
29
- const min = (a, b)=> a < b ? a : b;
29
+ function min(valueA, valueB) { return Math.min(valueA, valueB); }
30
30
 
31
31
  /** Returns highest of two values passed in
32
32
  * @param {Number} valueA
33
33
  * @param {Number} valueB
34
34
  * @return {Number}
35
35
  * @memberof Utilities */
36
- const max = (a, b)=> a > b ? a : b;
36
+ function max(valueA, valueB) { return Math.max(valueA, valueB); }
37
37
 
38
38
  /** Returns the sign of value passed in (also returns 1 if 0)
39
39
  * @param {Number} value
40
40
  * @return {Number}
41
41
  * @memberof Utilities */
42
- const sign = (a)=> a < 0 ? -1 : 1;
42
+ function sign(value) { return Math.sign(value); }
43
43
 
44
44
  /** Returns first parm modulo the second param, but adjusted so negative numbers work as expected
45
45
  * @param {Number} dividend
46
46
  * @param {Number} [divisor=1]
47
47
  * @return {Number}
48
48
  * @memberof Utilities */
49
- const mod = (a, b=1)=> ((a % b) + b) % b;
49
+ function mod(dividend, divisor=1) { return ((dividend % divisor) + divisor) % divisor; }
50
50
 
51
51
  /** Clamps the value beween max and min
52
52
  * @param {Number} value
@@ -54,7 +54,8 @@ const mod = (a, b=1)=> ((a % b) + b) % b;
54
54
  * @param {Number} [max=1]
55
55
  * @return {Number}
56
56
  * @memberof Utilities */
57
- const clamp = (v, min=0, max=1)=> v < min ? min : v > max ? max : v;
57
+ function clamp(value, min=0, max=1)
58
+ { return value < min ? min : value > max ? max : value; }
58
59
 
59
60
  /** Returns what percentage the value is between max and min
60
61
  * @param {Number} value
@@ -62,7 +63,8 @@ const clamp = (v, min=0, max=1)=> v < min ? min : v > max ? max : v;
62
63
  * @param {Number} [max=1]
63
64
  * @return {Number}
64
65
  * @memberof Utilities */
65
- const percent = (v, min=0, max=1)=> max-min ? clamp((v-min) / (max-min)) : 0;
66
+ function percent(value, min=0, max=1)
67
+ { return max-min ? clamp((value-min) / (max-min)) : 0; }
66
68
 
67
69
  /** Linearly interpolates the percent value between max and min
68
70
  * @param {Number} percent
@@ -70,28 +72,32 @@ const percent = (v, min=0, max=1)=> max-min ? clamp((v-min) / (max-min)) : 0;
70
72
  * @param {Number} [max=1]
71
73
  * @return {Number}
72
74
  * @memberof Utilities */
73
- const lerp = (p, min=0, max=1)=> min + clamp(p) * (max-min);
75
+ function lerp(percent, min=0, max=1){ return min + clamp(percent) * (max-min); }
74
76
 
75
77
  /** Applies smoothstep function to the percentage value
76
- * @param {Number} value
78
+ * @param {Number} percent
77
79
  * @return {Number}
78
80
  * @memberof Utilities */
79
- const smoothStep = (p)=> p * p * (3 - 2 * p);
81
+ function smoothStep(percent) { return percent * percent * (3 - 2 * percent); }
80
82
 
81
83
  /** Returns the nearest power of two not less then the value
82
84
  * @param {Number} value
83
85
  * @return {Number}
84
86
  * @memberof Utilities */
85
- const nearestPowerOfTwo = (v)=> 2**Math.ceil(Math.log2(v));
87
+ function nearestPowerOfTwo(value) { return 2**Math.ceil(Math.log2(value)); }
86
88
 
87
89
  /** Returns true if two axis aligned bounding boxes are overlapping
88
90
  * @param {Vector2} pointA - Center of box A
89
91
  * @param {Vector2} sizeA - Size of box A
90
92
  * @param {Vector2} pointB - Center of box B
91
- * @param {Vector2} [sizeB] - Size of box B
93
+ * @param {Vector2} sizeB - Size of box B
92
94
  * @return {Boolean} - True if overlapping
93
95
  * @memberof Utilities */
94
- const isOverlapping = (pA, sA, pB, sB)=> abs(pA.x - pB.x)*2 < sA.x + sB.x && abs(pA.y - pB.y)*2 < sA.y + sB.y;
96
+ function isOverlapping(pointA, sizeA, pointB, sizeB)
97
+ {
98
+ return abs(pointA.x - pointB.x)*2 < sizeA.x + sizeB.x
99
+ && abs(pointA.y - pointB.y)*2 < sizeA.y + sizeB.y;
100
+ }
95
101
 
96
102
  /** Returns an oscillating wave between 0 and amplitude with frequency of 1 Hz by default
97
103
  * @param {Number} [frequency=1] - Frequency of the wave in Hz
@@ -99,13 +105,14 @@ const isOverlapping = (pA, sA, pB, sB)=> abs(pA.x - pB.x)*2 < sA.x + sB.x && abs
99
105
  * @param {Number} [t=time] - Value to use for time of the wave
100
106
  * @return {Number} - Value waving between 0 and amplitude
101
107
  * @memberof Utilities */
102
- const wave = (frequency=1, amplitude=1, t=time)=> amplitude/2 * (1 - Math.cos(t*frequency*2*PI));
108
+ function wave(frequency=1, amplitude=1, t=time)
109
+ { return amplitude/2 * (1 - Math.cos(t*frequency*2*PI)); }
103
110
 
104
111
  /** Formats seconds to mm:ss style for display purposes
105
112
  * @param {Number} t - time in seconds
106
113
  * @return {String}
107
114
  * @memberof Utilities */
108
- const formatTime = (t)=> (t/60|0) + ':' + (t%60<10?'0':'') + (t%60|0);
115
+ function formatTime(t) { return (t/60|0) + ':' + (t%60<10?'0':'') + (t%60|0); }
109
116
 
110
117
  ///////////////////////////////////////////////////////////////////////////////
111
118
 
@@ -117,32 +124,33 @@ const formatTime = (t)=> (t/60|0) + ':' + (t%60<10?'0':'') + (t%60|0);
117
124
  * @param {Number} [valueB=0]
118
125
  * @return {Number}
119
126
  * @memberof Random */
120
- const rand = (a=1, b=0)=> b + (a-b)*Math.random();
127
+ function rand(valueA=1, valueB=0) { return valueB + Math.random() * (valueA-valueB); }
121
128
 
122
129
  /** Returns a floored random value the two values passed in
123
130
  * @param {Number} [valueA=1]
124
131
  * @param {Number} [valueB=0]
125
132
  * @return {Number}
126
133
  * @memberof Random */
127
- const randInt = (a=1, b=0)=> rand(a,b)|0;
134
+ function randInt(valueA=1, valueB=0) { return Math.floor(rand(valueA,valueB)); }
128
135
 
129
136
  /** Randomly returns either -1 or 1
130
137
  * @return {Number}
131
138
  * @memberof Random */
132
- const randSign = ()=> randInt(2) * 2 - 1;
139
+ function randSign() { return randInt(2) * 2 - 1; }
133
140
 
134
141
  /** Returns a random Vector2 within a circular shape
135
142
  * @param {Number} [radius=1]
136
143
  * @param {Number} [minRadius=0]
137
144
  * @return {Vector2}
138
145
  * @memberof Random */
139
- const randInCircle = (radius=1, minRadius=0)=> radius > 0 ? randVector(radius * rand(minRadius / radius, 1)**.5) : new Vector2;
146
+ function randInCircle(radius=1, minRadius=0)
147
+ { return radius > 0 ? randVector(radius * rand(minRadius / radius, 1)**.5) : new Vector2; }
140
148
 
141
149
  /** Returns a random Vector2 with the passed in length
142
150
  * @param {Number} [length=1]
143
151
  * @return {Vector2}
144
152
  * @memberof Random */
145
- const randVector = (length=1)=> new Vector2().setAngle(rand(2*PI), length);
153
+ function randVector(length=1) { return new Vector2().setAngle(rand(2*PI), length); }
146
154
 
147
155
  /** Returns a random color between the two passed in colors, combine components if linear
148
156
  * @param {Color} [colorA=Color()]
@@ -150,8 +158,11 @@ const randVector = (length=1)=> new Vector2().setAngle(rand(2*PI), length);
150
158
  * @param {Boolean} [linear]
151
159
  * @return {Color}
152
160
  * @memberof Random */
153
- const randColor = (cA = new Color, cB = new Color(0,0,0,1), linear)=>
154
- linear ? cA.lerp(cB, rand()) : new Color(rand(cA.r,cB.r),rand(cA.g,cB.g),rand(cA.b,cB.b),rand(cA.a,cB.a));
161
+ function randColor(colorA=new Color, colorB=new Color(0,0,0,1), linear)
162
+ {
163
+ return linear ? colorA.lerp(colorB, rand()) :
164
+ new Color(rand(colorA.r,colorB.r), rand(colorA.g,colorB.g), rand(colorA.b,colorB.b), rand(colorA.a,colorB.a));
165
+ }
155
166
 
156
167
  /** Seed used by the randSeeded function
157
168
  * @type {Number}
@@ -162,17 +173,20 @@ let randSeed = 1;
162
173
  /** Set seed used by the randSeeded function, should not be 0
163
174
  * @param {Number} seed
164
175
  * @memberof Random */
165
- const setRandSeed = (seed)=> randSeed = seed;
176
+ function setRandSeed(seed) { randSeed = seed; }
166
177
 
167
178
  /** Returns a seeded random value between the two values passed in using randSeed
168
179
  * @param {Number} [valueA=1]
169
180
  * @param {Number} [valueB=0]
170
181
  * @return {Number}
171
182
  * @memberof Random */
172
- const randSeeded = (a=1, b=0)=>
183
+ function randSeeded(valueA=1, valueB=0)
173
184
  {
174
- randSeed ^= randSeed << 13; randSeed ^= randSeed >>> 17; randSeed ^= randSeed << 5; // xorshift
175
- return b + (a-b) * abs(randSeed % 1e9) / 1e9;
185
+ // xorshift algorithm
186
+ randSeed ^= randSeed << 13;
187
+ randSeed ^= randSeed >>> 17;
188
+ randSeed ^= randSeed << 5;
189
+ return valueB + (valueA-valueB) * abs(randSeed % 1e9) / 1e9;
176
190
  }
177
191
 
178
192
  ///////////////////////////////////////////////////////////////////////////////
@@ -189,19 +203,20 @@ const randSeeded = (a=1, b=0)=>
189
203
  * b = vec2(); // set b to (0, 0)
190
204
  * @memberof Utilities
191
205
  */
192
- const vec2 = (x=0, y)=> x.x == undefined ? new Vector2(x, y == undefined? x : y) : new Vector2(x.x, x.y);
206
+ function vec2(x=0, y)
207
+ { return x.x == undefined ? new Vector2(x, y == undefined? x : y) : new Vector2(x.x, x.y); }
193
208
 
194
209
  /**
195
210
  * Check if object is a valid Vector2
196
- * @param {Vector2} vector
211
+ * @param {Vector2} v
197
212
  * @return {Boolean}
198
213
  * @memberof Utilities
199
214
  */
200
- const isVector2 = (v)=> !isNaN(v.x) && !isNaN(v.y);
215
+ function isVector2(v) { return !isNaN(v.x) && !isNaN(v.y); }
201
216
 
202
217
  /**
203
218
  * 2D Vector object with vector math library
204
- * <br> - Functions do not change this so they can be chained together
219
+ * - Functions do not change this so they can be chained together
205
220
  * @example
206
221
  * let a = new Vector2(2, 3); // vector with coordinates (2, 3)
207
222
  * let b = new Vector2; // vector with coordinates (0, 0)
@@ -226,27 +241,27 @@ class Vector2
226
241
  copy() { return new Vector2(this.x, this.y); }
227
242
 
228
243
  /** Returns a copy of this vector plus the vector passed in
229
- * @param {Vector2} vector
244
+ * @param {Vector2} v - other vector
230
245
  * @return {Vector2} */
231
246
  add(v) { ASSERT(isVector2(v)); return new Vector2(this.x + v.x, this.y + v.y); }
232
247
 
233
248
  /** Returns a copy of this vector minus the vector passed in
234
- * @param {Vector2} vector
249
+ * @param {Vector2} v - other vector
235
250
  * @return {Vector2} */
236
251
  subtract(v) { ASSERT(isVector2(v)); return new Vector2(this.x - v.x, this.y - v.y); }
237
252
 
238
253
  /** Returns a copy of this vector times the vector passed in
239
- * @param {Vector2} vector
254
+ * @param {Vector2} v - other vector
240
255
  * @return {Vector2} */
241
256
  multiply(v) { ASSERT(isVector2(v)); return new Vector2(this.x * v.x, this.y * v.y); }
242
257
 
243
258
  /** Returns a copy of this vector divided by the vector passed in
244
- * @param {Vector2} vector
259
+ * @param {Vector2} v - other vector
245
260
  * @return {Vector2} */
246
261
  divide(v) { ASSERT(isVector2(v)); return new Vector2(this.x / v.x, this.y / v.y); }
247
262
 
248
263
  /** Returns a copy of this vector scaled by the vector passed in
249
- * @param {Number} scale
264
+ * @param {Number} s - scale
250
265
  * @return {Vector2} */
251
266
  scale(s) { ASSERT(!isVector2(s)); return new Vector2(this.x * s, this.y * s); }
252
267
 
@@ -259,12 +274,12 @@ class Vector2
259
274
  lengthSquared() { return this.x**2 + this.y**2; }
260
275
 
261
276
  /** Returns the distance from this vector to vector passed in
262
- * @param {Vector2} vector
277
+ * @param {Vector2} v - other vector
263
278
  * @return {Number} */
264
279
  distance(v) { return this.distanceSquared(v)**.5; }
265
280
 
266
281
  /** Returns the distance squared from this vector to vector passed in
267
- * @param {Vector2} vector
282
+ * @param {Vector2} v - other vector
268
283
  * @return {Number} */
269
284
  distanceSquared(v) { return (this.x - v.x)**2 + (this.y - v.y)**2; }
270
285
 
@@ -279,12 +294,12 @@ class Vector2
279
294
  clampLength(length=1) { const l = this.length(); return l > length ? this.scale(length/l) : this; }
280
295
 
281
296
  /** Returns the dot product of this and the vector passed in
282
- * @param {Vector2} vector
297
+ * @param {Vector2} v - other vector
283
298
  * @return {Number} */
284
299
  dot(v) { ASSERT(isVector2(v)); return this.x*v.x + this.y*v.y; }
285
300
 
286
301
  /** Returns the cross product of this and the vector passed in
287
- * @param {Vector2} vector
302
+ * @param {Vector2} v - other vector
288
303
  * @return {Number} */
289
304
  cross(v) { ASSERT(isVector2(v)); return this.x*v.y - this.y*v.x; }
290
305
 
@@ -296,12 +311,17 @@ class Vector2
296
311
  * @param {Number} [angle=0]
297
312
  * @param {Number} [length=1]
298
313
  * @return {Vector2} */
299
- setAngle(a=0, length=1) { this.x = length*Math.sin(a); this.y = length*Math.cos(a); return this; }
314
+ setAngle(angle=0, length=1)
315
+ { this.x = length*Math.sin(angle); this.y = length*Math.cos(angle); return this; }
300
316
 
301
317
  /** Returns copy of this vector rotated by the angle passed in
302
318
  * @param {Number} angle
303
319
  * @return {Vector2} */
304
- rotate(a) { const c = Math.cos(a), s = Math.sin(a); return new Vector2(this.x*c-this.y*s, this.x*s+this.y*c); }
320
+ rotate(angle)
321
+ {
322
+ const c = Math.cos(angle), s = Math.sin(angle);
323
+ return new Vector2(this.x*c - this.y*s, this.x*s + this.y*c);
324
+ }
305
325
 
306
326
  /** Returns the integer direction of this vector, corrosponding to multiples of 90 degree rotation (0-3)
307
327
  * @return {Number} */
@@ -320,10 +340,11 @@ class Vector2
320
340
  area() { return abs(this.x * this.y); }
321
341
 
322
342
  /** Returns a new vector that is p percent between this and the vector passed in
323
- * @param {Vector2} vector
343
+ * @param {Vector2} v - other vector
324
344
  * @param {Number} percent
325
345
  * @return {Vector2} */
326
- lerp(v, p) { ASSERT(isVector2(v)); return this.add(v.subtract(this).scale(clamp(p))); }
346
+ lerp(v, percent)
347
+ { ASSERT(isVector2(v)); return this.add(v.subtract(this).scale(clamp(percent))); }
327
348
 
328
349
  /** Returns true if this vector is within the bounds of an array size passed in
329
350
  * @param {Vector2} arraySize
@@ -341,25 +362,25 @@ class Vector2
341
362
 
342
363
  /**
343
364
  * Create a color object with RGBA values
344
- * @param {Number} [r=1]
345
- * @param {Number} [g=1]
346
- * @param {Number} [b=1]
347
- * @param {Number} [a=1]
365
+ * @param {Number} [r=1] - red
366
+ * @param {Number} [g=1] - green
367
+ * @param {Number} [b=1] - blue
368
+ * @param {Number} [a=1] - alpha
348
369
  * @return {Color}
349
370
  * @memberof Utilities
350
371
  */
351
- const rgb = (r, g, b, a)=> new Color(r, g, b, a);
372
+ function rgb(r, g, b, a) { return new Color(r, g, b, a); }
352
373
 
353
374
  /**
354
375
  * Create a color object with HSLA values
355
- * @param {Number} [h=0]
356
- * @param {Number} [s=0]
357
- * @param {Number} [l=1]
358
- * @param {Number} [a=1]
376
+ * @param {Number} [h=0] - hue
377
+ * @param {Number} [s=0] - saturation
378
+ * @param {Number} [l=1] - lightness
379
+ * @param {Number} [a=1] - alpha
359
380
  * @return {Color}
360
381
  * @memberof Utilities
361
382
  */
362
- const hsl = (h, s, l, a)=> new Color().setHSLA(h, s, l, a);
383
+ function hsl(h, s, l, a) { return new Color().setHSLA(h, s, l, a); }
363
384
 
364
385
  /**
365
386
  * Color object (red, green, blue, alpha) with some helpful functions
@@ -372,11 +393,11 @@ const hsl = (h, s, l, a)=> new Color().setHSLA(h, s, l, a);
372
393
  */
373
394
  class Color
374
395
  {
375
- /** Create a color with the components passed in, white by default
376
- * @param {Number} [red=1]
377
- * @param {Number} [green=1]
378
- * @param {Number} [blue=1]
379
- * @param {Number} [alpha=1] */
396
+ /** Create a color with the rgba components passed in, white by default
397
+ * @param {Number} [r=1] - red
398
+ * @param {Number} [g=1] - green
399
+ * @param {Number} [b=1] - blue
400
+ * @param {Number} [a=1] - alpha*/
380
401
  constructor(r=1, g=1, b=1, a=1)
381
402
  {
382
403
  /** @property {Number} - Red */
@@ -394,22 +415,22 @@ class Color
394
415
  copy() { return new Color(this.r, this.g, this.b, this.a); }
395
416
 
396
417
  /** Returns a copy of this color plus the color passed in
397
- * @param {Color} color
418
+ * @param {Color} c - other color
398
419
  * @return {Color} */
399
420
  add(c) { return new Color(this.r+c.r, this.g+c.g, this.b+c.b, this.a+c.a); }
400
421
 
401
422
  /** Returns a copy of this color minus the color passed in
402
- * @param {Color} color
423
+ * @param {Color} c - other color
403
424
  * @return {Color} */
404
425
  subtract(c) { return new Color(this.r-c.r, this.g-c.g, this.b-c.b, this.a-c.a); }
405
426
 
406
427
  /** Returns a copy of this color times the color passed in
407
- * @param {Color} color
428
+ * @param {Color} c - other color
408
429
  * @return {Color} */
409
430
  multiply(c) { return new Color(this.r*c.r, this.g*c.g, this.b*c.b, this.a*c.a); }
410
431
 
411
432
  /** Returns a copy of this color divided by the color passed in
412
- * @param {Color} color
433
+ * @param {Color} c - other color
413
434
  * @return {Color} */
414
435
  divide(c) { return new Color(this.r/c.r, this.g/c.g, this.b/c.b, this.a/c.a); }
415
436
 
@@ -417,23 +438,24 @@ class Color
417
438
  * @param {Number} scale
418
439
  * @param {Number} [alphaScale=scale]
419
440
  * @return {Color} */
420
- scale(s, a=s) { return new Color(this.r*s, this.g*s, this.b*s, this.a*a); }
441
+ scale(scale, alphaScale=scale)
442
+ { return new Color(this.r*scale, this.g*scale, this.b*scale, this.a*alphaScale); }
421
443
 
422
444
  /** Returns a copy of this color clamped to the valid range between 0 and 1
423
445
  * @return {Color} */
424
446
  clamp() { return new Color(clamp(this.r), clamp(this.g), clamp(this.b), clamp(this.a)); }
425
447
 
426
448
  /** Returns a new color that is p percent between this and the color passed in
427
- * @param {Color} color
449
+ * @param {Color} c - other color
428
450
  * @param {Number} percent
429
451
  * @return {Color} */
430
- lerp(c, p) { return this.add(c.subtract(this).scale(clamp(p))); }
452
+ lerp(c, percent) { return this.add(c.subtract(this).scale(clamp(percent))); }
431
453
 
432
454
  /** Sets this color given a hue, saturation, lightness, and alpha
433
- * @param {Number} [hue=0]
434
- * @param {Number} [saturation=0]
435
- * @param {Number} [lightness=1]
436
- * @param {Number} [alpha=1]
455
+ * @param {Number} [h=0] - hue
456
+ * @param {Number} [s=0] - saturation
457
+ * @param {Number} [l=1] - lightness
458
+ * @param {Number} [a=1] - alpha
437
459
  * @return {Color} */
438
460
  setHSLA(h=0, s=0, l=1, a=1)
439
461
  {
@@ -574,7 +596,7 @@ class Timer
574
596
 
575
597
  /** Returns this timer expressed as a string
576
598
  * @return {String} */
577
- toString() { if (debug) { return this.unset() ? 'unset' : Math.abs(this.get()) + ' seconds ' + (this.get()<0 ? 'before' : 'after' ); }}
599
+ toString() { if (debug) { return this.isSet() ? Math.abs(this.get()) + ' seconds ' + (this.get()<0 ? 'before' : 'after' ) : 'unset'; }}
578
600
 
579
601
  /** Get how long since elapsed, returns 0 if not set (returns negative if currently active)
580
602
  * @return {Number} */
@@ -1,11 +1,11 @@
1
1
  /**
2
2
  * LittleJS WebGL Interface
3
- * <br> - All webgl used by the engine is wrapped up here
4
- * <br> - For normal stuff you won't need to see or call anything in this file
5
- * <br> - For advanced stuff there are helper functions to create shaders, textures, etc
6
- * <br> - Can be disabled with glEnable to revert to 2D canvas rendering
7
- * <br> - Batches sprite rendering on GPU for incredibly fast performance
8
- * <br> - Sprite transform math is done in the shader where possible
3
+ * - All webgl used by the engine is wrapped up here
4
+ * - For normal stuff you won't need to see or call anything in this file
5
+ * - For advanced stuff there are helper functions to create shaders, textures, etc
6
+ * - Can be disabled with glEnable to revert to 2D canvas rendering
7
+ * - Batches sprite rendering on GPU for incredibly fast performance
8
+ * - Sprite transform math is done in the shader where possible
9
9
  * @namespace WebGL
10
10
  */
11
11
 
@@ -80,7 +80,7 @@ function glSetBlendMode(additive)
80
80
  }
81
81
 
82
82
  /** Set the WebGl texture, not normally necessary unless multiple tile sheets are used
83
- * <br> - This may also flush the gl buffer resulting in more draw calls and worse performance
83
+ * - This may also flush the gl buffer resulting in more draw calls and worse performance
84
84
  * @param {WebGLTexture} [texture=glTileTexture]
85
85
  * @memberof WebGL */
86
86
  function glSetTexture(texture=glTileTexture)
@@ -141,7 +141,7 @@ function glCreateTexture(image)
141
141
  image && image.width && glContext.texImage2D(gl_TEXTURE_2D, 0, gl_RGBA, gl_RGBA, gl_UNSIGNED_BYTE, image);
142
142
 
143
143
  // use point filtering for pixelated rendering
144
- const filter = cavasPixelated ? gl_NEAREST : gl_LINEAR;
144
+ const filter = canvasPixelated ? gl_NEAREST : gl_LINEAR;
145
145
  glContext.texParameteri(gl_TEXTURE_2D, gl_TEXTURE_MIN_FILTER, filter);
146
146
  glContext.texParameteri(gl_TEXTURE_2D, gl_TEXTURE_MAG_FILTER, filter);
147
147
  glContext.texParameteri(gl_TEXTURE_2D, gl_TEXTURE_WRAP_S, gl_CLAMP_TO_EDGE);
@@ -1,52 +0,0 @@
1
- rem Simple build script for LittleJS by Frank Force
2
- rem Minfies and combines index.html and index.js and zips the result
3
-
4
- set NAME=game
5
- set BUILD_FOLDER=build
6
- set BUILD_FILENAME=index.js
7
-
8
- rem remove old files
9
- rmdir /s /q %BUILD_FOLDER%
10
- mkdir %BUILD_FOLDER%
11
- pushd %BUILD_FOLDER%
12
-
13
- rem copy engine release build
14
- type ..\..\..\build\littlejs.release.js >> %BUILD_FILENAME%
15
- echo. >> %BUILD_FILENAME%
16
-
17
- rem add your game's files to include here
18
- type ..\game.js >> %BUILD_FILENAME%
19
- echo. >> %BUILD_FILENAME%
20
-
21
- rem copy images to build folder
22
- copy ..\tiles.png tiles.png
23
-
24
- rem minify code with uglify
25
- call npx uglifyjs -o %BUILD_FILENAME% --compress --mangle -- %BUILD_FILENAME%
26
- if %ERRORLEVEL% NEQ 0 (
27
- pause
28
- exit /b %ERRORLEVEL%
29
- )
30
-
31
- rem build the html, you can add html header and footers here
32
- rem type ..\header.html >> index.html
33
- echo ^<body^>^<script^> >> index.html
34
- type %BUILD_FILENAME% >> index.html
35
- echo ^</script^> >> index.html
36
-
37
- rem delete intermediate files
38
- del %BUILD_FILENAME%
39
-
40
- rem copy elecron files to build folder
41
- copy ..\electron.js electron.js
42
- copy ..\package.json package.json
43
-
44
- popd
45
-
46
- rem build with electron
47
- call npx electron-packager ./%BUILD_FOLDER% --overwrite
48
- if %ERRORLEVEL% NEQ 0 (
49
- pause
50
- exit /b %ERRORLEVEL%
51
- )
52
- pause