littlejsengine 1.11.13 → 1.11.17

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 (51) hide show
  1. package/dist/littlejs.d.ts +1306 -66
  2. package/dist/littlejs.esm.js +3097 -269
  3. package/dist/littlejs.esm.min.js +1 -1
  4. package/dist/littlejs.js +253 -265
  5. package/dist/littlejs.min.js +1 -1
  6. package/dist/littlejs.release.js +155 -260
  7. package/examples/box2d/game.js +7 -10
  8. package/examples/box2d/gameObjects.js +33 -33
  9. package/examples/box2d/index.html +6 -6
  10. package/examples/box2d/scenes.js +28 -28
  11. package/examples/breakout/game.js +1 -4
  12. package/examples/breakout/index.html +4 -4
  13. package/examples/breakoutTutorial/index.html +2 -2
  14. package/examples/htmlMenu/game.js +3 -6
  15. package/examples/htmlMenu/index.html +2 -2
  16. package/examples/module/index.html +1 -1
  17. package/examples/particles/index.html +1 -1
  18. package/examples/platformer/game.js +0 -3
  19. package/examples/platformer/index.html +8 -8
  20. package/examples/puzzle/game.js +0 -3
  21. package/examples/puzzle/index.html +2 -2
  22. package/examples/shorts/base.html +1 -1
  23. package/examples/starter/build.js +4 -4
  24. package/examples/starter/index.html +13 -13
  25. package/examples/stress/index.html +3 -2
  26. package/examples/uiSystem/game.js +1 -7
  27. package/examples/uiSystem/index.html +3 -3
  28. package/package.json +3 -3
  29. package/plugins/box2d.js +1552 -640
  30. package/plugins/{Box2D_v2.3.1_min.wasm.js → box2d.wasm.js} +1 -1
  31. package/plugins/newgrounds.js +7 -8
  32. package/plugins/pluginExport.js +51 -0
  33. package/plugins/postProcess.js +94 -93
  34. package/plugins/uiSystem.js +145 -161
  35. package/plugins/zzfxm.js +163 -0
  36. package/src/engine.js +15 -20
  37. package/src/engineAudio.js +74 -204
  38. package/src/engineBuild.js +21 -3
  39. package/src/engineDebug.js +104 -6
  40. package/src/engineDraw.js +27 -14
  41. package/src/engineExport.js +12 -4
  42. package/src/engineParticles.js +6 -1
  43. package/src/engineRelease.js +6 -1
  44. package/src/engineSettings.js +2 -2
  45. package/src/engineUtilities.js +5 -11
  46. package/src/engineWebGL.js +19 -7
  47. package/examples/starter/build/index.html +0 -2
  48. package/examples/starter/build/index.js +0 -1
  49. package/examples/starter/build/tiles.png +0 -0
  50. package/examples/starter/game.zip +0 -0
  51. /package/plugins/{Box2D_v2.3.1_min.wasm.wasm → box2d.wasm.wasm} +0 -0
package/src/engineDraw.js CHANGED
@@ -160,6 +160,8 @@ class TextureInfo
160
160
  this.image = image;
161
161
  /** @property {Vector2} - size of the image */
162
162
  this.size = vec2(image.width, image.height);
163
+ /** @property {Vector2} - inverse of the size, cached for rendering */
164
+ this.sizeInverse = vec2(1/image.width, 1/image.height);
163
165
  /** @property {WebGLTexture} - webgl texture */
164
166
  this.glTexture = glEnable && glCreateTexture(image);
165
167
  }
@@ -205,19 +207,19 @@ function getCameraSize() { return mainCanvasSize.scale(1/cameraScale); }
205
207
  * @param {Color} [color=(1,1,1,1)] - Color to modulate with
206
208
  * @param {number} [angle] - Angle to rotate by
207
209
  * @param {boolean} [mirror] - If true image is flipped along the Y axis
208
- * @param {Color} [additiveColor=(0,0,0,0)] - Additive color to be applied
210
+ * @param {Color} [additiveColor] - Additive color to be applied if any
209
211
  * @param {boolean} [useWebGL=glEnable] - Use accelerated WebGL rendering
210
212
  * @param {boolean} [screenSpace=false] - If true the pos and size are in screen space
211
213
  * @param {CanvasRenderingContext2D|OffscreenCanvasRenderingContext2D} [context] - Canvas 2D context to draw to
212
214
  * @memberof Draw */
