littlejsengine 1.4.7 → 1.4.8

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.
@@ -492,7 +492,7 @@ const wave = (frequency=1, amplitude=1, t=time)=> amplitude/2 * (1 - Math.cos(t*
492
492
  * @param {Number} t - time in seconds
493
493
  * @return {String}
494
494
  * @memberof Utilities */
495
- const formatTime = (t)=> (t/60|0)+':'+(t%60<10?'0':'')+(t%60|0);
495
+ const formatTime = (t)=> (t/60|0) + ':' + (t%60<10?'0':'') + (t%60|0);
496
496
 
497
497
  ///////////////////////////////////////////////////////////////////////////////
498
498
 
@@ -516,7 +516,7 @@ const randInt = (a=1, b=0)=> rand(a,b)|0;
516
516
  /** Randomly returns either -1 or 1
517
517
  * @return {Number}
518
518
  * @memberof Random */
519
- const randSign = ()=> (rand(2)|0) * 2 - 1;
519
+ const randSign = ()=> randInt(2) * 2 - 1;
520
520
 
521
521
  /** Returns a random Vector2 within a circular shape
522
522
  * @param {Number} [radius=1]
@@ -540,10 +540,15 @@ const randVector = (length=1)=> new Vector2().setAngle(rand(2*PI), length);
540
540
  const randColor = (cA = new Color, cB = new Color(0,0,0,1), linear)=>
541
541
  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));
542
542
 
543
- /** The seed used by the randSeeded function, should not be 0
543
+ /** Seed used by the randSeeded function
544
544
  * @memberof Random */
545
545
  let randSeed = 1;
546
546
 
547
+ /** Set seed used by the randSeeded function, should not be 0
548
+ * @param {Number} seed
549
+ * @memberof Random */
550
+ const setRandSeed = (seed)=> randSeed = seed;
551
+
547
552
  /** Returns a seeded random value between the two values passed in using randSeed
548
553
  * @param {Number} [valueA=1]
549
554
  * @param {Number} [valueB=0]
@@ -571,6 +576,14 @@ const randSeeded = (a=1, b=0)=>
571
576
  */
572
577
  const vec2 = (x=0, y)=> x.x == undefined ? new Vector2(x, y == undefined? x : y) : new Vector2(x.x, x.y);
573
578
 
579
+ /**
580
+ * Check if object is a valid Vector2
581
+ * @param {Vector2} vector
582
+ * @return {Boolean}
583
+ * @memberof Utilities
584
+ */
585
+ const isVector2 = (v)=> !isNaN(v.x) && !isNaN(v.y);
586
+
574
587
  /**
575
588
  * 2D Vector object with vector math library
576
589
  * <br> - Functions do not change this so they can be chained together
@@ -600,27 +613,27 @@ class Vector2
600
613
  /** Returns a copy of this vector plus the vector passed in
601
614
  * @param {Vector2} vector
602
615
  * @return {Vector2} */
603
- add(v) { ASSERT(v.x!=undefined); return new Vector2(this.x + v.x, this.y + v.y); }
616
+ add(v) { ASSERT(isVector2(v)); return new Vector2(this.x + v.x, this.y + v.y); }
604
617
 
605
618
  /** Returns a copy of this vector minus the vector passed in
606
619
  * @param {Vector2} vector
607
620
  * @return {Vector2} */
608
- subtract(v) { ASSERT(v.x!=undefined); return new Vector2(this.x - v.x, this.y - v.y); }
621
+ subtract(v) { ASSERT(isVector2(v)); return new Vector2(this.x - v.x, this.y - v.y); }
609
622
 
610
623
  /** Returns a copy of this vector times the vector passed in
611
624
  * @param {Vector2} vector
612
625
  * @return {Vector2} */
613
- multiply(v) { ASSERT(v.x!=undefined); return new Vector2(this.x * v.x, this.y * v.y); }
626
+ multiply(v) { ASSERT(isVector2(v)); return new Vector2(this.x * v.x, this.y * v.y); }
614
627
 
615
628
  /** Returns a copy of this vector divided by the vector passed in
616
629
  * @param {Vector2} vector
617
630
  * @return {Vector2} */
618
- divide(v) { ASSERT(v.x!=undefined); return new Vector2(this.x / v.x, this.y / v.y); }
631
+ divide(v) { ASSERT(isVector2(v)); return new Vector2(this.x / v.x, this.y / v.y); }
619
632
 
620
633
  /** Returns a copy of this vector scaled by the vector passed in
621
634
  * @param {Number} scale
622
635
  * @return {Vector2} */
623
- scale(s) { ASSERT(s.x==undefined); return new Vector2(this.x * s, this.y * s); }
636
+ scale(s) { ASSERT(!isVector2(s)); return new Vector2(this.x * s, this.y * s); }
624
637
 
625
638
  /** Returns the length of this vector
626
639
  * @return {Number} */
@@ -653,12 +666,12 @@ class Vector2
653
666
  /** Returns the dot product of this and the vector passed in
654
667
  * @param {Vector2} vector
655
668
  * @return {Number} */
656
- dot(v) { ASSERT(v.x!=undefined); return this.x*v.x + this.y*v.y; }
669
+ dot(v) { ASSERT(isVector2(v)); return this.x*v.x + this.y*v.y; }
657
670
 
658
671
  /** Returns the cross product of this and the vector passed in
659
672
  * @param {Vector2} vector
660
673
  * @return {Number} */
661
- cross(v) { ASSERT(v.x!=undefined); return this.x*v.y - this.y*v.x; }
674
+ cross(v) { ASSERT(isVector2(v)); return this.x*v.y - this.y*v.x; }
662
675
 
663
676
  /** Returns the angle of this vector, up is angle 0
664
677
  * @return {Number} */
@@ -694,7 +707,7 @@ class Vector2
694
707
  * @param {Vector2} vector
695
708
  * @param {Number} percent
696
709
  * @return {Vector2} */
697
- lerp(v, p) { ASSERT(v.x!=undefined); return this.add(v.subtract(this).scale(clamp(p))); }
710
+ lerp(v, p) { ASSERT(isVector2(v)); return this.add(v.subtract(this).scale(clamp(p))); }
698
711
 
699
712
  /** Returns true if this vector is within the bounds of an array size passed in
700
713
  * @param {Vector2} arraySize
@@ -705,7 +718,7 @@ class Vector2
705
718
  * @param {float} digits - precision to display
706
719
  * @return {String} */
707
720
  toString(digits=3)
708
- { return `(${(this.x<0?'':' ') + this.x.toFixed(digits)},${(this.y<0?'':' ') + this.y.toFixed(digits)} )`; }
721
+ { if (debug) { return `(${(this.x<0?'':' ') + this.x.toFixed(digits)},${(this.y<0?'':' ') + this.y.toFixed(digits)} )`; }}
709
722
  }
710
723
 
711
724
  ///////////////////////////////////////////////////////////////////////////////
@@ -943,7 +956,7 @@ class Timer
943
956
 
944
957
  /** Returns this timer expressed as a string
945
958
  * @return {String} */
946
- toString() { if (debug) { return this.unset() ? 'unset' : Math.abs(this.get()) + ' seconds ' + (this.get()<0 ? 'before' : 'after' ); } }
959
+ toString() { if (debug) { return this.unset() ? 'unset' : Math.abs(this.get()) + ' seconds ' + (this.get()<0 ? 'before' : 'after' ); }}
947
960
 
948
961
  /** Get how long since elapsed, returns 0 if not set (returns negative if currently active)
949
962
  * @return {Number} */
@@ -956,6 +969,20 @@ class Timer
956
969
 
957
970
  'use strict';
958
971
 
972
+ ///////////////////////////////////////////////////////////////////////////////
973
+ // Camera settings
974
+
975
+ /** Position of camera in world space
976
+ * @type {Vector2}
977
+ * @default
978
+ * @memberof Settings */
979
+ let cameraPos = vec2();
980
+
981
+ /** Scale of camera in world space
982
+ * @default
983
+ * @memberof Settings */
984
+ let cameraScale = 16;
985
+
959
986
  ///////////////////////////////////////////////////////////////////////////////
960
987
  // Display settings
961
988
 
@@ -982,6 +1009,19 @@ let cavasPixelated = 1;
982
1009
  * @memberof Settings */
983
1010
  let fontDefault = 'arial';
984
1011
 
1012
+ ///////////////////////////////////////////////////////////////////////////////
1013
+ // WebGL settings
1014
+
1015
+ /** Enable webgl rendering, webgl can be disabled and removed from build (with some features disabled)
1016
+ * @default
1017
+ * @memberof Settings */
1018
+ let glEnable = 1;
1019
+
1020
+ /** Fixes slow rendering in some browsers by not compositing the WebGL canvas
1021
+ * @default
1022
+ * @memberof Settings */
1023
+ let glOverlay = 1;
1024
+
985
1025
  ///////////////////////////////////////////////////////////////////////////////
986
1026
  // Tile sheet settings
987
1027
 
@@ -1050,33 +1090,6 @@ let gravity = 0;
1050
1090
  * @memberof Settings */
1051
1091
  let particleEmitRateScale = 1;
1052
1092
 
1053
- ///////////////////////////////////////////////////////////////////////////////
1054
- // Camera settings
1055
-
1056
- /** Position of camera in world space
1057
- * @type {Vector2}
1058
- * @default
1059
- * @memberof Settings */
1060
- let cameraPos = vec2();
1061
-
1062
- /** Scale of camera in world space
1063
- * @default
1064
- * @memberof Settings */
1065
- let cameraScale = max(tileSizeDefault.x, tileSizeDefault.y);
1066
-
1067
- ///////////////////////////////////////////////////////////////////////////////
1068
- // WebGL settings
1069
-
1070
- /** Enable webgl rendering, webgl can be disabled and removed from build (with some features disabled)
1071
- * @default
1072
- * @memberof Settings */
1073
- let glEnable = 1;
1074
-
1075
- /** Fixes slow rendering in some browsers by not compositing the WebGL canvas
1076
- * @default
1077
- * @memberof Settings */
1078
- let glOverlay = 1;
1079
-
1080
1093
  ///////////////////////////////////////////////////////////////////////////////
1081
1094
  // Input settings
1082
1095
 
@@ -1217,7 +1230,7 @@ class EngineObject
1217
1230
  constructor(pos=vec2(), size=objectDefaultSize, tileIndex=-1, tileSize=tileSizeDefault, angle=0, color, renderOrder=0)
1218
1231
  {
1219
1232
  // set passed in params
1220
- ASSERT(pos && pos.x != undefined && size.x != undefined); // ensure pos and size are vec2s
1233
+ ASSERT(isVector2(pos) && isVector2(size)); // ensure pos and size are vec2s
1221
1234
 
1222
1235
  /** @property {Vector2} - World space position of the object */
1223
1236
  this.pos = pos.copy();
@@ -1307,7 +1320,7 @@ class EngineObject
1307
1320
  if (this.collideSolidObjects)
1308
1321
  {
1309
1322
  // check collisions against solid objects
1310
- const epsilon = 1e-3; // necessary to push slightly outside of the collision
1323
+ const epsilon = .001; // necessary to push slightly outside of the collision
1311
1324
  for (const o of engineObjectsCollide)
1312
1325
  {
1313
1326
  // non solid objects don't collide with eachother
@@ -1570,11 +1583,6 @@ class EngineObject
1570
1583
 
1571
1584
  'use strict';
1572
1585
 
1573
- /** Tile sheet for batch rendering system
1574
- * @type {Image}
1575
- * @memberof Draw */
1576
- const tileImage = new Image();
1577
-
1578
1586
  /** The primary 2D canvas visible to the user
1579
1587
  * @type {HTMLCanvasElement}
1580
1588
  * @memberof Draw */
@@ -1600,6 +1608,14 @@ let overlayContext;
1600
1608
  * @memberof Draw */
1601
1609
  let mainCanvasSize = vec2();
1602
1610
 
1611
+ /** Tile sheet for batch rendering system
1612
+ * @type {Image}
1613
+ * @memberof Draw */
1614
+ const tileImage = new Image;
1615
+
1616
+ // Engine internal variables not exposed to documentation
1617
+ let tileImageSize, tileImageFixBleed, drawCount;
1618
+
1603
1619
  /** Convert from screen to world space coordinates
1604
1620
  * - if calling outside of render, you may need to manually set mainCanvasSize
1605
1621
  * @param {Vector2} screenPos
@@ -1624,7 +1640,7 @@ const worldToScreen = (worldPos)=>
1624
1640
 
1625
1641
  /** Draw textured tile centered in world space, with color applied if using WebGL
1626
1642
  * @param {Vector2} pos - Center of the tile in world space
1627
- * @param {Vector2} [size=new Vector2(1,1)] - Size of the tile in world space, width and height
1643
+ * @param {Vector2} [size=new Vector2(1,1)] - Size of the tile in world space
1628
1644
  * @param {Number} [tileIndex=-1] - Tile index to use, negative is untextured
1629
1645
  * @param {Vector2} [tileSize=tileSizeDefault] - Tile size in source pixels
1630
1646
  * @param {Color} [color=new Color(1,1,1)] - Color to modulate with
@@ -1843,10 +1859,10 @@ class FontImage
1843
1859
  */
1844
1860
  constructor(image, tileSize=vec2(8), paddingSize=vec2(0,1), startTileIndex=0, context=overlayContext)
1845
1861
  {
1846
- if (!image && !engineFontImage)
1862
+ if (!engineFontImage)
1847
1863
  {
1848
1864
  // load default font image
1849
- engineFontImage = new Image();
1865
+ engineFontImage = new Image;
1850
1866
  engineFontImage.src = 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAQAAAAAYAQAAAAA9+x6JAAAAAnRSTlMAAHaTzTgAAAGiSURBVHjaZZABhxxBEIUf6ECLBdFY+Q0PMNgf0yCgsSAGZcT9sgIPtBWwIA5wgAPEoHUyJeeSlW+gjK+fegWwtROWpVQEyWh2npdpBmTUFVhb29RINgLIukoXr5LIAvYQ5ve+1FqWEMqNKTX3FAJHyQDRZvmKWubAACcv5z5Gtg2oyCWE+Yk/8JZQX1jTTCpKAFGIgza+dJCNBF2UskRlsgwitHbSV0QLgt9sTPtsRlvJjEr8C/FARWA2bJ/TtJ7lko34dNDn6usJUMzuErP89UUBJbWeozrwLLncXczd508deAjLWipLO4Q5XGPcJvPu92cNDaN0P5G1FL0nSOzddZOrJ6rNhbXGmeDvO3TF7DeJWl4bvaYQTNHCTeuqKZmbjHaSOFes+IX/+IhHrnAkXOAsfn24EM68XieIECoccD4KZLk/odiwzeo2rovYdhvb2HYFgyznJyDpYJdYOmfXgVdJTaUi4xA2uWYNYec9BLeqdl9EsoTw582mSFDX2DxVLbNt9U3YYoeatBad1c2Tj8t2akrjaIGJNywKB/7h75/gN3vCMSaadIUTAAAAAElFTkSuQmCC';
1851
1867
  }
1852
1868
 
@@ -1913,7 +1929,7 @@ class FontImage
1913
1929
  /** Returns true if fullscreen mode is active
1914
1930
  * @return {Boolean}
1915
1931
  * @memberof Draw */
1916
- const isFullscreen =()=> document.fullscreenElement;
1932
+ const isFullscreen = ()=> document.fullscreenElement;
1917
1933
 
1918
1934
  /** Toggle fullsceen mode
1919
1935
  * @memberof Draw */
@@ -1923,16 +1939,9 @@ function toggleFullscreen()
1923
1939
  {
1924
1940
  if (document.exitFullscreen)
1925
1941
  document.exitFullscreen();
1926
- else if (document.mozCancelFullScreen)
1927
- document.mozCancelFullScreen();
1928
- }
1929
- else
1930
- {
1931
- if (document.body.webkitRequestFullScreen)
1932
- document.body.webkitRequestFullScreen();
1933
- else if (document.body.mozRequestFullScreen)
1934
- document.body.mozRequestFullScreen();
1935
1942
  }
1943
+ else if (document.body.requestFullscreen)
1944
+ document.body.requestFullscreen();
1936
1945
  }
1937
1946
 
1938
1947
  /**
@@ -1951,7 +1960,7 @@ function toggleFullscreen()
1951
1960
  * @param {Number} [device=0]
1952
1961
  * @return {Boolean}
1953
1962
  * @memberof Input */
1954
- const keyIsDown = (key, device=0)=> inputData[device] && inputData[device][key] & 1 ? 1 : 0;
1963
+ const keyIsDown = (key, device=0)=> inputData[device] && inputData[device][key] & 1;
1955
1964
 
1956
1965
  /** Returns true if device key was pressed this frame
1957
1966
  * @param {Number} key
@@ -2191,35 +2200,40 @@ const isTouchDevice = window.ontouchstart !== undefined;
2191
2200
  if (isTouchDevice)
2192
2201
  {
2193
2202
  // override mouse events
2194
- const mouseDown = onmousedown, mouseUp = onmouseup, mouseMove = onmousemove;
2195
- onmousedown = onmouseup = onmousemove = (e)=> 0;
2203
+ let wasTouching, mouseDown = onmousedown, mouseUp = onmouseup;
2204
+ onmousedown = onmouseup = ()=> 0;
2196
2205
 
2197
- // handle all touch events the same way
2198
- let wasTouching, hadTouch;
2199
- ontouchstart = ontouchmove = ontouchend = (e)=>
2206
+ // setup touch input
2207
+ ontouchstart = (e)=>
2200
2208
  {
2201
- e.button = 0; // all touches are left click
2209
+ // fix mobile audio, force it to play a sound on first touch
2210
+ zzfx(0);
2202
2211
 
2203
- // check if touching and pass to mouse events
2204
- const touching = e.touches.length;
2205
- if (touching)
2212
+ // handle all touch events the same way
2213
+ ontouchstart = ontouchmove = ontouchend = (e)=>
2206
2214
  {
2207
- // fix mobile audio, force it to play a sound on first touch
2208
- hadTouch || zzfx(0, hadTouch=1);
2215
+ e.button = 0; // all touches are left click
2209
2216
 
2210
- // set event pos and pass it along
2211
- e.x = e.touches[0].clientX;
2212
- e.y = e.touches[0].clientY;
2213
- wasTouching ? mouseMove(e) : mouseDown(e);
2214
- }
2215
- else if (wasTouching)
2216
- mouseUp(e);
2217
+ // check if touching and pass to mouse events
2218
+ const touching = e.touches.length;
2219
+ if (touching)
2220
+ {
2221
+ // set event pos and pass it along
2222
+ e.x = e.touches[0].clientX;
2223
+ e.y = e.touches[0].clientY;
2224
+ wasTouching ? onmousemove(e) : mouseDown(e);
2225
+ }
2226
+ else if (wasTouching)
2227
+ mouseUp(e);
2217
2228
 
2218
- // set was touching
2219
- wasTouching = touching;
2229
+ // set was touching
2230
+ wasTouching = touching;
2231
+
2232
+ // must return true so the document will get focus
2233
+ return true;
2234
+ }
2220
2235
 
2221
- // must return true so the document will get focus
2222
- return true;
2236
+ return ontouchstart(e);
2223
2237
  }
2224
2238
  }
2225
2239
 
@@ -2227,7 +2241,7 @@ if (isTouchDevice)
2227
2241
  // touch gamepad, virtual on screen gamepad emulator for touch devices
2228
2242
 
2229
2243
  // touch input internal variables
2230
- let touchGamepadTimer = new Timer, touchGamepadButtons = [], touchGamepadStick = vec2();
2244
+ let touchGamepadTimer = new Timer, touchGamepadButtons, touchGamepadStick;
2231
2245
 
2232
2246
  // create the touch gamepad, called automatically by the engine
2233
2247
  function touchGamepadCreate()
@@ -2235,65 +2249,73 @@ function touchGamepadCreate()
2235
2249
  if (!touchGamepadEnable || !isTouchDevice)
2236
2250
  return;
2237
2251
 
2238
- ontouchstart = ontouchmove = ontouchend = (e)=>
2252
+ // touch input internal variables
2253
+ touchGamepadButtons = [];
2254
+ touchGamepadStick = vec2();
2255
+
2256
+ // setup touch input
2257
+ ontouchstart = (e)=>
2239
2258
  {
2240
- if (!touchGamepadEnable)
2241
- return;
2259
+ // fix mobile audio, force it to play a sound on first touch
2260
+ zzfx(0);
2242
2261
 
2243
- // clear touch gamepad input
2244
- touchGamepadStick = vec2();
2245
- touchGamepadButtons = [];
2246
-
2247
- const touching = e.touches.length;
2248
- if (touching)
2262
+ ontouchstart = ontouchmove = ontouchend = (e)=>
2249
2263
  {
2250
- touchGamepadTimer.isSet() || zzfx(0) ; // fix mobile audio, force it to play a sound the first time
2251
-
2252
- // set that gamepad is active
2253
- isUsingGamepad = 1;
2254
- touchGamepadTimer.set();
2255
-
2256
- if (paused)
2264
+ // clear touch gamepad input
2265
+ touchGamepadStick = vec2();
2266
+ touchGamepadButtons = [];
2267
+
2268
+ const touching = e.touches.length;
2269
+ if (touching)
2257
2270
  {
2258
- // touch anywhere to press start when paused
2259
- touchGamepadButtons[9] = 1;
2260
- return;
2271
+ // set that gamepad is active
2272
+ isUsingGamepad = 1;
2273
+ touchGamepadTimer.set();
2274
+
2275
+ if (paused)
2276
+ {
2277
+ // touch anywhere to press start when paused
2278
+ touchGamepadButtons[9] = 1;
2279
+ return;
2280
+ }
2261
2281
  }
2262
- }
2263
2282
 
2264
- // get center of left and right sides
2265
- const stickCenter = vec2(touchGamepadSize, mainCanvasSize.y-touchGamepadSize);
2266
- const buttonCenter = mainCanvasSize.subtract(vec2(touchGamepadSize, touchGamepadSize));
2267
- const startCenter = mainCanvasSize.scale(.5);
2283
+ // get center of left and right sides
2284
+ const stickCenter = vec2(touchGamepadSize, mainCanvasSize.y-touchGamepadSize);
2285
+ const buttonCenter = mainCanvasSize.subtract(vec2(touchGamepadSize, touchGamepadSize));
2286
+ const startCenter = mainCanvasSize.scale(.5);
2268
2287
 
2269
- // check each touch point
2270
- for (const touch of e.touches)
2271
- {
2272
- const touchPos = mouseToScreen(vec2(touch.clientX, touch.clientY));
2273
- if (touchPos.distance(stickCenter) < touchGamepadSize)
2288
+ // check each touch point
2289
+ for (const touch of e.touches)
2274
2290
  {
2275
- // virtual analog stick
2276
- if (touchGamepadAnalog)
2277
- touchGamepadStick = touchPos.subtract(stickCenter).scale(2/touchGamepadSize).clampLength();
2278
- else
2291
+ const touchPos = mouseToScreen(vec2(touch.clientX, touch.clientY));
2292
+ if (touchPos.distance(stickCenter) < touchGamepadSize)
2293
+ {
2294
+ // virtual analog stick
2295
+ if (touchGamepadAnalog)
2296
+ touchGamepadStick = touchPos.subtract(stickCenter).scale(2/touchGamepadSize).clampLength();
2297
+ else
2298
+ {
2299
+ // 8 way dpad
2300
+ const angle = touchPos.subtract(stickCenter).angle();
2301
+ touchGamepadStick.setAngle((angle * 4 / PI + 8.5 | 0) * PI / 4);
2302
+ }
2303
+ }
2304
+ else if (touchPos.distance(buttonCenter) < touchGamepadSize)
2279
2305
  {
2280
- // 8 way dpad
2281
- const angle = touchPos.subtract(stickCenter).angle();
2282
- touchGamepadStick.setAngle((angle * 4 / PI + 8.5 | 0) * PI / 4);
2306
+ // virtual face buttons
2307
+ const button = touchPos.subtract(buttonCenter).direction();
2308
+ touchGamepadButtons[button] = 1;
2309
+ }
2310
+ else if (touchPos.distance(startCenter) < touchGamepadSize)
2311
+ {
2312
+ // virtual start button in center
2313
+ touchGamepadButtons[9] = 1;
2283
2314
  }
2284
- }
2285
- else if (touchPos.distance(buttonCenter) < touchGamepadSize)
2286
- {
2287
- // virtual face buttons
2288
- const button = touchPos.subtract(buttonCenter).direction();
2289
- touchGamepadButtons[button] = 1;
2290
- }
2291
- else if (touchPos.distance(startCenter) < touchGamepadSize)
2292
- {
2293
- // virtual start button in center
2294
- touchGamepadButtons[9] = 1;
2295
2315
  }
2296
2316
  }
2317
+
2318
+ return ontouchstart(e);
2297
2319
  }
2298
2320
  }
2299
2321
 
@@ -2411,7 +2433,7 @@ class Sound
2411
2433
  {
2412
2434
  if (!soundEnable) return;
2413
2435
 
2414
- let pan = 0;
2436
+ let pan;
2415
2437
  if (pos)
2416
2438
  {
2417
2439
  const range = this.range;
@@ -2441,7 +2463,7 @@ class Sound
2441
2463
  * @param {Number} [volume=1] - How much to scale volume by (in addition to range fade)
2442
2464
  * @return {AudioBufferSourceNode} - The audio, can be used to stop sound later
2443
2465
  */
2444
- playNote(semitoneOffset, pos, volume=1)
2466
+ playNote(semitoneOffset, pos, volume)
2445
2467
  {
2446
2468
  if (!soundEnable) return;
2447
2469
 
@@ -2496,7 +2518,7 @@ class Music
2496
2518
  * @param {Boolean} [loop=1] - True if the music should loop when it reaches the end
2497
2519
  * @return {AudioBufferSourceNode} - The audio node, can be used to stop sound later
2498
2520
  */
2499
- play(volume = 1, loop = 1)
2521
+ play(volume, loop = 1)
2500
2522
  {
2501
2523
  if (!soundEnable) return;
2502
2524
 
@@ -2578,7 +2600,7 @@ function playSamples(sampleChannels, volume=1, rate=1, pan=0, loop=0)
2578
2600
 
2579
2601
  // create audio context
2580
2602
  if (!audioContext)
2581
- audioContext = new (window.AudioContext||webkitAudioContext);
2603
+ audioContext = new AudioContext;
2582
2604
 
2583
2605
  // fix stalled audio
2584
2606
  audioContext.resume();
@@ -2597,18 +2619,13 @@ function playSamples(sampleChannels, volume=1, rate=1, pan=0, loop=0)
2597
2619
  source.playbackRate.value = rate;
2598
2620
  source.loop = loop;
2599
2621
 
2600
- // create and connect gain node (createGain is more widley spported then GainNode construtor)
2622
+ // create and connect gain node (createGain is more widely spported then GainNode construtor)
2601
2623
  const gainNode = audioContext.createGain();
2602
2624
  gainNode.gain.value = soundVolume*volume;
2603
2625
  gainNode.connect(audioContext.destination);
2604
2626
 
2605
- // connect source to gain
2606
- (
2607
- window.StereoPannerNode ? // create pan node if possible
2608
- source.connect(new StereoPannerNode(audioContext, {'pan':clamp(pan, -1, 1)}))
2609
- : source
2610
- )
2611
- .connect(gainNode);
2627
+ // connect source to stereo panner and gain
2628
+ source.connect(new StereoPannerNode(audioContext, {'pan':clamp(pan, -1, 1)})).connect(gainNode);
2612
2629
 
2613
2630
  // play and return sound
2614
2631
  source.start();
@@ -2726,10 +2743,8 @@ function zzfxG
2726
2743
  * @memberof Audio */
2727
2744
  function zzfxM(instruments, patterns, sequence, BPM = 125)
2728
2745
  {
2746
+ let i, j, k;
2729
2747
  let instrumentParameters;
2730
- let i;
2731
- let j;
2732
- let k;
2733
2748
  let note;
2734
2749
  let sample;
2735
2750
  let patternChannel;
@@ -2899,14 +2914,11 @@ function tileCollisionRaycast(posStart, posEnd, object)
2899
2914
  {
2900
2915
  // test if a ray collides with tiles from start to end
2901
2916
  // todo: a way to get the exact hit point, it must still register as inside the hit tile
2902
- posStart = posStart.floor();
2903
- posEnd = posEnd.floor();
2904
- const posDelta = posEnd.subtract(posStart);
2917
+ const posDelta = (posEnd = posEnd.floor()).subtract(posStart = posStart.floor());
2905
2918
  const dx = abs(posDelta.x), dy = -abs(posDelta.y);
2906
2919
  const sx = sign(posDelta.x), sy = sign(posDelta.y);
2907
- let e = dx + dy;
2908
2920
 
2909
- for (let x = posStart.x, y = posStart.y;;)
2921
+ for (let x = posStart.x, y = posStart.y, e = dx + dy;;)
2910
2922
  {
2911
2923
  const tileData = getTileCollisionData(vec2(x,y));
2912
2924
  if (tileData && (object ? object.collideWithTileRaycast(tileData, new Vector2(x, y)) : tileData > 0))
@@ -2998,7 +3010,7 @@ constructor(pos, size=tileCollisionSize, tileSize=tileSizeDefault, scale=vec2(1)
2998
3010
  // init tile data
2999
3011
  this.data = [];
3000
3012
  for (let j = this.size.area(); j--;)
3001
- this.data.push(new TileLayerData());
3013
+ this.data.push(new TileLayerData);
3002
3014
  }
3003
3015
 
3004
3016
  /** Set data at a given position in the array
@@ -3054,21 +3066,23 @@ constructor(pos, size=tileCollisionSize, tileSize=tileSizeDefault, scale=vec2(1)
3054
3066
  * @param {Boolean} [clear=0] - Should it clear the canvas before drawing */
3055
3067
  redrawStart(clear = 0)
3056
3068
  {
3057
- if (clear)
3058
- {
3059
- // clear and set size
3060
- this.canvas.width = this.size.x * this.tileSize.x;
3061
- this.canvas.height = this.size.y * this.tileSize.y;
3062
- }
3063
-
3064
3069
  // save current render settings
3065
- this.savedRenderSettings = [mainCanvas, mainContext, cameraPos, cameraScale];
3070
+ this.savedRenderSettings = [mainCanvas, mainContext, mainCanvasSize, cameraPos, cameraScale];
3066
3071
 
3067
- // use normal rendering system to render the tiles
3072
+ // hack: use normal rendering system to render the tiles
3068
3073
  mainCanvas = this.canvas;
3069
3074
  mainContext = this.context;
3070
3075
  cameraPos = this.size.scale(.5);
3071
3076
  cameraScale = this.tileSize.x;
3077
+
3078
+ if (clear)
3079
+ {
3080
+ // clear and set size
3081
+ mainCanvas.width = this.size.x * this.tileSize.x;
3082
+ mainCanvas.height = this.size.y * this.tileSize.y;
3083
+ }
3084
+
3085
+ // begin a new render for the tile canvas
3072
3086
  enginePreRender();
3073
3087
  }
3074
3088
 
@@ -3080,7 +3094,7 @@ constructor(pos, size=tileCollisionSize, tileSize=tileSizeDefault, scale=vec2(1)
3080
3094
  //debugSaveCanvas(this.canvas);
3081
3095
 
3082
3096
  // set stuff back to normal
3083
- [mainCanvas, mainContext, cameraPos, cameraScale] = this.savedRenderSettings;
3097
+ [mainCanvas, mainContext, mainCanvasSize, cameraPos, cameraScale] = this.savedRenderSettings;
3084
3098
  }
3085
3099
 
3086
3100
  /** Draw the tile at a given position
@@ -3321,7 +3335,7 @@ class ParticleEmitter extends EngineObject
3321
3335
  this.parent && super.update();
3322
3336
 
3323
3337
  // update emitter
3324
- if (!this.emitTime || this.getAliveTime() <= this.emitTime)
3338
+ if (!this.emitTime | this.getAliveTime() <= this.emitTime)
3325
3339
  {
3326
3340
  // emit particles
3327
3341
  if (this.emitRate * particleEmitRateScale)
@@ -3343,9 +3357,9 @@ class ParticleEmitter extends EngineObject
3343
3357
  {
3344
3358
  // spawn a particle
3345
3359
  let pos = this.emitSize.x != undefined ? // check if vec2 was used for size
3346
- (new Vector2(rand(-.5,.5), rand(-.5,.5)))
3347
- .multiply(this.emitSize).rotate(this.angle) // box emitter
3348
- : randInCircle(this.emitSize * .5); // circle emitter
3360
+ (new Vector2(rand(-1,1), rand(-1,1)))
3361
+ .multiply(this.emitSize/2).rotate(this.angle) // box emitter
3362
+ : randInCircle(this.emitSize/2); // circle emitter
3349
3363
  let angle = rand(this.particleConeAngle, -this.particleConeAngle);
3350
3364
  if (!this.localSpace)
3351
3365
  {
@@ -3388,7 +3402,7 @@ class ParticleEmitter extends EngineObject
3388
3402
  particle.additive = this.additive;
3389
3403
  particle.renderOrder = this.renderOrder;
3390
3404
  particle.trailScale = this.trailScale;
3391
- particle.mirror = rand()<.5;
3405
+ particle.mirror = randInt(2);
3392
3406
  particle.localSpaceEmitter = this.localSpace && this;
3393
3407
 
3394
3408
  // setup callbacks for particles
@@ -3417,7 +3431,8 @@ class Particle extends EngineObject
3417
3431
  * @param {Vector2} [tileSize=tileSizeDefault] - Size of tile in source pixels
3418
3432
  * @param {Number} [angle=0] - Angle to rotate the particle
3419
3433
  */
3420
- constructor(pos, tileIndex, tileSize, angle) { super(pos, new Vector2, tileIndex, tileSize, angle); }
3434
+ constructor(pos, tileIndex, tileSize, angle)
3435
+ { super(pos, new Vector2, tileIndex, tileSize, angle); }
3421
3436
 
3422
3437
  /** Render the particle, automatically called each frame, sorted by renderOrder */
3423
3438
  render()
@@ -3537,7 +3552,7 @@ class Medal
3537
3552
  this.name = name;
3538
3553
  this.description = description;
3539
3554
  this.icon = icon;
3540
- this.image = new Image();
3555
+ this.image = new Image;
3541
3556
  if (src)
3542
3557
  this.image.src = src;
3543
3558
  }
@@ -3552,10 +3567,7 @@ class Medal
3552
3567
  ASSERT(medalsSaveName); // save name must be set
3553
3568
  localStorage[this.storageKey()] = this.unlocked = 1;
3554
3569
  medalsDisplayQueue.push(this);
3555
-
3556
- // save for newgrounds and OS13K
3557
3570
  newgrounds && newgrounds.unlockMedal(this.id);
3558
- localStorage['OS13kTrophy,' + this.icon + ',' + medalsSaveName + ',' + this.name] = this.description;
3559
3571
  }
3560
3572
 
3561
3573
  /** Render a medal
@@ -3571,20 +3583,19 @@ class Medal
3571
3583
  // draw containing rect and clip to that region
3572
3584
  context.save();
3573
3585
  context.beginPath();
3574
- context.fillStyle = '#ddd'
3575
- context.fill(context.rect(x, y, width, medalDisplayHeight));
3576
- context.strokeStyle = '#000';
3586
+ context.fillStyle = new Color(.9,.9,.9);
3587
+ context.strokeStyle = new Color(0,0,0);
3577
3588
  context.lineWidth = 3;
3589
+ context.fill(context.rect(x, y, width, medalDisplayHeight));
3578
3590
  context.stroke();
3579
3591
  context.clip();
3580
3592
 
3581
3593
  // draw the icon and text
3582
- this.renderIcon(x+15+medalDisplayIconSize/2, y+medalDisplayHeight/2);
3583
- context.textAlign = 'left';
3584
- context.font = '38px '+ fontDefault;
3585
- context.fillText(this.name, x+medalDisplayIconSize+30, y+28);
3586
- context.font = '24px '+ fontDefault;
3587
- context.fillText(this.description, x+medalDisplayIconSize+30, y+60);
3594
+ this.renderIcon(vec2(x+15+medalDisplayIconSize/2, y+medalDisplayHeight/2));
3595
+ const pos = vec2(x+medalDisplayIconSize+30, y+28);
3596
+ drawTextScreen(this.name, pos, 38, new Color(0,0,0), 0, 0, 'left');
3597
+ pos.y += 32;
3598
+ drawTextScreen(this.description, pos, 24, new Color(0,0,0), 0, 0, 'left');
3588
3599
  context.restore();
3589
3600
  }
3590
3601
 
@@ -3593,18 +3604,13 @@ class Medal
3593
3604
  * @param {Number} y - Screen space Y position
3594
3605
  * @param {Number} [size=medalDisplayIconSize] - Screen space size
3595
3606
  */
3596
- renderIcon(x, y, size=medalDisplayIconSize)
3607
+ renderIcon(pos, size=medalDisplayIconSize)
3597
3608
  {
3598
3609
  // draw the image or icon
3599
- const context = overlayContext;
3600
- context.fillStyle = '#000';
3601
- context.textAlign = 'center';
3602
- context.textBaseline = 'middle';
3603
- context.font = size*.7 + 'px '+ fontDefault;
3604
- if (this.image.src)
3605
- context.drawImage(this.image, x-size/2, y-size/2, size, size);
3610
+ if (this.image)
3611
+ overlayContext.drawImage(this.image, pos.x-size/2, pos.y-size/2, size, size);
3606
3612
  else
3607
- context.fillText(this.icon, x, y); // show icon if there is no image
3613
+ drawTextScreen(this.icon, pos, size*.7, new Color(0,0,0));
3608
3614
  }
3609
3615
 
3610
3616
  // Get local storage key used by the medal
@@ -3662,13 +3668,21 @@ class Newgrounds
3662
3668
  constructor(app_id, cipher)
3663
3669
  {
3664
3670
  ASSERT(!newgrounds && app_id);
3671
+
3672
+ // create an instance of CryptoJS for encrypted calls
3673
+ if (cipher)
3674
+ {
3675
+ ///////////////////////////////////////////////////////////////////////////////
3676
+ // Crypto-JS - https://github.com/brix/crypto-js [The MIT License (MIT)]
3677
+ // Copyright (c) 2009-2013 Jeff Mott Copyright (c) 2013-2016 Evan Vosberg
3678
+
3679
+ this.cryptoJS = eval(Function("[M='GBMGXz^oVYPPKKbB`agTXU|LxPc_ZBcMrZvCr~wyGfWrwk@ATqlqeTp^N?p{we}jIpEnB_sEr`l?YDkDhWhprc|Er|XETG?pTl`e}dIc[_N~}fzRycIfpW{HTolvoPB_FMe_eH~BTMx]yyOhv?biWPCGc]kABencBhgERHGf{OL`Dj`c^sh@canhy[secghiyotcdOWgO{tJIE^JtdGQRNSCrwKYciZOa]Y@tcRATYKzv|sXpboHcbCBf`}SKeXPFM|RiJsSNaIb]QPc[D]Jy_O^XkOVTZep`ONmntLL`Qz~UupHBX_Ia~WX]yTRJIxG`ioZ{fefLJFhdyYoyLPvqgH?b`[TMnTwwfzDXhfM?rKs^aFr|nyB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Mz?eqre`HiE@vNwBulglmQjj]DB@pPkPUgA^sjOAUNdSu_`oAzar?n?eMnw{{hYmslYi[TnlJD'",...']charCodeAtUinyxpf',"for(;e<10359;c[e++]=p-=128,A=A?p-A&&A:p==34&&p)for(p=1;p<128;y=f.map((n,x)=>(U=r[n]*2+1,U=Math.log(U/(h-U)),t-=a[x]*U,U/500)),t=~-h/(1+Math.exp(t))|1,i=o%h<t,o=o%h+(i?t:h-t)*(o>>17)-!i*t,f.map((n,x)=>(U=r[n]+=(i*h/2-r[n]<<13)/((C[n]+=C[n]<5)+1/20)>>13,a[x]+=y[x]*(i-t/h))),p=p*2+i)for(f='010202103203210431053105410642065206541'.split(t=0).map((n,x)=>(U=0,[...n].map((n,x)=>(U=U*997+(c[e-n]|0)|0)),h*32-1&U*997+p+!!A*129)*12+x);o<h*32;o=o*64|M.charCodeAt(d++)&63);for(C=String.fromCharCode(...c);r=/[\0-#?@\\\\~]/.exec(C);)with(C.split(r))C=join(shift());return C")([],[],1<<17,[0,0,0,0,0,0,0,0,0,0,0,0],new Uint16Array(51e6).fill(1<<15),new Uint8Array(51e6),0,0,0,0));
3680
+ }
3681
+
3665
3682
  this.app_id = app_id;
3666
3683
  this.cipher = cipher;
3667
3684
  this.host = location ? location.hostname : '';
3668
3685
 
3669
- // create an instance of CryptoJS for encrypted calls
3670
- cipher && (this.cryptoJS = CryptoJS());
3671
-
3672
3686
  // get session id from url search params
3673
3687
  const url = new URL(location.href);
3674
3688
  this.session_id = url.searchParams.get('ngio_session_id') || 0;
@@ -3771,12 +3785,6 @@ class Newgrounds
3771
3785
  return xmlHttp.responseText && JSON.parse(xmlHttp.responseText);
3772
3786
  }
3773
3787
  }
3774
-
3775
- ///////////////////////////////////////////////////////////////////////////////
3776
- // Crypto-JS - https://github.com/brix/crypto-js [The MIT License (MIT)]
3777
- // Copyright (c) 2009-2013 Jeff Mott Copyright (c) 2013-2016 Evan Vosberg
3778
-
3779
- const CryptoJS=()=>eval(Function("[M='GBMGXz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xUkDFagMnE{zHug{b`A~IYcQYBF_E}wiA}K@yxWHrZ{[d~|ARsYsjeNWzkMs~IOqqp[yzDE|WFrivsidTcnbHFRoW@XpAV`lv_zj?B~tPCppRjgbbDTALeFaOf?VcjnKTQMLyp{NwdylHCqmo?oelhjWuXj~}{fpuX`fra?GNkDiChYgVSh{R[BgF~eQa^WVz}ATI_CpY?g_diae]|ijH`TyNIF}|D_xpmBq_JpKih{Ba|sWzhnAoyraiDvk`h{qbBfsylBGmRH}DRPdryEsSaKS~tIaeF[s]I~xxHVrcNe@Jjxa@jlhZueLQqHh_]twVMqG_EGuwyab{nxOF?`HCle}nBZzlTQjkLmoXbXhOtBglFoMz?eqre`HiE@vNwBulglmQjj]DB@pPkPUgA^sjOAUNdSu_`oAzar?n?eMnw{{hYmslYi[TnlJD'",...']charCodeAtUinyxpf',"for(;e<10359;c[e++]=p-=128,A=A?p-A&&A:p==34&&p)for(p=1;p<128;y=f.map((n,x)=>(U=r[n]*2+1,U=Math.log(U/(h-U)),t-=a[x]*U,U/500)),t=~-h/(1+Math.exp(t))|1,i=o%h<t,o=o%h+(i?t:h-t)*(o>>17)-!i*t,f.map((n,x)=>(U=r[n]+=(i*h/2-r[n]<<13)/((C[n]+=C[n]<5)+1/20)>>13,a[x]+=y[x]*(i-t/h))),p=p*2+i)for(f='010202103203210431053105410642065206541'.split(t=0).map((n,x)=>(U=0,[...n].map((n,x)=>(U=U*997+(c[e-n]|0)|0)),h*32-1&U*997+p+!!A*129)*12+x);o<h*32;o=o*64|M.charCodeAt(d++)&63);for(C=String.fromCharCode(...c);r=/[\0-#?@\\\\~]/.exec(C);)with(C.split(r))C=join(shift());return C")([],[],1<<17,[0,0,0,0,0,0,0,0,0,0,0,0],new Uint16Array(51e6).fill(1<<15),new Uint8Array(51e6),0,0,0,0));
3780
3788
  /**
3781
3789
  * LittleJS WebGL Interface
3782
3790
  * <br> - All webgl used by the engine is wrapped up here
@@ -3806,7 +3814,7 @@ let glContext;
3806
3814
  let glTileTexture;
3807
3815
 
3808
3816
  // WebGL internal variables not exposed to documentation
3809
- let glActiveTexture, glShader, glArrayBuffer, glVertexData, glPositionData, glColorData, glBatchCount, glBatchAdditive, glAdditive;
3817
+ let glActiveTexture, glShader, glArrayBuffer, glPositionData, glColorData, glBatchCount, glBatchAdditive, glAdditive;
3810
3818
 
3811
3819
  ///////////////////////////////////////////////////////////////////////////////
3812
3820
 
@@ -3827,27 +3835,25 @@ function glInit()
3827
3835
  'uniform mat4 m;'+ // transform matrix
3828
3836
  'attribute vec2 p,t;'+ // position, uv
3829
3837
  'attribute vec4 c,a;'+ // color, additiveColor
3830
- 'varying vec2 v;'+ // return uv
3831
- 'varying vec4 d,e;'+ // return color, additiveColor
3838
+ 'varying vec4 v,d,e;'+ // return uv, color, additiveColor
3832
3839
  'void main(){'+ // shader entry point
3833
3840
  'gl_Position=m*vec4(p,1,1);'+ // transform position
3834
- 'v=t;d=c;e=a;'+ // pass stuff to fragment shader
3841
+ 'v=vec4(t,p);d=c;e=a;'+ // pass stuff to fragment shader
3835
3842
  '}' // end of shader
3836
3843
  ,
3837
- 'precision highp float;'+ // use highp for better accuracy
3838
- 'varying vec2 v;'+ // uv
3839
- 'varying vec4 d,e;'+ // color, additiveColor
3840
- 'uniform sampler2D s;'+ // texture
3841
- 'void main(){'+ // shader entry point
3842
- 'gl_FragColor=texture2D(s,v)*d+e;'+ // modulate texture by color plus additive
3843
- '}' // end of shader
3844
+ 'precision highp float;'+ // use highp for better accuracy
3845
+ 'varying vec4 v,d,e;'+ // uv, color, additiveColor
3846
+ 'uniform sampler2D s;'+ // texture
3847
+ 'void main(){'+ // shader entry point
3848
+ 'gl_FragColor=texture2D(s,v.xy)*d+e;'+ // modulate texture by color plus additive
3849
+ '}' // end of shader
3844
3850
  );
3845
3851
 
3846
3852
  // init buffers
3847
- glVertexData = new ArrayBuffer(gl_MAX_BATCH * gl_VERTICES_PER_QUAD * gl_VERTEX_BYTE_STRIDE);
3853
+ const vertexData = new ArrayBuffer(gl_VERTEX_BUFFER_SIZE);
3848
3854
  glArrayBuffer = glContext.createBuffer();
3849
- glPositionData = new Float32Array(glVertexData);
3850
- glColorData = new Uint32Array(glVertexData);
3855
+ glPositionData = new Float32Array(vertexData);
3856
+ glColorData = new Uint32Array(vertexData);
3851
3857
  glBatchCount = 0;
3852
3858
  }
3853
3859
 
@@ -3922,18 +3928,19 @@ function glCreateTexture(image)
3922
3928
  image && image.width && glContext.texImage2D(gl_TEXTURE_2D, 0, gl_RGBA, gl_RGBA, gl_UNSIGNED_BYTE, image);
3923
3929
 
3924
3930
  // use point filtering for pixelated rendering
3925
- glContext.texParameteri(gl_TEXTURE_2D, gl_TEXTURE_MIN_FILTER, cavasPixelated ? gl_NEAREST : gl_LINEAR);
3926
- glContext.texParameteri(gl_TEXTURE_2D, gl_TEXTURE_MAG_FILTER, cavasPixelated ? gl_NEAREST : gl_LINEAR);
3931
+ const filter = cavasPixelated ? gl_NEAREST : gl_LINEAR;
3932
+ glContext.texParameteri(gl_TEXTURE_2D, gl_TEXTURE_MIN_FILTER, filter);
3933
+ glContext.texParameteri(gl_TEXTURE_2D, gl_TEXTURE_MAG_FILTER, filter);
3927
3934
  glContext.texParameteri(gl_TEXTURE_2D, gl_TEXTURE_WRAP_S, gl_CLAMP_TO_EDGE);
3928
3935
  glContext.texParameteri(gl_TEXTURE_2D, gl_TEXTURE_WRAP_T, gl_CLAMP_TO_EDGE);
3929
3936
  return texture;
3930
3937
  }
3931
3938
 
3932
3939
  // called automatically by engine before render
3933
- function glPreRender(width, height, cameraX, cameraY, cameraScale)
3940
+ function glPreRender()
3934
3941
  {
3935
3942
  // clear and set to same size as main canvas
3936
- glContext.viewport(0, 0, glCanvas.width = width, glCanvas.height = height);
3943
+ glContext.viewport(0, 0, glCanvas.width = mainCanvas.width, glCanvas.height = mainCanvas.height);
3937
3944
  glContext.clear(gl_COLOR_BUFFER_BIT);
3938
3945
 
3939
3946
  // set up the shader
@@ -3941,7 +3948,7 @@ function glPreRender(width, height, cameraX, cameraY, cameraScale)
3941
3948
  glContext.activeTexture(gl_TEXTURE0);
3942
3949
  glContext.bindTexture(gl_TEXTURE_2D, glActiveTexture = glTileTexture);
3943
3950
  glContext.bindBuffer(gl_ARRAY_BUFFER, glArrayBuffer);
3944
- glContext.bufferData(gl_ARRAY_BUFFER, glVertexData.byteLength, gl_DYNAMIC_DRAW);
3951
+ glContext.bufferData(gl_ARRAY_BUFFER, gl_VERTEX_BUFFER_SIZE, gl_DYNAMIC_DRAW);
3945
3952
  glSetBlendMode();
3946
3953
 
3947
3954
  // set vertex attributes
@@ -3959,14 +3966,14 @@ function glPreRender(width, height, cameraX, cameraY, cameraScale)
3959
3966
  initVertexAttribArray('a', gl_UNSIGNED_BYTE, 1, 4, 1); // additiveColor
3960
3967
 
3961
3968
  // build the transform matrix
3962
- const sx = 2 * cameraScale / width;
3963
- const sy = 2 * cameraScale / height;
3969
+ const sx = 2 * cameraScale / mainCanvas.width;
3970
+ const sy = 2 * cameraScale / mainCanvas.height;
3964
3971
  glContext.uniformMatrix4fv(glContext.getUniformLocation(glShader, 'm'), 0,
3965
3972
  new Float32Array([
3966
3973
  sx, 0, 0, 0,
3967
3974
  0, sy, 0, 0,
3968
3975
  1, 1, -1, 1,
3969
- -1-sx*cameraX, -1-sy*cameraY, 0, 0
3976
+ -1-sx*cameraPos.x, -1-sy*cameraPos.y, 0, 0
3970
3977
  ])
3971
3978
  );
3972
3979
  }
@@ -4014,10 +4021,10 @@ function glCopyToContext(context, forceDraw)
4014
4021
  * @param uv0Y
4015
4022
  * @param uv1X
4016
4023
  * @param uv1Y
4017
- * @param [rgba=0xffffffff]
4024
+ * @param rgba
4018
4025
  * @param [rgbaAdditive=0]
4019
4026
  * @memberof WebGL */
4020
- function glDraw(x, y, sizeX, sizeY, angle, uv0X, uv0Y, uv1X, uv1Y, rgba=0xffffffff, rgbaAdditive=0)
4027
+ function glDraw(x, y, sizeX, sizeY, angle, uv0X, uv0Y, uv1X, uv1Y, rgba, rgbaAdditive=0)
4021
4028
  {
4022
4029
  // flush if there is no room for more verts or if different blend mode
4023
4030
  if (glBatchCount == gl_MAX_BATCH || glBatchAdditive != glAdditive)
@@ -4028,43 +4035,16 @@ function glDraw(x, y, sizeX, sizeY, angle, uv0X, uv0Y, uv1X, uv1Y, rgba=0xffffff
4028
4035
  const cx = c*sizeX, cy = c*sizeY, sx = s*sizeX, sy = s*sizeY;
4029
4036
 
4030
4037
  // setup 2 triangles to form a quad
4031
- let offset = glBatchCount++ * gl_VERTICES_PER_QUAD * gl_INDICIES_PER_VERT;
4032
-
4033
- // vertex 0
4034
- glPositionData[offset++] = x - cx - sy;
4035
- glPositionData[offset++] = y - cy + sx;
4036
- glPositionData[offset++] = uv0X; glPositionData[offset++] = uv1Y;
4037
- glColorData[offset++] = rgba; glColorData[offset++] = rgbaAdditive;
4038
-
4039
- // vertex 1
4040
- glPositionData[offset++] = x + cx + sy;
4041
- glPositionData[offset++] = y + cy - sx;
4042
- glPositionData[offset++] = uv1X; glPositionData[offset++] = uv0Y;
4043
- glColorData[offset++] = rgba; glColorData[offset++] = rgbaAdditive;
4044
-
4045
- // vertex 2
4046
- glPositionData[offset++] = x - cx + sy;
4047
- glPositionData[offset++] = y + cy + sx;
4048
- glPositionData[offset++] = uv0X; glPositionData[offset++] = uv0Y;
4049
- glColorData[offset++] = rgba; glColorData[offset++] = rgbaAdditive;
4050
-
4051
- // vertex 0
4052
- glPositionData[offset++] = x - cx - sy;
4053
- glPositionData[offset++] = y - cy + sx;
4054
- glPositionData[offset++] = uv0X; glPositionData[offset++] = uv1Y;
4055
- glColorData[offset++] = rgba; glColorData[offset++] = rgbaAdditive;
4056
-
4057
- // vertex 3
4058
- glPositionData[offset++] = x + cx - sy;
4059
- glPositionData[offset++] = y - cy - sx;
4060
- glPositionData[offset++] = uv1X; glPositionData[offset++] = uv1Y;
4061
- glColorData[offset++] = rgba; glColorData[offset++] = rgbaAdditive;
4062
-
4063
- // vertex 1
4064
- glPositionData[offset++] = x + cx + sy;
4065
- glPositionData[offset++] = y + cy - sx;
4066
- glPositionData[offset++] = uv1X; glPositionData[offset++] = uv0Y;
4067
- glColorData[offset++] = rgba; glColorData[offset++] = rgbaAdditive;
4038
+ for(let i=6, offset = glBatchCount++ * gl_VERTICES_PER_QUAD * gl_INDICIES_PER_VERT; i--;)
4039
+ {
4040
+ const a = i-4&&i>1, b = i-5&&i-2&&i-1;
4041
+ glPositionData[offset++] = x + (a?-cx:cx) + (b?sy:-sy);
4042
+ glPositionData[offset++] = y + (b?cy:-cy) + (a?sx:-sx);
4043
+ glPositionData[offset++] = a ? uv0X : uv1X;
4044
+ glPositionData[offset++] = b ? uv0Y : uv1Y;
4045
+ glColorData[offset++] = rgba;
4046
+ glColorData[offset++] = rgbaAdditive;
4047
+ }
4068
4048
  }
4069
4049
 
4070
4050
  ///////////////////////////////////////////////////////////////////////////////
@@ -4116,14 +4096,13 @@ function glRenderPostProcess()
4116
4096
  return;
4117
4097
 
4118
4098
  // prepare to render post process shader
4119
- const width = mainCanvas.width, height = mainCanvas.height;
4120
4099
  if (glEnable)
4121
4100
  {
4122
4101
  glFlush(); // clear out the buffer
4123
4102
  mainContext.drawImage(glCanvas, 0, 0); // copy to the main canvas
4124
4103
  }
4125
- else
4126
- glContext.viewport(0, 0, glCanvas.width = width, glCanvas.height = height); // set viewport
4104
+ else // set viewport
4105
+ glContext.viewport(0, 0, glCanvas.width = mainCanvas.width, glCanvas.height = mainCanvas.height);
4127
4106
 
4128
4107
  // setup shader program to draw one triangle
4129
4108
  glContext.useProgram(glPostShader);
@@ -4147,7 +4126,7 @@ function glRenderPostProcess()
4147
4126
  const uniformLocation = (name)=>glContext.getUniformLocation(glPostShader, name);
4148
4127
  glContext.uniform1i(uniformLocation('iChannel0'), 0);
4149
4128
  glContext.uniform1f(uniformLocation('iTime'), time);
4150
- glContext.uniform3f(uniformLocation('iResolution'), width, height, 1);
4129
+ glContext.uniform3f(uniformLocation('iResolution'), mainCanvas.width, mainCanvas.height, 1);
4151
4130
  glContext.drawArrays(gl_TRIANGLES, 0, 3);
4152
4131
  }
4153
4132
 
@@ -4187,7 +4166,8 @@ gl_UNPACK_FLIP_Y_WEBGL = 37440,
4187
4166
  gl_VERTICES_PER_QUAD = 6,
4188
4167
  gl_INDICIES_PER_VERT = 6,
4189
4168
  gl_MAX_BATCH = 1<<16,
4190
- gl_VERTEX_BYTE_STRIDE = (4 * 2) * 2 + (4) * 2; // vec2 * 2 + (char * 4) * 2
4169
+ gl_VERTEX_BYTE_STRIDE = (4 * 2) * 2 + (4) * 2, // vec2 * 2 + (char * 4) * 2
4170
+ gl_VERTEX_BUFFER_SIZE = gl_MAX_BATCH * gl_VERTICES_PER_QUAD * gl_VERTEX_BYTE_STRIDE;
4191
4171
  /*
4192
4172
  LittleJS - The Tiny JavaScript Game Engine That Can!
4193
4173
  MIT License - Copyright 2021 Frank Force
@@ -4203,6 +4183,7 @@ gl_VERTEX_BYTE_STRIDE = (4 * 2) * 2 + (4) * 2; // vec2 * 2 + (char * 4) * 2
4203
4183
  - Particle effect system
4204
4184
  - Medal system tracks and displays achievements
4205
4185
  - Debug tools and debug rendering system
4186
+ - Post processing effects
4206
4187
  - Call engineInit() to start it up!
4207
4188
  */
4208
4189
 
@@ -4212,7 +4193,7 @@ gl_VERTEX_BYTE_STRIDE = (4 * 2) * 2 + (4) * 2; // vec2 * 2 + (char * 4) * 2
4212
4193
  const engineName = 'LittleJS';
4213
4194
 
4214
4195
  /** Version of engine */
4215
- const engineVersion = '1.4.7';
4196
+ const engineVersion = '1.4.8';
4216
4197
 
4217
4198
  /** Frames per second to update objects
4218
4199
  * @default */
@@ -4237,14 +4218,13 @@ let time = 0;
4237
4218
  /** Actual clock time since start in seconds (not affected by pause or frame rate clamping) */
4238
4219
  let timeReal = 0;
4239
4220
 
4240
- /** Is the game paused? Causes time and objects to not be updated. */
4221
+ /** Is the game paused? Causes time and objects to not be updated */
4241
4222
  let paused = 0;
4242
4223
 
4243
- // Engine internal variables not exposed to documentation
4244
- let tileImageSize, tileImageFixBleed;
4245
-
4246
- // Engine stat tracking, if showWatermark is true
4247
- let averageFPS, drawCount;
4224
+ /** Set if game is paused
4225
+ * @param {Boolean} paused
4226
+ */
4227
+ function setPaused(_paused) { paused = _paused; }
4248
4228
 
4249
4229
  ///////////////////////////////////////////////////////////////////////////////
4250
4230
 
@@ -4265,13 +4245,11 @@ function engineInit(gameInit, gameUpdate, gameUpdatePost, gameRender, gameRender
4265
4245
  tileImageFixBleed = vec2(tileFixBleedScale).divide(tileImageSize = vec2(tileImage.width, tileImage.height));
4266
4246
  debug && (tileImage.onload=()=>ASSERT(1)); // tile sheet can not reloaded
4267
4247
 
4268
- // setup css
4248
+ // setup html
4269
4249
  const styleBody = 'margin:0;overflow:hidden;background:#000' + // fill the window
4270
4250
  ';touch-action:none' + // prevent mobile pinch to resize
4271
4251
  ';user-select:none' + // prevent mobile hold to select
4272
- ';-webkit-user-select:none;-moz-user-select:none'; // compatibility for mobile
4273
-
4274
- // setup html
4252
+ ';-webkit-user-select:none'; // compatibility for ios
4275
4253
  document.body.style = styleBody;
4276
4254
  document.body.appendChild(mainCanvas = document.createElement('canvas'));
4277
4255
  mainContext = mainCanvas.getContext('2d');
@@ -4286,7 +4264,7 @@ function engineInit(gameInit, gameUpdate, gameUpdatePost, gameRender, gameRender
4286
4264
 
4287
4265
  // set canvas style to fill the window
4288
4266
  const styleCanvas = 'position:absolute;top:50%;left:50%;transform:translate(-50%,-50%)';
4289
- (glCanvas||mainCanvas).style = overlayCanvas.style = mainCanvas.style = styleCanvas;
4267
+ (glCanvas||mainCanvas).style = mainCanvas.style = overlayCanvas.style = styleCanvas;
4290
4268
 
4291
4269
  gameInit();
4292
4270
  touchGamepadCreate();
@@ -4294,16 +4272,16 @@ function engineInit(gameInit, gameUpdate, gameUpdatePost, gameRender, gameRender
4294
4272
  };
4295
4273
 
4296
4274
  // frame time tracking
4297
- let frameTimeLastMS = 0, frameTimeBufferMS = 0;
4275
+ let frameTimeLastMS = 0, frameTimeBufferMS, averageFPS;
4298
4276
 
4299
4277
  // main update loop
4300
- const engineUpdate = (frameTimeMS=0)=>
4278
+ function engineUpdate(frameTimeMS=0)
4301
4279
  {
4302
4280
  // update time keeping
4303
4281
  let frameTimeDeltaMS = frameTimeMS - frameTimeLastMS;
4304
4282
  frameTimeLastMS = frameTimeMS;
4305
4283
  if (debug || showWatermark)
4306
- averageFPS = lerp(.05, averageFPS || 0, 1e3/(frameTimeDeltaMS||1));
4284
+ averageFPS = lerp(.05, averageFPS, 1e3/(frameTimeDeltaMS||1));
4307
4285
  const debugSpeedUp = debug && keyIsDown(107); // +
4308
4286
  const debugSpeedDown = debug && keyIsDown(109); // -
4309
4287
  if (debug)
@@ -4315,24 +4293,19 @@ function engineInit(gameInit, gameUpdate, gameUpdatePost, gameRender, gameRender
4315
4293
 
4316
4294
  if (canvasFixedSize.x)
4317
4295
  {
4318
- // clear set fixed size
4296
+ // clear canvas and set fixed size
4319
4297
  overlayCanvas.width = mainCanvas.width = canvasFixedSize.x;
4320
4298
  overlayCanvas.height = mainCanvas.height = canvasFixedSize.y;
4321
4299
 
4322
4300
  // fit to window by adding space on top or bottom if necessary
4323
4301
  const aspect = innerWidth / innerHeight;
4324
4302
  const fixedAspect = mainCanvas.width / mainCanvas.height;
4325
- mainCanvas.style.width = overlayCanvas.style.width = aspect < fixedAspect ? '100%' : '';
4326
- mainCanvas.style.height = overlayCanvas.style.height = aspect < fixedAspect ? '' : '100%';
4327
- if (glCanvas)
4328
- {
4329
- glCanvas.style.width = mainCanvas.style.width;
4330
- glCanvas.style.height = mainCanvas.style.height;
4331
- }
4303
+ (glCanvas||mainCanvas).style.width = mainCanvas.style.width = overlayCanvas.style.width = aspect < fixedAspect ? '100%' : '';
4304
+ (glCanvas||mainCanvas).style.height = mainCanvas.style.height = overlayCanvas.style.height = aspect < fixedAspect ? '' : '100%';
4332
4305
  }
4333
4306
  else
4334
4307
  {
4335
- // clear and set size to same as window
4308
+ // clear canvas and set size to same as window
4336
4309
  overlayCanvas.width = mainCanvas.width = min(innerWidth, canvasMaxSize.x);
4337
4310
  overlayCanvas.height = mainCanvas.height = min(innerHeight, canvasMaxSize.y);
4338
4311
  }
@@ -4399,7 +4372,7 @@ function engineInit(gameInit, gameUpdate, gameUpdatePost, gameRender, gameRender
4399
4372
  overlayContext.fillStyle = '#000';
4400
4373
  const text = engineName + ' ' + 'v' + engineVersion + ' / '
4401
4374
  + drawCount + ' / ' + engineObjects.length + ' / ' + averageFPS.toFixed(1)
4402
- + ' ' + (glEnable ? 'GL' : '2D') ;
4375
+ + (glEnable ? ' GL' : ' 2D') ;
4403
4376
  overlayContext.fillText(text, mainCanvas.width-3, 3);
4404
4377
  overlayContext.fillStyle = '#fff';
4405
4378
  overlayContext.fillText(text, mainCanvas.width-2, 2);
@@ -4413,7 +4386,7 @@ function engineInit(gameInit, gameUpdate, gameUpdatePost, gameRender, gameRender
4413
4386
  tileImageSource ? tileImage.src = tileImageSource : tileImage.onload();
4414
4387
  }
4415
4388
 
4416
- // called by engine to setup render system
4389
+ // Called automatically by engine to setup render system
4417
4390
  function enginePreRender()
4418
4391
  {
4419
4392
  // save canvas size
@@ -4423,12 +4396,10 @@ function enginePreRender()
4423
4396
  mainContext.imageSmoothingEnabled = !cavasPixelated;
4424
4397
 
4425
4398
  // setup gl rendering if enabled
4426
- glEnable && glPreRender(mainCanvas.width, mainCanvas.height, cameraPos.x, cameraPos.y, cameraScale);
4399
+ glEnable && glPreRender();
4427
4400
  }
4428
4401
 
4429
- ///////////////////////////////////////////////////////////////////////////////
4430
-
4431
- /** Calls update on each engine object (recursively if child), removes destroyed objects, and updated time */
4402
+ /** Update each engine object, remove destroyed objects, and update time */
4432
4403
  function engineObjectsUpdate()
4433
4404
  {
4434
4405
  // get list of solid objects for physics optimzation