littlejsengine 1.11.13 → 1.12.4
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.
- package/dist/littlejs.d.ts +1418 -109
- package/dist/littlejs.esm.js +3495 -581
- package/dist/littlejs.esm.min.js +1 -1
- package/dist/littlejs.js +3258 -399
- package/dist/littlejs.min.js +1 -1
- package/dist/littlejs.release.js +3147 -379
- package/examples/box2d/game.js +73 -45
- package/examples/box2d/gameObjects.js +96 -92
- package/examples/box2d/index.html +2 -7
- package/examples/box2d/scenes.js +82 -92
- package/examples/breakout/game.js +62 -30
- package/examples/breakout/gameObjects.js +45 -47
- package/examples/breakout/index.html +1 -5
- package/examples/breakoutTutorial/game.js +36 -29
- package/examples/breakoutTutorial/index.html +1 -3
- package/examples/empty/game.js +5 -2
- package/examples/empty/index.html +1 -3
- package/examples/htmlMenu/game.js +25 -19
- package/examples/htmlMenu/index.html +5 -7
- package/examples/index.html +2 -3
- package/examples/module/game.js +32 -34
- package/examples/module/index.html +1 -1
- package/examples/particles/index.html +27 -22
- package/examples/platformer/game.js +71 -48
- package/examples/platformer/gameCharacter.js +42 -34
- package/examples/platformer/gameEffects.js +82 -75
- package/examples/platformer/gameLevel.js +67 -38
- package/examples/platformer/{gameLevelData.js → gameLevelData.json} +1 -11
- package/examples/platformer/gameObjects.js +70 -64
- package/examples/platformer/gamePlayer.js +12 -7
- package/examples/platformer/index.html +1 -9
- package/examples/puzzle/game.js +58 -42
- package/examples/puzzle/index.html +1 -3
- package/examples/shorts/base.html +2 -2
- package/examples/shorts/particles.js +1 -1
- package/examples/shorts/platformer.js +1 -1
- package/examples/shorts/tileLayer.js +5 -6
- package/examples/shorts/tiles.png +0 -0
- package/examples/starter/build.js +4 -4
- package/examples/starter/game.js +9 -12
- package/examples/starter/index.html +13 -13
- package/examples/stress/index.html +44 -43
- package/examples/typescript/build.js +17 -18
- package/examples/typescript/game.js +32 -34
- package/examples/typescript/game.ts +32 -34
- package/examples/typescript/index.html +1 -1
- package/examples/uiSystem/game.js +33 -36
- package/examples/uiSystem/index.html +1 -5
- package/package.json +3 -3
- package/plugins/box2d.js +1556 -640
- package/plugins/{Box2D_v2.3.1_min.wasm.js → box2d.wasm.js} +1 -1
- package/plugins/newgrounds.js +7 -8
- package/plugins/pluginExport.js +50 -0
- package/plugins/postProcess.js +94 -93
- package/plugins/uiSystem.js +145 -161
- package/plugins/zzfxm.js +163 -0
- package/reference.md +29 -27
- package/src/engine.js +15 -20
- package/src/engineAudio.js +74 -204
- package/src/engineBuild.js +29 -4
- package/src/engineDebug.js +105 -9
- package/src/engineDraw.js +27 -14
- package/src/engineExport.js +12 -8
- package/src/engineInput.js +3 -1
- package/src/engineObject.js +18 -14
- package/src/engineParticles.js +6 -1
- package/src/engineRelease.js +6 -1
- package/src/engineSettings.js +8 -8
- package/src/engineTileLayer.js +179 -96
- package/src/engineUtilities.js +5 -11
- package/src/engineWebGL.js +19 -7
- package/examples/starter/build/index.html +0 -2
- package/examples/starter/build/index.js +0 -1
- package/examples/starter/build/tiles.png +0 -0
- package/examples/starter/game.zip +0 -0
- package/examples/typescript/build/dist/littlejs.esm.js +0 -4834
- package/examples/typescript/build/examples/typescript/build.js +0 -24
- package/examples/typescript/build/examples/typescript/game.js +0 -102
- /package/plugins/{Box2D_v2.3.1_min.wasm.wasm → box2d.wasm.wasm} +0 -0
package/src/engineTileLayer.js
CHANGED
|
@@ -2,75 +2,47 @@
|
|
|
2
2
|
* LittleJS Tile Layer System
|
|
3
3
|
* - Caches arrays of tiles to off screen canvas for fast rendering
|
|
4
4
|
* - Unlimited numbers of layers, allocates canvases as needed
|
|
5
|
-
* - Interfaces with EngineObject for collision
|
|
6
|
-
* - Collision layer is separate from visible layers
|
|
7
|
-
* - It is recommended to have a visible layer that matches the collision
|
|
8
5
|
* - Tile layers can be drawn to using their context with canvas2d
|
|
9
6
|
* - Drawn directly to the main canvas without using WebGL
|
|
7
|
+
* - Tile layers can also have collision with EngineObjects
|
|
10
8
|
* @namespace TileCollision
|
|
11
9
|
*/
|
|
12
10
|
|
|
13
11
|
'use strict';
|
|
14
12
|
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
* @memberof TileCollision */
|
|
18
|
-
let tileCollision = [];
|
|
19
|
-
|
|
20
|
-
/** Size of the tile collision layer 2d grid
|
|
21
|
-
* @type {Vector2}
|
|
22
|
-
* @memberof TileCollision */
|
|
23
|
-
let tileCollisionSize = vec2();
|
|
13
|
+
///////////////////////////////////////////////////////////////////////////////
|
|
14
|
+
// Tile Layer System
|
|
24
15
|
|
|
25
|
-
/**
|
|
26
|
-
* @
|
|
16
|
+
/** Keep track of all tile layers with collision
|
|
17
|
+
* @type {Array<TileCollisionLayer>}
|
|
27
18
|
* @memberof TileCollision */
|
|
28
|
-
|
|
29
|
-
{
|
|
30
|
-
tileCollisionSize = size;
|
|
31
|
-
tileCollision = [];
|
|
32
|
-
for (let i=tileCollision.length = tileCollisionSize.area(); i--;)
|
|
33
|
-
tileCollision[i] = 0;
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
/** Set tile collision data for a given cell in the grid
|
|
37
|
-
* @param {Vector2} pos
|
|
38
|
-
* @param {number} [data]
|
|
39
|
-
* @memberof TileCollision */
|
|
40
|
-
function setTileCollisionData(pos, data=0)
|
|
41
|
-
{
|
|
42
|
-
pos.arrayCheck(tileCollisionSize) && (tileCollision[(pos.y|0)*tileCollisionSize.x+pos.x|0] = data);
|
|
43
|
-
}
|
|
19
|
+
let tileCollisionLayers = [];
|
|
44
20
|
|
|
45
21
|
/** Get tile collision data for a given cell in the grid
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
22
|
+
* @param {Vector2} pos
|
|
23
|
+
* @return {number}
|
|
24
|
+
* @memberof TileCollision */
|
|
49
25
|
function getTileCollisionData(pos)
|
|
50
26
|
{
|
|
51
|
-
|
|
27
|
+
// check all tile collision layers
|
|
28
|
+
for (const layer of tileCollisionLayers)
|
|
29
|
+
if (pos.arrayCheck(layer.size))
|
|
30
|
+
return layer.getCollisionData(pos);
|
|
31
|
+
return 0;
|
|
52
32
|
}
|
|
53
33
|
|
|
54
|
-
/** Check if
|
|
34
|
+
/** Check if a tile layer collides with another object
|
|
55
35
|
* @param {Vector2} pos
|
|
56
36
|
* @param {Vector2} [size=(0,0)]
|
|
57
37
|
* @param {EngineObject} [object]
|
|
58
|
-
* @return {
|
|
38
|
+
* @return {TileCollisionLayer}
|
|
59
39
|
* @memberof TileCollision */
|
|
60
40
|
function tileCollisionTest(pos, size=vec2(), object)
|
|
61
41
|
{
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
for (let y = minY; y < maxY; ++y)
|
|
67
|
-
for (let x = minX; x < maxX; ++x)
|
|
68
|
-
{
|
|
69
|
-
const tileData = tileCollision[y*tileCollisionSize.x+x];
|
|
70
|
-
if (tileData && (!object || object.collideWithTile(tileData, vec2(x, y))))
|
|
71
|
-
return true;
|
|
72
|
-
}
|
|
73
|
-
return false;
|
|
42
|
+
// check all tile collision layers
|
|
43
|
+
for (const layer of tileCollisionLayers)
|
|
44
|
+
if (layer.collisionTest(pos, size, object))
|
|
45
|
+
return layer;
|
|
74
46
|
}
|
|
75
47
|
|
|
76
48
|
/** Return the center of first tile hit, undefined if nothing was hit.
|
|
@@ -82,49 +54,17 @@ function tileCollisionTest(pos, size=vec2(), object)
|
|
|
82
54
|
* @memberof TileCollision */
|
|
83
55
|
function tileCollisionRaycast(posStart, posEnd, object)
|
|
84
56
|
{
|
|
85
|
-
//
|
|
86
|
-
|
|
87
|
-
const delta = posEnd.subtract(posStart);
|
|
88
|
-
const totalLength = delta.length();
|
|
89
|
-
const normalizedDelta = delta.normalize();
|
|
90
|
-
const unit = vec2(abs(1/normalizedDelta.x), abs(1/normalizedDelta.y));
|
|
91
|
-
const flooredPosStart = posStart.floor();
|
|
92
|
-
|
|
93
|
-
// setup iteration variables
|
|
94
|
-
let pos = flooredPosStart;
|
|
95
|
-
let xi = unit.x * (delta.x < 0 ? posStart.x - pos.x : pos.x - posStart.x + 1);
|
|
96
|
-
let yi = unit.y * (delta.y < 0 ? posStart.y - pos.y : pos.y - posStart.y + 1);
|
|
97
|
-
|
|
98
|
-
while (true)
|
|
57
|
+
// check all tile collision layers
|
|
58
|
+
for (const layer of tileCollisionLayers)
|
|
99
59
|
{
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
{
|
|
104
|
-
debugRaycast && debugLine(posStart, posEnd, '#f00', .02);
|
|
105
|
-
debugRaycast && debugPoint(pos.add(vec2(.5)), '#ff0');
|
|
106
|
-
return pos.add(vec2(.5));
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
// check if past the end
|
|
110
|
-
if (xi > totalLength && yi > totalLength)
|
|
111
|
-
break;
|
|
112
|
-
|
|
113
|
-
// get coordinates of the next tile to check
|
|
114
|
-
if (xi > yi)
|
|
115
|
-
pos.y += sign(delta.y), yi += unit.y;
|
|
116
|
-
else
|
|
117
|
-
pos.x += sign(delta.x), xi += unit.x;
|
|
60
|
+
const hitPos = layer.collisionRaycast(posStart, posEnd, object)
|
|
61
|
+
if (hitPos)
|
|
62
|
+
return hitPos;
|
|
118
63
|
}
|
|
119
|
-
|
|
120
|
-
debugRaycast && debugLine(posStart, posEnd, '#00f', .02);
|
|
121
64
|
}
|
|
122
65
|
|
|
123
|
-
///////////////////////////////////////////////////////////////////////////////
|
|
124
|
-
// Tile Layer Rendering System
|
|
125
|
-
|
|
126
66
|
/**
|
|
127
|
-
* Tile layer data object stores info about how to
|
|
67
|
+
* Tile layer data object stores info about how to draw a tile
|
|
128
68
|
* @example
|
|
129
69
|
* // create tile layer data with tile index 0 and random orientation and color
|
|
130
70
|
* const tileIndex = 0;
|
|
@@ -156,28 +96,27 @@ class TileLayerData
|
|
|
156
96
|
clear() { this.tile = this.direction = 0; this.mirror = false; this.color = new Color; }
|
|
157
97
|
}
|
|
158
98
|
|
|
99
|
+
///////////////////////////////////////////////////////////////////////////////
|
|
159
100
|
/**
|
|
160
101
|
* Tile Layer - cached rendering system for tile layers
|
|
161
102
|
* - Each Tile layer is rendered to an off screen canvas
|
|
162
103
|
* - To allow dynamic modifications, layers are rendered using canvas 2d
|
|
163
104
|
* - Some devices like mobile phones are limited to 4k texture resolution
|
|
164
|
-
* -
|
|
105
|
+
* - For with 16x16 tiles this limits layers to 256x256 on mobile devices
|
|
165
106
|
* @extends EngineObject
|
|
166
107
|
* @example
|
|
167
|
-
*
|
|
168
|
-
* initTileCollision(vec2(200,100));
|
|
169
|
-
* const tileLayer = new TileLayer();
|
|
108
|
+
* const tileLayer = new TileLayer(vec2(), vec2(200,100));
|
|
170
109
|
*/
|
|
171
110
|
class TileLayer extends EngineObject
|
|
172
111
|
{
|
|
173
112
|
/** Create a tile layer object
|
|
174
|
-
* @param {Vector2} [position=(0,0)]
|
|
175
|
-
* @param {Vector2} [size=
|
|
176
|
-
* @param {TileInfo} [tileInfo]
|
|
177
|
-
* @param {Vector2} [scale=(1,1)]
|
|
178
|
-
* @param {number} [renderOrder]
|
|
113
|
+
* @param {Vector2} [position=(0,0)] - World space position
|
|
114
|
+
* @param {Vector2} [size=(1,1)] - World space size
|
|
115
|
+
* @param {TileInfo} [tileInfo] - Tile info for layer
|
|
116
|
+
* @param {Vector2} [scale=(1,1)] - How much to scale this layer when rendered
|
|
117
|
+
* @param {number} [renderOrder] - Objects are sorted by renderOrder
|
|
179
118
|
*/
|
|
180
|
-
constructor(position, size
|
|
119
|
+
constructor(position, size, tileInfo=tile(), scale=vec2(1), renderOrder=0)
|
|
181
120
|
{
|
|
182
121
|
super(position, size, tileInfo, 0, undefined, renderOrder);
|
|
183
122
|
|
|
@@ -189,6 +128,10 @@ class TileLayer extends EngineObject
|
|
|
189
128
|
this.scale = scale;
|
|
190
129
|
/** @property {boolean} - If true this layer will render to overlay canvas and appear above all objects */
|
|
191
130
|
this.isOverlay = false;
|
|
131
|
+
// set no friction by default, applied friction is max of both objects
|
|
132
|
+
this.friction = 0;
|
|
133
|
+
// set no elasticity by default, applied elasticity is max of both objects
|
|
134
|
+
this.elasticity = 0;
|
|
192
135
|
|
|
193
136
|
// init tile data
|
|
194
137
|
this.data = [];
|
|
@@ -385,4 +328,144 @@ class TileLayer extends EngineObject
|
|
|
385
328
|
* @param {number} [angle=0] */
|
|
386
329
|
drawRect(pos, size, color, angle)
|
|
387
330
|
{ this.drawTile(pos, size, undefined, color, angle); }
|
|
331
|
+
}
|
|
332
|
+
|
|
333
|
+
///////////////////////////////////////////////////////////////////////////////
|
|
334
|
+
/**
|
|
335
|
+
* Tile Collision Layer - a tile layer with collision
|
|
336
|
+
* - adds collision data and functions to TileLayer
|
|
337
|
+
* - there can be multiple tile collision layers
|
|
338
|
+
* - tile collison layers should not overlap each other
|
|
339
|
+
* @extends TileLayer
|
|
340
|
+
*/
|
|
341
|
+
class TileCollisionLayer extends TileLayer
|
|
342
|
+
{
|
|
343
|
+
/** Create a tile layer object
|
|
344
|
+
* @param {Vector2} [position=(0,0)] - World space position
|
|
345
|
+
* @param {Vector2} [size=(0,0)] - World space size
|
|
346
|
+
* @param {TileInfo} [tileInfo] - Tile info for layer
|
|
347
|
+
* @param {number} [renderOrder] - Objects are sorted by renderOrder
|
|
348
|
+
*/
|
|
349
|
+
constructor(position, size, tileInfo=tile(), renderOrder=0)
|
|
350
|
+
{
|
|
351
|
+
const scale = vec2(1); // collision layers are not scaled
|
|
352
|
+
super(position, size.floor(), tileInfo, scale, renderOrder);
|
|
353
|
+
|
|
354
|
+
/** @property {Array<number>} - The tile collision grid */
|
|
355
|
+
this.collisionData = [];
|
|
356
|
+
this.initCollision(this.size);
|
|
357
|
+
|
|
358
|
+
// keep track of all collision layers
|
|
359
|
+
tileCollisionLayers.push(this);
|
|
360
|
+
}
|
|
361
|
+
|
|
362
|
+
/** Destroy this collision layer */
|
|
363
|
+
destroy()
|
|
364
|
+
{
|
|
365
|
+
if (this.destroyed)
|
|
366
|
+
return;
|
|
367
|
+
|
|
368
|
+
// remove from collision layers array and destroy
|
|
369
|
+
const index = tileCollisionLayers.indexOf(this);
|
|
370
|
+
ASSERT(index >= 0, 'tile collision layer not found in array');
|
|
371
|
+
tileCollisionLayers.splice(index, 1);
|
|
372
|
+
super.destroy();
|
|
373
|
+
}
|
|
374
|
+
|
|
375
|
+
/** Clear and initialize tile collision to new size
|
|
376
|
+
* @param {Vector2} size - width and height of tile collision 2d grid */
|
|
377
|
+
initCollision(size)
|
|
378
|
+
{
|
|
379
|
+
this.size = size.floor();
|
|
380
|
+
this.collisionData = [];
|
|
381
|
+
this.collisionData.length = size.area();
|
|
382
|
+
this.collisionData.fill(0);
|
|
383
|
+
}
|
|
384
|
+
|
|
385
|
+
/** Set tile collision data for a given cell in the grid
|
|
386
|
+
* @param {Vector2} pos
|
|
387
|
+
* @param {number} [data] */
|
|
388
|
+
setCollisionData(pos, data=1)
|
|
389
|
+
{
|
|
390
|
+
const i = (pos.y|0)*this.size.x + pos.x|0;
|
|
391
|
+
pos.arrayCheck(this.size) && (this.collisionData[i] = data);
|
|
392
|
+
}
|
|
393
|
+
|
|
394
|
+
/** Get tile collision data for a given cell in the grid
|
|
395
|
+
* @param {Vector2} pos
|
|
396
|
+
* @return {number} */
|
|
397
|
+
getCollisionData(pos)
|
|
398
|
+
{
|
|
399
|
+
const i = (pos.y|0)*this.size.x + pos.x|0;
|
|
400
|
+
return pos.arrayCheck(this.size) ? this.collisionData[i] : 0;
|
|
401
|
+
}
|
|
402
|
+
|
|
403
|
+
/** Check if collision with another object should occur
|
|
404
|
+
* @param {Vector2} pos
|
|
405
|
+
* @param {Vector2} [size=(0,0)]
|
|
406
|
+
* @param {EngineObject} [object]
|
|
407
|
+
* @return {boolean} */
|
|
408
|
+
collisionTest(pos, size=vec2(), object)
|
|
409
|
+
{
|
|
410
|
+
const minX = max(pos.x - size.x/2|0, 0);
|
|
411
|
+
const minY = max(pos.y - size.y/2|0, 0);
|
|
412
|
+
const maxX = min(pos.x + size.x/2, this.size.x);
|
|
413
|
+
const maxY = min(pos.y + size.y/2, this.size.y);
|
|
414
|
+
for (let y = minY; y < maxY; ++y)
|
|
415
|
+
for (let x = minX; x < maxX; ++x)
|
|
416
|
+
{
|
|
417
|
+
// check if the object should collide with this tile
|
|
418
|
+
const tileData = this.collisionData[y*this.size.x+x];
|
|
419
|
+
if (tileData && (!object || object.collideWithTile(tileData, vec2(x, y))))
|
|
420
|
+
return true;
|
|
421
|
+
}
|
|
422
|
+
return false;
|
|
423
|
+
}
|
|
424
|
+
|
|
425
|
+
/** Return the center of first tile hit, undefined if nothing was hit.
|
|
426
|
+
* This does not return the exact intersection, but the center of the tile hit.
|
|
427
|
+
* @param {Vector2} posStart
|
|
428
|
+
* @param {Vector2} posEnd
|
|
429
|
+
* @param {EngineObject} [object]
|
|
430
|
+
* @return {Vector2} */
|
|
431
|
+
collisionRaycast(posStart, posEnd, object)
|
|
432
|
+
{
|
|
433
|
+
// test if a ray collides with tiles from start to end
|
|
434
|
+
// todo: a way to get the exact hit point, it must still be inside the hit tile
|
|
435
|
+
const delta = posEnd.subtract(posStart);
|
|
436
|
+
const totalLength = delta.length();
|
|
437
|
+
const normalizedDelta = delta.normalize();
|
|
438
|
+
const unit = vec2(abs(1/normalizedDelta.x), abs(1/normalizedDelta.y));
|
|
439
|
+
const flooredPosStart = posStart.floor();
|
|
440
|
+
|
|
441
|
+
// setup iteration variables
|
|
442
|
+
let pos = flooredPosStart;
|
|
443
|
+
let xi = unit.x * (delta.x < 0 ? posStart.x - pos.x : pos.x - posStart.x + 1);
|
|
444
|
+
let yi = unit.y * (delta.y < 0 ? posStart.y - pos.y : pos.y - posStart.y + 1);
|
|
445
|
+
|
|
446
|
+
// use line drawing algorithm to test for collisions
|
|
447
|
+
while (true)
|
|
448
|
+
{
|
|
449
|
+
// check for tile collision
|
|
450
|
+
const tileData = this.getCollisionData(pos);
|
|
451
|
+
if (tileData && (!object || object.collideWithTile(tileData, pos)))
|
|
452
|
+
{
|
|
453
|
+
debugRaycast && debugLine(posStart, posEnd, '#f00', .02);
|
|
454
|
+
debugRaycast && debugPoint(pos.add(vec2(.5)), '#ff0');
|
|
455
|
+
return pos.add(vec2(.5));
|
|
456
|
+
}
|
|
457
|
+
|
|
458
|
+
// check if past the end
|
|
459
|
+
if (xi > totalLength && yi > totalLength)
|
|
460
|
+
break;
|
|
461
|
+
|
|
462
|
+
// get coordinates of next tile to check
|
|
463
|
+
if (xi > yi)
|
|
464
|
+
pos.y += sign(delta.y), yi += unit.y;
|
|
465
|
+
else
|
|
466
|
+
pos.x += sign(delta.x), xi += unit.x;
|
|
467
|
+
}
|
|
468
|
+
|
|
469
|
+
debugRaycast && debugLine(posStart, posEnd, '#00f', .02);
|
|
470
|
+
}
|
|
388
471
|
}
|
package/src/engineUtilities.js
CHANGED
|
@@ -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
|
|
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
|
|
293
|
-
* @param {
|
|
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
|
package/src/engineWebGL.js
CHANGED
|
@@ -106,12 +106,12 @@ function glPreRender()
|
|
|
106
106
|
|
|
107
107
|
// set vertex attributes
|
|
108
108
|
let offset = glAdditive = glBatchAdditive = 0;
|
|
109
|
-
|
|
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
|
-
|
|
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
|