littlejsengine 1.12.4 → 1.13.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/box2d.wasm.js +630 -0
- package/dist/box2d.wasm.wasm +0 -0
- package/dist/littlejs.d.ts +437 -219
- package/dist/littlejs.esm.js +5950 -5307
- package/dist/littlejs.esm.min.js +4 -1
- package/dist/littlejs.js +5921 -5295
- package/dist/littlejs.min.js +4 -1
- package/dist/littlejs.release.js +5485 -4886
- package/examples/box2d/game.js +37 -42
- package/examples/box2d/gameObjects.js +41 -37
- package/examples/box2d/index.html +2 -2
- package/examples/box2d/scenes.js +24 -20
- package/examples/box2d/tiles.png +0 -0
- package/examples/breakout/game.js +1 -1
- package/examples/breakout/gameObjects.js +2 -2
- package/examples/breakout/index.html +1 -1
- package/examples/breakoutTutorial/README.md +2 -2
- package/examples/breakoutTutorial/game.js +1 -1
- package/examples/breakoutTutorial/index.html +1 -1
- package/examples/empty/index.html +1 -1
- package/examples/htmlMenu/index.html +1 -1
- package/examples/index.html +410 -159
- package/examples/module/game.js +1 -1
- package/examples/module/index.html +1 -1
- package/examples/platformer/game.js +6 -15
- package/examples/platformer/gameCharacter.js +6 -6
- package/examples/platformer/gameEffects.js +74 -57
- package/examples/platformer/gameLevel.js +61 -70
- package/examples/platformer/gameObjects.js +4 -4
- package/examples/platformer/index.html +1 -1
- package/examples/puzzle/index.html +1 -1
- package/examples/shorts/base.html +24 -3
- package/examples/shorts/box2d.js +46 -0
- package/examples/shorts/box2dCar.js +45 -0
- package/examples/shorts/flappyGame.js +52 -0
- package/examples/shorts/helloWorld.js +6 -3
- package/examples/shorts/hillGlideGame.js +56 -0
- package/examples/shorts/landerGame.js +32 -0
- package/examples/shorts/maze.js +47 -0
- package/examples/shorts/medals.js +42 -0
- package/examples/shorts/nineSlice.js +21 -0
- package/examples/shorts/piano.js +52 -0
- package/examples/shorts/platformer.js +24 -20
- package/examples/shorts/{pong.js → pongGame.js} +1 -1
- package/examples/shorts/postProcess.js +45 -0
- package/examples/shorts/raycasting.js +71 -0
- package/examples/shorts/slidingPuzzle.js +42 -0
- package/examples/shorts/spaceGame.js +56 -0
- package/examples/shorts/starfield.js +17 -0
- package/examples/shorts/tileLayer.js +3 -5
- package/examples/shorts/tiles.png +0 -0
- package/examples/shorts/tiltedView.js +8 -7
- package/examples/shorts/topDown.js +18 -26
- package/examples/shorts/uiSystem.js +36 -0
- package/examples/starter/build.bat +6 -1
- package/examples/starter/game.js +4 -2
- package/examples/starter/index.html +23 -13
- package/examples/stress/index.html +2 -3
- package/examples/style.css +136 -0
- package/examples/typescript/build.js +1 -2
- package/examples/typescript/game.js +2 -2
- package/examples/typescript/game.ts +1 -1
- package/examples/typescript/index.html +1 -1
- package/examples/uiSystem/game.js +9 -25
- package/examples/uiSystem/index.html +1 -1
- package/package.json +1 -1
- package/plugins/box2d.js +29 -35
- package/plugins/drawUtilities.js +126 -0
- package/plugins/newgrounds.js +1 -1
- package/plugins/pluginExport.js +8 -2
- package/plugins/postProcess.js +2 -2
- package/plugins/uiSystem.js +162 -68
- package/plugins/zzfxm.js +1 -1
- package/reference.md +10 -10
- package/src/engine.js +59 -39
- package/src/engineAudio.js +38 -20
- package/src/engineBuild.bat +6 -1
- package/src/engineBuild.js +32 -7
- package/src/engineDebug.js +53 -26
- package/src/engineDraw.js +108 -57
- package/src/engineExport.js +22 -9
- package/src/engineInput.js +112 -40
- package/src/engineObject.js +68 -67
- package/src/engineParticles.js +26 -9
- package/src/engineSettings.js +15 -16
- package/src/engineTileLayer.js +312 -153
- package/src/engineUtilities.js +198 -130
- package/src/engineWebGL.js +58 -35
package/plugins/box2d.js
CHANGED
|
@@ -1,31 +1,35 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* LittleJS Box2D Physics Plugin
|
|
3
3
|
* - Box2dObject extends EngineObject with Box2D physics
|
|
4
|
-
* - Call
|
|
4
|
+
* - Call box2dInit() before engineInit() to enable
|
|
5
5
|
* - You will also need to include box2d.wasm.js
|
|
6
|
-
* - Uses
|
|
6
|
+
* - Uses a super fast web assembly port of Box2D
|
|
7
7
|
* - More info: https://github.com/kripken/box2d.js
|
|
8
|
-
* - Fully wraps everything in Box2d
|
|
9
8
|
* - Functions to create polygon, circle, and edge shapes
|
|
10
|
-
* - Raycasting and querying
|
|
11
|
-
* - Joint creation
|
|
12
9
|
* - Contact begin and end callbacks
|
|
10
|
+
* - Wraps b2Vec2 type to/from Vector2
|
|
11
|
+
* - Raycasting and querying
|
|
12
|
+
* - Every type of joint
|
|
13
13
|
* - Debug physics drawing
|
|
14
|
+
* @namespace Box2D
|
|
14
15
|
*/
|
|
15
16
|
|
|
16
17
|
'use strict';
|
|
17
18
|
|
|
18
19
|
/** Global Box2d Plugin object
|
|
19
|
-
* @type {Box2dPlugin}
|
|
20
|
+
* @type {Box2dPlugin}
|
|
21
|
+
* @memberof Box2D */
|
|
20
22
|
let box2d;
|
|
21
23
|
|
|
22
24
|
/** Enable Box2D debug drawing
|
|
23
25
|
* @type {boolean}
|
|
24
|
-
* @default
|
|
26
|
+
* @default
|
|
27
|
+
* @memberof Box2D */
|
|
25
28
|
let box2dDebug = false;
|
|
26
29
|
|
|
27
30
|
/** Enable Box2D debug drawing
|
|
28
|
-
* @param {boolean} enable
|
|
31
|
+
* @param {boolean} enable
|
|
32
|
+
* @memberof Box2D */
|
|
29
33
|
function box2dSetDebug(enable) { box2dDebug = enable; }
|
|
30
34
|
|
|
31
35
|
///////////////////////////////////////////////////////////////////////////////
|
|
@@ -72,7 +76,7 @@ class Box2dObject extends EngineObject
|
|
|
72
76
|
/** Copy box2d update sim data */
|
|
73
77
|
update()
|
|
74
78
|
{
|
|
75
|
-
// use box2d physics update
|
|
79
|
+
// use box2d physics update instead of normal engine update
|
|
76
80
|
this.pos = box2d.vec2From(this.body.GetPosition());
|
|
77
81
|
this.angle = -this.body.GetAngle();
|
|
78
82
|
}
|
|
@@ -1588,7 +1592,7 @@ class Box2dPlugin
|
|
|
1588
1592
|
* @param {Color} [outlineColor]
|
|
1589
1593
|
* @param {number} [lineWidth]
|
|
1590
1594
|
* @param {CanvasRenderingContext2D} [context] */
|
|
1591
|
-
drawFixture(fixture, pos, angle, color=WHITE, outlineColor=BLACK, lineWidth=.1, context=
|
|
1595
|
+
drawFixture(fixture, pos, angle, color=WHITE, outlineColor=BLACK, lineWidth=.1, context=drawContext)
|
|
1592
1596
|
{
|
|
1593
1597
|
const shape = box2d.castObjectType(fixture.GetShape());
|
|
1594
1598
|
switch (shape.GetType())
|
|
@@ -1624,7 +1628,7 @@ class Box2dPlugin
|
|
|
1624
1628
|
* @param {Color} [outlineColor]
|
|
1625
1629
|
* @param {number} [lineWidth]
|
|
1626
1630
|
* @param {CanvasRenderingContext2D} [context] */
|
|
1627
|
-
drawCircle(pos, radius, color=WHITE, outlineColor=BLACK, lineWidth=.1, context=
|
|
1631
|
+
drawCircle(pos, radius, color=WHITE, outlineColor=BLACK, lineWidth=.1, context=drawContext)
|
|
1628
1632
|
{
|
|
1629
1633
|
drawCanvas2D(pos, vec2(1), 0, 0, context=>
|
|
1630
1634
|
{
|
|
@@ -1642,7 +1646,7 @@ class Box2dPlugin
|
|
|
1642
1646
|
* @param {Color} [outlineColor]
|
|
1643
1647
|
* @param {number} [lineWidth]
|
|
1644
1648
|
* @param {CanvasRenderingContext2D} [context] */
|
|
1645
|
-
drawPoly(pos, angle, points, color=WHITE, outlineColor=BLACK, lineWidth=.1, context=
|
|
1649
|
+
drawPoly(pos, angle, points, color=WHITE, outlineColor=BLACK, lineWidth=.1, context=drawContext)
|
|
1646
1650
|
{
|
|
1647
1651
|
drawCanvas2D(pos, vec2(1), angle, 0, context=>
|
|
1648
1652
|
{
|
|
@@ -1661,7 +1665,7 @@ class Box2dPlugin
|
|
|
1661
1665
|
* @param {Color} [color]
|
|
1662
1666
|
* @param {number} [lineWidth]
|
|
1663
1667
|
* @param {CanvasRenderingContext2D} [context] */
|
|
1664
|
-
drawLine(pos, angle, posA, posB, color=WHITE, lineWidth=.1, context=
|
|
1668
|
+
drawLine(pos, angle, posA, posB, color=WHITE, lineWidth=.1, context=drawContext)
|
|
1665
1669
|
{
|
|
1666
1670
|
drawCanvas2D(pos, vec2(1), angle, 0, context=>
|
|
1667
1671
|
{
|
|
@@ -1677,7 +1681,7 @@ class Box2dPlugin
|
|
|
1677
1681
|
* @param {Color} [outlineColor]
|
|
1678
1682
|
* @param {number} [lineWidth]
|
|
1679
1683
|
* @param {CanvasRenderingContext2D} [context] */
|
|
1680
|
-
drawFillStroke(color=WHITE, outlineColor=BLACK, lineWidth=.1, context=
|
|
1684
|
+
drawFillStroke(color=WHITE, outlineColor=BLACK, lineWidth=.1, context=drawContext)
|
|
1681
1685
|
{
|
|
1682
1686
|
if (color)
|
|
1683
1687
|
{
|
|
@@ -1766,28 +1770,18 @@ class Box2dPlugin
|
|
|
1766
1770
|
}
|
|
1767
1771
|
|
|
1768
1772
|
///////////////////////////////////////////////////////////////////////////////
|
|
1769
|
-
/** Box2d Init -
|
|
1770
|
-
* @
|
|
1771
|
-
* @
|
|
1772
|
-
|
|
1773
|
-
* @param {Function} gameRender - Called before objects are rendered, for drawing the background
|
|
1774
|
-
* @param {Function} gameRenderPost - Called after objects are rendered, useful for drawing UI
|
|
1775
|
-
* @param {Array<string>} [imageSources=[]] - List of images to load
|
|
1776
|
-
* @param {HTMLElement} [rootElement] - Root element to attach to, the document body by default */
|
|
1777
|
-
function box2dEngineInit(gameInit, gameUpdate, gameUpdatePost, gameRender, gameRenderPost, imageSources, rootElement)
|
|
1773
|
+
/** Box2d Init - Call with await before starting LittleJS to init box2d
|
|
1774
|
+
* @return {Promise<Box2dPlugin>}
|
|
1775
|
+
* @memberof Box2D */
|
|
1776
|
+
async function box2dInit()
|
|
1778
1777
|
{
|
|
1779
|
-
|
|
1780
|
-
|
|
1781
|
-
|
|
1782
|
-
|
|
1783
|
-
|
|
1778
|
+
// load box2d
|
|
1779
|
+
new Box2dPlugin(await Box2D());
|
|
1780
|
+
setupDebugDraw();
|
|
1781
|
+
engineAddPlugin(box2dUpdate, box2dRender);
|
|
1782
|
+
return box2d;
|
|
1784
1783
|
|
|
1785
|
-
|
|
1786
|
-
engineAddPlugin(box2dUpdate, box2dRender);
|
|
1787
|
-
engineInit(gameInit, gameUpdate, gameUpdatePost, gameRender, gameRenderPost, imageSources, rootElement);
|
|
1788
|
-
});
|
|
1789
|
-
|
|
1790
|
-
// hook up box2d plugin to update and render
|
|
1784
|
+
// add the box2d plugin to the engine
|
|
1791
1785
|
function box2dUpdate()
|
|
1792
1786
|
{
|
|
1793
1787
|
if (!paused)
|
|
@@ -1866,4 +1860,4 @@ function box2dEngineInit(gameInit, gameUpdate, gameUpdatePost, gameRender, gameR
|
|
|
1866
1860
|
//debugDraw.AppendFlags(box2d.instance.b2Draw.e_centerOfMassBit);
|
|
1867
1861
|
box2d.world.SetDebugDraw(debugDraw);
|
|
1868
1862
|
}
|
|
1869
|
-
}
|
|
1863
|
+
}
|
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* LittleJS Drawing Utilities Plugin
|
|
3
|
+
* - Extra drawing functions for LittleJS
|
|
4
|
+
* - Nine slice and three slice drawing
|
|
5
|
+
* @namespace DrawUtilities
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
'use strict';
|
|
9
|
+
|
|
10
|
+
///////////////////////////////////////////////////////////////////////////////
|
|
11
|
+
|
|
12
|
+
/** Draw a scalable nine-slice UI element to the overlay canvas in screen space
|
|
13
|
+
* This function can not apply color because it draws using the overlay 2d context
|
|
14
|
+
* @param {Vector2} pos - Screen space position
|
|
15
|
+
* @param {Vector2} size - Screen space size
|
|
16
|
+
* @param {TileInfo} startTile - Starting tile for the nine-slice pattern
|
|
17
|
+
* @param {number} [borderSize] - Width of the border sections
|
|
18
|
+
* @param {number} [extraSpace] - Extra spacing adjustment
|
|
19
|
+
* @memberof DrawUtilities */
|
|
20
|
+
function drawNineSliceScreen(pos, size, startTile, borderSize=32, extraSpace=1)
|
|
21
|
+
{
|
|
22
|
+
drawNineSlice(pos, size, startTile, WHITE, borderSize, BLACK, extraSpace, false, true, overlayContext);
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
/** Draw a scalable nine-slice UI element in world space
|
|
26
|
+
* This function can apply color and additive color if webgl is enabled
|
|
27
|
+
* @param {Vector2} pos - World space position
|
|
28
|
+
* @param {Vector2} size - World space size
|
|
29
|
+
* @param {TileInfo} startTile - Starting tile for the nine-slice pattern
|
|
30
|
+
* @param {Color} [color] - Color to modulate with
|
|
31
|
+
* @param {number} [borderSize] - Width of the border sections
|
|
32
|
+
* @param {Color} [additiveColor] - Additive color
|
|
33
|
+
* @param {number} [extraSpace] - Extra spacing adjustment
|
|
34
|
+
* @param {boolean} [useWebGL=glEnable] - Use WebGL for rendering
|
|
35
|
+
* @param {boolean} [screenSpace] - Use screen space coordinates
|
|
36
|
+
* @param {CanvasRenderingContext2D} [context] - Canvas context to use
|
|
37
|
+
* @memberof DrawUtilities */
|
|
38
|
+
function drawNineSlice(pos, size, startTile, color, borderSize=1, additiveColor, extraSpace=.01, useWebGL=glEnable, screenSpace, context)
|
|
39
|
+
{
|
|
40
|
+
// setup nine slice tiles
|
|
41
|
+
const centerTile = startTile.offset(startTile.size);
|
|
42
|
+
const centerSize = size.add(vec2(extraSpace-borderSize*2));
|
|
43
|
+
const cornerSize = vec2(borderSize);
|
|
44
|
+
const cornerOffset = size.scale(.5).subtract(cornerSize.scale(.5));
|
|
45
|
+
const flip = screenSpace ? -1 : 1;
|
|
46
|
+
|
|
47
|
+
// center
|
|
48
|
+
drawTile(pos, centerSize, centerTile, color, 0, false, additiveColor, useWebGL, screenSpace, context);
|
|
49
|
+
for(let i=4; i--;)
|
|
50
|
+
{
|
|
51
|
+
// sides
|
|
52
|
+
const horizontal = i%2;
|
|
53
|
+
const sidePos = cornerOffset.multiply(vec2(horizontal?i==1?1:-1:0, horizontal?0:i?-1:1));
|
|
54
|
+
const sideSize = vec2(horizontal ? borderSize : centerSize.x, horizontal ? centerSize.y : borderSize);
|
|
55
|
+
const sideTile = centerTile.offset(startTile.size.multiply(vec2(i==1?1:i==3?-1:0,i==0?-flip:i==2?flip:0)))
|
|
56
|
+
drawTile(pos.add(sidePos), sideSize, sideTile, color, 0, false, additiveColor, useWebGL, screenSpace, context);
|
|
57
|
+
}
|
|
58
|
+
for(let i=4; i--;)
|
|
59
|
+
{
|
|
60
|
+
// corners
|
|
61
|
+
const flipX = i>1;
|
|
62
|
+
const flipY = i && i<3;
|
|
63
|
+
const cornerPos = cornerOffset.multiply(vec2(flipX?-1:1, flipY?-1:1));
|
|
64
|
+
const cornerTile = centerTile.offset(startTile.size.multiply(vec2(flipX?-1:1,flipY?flip:-flip)));
|
|
65
|
+
drawTile(pos.add(cornerPos), cornerSize, cornerTile, color, 0, false, additiveColor, useWebGL, screenSpace, context);
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
/** Draw a scalable three-slice UI element to the overlay canvas in screen space
|
|
70
|
+
* This function can not apply color because it draws using the overlay 2d context
|
|
71
|
+
* @param {Vector2} pos - Screen space position
|
|
72
|
+
* @param {Vector2} size - Screen space size
|
|
73
|
+
* @param {TileInfo} startTile - Starting tile for the three-slice pattern
|
|
74
|
+
* @param {number} [borderSize] - Width of the border sections
|
|
75
|
+
* @param {number} [extraSpace] - Extra spacing adjustment
|
|
76
|
+
* @memberof DrawUtilities */
|
|
77
|
+
function drawThreeSliceScreen(pos, size, startTile, borderSize=32, extraSpace=1)
|
|
78
|
+
{
|
|
79
|
+
drawThreeSlice(pos, size, startTile, WHITE, borderSize, BLACK, extraSpace, false, true, overlayContext);
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
/** Draw a scalable three-slice UI element in world space
|
|
83
|
+
* This function can apply color and additive color if webgl is enabled
|
|
84
|
+
* @param {Vector2} pos - World space position
|
|
85
|
+
* @param {Vector2} size - World space size
|
|
86
|
+
* @param {TileInfo} startTile - Starting tile for the three-slice pattern
|
|
87
|
+
* @param {Color} [color] - Color to modulate with
|
|
88
|
+
* @param {number} [borderSize] - Width of the border sections
|
|
89
|
+
* @param {Color} [additiveColor] - Additive color
|
|
90
|
+
* @param {number} [extraSpace] - Extra spacing adjustment
|
|
91
|
+
* @param {boolean} [useWebGL=glEnable] - Use WebGL for rendering
|
|
92
|
+
* @param {boolean} [screenSpace] - Use screen space coordinates
|
|
93
|
+
* @param {CanvasRenderingContext2D} [context] - Canvas context to use
|
|
94
|
+
* @memberof DrawUtilities */
|
|
95
|
+
function drawThreeSlice(pos, size, startTile, color, borderSize=1, additiveColor, extraSpace=.01, useWebGL=glEnable, screenSpace, context)
|
|
96
|
+
{
|
|
97
|
+
// setup three slice tiles
|
|
98
|
+
const cornerTile = startTile.frame(0);
|
|
99
|
+
const sideTile = startTile.frame(1);
|
|
100
|
+
const centerTile = startTile.frame(2);
|
|
101
|
+
const centerSize = size.add(vec2(extraSpace-borderSize*2));
|
|
102
|
+
const cornerSize = vec2(borderSize);
|
|
103
|
+
const cornerOffset = size.scale(.5).subtract(cornerSize.scale(.5));
|
|
104
|
+
const flip = screenSpace ? -1 : 1;
|
|
105
|
+
|
|
106
|
+
// center
|
|
107
|
+
drawTile(pos, centerSize, centerTile, color, 0, false, additiveColor, useWebGL, screenSpace, context);
|
|
108
|
+
for(let i=4; i--;)
|
|
109
|
+
{
|
|
110
|
+
// sides
|
|
111
|
+
const angle = i*PI/2;
|
|
112
|
+
const horizontal = i%2;
|
|
113
|
+
const sidePos = cornerOffset.multiply(vec2(horizontal?i==1?1:-1:0, horizontal?0:i?-flip:flip));
|
|
114
|
+
const sideSize = vec2(horizontal ? centerSize.y : centerSize.x, borderSize);
|
|
115
|
+
drawTile(pos.add(sidePos), sideSize, sideTile, color, angle, false, additiveColor, useWebGL, screenSpace, context);
|
|
116
|
+
}
|
|
117
|
+
for(let i=4; i--;)
|
|
118
|
+
{
|
|
119
|
+
// corners
|
|
120
|
+
const angle = i*PI/2;
|
|
121
|
+
const flipX = !i || i>2;
|
|
122
|
+
const flipY = i>1;
|
|
123
|
+
const cornerPos = cornerOffset.multiply(vec2(flipX?-1:1, flipY?-flip:flip));
|
|
124
|
+
drawTile(pos.add(cornerPos), cornerSize, cornerTile, color, angle, false, additiveColor, useWebGL, screenSpace, context);
|
|
125
|
+
}
|
|
126
|
+
}
|
package/plugins/newgrounds.js
CHANGED
package/plugins/pluginExport.js
CHANGED
|
@@ -30,7 +30,7 @@ export
|
|
|
30
30
|
box2d,
|
|
31
31
|
box2dDebug,
|
|
32
32
|
box2dSetDebug,
|
|
33
|
-
|
|
33
|
+
box2dInit,
|
|
34
34
|
Box2dPlugin,
|
|
35
35
|
Box2dObject,
|
|
36
36
|
Box2dRaycastResult,
|
|
@@ -47,4 +47,10 @@ export
|
|
|
47
47
|
Box2dFrictionJoint,
|
|
48
48
|
Box2dPulleyJoint,
|
|
49
49
|
Box2dMotorJoint,
|
|
50
|
-
|
|
50
|
+
|
|
51
|
+
// Drawing Utilities
|
|
52
|
+
drawNineSlice,
|
|
53
|
+
drawNineSliceScreen,
|
|
54
|
+
drawThreeSlice,
|
|
55
|
+
drawThreeSliceScreen,
|
|
56
|
+
};
|
package/plugins/postProcess.js
CHANGED
|
@@ -78,7 +78,7 @@ class PostProcessPlugin
|
|
|
78
78
|
else
|
|
79
79
|
{
|
|
80
80
|
// set the viewport
|
|
81
|
-
glContext.viewport(0, 0, glCanvas.width =
|
|
81
|
+
glContext.viewport(0, 0, glCanvas.width = drawCanvas.width, glCanvas.height = drawCanvas.height);
|
|
82
82
|
}
|
|
83
83
|
|
|
84
84
|
if (postProcess.includeOverlay)
|
|
@@ -113,4 +113,4 @@ class PostProcessPlugin
|
|
|
113
113
|
glContext.drawArrays(glContext.TRIANGLE_STRIP, 0, 4);
|
|
114
114
|
}
|
|
115
115
|
}
|
|
116
|
-
}
|
|
116
|
+
}
|