littlejsengine 1.6.6 → 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 (57) hide show
  1. package/README.md +51 -35
  2. package/build/littlejs.d.ts +71 -80
  3. package/build/littlejs.esm.js +162 -139
  4. package/build/littlejs.esm.min.js +1 -1
  5. package/build/littlejs.js +159 -129
  6. package/build/littlejs.min.js +1 -1
  7. package/build/littlejs.release.js +1942 -1907
  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/js13k/build.bat +2 -0
  20. package/examples/js13k/build.js +110 -0
  21. package/examples/js13k/game.js +109 -0
  22. package/examples/js13k/index.html +18 -0
  23. package/examples/js13k/tiles.png +0 -0
  24. package/examples/module/game.js +9 -3
  25. package/examples/module/index.html +2 -2
  26. package/examples/particles/index.html +7 -13
  27. package/examples/platformer/game.js +5 -2
  28. package/examples/platformer/gameEffects.js +1 -2
  29. package/examples/platformer/gamePlayer.js +2 -2
  30. package/examples/platformer/index.html +8 -8
  31. package/examples/puzzle/game.js +5 -3
  32. package/examples/puzzle/index.html +4 -4
  33. package/examples/starter/build.bat +2 -78
  34. package/examples/starter/build.js +109 -0
  35. package/examples/starter/game.js +4 -1
  36. package/examples/starter/index.html +15 -18
  37. package/examples/stress/index.html +2 -4
  38. package/examples/typescript/build.bat +2 -14
  39. package/examples/typescript/build.js +31 -0
  40. package/examples/typescript/game.js +94 -89
  41. package/examples/typescript/game.ts +9 -3
  42. package/examples/typescript/index.html +2 -2
  43. package/package.json +2 -2
  44. package/src/engine.js +3 -3
  45. package/src/engineAudio.js +2 -2
  46. package/src/engineBuild.bat +2 -132
  47. package/src/engineBuild.js +143 -0
  48. package/src/engineDebug.js +4 -10
  49. package/src/engineDraw.js +12 -4
  50. package/src/engineExport.js +1 -8
  51. package/src/engineInput.js +1 -1
  52. package/src/engineObject.js +13 -11
  53. package/src/engineParticles.js +6 -6
  54. package/src/engineRelease.js +0 -1
  55. package/src/engineTileLayer.js +31 -18
  56. package/src/engineUtilities.js +74 -61
  57. package/examples/electron/build.bat +0 -52
@@ -67,12 +67,12 @@ function tileCollisionTest(pos, size=vec2(), object)
67
67
  for (let x = minX; x < maxX; ++x)
68
68
  {
69
69
  const tileData = tileCollision[y*tileCollisionSize.x+x];
70
- if (tileData && (!object || object.collideWithTile(tileData, new Vector2(x, y))))
70
+ if (tileData && (!object || object.collideWithTile(tileData, vec2(x, y))))
71
71
  return 1;
72
72
  }
73
73
  }
74
74
 
