littlejsengine 1.8.6 → 1.8.9
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 -3
- package/build/littlejs.d.ts +18 -9
- package/build/littlejs.esm.js +298 -92
- package/build/littlejs.esm.min.js +1 -1
- package/build/littlejs.js +296 -92
- package/build/littlejs.min.js +1 -1
- package/build/littlejs.release.js +296 -92
- package/examples/breakout/game.js +3 -0
- package/examples/breakout/index.html +3 -3
- package/examples/breakoutTutorial/index.html +2 -2
- package/examples/electron/game.js +3 -0
- package/examples/electron/index.html +2 -2
- package/examples/js13k/index.html +13 -13
- package/examples/logo.png +0 -0
- package/examples/module/game.js +3 -0
- package/examples/module/index.html +1 -1
- package/examples/particles/index.html +1 -1
- package/examples/platformer/game.js +3 -0
- package/examples/platformer/gameEffects.js +1 -1
- package/examples/platformer/index.html +6 -6
- package/examples/puzzle/game.js +3 -0
- package/examples/puzzle/index.html +2 -2
- package/examples/starter/game.js +4 -1
- package/examples/starter/index.html +13 -13
- package/examples/starter/tiles.png +0 -0
- package/examples/stress/index.html +3 -1
- package/examples/typescript/game.js +2 -0
- package/examples/typescript/game.ts +3 -0
- package/examples/typescript/index.html +1 -1
- package/package.json +1 -1
- package/src/engine.js +189 -9
- package/src/engineAudio.js +72 -58
- package/src/engineDraw.js +1 -1
- package/src/engineExport.js +2 -0
- package/src/engineParticles.js +7 -7
- package/src/engineSettings.js +11 -0
- package/src/engineUtilities.js +4 -5
- package/src/engineWebGL.js +12 -12
|
@@ -18,7 +18,7 @@ const sound_destroyObject =new Sound([.5,,1e3,.02,,.2,1,3,.1,,,,,1,-30,.5,,.5]);
|
|
|
18
18
|
const sound_die = new Sound([.5,.4,126,.05,,.2,1,2.09,,-4,,,1,1,1,.4,.03]);
|
|
19
19
|
const sound_jump = new Sound([.4,.2,250,.04,,.04,,,1,,,,,3]);
|
|
20
20
|
const sound_dodge = new Sound([.4,.2,150,.05,,.05,,,-1,,,,,4,,,,,.02]);
|
|
21
|
-
const sound_walk = new Sound([.3,.1,
|
|
21
|
+
const sound_walk = new Sound([.3,.1,200,,,.01,4,,,,-9,.1,,,,,,.5]);
|
|
22
22
|
const sound_explosion = new Sound([2,.2,72,.01,.01,.2,4,,,,,,,1,,.5,.1,.5,.02]);
|
|
23
23
|
const sound_grenade = new Sound([.5,.01,300,,,.02,3,.22,,,-9,.2,,,,,,.5]);
|
|
24
24
|
const sound_killEnemy = new Sound([,,783,,.03,.02,1,2,,,940,.03,,,,,.2,.6,,.06]);
|
|
@@ -6,9 +6,9 @@
|
|
|
6
6
|
<link rel=icon type=image/png href=../favicon.png>
|
|
7
7
|
</head><body>
|
|
8
8
|
|
|
9
|
-
<script src=../../build/littlejs.js?
|
|
10
|
-
<script src=gameObjects.js?
|
|
11
|
-
<script src=gamePlayer.js?
|
|
12
|
-
<script src=gameEffects.js?
|
|
13
|
-
<script src=gameLevel.js?
|
|
14
|
-
<script src=game.js?
|
|
9
|
+
<script src=../../build/littlejs.js?188></script>
|
|
10
|
+
<script src=gameObjects.js?188></script>
|
|
11
|
+
<script src=gamePlayer.js?188></script>
|
|
12
|
+
<script src=gameEffects.js?188></script>
|
|
13
|
+
<script src=gameLevel.js?188></script>
|
|
14
|
+
<script src=game.js?188></script>
|
package/examples/puzzle/game.js
CHANGED
package/examples/starter/game.js
CHANGED
|
@@ -7,6 +7,9 @@
|
|
|
7
7
|
|
|
8
8
|
'use strict';
|
|
9
9
|
|
|
10
|
+
// show the LittleJS splash screen
|
|
11
|
+
showSplashScreen = 1;
|
|
12
|
+
|
|
10
13
|
// sound effects
|
|
11
14
|
const sound_click = new Sound([1,.5]);
|
|
12
15
|
|
|
@@ -108,7 +111,7 @@ function gameRender()
|
|
|
108
111
|
drawRect(vec2(16,8), vec2(20,14), hsl(0,0,.6), 0, 0);
|
|
109
112
|
|
|
110
113
|
// draw the logo as a tile
|
|
111
|
-
drawTile(vec2(21,5), vec2(4.5), tile(
|
|
114
|
+
drawTile(vec2(21,5), vec2(4.5), tile(3,128));
|
|
112
115
|
}
|
|
113
116
|
|
|
114
117
|
///////////////////////////////////////////////////////////////////////////////
|
|
@@ -6,18 +6,18 @@
|
|
|
6
6
|
</head><body>
|
|
7
7
|
|
|
8
8
|
<!-- 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?
|
|
9
|
+
<script src=../../src/engineDebug.js?188></script>
|
|
10
|
+
<script src=../../src/engineUtilities.js?188></script>
|
|
11
|
+
<script src=../../src/engineSettings.js?188></script>
|
|
12
|
+
<script src=../../src/engineObject.js?188></script>
|
|
13
|
+
<script src=../../src/engineDraw.js?188></script>
|
|
14
|
+
<script src=../../src/engineInput.js?188></script>
|
|
15
|
+
<script src=../../src/engineAudio.js?188></script>
|
|
16
|
+
<script src=../../src/engineTileLayer.js?188></script>
|
|
17
|
+
<script src=../../src/engineParticles.js?188></script>
|
|
18
|
+
<script src=../../src/engineMedals.js?188></script>
|
|
19
|
+
<script src=../../src/engineWebGL.js?188></script>
|
|
20
|
+
<script src=../../src/engine.js?188></script>
|
|
21
21
|
|
|
22
22
|
<!-- Add your game scripts here -->
|
|
23
|
-
<script src=game.js?
|
|
23
|
+
<script src=game.js?188></script>
|
|
Binary file
|
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
</head><body>
|
|
7
7
|
|
|
8
8
|
<!-- LittleJS Engine -->
|
|
9
|
-
<script src=../../build/littlejs.min.js?
|
|
9
|
+
<script src=../../build/littlejs.min.js?188></script>
|
|
10
10
|
<script>
|
|
11
11
|
|
|
12
12
|
/*
|
|
@@ -36,6 +36,8 @@ class TestObject extends EngineObject
|
|
|
36
36
|
///////////////////////////////////////////////////////////////////////////////
|
|
37
37
|
function gameInit()
|
|
38
38
|
{
|
|
39
|
+
canvasFixedSize = vec2(800, 600); // 720p
|
|
40
|
+
|
|
39
41
|
// create tile collision
|
|
40
42
|
initTileCollision(vec2(80,50));
|
|
41
43
|
for (let x = tileCollisionSize.x; x--;)
|
|
@@ -7,6 +7,8 @@
|
|
|
7
7
|
// import module
|
|
8
8
|
import * as LittleJS from '../../build/littlejs.esm.js';
|
|
9
9
|
const { Vector2, Color, Timer, vec2, tile } = LittleJS;
|
|
10
|
+
// show the LittleJS splash screen
|
|
11
|
+
LittleJS.setShowSplashScreen(true);
|
|
10
12
|
// sound effects
|
|
11
13
|
const sound_click = new LittleJS.Sound([1, .5]);
|
|
12
14
|
// medals
|
|
@@ -10,6 +10,9 @@
|
|
|
10
10
|
import * as LittleJS from '../../build/littlejs.esm.js';
|
|
11
11
|
const {Vector2, Color, Timer, vec2, tile} = LittleJS;
|
|
12
12
|
|
|
13
|
+
// show the LittleJS splash screen
|
|
14
|
+
LittleJS.setShowSplashScreen(true);
|
|
15
|
+
|
|
13
16
|
// sound effects
|
|
14
17
|
const sound_click = new LittleJS.Sound([1,.5]);
|
|
15
18
|
|
package/package.json
CHANGED
package/src/engine.js
CHANGED
|
@@ -30,7 +30,7 @@ const engineName = 'LittleJS';
|
|
|
30
30
|
* @type {String}
|
|
31
31
|
* @default
|
|
32
32
|
* @memberof Engine */
|
|
33
|
-
const engineVersion = '1.8.
|
|
33
|
+
const engineVersion = '1.8.9';
|
|
34
34
|
|
|
35
35
|
/** Frames per second to update objects
|
|
36
36
|
* @type {Number}
|
|
@@ -213,7 +213,7 @@ function engineInit(gameInit, gameUpdate, gameUpdatePost, gameRender, gameRender
|
|
|
213
213
|
}
|
|
214
214
|
|
|
215
215
|
// setup html
|
|
216
|
-
|
|
216
|
+
const styleBody =
|
|
217
217
|
'margin:0;overflow:hidden;' + // fill the window
|
|
218
218
|
'background:#000;' + // set background color
|
|
219
219
|
'touch-action:none;' + // prevent mobile pinch to resize
|
|
@@ -234,14 +234,13 @@ function engineInit(gameInit, gameUpdate, gameUpdatePost, gameRender, gameRender
|
|
|
234
234
|
|
|
235
235
|
// set canvas style
|
|
236
236
|
const styleCanvas =
|
|
237
|
-
'position:absolute;' +
|
|
238
|
-
'top:50%;left:50%;transform:translate(-50%,-50%);
|
|
239
|
-
(canvasPixelated?'image-rendering:pixelated':''); // pixelated rendering
|
|
237
|
+
'position:absolute;' + // position
|
|
238
|
+
'top:50%;left:50%;transform:translate(-50%,-50%)'; // center
|
|
240
239
|
(glCanvas||mainCanvas).style = mainCanvas.style = overlayCanvas.style = styleCanvas;
|
|
241
240
|
|
|
242
|
-
//
|
|
243
|
-
|
|
244
|
-
new Promise(
|
|
241
|
+
// create promises for loading images
|
|
242
|
+
const promises = imageSources.map((src, textureIndex)=>
|
|
243
|
+
new Promise(resolve =>
|
|
245
244
|
{
|
|
246
245
|
const image = new Image;
|
|
247
246
|
image.onerror = image.onload = ()=>
|
|
@@ -251,7 +250,24 @@ function engineInit(gameInit, gameUpdate, gameUpdatePost, gameRender, gameRender
|
|
|
251
250
|
}
|
|
252
251
|
image.src = src;
|
|
253
252
|
})
|
|
254
|
-
)
|
|
253
|
+
)
|
|
254
|
+
|
|
255
|
+
// draw splash screen
|
|
256
|
+
showSplashScreen && promises.push(new Promise(resolve =>
|
|
257
|
+
{
|
|
258
|
+
let t = 0;
|
|
259
|
+
console.log(`LittleJS Engine v${engineVersion}`);
|
|
260
|
+
updateSplash();
|
|
261
|
+
function updateSplash()
|
|
262
|
+
{
|
|
263
|
+
clearInput();
|
|
264
|
+
drawEngineSplashScreen(t+=.01);
|
|
265
|
+
t>1 ? resolve() : setTimeout(updateSplash,16);
|
|
266
|
+
}
|
|
267
|
+
}));
|
|
268
|
+
|
|
269
|
+
// load all of the images
|
|
270
|
+
Promise.all(promises).then(()=>
|
|
255
271
|
{
|
|
256
272
|
// start the engine
|
|
257
273
|
gameInit();
|
|
@@ -329,4 +345,168 @@ function engineObjectsCallback(pos, size, callbackFunction, objects=engineObject
|
|
|
329
345
|
for (const o of objects)
|
|
330
346
|
pos.distanceSquared(o.pos) < sizeSquared && callbackFunction(o);
|
|
331
347
|
}
|
|
348
|
+
}
|
|
349
|
+
|
|
350
|
+
///////////////////////////////////////////////////////////////////////////////
|
|
351
|
+
// LittleJS splash screen and logo
|
|
352
|
+
|
|
353
|
+
function drawEngineSplashScreen(t)
|
|
354
|
+
{
|
|
355
|
+
const x = mainContext;
|
|
356
|
+
const w = mainCanvas.width = innerWidth;
|
|
357
|
+
const h = mainCanvas.height = innerHeight;
|
|
358
|
+
{
|
|
359
|
+
// background
|
|
360
|
+
const p3 = percent(t, 1, .8);
|
|
361
|
+
const p4 = percent(t, 0, .5);
|
|
362
|
+
const g = x.createRadialGradient(w/2,h/2,0,w/2,h/2,Math.hypot(w,h)*.7);
|
|
363
|
+
g.addColorStop(0,hsl(0,0,lerp(p4,0,p3/2),p3));
|
|
364
|
+
g.addColorStop(1,hsl(0,0,0,p3));
|
|
365
|
+
x.save();
|
|
366
|
+
x.fillStyle = g;
|
|
367
|
+
x.fillRect(0,0,w,h);
|
|
368
|
+
}
|
|
369
|
+
|
|
370
|
+
// draw LittleJS logo...
|
|
371
|
+
|
|
372
|
+
const rect = (X, Y, W, H, C)=>
|
|
373
|
+
{
|
|
374
|
+
x.beginPath();
|
|
375
|
+
x.rect(X,Y,W,C?H*p:H);
|
|
376
|
+
x.fillStyle = C;
|
|
377
|
+
C ? x.fill() : x.stroke();
|
|
378
|
+
};
|
|
379
|
+
const line = (X, Y, Z, W)=>
|
|
380
|
+
{
|
|
381
|
+
x.beginPath();
|
|
382
|
+
x.lineTo(X,Y);
|
|
383
|
+
x.lineTo(Z,W);
|
|
384
|
+
x.stroke();
|
|
385
|
+
};
|
|
386
|
+
const circle = (X, Y, R, A=0, B=2*PI, C, F)=>
|
|
387
|
+
{
|
|
388
|
+
const D = (A+B)/2, E = p*(B-A)/2;
|
|
389
|
+
x.beginPath();
|
|
390
|
+
F && x.lineTo(X,Y);
|
|
391
|
+
x.arc(X,Y,R,D-E,D+E);
|
|
392
|
+
x.fillStyle = C;
|
|
393
|
+
C ? x.fill() : x.stroke();
|
|
394
|
+
};
|
|
395
|
+
const color = (c=0, l=0) =>
|
|
396
|
+
hsl([.98,.3,.57,.14][c%4]-10,.8,[0,.3,.5,.8,.9][l]);
|
|
397
|
+
const alpha = wave(1,1,t);
|
|
398
|
+
const p = percent(alpha, .1, .5);
|
|
399
|
+
|
|
400
|
+
// setup
|
|
401
|
+
x.translate(w/2,h/2);
|
|
402
|
+
const size = min(6, min(w,h)/99); // fit to screen
|
|
403
|
+
x.scale(size,size);
|
|
404
|
+
x.translate(-40,-35);
|
|
405
|
+
x.lineJoin = x.lineCap = 'round';
|
|
406
|
+
x.lineWidth = 1+p;
|
|
407
|
+
|
|
408
|
+
// drawing effect
|
|
409
|
+
const p2 = percent(alpha,.1,1);
|
|
410
|
+
x.setLineDash([99*p2,99]);
|
|
411
|
+
|
|
412
|
+
// cab top
|
|
413
|
+
rect(7,17,18,-8,color(2,2));
|
|
414
|
+
rect(7,9,18,4,color(2,3));
|
|
415
|
+
rect(25,9,8,8,color(2,1));
|
|
416
|
+
rect(25,9,-18,8);
|
|
417
|
+
rect(25,9,8,8);
|
|
418
|
+
|
|
419
|
+
// cab
|
|
420
|
+
rect(25,17,7,22,color());
|
|
421
|
+
rect(11,40,14,-23,color(1,1));
|
|
422
|
+
rect(11,17,14,17,color(1,2));
|
|
423
|
+
rect(11,17,14,9,color(1,3));
|
|
424
|
+
rect(15,31,6,-9,color(2,2));
|
|
425
|
+
circle(15,23,5,0,PI/2,color(2,4),1);
|
|
426
|
+
rect(25,17,-14,23);
|
|
427
|
+
rect(21,22,-6,9);
|
|
428
|
+
|
|
429
|
+
// little stack
|
|
430
|
+
rect(37,14,9,6,color(3,2));
|
|
431
|
+
rect(37,14,4,6,color(3,3));
|
|
432
|
+
rect(37,14,9,6);
|
|
433
|
+
|
|
434
|
+
// big stack
|
|
435
|
+
rect(50,20,10,-10,color(0,1));
|
|
436
|
+
rect(50,20,6,-10,color(0,2));
|
|
437
|
+
rect(50,20,3,-10,color(0,3));
|
|
438
|
+
rect(50,10,10,10);
|
|
439
|
+
circle(55,2,11.4,.5,PI-.5,color(3,3));
|
|
440
|
+
circle(55,2,11.4,.5,PI/2,color(3,2),1);
|
|
441
|
+
circle(55,2,11.4,.5,PI-.5);
|
|
442
|
+
rect(45,7,20,-7,color(0,2));
|
|
443
|
+
rect(45,0,20,3,color(0,3));
|
|
444
|
+
rect(45,0,20,7);
|
|
445
|
+
|
|
446
|
+
// engine
|
|
447
|
+
for (let i=5; i--;)
|
|
448
|
+
{
|
|
449
|
+
// stagger radius to fix slight seam
|
|
450
|
+
circle(60-i*6,30, 9.9,0,2*PI,color(i+2,3));
|
|
451
|
+
circle(60-i*6,30,10.0,-.5,PI+.5,color(i+2,2));
|
|
452
|
+
circle(60-i*6,30,10.1,.5,PI-.5,color(i+2,1));
|
|
453
|
+
}
|
|
454
|
+
|
|
455
|
+
// engine outline
|
|
456
|
+
circle(36,30,10,PI/2,PI*3/2);
|
|
457
|
+
circle(47,30,10,PI/2,PI*3/2);
|
|
458
|
+
circle(60,30,10);
|
|
459
|
+
line(36,20,60,20);
|
|
460
|
+
|
|
461
|
+
// engine front light
|
|
462
|
+
circle(60,30,4,PI,3*PI,color(3,2));
|
|
463
|
+
circle(60,30,4,PI,2*PI,color(3,3));
|
|
464
|
+
circle(60,30,4,PI,3*PI);
|
|
465
|
+
|
|
466
|
+
// front brush
|
|
467
|
+
for (let i=6; i--;)
|
|
468
|
+
{
|
|
469
|
+
x.beginPath();
|
|
470
|
+
x.lineTo(53,54);
|
|
471
|
+
x.lineTo(53,40);
|
|
472
|
+
x.lineTo(53+(1+i*2.9)*p,40);
|
|
473
|
+
x.lineTo(53+(4+i*3.5)*p,54);
|
|
474
|
+
x.fillStyle = color(0,i%2+2);
|
|
475
|
+
x.fill() || i%2 && x.stroke();
|
|
476
|
+
}
|
|
477
|
+
|
|
478
|
+
// wheels
|
|
479
|
+
rect(6,40,5,5);
|
|
480
|
+
rect(6,40,5,5,color());
|
|
481
|
+
rect(15,54,38,-14,color());
|
|
482
|
+
for (let i=3; i--;)
|
|
483
|
+
for (let j=2; j--;)
|
|
484
|
+
{
|
|
485
|
+
circle(15*i+15,47,j?7:1,PI,3*PI,color(i,3));
|
|
486
|
+
x.stroke();
|
|
487
|
+
circle(15*i+15,47,j?7:1,0,PI,color(i,2));
|
|
488
|
+
x.stroke();
|
|
489
|
+
}
|
|
490
|
+
line(6,40,68,40); // center
|
|
491
|
+
line(77,54,4,54); // bottom
|
|
492
|
+
|
|
493
|
+
// draw engine name
|
|
494
|
+
const s = engineName;
|
|
495
|
+
x.font = '900 16px arial';
|
|
496
|
+
x.textAlign = 'center';
|
|
497
|
+
x.textBaseline = 'top';
|
|
498
|
+
x.lineWidth = 1+p*3;
|
|
499
|
+
let w2 = 0;
|
|
500
|
+
for (let i=0; i<s.length; ++i)
|
|
501
|
+
w2 += x.measureText(s[i]).width;
|
|
502
|
+
for (let j=2; j--;)
|
|
503
|
+
for (let i=0, X=41-w2/2; i<s.length; ++i)
|
|
504
|
+
{
|
|
505
|
+
x.fillStyle = color(i,2);
|
|
506
|
+
const w = x.measureText(s[i]).width;
|
|
507
|
+
x[j?'strokeText':'fillText'](s[i],X+w/2,55.5,17*p);
|
|
508
|
+
X += w;
|
|
509
|
+
}
|
|
510
|
+
|
|
511
|
+
x.restore();
|
|
332
512
|
}
|
package/src/engineAudio.js
CHANGED
|
@@ -327,7 +327,7 @@ function playSamples(sampleChannels, volume=1, rate=1, pan=0, loop=0, sampleRate
|
|
|
327
327
|
}
|
|
328
328
|
|
|
329
329
|
///////////////////////////////////////////////////////////////////////////////
|
|
330
|
-
// ZzFXMicro - Zuper Zmall Zound Zynth - v1.
|
|
330
|
+
// ZzFXMicro - Zuper Zmall Zound Zynth - v1.3.0 by Frank Force
|
|
331
331
|
|
|
332
332
|
/** Generate and play a ZzFX sound
|
|
333
333
|
*
|
|
@@ -363,6 +363,7 @@ const zzfxR = 44100;
|
|
|
363
363
|
* @param {Number} [sustainVolume=1] - Volume level for sustain (percent)
|
|
364
364
|
* @param {Number} [decay=0] - Decay time, how long to reach sustain after attack (seconds)
|
|
365
365
|
* @param {Number} [tremolo=0] - Trembling effect, rate controlled by repeat time (precent)
|
|
366
|
+
* @param {Number} [filter=0] - Filter cutoff frequency, positive for HPF, negative for LPF (Hz)
|
|
366
367
|
* @return {Array} - Array of audio samples
|
|
367
368
|
* @memberof Audio
|
|
368
369
|
*/
|
|
@@ -372,78 +373,91 @@ function zzfxG
|
|
|
372
373
|
volume = 1, randomness = .05, frequency = 220, attack = 0, sustain = 0,
|
|
373
374
|
release = .1, shape = 0, shapeCurve = 1, slide = 0, deltaSlide = 0,
|
|
374
375
|
pitchJump = 0, pitchJumpTime = 0, repeatTime = 0, noise = 0, modulation = 0,
|
|
375
|
-
bitCrush = 0, delay = 0, sustainVolume = 1, decay = 0, tremolo = 0
|
|
376
|
+
bitCrush = 0, delay = 0, sustainVolume = 1, decay = 0, tremolo = 0, filter = 0
|
|
376
377
|
)
|
|
377
378
|
{
|
|
378
|
-
//
|
|
379
|
-
let PI2 = PI*2,
|
|
380
|
-
|
|
381
|
-
|
|
379
|
+
// init parameters
|
|
380
|
+
let PI2 = PI*2, sampleRate = zzfxR,
|
|
381
|
+
startSlide = slide *= 500 * PI2 / sampleRate / sampleRate,
|
|
382
|
+
startFrequency = frequency *=
|
|
383
|
+
rand(1 + randomness, 1-randomness) * PI2 / sampleRate,
|
|
384
|
+
b = [], t = 0, tm = 0, i = 0, j = 1, r = 0, c = 0, s = 0, f, length,
|
|
385
|
+
|
|
386
|
+
// biquad LP/HP filter
|
|
387
|
+
quality = 2, w = PI2 * abs(filter) * 2 / sampleRate,
|
|
388
|
+
cos = Math.cos(w), alpha = Math.sin(w) / 2 / quality,
|
|
389
|
+
a0 = 1 + alpha, a1 = -2*cos / a0, a2 = (1 - alpha) / a0,
|
|
390
|
+
b0 = (1 + sign(filter) * cos) / 2 / a0,
|
|
391
|
+
b1 = -(sign(filter) + cos) / a0, b2 = b0,
|
|
392
|
+
x2 = 0, x1 = 0, y2 = 0, y1 = 0;
|
|
382
393
|
|
|
383
394
|
// scale by sample rate
|
|
384
|
-
attack = attack *
|
|
385
|
-
decay *=
|
|
386
|
-
sustain *=
|
|
387
|
-
release *=
|
|
388
|
-
delay *=
|
|
389
|
-
deltaSlide *= 500 * PI2 /
|
|
390
|
-
modulation *= PI2 /
|
|
391
|
-
pitchJump *= PI2 /
|
|
392
|
-
pitchJumpTime *=
|
|
393
|
-
repeatTime = repeatTime *
|
|
395
|
+
attack = attack * sampleRate + 9; // minimum attack to prevent pop
|
|
396
|
+
decay *= sampleRate;
|
|
397
|
+
sustain *= sampleRate;
|
|
398
|
+
release *= sampleRate;
|
|
399
|
+
delay *= sampleRate;
|
|
400
|
+
deltaSlide *= 500 * PI2 / sampleRate**3;
|
|
401
|
+
modulation *= PI2 / sampleRate;
|
|
402
|
+
pitchJump *= PI2 / sampleRate;
|
|
403
|
+
pitchJumpTime *= sampleRate;
|
|
404
|
+
repeatTime = repeatTime * sampleRate | 0;
|
|
405
|
+
volume *= soundVolume;
|
|
394
406
|
|
|
395
407
|
// generate waveform
|
|
396
|
-
for
|
|
397
|
-
i < length; b[i++] = s)
|
|
408
|
+
for(length = attack + decay + sustain + release + delay | 0;
|
|
409
|
+
i < length; b[i++] = s * volume) // sample
|
|
398
410
|
{
|
|
399
|
-
if (!(++c%(bitCrush*100|0)))
|
|
411
|
+
if (!(++c%(bitCrush*100|0))) // bit crush
|
|
400
412
|
{
|
|
401
|
-
s = shape? shape>1? shape>2? shape>3?
|
|
402
|
-
Math.sin(
|
|
403
|
-
|
|
404
|
-
1-(2*t/PI2%2+2)%2:
|
|
405
|
-
1-4*abs(Math.round(t/PI2)-t/PI2):
|
|
406
|
-
Math.sin(t);
|
|
407
|
-
|
|
413
|
+
s = shape? shape>1? shape>2? shape>3? // wave shape
|
|
414
|
+
Math.sin(t*t) : // 4 noise
|
|
415
|
+
clamp(Math.tan(t),1,-1): // 3 tan
|
|
416
|
+
1-(2*t/PI2%2+2)%2: // 2 saw
|
|
417
|
+
1-4*abs(Math.round(t/PI2)-t/PI2): // 1 triangle
|
|
418
|
+
Math.sin(t); // 0 sin
|
|
419
|
+
|
|
408
420
|
s = (repeatTime ?
|
|
409
421
|
1 - tremolo + tremolo*Math.sin(PI2*i/repeatTime) // tremolo
|
|
410
422
|
: 1) *
|
|
411
|
-
sign(s)*(abs(s)**shapeCurve) *
|
|
412
|
-
|
|
413
|
-
i < attack
|
|
414
|
-
i
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
423
|
+
sign(s)*(abs(s)**shapeCurve) * // curve
|
|
424
|
+
(i < attack ? i/attack : // attack
|
|
425
|
+
i < attack + decay ? // decay
|
|
426
|
+
1-((i-attack)/decay)*(1-sustainVolume) : // decay falloff
|
|
427
|
+
i < attack + decay + sustain ? // sustain
|
|
428
|
+
sustainVolume : // sustain volume
|
|
429
|
+
i < length - delay ? // release
|
|
430
|
+
(length - i - delay)/release * // release falloff
|
|
431
|
+
sustainVolume : // release volume
|
|
432
|
+
0); // post release
|
|
433
|
+
|
|
434
|
+
s = delay ? s/2 + (delay > i ? 0 : // delay
|
|
435
|
+
(i<length-delay? 1 : (length-i)/delay) * // release delay
|
|
436
|
+
b[i-delay|0]/2/volume) : s; // sample delay
|
|
437
|
+
|
|
438
|
+
if (filter) // apply filter
|
|
439
|
+
s = y1 = b2*x2 + b1*(x2=x1) + b0*(x1=s) - a2*y2 - a1*(y2=y1);
|
|
426
440
|
}
|
|
427
441
|
|
|
428
|
-
f = (frequency += slide += deltaSlide)
|
|
429
|
-
Math.cos(modulation*tm++);
|
|
430
|
-
t += f
|
|
431
|
-
|
|
432
|
-
if (j && ++j > pitchJumpTime)
|
|
433
|
-
{
|
|
434
|
-
frequency += pitchJump;
|
|
435
|
-
startFrequency += pitchJump;
|
|
436
|
-
j = 0;
|
|
437
|
-
}
|
|
438
|
-
|
|
439
|
-
if (repeatTime && !(++r % repeatTime))
|
|
440
|
-
{
|
|
441
|
-
frequency = startFrequency;
|
|
442
|
-
slide = startSlide;
|
|
443
|
-
j
|
|
442
|
+
f = (frequency += slide += deltaSlide) *// frequency
|
|
443
|
+
Math.cos(modulation*tm++); // modulation
|
|
444
|
+
t += f + f*noise*Math.sin(i**5); // noise
|
|
445
|
+
|
|
446
|
+
if (j && ++j > pitchJumpTime) // pitch jump
|
|
447
|
+
{
|
|
448
|
+
frequency += pitchJump; // apply pitch jump
|
|
449
|
+
startFrequency += pitchJump; // also apply to start
|
|
450
|
+
j = 0; // stop pitch jump time
|
|
451
|
+
}
|
|
452
|
+
|
|
453
|
+
if (repeatTime && !(++r % repeatTime)) // repeat
|
|
454
|
+
{
|
|
455
|
+
frequency = startFrequency; // reset frequency
|
|
456
|
+
slide = startSlide; // reset slide
|
|
457
|
+
j = j || 1; // reset pitch jump time
|
|
444
458
|
}
|
|
445
459
|
}
|
|
446
|
-
|
|
460
|
+
|
|
447
461
|
return b;
|
|
448
462
|
}
|
|
449
463
|
|
package/src/engineDraw.js
CHANGED
|
@@ -52,7 +52,7 @@ let mainCanvasSize = vec2();
|
|
|
52
52
|
* @memberof Draw */
|
|
53
53
|
let textureInfos = [];
|
|
54
54
|
|
|
55
|
-
//
|
|
55
|
+
// Keep track of how many draw calls there were each frame for debugging
|
|
56
56
|
let drawCount;
|
|
57
57
|
|
|
58
58
|
///////////////////////////////////////////////////////////////////////////////
|
package/src/engineExport.js
CHANGED
|
@@ -43,6 +43,7 @@ export {
|
|
|
43
43
|
canvasFixedSize,
|
|
44
44
|
canvasPixelated,
|
|
45
45
|
fontDefault,
|
|
46
|
+
showSplashScreen,
|
|
46
47
|
tileSizeDefault,
|
|
47
48
|
tileFixBleedScale,
|
|
48
49
|
enablePhysicsSolver,
|
|
@@ -80,6 +81,7 @@ export {
|
|
|
80
81
|
setCanvasFixedSize,
|
|
81
82
|
setCanvasPixelated,
|
|
82
83
|
setFontDefault,
|
|
84
|
+
setShowSplashScreen,
|
|
83
85
|
setGlEnable,
|
|
84
86
|
setGlOverlay,
|
|
85
87
|
setTileSizeDefault,
|
package/src/engineParticles.js
CHANGED
|
@@ -24,13 +24,13 @@
|
|
|
24
24
|
class ParticleEmitter extends EngineObject
|
|
25
25
|
{
|
|
26
26
|
/** Create a particle system with the given settings
|
|
27
|
-
* @param {Vector2} position
|
|
28
|
-
* @param {Number} [angle=0]
|
|
29
|
-
* @param {Number} [emitSize=0]
|
|
30
|
-
* @param {Number} [emitTime=0]
|
|
31
|
-
* @param {Number} [emitRate=100]
|
|
27
|
+
* @param {Vector2} position - World space position of the emitter
|
|
28
|
+
* @param {Number} [angle=0] - Angle to emit the particles
|
|
29
|
+
* @param {Number|Vector2} [emitSize=0] - World space size of the emitter (float for circle diameter, vec2 for rect)
|
|
30
|
+
* @param {Number} [emitTime=0] - How long to stay alive (0 is forever)
|
|
31
|
+
* @param {Number} [emitRate=100] - How many particles per second to spawn, does not emit if 0
|
|
32
32
|
* @param {Number} [emitConeAngle=PI] - Local angle to apply velocity to particles from emitter
|
|
33
|
-
* @param {TileInfo} [tileInfo]
|
|
33
|
+
* @param {TileInfo} [tileInfo] - Tile info to render particles (undefined is untextured)
|
|
34
34
|
* @param {Color} [colorStartA=Color()] - Color at start of life 1, randomized between start colors
|
|
35
35
|
* @param {Color} [colorStartB=Color()] - Color at start of life 2, randomized between start colors
|
|
36
36
|
* @param {Color} [colorEndA=Color(1,1,1,0)] - Color at end of life 1, randomized between end colors
|
|
@@ -86,7 +86,7 @@ class ParticleEmitter extends EngineObject
|
|
|
86
86
|
super(pos, vec2(), tileInfo, angle, undefined, renderOrder);
|
|
87
87
|
|
|
88
88
|
// emitter settings
|
|
89
|
-
/** @property {Number} - World space size of the emitter (float for circle diameter, vec2 for rect) */
|
|
89
|
+
/** @property {Number|Vector2} - World space size of the emitter (float for circle diameter, vec2 for rect) */
|
|
90
90
|
this.emitSize = emitSize
|
|
91
91
|
/** @property {Number} - How long to stay alive (0 is forever) */
|
|
92
92
|
this.emitTime = emitTime;
|
package/src/engineSettings.js
CHANGED
|
@@ -49,6 +49,12 @@ let canvasPixelated = 1;
|
|
|
49
49
|
* @memberof Settings */
|
|
50
50
|
let fontDefault = 'arial';
|
|
51
51
|
|
|
52
|
+
/** Enable to show the LittleJS splash screen be shown on startup
|
|
53
|
+
* @type {Boolean}
|
|
54
|
+
* @default
|
|
55
|
+
* @memberof Settings */
|
|
56
|
+
let showSplashScreen = 0;
|
|
57
|
+
|
|
52
58
|
///////////////////////////////////////////////////////////////////////////////
|
|
53
59
|
// WebGL settings
|
|
54
60
|
|
|
@@ -282,6 +288,11 @@ function setCanvasPixelated(pixelated) { canvasPixelated = pixelated; }
|
|
|
282
288
|
* @memberof Settings */
|
|
283
289
|
function setFontDefault(font) { fontDefault = font; }
|
|
284
290
|
|
|
291
|
+
/** Set if the LittleJS splash screen be shown on startup
|
|
292
|
+
* @param {Boolean} show
|
|
293
|
+
* @memberof Settings */
|
|
294
|
+
function setShowSplashScreen(show) { showSplashScreen = show; }
|
|
295
|
+
|
|
285
296
|
/** Set if webgl rendering is enabled
|
|
286
297
|
* @param {Boolean} enable
|
|
287
298
|
* @memberof Settings */
|