littlejsengine 1.1.6 → 1.1.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/docs/Audio.html +2268 -0
- package/docs/Color.html +2989 -0
- package/docs/Debug.html +2933 -0
- package/docs/Draw.html +4092 -0
- package/docs/EngineObject.html +4458 -0
- package/docs/Input.html +2482 -0
- package/docs/Medal.html +1007 -0
- package/docs/Medals.html +628 -0
- package/docs/Music.html +584 -0
- package/docs/Newgrounds.html +1399 -0
- package/docs/Particle.html +4535 -0
- package/docs/ParticleEmitter.html +7770 -0
- package/docs/Random.html +1774 -0
- package/docs/Settings.html +2679 -0
- package/docs/Sound.html +1249 -0
- package/docs/TileCollision.html +1409 -0
- package/docs/TileLayer.html +6948 -0
- package/docs/TileLayerData.html +1052 -0
- package/docs/Timer.html +1183 -0
- package/docs/Utilities.html +3281 -0
- package/docs/Vector2.html +4207 -0
- package/docs/WebGL.html +2327 -0
- package/docs/engine.js.html +429 -0
- package/docs/engineAudio.js.html +609 -0
- package/docs/engineDebug.js.html +725 -0
- package/docs/engineDraw.js.html +419 -0
- package/docs/engineInput.js.html +401 -0
- package/docs/engineMedals.js.html +461 -0
- package/docs/engineObject.js.html +518 -0
- package/docs/engineParticles.js.html +441 -0
- package/docs/engineSettings.js.html +349 -0
- package/docs/engineTileLayer.js.html +513 -0
- package/docs/engineUtilities.js.html +647 -0
- package/docs/engineWebGL.js.html +522 -0
- package/docs/fonts/MavenPro-Regular.ttf +0 -0
- package/docs/fonts/Montserrat-Regular.ttf +0 -0
- package/docs/fonts/Muli-Black.ttf +0 -0
- package/docs/fonts/OFL-hind.txt +93 -0
- package/docs/fonts/OFL-montserrat.txt +93 -0
- package/docs/global.html +1691 -0
- package/docs/index.css +6 -0
- package/docs/index.html +247 -0
- package/docs/scripts/fix-code-block.js +53 -0
- package/docs/scripts/fix-navbar.js +25 -0
- package/docs/scripts/linenumber.js +25 -0
- package/docs/scripts/misc.js +217 -0
- package/docs/scripts/resize.js +85 -0
- package/docs/scripts/search.js +83 -0
- package/docs/scripts/third-party/Apache-License-2.0.txt +202 -0
- package/docs/scripts/third-party/fuse.js +9 -0
- package/docs/scripts/third-party/lang-css.js +2 -0
- package/docs/scripts/third-party/prettify.js +28 -0
- package/docs/static/favicon.png +0 -0
- package/docs/static/index.css +4 -0
- package/docs/styles/clean-jsdoc-theme-base.css +393 -0
- package/docs/styles/clean-jsdoc-theme-dark.css +324 -0
- package/docs/styles/clean-jsdoc-theme-light.css +319 -0
- package/docs/styles/reset.css +346 -0
- package/docs/styles/third-party/ionicons.min.css +11 -0
- package/docs/styles/third-party/prettify-jsdoc.css +111 -0
- package/docs/styles/third-party/prettify-tomorrow.css +5 -0
- package/engine/engine.all.js +94 -110
- package/engine/engine.all.min.js +1 -1
- package/engine/engine.all.release.js +94 -110
- package/engine/engine.js +14 -17
- package/engine/engineAudio.js +7 -7
- package/engine/engineDraw.js +6 -6
- package/engine/engineInput.js +7 -7
- package/engine/engineMedals.js +3 -3
- package/engine/engineObject.js +15 -15
- package/engine/engineParticles.js +3 -3
- package/engine/engineSettings.js +30 -43
- package/engine/engineTileLayer.js +5 -5
- package/engine/engineUtilities.js +4 -4
- package/examples/breakout/game.js +1 -1
- package/examples/breakout/gameObjects.js +1 -1
- package/examples/breakout/index.html +3 -3
- package/examples/platformer/gameObjects.js +1 -1
- package/examples/platformer/gamePlayer.js +1 -1
- package/examples/platformer/index.html +6 -6
- package/examples/puzzle/game.js +1 -1
- package/examples/puzzle/index.html +2 -2
- package/examples/stress/index.html +1 -1
- package/index.html +13 -13
- package/package.json +1 -1
|
@@ -363,10 +363,10 @@ class Vector2
|
|
|
363
363
|
class Color
|
|
364
364
|
{
|
|
365
365
|
/** Create a color with the components passed in, white by default
|
|
366
|
-
* @param {Number} [
|
|
367
|
-
* @param {Number} [
|
|
368
|
-
* @param {Number} [
|
|
369
|
-
* @param {Number} [
|
|
366
|
+
* @param {Number} [red=1]
|
|
367
|
+
* @param {Number} [green=1]
|
|
368
|
+
* @param {Number} [blue=1]
|
|
369
|
+
* @param {Number} [alpha=1] */
|
|
370
370
|
constructor(r=1, g=1, b=1, a=1)
|
|
371
371
|
{
|
|
372
372
|
/** @property {Number} - Red */
|
|
@@ -526,35 +526,27 @@ class Timer
|
|
|
526
526
|
///////////////////////////////////////////////////////////////////////////////
|
|
527
527
|
// Display settings
|
|
528
528
|
|
|
529
|
-
/** The max
|
|
530
|
-
* @
|
|
531
|
-
* @memberof Settings */
|
|
532
|
-
const maxWidth = 1920;
|
|
533
|
-
|
|
534
|
-
/** The max height of the canvas, centered if window is larger
|
|
535
|
-
* @default
|
|
536
|
-
* @memberof Settings */
|
|
537
|
-
const maxHeight = 1200; // up to 1080p and 16:10
|
|
538
|
-
|
|
539
|
-
/** Fixed witdh, if enabled cavnvas size never changes
|
|
529
|
+
/** The max size of the canvas, centered if window is larger
|
|
530
|
+
* @type {Vector2}
|
|
540
531
|
* @default
|
|
541
532
|
* @memberof Settings */
|
|
542
|
-
|
|
533
|
+
const maxSize = vec2(1920, 1200);
|
|
543
534
|
|
|
544
|
-
/** Fixed
|
|
535
|
+
/** Fixed size of the canvas, if enabled cavnvas size never changes
|
|
536
|
+
* @type {Vector2}
|
|
545
537
|
* @default
|
|
546
538
|
* @memberof Settings */
|
|
547
|
-
let
|
|
539
|
+
let fixedSize = vec2();
|
|
548
540
|
|
|
549
|
-
/**
|
|
541
|
+
/** Default font used for text rendering
|
|
550
542
|
* @default
|
|
551
543
|
* @memberof Settings */
|
|
552
|
-
let
|
|
544
|
+
let fontDefault = 'arial';
|
|
553
545
|
|
|
554
|
-
/**
|
|
546
|
+
/** Use crisp pixels for pixel art if true
|
|
555
547
|
* @default
|
|
556
548
|
* @memberof Settings */
|
|
557
|
-
let
|
|
549
|
+
let pixelated = 1;
|
|
558
550
|
|
|
559
551
|
///////////////////////////////////////////////////////////////////////////////
|
|
560
552
|
// Tile sheet settings
|
|
@@ -563,18 +555,13 @@ let defaultFont = 'arial';
|
|
|
563
555
|
* @type {Vector2}
|
|
564
556
|
* @default
|
|
565
557
|
* @memberof Settings */
|
|
566
|
-
const
|
|
558
|
+
const tileSizeDefault = vec2(16);
|
|
567
559
|
|
|
568
560
|
/** Prevent tile bleeding from neighbors in pixels
|
|
569
561
|
* @default
|
|
570
562
|
* @memberof Settings */
|
|
571
563
|
const tileBleedShrinkFix = .3;
|
|
572
564
|
|
|
573
|
-
/** Use crisp pixels for pixel art if true
|
|
574
|
-
* @default
|
|
575
|
-
* @memberof Settings */
|
|
576
|
-
let pixelated = 1;
|
|
577
|
-
|
|
578
565
|
///////////////////////////////////////////////////////////////////////////////
|
|
579
566
|
// Object settings
|
|
580
567
|
|
|
@@ -582,37 +569,37 @@ let pixelated = 1;
|
|
|
582
569
|
* @type {Vector2}
|
|
583
570
|
* @default
|
|
584
571
|
* @memberof Settings */
|
|
585
|
-
const
|
|
572
|
+
const objectDefaultSize = vec2(1);
|
|
586
573
|
|
|
587
574
|
/** Default object mass for collison calcuations (how heavy objects are)
|
|
588
575
|
* @default
|
|
589
576
|
* @memberof Settings */
|
|
590
|
-
const
|
|
577
|
+
const objectDefaultMass = 1;
|
|
591
578
|
|
|
592
579
|
/** How much to slow velocity by each frame (0-1)
|
|
593
580
|
* @default
|
|
594
581
|
* @memberof Settings */
|
|
595
|
-
const
|
|
582
|
+
const objectDefaultDamping = .99;
|
|
596
583
|
|
|
597
584
|
/** How much to slow angular velocity each frame (0-1)
|
|
598
585
|
* @default
|
|
599
586
|
* @memberof Settings */
|
|
600
|
-
const
|
|
587
|
+
const objectDefaultAngleDamping = .99;
|
|
601
588
|
|
|
602
589
|
/** How much to bounce when a collision occurs (0-1)
|
|
603
590
|
* @default
|
|
604
591
|
* @memberof Settings */
|
|
605
|
-
const
|
|
592
|
+
const objectDefaultElasticity = 0;
|
|
606
593
|
|
|
607
594
|
/** How much to slow when touching (0-1)
|
|
608
595
|
* @default
|
|
609
596
|
* @memberof Settings */
|
|
610
|
-
const
|
|
597
|
+
const objectDefaultFriction = .8;
|
|
611
598
|
|
|
612
599
|
/** Clamp max speed to avoid fast objects missing collisions
|
|
613
600
|
* @default
|
|
614
601
|
* @memberof Settings */
|
|
615
|
-
const
|
|
602
|
+
const objectMaxSpeed = 1;
|
|
616
603
|
|
|
617
604
|
/** How much gravity to apply to objects along the Y axis, negative is down
|
|
618
605
|
* @default
|
|
@@ -631,7 +618,7 @@ let cameraPos = vec2();
|
|
|
631
618
|
/** Scale of camera in world space
|
|
632
619
|
* @default
|
|
633
620
|
* @memberof Settings */
|
|
634
|
-
let cameraScale = max(
|
|
621
|
+
let cameraScale = max(tileSizeDefault.x, tileSizeDefault.y);
|
|
635
622
|
|
|
636
623
|
///////////////////////////////////////////////////////////////////////////////
|
|
637
624
|
// WebGL settings
|
|
@@ -654,43 +641,43 @@ let glOverlay = 1;
|
|
|
654
641
|
* @memberof Settings */
|
|
655
642
|
const gamepadsEnable = 1;
|
|
656
643
|
|
|
657
|
-
/** If true
|
|
644
|
+
/** If true, the dpad input is also routed to the left analog stick (for better accessability)
|
|
658
645
|
* @default
|
|
659
646
|
* @memberof Settings */
|
|
660
|
-
const
|
|
647
|
+
const gamepadDirectionEmulateStick = 1;
|
|
661
648
|
|
|
662
|
-
/** If true
|
|
649
|
+
/** If true touch input is routed to mouse functions
|
|
663
650
|
* @default
|
|
664
651
|
* @memberof Settings */
|
|
665
|
-
const
|
|
652
|
+
const inputTouchEnable = 1;
|
|
666
653
|
|
|
667
654
|
/** If true the WASD keys are also routed to the direction keys (for better accessability)
|
|
668
655
|
* @default
|
|
669
656
|
* @memberof Settings */
|
|
670
|
-
const
|
|
657
|
+
const inputWASDEmulateDirection = 1;
|
|
671
658
|
|
|
672
659
|
///////////////////////////////////////////////////////////////////////////////
|
|
673
660
|
// Audio settings
|
|
674
661
|
|
|
675
|
-
/**
|
|
662
|
+
/** Volume scale to apply to all sound, music and speech
|
|
676
663
|
* @default
|
|
677
664
|
* @memberof Settings */
|
|
678
|
-
|
|
665
|
+
let soundVolume = .5;
|
|
679
666
|
|
|
680
|
-
/**
|
|
667
|
+
/** All audio code can be disabled and removed from build
|
|
681
668
|
* @default
|
|
682
669
|
* @memberof Settings */
|
|
683
|
-
|
|
670
|
+
const soundEnable = 1;
|
|
684
671
|
|
|
685
672
|
/** Default range where sound no longer plays
|
|
686
673
|
* @default
|
|
687
674
|
* @memberof Settings */
|
|
688
|
-
const
|
|
675
|
+
const soundDefaultRange = 30;
|
|
689
676
|
|
|
690
677
|
/** Default range percent to start tapering off sound (0-1)
|
|
691
678
|
* @default
|
|
692
679
|
* @memberof Settings */
|
|
693
|
-
const
|
|
680
|
+
const soundDefaultTaper = .7;
|
|
694
681
|
|
|
695
682
|
///////////////////////////////////////////////////////////////////////////////
|
|
696
683
|
// Medals settings
|
|
@@ -743,7 +730,7 @@ const medalDisplayIconSize = 80;
|
|
|
743
730
|
const engineName = 'LittleJS';
|
|
744
731
|
|
|
745
732
|
/** Version of engine */
|
|
746
|
-
const engineVersion = '1.1.
|
|
733
|
+
const engineVersion = '1.1.8';
|
|
747
734
|
|
|
748
735
|
/** Frames per second to update objects
|
|
749
736
|
* @default */
|
|
@@ -868,31 +855,28 @@ function engineInit(gameInit, gameUpdate, gameUpdatePost, gameRender, gameRender
|
|
|
868
855
|
frameTimeBufferMS += deltaSmooth;
|
|
869
856
|
}
|
|
870
857
|
|
|
871
|
-
if (
|
|
858
|
+
if (fixedSize.x)
|
|
872
859
|
{
|
|
873
860
|
// clear set fixed size
|
|
874
|
-
mainCanvas.width =
|
|
875
|
-
mainCanvas.height =
|
|
861
|
+
mainCanvas.width = fixedSize.x;
|
|
862
|
+
mainCanvas.height = fixedSize.y;
|
|
876
863
|
|
|
877
|
-
if
|
|
864
|
+
// fit to window by adding space on top or bottom if necessary
|
|
865
|
+
const aspect = innerWidth / innerHeight;
|
|
866
|
+
const fixedAspect = mainCanvas.width / mainCanvas.height;
|
|
867
|
+
mainCanvas.style.width = overlayCanvas.style.width = aspect < fixedAspect ? '100%' : '';
|
|
868
|
+
mainCanvas.style.height = overlayCanvas.style.height = aspect < fixedAspect ? '' : '100%';
|
|
869
|
+
if (glCanvas)
|
|
878
870
|
{
|
|
879
|
-
|
|
880
|
-
|
|
881
|
-
const fixedAspect = fixedWidth / fixedHeight;
|
|
882
|
-
mainCanvas.style.width = overlayCanvas.style.width = aspect < fixedAspect ? '100%' : '';
|
|
883
|
-
mainCanvas.style.height = overlayCanvas.style.height = aspect < fixedAspect ? '' : '100%';
|
|
884
|
-
if (glCanvas)
|
|
885
|
-
{
|
|
886
|
-
glCanvas.style.width = mainCanvas.style.width;
|
|
887
|
-
glCanvas.style.height = mainCanvas.style.height;
|
|
888
|
-
}
|
|
871
|
+
glCanvas.style.width = mainCanvas.style.width;
|
|
872
|
+
glCanvas.style.height = mainCanvas.style.height;
|
|
889
873
|
}
|
|
890
874
|
}
|
|
891
875
|
else
|
|
892
876
|
{
|
|
893
877
|
// clear and set size to same as window
|
|
894
|
-
mainCanvas.width = min(innerWidth,
|
|
895
|
-
mainCanvas.height = min(innerHeight,
|
|
878
|
+
mainCanvas.width = min(innerWidth, maxSize.x);
|
|
879
|
+
mainCanvas.height = min(innerHeight, maxSize.y);
|
|
896
880
|
}
|
|
897
881
|
|
|
898
882
|
// save canvas size and clear overlay canvas
|
|
@@ -1019,14 +1003,14 @@ class EngineObject
|
|
|
1019
1003
|
{
|
|
1020
1004
|
/** Create an engine object and adds it to the list of objects
|
|
1021
1005
|
* @param {Vector2} [position=new Vector2(0,0)] - World space position of the object
|
|
1022
|
-
* @param {Vector2} [size=
|
|
1006
|
+
* @param {Vector2} [size=objectDefaultSize] - World space size of the object
|
|
1023
1007
|
* @param {Number} [tileIndex=-1] - Tile to use to render object, untextured if -1
|
|
1024
|
-
* @param {Vector2} [tileSize=
|
|
1008
|
+
* @param {Vector2} [tileSize=tileSizeDefault] - Size of tile in source pixels
|
|
1025
1009
|
* @param {Number} [angle=0] - Angle to rotate the object
|
|
1026
1010
|
* @param {Color} [color] - Color to apply to tile when rendered
|
|
1027
1011
|
* @param {Number} [renderOrder=0] - Objects sorted by renderOrder before being rendered
|
|
1028
1012
|
*/
|
|
1029
|
-
constructor(pos=vec2(), size=
|
|
1013
|
+
constructor(pos=vec2(), size=objectDefaultSize, tileIndex=-1, tileSize=tileSizeDefault, angle=0, color, renderOrder=0)
|
|
1030
1014
|
{
|
|
1031
1015
|
// set passed in params
|
|
1032
1016
|
ASSERT(pos && pos.x != undefined && size.x != undefined); // ensure pos and size are vec2s
|
|
@@ -1049,16 +1033,16 @@ class EngineObject
|
|
|
1049
1033
|
this.additiveColor;
|
|
1050
1034
|
|
|
1051
1035
|
// set object defaults
|
|
1052
|
-
/** @property {Number} [mass=
|
|
1053
|
-
this.mass =
|
|
1054
|
-
/** @property {Number} [damping=
|
|
1055
|
-
this.damping =
|
|
1056
|
-
/** @property {Number} [angleDamping=
|
|
1057
|
-
this.angleDamping =
|
|
1058
|
-
/** @property {Number} [elasticity=
|
|
1059
|
-
this.elasticity =
|
|
1060
|
-
/** @property {Number} [friction=
|
|
1061
|
-
this.friction =
|
|
1036
|
+
/** @property {Number} [mass=objectDefaultMass] - How heavy the object is */
|
|
1037
|
+
this.mass = objectDefaultMass;
|
|
1038
|
+
/** @property {Number} [damping=objectDefaultDamping] - How much to slow down velocity each frame (0-1) */
|
|
1039
|
+
this.damping = objectDefaultDamping;
|
|
1040
|
+
/** @property {Number} [angleDamping=objectDefaultAngleDamping] - How much to slow down rotation each frame (0-1) */
|
|
1041
|
+
this.angleDamping = objectDefaultAngleDamping;
|
|
1042
|
+
/** @property {Number} [elasticity=objectDefaultElasticity] - How bouncy the object is when colliding (0-1) */
|
|
1043
|
+
this.elasticity = objectDefaultElasticity;
|
|
1044
|
+
/** @property {Number} [friction=objectDefaultFriction] - How much friction to apply when sliding (0-1) */
|
|
1045
|
+
this.friction = objectDefaultFriction;
|
|
1062
1046
|
/** @property {Number} [gravityScale=1] - How much to scale gravity by for this object */
|
|
1063
1047
|
this.gravityScale = 1;
|
|
1064
1048
|
/** @property {Number} [renderOrder=0] - Objects are sorted by render order */
|
|
@@ -1087,8 +1071,8 @@ class EngineObject
|
|
|
1087
1071
|
}
|
|
1088
1072
|
|
|
1089
1073
|
// limit max speed to prevent missing collisions
|
|
1090
|
-
this.velocity.x = clamp(this.velocity.x,
|
|
1091
|
-
this.velocity.y = clamp(this.velocity.y,
|
|
1074
|
+
this.velocity.x = clamp(this.velocity.x, objectMaxSpeed, -objectMaxSpeed);
|
|
1075
|
+
this.velocity.y = clamp(this.velocity.y, objectMaxSpeed, -objectMaxSpeed);
|
|
1092
1076
|
|
|
1093
1077
|
// apply physics
|
|
1094
1078
|
const oldPos = this.pos.copy();
|
|
@@ -1410,14 +1394,14 @@ const worldToScreen = (worldPos)=>
|
|
|
1410
1394
|
* @param {Vector2} pos - Center of the tile in world space
|
|
1411
1395
|
* @param {Vector2} [size=new Vector2(1,1)] - Size of the tile in world space, width and height
|
|
1412
1396
|
* @param {Number} [tileIndex=-1] - Tile index to use, negative is untextured
|
|
1413
|
-
* @param {Vector2} [tileSize=
|
|
1397
|
+
* @param {Vector2} [tileSize=tileSizeDefault] - Tile size in source pixels
|
|
1414
1398
|
* @param {Color} [color=new Color(1,1,1)] - Color to modulate with
|
|
1415
1399
|
* @param {Number} [angle=0] - Angle to rotate by
|
|
1416
1400
|
* @param {Boolean} [mirror=0] - If true image is flipped along the Y axis
|
|
1417
1401
|
* @param {Color} [additiveColor=new Color(0,0,0,0)] - Additive color to be applied
|
|
1418
1402
|
* @param {Boolean} [useWebGL=glEnable] - Use accelerated WebGL rendering
|
|
1419
1403
|
* @memberof Draw */
|
|
1420
|
-
function drawTile(pos, size=vec2(1), tileIndex=-1, tileSize=
|
|
1404
|
+
function drawTile(pos, size=vec2(1), tileIndex=-1, tileSize=tileSizeDefault, color=new Color, angle=0, mirror,
|
|
1421
1405
|
additiveColor=new Color(0,0,0,0), useWebGL=glEnable)
|
|
1422
1406
|
{
|
|
1423
1407
|
showWatermark && ++drawCount;
|
|
@@ -1481,14 +1465,14 @@ function drawTile(pos, size=vec2(1), tileIndex=-1, tileSize=defaultTileSize, col
|
|
|
1481
1465
|
* @memberof Draw */
|
|
1482
1466
|
function drawRect(pos, size, color, angle, useWebGL)
|
|
1483
1467
|
{
|
|
1484
|
-
drawTile(pos, size, -1,
|
|
1468
|
+
drawTile(pos, size, -1, tileSizeDefault, color, angle, 0, 0, useWebGL);
|
|
1485
1469
|
}
|
|
1486
1470
|
|
|
1487
1471
|
/** Draw textured tile centered on pos in screen space
|
|
1488
1472
|
* @param {Vector2} pos - Center of the tile
|
|
1489
1473
|
* @param {Vector2} [size=new Vector2(1,1)] - Size of the tile
|
|
1490
1474
|
* @param {Number} [tileIndex=-1] - Tile index to use, negative is untextured
|
|
1491
|
-
* @param {Vector2} [tileSize=
|
|
1475
|
+
* @param {Vector2} [tileSize=tileSizeDefault] - Tile size in source pixels
|
|
1492
1476
|
* @param {Color} [color=new Color]
|
|
1493
1477
|
* @param {Number} [angle=0]
|
|
1494
1478
|
* @param {Boolean} [mirror=0]
|
|
@@ -1509,7 +1493,7 @@ function drawTileScreenSpace(pos, size=vec2(1), tileIndex, tileSize, color, angl
|
|
|
1509
1493
|
* @memberof Draw */
|
|
1510
1494
|
function drawRectScreenSpace(pos, size, color, angle, useWebGL)
|
|
1511
1495
|
{
|
|
1512
|
-
drawTileSrceenSpace(pos, size, -1,
|
|
1496
|
+
drawTileSrceenSpace(pos, size, -1, tileSizeDefault, color, angle, 0, 0, useWebGL);
|
|
1513
1497
|
}
|
|
1514
1498
|
|
|
1515
1499
|
/** Draw colored line between two points
|
|
@@ -1556,7 +1540,7 @@ function drawCanvas2D(pos, size, angle, mirror, drawFunction, context = mainCont
|
|
|
1556
1540
|
* @param {Color} [lineColor=new Color(0,0,0)]
|
|
1557
1541
|
* @param {String} [textAlign='center']
|
|
1558
1542
|
* @memberof Draw */
|
|
1559
|
-
function drawText(text, pos, size=1, color=new Color, lineWidth=0, lineColor=new Color(0,0,0), textAlign='center', font=
|
|
1543
|
+
function drawText(text, pos, size=1, color=new Color, lineWidth=0, lineColor=new Color(0,0,0), textAlign='center', font=fontDefault)
|
|
1560
1544
|
{
|
|
1561
1545
|
pos = worldToScreen(pos);
|
|
1562
1546
|
overlayContext.font = size*cameraScale + 'px '+ font;
|
|
@@ -1680,7 +1664,7 @@ let mouseWheel = 0;
|
|
|
1680
1664
|
|
|
1681
1665
|
/** Returns true if user is using gamepad (has more recently pressed a gamepad button)
|
|
1682
1666
|
* @memberof Input */
|
|
1683
|
-
let
|
|
1667
|
+
let isUsingGamepad = 0;
|
|
1684
1668
|
|
|
1685
1669
|
/** Returns true if gamepad button is down
|
|
1686
1670
|
* @param {Number} button
|
|
@@ -1742,7 +1726,7 @@ function inputUpdatePost()
|
|
|
1742
1726
|
onkeydown = e=>
|
|
1743
1727
|
{
|
|
1744
1728
|
if (debug && e.target != document.body) return;
|
|
1745
|
-
e.repeat || (inputData[
|
|
1729
|
+
e.repeat || (inputData[isUsingGamepad = 0][remapKeyCode(e.keyCode)] = 3);
|
|
1746
1730
|
debug || e.preventDefault();
|
|
1747
1731
|
}
|
|
1748
1732
|
onkeyup = e=>
|
|
@@ -1750,12 +1734,12 @@ onkeyup = e=>
|
|
|
1750
1734
|
if (debug && e.target != document.body) return;
|
|
1751
1735
|
inputData[0][remapKeyCode(e.keyCode)] = 4;
|
|
1752
1736
|
}
|
|
1753
|
-
const remapKeyCode = c=>
|
|
1737
|
+
const remapKeyCode = c=> inputWASDEmulateDirection ? c==87?38 : c==83?40 : c==65?37 : c==68?39 : c : c;
|
|
1754
1738
|
|
|
1755
1739
|
///////////////////////////////////////////////////////////////////////////////
|
|
1756
1740
|
// Mouse event handlers
|
|
1757
1741
|
|
|
1758
|
-
onmousedown = e=> {inputData[
|
|
1742
|
+
onmousedown = e=> {inputData[isUsingGamepad = 0][e.button] = 3; onmousemove(e); e.button && e.preventDefault();}
|
|
1759
1743
|
onmouseup = e=> inputData[0][e.button] = inputData[0][e.button] & 2 | 4;
|
|
1760
1744
|
onmousemove = e=>
|
|
1761
1745
|
{
|
|
@@ -1803,10 +1787,10 @@ function gamepadsUpdate()
|
|
|
1803
1787
|
{
|
|
1804
1788
|
const button = gamepad.buttons[j];
|
|
1805
1789
|
data[j] = button.pressed ? 1 + 2*!gamepadIsDown(j,i) : 4*gamepadIsDown(j,i);
|
|
1806
|
-
|
|
1790
|
+
isUsingGamepad |= !i && button.pressed;
|
|
1807
1791
|
}
|
|
1808
1792
|
|
|
1809
|
-
if (
|
|
1793
|
+
if (gamepadDirectionEmulateStick)
|
|
1810
1794
|
{
|
|
1811
1795
|
// copy dpad to left analog stick when pressed
|
|
1812
1796
|
const dpad = vec2(gamepadIsDown(15,i) - gamepadIsDown(14,i), gamepadIsDown(12,i) - gamepadIsDown(13,i));
|
|
@@ -1823,7 +1807,7 @@ function gamepadsUpdate()
|
|
|
1823
1807
|
/** True if a touch device has been detected
|
|
1824
1808
|
* @const {boolean}
|
|
1825
1809
|
* @memberof Input */
|
|
1826
|
-
const isTouchDevice =
|
|
1810
|
+
const isTouchDevice = inputTouchEnable && window.ontouchstart !== undefined;
|
|
1827
1811
|
if (isTouchDevice)
|
|
1828
1812
|
{
|
|
1829
1813
|
// handle all touch events the same way
|
|
@@ -1878,10 +1862,10 @@ class Sound
|
|
|
1878
1862
|
{
|
|
1879
1863
|
/** Create a sound object and cache the zzfx samples for later use
|
|
1880
1864
|
* @param {Array} zzfxSound - Array of zzfx parameters, ex. [.5,.5]
|
|
1881
|
-
* @param {Number} [range=
|
|
1882
|
-
* @param {Number} [taper=
|
|
1865
|
+
* @param {Number} [range=soundDefaultRange] - World space max range of sound, will not play if camera is farther away
|
|
1866
|
+
* @param {Number} [taper=soundDefaultTaper] - At what percentage of range should it start tapering off
|
|
1883
1867
|
*/
|
|
1884
|
-
constructor(zzfxSound, range=
|
|
1868
|
+
constructor(zzfxSound, range=soundDefaultRange, taper=soundDefaultTaper)
|
|
1885
1869
|
{
|
|
1886
1870
|
if (!soundEnable) return;
|
|
1887
1871
|
|
|
@@ -2012,7 +1996,7 @@ function playAudioFile(url, volume=1, loop=1)
|
|
|
2012
1996
|
if (!soundEnable) return;
|
|
2013
1997
|
|
|
2014
1998
|
const audio = new Audio(url);
|
|
2015
|
-
audio.volume =
|
|
1999
|
+
audio.volume = soundVolume * volume;
|
|
2016
2000
|
audio.loop = loop;
|
|
2017
2001
|
audio.play();
|
|
2018
2002
|
return audio;
|
|
@@ -2037,7 +2021,7 @@ function speak(text, language='', volume=1, rate=1, pitch=1)
|
|
|
2037
2021
|
// build utterance and speak
|
|
2038
2022
|
const utterance = new SpeechSynthesisUtterance(text);
|
|
2039
2023
|
utterance.lang = language;
|
|
2040
|
-
utterance.volume = 2*volume*
|
|
2024
|
+
utterance.volume = 2*volume*soundVolume;
|
|
2041
2025
|
utterance.rate = rate;
|
|
2042
2026
|
utterance.pitch = pitch;
|
|
2043
2027
|
speechSynthesis.speak(utterance);
|
|
@@ -2090,7 +2074,7 @@ function playSamples(sampleChannels, volume=1, rate=1, pan=0, loop=0)
|
|
|
2090
2074
|
// create pan and gain nodes
|
|
2091
2075
|
source
|
|
2092
2076
|
.connect(new StereoPannerNode(audioContext, {'pan':clamp(pan, 1, -1)}))
|
|
2093
|
-
.connect(new GainNode(audioContext, {'gain':
|
|
2077
|
+
.connect(new GainNode(audioContext, {'gain':soundVolume*volume}))
|
|
2094
2078
|
.connect(audioContext.destination);
|
|
2095
2079
|
|
|
2096
2080
|
// play and return sound
|
|
@@ -2158,7 +2142,7 @@ function zzfxG
|
|
|
2158
2142
|
1 - tremolo + tremolo*Math.sin(PI2*i/repeatTime) // tremolo
|
|
2159
2143
|
: 1) *
|
|
2160
2144
|
sign(s)*(abs(s)**shapeCurve) * // curve 0=square, 2=pointy
|
|
2161
|
-
volume *
|
|
2145
|
+
volume * soundVolume * ( // envelope
|
|
2162
2146
|
i < attack ? i/attack : // attack
|
|
2163
2147
|
i < attack + decay ? // decay
|
|
2164
2148
|
1-((i-attack)/decay)*(1-sustainVolume) : // decay falloff
|
|
@@ -2461,12 +2445,12 @@ class TileLayer extends EngineObject
|
|
|
2461
2445
|
{
|
|
2462
2446
|
/** Create a tile layer object
|
|
2463
2447
|
* @param {Vector2} [position=new Vector2(0,0)] - World space position
|
|
2464
|
-
* @param {Vector2} [size=
|
|
2465
|
-
* @param {Vector2} [tileSize=
|
|
2448
|
+
* @param {Vector2} [size=objectDefaultSize] - World space size
|
|
2449
|
+
* @param {Vector2} [tileSize=tileSizeDefault] - Size of tiles in source pixels
|
|
2466
2450
|
* @param {Vector2} [scale=new Vector2(1,1)] - How much to scale this layer when rendered
|
|
2467
2451
|
* @param {Number} [renderOrder=0] - Objects sorted by renderOrder before being rendered
|
|
2468
2452
|
*/
|
|
2469
|
-
constructor(pos, size=tileCollisionSize, tileSize=
|
|
2453
|
+
constructor(pos, size=tileCollisionSize, tileSize=tileSizeDefault, scale=vec2(1), renderOrder=0)
|
|
2470
2454
|
{
|
|
2471
2455
|
super(pos, size, -1, tileSize, 0, undefined, renderOrder);
|
|
2472
2456
|
|
|
@@ -2625,11 +2609,11 @@ class TileLayer extends EngineObject
|
|
|
2625
2609
|
* @param {Vector2} pos
|
|
2626
2610
|
* @param {Vector2} [size=new Vector2(1,1)]
|
|
2627
2611
|
* @param {Number} [tileIndex=-1]
|
|
2628
|
-
* @param {Vector2} [tileSize=
|
|
2612
|
+
* @param {Vector2} [tileSize=tileSizeDefault]
|
|
2629
2613
|
* @param {Color} [color=new Color(1,1,1)]
|
|
2630
2614
|
* @param {Number} [angle=0]
|
|
2631
2615
|
* @param {Boolean} [mirror=0] */
|
|
2632
|
-
drawTile(pos, size=vec2(1), tileIndex=-1, tileSize=
|
|
2616
|
+
drawTile(pos, size=vec2(1), tileIndex=-1, tileSize=tileSizeDefault, color=new Color, angle=0, mirror)
|
|
2633
2617
|
{
|
|
2634
2618
|
this.drawCanvas2D(pos, size, angle, mirror, (context)=>
|
|
2635
2619
|
{
|
|
@@ -2692,7 +2676,7 @@ class ParticleEmitter extends EngineObject
|
|
|
2692
2676
|
* @param {Number} [emitRate=100] - How many particles per second to spawn, does not emit if 0
|
|
2693
2677
|
* @param {Number} [emitConeAngle=PI] - Local angle to apply velocity to particles from emitter
|
|
2694
2678
|
* @param {Number} [tileIndex=-1] - Index into tile sheet, if <0 no texture is applied
|
|
2695
|
-
* @param {Number} [tileSize=
|
|
2679
|
+
* @param {Number} [tileSize=tileSizeDefault] - Tile size for particles
|
|
2696
2680
|
* @param {Color} [colorStartA=new Color(1,1,1)] - Color at start of life 1, randomized between start colors
|
|
2697
2681
|
* @param {Color} [colorStartB=new Color(1,1,1)] - Color at start of life 2, randomized between start colors
|
|
2698
2682
|
* @param {Color} [colorEndA=new Color(1,1,1,0)] - Color at end of life 1, randomized between end colors
|
|
@@ -2721,7 +2705,7 @@ class ParticleEmitter extends EngineObject
|
|
|
2721
2705
|
emitRate = 100,
|
|
2722
2706
|
emitConeAngle = PI,
|
|
2723
2707
|
tileIndex = -1,
|
|
2724
|
-
tileSize =
|
|
2708
|
+
tileSize = tileSizeDefault,
|
|
2725
2709
|
colorStartA = new Color,
|
|
2726
2710
|
colorStartB = new Color,
|
|
2727
2711
|
colorEndA = new Color(1,1,1,0),
|
|
@@ -2892,7 +2876,7 @@ class Particle extends EngineObject
|
|
|
2892
2876
|
* Create a particle with the given settings
|
|
2893
2877
|
* @param {Vector2} position - World space position of the particle
|
|
2894
2878
|
* @param {Number} [tileIndex=-1] - Tile to use to render, untextured if -1
|
|
2895
|
-
* @param {Vector2} [tileSize=
|
|
2879
|
+
* @param {Vector2} [tileSize=tileSizeDefault] - Size of tile in source pixels
|
|
2896
2880
|
* @param {Number} [angle=0] - Angle to rotate the particle
|
|
2897
2881
|
*/
|
|
2898
2882
|
constructor(pos, tileIndex, tileSize, angle) { super(pos, new Vector2, tileIndex, tileSize, angle); }
|
|
@@ -3054,9 +3038,9 @@ class Medal
|
|
|
3054
3038
|
|
|
3055
3039
|
// draw the text
|
|
3056
3040
|
context.textAlign = 'left';
|
|
3057
|
-
context.font = '3em '+
|
|
3041
|
+
context.font = '3em '+ fontDefault;
|
|
3058
3042
|
context.fillText(this.name, x+medalDisplayIconSize+25, y+35);
|
|
3059
|
-
context.font = '1.5em '+
|
|
3043
|
+
context.font = '1.5em '+ fontDefault;
|
|
3060
3044
|
context.restore(context.fillText(this.description, x+medalDisplayIconSize+25, y+70));
|
|
3061
3045
|
}
|
|
3062
3046
|
|
|
@@ -3071,7 +3055,7 @@ class Medal
|
|
|
3071
3055
|
const context = overlayContext;
|
|
3072
3056
|
context.textAlign = 'center';
|
|
3073
3057
|
context.textBaseline = 'middle';
|
|
3074
|
-
context.font = size*.6 + 'px '+
|
|
3058
|
+
context.font = size*.6 + 'px '+ fontDefault;
|
|
3075
3059
|
context.fillStyle = '#000';
|
|
3076
3060
|
if (this.image)
|
|
3077
3061
|
context.drawImage(this.image, x-size/2, y-size/2, size, size);
|
package/engine/engine.js
CHANGED
|
@@ -22,7 +22,7 @@
|
|
|
22
22
|
const engineName = 'LittleJS';
|
|
23
23
|
|
|
24
24
|
/** Version of engine */
|
|
25
|
-
const engineVersion = '1.1.
|
|
25
|
+
const engineVersion = '1.1.8';
|
|
26
26
|
|
|
27
27
|
/** Frames per second to update objects
|
|
28
28
|
* @default */
|
|
@@ -147,31 +147,28 @@ function engineInit(gameInit, gameUpdate, gameUpdatePost, gameRender, gameRender
|
|
|
147
147
|
frameTimeBufferMS += deltaSmooth;
|
|
148
148
|
}
|
|
149
149
|
|
|
150
|
-
if (
|
|
150
|
+
if (fixedSize.x)
|
|
151
151
|
{
|
|
152
152
|
// clear set fixed size
|
|
153
|
-
mainCanvas.width =
|
|
154
|
-
mainCanvas.height =
|
|
153
|
+
mainCanvas.width = fixedSize.x;
|
|
154
|
+
mainCanvas.height = fixedSize.y;
|
|
155
155
|
|
|
156
|
-
if
|
|
156
|
+
// fit to window by adding space on top or bottom if necessary
|
|
157
|
+
const aspect = innerWidth / innerHeight;
|
|
158
|
+
const fixedAspect = mainCanvas.width / mainCanvas.height;
|
|
159
|
+
mainCanvas.style.width = overlayCanvas.style.width = aspect < fixedAspect ? '100%' : '';
|
|
160
|
+
mainCanvas.style.height = overlayCanvas.style.height = aspect < fixedAspect ? '' : '100%';
|
|
161
|
+
if (glCanvas)
|
|
157
162
|
{
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
const fixedAspect = fixedWidth / fixedHeight;
|
|
161
|
-
mainCanvas.style.width = overlayCanvas.style.width = aspect < fixedAspect ? '100%' : '';
|
|
162
|
-
mainCanvas.style.height = overlayCanvas.style.height = aspect < fixedAspect ? '' : '100%';
|
|
163
|
-
if (glCanvas)
|
|
164
|
-
{
|
|
165
|
-
glCanvas.style.width = mainCanvas.style.width;
|
|
166
|
-
glCanvas.style.height = mainCanvas.style.height;
|
|
167
|
-
}
|
|
163
|
+
glCanvas.style.width = mainCanvas.style.width;
|
|
164
|
+
glCanvas.style.height = mainCanvas.style.height;
|
|
168
165
|
}
|
|
169
166
|
}
|
|
170
167
|
else
|
|
171
168
|
{
|
|
172
169
|
// clear and set size to same as window
|
|
173
|
-
mainCanvas.width = min(innerWidth,
|
|
174
|
-
mainCanvas.height = min(innerHeight,
|
|
170
|
+
mainCanvas.width = min(innerWidth, maxSize.x);
|
|
171
|
+
mainCanvas.height = min(innerHeight, maxSize.y);
|
|
175
172
|
}
|
|
176
173
|
|
|
177
174
|
// save canvas size and clear overlay canvas
|
package/engine/engineAudio.js
CHANGED
|
@@ -23,10 +23,10 @@ class Sound
|
|
|
23
23
|
{
|
|
24
24
|
/** Create a sound object and cache the zzfx samples for later use
|
|
25
25
|
* @param {Array} zzfxSound - Array of zzfx parameters, ex. [.5,.5]
|
|
26
|
-
* @param {Number} [range=
|
|
27
|
-
* @param {Number} [taper=
|
|
26
|
+
* @param {Number} [range=soundDefaultRange] - World space max range of sound, will not play if camera is farther away
|
|
27
|
+
* @param {Number} [taper=soundDefaultTaper] - At what percentage of range should it start tapering off
|
|
28
28
|
*/
|
|
29
|
-
constructor(zzfxSound, range=
|
|
29
|
+
constructor(zzfxSound, range=soundDefaultRange, taper=soundDefaultTaper)
|
|
30
30
|
{
|
|
31
31
|
if (!soundEnable) return;
|
|
32
32
|
|
|
@@ -157,7 +157,7 @@ function playAudioFile(url, volume=1, loop=1)
|
|
|
157
157
|
if (!soundEnable) return;
|
|
158
158
|
|
|
159
159
|
const audio = new Audio(url);
|
|
160
|
-
audio.volume =
|
|
160
|
+
audio.volume = soundVolume * volume;
|
|
161
161
|
audio.loop = loop;
|
|
162
162
|
audio.play();
|
|
163
163
|
return audio;
|
|
@@ -182,7 +182,7 @@ function speak(text, language='', volume=1, rate=1, pitch=1)
|
|
|
182
182
|
// build utterance and speak
|
|
183
183
|
const utterance = new SpeechSynthesisUtterance(text);
|
|
184
184
|
utterance.lang = language;
|
|
185
|
-
utterance.volume = 2*volume*
|
|
185
|
+
utterance.volume = 2*volume*soundVolume;
|
|
186
186
|
utterance.rate = rate;
|
|
187
187
|
utterance.pitch = pitch;
|
|
188
188
|
speechSynthesis.speak(utterance);
|
|
@@ -235,7 +235,7 @@ function playSamples(sampleChannels, volume=1, rate=1, pan=0, loop=0)
|
|
|
235
235
|
// create pan and gain nodes
|
|
236
236
|
source
|
|
237
237
|
.connect(new StereoPannerNode(audioContext, {'pan':clamp(pan, 1, -1)}))
|
|
238
|
-
.connect(new GainNode(audioContext, {'gain':
|
|
238
|
+
.connect(new GainNode(audioContext, {'gain':soundVolume*volume}))
|
|
239
239
|
.connect(audioContext.destination);
|
|
240
240
|
|
|
241
241
|
// play and return sound
|
|
@@ -303,7 +303,7 @@ function zzfxG
|
|
|
303
303
|
1 - tremolo + tremolo*Math.sin(PI2*i/repeatTime) // tremolo
|
|
304
304
|
: 1) *
|
|
305
305
|
sign(s)*(abs(s)**shapeCurve) * // curve 0=square, 2=pointy
|
|
306
|
-
volume *
|
|
306
|
+
volume * soundVolume * ( // envelope
|
|
307
307
|
i < attack ? i/attack : // attack
|
|
308
308
|
i < attack + decay ? // decay
|
|
309
309
|
1-((i-attack)/decay)*(1-sustainVolume) : // decay falloff
|