75
- /** Return the center of tile if any that is hit (this does not return the exact hit point)
75
+ /** Return the center of tile if any that is hit (does not return the exact intersection)
76
76
  * @param {Vector2} posStart
77
77
  * @param {Vector2} posEnd
78
78
  * @param {EngineObject} [object]
@@ -81,28 +81,41 @@ function tileCollisionTest(pos, size=vec2(), object)
81
81
  function tileCollisionRaycast(posStart, posEnd, object)
82
82
  {
83
83
  // test if a ray collides with tiles from start to end
84
- // todo: a way to get the exact hit point, it must still register as inside the hit tile
85
- const posDelta = (posEnd = posEnd.floor()).subtract(posStart = posStart.floor());
86
- const dx = abs(posDelta.x), dy = -abs(posDelta.y);
87
- const sx = sign(posDelta.x), sy = sign(posDelta.y);
84
+ // todo: a way to get the exact hit point, it must still be inside the hit tile
85
+ const delta = posEnd.subtract(posStart);
86
+ const totalLength = delta.length();
87
+ const normalizedDelta = delta.normalize();
88
+ const unit = vec2(abs(1/normalizedDelta.x), abs(1/normalizedDelta.y));
89
+ const flooredPosStart = posStart.floor();
88
90
 
89
- for (let x = posStart.x, y = posStart.y, e = dx + dy;;)
91
+ // setup iteration variables
92
+ let pos = flooredPosStart;
93
+ let xi = unit.x * (delta.x < 0 ? posStart.x - pos.x : pos.x - posStart.x + 1);
94
+ let yi = unit.y * (delta.y < 0 ? posStart.y - pos.y : pos.y - posStart.y + 1);
95
+
96
+ while (1)
90
97
  {
91
- const tileData = getTileCollisionData(vec2(x,y));
92
- if (tileData && (object ? object.collideWithTileRaycast(tileData, new Vector2(x, y)) : tileData > 0))
98
+ // check for tile collision
99
+ const tileData = getTileCollisionData(pos);
100
+ if (tileData && (!object || object.collideWithTile(tileData, pos)))
93
101
  {
94
- debugRaycast && debugLine(posStart, posEnd, '#f00',.02, 1);
95
- debugRaycast && debugPoint(new Vector2(x+.5, y+.5), '#ff0', 1);
96
- return new Vector2(x+.5, y+.5);
102
+ debugRaycast && debugLine(posStart, posEnd, '#f00', .02);
103
+ debugRaycast && debugPoint(pos.add(vec2(.5)), '#ff0');
104
+ return pos.add(vec2(.5));
97
105
  }
98
106
 
99
- // update Bresenham line drawing algorithm
100
- if (x == posEnd.x & y == posEnd.y) break;
101
- const e2 = 2*e;
102
- if (e2 >= dy) e += dy, x += sx;
103
- if (e2 <= dx) e += dx, y += sy;
107
+ // check if past the end
108
+ if (xi > totalLength && yi > totalLength)
109
+ break;
110
+
111
+ // get coordinates of the next tile to check
112
+ if (xi > yi)
113
+ pos.y += sign(delta.y), yi += unit.y;
114
+ else
115
+ pos.x += sign(delta.x), xi += unit.x;
104
116
  }
105
- debugRaycast && debugLine(posStart, posEnd, '#00f',.02, 1);
117
+
118
+ debugRaycast && debugLine(posStart, posEnd, '#00f', .02);
106
119
  }
107
120
 
108
121
  ///////////////////////////////////////////////////////////////////////////////
@@ -19,34 +19,34 @@ const PI = Math.PI;
19
19
  * @param {Number} value
20
20
  * @return {Number}
21
21
  * @memberof Utilities */