213
215
  function drawTile(pos, size=vec2(1), tileInfo, color=new Color,
214
- angle=0, mirror, additiveColor=new Color(0,0,0,0), useWebGL=glEnable, screenSpace, context)
216
+ angle=0, mirror, additiveColor, useWebGL=glEnable, screenSpace, context)
215
217
  {
216
218
  ASSERT(!context || !useWebGL, 'context only supported in canvas 2D mode');
217
219
  ASSERT(typeof tileInfo !== 'number' || !tileInfo,
218
220
  'this is an old style calls, to fix replace it with tile(tileIndex, tileSize)');
219
221
  ASSERT(isVector2(pos) && isVector2(size));
220
- ASSERT(isColor(color) && isColor(additiveColor));
222
+ ASSERT(isColor(color) && (!additiveColor || isColor(additiveColor)));
221
223
 
222
224
  const textureInfo = tileInfo && tileInfo.getTextureInfo();
223
225
  if (useWebGL)
@@ -228,21 +230,30 @@ function drawTile(pos, size=vec2(1), tileInfo, color=new Color,
228
230
  pos = screenToWorld(pos);
229
231
  size = size.scale(1/cameraScale);
230
232
  }
231
-
232
233
  if (textureInfo)
233
234
  {
234
235
  // calculate uvs and render
235
- const sizeInverse = vec2(1).divide(textureInfo.size);
236
+ const sizeInverse = textureInfo.sizeInverse;
236
237
  const x = tileInfo.pos.x * sizeInverse.x;
237
238
  const y = tileInfo.pos.y * sizeInverse.y;
238
239
  const w = tileInfo.size.x * sizeInverse.x;
239
240
  const h = tileInfo.size.y * sizeInverse.y;
240
- const tileImageFixBleed = sizeInverse.scale(tileFixBleedScale);
241
241
  glSetTexture(textureInfo.glTexture);
242
- glDraw(pos.x, pos.y, mirror ? -size.x : size.x, size.y, angle,
243
- x + tileImageFixBleed.x, y + tileImageFixBleed.y,
244
- x - tileImageFixBleed.x + w, y - tileImageFixBleed.y + h,
245
- color.rgbaInt(), additiveColor.rgbaInt());
242
+ if (tileFixBleedScale)
243
+ {
244
+ const tileImageFixBleedX = sizeInverse.x*tileFixBleedScale;
245
+ const tileImageFixBleedY = sizeInverse.y*tileFixBleedScale;
246
+ glDraw(pos.x, pos.y, mirror ? -size.x : size.x, size.y, angle,
247
+ x + tileImageFixBleedX, y + tileImageFixBleedY,
248
+ x - tileImageFixBleedX + w, y - tileImageFixBleedY + h,
249
+ color.rgbaInt(), additiveColor && additiveColor.rgbaInt());
250
+ }
251
+ else
252
+ {
253
+ glDraw(pos.x, pos.y, mirror ? -size.x : size.x, size.y, angle,
254
+ x, y, x + w, y + h,
255
+ color.rgbaInt(), additiveColor && additiveColor.rgbaInt());
256
+ }
246
257
  }
247
258
  else
248
259
  {
@@ -454,16 +465,15 @@ function drawTextOverlay(text, pos, size=1, color, lineWidth=0, lineColor, textA
454
465
  function drawTextScreen(text, pos, size=1, color=new Color, lineWidth=0, lineColor=new Color(0,0,0), textAlign='center', font=fontDefault, maxWidth=undefined, context=overlayContext)
455
466
  {
456
467
  context.fillStyle = color.toString();
457
- context.lineWidth = lineWidth;
458
468
  context.strokeStyle = lineColor.toString();
469
+ context.lineWidth = lineWidth;
459
470
  context.textAlign = textAlign;
460
471
  context.font = size + 'px '+ font;
461
472
  context.textBaseline = 'middle';
462
473
  context.lineJoin = 'round';
463
474
 
464
- pos = pos.copy();
465
-
466
475
  const lines = (text+'').split('\n');
476
+ pos = pos.copy();
467
477
  pos.y -= (lines.length-1) * size/2; // center text vertically
468
478
  lines.forEach(line=>
469
479
  {
@@ -533,7 +543,10 @@ class FontImage
533
543
  {
534
544
  // load default font image
535
545
  if (!engineFontImage)
536
- (engineFontImage = new Image).src = 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAQAAAAAYAQAAAAA9+x6JAAAAAnRSTlMAAHaTzTgAAAGiSURBVHjaZZABhxxBEIUf6ECLBdFY+Q0PMNgf0yCgsSAGZcT9sgIPtBWwIA5wgAPEoHUyJeeSlW+gjK+fegWwtROWpVQEyWh2npdpBmTUFVhb29RINgLIukoXr5LIAvYQ5ve+1FqWEMqNKTX3FAJHyQDRZvmKWubAACcv5z5Gtg2oyCWE+Yk/8JZQX1jTTCpKAFGIgza+dJCNBF2UskRlsgwitHbSV0QLgt9sTPtsRlvJjEr8C/FARWA2bJ/TtJ7lko34dNDn6usJUMzuErP89UUBJbWeozrwLLncXczd508deAjLWipLO4Q5XGPcJvPu92cNDaN0P5G1FL0nSOzddZOrJ6rNhbXGmeDvO3TF7DeJWl4bvaYQTNHCTeuqKZmbjHaSOFes+IX/+IhHrnAkXOAsfn24EM68XieIECoccD4KZLk/odiwzeo2rovYdhvb2HYFgyznJyDpYJdYOmfXgVdJTaUi4xA2uWYNYec9BLeqdl9EsoTw582mSFDX2DxVLbNt9U3YYoeatBad1c2Tj8t2akrjaIGJNywKB/7h75/gN3vCMSaadIUTAAAAAElFTkSuQmCC';
546
+ {
547
+ engineFontImage = new Image;
548
+ engineFontImage.src = 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAQAAAAAYAQAAAAA9+x6JAAAAAnRSTlMAAHaTzTgAAAGiSURBVHjaZZABhxxBEIUf6ECLBdFY+Q0PMNgf0yCgsSAGZcT9sgIPtBWwIA5wgAPEoHUyJeeSlW+gjK+fegWwtROWpVQEyWh2npdpBmTUFVhb29RINgLIukoXr5LIAvYQ5ve+1FqWEMqNKTX3FAJHyQDRZvmKWubAACcv5z5Gtg2oyCWE+Yk/8JZQX1jTTCpKAFGIgza+dJCNBF2UskRlsgwitHbSV0QLgt9sTPtsRlvJjEr8C/FARWA2bJ/TtJ7lko34dNDn6usJUMzuErP89UUBJbWeozrwLLncXczd508deAjLWipLO4Q5XGPcJvPu92cNDaN0P5G1FL0nSOzddZOrJ6rNhbXGmeDvO3TF7DeJWl4bvaYQTNHCTeuqKZmbjHaSOFes+IX/+IhHrnAkXOAsfn24EM68XieIECoccD4KZLk/odiwzeo2rovYdhvb2HYFgyznJyDpYJdYOmfXgVdJTaUi4xA2uWYNYec9BLeqdl9EsoTw582mSFDX2DxVLbNt9U3YYoeatBad1c2Tj8t2akrjaIGJNywKB/7h75/gN3vCMSaadIUTAAAAAElFTkSuQmCC';
549
+ }
537
550
 
538
551
  this.image = image || engineFontImage;
539
552
  this.tileSize = tileSize;
@@ -1,8 +1,9 @@
1
1
  /**
2
2
  * LittleJS Module Export
3
- * - Export engine as a module
4
3
  */
5
4
 
5
+ 'use strict';
6
+
6
7
  export
7
8
  {
8
9
  // Engine
@@ -43,6 +44,10 @@ export
43
44
  debugSaveCanvas,
44
45
  debugSaveText,
45
46
  debugSaveDataURL,
47
+ debugShowErrors,
48
+ debugVideoCaptureIsActive,
49
+ debugVideoCaptureStart,
50
+ debugVideoCaptureStop,
46
51
 
47
52
  // Settings
48
53
  cameraPos,
@@ -216,6 +221,7 @@ export
216
221
  glCopyToContext,
217
222
  glCreateProgram,
218
223
  glCreateTexture,
224
+ glSetTextureData,
219
225
  glDraw,
220
226
  glFlush,
221
227
  glSetTexture,
@@ -245,7 +251,8 @@ export
245
251
  mousePosScreen,
246
252
  mouseWheel,
247
253
  isUsingGamepad,
248
- preventDefaultInput,
254
+ inputPreventDefault,
255
+ setInputPreventDefault,
249
256
  gamepadIsDown,
250
257
  gamepadWasPressed,
251
258
  gamepadWasReleased,
@@ -258,14 +265,15 @@ export
258
265
  // Audio
259
266
  Sound,
260
267
  SoundWave,
261
- Music,
262
268
  playAudioFile,
263
269
  speak,
264
270
  speakStop,
265
271
  getNoteFrequency,
266
- audioContext,
267
272
  playSamples,
268
273
  zzfx,
274
+ zzfxG,
275
+ zzfxR,
276
+ audioContext,
269
277
 
270
278
  // Base Object
271
279
  EngineObject,
@@ -166,7 +166,12 @@ class ParticleEmitter extends EngineObject
166
166
  else
167
167
  this.destroy();
168
168
 
169
- debugParticles && debugRect(this.pos, vec2(this.emitSize), '#0f0', 0, this.angle);
169
+ if (debugParticles)
170
+ {
171
+ // show emitter bounds
172
+ const emitSize = typeof this.emitSize === 'number' ? vec2(this.emitSize) : this.emitSize;
173
+ debugRect(this.pos, emitSize, '#0f0', 0, this.angle);
174
+ }
170
175
  }
171
176
 
172
177
  /** Spawn one particle
@@ -32,4 +32,9 @@ function debugClear (){}
32
32
  function debugScreenshot (){}
33
33
  function debugSaveCanvas (){}
34
34
  function debugSaveText (){}
35
- function debugSaveDataURL(){}
35
+ function debugSaveDataURL(){}
36
+ function debugShowErrors(){}
37
+ function debugVideoCaptureIsActive(){ return false; }
38
+ function debugVideoCaptureStart (){}
39
+ function debugVideoCaptureStop (){}
40
+ function debugVideoCaptureUpdate(){}
@@ -443,8 +443,8 @@ function setSoundEnable(enable) { soundEnable = enable; }
443
443
  function setSoundVolume(volume)
444
444
  {
445
445
  soundVolume = volume;
446
- if (soundEnable && !headlessMode && audioGainNode)
447
- audioGainNode.gain.value = volume; // update gain immediately
446
+ if (soundEnable && !headlessMode && audioMasterGain)
447
+ audioMasterGain.gain.value = volume; // update gain immediately
448
448
  }
449
449
 
450
450
  /** Set default range where sound no longer plays
@@ -91,7 +91,7 @@ function distanceWrap(valueA, valueB, wrapSize=1)
91
91
  * @returns {number}
92
92
  * @memberof Utilities */
93
93
  function lerpWrap(percent, valueA, valueB, wrapSize=1)
94
- { return valueB + clamp(percent) * distanceWrap(valueA, valueB, wrapSize); }
94
+ { return valueA + clamp(percent) * distanceWrap(valueB, valueA, wrapSize); }
95
95
 
96
96
  /** Returns signed wrapped distance between the two angles passed in
97
97
  * @param {number} angleA
@@ -289,23 +289,17 @@ class RandomGenerator
289
289
  ///////////////////////////////////////////////////////////////////////////////
290
290
 
291
291
  /**
292
- * Create a 2d vector, can take another Vector2 to copy, 2 scalars, or 1 scalar
293
- * @param {Vector2|number} [x]
294
- * @param {number} [y]
292
+ * Create a 2d vector, can take 1 or 2 scalar values
293
+ * @param {number} [x]
294
+ * @param {number} [y] - if y is undefined, x is used for both
295
295
  * @return {Vector2}
296
296
  * @example
297
297
  * let a = vec2(0, 1); // vector with coordinates (0, 1)
298
- * let b = vec2(a); // copy a into b
299
298
  * a = vec2(5); // set a to (5, 5)
300
299
  * b = vec2(); // set b to (0, 0)
301
300
  * @memberof Utilities
302
301
  */
303
- function vec2(x=0, y)
304
- {
305
- return typeof x == 'number' ?
306
- new Vector2(x, y == undefined? x : y) :
307
- new Vector2(x.x, x.y);
308
- }
302
+ function vec2(x=0, y) { return new Vector2(x, y == undefined? x : y); }
309
303
 
310
304
  /**
311
305
  * Check if object is a valid Vector2
@@ -106,12 +106,12 @@ function glPreRender()
106
106
 
107
107
  // set vertex attributes
108
108
  let offset = glAdditive = glBatchAdditive = 0;
109
- let initVertexAttribArray = (name, type, typeSize, size)=>
109
+ const initVertexAttribArray = (name, type, typeSize, size)=>
110
110
  {
111
111
  const location = glContext.getAttribLocation(glShader, name);
112
112
  const stride = typeSize && gl_INSTANCE_BYTE_STRIDE; // only if not geometry
113
113
  const divisor = typeSize && 1; // only if not geometry
114
- const normalize = typeSize==1; // only if color
114
+ const normalize = typeSize == 1; // only if color
115
115
  glContext.enableVertexAttribArray(location);
116
116
  glContext.vertexAttribPointer(location, size, type, normalize, stride, offset);
117
117
  glContext.vertexAttribDivisor(location, divisor);
@@ -210,14 +210,14 @@ function glCreateTexture(image)
210
210
  const texture = glContext.createTexture();
211
211
  glContext.bindTexture(glContext.TEXTURE_2D, texture);
212
212
  if (image && image.width)
213
- glContext.texImage2D(glContext.TEXTURE_2D, 0, glContext.RGBA, glContext.RGBA, glContext.UNSIGNED_BYTE, image);
213
+ glSetTextureData(texture, image);
214
214
  else
215
215
  {
216
216
  // create a white texture
217
217
  const whitePixel = new Uint8Array([255, 255, 255, 255]);
218
218
  glContext.texImage2D(glContext.TEXTURE_2D, 0, glContext.RGBA, 1, 1, 0, glContext.RGBA, glContext.UNSIGNED_BYTE, whitePixel);
219
219
  }
220
-
220
+
221
221
  // use point filtering for pixelated rendering
222
222
  const filter = tilesPixelated ? glContext.NEAREST : glContext.LINEAR;
223
223
  glContext.texParameteri(glContext.TEXTURE_2D, glContext.TEXTURE_MIN_FILTER, filter);
@@ -225,6 +225,18 @@ function glCreateTexture(image)
225
225
  return texture;
226
226
  }
227
227
 
228
+ /** Set WebGL texture data from an image
229
+ * @param {WebGLTexture} texture
230
+ * @param {HTMLImageElement} image
231
+ * @memberof WebGL */
232
+ function glSetTextureData(texture, image)
233
+ {
234
+ // build the texture
235
+ ASSERT(!!image && image.width > 0, 'Invalid image data.');
236
+ glContext.bindTexture(glContext.TEXTURE_2D, texture);
237
+ glContext.texImage2D(glContext.TEXTURE_2D, 0, glContext.RGBA, glContext.RGBA, glContext.UNSIGNED_BYTE, image);
238
+ }
239
+
228
240
  /** Draw all sprites and clear out the buffer, called automatically by the system whenever necessary
229
241
  * @memberof WebGL */
230
242
  function glFlush()
@@ -278,10 +290,10 @@ function glSetAntialias(antialias=true)
278
290
  * @param {Number} uv0Y
279
291
  * @param {Number} uv1X
280
292
  * @param {Number} uv1Y
281
- * @param {Number} rgba
282
- * @param {Number} [rgbaAdditive=0]
293
+ * @param {Number} [rgba=-1] - white is -1
294
+ * @param {Number} [rgbaAdditive=0] - black is 0
283
295
  * @memberof WebGL */
284
- function glDraw(x, y, sizeX, sizeY, angle, uv0X, uv0Y, uv1X, uv1Y, rgba, rgbaAdditive=0)
296
+ function glDraw(x, y, sizeX, sizeY, angle, uv0X, uv0Y, uv1X, uv1Y, rgba=-1, rgbaAdditive=0)
285
297
  {
286
298
  ASSERT(typeof rgba == 'number' && typeof rgbaAdditive == 'number', 'invalid color');
287
299
 
@@ -1,2 +0,0 @@
1
- <!DOCTYPE html><head><title>Little JS Starter Project</title></head><body><script>const h=Math.PI;function aa(t,i=1){return(t%i+i)%i}function k(t,i=0,e=1){return t<i?i:e<t?e:t}function r(t,i,e){return(e-=i)?k((t-i)/e):0}function ba(t,i,e,a=u()){return 2*Math.abs(t.x-e.x)<i.x+a.x&&2*Math.abs(t.y-e.y)<i.y+a.y}function ha(t=ia){return.5*(1-Math.cos(2*t*h))}function v(t=1,i=0){return i+Math.random()*(t-i)}function ja(t=1){return ma(new w,v(2*h),t)}function na(t=1){return 0<t?ja(t*v(0/t,1)**.5):new w}function oa(t=new x,i=new x(0,0,0,1),e=!1){return e?t.la(i,v()):new x(v(t.r,i.r),v(t.j,i.j),v(t.b,i.b),v(t.a,i.a))}function u(t=0,i){return"number"==typeof t?new w(t,null==i?t:i):new w(t.x,t.y)}function ma(t,i=0,e=1){return t.x=e*Math.sin(i),t.y=e*Math.cos(i),t}function pa(t){return t.x**2+t.y**2}function qa(t){var i=t.length();return 1<i?t.scale(1/i):t}function ra(t,i){return 0<=t.x&&0<=t.y&&t.x<i.x&&t.y<i.y}class w{constructor(t=0,i=0){this.x=t,this.y=i}set(t=0,i=0){return this.x=t,this.y=i,this}v(){return new w(this.x,this.y)}add(t){return new w(this.x+t.x,this.y+t.y)}u(t){return new w(this.x-t.x,this.y-t.y)}multiply(t){return new w(this.x*t.x,this.y*t.y)}U(t){return new w(this.x/t.x,this.y/t.y)}scale(t){return new w(this.x*t,this.y*t)}length(){return pa(this)**.5}normalize(t=1){var i=this.length();return i?this.scale(t/i):new w(0,t)}angle(){return Math.atan2(this.x,this.y)}rotate(t){var i=Math.cos(-t);return t=Math.sin(-t),new w(this.x*i-this.y*t,this.x*t+this.y*i)}setDirection(t,i=1){return u((t=aa(t,4))%2?t-1?-i:i:0,t%2?0:t?-i:i)}direction(){return Math.abs(this.x)>Math.abs(this.y)?this.x<0?3:1:this.y<0?2:0}floor(){return new w(Math.floor(this.x),Math.floor(this.y))}la(t,i){return this.add(t.u(this).scale(k(i)))}toString(){}}function y(t=0,i=0,e=1,a=1){var s=new x,h=(t=aa(t,1),i=k(i),e=k(e),(t,i,e)=>6*(e=aa(e,1))<1?t+6*(i-t)*e:2*e<1?i:3*e<2?t+(i-t)*(4-6*e):t);return s.r=h(e=2*e-(i=e<.5?e*(1+i):e+i-e*i),i,t+1/3),s.j=h(e,i,t),s.b=h(e,i,t-1/3),s.a=a,s}function sa(t){return(255*k(t.r)|0)+(255*k(t.j)<<8)+(255*k(t.b)<<16)+(255*k(t.a)<<24)}class x{constructor(t=1,i=1,e=1,a=1){this.r=t,this.j=i,this.b=e,this.a=a}set(t=1,i=1,e=1,a=1){return this.r=t,this.j=i,this.b=e,this.a=a,this}v(){return new x(this.r,this.j,this.b,this.a)}add(t){return new x(this.r+t.r,this.j+t.j,this.b+t.b,this.a+t.a)}u(t){return new x(this.r-t.r,this.j-t.j,this.b-t.b,this.a-t.a)}multiply(t){return new x(this.r*t.r,this.j*t.j,this.b*t.b,this.a*t.a)}U(t){return new x(this.r/t.r,this.j/t.j,this.b/t.b,this.a/t.a)}scale(t,i=t){return new x(this.r*t,this.j*t,this.b*t,this.a*i)}la(t,i){return this.add(t.u(this).scale(k(i)))}toString(t=!0){var i=t=>((t=255*k(t)|0)<16?"0":"")+t.toString(16);return"#"+i(this.r)+i(this.j)+i(this.b)+(t?i(this.a):"")}}let A=u(),B=32,ta=u(1920,1080),ua=u(),va=!1,za=u(16),Aa=0,Ba=0,Ca=u(640,80);function Da(t){var i,e=t.parent;e&&(i=e.o?-1:1,t.i=t.ya.multiply(u(i,1)).rotate(e.angle).add(e.i),t.angle=i*t.xa+e.angle);for(const a of t.children)Da(a)}function Ea(t){if(!t.A){t.A=1,t.parent&&t.parent.removeChild(t);for(const i of t.children)Ea(i,i.parent=0)}}class Fa{constructor(t=u(),i=u(1),e,a=0,s=new x,h=0){this.i=t.v(),this.size=i,this.ua=void 0,this.l=e,this.angle=a,this.color=s,this.sa=void 0,this.o=!1,this.J=this.D=this.h=1,this.s=0,this.W=.8,this.N=1,this.P=h,this.g=u(),this.R=0,this.ra=ia,this.children=[],this.ba=!0,this.parent=this.m=void 0,this.ya=u(),this.xa=0,this.ka=this.ca=this.K=!1,C.push(this)}update(){var t;if(!this.parent&&(this.ba?(this.g.x=k(this.g.x,-1,1),this.g.y=k(this.g.y,-1,1)):1<(t=pa(this.g))&&(this.g.x*=t=1/t**.5,this.g.y*=t),t=this.i.v(),this.g.x*=this.D,this.g.y*=this.D,this.h&&(this.g.y+=Ba*this.N),this.i.x+=this.g.x,this.i.y+=this.g.y,this.angle+=this.R*=this.J,this.h)){var i,e,a,s,h,n,r=this.g.y<0;if(this.m&&(i=this.m.g?this.m.g.x:0,this.g.x=i+(this.g.x-i)*this.W,this.m=void 0),this.ca)for(var o of Ga)!this.ka&&!o.ka||o.A||o.parent||o==this||ba(this.i,this.size,o.i,o.size)&&(ba(t,this.size,o.i,o.size)?(i=(e=(i=t.u(o.i)).length())<.01?ja(.001):i.scale(.001/e),this.g=this.g.add(i),o.h&&(o.g=o.g.u(i))):(e=this.size.add(o.size),a=2*(t.y-o.i.y)>e.y+Ba,s=2*Math.abs(t.y-o.i.y)<e.y,h=2*Math.abs(t.x-o.i.x)<e.x,i=Math.max(this.s,o.s),!a&&!h&&s||(this.i.y=o.i.y+(e.y/2+.001)*Math.sign(t.y-o.i.y),o.m&&r||!o.h?(r&&(this.m=o),this.g.y*=-i):o.h&&(h=(this.h*this.g.y+o.h*o.g.y)/(this.h+o.h),n=o.g.y*(o.h-this.h)/(this.h+o.h)+2*this.g.y*this.h/(this.h+o.h),this.g.y=h+k(i)*(this.g.y*(this.h-o.h)/(this.h+o.h)+2*o.g.y*o.h/(this.h+o.h)-h),o.g.y=h+k(i)*(n-h))),!a&&s&&(this.i.x=o.i.x+(e.x/2+.001)*Math.sign(t.x-o.i.x),o.h?(e=(this.h*this.g.x+o.h*o.g.x)/(this.h+o.h),a=o.g.x*(o.h-this.h)/(this.h+o.h)+2*this.g.x*this.h/(this.h+o.h),this.g.x=e+k(i)*(this.g.x*(this.h-o.h)/(this.h+o.h)+2*o.g.x*o.h/(this.h+o.h)-e),o.g.x=e+k(i)*(a-e)):this.g.x*=-i)));this.K&&Ha(this.i,this.size,this)&&!Ha(t,this.size,this)&&(o=Ha(u(this.i.x,t.y),this.size,this),!Ha(u(t.x,this.i.y),this.size,this)&&o||(this.g.y*=-this.s,r?(this.i.y=(t.y-this.size.y/2|0)+this.size.y/2+1e-4,this.m=this):(this.i.y=t.y,this.m=void 0)),o)&&(this.i.x=t.x,this.g.x*=-this.s)}}C(){Ia(this.i,this.ua||this.size,this.l,this.color,this.angle,this.o,this.sa)}removeChild(t){t.parent==this&&this.children.includes(t),this.children.splice(this.children.indexOf(t),1),t.parent=0}toString(){}}let D,E,G,I,J=u(),K=[];function Ja(t=u(),i=za,e=0,a=0){"number"==typeof i&&(i=u(i));var s=K[e],h=i.add(u(2*a));return"number"==typeof t&&(t=0<(s=s.size.x/h.x|0)?u(t%s,t/s|0):u()),t=u(t.x*h.x+a,t.y*h.y+a),new Ka(t,i,e,a)}class Ka{constructor(t=u(),i=za,e=0,a=0){this.i=t.v(),this.size=i.v(),this.Z=e,this.padding=a}offset(t){return new Ka(this.i.add(t),this.size,this.Z)}frame(t){return this.offset(u(t*(this.size.x+2*this.padding),0))}}class La{constructor(t){this.image=t,this.size=u(t.width,t.height);var i=L.createTexture();L.bindTexture(L.TEXTURE_2D,i),t&&t.width?L.texImage2D(L.TEXTURE_2D,0,L.RGBA,L.RGBA,L.UNSIGNED_BYTE,t):(t=new Uint8Array([255,255,255,255]),L.texImage2D(L.TEXTURE_2D,0,L.RGBA,1,1,0,L.RGBA,L.UNSIGNED_BYTE,t)),t=L.NEAREST,L.texParameteri(L.TEXTURE_2D,L.TEXTURE_MIN_FILTER,t),L.texParameteri(L.TEXTURE_2D,L.TEXTURE_MAG_FILTER,t),this.ja=i}}function Ma(){var t=Pa;return new w((t.x-J.x/2+.5)/B+A.x,(t.y-J.y/2+.5)/-B+A.y)}function Qa(t){return new w((t.x-A.x)*B+J.x/2-.5,(t.y-A.y)*-B+J.y/2-.5)}function Ia(t,i=u(1),h,n=new x,e=0,a,s=new x(0,0,0,0),r=!0){const o=h&&K[h.Z];var l,c,b,d;r?o?(d=u(1).U(o.size),r=h.i.x*d.x,l=h.i.y*d.y,c=h.size.x*d.x,b=h.size.y*d.y,d=d.scale(Aa),Ra(o.ja),Sa(t.x,t.y,a?-i.x:i.x,i.y,e,r+d.x,l+d.y,r-d.x+c,l-d.y+b,sa(n),sa(s))):Sa(t.x,t.y,i.x,i.y,e,0,0,0,0,0,sa(n)):Ta(t,i=u(i.x,-i.y),e,a,t=>{var i,e,a,s;o?(i=h.i.x+Aa,e=h.i.y+Aa,a=h.size.x-2*Aa,s=h.size.y-2*Aa,t.globalAlpha=n.a,t.drawImage(o.image,i,e,a,s,-.5,-.5,1,1),t.globalAlpha=1):(t.fillStyle=n.toString(),t.fillRect(-.5,-.5,1,1))})}function Ta(t,i,e,a,s){var h=E;t=Qa(t),i=i.scale(B),h.save(),h.translate(t.x+.5,t.y+.5),h.rotate(e),h.scale(a?-i.x:i.x,-i.y),s(h),h.restore()}function Ua(t,i,e=1,a=new x,s=0,h=new x(0,0,0),n="center"){var r=I;r.fillStyle=a.toString(),r.lineWidth=s,r.strokeStyle=h.toString(),r.textAlign=n,r.font=e+"px arial",r.textBaseline="middle",r.lineJoin="round",i=i.v(),t=(t+"").split("\n"),i.y-=(t.length-1)*e/2,t.forEach(t=>{s&&r.strokeText(t,i.x,i.y,void 0),r.fillText(t,i.x,i.y,void 0),i.y+=e})}function Va(t,i=0){return O[i]&&!!(1&O[i][t])}let Wa=u(),Pa=u(),Xa=0,Ya=!1;function Za(t,i=0){return Va(t,i+1)}let O=[[]];function $a(){for(const t of O)for(const i in t)t[i]&=1;Xa=0}function ab(){function i(t){return"KeyW"==t?"ArrowUp":"KeyS"==t?"ArrowDown":"KeyA"==t?"ArrowLeft":"KeyD"==t?"ArrowRight":t}onkeydown=t=>{t.repeat||(Ya=!1,O[0][t.code]=3,O[0][i(t.code)]=3)},onkeyup=t=>{O[0][t.code]=4,O[0][i(t.code)]=4},onmousedown=t=>{P&&"running"!=P.state&&P.resume(),Ya=!1,O[0][t.button]=3,Pa=bb(t),t.button&&t.preventDefault()},onmouseup=t=>O[0][t.button]=2&O[0][t.button]|4,onmousemove=t=>Pa=bb(t),onwheel=t=>Xa=t.ctrlKey?0:Math.sign(t.deltaY),oncontextmenu=()=>!1,onblur=()=>{O=[[]]},cb&&db()}function bb(t){var i=D.getBoundingClientRect();return u(r(t.x,i.left,i.right)*D.width,r(t.y,i.top,i.bottom)*D.height)}const eb=[];function fb(){var i,e;if(navigator&&navigator.getGamepads&&document.hasFocus()){var a=navigator.getGamepads();for(let t=a.length;t--;){var s=a[t],h=O[t+1]||(O[t+1]=[]),n=eb[t]||(eb[t]=[]);if(s){for(var o=0;o<s.axes.length-1;o+=2)n[o>>1]=(i=u(s.axes[o],s.axes[o+1]),void 0,qa(u((e=t=>.3<t?r(t,.3,.8):t<-.3?-r(-t,.3,.8):0)(i.x),e(-i.y))));for(o=s.buttons.length;o--;){var l=s.buttons[o],c=Za(o,t);h[o]=l.pressed?c?1:3:c?4:0,Ya||=!t&&l.pressed}pa(s=u((Za(15,t)&&1)-(Za(14,t)&&1),(Za(12,t)&&1)-(Za(13,t)&&1)))&&(n[0]=qa(s))}}}}const cb=void 0!==window.ontouchstart;function db(){function i(t){P&&"running"!=P.state&&P.resume();var i=t.touches.length;return i?(Pa=bb(u(t.touches[0].clientX,t.touches[0].clientY)),e?Ya=!1:O[0][0]=3):e&&(O[0][0]=2&O[0][0]|4),e=i,document.hasFocus()&&t.preventDefault(),!0}document.addEventListener("touchstart",t=>i(t),{passive:!1}),document.addEventListener("touchmove",t=>i(t),{passive:!1}),document.addEventListener("touchend",t=>i(t),{passive:!1}),onmousedown=onmouseup=()=>0;let e}let P=new AudioContext,gb;class hb{constructor(){var t=[1,.5];this.Ba=40,this.Fa=.7,this.O=0,t&&(this.O=null!=t[1]?t[1]:.05,t[1]=0,this.qa=[ib(...t)],this.sampleRate=44100)}play(t,i=1,e=1,a=1,s=!1){if(this.qa){var h;if(t){if(h=this.Ba){var n=A;if(h*h<(n=(A.x-t.x)**2+(n.y-t.y)**2))return;i*=r(n**.5,h,h*this.Fa)}h=2*Qa(t).x/D.width-1}return t=e+e*this.O*a*v(-1,1),this.va=P.createGain(),this.source=jb(this.qa,i,t,h,s,this.sampleRate,this.va)}}stop(){this.source&&this.source.stop(),this.source=void 0}}function jb(t,i=1,e=1,a=0,s=!1,h=44100,n){const r=P.createBuffer(t.length,t[0].length,h),o=P.createBufferSource();return t.forEach((t,i)=>r.getChannelData(i).set(t)),o.buffer=r,o.playbackRate.value=e,o.loop=s,(n=n||P.createGain()).gain.value=i,n.connect(gb),t=new StereoPannerNode(P,{pan:k(a,-1,1)}),o.connect(t).connect(n),"running"!=P.state?P.resume().then(()=>o.start()):o.start(),o}function ib(t=1,i=.05,e=220,a=0,s=0,n=.1,r=0,o=1,u=0,l=0,c=0,b=0,x=0,d=0,y=0,g=0,f=0,m=1,w=0,p=0,L=0){var A=2*h,G=u*=500*A/44100/44100;i=e*=v(1+i,1-i)*A/44100;let E=[],D=0,J=0,R=0,T=1,W=0,_=0,M=0;var S=A*Math.abs(L)*2/44100,B=Math.cos(S),P=1+(z=Math.sin(S)/2/2),S=-2*B/P,z=(1-z)/P;let U=(1+Math.sign(L)*B)/2/P,j=-(Math.sign(L)+B)/P,I=0,C=0,F=0,O=0;for(l*=500*A/44100**3,y*=A/44100,c*=A/44100,b*=44100,x=44100*x|0,P=(a=44100*a+9)+(w*=44100)+(s*=44100)+(n*=44100)+(f*=44100)|0;R<P;E[R++]=M*t)++_%(100*g|0)||(M=r?1<r?2<r?3<r?Math.sin(D**3):k(Math.tan(D),1,-1):1-(2*D/A%2+2)%2:1-4*Math.abs(Math.round(D/A)-D/A):Math.sin(D),M=(x?1-p+p*Math.sin(A*R/x):1)*Math.sign(M)*Math.abs(M)**o*(R<a?R/a:R<a+w?1-(R-a)/w*(1-m):R<a+w+s?m:R<P-f?(P-R-f)/n*m:0),M=f?M/2+(f>R?0:(R<P-f?1:(P-R)/f)*E[R-f|0]/2/t):M,L&&(M=O=U*I+j*(I=C)+U*(C=M)-z*F-S*(F=O))),B=(e+=u+=l)*Math.cos(y*J++),D+=B+B*d*Math.sin(R**5),T&&++T>b&&(e+=c,i+=c,T=0),!x||++W%x||(e=i,u=G,T=T||1);return E}let pb=[],Q=u();function Ha(t,i=u(),e){var a=Math.max(t.x-i.x/2|0,0),s=Math.max(t.y-i.y/2|0,0),h=Math.min(t.x+i.x/2,Q.x);for(t=Math.min(t.y+i.y/2,Q.y);s<t;++s)for(i=a;i<h;++i){var n=pb[s*Q.x+i];if(n&&(!e||0<n))return!0}return!1}class qb{constructor(t,i=0,e=!1,a=new x){this.$=t,this.direction=i,this.o=e,this.color=a}clear(){this.$=this.direction=0,this.o=!1,this.color=new x}}function rb(t,i,e=!0){var a=t.l.size;e&&(e=i.multiply(a),t.context.clearRect(e.x,t.canvas.height-e.y,a.x,-a.y)),null!=(e=t.getData(i)).$&&(i=i.add(u(.5)),t=Ja(e.$,a,t.l.Z,t.l.padding),Ia(i,u(1),t,e.color,e.direction*h/2,e.o))}class sb extends Fa{constructor(t,i=Q){var e=Ja(),a=u(1);for(super(t,i,e,0,void 0,0),this.canvas=document.createElement("canvas"),this.context=this.canvas.getContext("2d"),this.scale=a,this.wa=!1,this.data=[],t=this.size,t=Math.abs(t.x*t.y);t--;)this.data.push(new qb)}setData(t,i,e=!1){ra(t,this.size)&&(this.data[(0|t.y)*this.size.x+t.x|0]=i,e)&&rb(this,t)}getData(t){return ra(t,this.size)&&this.data[(0|t.y)*this.size.x+t.x|0]}update(){}C(){let t=Qa(this.i.add(u(0,this.size.y*this.scale.y)));t=t.floor(),(this.wa?I:E).drawImage(this.canvas,t.x,t.y,B*this.size.x*this.scale.x,B*this.size.y*this.scale.y)}}function tb(t){var i="number"==typeof t.V?na(t.V/2):u(v(-.5,.5),v(-.5,.5)).multiply(t.V).rotate(t.angle);let e=v(t.na,-t.na);t.X||(i=t.i.add(i),e+=t.angle);const a=t.O;var s=(o=t=>t+t*v(a,-a))(t.Aa),h=o(t.Y),n=o(t.Da),r=o(t.speed),o=o(t.ta)*(2*Math.floor(v(2,0))-1),l=v(t.ga,-t.ga),c=oa(t.S,t.T,t.pa),b=oa(t.da,t.ea,t.pa),l=t.X?l:t.angle+l;(i=new ub(i,t.l,e,c,b,s,h,n,t.G,t.I,t.H,t.X&&t,t.za)).g=ma(u(),l,r),i.R=o,i.G=t.G,i.D=t.D,i.J=t.J,i.s=t.s,i.W=t.W,i.N=t.N,i.K=t.K,i.P=t.P,i.o=!!Math.floor(v(2,0)),t.oa&&t.oa(i)}class vb extends Fa{constructor(t,i,e=0,a=0,s=100,n=h,r,o=new x,l=new x,c=new x(1,1,1,0),b=new x(1,1,1,0),d=.5,y=.1,g=1,f=.1,v=.05,m=1,w=1,p=0,L=h,A=.1,E=.2,D=!1,R=!1,T=!0,M=R?1e9:0,S=!1){super(t,u(),r,i,void 0,M),this.V=e,this.ia=a,this.ha=s,this.ga=n,this.S=o,this.T=l,this.da=c,this.ea=b,this.pa=T,this.Aa=d,this.Y=y,this.Da=g,this.speed=f,this.ta=v,this.D=m,this.J=w,this.N=p,this.na=L,this.G=A,this.O=E,this.K=D,this.I=R,this.X=S,this.H=0,this.oa=this.za=void 0,this.F=0}update(){if(this.parent&&super.update(),!this.ia||ia-this.ra<=this.ia){if(+this.ha){var t=1/this.ha;for(this.F+=wb;0<this.F;this.F-=t)tb(this)}}else Ea(this)}C(){}}class ub extends Fa{constructor(t,i,e,a,s,h,n,r,o,l,c,b,x){super(t,u(),i,e),this.M=a,this.L=s.u(a),this.ma=h,this.Y=n,this.Ea=r-n,this.G=o,this.I=l,this.H=c,this.B=b,this.fa=x,this.ba=!1}C(){var t=0<this.ma?Math.min((ia-this.ra)/this.ma,1):1,i=u(this.Y+t*this.Ea),e=this.G/2,e=new x(this.M.r+t*this.L.r,this.M.j+t*this.L.j,this.M.b+t*this.L.b,(this.M.a+t*this.L.a)*(t<e?t/e:1-e<t?(1-t)/e:1));this.I&&(xb=!0);let a=this.i;var s,h,n=this.angle;this.B&&(a=this.B.i.add(a.rotate(-this.B.angle)),n+=this.B.angle),this.H?(s=this.g,(n=(s=this.B?s.rotate(-this.B.angle):s).length())&&(s=s.scale(1/n),h=n*this.H,i.y=Math.max(i.x,h),n=s.angle(),Ia(a.add(s.multiply(u(0,-h/2))),i,this.l,e,n,this.o))):Ia(a,i,this.l,e,n,this.o),this.I&&(xb=void 0),1==t&&(this.color=e,this.size=i,this.fa&&this.fa(this),this.A=1)}}const yb={};let zb=[],Ab,Bb;function Cb(i){Object.values(yb).forEach(t=>i(t))}class Db{constructor(){this.id=0,this.name="Example Medal",this.description="Welcome to LittleJS!",this.icon="🏆",this.aa=!1,yb[0]=this}unlock(){this.aa||(localStorage[Ab+"_"+this.id]=this.aa=!0,zb.push(this))}C(t=0){var i=I,e=Math.min(Ca.x,D.width),a=G.width-e;t*=-Ca.y,i.save(),i.beginPath(),i.fillStyle=new x(.9,.9,.9).toString(),i.strokeStyle=new x(0,0,0).toString(),i.lineWidth=3,i.rect(a,t,e,Ca.y),i.fill(),i.stroke(),i.clip(),e=u(a+15+25,t+Ca.y/2),this.image?I.drawImage(this.image,e.x-25,e.y-25,50,50):Ua(this.icon,e,35,new x(0,0,0)),a=u(a+50+30,t+28),Ua(this.name,a,38,new x(0,0,0),0,void 0,"left"),a.y+=32,Ua(this.description,a,24,new x(0,0,0),0,void 0,"left"),i.restore()}}let R,L,Eb,Fb,Gb,Hb,U,Ib,V,xb,Jb;function Kb(){R=document.createElement("canvas"),L=R.getContext("webgl2",{antialias:!0}),D.parentElement.appendChild(R);var t=L.createProgram();L.attachShader(t,Ob("#version 300 es\nprecision highp float;uniform mat4 m;in vec2 g;in vec4 p,u,c,a;in float r;out vec2 v;out vec4 d,e;void main(){vec2 s=(g-.5)*p.zw;gl_Position=m*vec4(p.xy+s*cos(r)-vec2(-s.y,s)*sin(r),1,1);v=mix(u.xw,u.zy,g);d=c;e=a;}",L.VERTEX_SHADER)),L.attachShader(t,Ob("#version 300 es\nprecision highp float;uniform sampler2D s;in vec2 v;in vec4 d,e;out vec4 c;void main(){c=texture(s,v)*d+e;}",L.FRAGMENT_SHADER)),L.linkProgram(t),Eb=t,t=new ArrayBuffer(44e4),U=new Float32Array(t),Ib=new Uint32Array(t),Gb=L.createBuffer(),Hb=L.createBuffer(),t=new Float32Array([V=0,0,1,0,0,1,1,1]),L.bindBuffer(L.ARRAY_BUFFER,Hb),L.bufferData(L.ARRAY_BUFFER,t,L.STATIC_DRAW)}function Pb(){L.viewport(0,0,R.width=D.width,R.height=D.height),L.clear(L.COLOR_BUFFER_BIT),L.useProgram(Eb),L.activeTexture(L.TEXTURE0),K[0]&&L.bindTexture(L.TEXTURE_2D,Fb=K[0].ja);let r=xb=Jb=0;var t=(t,i,e,a)=>{t=L.getAttribLocation(Eb,t);var s=e&&44,h=e&&1,n=1==e;L.enableVertexAttribArray(t),L.vertexAttribPointer(t,a,i,n,s,r),L.vertexAttribDivisor(t,h),r+=a*e},i=(L.bindBuffer(L.ARRAY_BUFFER,Hb),t("g",L.FLOAT,0,2),L.bindBuffer(L.ARRAY_BUFFER,Gb),L.bufferData(L.ARRAY_BUFFER,44e4,L.DYNAMIC_DRAW),t("p",L.FLOAT,4,4),t("u",L.FLOAT,4,4),t("c",L.UNSIGNED_BYTE,1,4),t("a",L.UNSIGNED_BYTE,1,4),t("r",L.FLOAT,4,1),t=u(2*B).U(J),u(-1).u(A.multiply(t)));L.uniformMatrix4fv(L.getUniformLocation(Eb,"m"),!1,[t.x,0,0,0,0,t.y,0,0,1,1,1,1,i.x,i.y,0,0])}function Ra(t){t!=Fb&&(Qb(),L.bindTexture(L.TEXTURE_2D,Fb=t))}function Ob(t,i){return i=L.createShader(i),L.shaderSource(i,t),L.compileShader(i),i}function Qb(){var t;V&&(t=Jb?L.ONE:L.ONE_MINUS_SRC_ALPHA,L.blendFuncSeparate(L.SRC_ALPHA,t,L.ONE,t),L.enable(L.BLEND),L.bufferSubData(L.ARRAY_BUFFER,0,U),L.drawArraysInstanced(L.TRIANGLE_STRIP,0,4,V),V=0,Jb=xb)}function Rb(t=!1){var i=E;(V||t)&&(Qb(),t)&&i.drawImage(R,0,0)}function Sa(t,i,e,a,s,h,n,r,o,u,l=0){(1e4<=V||Jb!=xb)&&Qb();var c=11*V++;U[c++]=t,U[c++]=i,U[c++]=e,U[c++]=a,U[c++]=h,U[c++]=n,U[c++]=r,U[c++]=o,Ib[c++]=u,Ib[c++]=l,U[+c]=s}const wb=1/60;let C=[],Ga=[],Sb=0,ia=0,Tb=0,Ub=0,W=0;const Vb=[],Wb=[];function Xb(t){Vb.includes(void 0),Wb.includes(t),t&&Wb.push(t)}function Yb(){Ga=C.filter(t=>t.ca);for(const t of C)t.parent||(function t(i){if(!i.A){i.update();for(const e of i.children)t(e)}}(t),Da(t));C=C.filter(t=>!t.A)}function Zb(t){const u=I;var e=G.width=innerWidth,a=G.height=innerHeight,s=r(t,1,.8),n=r(t,0,.5),i=u.createRadialGradient(e/2,a/2,0,e/2,a/2,.7*Math.hypot(e,a));i.addColorStop(0,y(0,0,s/2*k(n),s).toString()),i.addColorStop(1,y(0,0,0,s).toString()),u.save(),u.fillStyle=i,u.fillRect(0,0,e,a),i=(t,i,e,a,s)=>{u.beginPath(),u.rect(t,i,e,s?a*l:a),(u.fillStyle=s)?u.fill():u.stroke()},n=(t,i,e,a=0,s=2*h,n,r)=>{var o=(a+s)/2;a=l*(s-a)/2,u.beginPath(),r&&u.lineTo(t,i),u.arc(t,i,e,o-a,o+a),(u.fillStyle=n)?u.fill():u.stroke()},s=(t=0,i=0)=>y([.98,.3,.57,.14][t%4]-10,.8,[0,.3,.5,.8,.9][i]).toString();const l=r(t=ha(t),.1,.5);for(u.translate(e/2,a/2),e=Math.min(6,Math.min(e,a)/99),u.scale(e,e),u.translate(-40,-35),u.lineJoin=u.lineCap="round",u.lineWidth=.1+1.9*l,u.setLineDash([99*r(t,.1,1),99]),i(7,16,18,-8,s(2,2)),i(7,8,18,4,s(2,3)),i(25,8,8,8,s(2,1)),i(25,8,-18,8),i(25,8,8,8),i(25,16,7,23,s()),i(11,39,14,-23,s(1,1)),i(11,16,14,18,s(1,2)),i(11,16,14,8,s(1,3)),i(25,16,-14,24),i(15,29,6,-9,s(2,2)),n(15,21,5,0,h/2,s(2,4),1),i(21,21,-6,9),i(37,14,9,6,s(3,2)),i(37,14,4.5,6,s(3,3)),i(37,14,9,6),i(50,20,10,-8,s(0,1)),i(50,20,6.5,-8,s(0,2)),i(50,20,3.5,-8,s(0,3)),i(50,20,10,-8),n(55,2,11.4,.5,h-.5,s(3,3)),n(55,2,11.4,.5,h/2,s(3,2),1),n(55,2,11.4,.5,h-.5),i(45,7,20,-7,s(0,2)),i(45,-1,20,4,s(0,3)),i(45,-1,20,8),e=5;e--;)n(60-6*e,30,9.9,0,2*h,s(e+2,3)),n(60-6*e,30,10,-.5,h+.5,s(e+2,2)),n(60-6*e,30,10.1,.5,h-.5,s(e+2,1));for(n(36,30,10,h/2,3*h/2),n(48,30,10,h/2,3*h/2),n(60,30,10),u.beginPath(),u.lineTo(36,20),u.lineTo(60,20),u.stroke(),n(60,30,4,h,3*h,s(3,2)),n(60,30,4,h,2*h,s(3,3)),n(60,30,4,h,3*h),e=6;e--;)u.beginPath(),u.lineTo(53,54),u.lineTo(53,40),u.lineTo(53+(1+2.9*e)*l,40),u.lineTo(53+(4+3.5*e)*l,54),u.fillStyle=s(0,e%2+2),u.fill(),e%2&&u.stroke();for(i(6,40,5,5),i(6,40,5,5,s()),i(15,54,38,-14,s()),e=3;e--;)for(a=2;a--;)n(15*e+15,47,a?7:1,h,3*h,s(e,3)),u.stroke(),n(15*e+15,47,a?7:1,0,h,s(e,2)),u.stroke();for(u.beginPath(),u.lineTo(6,40),u.lineTo(68,40),u.stroke(),u.beginPath(),u.lineTo(77,54),u.lineTo(4,54),u.stroke(),u.font="900 16px arial",u.textAlign="center",u.textBaseline="top",u.lineWidth=.1+3.9*l,e=n=0;e<8;++e)n+=u.measureText("LittleJS"[e]).width;for(e=2;e--;)for(let t=0,i=41-n/2;t<8;++t)u.fillStyle=s(t,2),a=u.measureText("LittleJS"[t]).width,u[e?"strokeText":"fillText"]("LittleJS"[t],i+a/2,55.5,17*l),i+=a;u.restore()}va=!0,Aa=.5;const $b=new hb,ac=new Db;Ab="Hello World",Cb(t=>t.aa=!!localStorage[Ab+"_"+t.id]),Xb(function(){var t,i;zb.length&&(t=zb[0],i=Tb-Bb,Bb?5<i?(Bb=0,zb.shift()):t.C(i<.5?1-i/.5:4.5<i?(i-4.5)/.5:0):Bb=Tb)});let Z;!function(i,a,s,h,n,t,e=document.body){function r(t=0){var i=t-Ub;for(Ub=t,Tb+=i/1e3,W+=i,W=Math.min(W,50),o(),t=0,W<0&&-9<W&&(t=W,W=0);0<=W;W-=1e3/60)ia=Sb++/60,cb||document.hasFocus()||(O=[[]]),Wa=Ma(),fb(),a(),Vb.forEach(t=>t()),Yb(),s(),$a();W+=t,J=u(D.width,D.height),I.imageSmoothingEnabled=E.imageSmoothingEnabled=!1,Pb(),h(),C.sort((t,i)=>t.P-i.P);for(const e of C)e.A||e.C();n(),Wb.forEach(t=>t()),Rb(),requestAnimationFrame(r)}function o(){var t,i;ua.x?(D.width=ua.x,D.height=ua.y,t=innerWidth/innerHeight,i=D.width/D.height,(R||D).style.width=D.style.width=G.style.width=t<i?"100%":"",(R||D).style.height=D.style.height=G.style.height=t<i?"":"100%"):(D.width=Math.min(innerWidth,ta.x),D.height=Math.min(innerHeight,ta.y)),G.width=D.width,G.height=D.height,J=u(D.width,D.height)}i||=()=>{},a||=()=>{},s||=()=>{},h||=()=>{},n||=()=>{},e.style.cssText="margin:0;overflow:hidden;width:100vw;height:100vh;display:flex;align-items:center;justify-content:center;background:#000;image-rendering:pixelated;user-select:none;-webkit-user-select:none;touch-action:none;-webkit-touch-callout:none",e.appendChild(D=document.createElement("canvas")),E=D.getContext("2d"),ab(),(gb=P.createGain()).connect(P.destination),gb.gain.value=.3,Kb(),e.appendChild(G=document.createElement("canvas")),I=G.getContext("2d"),D.style.cssText=G.style.cssText="position:absolute",R&&(R.style.cssText="position:absolute"),o(),e=t.map((e,a)=>new Promise(t=>{const i=new Image;i.crossOrigin="anonymous",i.onerror=i.onload=()=>{K[a]=new La(i),t()},i.src=e})),t.length||e.push(new Promise(t=>{K[0]=new La(new Image),t()})),va&&e.push(new Promise(i=>{let e=0;console.log("LittleJS Engine v1.11.10"),function t(){O=[[]],Zb(e+=.01),1<e?i():setTimeout(t,16)}()})),Promise.all(e).then(function(){new Promise(t=>t(i())).then(r)})}(function(){Q=u(32,16);for(var t=(pb=[]).length=Math.abs(Q.x*Q.y);t--;)pb[t]=0;var i,e,a,s=u(),t=new sb(s,Q),n=K[0].image,r=(E.drawImage(n,0,0),E.getImageData(0,0,n.width,n.height).data);for(s.x=Q.x;s.x--;)for(s.y=Q.y;s.y--;)r[4*(s.x+n.width*(15+Q.y-s.y))]&&(i=Math.floor(v(4,0)),e=!Math.floor(v(2,0)),a=oa(),t.setData(s,new qb(1,i,e,a)),ra(s,Q))&&(pb[(0|s.y)*Q.x+s.x|0]=1);for(t.Ca=[D,E,J,A,B],D=t.canvas,E=t.context,J=t.size.multiply(t.l.size),A=t.size.scale(.5),B=t.l.size.x,D.width=J.x,D.height=J.y,t.context.imageSmoothingEnabled=!1,Pb(),s=t.size.x;s--;)for(n=t.size.y;n--;)rb(t,u(s,n),!1);Rb(!0),[D,E,J,A,B]=t.Ca,A=u(16,8),B=32,Ba=-.01,(Z=new vb(u(16,9),0,0,0,500,h,Ja(0,16),y(1,1,1),y(0,0,0),y(0,0,0,0),y(0,0,0,0),2,.2,.2,.1,.05,.99,1,1,h,.05,.5,!0,!0)).s=.3,Z.H=2},function(){O[0]&&2&O[0][0]&&($b.play(Wa),Z.S=y(),Z.T=oa(),Z.da=Z.S.scale(1,0),Z.ea=Z.T.scale(1,0),ac.unlock()),Xa&&(B=k(B-=Math.sign(Xa)*B/5,10,300)),Pa.x&&(Z.i=Wa)},function(){},function(){Ia(u(16,8),u(20,14),void 0,y(0,0,.6),0,!1,void 0,!1),Ia(u(21,5),u(4.5),Ja(3,128))},function(){Ua("LittleJS Demo",u(J.x/2,70),80,y(0,0,1),6,y(0,0,0))},["tiles.png"]);
2
- </script>
@@ -1 +0,0 @@
1
- const h=Math.PI;function aa(t,i=1){return(t%i+i)%i}function k(t,i=0,e=1){return t<i?i:e<t?e:t}function r(t,i,e){return(e-=i)?k((t-i)/e):0}function ba(t,i,e,a=u()){return 2*Math.abs(t.x-e.x)<i.x+a.x&&2*Math.abs(t.y-e.y)<i.y+a.y}function ha(t=ia){return.5*(1-Math.cos(2*t*h))}function v(t=1,i=0){return i+Math.random()*(t-i)}function ja(t=1){return ma(new w,v(2*h),t)}function na(t=1){return 0<t?ja(t*v(0/t,1)**.5):new w}function oa(t=new x,i=new x(0,0,0,1),e=!1){return e?t.la(i,v()):new x(v(t.r,i.r),v(t.j,i.j),v(t.b,i.b),v(t.a,i.a))}function u(t=0,i){return"number"==typeof t?new w(t,null==i?t:i):new w(t.x,t.y)}function ma(t,i=0,e=1){return t.x=e*Math.sin(i),t.y=e*Math.cos(i),t}function pa(t){return t.x**2+t.y**2}function qa(t){var i=t.length();return 1<i?t.scale(1/i):t}function ra(t,i){return 0<=t.x&&0<=t.y&&t.x<i.x&&t.y<i.y}class w{constructor(t=0,i=0){this.x=t,this.y=i}set(t=0,i=0){return this.x=t,this.y=i,this}v(){return new w(this.x,this.y)}add(t){return new w(this.x+t.x,this.y+t.y)}u(t){return new w(this.x-t.x,this.y-t.y)}multiply(t){return new w(this.x*t.x,this.y*t.y)}U(t){return new w(this.x/t.x,this.y/t.y)}scale(t){return new w(this.x*t,this.y*t)}length(){return pa(this)**.5}normalize(t=1){var i=this.length();return i?this.scale(t/i):new w(0,t)}angle(){return Math.atan2(this.x,this.y)}rotate(t){var i=Math.cos(-t);return t=Math.sin(-t),new w(this.x*i-this.y*t,this.x*t+this.y*i)}setDirection(t,i=1){return u((t=aa(t,4))%2?t-1?-i:i:0,t%2?0:t?-i:i)}direction(){return Math.abs(this.x)>Math.abs(this.y)?this.x<0?3:1:this.y<0?2:0}floor(){return new w(Math.floor(this.x),Math.floor(this.y))}la(t,i){return this.add(t.u(this).scale(k(i)))}toString(){}}function y(t=0,i=0,e=1,a=1){var s=new x,h=(t=aa(t,1),i=k(i),e=k(e),(t,i,e)=>6*(e=aa(e,1))<1?t+6*(i-t)*e:2*e<1?i:3*e<2?t+(i-t)*(4-6*e):t);return s.r=h(e=2*e-(i=e<.5?e*(1+i):e+i-e*i),i,t+1/3),s.j=h(e,i,t),s.b=h(e,i,t-1/3),s.a=a,s}function sa(t){return(255*k(t.r)|0)+(255*k(t.j)<<8)+(255*k(t.b)<<16)+(255*k(t.a)<<24)}class x{constructor(t=1,i=1,e=1,a=1){this.r=t,this.j=i,this.b=e,this.a=a}set(t=1,i=1,e=1,a=1){return this.r=t,this.j=i,this.b=e,this.a=a,this}v(){return new x(this.r,this.j,this.b,this.a)}add(t){return new x(this.r+t.r,this.j+t.j,this.b+t.b,this.a+t.a)}u(t){return new x(this.r-t.r,this.j-t.j,this.b-t.b,this.a-t.a)}multiply(t){return new x(this.r*t.r,this.j*t.j,this.b*t.b,this.a*t.a)}U(t){return new x(this.r/t.r,this.j/t.j,this.b/t.b,this.a/t.a)}scale(t,i=t){return new x(this.r*t,this.j*t,this.b*t,this.a*i)}la(t,i){return this.add(t.u(this).scale(k(i)))}toString(t=!0){var i=t=>((t=255*k(t)|0)<16?"0":"")+t.toString(16);return"#"+i(this.r)+i(this.j)+i(this.b)+(t?i(this.a):"")}}let A=u(),B=32,ta=u(1920,1080),ua=u(),va=!1,za=u(16),Aa=0,Ba=0,Ca=u(640,80);function Da(t){var i,e=t.parent;e&&(i=e.o?-1:1,t.i=t.ya.multiply(u(i,1)).rotate(e.angle).add(e.i),t.angle=i*t.xa+e.angle);for(const a of t.children)Da(a)}function Ea(t){if(!t.A){t.A=1,t.parent&&t.parent.removeChild(t);for(const i of t.children)Ea(i,i.parent=0)}}class Fa{constructor(t=u(),i=u(1),e,a=0,s=new x,h=0){this.i=t.v(),this.size=i,this.ua=void 0,this.l=e,this.angle=a,this.color=s,this.sa=void 0,this.o=!1,this.J=this.D=this.h=1,this.s=0,this.W=.8,this.N=1,this.P=h,this.g=u(),this.R=0,this.ra=ia,this.children=[],this.ba=!0,this.parent=this.m=void 0,this.ya=u(),this.xa=0,this.ka=this.ca=this.K=!1,C.push(this)}update(){var t;if(!this.parent&&(this.ba?(this.g.x=k(this.g.x,-1,1),this.g.y=k(this.g.y,-1,1)):1<(t=pa(this.g))&&(this.g.x*=t=1/t**.5,this.g.y*=t),t=this.i.v(),this.g.x*=this.D,this.g.y*=this.D,this.h&&(this.g.y+=Ba*this.N),this.i.x+=this.g.x,this.i.y+=this.g.y,this.angle+=this.R*=this.J,this.h)){var i,e,a,s,h,n,r=this.g.y<0;if(this.m&&(i=this.m.g?this.m.g.x:0,this.g.x=i+(this.g.x-i)*this.W,this.m=void 0),this.ca)for(var o of Ga)!this.ka&&!o.ka||o.A||o.parent||o==this||ba(this.i,this.size,o.i,o.size)&&(ba(t,this.size,o.i,o.size)?(i=(e=(i=t.u(o.i)).length())<.01?ja(.001):i.scale(.001/e),this.g=this.g.add(i),o.h&&(o.g=o.g.u(i))):(e=this.size.add(o.size),a=2*(t.y-o.i.y)>e.y+Ba,s=2*Math.abs(t.y-o.i.y)<e.y,h=2*Math.abs(t.x-o.i.x)<e.x,i=Math.max(this.s,o.s),!a&&!h&&s||(this.i.y=o.i.y+(e.y/2+.001)*Math.sign(t.y-o.i.y),o.m&&r||!o.h?(r&&(this.m=o),this.g.y*=-i):o.h&&(h=(this.h*this.g.y+o.h*o.g.y)/(this.h+o.h),n=o.g.y*(o.h-this.h)/(this.h+o.h)+2*this.g.y*this.h/(this.h+o.h),this.g.y=h+k(i)*(this.g.y*(this.h-o.h)/(this.h+o.h)+2*o.g.y*o.h/(this.h+o.h)-h),o.g.y=h+k(i)*(n-h))),!a&&s&&(this.i.x=o.i.x+(e.x/2+.001)*Math.sign(t.x-o.i.x),o.h?(e=(this.h*this.g.x+o.h*o.g.x)/(this.h+o.h),a=o.g.x*(o.h-this.h)/(this.h+o.h)+2*this.g.x*this.h/(this.h+o.h),this.g.x=e+k(i)*(this.g.x*(this.h-o.h)/(this.h+o.h)+2*o.g.x*o.h/(this.h+o.h)-e),o.g.x=e+k(i)*(a-e)):this.g.x*=-i)));this.K&&Ha(this.i,this.size,this)&&!Ha(t,this.size,this)&&(o=Ha(u(this.i.x,t.y),this.size,this),!Ha(u(t.x,this.i.y),this.size,this)&&o||(this.g.y*=-this.s,r?(this.i.y=(t.y-this.size.y/2|0)+this.size.y/2+1e-4,this.m=this):(this.i.y=t.y,this.m=void 0)),o)&&(this.i.x=t.x,this.g.x*=-this.s)}}C(){Ia(this.i,this.ua||this.size,this.l,this.color,this.angle,this.o,this.sa)}removeChild(t){t.parent==this&&this.children.includes(t),this.children.splice(this.children.indexOf(t),1),t.parent=0}toString(){}}let D,E,G,I,J=u(),K=[];function Ja(t=u(),i=za,e=0,a=0){"number"==typeof i&&(i=u(i));var s=K[e],h=i.add(u(2*a));return"number"==typeof t&&(t=0<(s=s.size.x/h.x|0)?u(t%s,t/s|0):u()),t=u(t.x*h.x+a,t.y*h.y+a),new Ka(t,i,e,a)}class Ka{constructor(t=u(),i=za,e=0,a=0){this.i=t.v(),this.size=i.v(),this.Z=e,this.padding=a}offset(t){return new Ka(this.i.add(t),this.size,this.Z)}frame(t){return this.offset(u(t*(this.size.x+2*this.padding),0))}}class La{constructor(t){this.image=t,this.size=u(t.width,t.height);var i=L.createTexture();L.bindTexture(L.TEXTURE_2D,i),t&&t.width?L.texImage2D(L.TEXTURE_2D,0,L.RGBA,L.RGBA,L.UNSIGNED_BYTE,t):(t=new Uint8Array([255,255,255,255]),L.texImage2D(L.TEXTURE_2D,0,L.RGBA,1,1,0,L.RGBA,L.UNSIGNED_BYTE,t)),t=L.NEAREST,L.texParameteri(L.TEXTURE_2D,L.TEXTURE_MIN_FILTER,t),L.texParameteri(L.TEXTURE_2D,L.TEXTURE_MAG_FILTER,t),this.ja=i}}function Ma(){var t=Pa;return new w((t.x-J.x/2+.5)/B+A.x,(t.y-J.y/2+.5)/-B+A.y)}function Qa(t){return new w((t.x-A.x)*B+J.x/2-.5,(t.y-A.y)*-B+J.y/2-.5)}function Ia(t,i=u(1),h,n=new x,e=0,a,s=new x(0,0,0,0),r=!0){const o=h&&K[h.Z];var l,c,b,d;r?o?(d=u(1).U(o.size),r=h.i.x*d.x,l=h.i.y*d.y,c=h.size.x*d.x,b=h.size.y*d.y,d=d.scale(Aa),Ra(o.ja),Sa(t.x,t.y,a?-i.x:i.x,i.y,e,r+d.x,l+d.y,r-d.x+c,l-d.y+b,sa(n),sa(s))):Sa(t.x,t.y,i.x,i.y,e,0,0,0,0,0,sa(n)):Ta(t,i=u(i.x,-i.y),e,a,t=>{var i,e,a,s;o?(i=h.i.x+Aa,e=h.i.y+Aa,a=h.size.x-2*Aa,s=h.size.y-2*Aa,t.globalAlpha=n.a,t.drawImage(o.image,i,e,a,s,-.5,-.5,1,1),t.globalAlpha=1):(t.fillStyle=n.toString(),t.fillRect(-.5,-.5,1,1))})}function Ta(t,i,e,a,s){var h=E;t=Qa(t),i=i.scale(B),h.save(),h.translate(t.x+.5,t.y+.5),h.rotate(e),h.scale(a?-i.x:i.x,-i.y),s(h),h.restore()}function Ua(t,i,e=1,a=new x,s=0,h=new x(0,0,0),n="center"){var r=I;r.fillStyle=a.toString(),r.lineWidth=s,r.strokeStyle=h.toString(),r.textAlign=n,r.font=e+"px arial",r.textBaseline="middle",r.lineJoin="round",i=i.v(),t=(t+"").split("\n"),i.y-=(t.length-1)*e/2,t.forEach(t=>{s&&r.strokeText(t,i.x,i.y,void 0),r.fillText(t,i.x,i.y,void 0),i.y+=e})}function Va(t,i=0){return O[i]&&!!(1&O[i][t])}let Wa=u(),Pa=u(),Xa=0,Ya=!1;function Za(t,i=0){return Va(t,i+1)}let O=[[]];function $a(){for(const t of O)for(const i in t)t[i]&=1;Xa=0}function ab(){function i(t){return"KeyW"==t?"ArrowUp":"KeyS"==t?"ArrowDown":"KeyA"==t?"ArrowLeft":"KeyD"==t?"ArrowRight":t}onkeydown=t=>{t.repeat||(Ya=!1,O[0][t.code]=3,O[0][i(t.code)]=3)},onkeyup=t=>{O[0][t.code]=4,O[0][i(t.code)]=4},onmousedown=t=>{P&&"running"!=P.state&&P.resume(),Ya=!1,O[0][t.button]=3,Pa=bb(t),t.button&&t.preventDefault()},onmouseup=t=>O[0][t.button]=2&O[0][t.button]|4,onmousemove=t=>Pa=bb(t),onwheel=t=>Xa=t.ctrlKey?0:Math.sign(t.deltaY),oncontextmenu=()=>!1,onblur=()=>{O=[[]]},cb&&db()}function bb(t){var i=D.getBoundingClientRect();return u(r(t.x,i.left,i.right)*D.width,r(t.y,i.top,i.bottom)*D.height)}const eb=[];function fb(){var i,e;if(navigator&&navigator.getGamepads&&document.hasFocus()){var a=navigator.getGamepads();for(let t=a.length;t--;){var s=a[t],h=O[t+1]||(O[t+1]=[]),n=eb[t]||(eb[t]=[]);if(s){for(var o=0;o<s.axes.length-1;o+=2)n[o>>1]=(i=u(s.axes[o],s.axes[o+1]),void 0,qa(u((e=t=>.3<t?r(t,.3,.8):t<-.3?-r(-t,.3,.8):0)(i.x),e(-i.y))));for(o=s.buttons.length;o--;){var l=s.buttons[o],c=Za(o,t);h[o]=l.pressed?c?1:3:c?4:0,Ya||=!t&&l.pressed}pa(s=u((Za(15,t)&&1)-(Za(14,t)&&1),(Za(12,t)&&1)-(Za(13,t)&&1)))&&(n[0]=qa(s))}}}}const cb=void 0!==window.ontouchstart;function db(){function i(t){P&&"running"!=P.state&&P.resume();var i=t.touches.length;return i?(Pa=bb(u(t.touches[0].clientX,t.touches[0].clientY)),e?Ya=!1:O[0][0]=3):e&&(O[0][0]=2&O[0][0]|4),e=i,document.hasFocus()&&t.preventDefault(),!0}document.addEventListener("touchstart",t=>i(t),{passive:!1}),document.addEventListener("touchmove",t=>i(t),{passive:!1}),document.addEventListener("touchend",t=>i(t),{passive:!1}),onmousedown=onmouseup=()=>0;let e}let P=new AudioContext,gb;class hb{constructor(){var t=[1,.5];this.Ba=40,this.Fa=.7,this.O=0,t&&(this.O=null!=t[1]?t[1]:.05,t[1]=0,this.qa=[ib(...t)],this.sampleRate=44100)}play(t,i=1,e=1,a=1,s=!1){if(this.qa){var h;if(t){if(h=this.Ba){var n=A;if(h*h<(n=(A.x-t.x)**2+(n.y-t.y)**2))return;i*=r(n**.5,h,h*this.Fa)}h=2*Qa(t).x/D.width-1}return t=e+e*this.O*a*v(-1,1),this.va=P.createGain(),this.source=jb(this.qa,i,t,h,s,this.sampleRate,this.va)}}stop(){this.source&&this.source.stop(),this.source=void 0}}function jb(t,i=1,e=1,a=0,s=!1,h=44100,n){const r=P.createBuffer(t.length,t[0].length,h),o=P.createBufferSource();return t.forEach((t,i)=>r.getChannelData(i).set(t)),o.buffer=r,o.playbackRate.value=e,o.loop=s,(n=n||P.createGain()).gain.value=i,n.connect(gb),t=new StereoPannerNode(P,{pan:k(a,-1,1)}),o.connect(t).connect(n),"running"!=P.state?P.resume().then(()=>o.start()):o.start(),o}function ib(t=1,i=.05,e=220,a=0,s=0,n=.1,r=0,o=1,u=0,l=0,c=0,b=0,x=0,d=0,y=0,g=0,f=0,m=1,w=0,p=0,L=0){var A=2*h,G=u*=500*A/44100/44100;i=e*=v(1+i,1-i)*A/44100;let E=[],D=0,J=0,R=0,T=1,W=0,_=0,M=0;var S=A*Math.abs(L)*2/44100,B=Math.cos(S),P=1+(z=Math.sin(S)/2/2),S=-2*B/P,z=(1-z)/P;let U=(1+Math.sign(L)*B)/2/P,j=-(Math.sign(L)+B)/P,I=0,C=0,F=0,O=0;for(l*=500*A/44100**3,y*=A/44100,c*=A/44100,b*=44100,x=44100*x|0,P=(a=44100*a+9)+(w*=44100)+(s*=44100)+(n*=44100)+(f*=44100)|0;R<P;E[R++]=M*t)++_%(100*g|0)||(M=r?1<r?2<r?3<r?Math.sin(D**3):k(Math.tan(D),1,-1):1-(2*D/A%2+2)%2:1-4*Math.abs(Math.round(D/A)-D/A):Math.sin(D),M=(x?1-p+p*Math.sin(A*R/x):1)*Math.sign(M)*Math.abs(M)**o*(R<a?R/a:R<a+w?1-(R-a)/w*(1-m):R<a+w+s?m:R<P-f?(P-R-f)/n*m:0),M=f?M/2+(f>R?0:(R<P-f?1:(P-R)/f)*E[R-f|0]/2/t):M,L&&(M=O=U*I+j*(I=C)+U*(C=M)-z*F-S*(F=O))),B=(e+=u+=l)*Math.cos(y*J++),D+=B+B*d*Math.sin(R**5),T&&++T>b&&(e+=c,i+=c,T=0),!x||++W%x||(e=i,u=G,T=T||1);return E}let pb=[],Q=u();function Ha(t,i=u(),e){var a=Math.max(t.x-i.x/2|0,0),s=Math.max(t.y-i.y/2|0,0),h=Math.min(t.x+i.x/2,Q.x);for(t=Math.min(t.y+i.y/2,Q.y);s<t;++s)for(i=a;i<h;++i){var n=pb[s*Q.x+i];if(n&&(!e||0<n))return!0}return!1}class qb{constructor(t,i=0,e=!1,a=new x){this.$=t,this.direction=i,this.o=e,this.color=a}clear(){this.$=this.direction=0,this.o=!1,this.color=new x}}function rb(t,i,e=!0){var a=t.l.size;e&&(e=i.multiply(a),t.context.clearRect(e.x,t.canvas.height-e.y,a.x,-a.y)),null!=(e=t.getData(i)).$&&(i=i.add(u(.5)),t=Ja(e.$,a,t.l.Z,t.l.padding),Ia(i,u(1),t,e.color,e.direction*h/2,e.o))}class sb extends Fa{constructor(t,i=Q){var e=Ja(),a=u(1);for(super(t,i,e,0,void 0,0),this.canvas=document.createElement("canvas"),this.context=this.canvas.getContext("2d"),this.scale=a,this.wa=!1,this.data=[],t=this.size,t=Math.abs(t.x*t.y);t--;)this.data.push(new qb)}setData(t,i,e=!1){ra(t,this.size)&&(this.data[(0|t.y)*this.size.x+t.x|0]=i,e)&&rb(this,t)}getData(t){return ra(t,this.size)&&this.data[(0|t.y)*this.size.x+t.x|0]}update(){}C(){let t=Qa(this.i.add(u(0,this.size.y*this.scale.y)));t=t.floor(),(this.wa?I:E).drawImage(this.canvas,t.x,t.y,B*this.size.x*this.scale.x,B*this.size.y*this.scale.y)}}function tb(t){var i="number"==typeof t.V?na(t.V/2):u(v(-.5,.5),v(-.5,.5)).multiply(t.V).rotate(t.angle);let e=v(t.na,-t.na);t.X||(i=t.i.add(i),e+=t.angle);const a=t.O;var s=(o=t=>t+t*v(a,-a))(t.Aa),h=o(t.Y),n=o(t.Da),r=o(t.speed),o=o(t.ta)*(2*Math.floor(v(2,0))-1),l=v(t.ga,-t.ga),c=oa(t.S,t.T,t.pa),b=oa(t.da,t.ea,t.pa),l=t.X?l:t.angle+l;(i=new ub(i,t.l,e,c,b,s,h,n,t.G,t.I,t.H,t.X&&t,t.za)).g=ma(u(),l,r),i.R=o,i.G=t.G,i.D=t.D,i.J=t.J,i.s=t.s,i.W=t.W,i.N=t.N,i.K=t.K,i.P=t.P,i.o=!!Math.floor(v(2,0)),t.oa&&t.oa(i)}class vb extends Fa{constructor(t,i,e=0,a=0,s=100,n=h,r,o=new x,l=new x,c=new x(1,1,1,0),b=new x(1,1,1,0),d=.5,y=.1,g=1,f=.1,v=.05,m=1,w=1,p=0,L=h,A=.1,E=.2,D=!1,R=!1,T=!0,M=R?1e9:0,S=!1){super(t,u(),r,i,void 0,M),this.V=e,this.ia=a,this.ha=s,this.ga=n,this.S=o,this.T=l,this.da=c,this.ea=b,this.pa=T,this.Aa=d,this.Y=y,this.Da=g,this.speed=f,this.ta=v,this.D=m,this.J=w,this.N=p,this.na=L,this.G=A,this.O=E,this.K=D,this.I=R,this.X=S,this.H=0,this.oa=this.za=void 0,this.F=0}update(){if(this.parent&&super.update(),!this.ia||ia-this.ra<=this.ia){if(+this.ha){var t=1/this.ha;for(this.F+=wb;0<this.F;this.F-=t)tb(this)}}else Ea(this)}C(){}}class ub extends Fa{constructor(t,i,e,a,s,h,n,r,o,l,c,b,x){super(t,u(),i,e),this.M=a,this.L=s.u(a),this.ma=h,this.Y=n,this.Ea=r-n,this.G=o,this.I=l,this.H=c,this.B=b,this.fa=x,this.ba=!1}C(){var t=0<this.ma?Math.min((ia-this.ra)/this.ma,1):1,i=u(this.Y+t*this.Ea),e=this.G/2,e=new x(this.M.r+t*this.L.r,this.M.j+t*this.L.j,this.M.b+t*this.L.b,(this.M.a+t*this.L.a)*(t<e?t/e:1-e<t?(1-t)/e:1));this.I&&(xb=!0);let a=this.i;var s,h,n=this.angle;this.B&&(a=this.B.i.add(a.rotate(-this.B.angle)),n+=this.B.angle),this.H?(s=this.g,(n=(s=this.B?s.rotate(-this.B.angle):s).length())&&(s=s.scale(1/n),h=n*this.H,i.y=Math.max(i.x,h),n=s.angle(),Ia(a.add(s.multiply(u(0,-h/2))),i,this.l,e,n,this.o))):Ia(a,i,this.l,e,n,this.o),this.I&&(xb=void 0),1==t&&(this.color=e,this.size=i,this.fa&&this.fa(this),this.A=1)}}const yb={};let zb=[],Ab,Bb;function Cb(i){Object.values(yb).forEach(t=>i(t))}class Db{constructor(){this.id=0,this.name="Example Medal",this.description="Welcome to LittleJS!",this.icon="🏆",this.aa=!1,yb[0]=this}unlock(){this.aa||(localStorage[Ab+"_"+this.id]=this.aa=!0,zb.push(this))}C(t=0){var i=I,e=Math.min(Ca.x,D.width),a=G.width-e;t*=-Ca.y,i.save(),i.beginPath(),i.fillStyle=new x(.9,.9,.9).toString(),i.strokeStyle=new x(0,0,0).toString(),i.lineWidth=3,i.rect(a,t,e,Ca.y),i.fill(),i.stroke(),i.clip(),e=u(a+15+25,t+Ca.y/2),this.image?I.drawImage(this.image,e.x-25,e.y-25,50,50):Ua(this.icon,e,35,new x(0,0,0)),a=u(a+50+30,t+28),Ua(this.name,a,38,new x(0,0,0),0,void 0,"left"),a.y+=32,Ua(this.description,a,24,new x(0,0,0),0,void 0,"left"),i.restore()}}let R,L,Eb,Fb,Gb,Hb,U,Ib,V,xb,Jb;function Kb(){R=document.createElement("canvas"),L=R.getContext("webgl2",{antialias:!0}),D.parentElement.appendChild(R);var t=L.createProgram();L.attachShader(t,Ob("#version 300 es\nprecision highp float;uniform mat4 m;in vec2 g;in vec4 p,u,c,a;in float r;out vec2 v;out vec4 d,e;void main(){vec2 s=(g-.5)*p.zw;gl_Position=m*vec4(p.xy+s*cos(r)-vec2(-s.y,s)*sin(r),1,1);v=mix(u.xw,u.zy,g);d=c;e=a;}",L.VERTEX_SHADER)),L.attachShader(t,Ob("#version 300 es\nprecision highp float;uniform sampler2D s;in vec2 v;in vec4 d,e;out vec4 c;void main(){c=texture(s,v)*d+e;}",L.FRAGMENT_SHADER)),L.linkProgram(t),Eb=t,t=new ArrayBuffer(44e4),U=new Float32Array(t),Ib=new Uint32Array(t),Gb=L.createBuffer(),Hb=L.createBuffer(),t=new Float32Array([V=0,0,1,0,0,1,1,1]),L.bindBuffer(L.ARRAY_BUFFER,Hb),L.bufferData(L.ARRAY_BUFFER,t,L.STATIC_DRAW)}function Pb(){L.viewport(0,0,R.width=D.width,R.height=D.height),L.clear(L.COLOR_BUFFER_BIT),L.useProgram(Eb),L.activeTexture(L.TEXTURE0),K[0]&&L.bindTexture(L.TEXTURE_2D,Fb=K[0].ja);let r=xb=Jb=0;var t=(t,i,e,a)=>{t=L.getAttribLocation(Eb,t);var s=e&&44,h=e&&1,n=1==e;L.enableVertexAttribArray(t),L.vertexAttribPointer(t,a,i,n,s,r),L.vertexAttribDivisor(t,h),r+=a*e},i=(L.bindBuffer(L.ARRAY_BUFFER,Hb),t("g",L.FLOAT,0,2),L.bindBuffer(L.ARRAY_BUFFER,Gb),L.bufferData(L.ARRAY_BUFFER,44e4,L.DYNAMIC_DRAW),t("p",L.FLOAT,4,4),t("u",L.FLOAT,4,4),t("c",L.UNSIGNED_BYTE,1,4),t("a",L.UNSIGNED_BYTE,1,4),t("r",L.FLOAT,4,1),t=u(2*B).U(J),u(-1).u(A.multiply(t)));L.uniformMatrix4fv(L.getUniformLocation(Eb,"m"),!1,[t.x,0,0,0,0,t.y,0,0,1,1,1,1,i.x,i.y,0,0])}function Ra(t){t!=Fb&&(Qb(),L.bindTexture(L.TEXTURE_2D,Fb=t))}function Ob(t,i){return i=L.createShader(i),L.shaderSource(i,t),L.compileShader(i),i}function Qb(){var t;V&&(t=Jb?L.ONE:L.ONE_MINUS_SRC_ALPHA,L.blendFuncSeparate(L.SRC_ALPHA,t,L.ONE,t),L.enable(L.BLEND),L.bufferSubData(L.ARRAY_BUFFER,0,U),L.drawArraysInstanced(L.TRIANGLE_STRIP,0,4,V),V=0,Jb=xb)}function Rb(t=!1){var i=E;(V||t)&&(Qb(),t)&&i.drawImage(R,0,0)}function Sa(t,i,e,a,s,h,n,r,o,u,l=0){(1e4<=V||Jb!=xb)&&Qb();var c=11*V++;U[c++]=t,U[c++]=i,U[c++]=e,U[c++]=a,U[c++]=h,U[c++]=n,U[c++]=r,U[c++]=o,Ib[c++]=u,Ib[c++]=l,U[+c]=s}const wb=1/60;let C=[],Ga=[],Sb=0,ia=0,Tb=0,Ub=0,W=0;const Vb=[],Wb=[];function Xb(t){Vb.includes(void 0),Wb.includes(t),t&&Wb.push(t)}function Yb(){Ga=C.filter(t=>t.ca);for(const t of C)t.parent||(function t(i){if(!i.A){i.update();for(const e of i.children)t(e)}}(t),Da(t));C=C.filter(t=>!t.A)}function Zb(t){const u=I;var e=G.width=innerWidth,a=G.height=innerHeight,s=r(t,1,.8),n=r(t,0,.5),i=u.createRadialGradient(e/2,a/2,0,e/2,a/2,.7*Math.hypot(e,a));i.addColorStop(0,y(0,0,s/2*k(n),s).toString()),i.addColorStop(1,y(0,0,0,s).toString()),u.save(),u.fillStyle=i,u.fillRect(0,0,e,a),i=(t,i,e,a,s)=>{u.beginPath(),u.rect(t,i,e,s?a*l:a),(u.fillStyle=s)?u.fill():u.stroke()},n=(t,i,e,a=0,s=2*h,n,r)=>{var o=(a+s)/2;a=l*(s-a)/2,u.beginPath(),r&&u.lineTo(t,i),u.arc(t,i,e,o-a,o+a),(u.fillStyle=n)?u.fill():u.stroke()},s=(t=0,i=0)=>y([.98,.3,.57,.14][t%4]-10,.8,[0,.3,.5,.8,.9][i]).toString();const l=r(t=ha(t),.1,.5);for(u.translate(e/2,a/2),e=Math.min(6,Math.min(e,a)/99),u.scale(e,e),u.translate(-40,-35),u.lineJoin=u.lineCap="round",u.lineWidth=.1+1.9*l,u.setLineDash([99*r(t,.1,1),99]),i(7,16,18,-8,s(2,2)),i(7,8,18,4,s(2,3)),i(25,8,8,8,s(2,1)),i(25,8,-18,8),i(25,8,8,8),i(25,16,7,23,s()),i(11,39,14,-23,s(1,1)),i(11,16,14,18,s(1,2)),i(11,16,14,8,s(1,3)),i(25,16,-14,24),i(15,29,6,-9,s(2,2)),n(15,21,5,0,h/2,s(2,4),1),i(21,21,-6,9),i(37,14,9,6,s(3,2)),i(37,14,4.5,6,s(3,3)),i(37,14,9,6),i(50,20,10,-8,s(0,1)),i(50,20,6.5,-8,s(0,2)),i(50,20,3.5,-8,s(0,3)),i(50,20,10,-8),n(55,2,11.4,.5,h-.5,s(3,3)),n(55,2,11.4,.5,h/2,s(3,2),1),n(55,2,11.4,.5,h-.5),i(45,7,20,-7,s(0,2)),i(45,-1,20,4,s(0,3)),i(45,-1,20,8),e=5;e--;)n(60-6*e,30,9.9,0,2*h,s(e+2,3)),n(60-6*e,30,10,-.5,h+.5,s(e+2,2)),n(60-6*e,30,10.1,.5,h-.5,s(e+2,1));for(n(36,30,10,h/2,3*h/2),n(48,30,10,h/2,3*h/2),n(60,30,10),u.beginPath(),u.lineTo(36,20),u.lineTo(60,20),u.stroke(),n(60,30,4,h,3*h,s(3,2)),n(60,30,4,h,2*h,s(3,3)),n(60,30,4,h,3*h),e=6;e--;)u.beginPath(),u.lineTo(53,54),u.lineTo(53,40),u.lineTo(53+(1+2.9*e)*l,40),u.lineTo(53+(4+3.5*e)*l,54),u.fillStyle=s(0,e%2+2),u.fill(),e%2&&u.stroke();for(i(6,40,5,5),i(6,40,5,5,s()),i(15,54,38,-14,s()),e=3;e--;)for(a=2;a--;)n(15*e+15,47,a?7:1,h,3*h,s(e,3)),u.stroke(),n(15*e+15,47,a?7:1,0,h,s(e,2)),u.stroke();for(u.beginPath(),u.lineTo(6,40),u.lineTo(68,40),u.stroke(),u.beginPath(),u.lineTo(77,54),u.lineTo(4,54),u.stroke(),u.font="900 16px arial",u.textAlign="center",u.textBaseline="top",u.lineWidth=.1+3.9*l,e=n=0;e<8;++e)n+=u.measureText("LittleJS"[e]).width;for(e=2;e--;)for(let t=0,i=41-n/2;t<8;++t)u.fillStyle=s(t,2),a=u.measureText("LittleJS"[t]).width,u[e?"strokeText":"fillText"]("LittleJS"[t],i+a/2,55.5,17*l),i+=a;u.restore()}va=!0,Aa=.5;const $b=new hb,ac=new Db;Ab="Hello World",Cb(t=>t.aa=!!localStorage[Ab+"_"+t.id]),Xb(function(){var t,i;zb.length&&(t=zb[0],i=Tb-Bb,Bb?5<i?(Bb=0,zb.shift()):t.C(i<.5?1-i/.5:4.5<i?(i-4.5)/.5:0):Bb=Tb)});let Z;!function(i,a,s,h,n,t,e=document.body){function r(t=0){var i=t-Ub;for(Ub=t,Tb+=i/1e3,W+=i,W=Math.min(W,50),o(),t=0,W<0&&-9<W&&(t=W,W=0);0<=W;W-=1e3/60)ia=Sb++/60,cb||document.hasFocus()||(O=[[]]),Wa=Ma(),fb(),a(),Vb.forEach(t=>t()),Yb(),s(),$a();W+=t,J=u(D.width,D.height),I.imageSmoothingEnabled=E.imageSmoothingEnabled=!1,Pb(),h(),C.sort((t,i)=>t.P-i.P);for(const e of C)e.A||e.C();n(),Wb.forEach(t=>t()),Rb(),requestAnimationFrame(r)}function o(){var t,i;ua.x?(D.width=ua.x,D.height=ua.y,t=innerWidth/innerHeight,i=D.width/D.height,(R||D).style.width=D.style.width=G.style.width=t<i?"100%":"",(R||D).style.height=D.style.height=G.style.height=t<i?"":"100%"):(D.width=Math.min(innerWidth,ta.x),D.height=Math.min(innerHeight,ta.y)),G.width=D.width,G.height=D.height,J=u(D.width,D.height)}i||=()=>{},a||=()=>{},s||=()=>{},h||=()=>{},n||=()=>{},e.style.cssText="margin:0;overflow:hidden;width:100vw;height:100vh;display:flex;align-items:center;justify-content:center;background:#000;image-rendering:pixelated;user-select:none;-webkit-user-select:none;touch-action:none;-webkit-touch-callout:none",e.appendChild(D=document.createElement("canvas")),E=D.getContext("2d"),ab(),(gb=P.createGain()).connect(P.destination),gb.gain.value=.3,Kb(),e.appendChild(G=document.createElement("canvas")),I=G.getContext("2d"),D.style.cssText=G.style.cssText="position:absolute",R&&(R.style.cssText="position:absolute"),o(),e=t.map((e,a)=>new Promise(t=>{const i=new Image;i.crossOrigin="anonymous",i.onerror=i.onload=()=>{K[a]=new La(i),t()},i.src=e})),t.length||e.push(new Promise(t=>{K[0]=new La(new Image),t()})),va&&e.push(new Promise(i=>{let e=0;console.log("LittleJS Engine v1.11.10"),function t(){O=[[]],Zb(e+=.01),1<e?i():setTimeout(t,16)}()})),Promise.all(e).then(function(){new Promise(t=>t(i())).then(r)})}(function(){Q=u(32,16);for(var t=(pb=[]).length=Math.abs(Q.x*Q.y);t--;)pb[t]=0;var i,e,a,s=u(),t=new sb(s,Q),n=K[0].image,r=(E.drawImage(n,0,0),E.getImageData(0,0,n.width,n.height).data);for(s.x=Q.x;s.x--;)for(s.y=Q.y;s.y--;)r[4*(s.x+n.width*(15+Q.y-s.y))]&&(i=Math.floor(v(4,0)),e=!Math.floor(v(2,0)),a=oa(),t.setData(s,new qb(1,i,e,a)),ra(s,Q))&&(pb[(0|s.y)*Q.x+s.x|0]=1);for(t.Ca=[D,E,J,A,B],D=t.canvas,E=t.context,J=t.size.multiply(t.l.size),A=t.size.scale(.5),B=t.l.size.x,D.width=J.x,D.height=J.y,t.context.imageSmoothingEnabled=!1,Pb(),s=t.size.x;s--;)for(n=t.size.y;n--;)rb(t,u(s,n),!1);Rb(!0),[D,E,J,A,B]=t.Ca,A=u(16,8),B=32,Ba=-.01,(Z=new vb(u(16,9),0,0,0,500,h,Ja(0,16),y(1,1,1),y(0,0,0),y(0,0,0,0),y(0,0,0,0),2,.2,.2,.1,.05,.99,1,1,h,.05,.5,!0,!0)).s=.3,Z.H=2},function(){O[0]&&2&O[0][0]&&($b.play(Wa),Z.S=y(),Z.T=oa(),Z.da=Z.S.scale(1,0),Z.ea=Z.T.scale(1,0),ac.unlock()),Xa&&(B=k(B-=Math.sign(Xa)*B/5,10,300)),Pa.x&&(Z.i=Wa)},function(){},function(){Ia(u(16,8),u(20,14),void 0,y(0,0,.6),0,!1,void 0,!1),Ia(u(21,5),u(4.5),Ja(3,128))},function(){Ua("LittleJS Demo",u(J.x/2,70),80,y(0,0,1),6,y(0,0,0))},["tiles.png"]);
Binary file
Binary file