littlejsengine 1.9.11 → 1.10.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/README.md +9 -13
- package/dist/littlejs.d.ts +129 -10
- package/dist/littlejs.esm.js +220 -75
- package/dist/littlejs.esm.min.js +1 -1
- package/dist/littlejs.js +188 -73
- package/dist/littlejs.min.js +1 -1
- package/dist/littlejs.release.js +187 -72
- package/examples/box2d/game.js +4 -1
- package/examples/box2d/index.html +7 -6
- package/examples/breakout/game.js +1 -1
- package/examples/breakout/index.html +5 -4
- package/examples/breakoutTutorial/README.md +9 -7
- package/examples/breakoutTutorial/game.js +6 -6
- package/examples/breakoutTutorial/index.html +4 -3
- package/examples/electron/game.js +1 -1
- package/examples/electron/index.html +4 -3
- package/examples/empty/game.js +1 -1
- package/examples/empty/index.html +2 -1
- package/examples/htmlMenu/game.js +67 -0
- package/examples/htmlMenu/index.html +56 -0
- package/examples/htmlMenu/tiles.png +0 -0
- package/examples/index.html +33 -0
- package/examples/js13k/build/index.html +1 -0
- package/examples/js13k/build/index.js +1 -0
- package/examples/js13k/build/tiles.png +0 -0
- package/examples/js13k/game - Copy.zip +0 -0
- package/examples/js13k/game.js +1 -1
- package/examples/js13k/game.zip +0 -0
- package/examples/js13k/index.html +17 -14
- package/examples/module/game.js +1 -1
- package/examples/module/index.html +3 -2
- package/examples/particles/index.html +4 -3
- package/examples/platformer/game.js +7 -5
- package/examples/platformer/gameCharacter.js +12 -11
- package/examples/platformer/gameEffects.js +3 -4
- package/examples/platformer/gameLevel.js +18 -34
- package/examples/platformer/gameObjects.js +9 -15
- package/examples/platformer/index.html +10 -9
- package/examples/puzzle/game.js +1 -1
- package/examples/puzzle/index.html +4 -3
- package/examples/starter/build/index.html +2 -0
- package/examples/starter/build/index.js +1 -0
- package/examples/starter/build/tiles.png +0 -0
- package/examples/starter/game.js +4 -4
- package/examples/starter/game.zip +0 -0
- package/examples/starter/index.html +15 -14
- package/examples/stress/index.html +3 -2
- package/examples/typescript/build/build/littlejs.esm.js +4327 -0
- package/examples/typescript/build/dist/littlejs.esm.js +4425 -0
- package/examples/typescript/build/examples/typescript/build.js +24 -0
- package/examples/typescript/build/examples/typescript/game.js +100 -0
- package/examples/typescript/build/examples/typescript/test/build/littlejs.esm.js +3934 -0
- package/examples/typescript/build/examples/typescript/test/examples/typescript/build.js +86 -0
- package/examples/typescript/build/examples/typescript/test/examples/typescript/game.js +92 -0
- package/examples/typescript/game.js +1 -1
- package/examples/typescript/game.ts +1 -1
- package/examples/typescript/index.html +3 -2
- package/examples/uiSystem/game.js +134 -0
- package/examples/uiSystem/index.html +25 -0
- package/examples/uiSystem/tiles.png +0 -0
- package/jsconfig.json +11 -0
- package/package.json +1 -1
- package/plugins/box2d.js +2 -1
- package/plugins/postProcess.js +14 -8
- package/plugins/uiSystem.js +243 -0
- package/src/engine.js +42 -22
- package/src/engineAudio.js +10 -13
- package/src/engineDebug.js +1 -1
- package/src/engineDraw.js +102 -27
- package/src/engineExport.js +32 -2
- package/src/engineInput.js +1 -3
- package/src/engineObject.js +1 -0
- package/src/engineSettings.js +1 -1
- package/src/engineTileLayer.js +2 -1
- package/src/engineUtilities.js +2 -1
- package/src/engineWebGL.js +26 -4
|
@@ -12,16 +12,14 @@ const tileType_empty = 0;
|
|
|
12
12
|
const tileType_solid = 1;
|
|
13
13
|
const tileType_breakable = 2;
|
|
14
14
|
|
|
15
|
-
let player, playerStartPos,
|
|
16
|
-
let levelSize, levelColor, levelBackgroundColor, levelOutlineColor
|
|
17
|
-
|
|
18
|
-
const setTileData = (pos, layer, data)=>
|
|
19
|
-
pos.arrayCheck(tileCollisionSize) && (tileData[layer][(pos.y|0)*tileCollisionSize.x+pos.x|0] = data);
|
|
20
|
-
const getTileData = (pos, layer)=>
|
|
21
|
-
pos.arrayCheck(tileCollisionSize) ? tileData[layer][(pos.y|0)*tileCollisionSize.x+pos.x|0]: 0;
|
|
15
|
+
let player, playerStartPos, tileLayers, foregroundLayerIndex, sky;
|
|
16
|
+
let levelSize, levelColor, levelBackgroundColor, levelOutlineColor;
|
|
22
17
|
|
|
23
18
|
function buildLevel()
|
|
24
19
|
{
|
|
20
|
+
// destroy all objects
|
|
21
|
+
engineObjectsDestroy();
|
|
22
|
+
|
|
25
23
|
// create the level
|
|
26
24
|
levelColor = randColor(hsl(0,0,.2), hsl(0,0,.8));
|
|
27
25
|
levelBackgroundColor = levelColor.mutate().scale(.4,1);
|
|
@@ -34,33 +32,17 @@ function buildLevel()
|
|
|
34
32
|
// create parallax layers
|
|
35
33
|
for (let i=3; i--;)
|
|
36
34
|
new ParallaxLayer(i);
|
|
37
|
-
|
|
38
|
-
// apply decoration to all level tiles
|
|
39
|
-
const pos = vec2();
|
|
40
|
-
const layerCount = tileLayers.length;
|
|
41
|
-
for (let layer=layerCount; layer--;)
|
|
42
|
-
for (pos.x=levelSize.x; pos.x--;)
|
|
43
|
-
for (pos.y=levelSize.y; pos.y--;)
|
|
44
|
-
decorateTile(pos, layer);
|
|
45
|
-
|
|
46
|
-
// warm up level
|
|
47
|
-
warmup = 1;
|
|
48
|
-
for (let i = 500; i--;)
|
|
49
|
-
engineObjectsUpdate();
|
|
50
|
-
warmup = 0;
|
|
51
35
|
|
|
52
36
|
// spawn player
|
|
53
37
|
player = new Player(playerStartPos);
|
|
54
38
|
}
|
|
55
39
|
|
|
56
|
-
function loadLevel()
|
|
40
|
+
function loadLevel(level=0)
|
|
57
41
|
{
|
|
58
42
|
// load level data from an exported Tiled js file
|
|
59
|
-
const
|
|
60
|
-
const tileMapData = TileMaps[dataName];
|
|
43
|
+
const tileMapData = TileMaps['gameLevelData'];
|
|
61
44
|
levelSize = vec2(tileMapData.width, tileMapData.height);
|
|
62
45
|
initTileCollision(levelSize);
|
|
63
|
-
engineObjectsDestroy();
|
|
64
46
|
|
|
65
47
|
// create table for tiles in the level tilemap
|
|
66
48
|
const tileLookup =
|
|
@@ -76,7 +58,6 @@ function loadLevel()
|
|
|
76
58
|
}
|
|
77
59
|
|
|
78
60
|
// set all level data tiles
|
|
79
|
-
tileData = [];
|
|
80
61
|
tileLayers = [];
|
|
81
62
|
playerStartPos = vec2(1, levelSize.y);
|
|
82
63
|
const layerCount = tileMapData.layers.length;
|
|
@@ -87,7 +68,6 @@ function loadLevel()
|
|
|
87
68
|
const tileLayer = new TileLayer(vec2(), levelSize, tile(0,16,1));
|
|
88
69
|
tileLayer.renderOrder = -1e3+layer;
|
|
89
70
|
tileLayers[layer] = tileLayer;
|
|
90
|
-
tileData[layer] = [];
|
|
91
71
|
|
|
92
72
|
for (let x=levelSize.x; x--;)
|
|
93
73
|
for (let y=levelSize.y; y--;)
|
|
@@ -109,10 +89,7 @@ function loadLevel()
|
|
|
109
89
|
new Coin(objectPos);
|
|
110
90
|
continue;
|
|
111
91
|
}
|
|
112
|
-
|
|
113
|
-
// set the tile data
|
|
114
|
-
setTileData(pos, layer, tile);
|
|
115
|
-
|
|
92
|
+
|
|
116
93
|
// get tile type for special tiles
|
|
117
94
|
let tileType = tileType_empty;
|
|
118
95
|
if (tile > 0)
|
|
@@ -144,6 +121,13 @@ function loadLevel()
|
|
|
144
121
|
}
|
|
145
122
|
tileLayer.redraw();
|
|
146
123
|
}
|
|
124
|
+
|
|
125
|
+
// apply decoration to all level tiles
|
|
126
|
+
const pos = vec2();
|
|
127
|
+
for (let layer=layerCount; layer--;)
|
|
128
|
+
for (pos.x=levelSize.x; pos.x--;)
|
|
129
|
+
for (pos.y=levelSize.y; pos.y--;)
|
|
130
|
+
decorateTile(pos, layer);
|
|
147
131
|
}
|
|
148
132
|
|
|
149
133
|
function decorateTile(pos, layer=1)
|
|
@@ -181,11 +165,11 @@ function decorateTile(pos, layer=1)
|
|
|
181
165
|
else
|
|
182
166
|
{
|
|
183
167
|
// make round corners
|
|
184
|
-
for (let i=4;i--;)
|
|
168
|
+
for (let i=4; i--;)
|
|
185
169
|
{
|
|
186
170
|
// check corner neighbors
|
|
187
|
-
const neighborTileDataA =
|
|
188
|
-
const neighborTileDataB =
|
|
171
|
+
const neighborTileDataA = tileLayer.getData(pos.add(vec2().setDirection(i))).tile;
|
|
172
|
+
const neighborTileDataB = tileLayer.getData(pos.add(vec2().setDirection((i+1)%4))).tile;
|
|
189
173
|
if (neighborTileDataA > 0 || neighborTileDataB > 0)
|
|
190
174
|
continue;
|
|
191
175
|
|
|
@@ -23,17 +23,14 @@ class GameObject extends EngineObject
|
|
|
23
23
|
super.update();
|
|
24
24
|
|
|
25
25
|
// flash white when damaged
|
|
26
|
+
let brightness = 0;
|
|
26
27
|
if (!this.isDead() && this.damageTimer.isSet())
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
this.additiveColor = hsl(0,0,a,0);
|
|
30
|
-
}
|
|
31
|
-
else
|
|
32
|
-
this.additiveColor = hsl(0,0,0,0);
|
|
28
|
+
brightness = .5*percent(this.damageTimer, .15, 0);
|
|
29
|
+
this.additiveColor = hsl(0,0,brightness,0);
|
|
33
30
|
|
|
34
31
|
// kill if below level
|
|
35
32
|
if (!this.isDead() && this.pos.y < -9)
|
|
36
|
-
|
|
33
|
+
this.kill();
|
|
37
34
|
}
|
|
38
35
|
|
|
39
36
|
damage(damage, damagingObject)
|
|
@@ -104,10 +101,10 @@ class Coin extends EngineObject
|
|
|
104
101
|
drawTile(this.pos, vec2(.5+.5*Math.sin(t*2*PI), 1), this.tileInfo, this.color);
|
|
105
102
|
}
|
|
106
103
|
|
|
107
|
-
update(
|
|
104
|
+
update()
|
|
108
105
|
{
|
|
109
106
|
if (!player)
|
|
110
|
-
|
|
107
|
+
return;
|
|
111
108
|
|
|
112
109
|
// check if player in range
|
|
113
110
|
const d = this.pos.distanceSquared(player.pos);
|
|
@@ -145,10 +142,7 @@ class Enemy extends GameObject
|
|
|
145
142
|
|
|
146
143
|
// jump around randomly
|
|
147
144
|
if (this.groundObject && rand() < .01 && this.pos.distance(player.pos) < 20)
|
|
148
|
-
{
|
|
149
145
|
this.velocity = vec2(rand(.1,-.1), rand(.4,.2));
|
|
150
|
-
sound_jump.play(this.pos, .4, 2);
|
|
151
|
-
}
|
|
152
146
|
|
|
153
147
|
// damage player if touching
|
|
154
148
|
if (isOverlapping(this.pos, this.size, player.pos, player.size))
|
|
@@ -345,17 +339,17 @@ class Bullet extends EngineObject
|
|
|
345
339
|
}
|
|
346
340
|
|
|
347
341
|
this.kill();
|
|
348
|
-
return
|
|
342
|
+
return true;
|
|
349
343
|
}
|
|
350
344
|
|
|
351
345
|
collideWithTile(data, pos)
|
|
352
346
|
{
|
|
353
347
|
if (data <= 0)
|
|
354
|
-
return
|
|
348
|
+
return false;
|
|
355
349
|
|
|
356
350
|
destroyTile(pos);
|
|
357
351
|
this.kill();
|
|
358
|
-
return
|
|
352
|
+
return true;
|
|
359
353
|
}
|
|
360
354
|
|
|
361
355
|
kill()
|
|
@@ -1,16 +1,17 @@
|
|
|
1
1
|
<!DOCTYPE html><head>
|
|
2
|
-
<title>
|
|
2
|
+
<title>LittleJS Platforming Game</title>
|
|
3
|
+
<meta charset=utf-8>
|
|
3
4
|
<meta name=viewport content=width=device-width,height=device-height,initial-scale=1,maximum-scale=1>
|
|
4
5
|
<meta name=apple-mobile-web-app-capable content=yes>
|
|
5
6
|
<meta name=mobile-web-app-capable content=yes>
|
|
6
7
|
<link rel=icon type=image/png href=../favicon.png>
|
|
7
8
|
</head><body>
|
|
8
9
|
|
|
9
|
-
<script src=../../dist/littlejs.js?
|
|
10
|
-
<script src=gameObjects.js?
|
|
11
|
-
<script src=gameCharacter.js?
|
|
12
|
-
<script src=gamePlayer.js?
|
|
13
|
-
<script src=gameEffects.js?
|
|
14
|
-
<script src=gameLevel.js?
|
|
15
|
-
<script src=gameLevelData.js?
|
|
16
|
-
<script src=game.js?
|
|
10
|
+
<script src=../../dist/littlejs.js?1100></script>
|
|
11
|
+
<script src=gameObjects.js?1100></script>
|
|
12
|
+
<script src=gameCharacter.js?1100></script>
|
|
13
|
+
<script src=gamePlayer.js?1100></script>
|
|
14
|
+
<script src=gameEffects.js?1100></script>
|
|
15
|
+
<script src=gameLevel.js?1100></script>
|
|
16
|
+
<script src=gameLevelData.js?1100></script>
|
|
17
|
+
<script src=game.js?1100></script>
|
package/examples/puzzle/game.js
CHANGED
|
@@ -229,7 +229,7 @@ function gameRenderPost()
|
|
|
229
229
|
|
|
230
230
|
///////////////////////////////////////////////////////////////////////////////
|
|
231
231
|
// Startup LittleJS Engine
|
|
232
|
-
engineInit(gameInit, gameUpdate, gameUpdatePost, gameRender, gameRenderPost);
|
|
232
|
+
engineInit(gameInit, gameUpdate, gameUpdatePost, gameRender, gameRenderPost, ['tiles.png']);
|
|
233
233
|
|
|
234
234
|
///////////////////////////////////////////////////////////////////////////////
|
|
235
235
|
// find and remove all runs of 3 or higher
|
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
<!DOCTYPE html><head>
|
|
2
|
-
<title>
|
|
2
|
+
<title>LittleJS Puzzle Game</title>
|
|
3
|
+
<meta charset=utf-8>
|
|
3
4
|
<meta name=apple-mobile-web-app-capable content=yes>
|
|
4
5
|
<meta name=mobile-web-app-capable content=yes>
|
|
5
6
|
<link rel=icon type=image/png href=../favicon.png>
|
|
6
7
|
</head><body>
|
|
7
8
|
|
|
8
|
-
<script src=../../dist/littlejs.js?
|
|
9
|
-
<script src=game.js?
|
|
9
|
+
<script src=../../dist/littlejs.js?1100></script>
|
|
10
|
+
<script src=game.js?1100></script>
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
<!DOCTYPE html><head><title>Little JS Starter Project</title></head><script>const h=Math.PI;function m(t,i=0,a=1){return t<i?i:a<t?a:t}function aa(t,i,a){return a-i?m((t-i)/(a-i)):0}function ba(t,i,a,e){return 2*Math.abs(t.x-a.x)<i.x+e.x&&2*Math.abs(t.y-a.y)<i.y+e.y}function n(t=1,i=0){return i+Math.random()*(t-i)}function ca(t=1){return fa(new p,n(2*h),t)}function ha(t=1){return 0<t?ca(t*n(0/t,1)**.5):new p}function ia(t=new v,i=new v(0,0,0,1),a){return a?t.ha(i,n()):new v(n(t.r,i.r),n(t.j,i.j),n(t.b,i.b),n(t.a,i.a))}function x(t=0,i){return null==t.x?new p(t,null==i?t:i):new p(t.x,t.y)}function fa(t,i=0,a=1){return t.x=a*Math.sin(i),t.y=a*Math.cos(i),t}function ja(t){var i=t.length();return 1<i?t.scale(1/i):t}function ka(t,i){return 0<=t.x&&0<=t.y&&t.x<i.x&&t.y<i.y}class p{constructor(t=0,i=0){this.x=t,this.y=i}M(){return new p(this.x,this.y)}add(t){return new p(this.x+t.x,this.y+t.y)}u(t){return new p(this.x-t.x,this.y-t.y)}multiply(t){return new p(this.x*t.x,this.y*t.y)}ca(t){return new p(this.x/t.x,this.y/t.y)}scale(t){return new p(this.x*t,this.y*t)}length(){return(this.x**2+this.y**2)**.5}normalize(t=1){var i=this.length();return i?this.scale(t/i):new p(0,t)}angle(){return Math.atan2(this.x,this.y)}rotate(t){var i=Math.cos(t);return t=Math.sin(t),new p(this.x*i-this.y*t,this.x*t+this.y*i)}direction(){return Math.abs(this.x)>Math.abs(this.y)?this.x<0?3:1:this.y<0?2:0}floor(){return new p(Math.floor(this.x),Math.floor(this.y))}ha(t,i){return this.add(t.u(this).scale(m(i)))}toString(){}}function la(t=1){var i=new v,a=t<.5?+t:t+0-0*t,e=(t,i,a)=>(a=(a%1+1)%1)<1/6?t+6*(i-t)*a:a<.5?i:a<2/3?t+(i-t)*(2/3-a)*6:t;return i.r=e(t=2*t-a,a,1/3),i.j=e(t,a,0),i.b=e(t,a,-1/3),i.a=1,i}function ma(t){return(255*m(t.r)|0)+((255*m(t.j)|0)<<8)+((255*m(t.b)|0)<<16)+((255*m(t.a)|0)<<24)}class v{constructor(t=1,i=1,a=1,e=1){this.r=t,this.j=i,this.b=a,this.a=e}M(){return new v(this.r,this.j,this.b,this.a)}add(t){return new v(this.r+t.r,this.j+t.j,this.b+t.b,this.a+t.a)}u(t){return new v(this.r-t.r,this.j-t.j,this.b-t.b,this.a-t.a)}multiply(t){return new v(this.r*t.r,this.j*t.j,this.b*t.b,this.a*t.a)}ca(t){return new v(this.r/t.r,this.j/t.j,this.b/t.b,this.a/t.a)}scale(t,i=t){return new v(this.r*t,this.j*t,this.b*t,this.a*i)}ha(t,i){return this.add(t.u(this).scale(m(i)))}toString(t=1){var i=t=>((t=255*t|0)<16?"0":"")+t.toString(16);return"#"+i(this.r)+i(this.j)+i(this.b)+(t?i(this.a):"")}}let y=x(),z=32,na=x(1920,1200),oa=x(),pa=x(16),qa=0,ra=x(640,80);function sa(t){if(!t.v){t.v=1,t.parent&&t.parent.removeChild(t);for(const i of t.children)sa(i,i.parent=0)}}class ta{constructor(t=x(),i=x(1),a,e=0,s,h=0){this.i=t.M(),this.size=i,this.pa,this.l=a,this.angle=e,this.color=s,this.ma,this.I=this.m=this.h=1,this.s=0,this.W=.8,this.A=1,this.O=h,this.g=x(),this.R=0,this.ka=ua,this.children=[],this.J=1,A.push(this)}update(){var t=this.parent;if(t)this.i=this.Ca.multiply(x(t.o?-1:1,1)).rotate(-t.angle).add(t.i),this.angle=(t.o?-1:1)*this.Ba+t.angle;else if(this.g.x=m(this.g.x,-1,1),this.g.y=m(this.g.y,-1,1),t=this.i.M(),this.g.y+=qa*this.A,this.i.x+=this.g.x*=this.m,this.i.y+=this.g.y*=this.m,this.angle+=this.R*=this.I,this.h){var i,a,e,s,h,n,r=this.g.y<0;if(this.B&&(i=this.B.g?this.B.g.x:0,this.g.x=i+(this.g.x-i)*this.W,this.B=0),this.oa)for(var o of va)!this.sa&&!o.sa||o.v||o.parent||o==this||ba(this.i,this.size,o.i,o.size)&&(ba(t,this.size,o.i,o.size)?(i=(a=(i=t.u(o.i)).length())<.01?ca(.001):i.scale(.001/a),this.g=this.g.add(i),o.h&&(o.g=o.g.u(i))):(a=this.size.add(o.size),e=2*(t.y-o.i.y)>a.y+qa,s=2*Math.abs(t.y-o.i.y)<a.y,h=2*Math.abs(t.x-o.i.x)<a.x,i=Math.max(this.s,o.s),!e&&!h&&s||(this.i.y=o.i.y+(a.y/2+.001)*Math.sign(t.y-o.i.y),o.B&&r||!o.h?(r&&(this.B=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+m(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+m(i)*(n-h))),!e&&s&&(this.i.x=o.i.x+(a.x/2+.001)*Math.sign(t.x-o.i.x),o.h?(a=(this.h*this.g.x+o.h*o.g.x)/(this.h+o.h),e=o.g.x*(o.h-this.h)/(this.h+o.h)+2*this.g.x*this.h/(this.h+o.h),this.g.x=a+m(i)*(this.g.x*(this.h-o.h)/(this.h+o.h)+2*o.g.x*o.h/(this.h+o.h)-a),o.g.x=a+m(i)*(e-a)):this.g.x*=-i)));this.J&&wa(this.i,this.size,this)&&!wa(t,this.size,this)&&(o=wa(x(this.i.x,t.y),this.size,this),!wa(x(t.x,this.i.y),this.size,this)&&o||(this.B=r,this.g.y*=-this.s,(r=(t.y-this.size.y/2|0)-(t.y-this.size.y/2))<0&&r>this.m*this.g.y+qa*this.A&&(this.g.y=this.m?(r-qa*this.A)/this.m:0),this.i.y=t.y),o)&&(this.i.x=t.x,this.g.x*=-this.s)}}D(){B(this.i,this.pa||this.size,this.l,this.color,this.angle,this.o,this.ma)}removeChild(t){t.parent==this&&this.children.includes(t),this.children.splice(this.children.indexOf(t),1),t.parent=0}toString(){}}let D,G,H,xa,J=x(),K=[];function Da(t=x(),i=pa,a=0){var e;return null==i.x&&(i=x(i)),null==t.x&&(t=x(t%(e=K[a].size.x/i.x|0)*i.x,(t/e|0)*i.y)),new Ea(t,i,a)}class Ea{constructor(t=x(),i=pa,a=0){this.i=t,this.size=i,this.P=a}offset(t){return new Ea(this.i.add(t),this.size,this.P)}}class Fa{constructor(t){this.image=t,this.size=x(t.width,t.height);var i=L.createTexture();L.bindTexture(3553,i),t&&t.width&&L.texImage2D(3553,0,6408,6408,5121,t),L.texParameteri(3553,10241,9728),L.texParameteri(3553,10240,9728),L.texParameteri(3553,10242,33071),L.texParameteri(3553,10243,33071),this.ga=i,this.qa=x(.3).ca(this.size)}}function Ga(){var t=Ha;return new p((t.x-J.x/2+.5)/z+y.x,(t.y-J.y/2+.5)/-z+y.y)}function Ia(t){return new p((t.x-y.x)*z+J.x/2-.5,(t.y-y.y)*-z+J.y/2-.5)}function B(t,i=x(1),h,n=new v,a=0,e,s=new v(0,0,0,0),r=1){var o,l,c,u,y;r?h?(r=K[h.P],o=h.size.x/r.size.x,l=h.size.y/r.size.y,c=h.i.x/r.size.x,u=h.i.y/r.size.y,y=r.qa,Ja(r.ga),Ka(t.x,t.y,e?-i.x:i.x,i.y,a,c+y.x,u+y.y,c-y.x+o,u-y.y+l,ma(n),ma(s))):Ka(t.x,t.y,i.x,i.y,a,0,0,0,0,0,ma(n)):La(t,i,a,e,t=>{var i,a,e,s;h?(i=h.i.x+.3,a=h.i.y+.3,e=h.size.x-.6,s=h.size.y-.6,t.globalAlpha=n.a,t.drawImage(K[h.P].image,i,a,e,s,-.5,-.5,1,1)):(t.fillStyle=n,t.fillRect(-.5,-.5,1,1))})}function La(t,i,a,e,s){var h=G;t=Ia(t),i=i.scale(z),h.save(),h.translate(t.x+.5,t.y+.5),h.rotate(a),h.scale(e?-i.x:i.x,i.y),s(h),h.restore()}function Ma(t,i,a=1,e=new v,s=0,h=new v(0,0,0),n="center"){var r=xa;r.fillStyle=e,r.lineWidth=s,r.strokeStyle=h,r.textAlign=n,r.font=a+"px arial",r.textBaseline="middle",r.lineJoin="round",i=i.M(),(t+"").split("\n").forEach(t=>{s&&r.strokeText(t,i.x,i.y),r.fillText(t,i.x,i.y),i.y+=a})}function Na(t,i=0){return M[i]&&1&M[i][t]}let Oa=x(),Ha=x();function N(t,i=0){return Na(t,i+1)}let M=[[]];function Pa(){for(const t of M)for(const i in t)t[i]&=1}function Qa(t){return 87==t?38:83==t?40:65==t?37:68==t?39:t}onkeydown=t=>{t.repeat||(M[0][Qa(t.which)]=3)},onkeyup=t=>{M[0][Qa(t.which)]=4},onmousedown=t=>{M[0][t.button]=3,onmousemove(t),t.button&&t.preventDefault()},onmouseup=t=>M[0][t.button]=2&M[0][t.button]|4,onmousemove=t=>{var i;return t=D?(i=D.getBoundingClientRect(),x(D.width,D.height).multiply(x(aa(t.x,i.left,i.right),aa(t.y,i.top,i.bottom)))):x(),Ha=t},onwheel=t=>t.ctrlKey||Math.sign(t.deltaY),oncontextmenu=()=>!1;const Ra=[];function Sa(){if(navigator&&navigator.getGamepads&&document.hasFocus()){var i=navigator.getGamepads();for(let t=i.length;t--;){var a=i[t],e=M[t+1]||(M[t+1]=[]),s=Ra[t]||(Ra[t]=[]);if(a){var h=t=>.3<t?aa(t,.3,.8):t<-.3?-aa(-t,.3,.8):0;for(let t=0;t<a.axes.length-1;t+=2)s[t>>1]=ja(x(h(a.axes[t]),h(-a.axes[t+1])));for(h=a.buttons.length;h--;)e[h]=a.buttons[h].pressed?1+2*!N(h,t):4*N(h,t);(a=x(N(15,t)-N(14,t),N(12,t)-N(13,t))).x**2+a.y**2&&(s[0]=ja(a))}}}}const Ta=void 0!==window.ontouchstart;if(Ta){let a,e=onmousedown,s=onmouseup;onmousedown=onmouseup=()=>0,ontouchstart=ontouchmove=ontouchend=t=>{t.button=0,O?O.resume():Ua([Va(0)]);var i=t.touches.length;return i?(t.x=t.touches[0].clientX,t.y=t.touches[0].clientY,(a?onmousemove:e)(t)):a&&s(t),a=i,document.hasFocus()&&t.preventDefault(),!0}}class Wa{constructor(){var t=[1,.5];this.wa=40,this.Aa=.7,this.N=0,t&&(this.N=t[1]||(t[1]=0),this.ja=[Va(...t)],this.sampleRate=44100)}play(t,i=1,a=1,e=1,s=0){if(this.ja){var h;if(t){if(h=this.wa){var r=y;if(h*h<(r=(y.x-t.x)**2+(r.y-t.y)**2))return;i*=aa(r**.5,h,h*this.Aa)}h=2*Ia(t).x/D.width-1}return this.source=Ua(this.ja,i,a+a*this.N*e*n(-1,1),h,s,this.sampleRate)}}stop(){this.source&&this.source.stop(),this.source=0}}let O;function Ua(t,i=1,a=1,e=0,s=0,h=44100){var n;if("running"==(O||=new AudioContext).state)return n=O.createBuffer(t.length,t[0].length,h),h=O.createBufferSource(),t.forEach((t,i)=>n.getChannelData(i).set(t)),h.buffer=n,h.playbackRate.value=a,h.loop=s,(t=O.createGain()).gain.value=.5*i,t.connect(O.destination),h.connect(new StereoPannerNode(O,{pan:m(e,-1,1)})).connect(t),h.start(),h;O.resume()}function Va(t=1,i=.05,a=220,e=0,s=0,r=.1,o=0,l=1,c=0,u=0,x=0,y=0,d=0,b=0,g=0,f=0,v=0,m=1,w=0,p=0){var M=2*h,z=c*=500*M/44100/44100,D=[];i=a*=(1+i*n(-1,1))*M/44100;let L=0,S=0,A=0,j=1,B=0,C=0,G=0,k,H;for(u*=500*M/44100**3,g*=M/44100,x*=M/44100,y*=44100,d=44100*d|0,H=(e=44100*e+9)+(w*=44100)+(s*=44100)+(r*=44100)+(v*=44100)|0;A<H;D[A++]=G)++C%(100*f|0)||(G=o?1<o?2<o?3<o?Math.sin((L%M)**3):Math.max(Math.min(Math.tan(L),1),-1):1-(2*L/M%2+2)%2:1-4*Math.abs(Math.round(L/M)-L/M):Math.sin(L),G=(d?1-p+p*Math.sin(M*A/d):1)*Math.sign(G)*Math.abs(G)**l*t*.5*(A<e?A/e:A<e+w?1-(A-e)/w*(1-m):A<e+w+s?m:A<H-v?(H-A-v)/r*m:0),G=v?G/2+(v>A?0:(A<H-v?1:(H-A)/v)*D[A-v|0]/2):G),k=(a+=c+=u)*Math.cos(g*S++),L+=k-k*b*(1-1e9*(Math.sin(A)+1)%2),j&&++j>y&&(a+=x,i+=x,j=0),!d||++B%d||(a=i,c=z,j||=1);return D}let Xa=[],Q=x();function wa(t,i=x(),a){var e=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=e;i<h;++i){var n=Xa[s*Q.x+i];if(n&&(!a||0<n))return 1}}class Ya{constructor(t,i=0,a=0,e=new v){this.Z=t,this.direction=i,this.o=a,this.color=e}clear(){this.Z=this.direction=this.o=0,color=new v}}function Za(t,i){var a=i.floor().add(t.i).add(x(.5));$a(t,a,t=>t.clearRect(-.5,-.5,1,1)),null!=(i=t.getData(i)).Z&&B(a,x(1),Da(i.Z,t.l.size,t.l.P),i.color,i.direction*h/2,i.o)}function $a(t,i,a){var e=x(1),s=t.context;s.save(),i=i.u(t.i).multiply(t.l.size),e=e.multiply(t.l.size),s.translate(i.x,t.canvas.height-i.y),s.rotate(0),s.scale(e.x,e.y),a(s),s.restore()}class ab extends ta{constructor(t,i=Q){var a=x(1);for(super(t,i,Da(),0,void 0,0),this.canvas=document.createElement("canvas"),this.context=this.canvas.getContext("2d"),this.scale=a,this.ra,this.data=[],t=this.size,t=Math.abs(t.x*t.y);t--;)this.data.push(new Ya)}setData(t,i,a){ka(t,this.size)&&(this.data[(0|t.y)*this.size.x+t.x|0]=i,a)&&Za(this,t)}getData(t){return ka(t,this.size)&&this.data[(0|t.y)*this.size.x+t.x|0]}update(){}D(){var t=Ia(this.i.add(x(0,this.size.y*this.scale.y)));(this.ra?xa:G).drawImage(this.canvas,t.x,t.y,z*this.size.x*this.scale.x,z*this.size.y*this.scale.y)}}function bb(t){var i=null!=t.U.x?x(n(-.5,.5),n(-.5,.5)).multiply(t.U).rotate(t.angle):ha(t.U/2);t.X||(i=t.i.add(i)),i=new cb(i,t.l,t.Ea);const a=t.N;var e=(o=t=>t+t*n(a,-a))(t.va),s=o(t.Y),h=o(t.ya),r=o(t.speed),o=o(t.na)*(2*Math.floor(n(2,0))-1),l=n(t.da,-t.da),c=ia(t.S,t.T,t.ia),u=ia(t.$,t.aa,t.ia),l=t.X?l:t.angle+l;i.L=c,i.K=u.u(c),i.g=fa(x(),l,r),i.R=o,i.ta=e,i.Y=s,i.za=h-s,i.V=t.V,i.m=t.m,i.I=t.I,i.s=t.s,i.W=t.W,i.A=t.A,i.J=t.J,i.H=t.H,i.O=t.O,i.G=t.G,i.o=Math.floor(n(2,0)),i.C=t.X&&t,i.ba=t.Da,t.ua&&t.ua(i)}class db extends ta{constructor(t,i,a=0,e=0,s=100,n=h,r,o=new v,l=new v,c=new v(1,1,1,0),u=new v(1,1,1,0),y=.5,d=.1,b=1,g=.1,f=.05,m=1,w=1,p=0,M,z=.1,D=.2,L,S,A=1,j=S?1e9:0,B){super(t,x(),r,i,void 0,j),this.U=a,this.fa=e,this.ea=s,this.da=n,this.S=o,this.T=l,this.$=c,this.aa=u,this.ia=A,this.va=y,this.Y=d,this.ya=b,this.speed=g,this.na=f,this.m=m,this.I=w,this.A=p,this.V=z,this.N=D,this.J=L,this.H=S,this.X=B,this.F=this.G=0}update(){if(this.parent&&super.update(),!this.fa||ua-this.ka<=this.fa){if(+this.ea){var t=1/this.ea;for(this.F+=eb;0<this.F;this.F-=t)bb(this)}}else sa(this)}D(){}}class cb extends ta{constructor(t,i,a){super(t,x(),i,a)}D(){var t=Math.min((ua-this.ka)/this.ta,1),i=x(this.Y+t*this.za),a=this.V/2,a=new v(this.L.r+t*this.K.r,this.L.j+t*this.K.j,this.L.b+t*this.K.b,(this.L.a+t*this.K.a)*(t<a?t/a:1-a<t?(1-t)/a:1));this.H&&fb(1);let e=this.i;var s,h,n=this.angle;this.C&&(e=this.C.i.add(e.rotate(-this.C.angle)),n+=this.C.angle),this.G?(s=this.g,n=(s=this.C?s.rotate(-this.C.angle):s).length(),s=s.scale(1/n),h=n*this.G,i.y=Math.max(i.x,h),n=s.angle(),B(e.add(s.multiply(x(0,-h/2))),i,this.l,a,n,this.o)):B(e,i,this.l,a,n,this.o),this.H&&fb(),1==t&&(this.color=a,this.size=i,this.ba&&this.ba(this),this.v=1)}}const gb=[];let hb=[],ib,jb;class kb{constructor(){(gb[this.id=0]=this).name="Example Medal",this.description="Welcome to LittleJS!",this.icon="🏆"}unlock(){this.la||(localStorage[ib+"_"+this.id]=this.la=1,hb.push(this),lb&&lb.Fa(this.id))}D(t=0){var i=xa,a=Math.min(ra.x,D.width),e=H.width-a;t*=-ra.y,i.save(),i.beginPath(),i.fillStyle=new v(.9,.9,.9),i.strokeStyle=new v(0,0,0),i.lineWidth=3,i.fill(i.rect(e,t,a,ra.y)),i.stroke(),i.clip(),a=x(e+15+25,t+ra.y/2),this.image?xa.drawImage(this.image,a.x-25,a.y-25,50,50):Ma(this.icon,a,35,new v(0,0,0)),e=x(e+50+30,t+28),Ma(this.name,e,38,new v(0,0,0),0,0,"left"),e.y+=32,Ma(this.description,e,24,new v(0,0,0),0,0,"left"),i.restore()}}function mb(){var t,i;hb.length&&(t=hb[0],i=nb-jb,jb?5<i?hb.shift(jb=0):t.D(i<.5?1-i/.5:4.5<i?(i-4.5)/.5:0):jb=nb)}let lb,S,L,ob,pb,qb,T,tb,U,ub,vb;function wb(){S=document.createElement("canvas"),L=S.getContext("webgl",{antialias:!1}),document.body.appendChild(S);var t=L.createProgram();L.attachShader(t,xb("precision highp float;uniform mat4 m;attribute vec2 p,t;attribute vec4 c,a;varying vec4 v,d,e;void main(){gl_Position=m*vec4(p,1,1);v=vec4(t,p);d=c;e=a;}",35633)),L.attachShader(t,xb("precision highp float;varying vec4 v,d,e;uniform sampler2D s;void main(){gl_FragColor=texture2D(s,v.xy)*d+e;}",35632)),L.linkProgram(t),pb=t,t=new ArrayBuffer(24e5),qb=L.createBuffer(),T=new Float32Array(t),tb=new Uint32Array(t),U=0}function yb(){L.viewport(0,0,S.width=D.width,S.height=D.height),L.clear(16384),L.useProgram(pb),L.activeTexture(33984),L.bindTexture(3553,ob=K[0].ga),L.bindBuffer(34962,qb),L.bufferData(34962,24e5,35048),fb();let h=0;var t=(t,i,a,e,s=0)=>{t=L.getAttribLocation(pb,t),L.enableVertexAttribArray(t),L.vertexAttribPointer(t,e,i,s,24,h),h+=e*a},i=(t("p",5126,4,2),t("t",5126,4,2),t("c",5121,1,4,1),t("a",5121,1,4,1),t=2*z/D.width,2*z/D.height);L.uniformMatrix4fv(L.getUniformLocation(pb,"m"),0,new Float32Array([t,0,0,0,0,i,0,0,1,1,-1,1,-1-t*y.x,-1-i*y.y,0,0]))}function fb(t=0){vb=t}function Ja(t){t!=ob&&(zb(),L.bindTexture(3553,ob=t))}function xb(t,i){return i=L.createShader(i),L.shaderSource(i,t),L.compileShader(i),i}function zb(){var t;U&&(t=ub?1:771,L.blendFuncSeparate(770,t,1,t),L.enable(3042),L.bufferSubData(34962,0,T.subarray(0,6*U)),L.drawArrays(5,0,U),U=0,ub=vb)}function Ab(t){var i=G;(U||t)&&(zb(),t)&&i.drawImage(S,0,0)}function Ka(a,e,t,i,s,h,n,r,o,l,c=0){(99994<=U||ub!=vb)&&zb();var u=Math.cos(s)/2,x=Math.sin(s)/2;s=u*t,u*=i,a=[a-s+(i*=x),e+u+(t*=x),h,n,a-s-i,e-u+t,h,o,a+s+i,e+u-t,r,n,a+s-i,e-u-t,r,o];for(let t=6,i=6*U;t--;)e=4*m(t-1,0,3),T[i++]=a[e++],T[i++]=a[e++],T[i++]=a[e++],T[i++]=a[e++],tb[i++]=l,tb[i++]=c;U+=6}const eb=1/60;let A=[],va=[],Bb=0,ua=0,nb=0,Cb=0,V=0;function Db(){J=x(D.width,D.height),G.imageSmoothingEnabled=!1,yb()}function Eb(){va=A.filter(t=>t.oa);for(const t of A)t.parent||function t(i){if(!i.v){i.update();for(const a of i.children)t(a)}}(t);A=A.filter(t=>!t.v)}const Fb=new Wa,Gb=new kb;ib="Hello World",gb.forEach(t=>t.la=0|localStorage[ib+"_"+t.id]);let Z;!function(e,s,r,o){function l(t=0){var i=t-Cb;for(Cb=t,nb+=i/1e3,V+=i,V=Math.min(V,50),oa.x?(D.width=oa.x,D.height=oa.y,t=innerWidth/innerHeight,i=D.width/D.height,(S||D).style.width=D.style.width=H.style.width=t<i?"100%":"",(S||D).style.height=D.style.height=H.style.height=t<i?"":"100%"):(D.width=Math.min(innerWidth,na.x),D.height=Math.min(innerHeight,na.y)),H.width=D.width,H.height=D.height,J=x(D.width,D.height),t=0,V<0&&-9<V&&(t=V,V=0);0<=V;V-=1e3/60)ua=Bb++/60,Ta||document.hasFocus()||(M=[[]]),Oa=Ga(),Sa(),e(),Eb(),s(),Pa();V+=t,Db(),r(),A.sort((t,i)=>t.O-i.O);for(const a of A)a.v||a.D();o(),mb(),Ab(),requestAnimationFrame(l)}document.body.style="margin:0;overflow:hidden;background:#000;touch-action:none;user-select:none;-webkit-user-select:none;-webkit-touch-callout:none",document.body.appendChild(D=document.createElement("canvas")),G=D.getContext("2d"),wb(),document.body.appendChild(H=document.createElement("canvas")),xa=H.getContext("2d"),(S||D).style=D.style=H.style="position:absolute;top:50%;left:50%;transform:translate(-50%,-50%);image-rendering:pixelated",Promise.all(["tiles.png","tiles3.png"].map((a,e)=>new Promise(t=>{const i=new Image;i.onerror=i.onload=()=>{K[e]=new Fa(i),t()},i.src=a}))).then(()=>{{Q=x(32,16);for(var t=(Xa=[]).length=Math.abs(Q.x*Q.y);t--;)Xa[t]=0;var i=x(),t=new ab(i,Q),a=K[0].image,e=(G.drawImage(a,0,0),G.getImageData(0,0,a.width,a.height).data),s,r,o;for(i.x=Q.x;i.x--;)for(i.y=Q.y;i.y--;)e[4*(i.x+a.width*(15+Q.y-i.y))]&&(s=Math.floor(n(4,0)),r=Math.floor(n(2,0)),(o=ia()).a=.1,t.setData(i,new Ya(1,s,r,o)),ka(i,Q))&&(Xa[(0|i.y)*Q.x+i.x|0]=1);for(t.xa=[D,G,J,y,z],D=t.canvas,G=t.context,y=t.size.scale(.5),z=t.l.size.x,D.width=t.size.x*t.l.size.x,D.height=t.size.y*t.l.size.y,Db(),i=t.size.x;i--;)for(a=t.size.y;a--;)Za(t,x(i,a));Ab(1),[D,G,J,y,z]=t.xa,y=x(16,8),z=48,qa=-.01,(Z=new db(x(16,15),0,1,0,500,h,Da(0,16),new v(1,1,1),new v(0,0,0),new v(1,1,1,0),new v(0,0,0,0),2,.2,.2,.1,.05,.99,1,1,h,.05,.5,1,1)).s=.3,Z.G=2}l()})}(function(){M[0]&&2&M[0][0]&&(Fb.play(Oa),Z.S=new v,Z.T=ia(),Z.$=Z.S.scale(1,0),Z.aa=Z.T.scale(1,0),Gb.unlock()),Ha.x&&(Z.i=Oa)},function(){},function(){B(x(16,8),x(20,14),void 0,la(.6),0,0,void 0,0),B(x(21,5),x(4.5),Da(2,16,1))},function(){Ma("LittleJS Engine Demo",x(J.x/2,70),80,la(1),6,la(0))});
|
|
2
|
+
</script>
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
const h=Math.PI;function m(t,i=0,a=1){return t<i?i:a<t?a:t}function aa(t,i,a){return a-i?m((t-i)/(a-i)):0}function ba(t,i,a,e){return 2*Math.abs(t.x-a.x)<i.x+e.x&&2*Math.abs(t.y-a.y)<i.y+e.y}function n(t=1,i=0){return i+Math.random()*(t-i)}function ca(t=1){return fa(new p,n(2*h),t)}function ha(t=1){return 0<t?ca(t*n(0/t,1)**.5):new p}function ia(t=new v,i=new v(0,0,0,1),a){return a?t.ha(i,n()):new v(n(t.r,i.r),n(t.j,i.j),n(t.b,i.b),n(t.a,i.a))}function x(t=0,i){return null==t.x?new p(t,null==i?t:i):new p(t.x,t.y)}function fa(t,i=0,a=1){return t.x=a*Math.sin(i),t.y=a*Math.cos(i),t}function ja(t){var i=t.length();return 1<i?t.scale(1/i):t}function ka(t,i){return 0<=t.x&&0<=t.y&&t.x<i.x&&t.y<i.y}class p{constructor(t=0,i=0){this.x=t,this.y=i}M(){return new p(this.x,this.y)}add(t){return new p(this.x+t.x,this.y+t.y)}u(t){return new p(this.x-t.x,this.y-t.y)}multiply(t){return new p(this.x*t.x,this.y*t.y)}ca(t){return new p(this.x/t.x,this.y/t.y)}scale(t){return new p(this.x*t,this.y*t)}length(){return(this.x**2+this.y**2)**.5}normalize(t=1){var i=this.length();return i?this.scale(t/i):new p(0,t)}angle(){return Math.atan2(this.x,this.y)}rotate(t){var i=Math.cos(t);return t=Math.sin(t),new p(this.x*i-this.y*t,this.x*t+this.y*i)}direction(){return Math.abs(this.x)>Math.abs(this.y)?this.x<0?3:1:this.y<0?2:0}floor(){return new p(Math.floor(this.x),Math.floor(this.y))}ha(t,i){return this.add(t.u(this).scale(m(i)))}toString(){}}function la(t=1){var i=new v,a=t<.5?+t:t+0-0*t,e=(t,i,a)=>(a=(a%1+1)%1)<1/6?t+6*(i-t)*a:a<.5?i:a<2/3?t+(i-t)*(2/3-a)*6:t;return i.r=e(t=2*t-a,a,1/3),i.j=e(t,a,0),i.b=e(t,a,-1/3),i.a=1,i}function ma(t){return(255*m(t.r)|0)+((255*m(t.j)|0)<<8)+((255*m(t.b)|0)<<16)+((255*m(t.a)|0)<<24)}class v{constructor(t=1,i=1,a=1,e=1){this.r=t,this.j=i,this.b=a,this.a=e}M(){return new v(this.r,this.j,this.b,this.a)}add(t){return new v(this.r+t.r,this.j+t.j,this.b+t.b,this.a+t.a)}u(t){return new v(this.r-t.r,this.j-t.j,this.b-t.b,this.a-t.a)}multiply(t){return new v(this.r*t.r,this.j*t.j,this.b*t.b,this.a*t.a)}ca(t){return new v(this.r/t.r,this.j/t.j,this.b/t.b,this.a/t.a)}scale(t,i=t){return new v(this.r*t,this.j*t,this.b*t,this.a*i)}ha(t,i){return this.add(t.u(this).scale(m(i)))}toString(t=1){var i=t=>((t=255*t|0)<16?"0":"")+t.toString(16);return"#"+i(this.r)+i(this.j)+i(this.b)+(t?i(this.a):"")}}let y=x(),z=32,na=x(1920,1200),oa=x(),pa=x(16),qa=0,ra=x(640,80);function sa(t){if(!t.v){t.v=1,t.parent&&t.parent.removeChild(t);for(const i of t.children)sa(i,i.parent=0)}}class ta{constructor(t=x(),i=x(1),a,e=0,s,h=0){this.i=t.M(),this.size=i,this.pa,this.l=a,this.angle=e,this.color=s,this.ma,this.I=this.m=this.h=1,this.s=0,this.W=.8,this.A=1,this.O=h,this.g=x(),this.R=0,this.ka=ua,this.children=[],this.J=1,A.push(this)}update(){var t=this.parent;if(t)this.i=this.Ca.multiply(x(t.o?-1:1,1)).rotate(-t.angle).add(t.i),this.angle=(t.o?-1:1)*this.Ba+t.angle;else if(this.g.x=m(this.g.x,-1,1),this.g.y=m(this.g.y,-1,1),t=this.i.M(),this.g.y+=qa*this.A,this.i.x+=this.g.x*=this.m,this.i.y+=this.g.y*=this.m,this.angle+=this.R*=this.I,this.h){var i,a,e,s,h,n,r=this.g.y<0;if(this.B&&(i=this.B.g?this.B.g.x:0,this.g.x=i+(this.g.x-i)*this.W,this.B=0),this.oa)for(var o of va)!this.sa&&!o.sa||o.v||o.parent||o==this||ba(this.i,this.size,o.i,o.size)&&(ba(t,this.size,o.i,o.size)?(i=(a=(i=t.u(o.i)).length())<.01?ca(.001):i.scale(.001/a),this.g=this.g.add(i),o.h&&(o.g=o.g.u(i))):(a=this.size.add(o.size),e=2*(t.y-o.i.y)>a.y+qa,s=2*Math.abs(t.y-o.i.y)<a.y,h=2*Math.abs(t.x-o.i.x)<a.x,i=Math.max(this.s,o.s),!e&&!h&&s||(this.i.y=o.i.y+(a.y/2+.001)*Math.sign(t.y-o.i.y),o.B&&r||!o.h?(r&&(this.B=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+m(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+m(i)*(n-h))),!e&&s&&(this.i.x=o.i.x+(a.x/2+.001)*Math.sign(t.x-o.i.x),o.h?(a=(this.h*this.g.x+o.h*o.g.x)/(this.h+o.h),e=o.g.x*(o.h-this.h)/(this.h+o.h)+2*this.g.x*this.h/(this.h+o.h),this.g.x=a+m(i)*(this.g.x*(this.h-o.h)/(this.h+o.h)+2*o.g.x*o.h/(this.h+o.h)-a),o.g.x=a+m(i)*(e-a)):this.g.x*=-i)));this.J&&wa(this.i,this.size,this)&&!wa(t,this.size,this)&&(o=wa(x(this.i.x,t.y),this.size,this),!wa(x(t.x,this.i.y),this.size,this)&&o||(this.B=r,this.g.y*=-this.s,(r=(t.y-this.size.y/2|0)-(t.y-this.size.y/2))<0&&r>this.m*this.g.y+qa*this.A&&(this.g.y=this.m?(r-qa*this.A)/this.m:0),this.i.y=t.y),o)&&(this.i.x=t.x,this.g.x*=-this.s)}}D(){B(this.i,this.pa||this.size,this.l,this.color,this.angle,this.o,this.ma)}removeChild(t){t.parent==this&&this.children.includes(t),this.children.splice(this.children.indexOf(t),1),t.parent=0}toString(){}}let D,G,H,xa,J=x(),K=[];function Da(t=x(),i=pa,a=0){var e;return null==i.x&&(i=x(i)),null==t.x&&(t=x(t%(e=K[a].size.x/i.x|0)*i.x,(t/e|0)*i.y)),new Ea(t,i,a)}class Ea{constructor(t=x(),i=pa,a=0){this.i=t,this.size=i,this.P=a}offset(t){return new Ea(this.i.add(t),this.size,this.P)}}class Fa{constructor(t){this.image=t,this.size=x(t.width,t.height);var i=L.createTexture();L.bindTexture(3553,i),t&&t.width&&L.texImage2D(3553,0,6408,6408,5121,t),L.texParameteri(3553,10241,9728),L.texParameteri(3553,10240,9728),L.texParameteri(3553,10242,33071),L.texParameteri(3553,10243,33071),this.ga=i,this.qa=x(.3).ca(this.size)}}function Ga(){var t=Ha;return new p((t.x-J.x/2+.5)/z+y.x,(t.y-J.y/2+.5)/-z+y.y)}function Ia(t){return new p((t.x-y.x)*z+J.x/2-.5,(t.y-y.y)*-z+J.y/2-.5)}function B(t,i=x(1),h,n=new v,a=0,e,s=new v(0,0,0,0),r=1){var o,l,c,u,y;r?h?(r=K[h.P],o=h.size.x/r.size.x,l=h.size.y/r.size.y,c=h.i.x/r.size.x,u=h.i.y/r.size.y,y=r.qa,Ja(r.ga),Ka(t.x,t.y,e?-i.x:i.x,i.y,a,c+y.x,u+y.y,c-y.x+o,u-y.y+l,ma(n),ma(s))):Ka(t.x,t.y,i.x,i.y,a,0,0,0,0,0,ma(n)):La(t,i,a,e,t=>{var i,a,e,s;h?(i=h.i.x+.3,a=h.i.y+.3,e=h.size.x-.6,s=h.size.y-.6,t.globalAlpha=n.a,t.drawImage(K[h.P].image,i,a,e,s,-.5,-.5,1,1)):(t.fillStyle=n,t.fillRect(-.5,-.5,1,1))})}function La(t,i,a,e,s){var h=G;t=Ia(t),i=i.scale(z),h.save(),h.translate(t.x+.5,t.y+.5),h.rotate(a),h.scale(e?-i.x:i.x,i.y),s(h),h.restore()}function Ma(t,i,a=1,e=new v,s=0,h=new v(0,0,0),n="center"){var r=xa;r.fillStyle=e,r.lineWidth=s,r.strokeStyle=h,r.textAlign=n,r.font=a+"px arial",r.textBaseline="middle",r.lineJoin="round",i=i.M(),(t+"").split("\n").forEach(t=>{s&&r.strokeText(t,i.x,i.y),r.fillText(t,i.x,i.y),i.y+=a})}function Na(t,i=0){return M[i]&&1&M[i][t]}let Oa=x(),Ha=x();function N(t,i=0){return Na(t,i+1)}let M=[[]];function Pa(){for(const t of M)for(const i in t)t[i]&=1}function Qa(t){return 87==t?38:83==t?40:65==t?37:68==t?39:t}onkeydown=t=>{t.repeat||(M[0][Qa(t.which)]=3)},onkeyup=t=>{M[0][Qa(t.which)]=4},onmousedown=t=>{M[0][t.button]=3,onmousemove(t),t.button&&t.preventDefault()},onmouseup=t=>M[0][t.button]=2&M[0][t.button]|4,onmousemove=t=>{var i;return t=D?(i=D.getBoundingClientRect(),x(D.width,D.height).multiply(x(aa(t.x,i.left,i.right),aa(t.y,i.top,i.bottom)))):x(),Ha=t},onwheel=t=>t.ctrlKey||Math.sign(t.deltaY),oncontextmenu=()=>!1;const Ra=[];function Sa(){if(navigator&&navigator.getGamepads&&document.hasFocus()){var i=navigator.getGamepads();for(let t=i.length;t--;){var a=i[t],e=M[t+1]||(M[t+1]=[]),s=Ra[t]||(Ra[t]=[]);if(a){var h=t=>.3<t?aa(t,.3,.8):t<-.3?-aa(-t,.3,.8):0;for(let t=0;t<a.axes.length-1;t+=2)s[t>>1]=ja(x(h(a.axes[t]),h(-a.axes[t+1])));for(h=a.buttons.length;h--;)e[h]=a.buttons[h].pressed?1+2*!N(h,t):4*N(h,t);(a=x(N(15,t)-N(14,t),N(12,t)-N(13,t))).x**2+a.y**2&&(s[0]=ja(a))}}}}const Ta=void 0!==window.ontouchstart;if(Ta){let a,e=onmousedown,s=onmouseup;onmousedown=onmouseup=()=>0,ontouchstart=ontouchmove=ontouchend=t=>{t.button=0,O?O.resume():Ua([Va(0)]);var i=t.touches.length;return i?(t.x=t.touches[0].clientX,t.y=t.touches[0].clientY,(a?onmousemove:e)(t)):a&&s(t),a=i,document.hasFocus()&&t.preventDefault(),!0}}class Wa{constructor(){var t=[1,.5];this.wa=40,this.Aa=.7,this.N=0,t&&(this.N=t[1]||(t[1]=0),this.ja=[Va(...t)],this.sampleRate=44100)}play(t,i=1,a=1,e=1,s=0){if(this.ja){var h;if(t){if(h=this.wa){var r=y;if(h*h<(r=(y.x-t.x)**2+(r.y-t.y)**2))return;i*=aa(r**.5,h,h*this.Aa)}h=2*Ia(t).x/D.width-1}return this.source=Ua(this.ja,i,a+a*this.N*e*n(-1,1),h,s,this.sampleRate)}}stop(){this.source&&this.source.stop(),this.source=0}}let O;function Ua(t,i=1,a=1,e=0,s=0,h=44100){var n;if("running"==(O||=new AudioContext).state)return n=O.createBuffer(t.length,t[0].length,h),h=O.createBufferSource(),t.forEach((t,i)=>n.getChannelData(i).set(t)),h.buffer=n,h.playbackRate.value=a,h.loop=s,(t=O.createGain()).gain.value=.5*i,t.connect(O.destination),h.connect(new StereoPannerNode(O,{pan:m(e,-1,1)})).connect(t),h.start(),h;O.resume()}function Va(t=1,i=.05,a=220,e=0,s=0,r=.1,o=0,l=1,c=0,u=0,x=0,y=0,d=0,b=0,g=0,f=0,v=0,m=1,w=0,p=0){var M=2*h,z=c*=500*M/44100/44100,D=[];i=a*=(1+i*n(-1,1))*M/44100;let L=0,S=0,A=0,j=1,B=0,C=0,G=0,k,H;for(u*=500*M/44100**3,g*=M/44100,x*=M/44100,y*=44100,d=44100*d|0,H=(e=44100*e+9)+(w*=44100)+(s*=44100)+(r*=44100)+(v*=44100)|0;A<H;D[A++]=G)++C%(100*f|0)||(G=o?1<o?2<o?3<o?Math.sin((L%M)**3):Math.max(Math.min(Math.tan(L),1),-1):1-(2*L/M%2+2)%2:1-4*Math.abs(Math.round(L/M)-L/M):Math.sin(L),G=(d?1-p+p*Math.sin(M*A/d):1)*Math.sign(G)*Math.abs(G)**l*t*.5*(A<e?A/e:A<e+w?1-(A-e)/w*(1-m):A<e+w+s?m:A<H-v?(H-A-v)/r*m:0),G=v?G/2+(v>A?0:(A<H-v?1:(H-A)/v)*D[A-v|0]/2):G),k=(a+=c+=u)*Math.cos(g*S++),L+=k-k*b*(1-1e9*(Math.sin(A)+1)%2),j&&++j>y&&(a+=x,i+=x,j=0),!d||++B%d||(a=i,c=z,j||=1);return D}let Xa=[],Q=x();function wa(t,i=x(),a){var e=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=e;i<h;++i){var n=Xa[s*Q.x+i];if(n&&(!a||0<n))return 1}}class Ya{constructor(t,i=0,a=0,e=new v){this.Z=t,this.direction=i,this.o=a,this.color=e}clear(){this.Z=this.direction=this.o=0,color=new v}}function Za(t,i){var a=i.floor().add(t.i).add(x(.5));$a(t,a,t=>t.clearRect(-.5,-.5,1,1)),null!=(i=t.getData(i)).Z&&B(a,x(1),Da(i.Z,t.l.size,t.l.P),i.color,i.direction*h/2,i.o)}function $a(t,i,a){var e=x(1),s=t.context;s.save(),i=i.u(t.i).multiply(t.l.size),e=e.multiply(t.l.size),s.translate(i.x,t.canvas.height-i.y),s.rotate(0),s.scale(e.x,e.y),a(s),s.restore()}class ab extends ta{constructor(t,i=Q){var a=x(1);for(super(t,i,Da(),0,void 0,0),this.canvas=document.createElement("canvas"),this.context=this.canvas.getContext("2d"),this.scale=a,this.ra,this.data=[],t=this.size,t=Math.abs(t.x*t.y);t--;)this.data.push(new Ya)}setData(t,i,a){ka(t,this.size)&&(this.data[(0|t.y)*this.size.x+t.x|0]=i,a)&&Za(this,t)}getData(t){return ka(t,this.size)&&this.data[(0|t.y)*this.size.x+t.x|0]}update(){}D(){var t=Ia(this.i.add(x(0,this.size.y*this.scale.y)));(this.ra?xa:G).drawImage(this.canvas,t.x,t.y,z*this.size.x*this.scale.x,z*this.size.y*this.scale.y)}}function bb(t){var i=null!=t.U.x?x(n(-.5,.5),n(-.5,.5)).multiply(t.U).rotate(t.angle):ha(t.U/2);t.X||(i=t.i.add(i)),i=new cb(i,t.l,t.Ea);const a=t.N;var e=(o=t=>t+t*n(a,-a))(t.va),s=o(t.Y),h=o(t.ya),r=o(t.speed),o=o(t.na)*(2*Math.floor(n(2,0))-1),l=n(t.da,-t.da),c=ia(t.S,t.T,t.ia),u=ia(t.$,t.aa,t.ia),l=t.X?l:t.angle+l;i.L=c,i.K=u.u(c),i.g=fa(x(),l,r),i.R=o,i.ta=e,i.Y=s,i.za=h-s,i.V=t.V,i.m=t.m,i.I=t.I,i.s=t.s,i.W=t.W,i.A=t.A,i.J=t.J,i.H=t.H,i.O=t.O,i.G=t.G,i.o=Math.floor(n(2,0)),i.C=t.X&&t,i.ba=t.Da,t.ua&&t.ua(i)}class db extends ta{constructor(t,i,a=0,e=0,s=100,n=h,r,o=new v,l=new v,c=new v(1,1,1,0),u=new v(1,1,1,0),y=.5,d=.1,b=1,g=.1,f=.05,m=1,w=1,p=0,M,z=.1,D=.2,L,S,A=1,j=S?1e9:0,B){super(t,x(),r,i,void 0,j),this.U=a,this.fa=e,this.ea=s,this.da=n,this.S=o,this.T=l,this.$=c,this.aa=u,this.ia=A,this.va=y,this.Y=d,this.ya=b,this.speed=g,this.na=f,this.m=m,this.I=w,this.A=p,this.V=z,this.N=D,this.J=L,this.H=S,this.X=B,this.F=this.G=0}update(){if(this.parent&&super.update(),!this.fa||ua-this.ka<=this.fa){if(+this.ea){var t=1/this.ea;for(this.F+=eb;0<this.F;this.F-=t)bb(this)}}else sa(this)}D(){}}class cb extends ta{constructor(t,i,a){super(t,x(),i,a)}D(){var t=Math.min((ua-this.ka)/this.ta,1),i=x(this.Y+t*this.za),a=this.V/2,a=new v(this.L.r+t*this.K.r,this.L.j+t*this.K.j,this.L.b+t*this.K.b,(this.L.a+t*this.K.a)*(t<a?t/a:1-a<t?(1-t)/a:1));this.H&&fb(1);let e=this.i;var s,h,n=this.angle;this.C&&(e=this.C.i.add(e.rotate(-this.C.angle)),n+=this.C.angle),this.G?(s=this.g,n=(s=this.C?s.rotate(-this.C.angle):s).length(),s=s.scale(1/n),h=n*this.G,i.y=Math.max(i.x,h),n=s.angle(),B(e.add(s.multiply(x(0,-h/2))),i,this.l,a,n,this.o)):B(e,i,this.l,a,n,this.o),this.H&&fb(),1==t&&(this.color=a,this.size=i,this.ba&&this.ba(this),this.v=1)}}const gb=[];let hb=[],ib,jb;class kb{constructor(){(gb[this.id=0]=this).name="Example Medal",this.description="Welcome to LittleJS!",this.icon="🏆"}unlock(){this.la||(localStorage[ib+"_"+this.id]=this.la=1,hb.push(this),lb&&lb.Fa(this.id))}D(t=0){var i=xa,a=Math.min(ra.x,D.width),e=H.width-a;t*=-ra.y,i.save(),i.beginPath(),i.fillStyle=new v(.9,.9,.9),i.strokeStyle=new v(0,0,0),i.lineWidth=3,i.fill(i.rect(e,t,a,ra.y)),i.stroke(),i.clip(),a=x(e+15+25,t+ra.y/2),this.image?xa.drawImage(this.image,a.x-25,a.y-25,50,50):Ma(this.icon,a,35,new v(0,0,0)),e=x(e+50+30,t+28),Ma(this.name,e,38,new v(0,0,0),0,0,"left"),e.y+=32,Ma(this.description,e,24,new v(0,0,0),0,0,"left"),i.restore()}}function mb(){var t,i;hb.length&&(t=hb[0],i=nb-jb,jb?5<i?hb.shift(jb=0):t.D(i<.5?1-i/.5:4.5<i?(i-4.5)/.5:0):jb=nb)}let lb,S,L,ob,pb,qb,T,tb,U,ub,vb;function wb(){S=document.createElement("canvas"),L=S.getContext("webgl",{antialias:!1}),document.body.appendChild(S);var t=L.createProgram();L.attachShader(t,xb("precision highp float;uniform mat4 m;attribute vec2 p,t;attribute vec4 c,a;varying vec4 v,d,e;void main(){gl_Position=m*vec4(p,1,1);v=vec4(t,p);d=c;e=a;}",35633)),L.attachShader(t,xb("precision highp float;varying vec4 v,d,e;uniform sampler2D s;void main(){gl_FragColor=texture2D(s,v.xy)*d+e;}",35632)),L.linkProgram(t),pb=t,t=new ArrayBuffer(24e5),qb=L.createBuffer(),T=new Float32Array(t),tb=new Uint32Array(t),U=0}function yb(){L.viewport(0,0,S.width=D.width,S.height=D.height),L.clear(16384),L.useProgram(pb),L.activeTexture(33984),L.bindTexture(3553,ob=K[0].ga),L.bindBuffer(34962,qb),L.bufferData(34962,24e5,35048),fb();let h=0;var t=(t,i,a,e,s=0)=>{t=L.getAttribLocation(pb,t),L.enableVertexAttribArray(t),L.vertexAttribPointer(t,e,i,s,24,h),h+=e*a},i=(t("p",5126,4,2),t("t",5126,4,2),t("c",5121,1,4,1),t("a",5121,1,4,1),t=2*z/D.width,2*z/D.height);L.uniformMatrix4fv(L.getUniformLocation(pb,"m"),0,new Float32Array([t,0,0,0,0,i,0,0,1,1,-1,1,-1-t*y.x,-1-i*y.y,0,0]))}function fb(t=0){vb=t}function Ja(t){t!=ob&&(zb(),L.bindTexture(3553,ob=t))}function xb(t,i){return i=L.createShader(i),L.shaderSource(i,t),L.compileShader(i),i}function zb(){var t;U&&(t=ub?1:771,L.blendFuncSeparate(770,t,1,t),L.enable(3042),L.bufferSubData(34962,0,T.subarray(0,6*U)),L.drawArrays(5,0,U),U=0,ub=vb)}function Ab(t){var i=G;(U||t)&&(zb(),t)&&i.drawImage(S,0,0)}function Ka(a,e,t,i,s,h,n,r,o,l,c=0){(99994<=U||ub!=vb)&&zb();var u=Math.cos(s)/2,x=Math.sin(s)/2;s=u*t,u*=i,a=[a-s+(i*=x),e+u+(t*=x),h,n,a-s-i,e-u+t,h,o,a+s+i,e+u-t,r,n,a+s-i,e-u-t,r,o];for(let t=6,i=6*U;t--;)e=4*m(t-1,0,3),T[i++]=a[e++],T[i++]=a[e++],T[i++]=a[e++],T[i++]=a[e++],tb[i++]=l,tb[i++]=c;U+=6}const eb=1/60;let A=[],va=[],Bb=0,ua=0,nb=0,Cb=0,V=0;function Db(){J=x(D.width,D.height),G.imageSmoothingEnabled=!1,yb()}function Eb(){va=A.filter(t=>t.oa);for(const t of A)t.parent||function t(i){if(!i.v){i.update();for(const a of i.children)t(a)}}(t);A=A.filter(t=>!t.v)}const Fb=new Wa,Gb=new kb;ib="Hello World",gb.forEach(t=>t.la=0|localStorage[ib+"_"+t.id]);let Z;!function(e,s,r,o){function l(t=0){var i=t-Cb;for(Cb=t,nb+=i/1e3,V+=i,V=Math.min(V,50),oa.x?(D.width=oa.x,D.height=oa.y,t=innerWidth/innerHeight,i=D.width/D.height,(S||D).style.width=D.style.width=H.style.width=t<i?"100%":"",(S||D).style.height=D.style.height=H.style.height=t<i?"":"100%"):(D.width=Math.min(innerWidth,na.x),D.height=Math.min(innerHeight,na.y)),H.width=D.width,H.height=D.height,J=x(D.width,D.height),t=0,V<0&&-9<V&&(t=V,V=0);0<=V;V-=1e3/60)ua=Bb++/60,Ta||document.hasFocus()||(M=[[]]),Oa=Ga(),Sa(),e(),Eb(),s(),Pa();V+=t,Db(),r(),A.sort((t,i)=>t.O-i.O);for(const a of A)a.v||a.D();o(),mb(),Ab(),requestAnimationFrame(l)}document.body.style="margin:0;overflow:hidden;background:#000;touch-action:none;user-select:none;-webkit-user-select:none;-webkit-touch-callout:none",document.body.appendChild(D=document.createElement("canvas")),G=D.getContext("2d"),wb(),document.body.appendChild(H=document.createElement("canvas")),xa=H.getContext("2d"),(S||D).style=D.style=H.style="position:absolute;top:50%;left:50%;transform:translate(-50%,-50%);image-rendering:pixelated",Promise.all(["tiles.png","tiles3.png"].map((a,e)=>new Promise(t=>{const i=new Image;i.onerror=i.onload=()=>{K[e]=new Fa(i),t()},i.src=a}))).then(()=>{{Q=x(32,16);for(var t=(Xa=[]).length=Math.abs(Q.x*Q.y);t--;)Xa[t]=0;var i=x(),t=new ab(i,Q),a=K[0].image,e=(G.drawImage(a,0,0),G.getImageData(0,0,a.width,a.height).data),s,r,o;for(i.x=Q.x;i.x--;)for(i.y=Q.y;i.y--;)e[4*(i.x+a.width*(15+Q.y-i.y))]&&(s=Math.floor(n(4,0)),r=Math.floor(n(2,0)),(o=ia()).a=.1,t.setData(i,new Ya(1,s,r,o)),ka(i,Q))&&(Xa[(0|i.y)*Q.x+i.x|0]=1);for(t.xa=[D,G,J,y,z],D=t.canvas,G=t.context,y=t.size.scale(.5),z=t.l.size.x,D.width=t.size.x*t.l.size.x,D.height=t.size.y*t.l.size.y,Db(),i=t.size.x;i--;)for(a=t.size.y;a--;)Za(t,x(i,a));Ab(1),[D,G,J,y,z]=t.xa,y=x(16,8),z=48,qa=-.01,(Z=new db(x(16,15),0,1,0,500,h,Da(0,16),new v(1,1,1),new v(0,0,0),new v(1,1,1,0),new v(0,0,0,0),2,.2,.2,.1,.05,.99,1,1,h,.05,.5,1,1)).s=.3,Z.G=2}l()})}(function(){M[0]&&2&M[0][0]&&(Fb.play(Oa),Z.S=new v,Z.T=ia(),Z.$=Z.S.scale(1,0),Z.aa=Z.T.scale(1,0),Gb.unlock()),Ha.x&&(Z.i=Oa)},function(){},function(){B(x(16,8),x(20,14),void 0,la(.6),0,0,void 0,0),B(x(21,5),x(4.5),Da(2,16,1))},function(){Ma("LittleJS Engine Demo",x(J.x/2,70),80,la(1),6,la(0))});
|
|
Binary file
|
package/examples/starter/game.js
CHANGED
|
@@ -43,7 +43,7 @@ function gameInit()
|
|
|
43
43
|
// set tile data
|
|
44
44
|
const tileIndex = 1;
|
|
45
45
|
const direction = randInt(4)
|
|
46
|
-
const mirror = randInt(2);
|
|
46
|
+
const mirror = !randInt(2);
|
|
47
47
|
const color = randColor();
|
|
48
48
|
const data = new TileLayerData(tileIndex, direction, mirror, color);
|
|
49
49
|
tileLayer.setData(pos, data);
|
|
@@ -69,7 +69,7 @@ function gameInit()
|
|
|
69
69
|
hsl(0,0,0,0), hsl(0,0,0,0), // colorEndA, colorEndB
|
|
70
70
|
2, .2, .2, .1, .05, // time, sizeStart, sizeEnd, speed, angleSpeed
|
|
71
71
|
.99, 1, 1, PI, // damping, angleDamping, gravityScale, cone
|
|
72
|
-
.05, .5,
|
|
72
|
+
.05, .5, true, true // fadeRate, randomness, collide, additive
|
|
73
73
|
);
|
|
74
74
|
particleEmitter.elasticity = .3; // bounce when it collides
|
|
75
75
|
particleEmitter.trailScale = 2; // stretch in direction of motion
|
|
@@ -108,7 +108,7 @@ function gameUpdatePost()
|
|
|
108
108
|
function gameRender()
|
|
109
109
|
{
|
|
110
110
|
// draw a grey square in the background without using webgl
|
|
111
|
-
drawRect(vec2(16,8), vec2(20,14), hsl(0,0,.6), 0,
|
|
111
|
+
drawRect(vec2(16,8), vec2(20,14), hsl(0,0,.6), 0, false);
|
|
112
112
|
|
|
113
113
|
// draw the logo as a tile
|
|
114
114
|
drawTile(vec2(21,5), vec2(4.5), tile(3,128));
|
|
@@ -125,4 +125,4 @@ function gameRenderPost()
|
|
|
125
125
|
|
|
126
126
|
///////////////////////////////////////////////////////////////////////////////
|
|
127
127
|
// Startup LittleJS Engine
|
|
128
|
-
engineInit(gameInit, gameUpdate, gameUpdatePost, gameRender, gameRenderPost);
|
|
128
|
+
engineInit(gameInit, gameUpdate, gameUpdatePost, gameRender, gameRenderPost, ['tiles.png']);
|
|
Binary file
|
|
@@ -1,23 +1,24 @@
|
|
|
1
1
|
<!DOCTYPE html><head>
|
|
2
|
-
<title>
|
|
2
|
+
<title>LittleJS Starter Project</title>
|
|
3
|
+
<meta charset=utf-8>
|
|
3
4
|
<meta name=apple-mobile-web-app-capable content=yes>
|
|
4
5
|
<meta name=mobile-web-app-capable content=yes>
|
|
5
6
|
<link rel=icon type=image/png href=../favicon.png>
|
|
6
7
|
</head><body>
|
|
7
8
|
|
|
8
9
|
<!-- LittleJS Engine -->
|
|
9
|
-
<script src=../../src/engineDebug.js?
|
|
10
|
-
<script src=../../src/engineUtilities.js?
|
|
11
|
-
<script src=../../src/engineSettings.js?
|
|
12
|
-
<script src=../../src/engineObject.js?
|
|
13
|
-
<script src=../../src/engineDraw.js?
|
|
14
|
-
<script src=../../src/engineInput.js?
|
|
15
|
-
<script src=../../src/engineAudio.js?
|
|
16
|
-
<script src=../../src/engineTileLayer.js?
|
|
17
|
-
<script src=../../src/engineParticles.js?
|
|
18
|
-
<script src=../../src/engineMedals.js?
|
|
19
|
-
<script src=../../src/engineWebGL.js?
|
|
20
|
-
<script src=../../src/engine.js?
|
|
10
|
+
<script src=../../src/engineDebug.js?1100></script>
|
|
11
|
+
<script src=../../src/engineUtilities.js?1100></script>
|
|
12
|
+
<script src=../../src/engineSettings.js?1100></script>
|
|
13
|
+
<script src=../../src/engineObject.js?1100></script>
|
|
14
|
+
<script src=../../src/engineDraw.js?1100></script>
|
|
15
|
+
<script src=../../src/engineInput.js?1100></script>
|
|
16
|
+
<script src=../../src/engineAudio.js?1100></script>
|
|
17
|
+
<script src=../../src/engineTileLayer.js?1100></script>
|
|
18
|
+
<script src=../../src/engineParticles.js?1100></script>
|
|
19
|
+
<script src=../../src/engineMedals.js?1100></script>
|
|
20
|
+
<script src=../../src/engineWebGL.js?1100></script>
|
|
21
|
+
<script src=../../src/engine.js?1100></script>
|
|
21
22
|
|
|
22
23
|
<!-- Add your game scripts here -->
|
|
23
|
-
<script src=game.js?
|
|
24
|
+
<script src=game.js?1100></script>
|
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
<!DOCTYPE html><head>
|
|
2
|
-
<title>
|
|
2
|
+
<title>LittleJS Stress Test</title>
|
|
3
|
+
<meta charset=utf-8>
|
|
3
4
|
<meta name=apple-mobile-web-app-capable content=yes>
|
|
4
5
|
<meta name=mobile-web-app-capable content=yes>
|
|
5
6
|
<link rel=icon type=image/png href=../favicon.png>
|
|
6
7
|
</head><body>
|
|
7
8
|
|
|
8
9
|
<!-- LittleJS Engine -->
|
|
9
|
-
<script src=../../dist/littlejs.min.js?
|
|
10
|
+
<script src=../../dist/littlejs.min.js?1100></script>
|
|
10
11
|
<script>
|
|
11
12
|
|
|
12
13
|
/*
|