22
- function abs(a) { return 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
- function min(a, b) { return 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
- function max(a, b) { return 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
- function sign(a) { return 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
- function mod(a, b=1) { return ((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,8 +54,8 @@ function mod(a, b=1) { return ((a % b) + b) % b; }
54
54
  * @param {Number} [max=1]
55
55
  * @return {Number}
56
56
  * @memberof Utilities */
57
- function clamp(v, min=0, max=1)
58
- { return v < min ? min : v > max ? max : v; }
57
+ function clamp(value, min=0, max=1)
58
+ { return value < min ? min : value > max ? max : value; }
59
59
 
60
60
  /** Returns what percentage the value is between max and min
61
61
  * @param {Number} value
@@ -63,8 +63,8 @@ function clamp(v, min=0, max=1)
63
63
  * @param {Number} [max=1]
64
64
  * @return {Number}
65
65
  * @memberof Utilities */
66
- function percent(v, min=0, max=1)
67
- { return 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; }
68
68
 
69
69
  /** Linearly interpolates the percent value between max and min
70
70
  * @param {Number} percent
@@ -72,29 +72,32 @@ function percent(v, min=0, max=1)
72
72
  * @param {Number} [max=1]
73
73
  * @return {Number}
74
74
  * @memberof Utilities */
75
- function lerp(p, min=0, max=1){ return min + clamp(p) * (max-min); }
75
+ function lerp(percent, min=0, max=1){ return min + clamp(percent) * (max-min); }
76
76
 
77
77
  /** Applies smoothstep function to the percentage value
78
- * @param {Number} value
78
+ * @param {Number} percent
79
79
  * @return {Number}
80
80
  * @memberof Utilities */
81
- function smoothStep(p) { return p * p * (3 - 2 * p); }
81
+ function smoothStep(percent) { return percent * percent * (3 - 2 * percent); }
82
82
 
83
83
  /** Returns the nearest power of two not less then the value
84
84
  * @param {Number} value
85
85
  * @return {Number}
86
86
  * @memberof Utilities */
87
- function nearestPowerOfTwo(v) { return 2**Math.ceil(Math.log2(v)); }
87
+ function nearestPowerOfTwo(value) { return 2**Math.ceil(Math.log2(value)); }
88
88
 
89
89
  /** Returns true if two axis aligned bounding boxes are overlapping
90
90
  * @param {Vector2} pointA - Center of box A
91
91
  * @param {Vector2} sizeA - Size of box A
92
92
  * @param {Vector2} pointB - Center of box B
93
- * @param {Vector2} [sizeB] - Size of box B
93
+ * @param {Vector2} sizeB - Size of box B
94
94
  * @return {Boolean} - True if overlapping
95
95
  * @memberof Utilities */
96
- function isOverlapping(pA, sA, pB, sB)
97
- { return 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
+ }
98
101
 
99
102
  /** Returns an oscillating wave between 0 and amplitude with frequency of 1 Hz by default
100
103
  * @param {Number} [frequency=1] - Frequency of the wave in Hz
@@ -121,14 +124,14 @@ function formatTime(t) { return (t/60|0) + ':' + (t%60<10?'0':'') + (t%60|0); }
121
124
  * @param {Number} [valueB=0]
122
125
  * @return {Number}
123
126
  * @memberof Random */
124
- function rand(a=1, b=0) { return b + (a-b)*Math.random(); }
127
+ function rand(valueA=1, valueB=0) { return valueB + Math.random() * (valueA-valueB); }
125
128
 
126
129
  /** Returns a floored random value the two values passed in
127
130
  * @param {Number} [valueA=1]
128
131
  * @param {Number} [valueB=0]
129
132
  * @return {Number}
130
133
  * @memberof Random */
131
- function randInt(a=1, b=0) { return rand(a,b)|0; }
134
+ function randInt(valueA=1, valueB=0) { return Math.floor(rand(valueA,valueB)); }
132
135
 
133
136
  /** Randomly returns either -1 or 1
134
137
  * @return {Number}
@@ -155,8 +158,11 @@ function randVector(length=1) { return new Vector2().setAngle(rand(2*PI), length
155
158
  * @param {Boolean} [linear]
156
159
  * @return {Color}
157
160
  * @memberof Random */
158
- function randColor(cA = new Color, cB = new Color(0,0,0,1), linear)
159
- { return 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
+ }
160
166
 
161
167
  /** Seed used by the randSeeded function
162
168
  * @type {Number}
@@ -174,13 +180,13 @@ function setRandSeed(seed) { randSeed = seed; }
174
180
  * @param {Number} [valueB=0]
175
181
  * @return {Number}
176
182
  * @memberof Random */
177
- function randSeeded(a=1, b=0)
183
+ function randSeeded(valueA=1, valueB=0)
178
184
  {
179
185
  // xorshift algorithm
180
186
  randSeed ^= randSeed << 13;
181
187
  randSeed ^= randSeed >>> 17;
182
188
  randSeed ^= randSeed << 5;
183
- return b + (a-b) * abs(randSeed % 1e9) / 1e9;
189
+ return valueB + (valueA-valueB) * abs(randSeed % 1e9) / 1e9;
184
190
  }
185
191
 
186
192
  ///////////////////////////////////////////////////////////////////////////////
@@ -202,7 +208,7 @@ function vec2(x=0, y)
202
208
 
203
209
  /**
204
210
  * Check if object is a valid Vector2
205
- * @param {Vector2} vector
211
+ * @param {Vector2} v
206
212
  * @return {Boolean}
207
213
  * @memberof Utilities
208
214
  */
@@ -235,27 +241,27 @@ class Vector2
235
241
  copy() { return new Vector2(this.x, this.y); }
236
242
 
237
243
  /** Returns a copy of this vector plus the vector passed in
238
- * @param {Vector2} vector
244
+ * @param {Vector2} v - other vector
239
245
  * @return {Vector2} */
240
246
  add(v) { ASSERT(isVector2(v)); return new Vector2(this.x + v.x, this.y + v.y); }
241
247
 
242
248
  /** Returns a copy of this vector minus the vector passed in
243
- * @param {Vector2} vector
249
+ * @param {Vector2} v - other vector
244
250
  * @return {Vector2} */
245
251
  subtract(v) { ASSERT(isVector2(v)); return new Vector2(this.x - v.x, this.y - v.y); }
246
252
 
247
253
  /** Returns a copy of this vector times the vector passed in
248
- * @param {Vector2} vector
254
+ * @param {Vector2} v - other vector
249
255
  * @return {Vector2} */
250
256
  multiply(v) { ASSERT(isVector2(v)); return new Vector2(this.x * v.x, this.y * v.y); }
251
257
 
252
258
  /** Returns a copy of this vector divided by the vector passed in
253
- * @param {Vector2} vector
259
+ * @param {Vector2} v - other vector
254
260
  * @return {Vector2} */
255
261
  divide(v) { ASSERT(isVector2(v)); return new Vector2(this.x / v.x, this.y / v.y); }
256
262
 
257
263
  /** Returns a copy of this vector scaled by the vector passed in
258
- * @param {Number} scale
264
+ * @param {Number} s - scale
259
265
  * @return {Vector2} */
260
266
  scale(s) { ASSERT(!isVector2(s)); return new Vector2(this.x * s, this.y * s); }
261
267
 
@@ -268,12 +274,12 @@ class Vector2
268
274
  lengthSquared() { return this.x**2 + this.y**2; }
269
275
 
270
276
  /** Returns the distance from this vector to vector passed in
271
- * @param {Vector2} vector
277
+ * @param {Vector2} v - other vector
272
278
  * @return {Number} */
273
279
  distance(v) { return this.distanceSquared(v)**.5; }
274
280
 
275
281
  /** Returns the distance squared from this vector to vector passed in
276
- * @param {Vector2} vector
282
+ * @param {Vector2} v - other vector
277
283
  * @return {Number} */
278
284
  distanceSquared(v) { return (this.x - v.x)**2 + (this.y - v.y)**2; }
279
285
 
@@ -288,12 +294,12 @@ class Vector2
288
294
  clampLength(length=1) { const l = this.length(); return l > length ? this.scale(length/l) : this; }
289
295
 
290
296
  /** Returns the dot product of this and the vector passed in
291
- * @param {Vector2} vector
297
+ * @param {Vector2} v - other vector
292
298
  * @return {Number} */
293
299
  dot(v) { ASSERT(isVector2(v)); return this.x*v.x + this.y*v.y; }
294
300
 
295
301
  /** Returns the cross product of this and the vector passed in
296
- * @param {Vector2} vector
302
+ * @param {Vector2} v - other vector
297
303
  * @return {Number} */
298
304
  cross(v) { ASSERT(isVector2(v)); return this.x*v.y - this.y*v.x; }
299
305
 
@@ -305,12 +311,17 @@ class Vector2
305
311
  * @param {Number} [angle=0]
306
312
  * @param {Number} [length=1]
307
313
  * @return {Vector2} */
308
- 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; }
309
316
 
310
317
  /** Returns copy of this vector rotated by the angle passed in
311
318
  * @param {Number} angle
312
319
  * @return {Vector2} */
313
- 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
+ }
314
325
 
315
326
  /** Returns the integer direction of this vector, corrosponding to multiples of 90 degree rotation (0-3)
316
327
  * @return {Number} */
@@ -329,10 +340,11 @@ class Vector2
329
340
  area() { return abs(this.x * this.y); }
330
341
 
331
342
  /** Returns a new vector that is p percent between this and the vector passed in
332
- * @param {Vector2} vector
343
+ * @param {Vector2} v - other vector
333
344
  * @param {Number} percent
334
345
  * @return {Vector2} */
335
- 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))); }
336
348
 
337
349
  /** Returns true if this vector is within the bounds of an array size passed in
338
350
  * @param {Vector2} arraySize
@@ -350,10 +362,10 @@ class Vector2
350
362
 
351
363
  /**
352
364
  * Create a color object with RGBA values
353
- * @param {Number} [r=1]
354
- * @param {Number} [g=1]
355
- * @param {Number} [b=1]
356
- * @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
357
369
  * @return {Color}
358
370
  * @memberof Utilities
359
371
  */
@@ -361,10 +373,10 @@ function rgb(r, g, b, a) { return new Color(r, g, b, a); }
361
373
 
362
374
  /**
363
375
  * Create a color object with HSLA values
364
- * @param {Number} [h=0]
365
- * @param {Number} [s=0]
366
- * @param {Number} [l=1]
367
- * @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
368
380
  * @return {Color}
369
381
  * @memberof Utilities
370
382
  */
@@ -381,11 +393,11 @@ function hsl(h, s, l, a) { return new Color().setHSLA(h, s, l, a); }
381
393
  */
382
394
  class Color
383
395
  {
384
- /** Create a color with the components passed in, white by default
385
- * @param {Number} [red=1]
386
- * @param {Number} [green=1]
387
- * @param {Number} [blue=1]
388
- * @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*/
389
401
  constructor(r=1, g=1, b=1, a=1)
390
402
  {
391
403
  /** @property {Number} - Red */
@@ -403,22 +415,22 @@ class Color
403
415
  copy() { return new Color(this.r, this.g, this.b, this.a); }
404
416
 
405
417
  /** Returns a copy of this color plus the color passed in
406
- * @param {Color} color
418
+ * @param {Color} c - other color
407
419
  * @return {Color} */
408
420
  add(c) { return new Color(this.r+c.r, this.g+c.g, this.b+c.b, this.a+c.a); }
409
421
 
410
422
  /** Returns a copy of this color minus the color passed in
411
- * @param {Color} color
423
+ * @param {Color} c - other color
412
424
  * @return {Color} */
413
425
  subtract(c) { return new Color(this.r-c.r, this.g-c.g, this.b-c.b, this.a-c.a); }
414
426
 
415
427
  /** Returns a copy of this color times the color passed in
416
- * @param {Color} color
428
+ * @param {Color} c - other color
417
429
  * @return {Color} */
418
430
  multiply(c) { return new Color(this.r*c.r, this.g*c.g, this.b*c.b, this.a*c.a); }
419
431
 
420
432
  /** Returns a copy of this color divided by the color passed in
421
- * @param {Color} color
433
+ * @param {Color} c - other color
422
434
  * @return {Color} */
423
435
  divide(c) { return new Color(this.r/c.r, this.g/c.g, this.b/c.b, this.a/c.a); }
424
436
 
@@ -426,23 +438,24 @@ class Color
426
438
  * @param {Number} scale
427
439
  * @param {Number} [alphaScale=scale]
428
440
  * @return {Color} */
429
- 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); }
430
443
 
431
444
  /** Returns a copy of this color clamped to the valid range between 0 and 1
432
445
  * @return {Color} */
433
446
  clamp() { return new Color(clamp(this.r), clamp(this.g), clamp(this.b), clamp(this.a)); }
434
447
 
435
448
  /** Returns a new color that is p percent between this and the color passed in
436
- * @param {Color} color
449
+ * @param {Color} c - other color
437
450
  * @param {Number} percent
438
451
  * @return {Color} */
439
- 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))); }
440
453
 
441
454
  /** Sets this color given a hue, saturation, lightness, and alpha
442
- * @param {Number} [hue=0]
443
- * @param {Number} [saturation=0]
444
- * @param {Number} [lightness=1]
445
- * @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
446
459
  * @return {Color} */
447
460
  setHSLA(h=0, s=0, l=1, a=1)
448
461
  {
@@ -583,7 +596,7 @@ class Timer
583
596
 
584
597
  /** Returns this timer expressed as a string
585
598
  * @return {String} */
586
- 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'; }}
587
600
 
588
601
  /** Get how long since elapsed, returns 0 if not set (returns negative if currently active)
589
602
  * @return {Number} */
@@ -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