littlejsengine 1.11.13 → 1.12.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/littlejs.d.ts +1418 -109
- package/dist/littlejs.esm.js +3495 -581
- package/dist/littlejs.esm.min.js +1 -1
- package/dist/littlejs.js +3258 -399
- package/dist/littlejs.min.js +1 -1
- package/dist/littlejs.release.js +3147 -379
- package/examples/box2d/game.js +73 -45
- package/examples/box2d/gameObjects.js +96 -92
- package/examples/box2d/index.html +2 -7
- package/examples/box2d/scenes.js +82 -92
- package/examples/breakout/game.js +62 -30
- package/examples/breakout/gameObjects.js +45 -47
- package/examples/breakout/index.html +1 -5
- package/examples/breakoutTutorial/game.js +36 -29
- package/examples/breakoutTutorial/index.html +1 -3
- package/examples/empty/game.js +5 -2
- package/examples/empty/index.html +1 -3
- package/examples/htmlMenu/game.js +25 -19
- package/examples/htmlMenu/index.html +5 -7
- package/examples/index.html +2 -3
- package/examples/module/game.js +32 -34
- package/examples/module/index.html +1 -1
- package/examples/particles/index.html +27 -22
- package/examples/platformer/game.js +71 -48
- package/examples/platformer/gameCharacter.js +42 -34
- package/examples/platformer/gameEffects.js +82 -75
- package/examples/platformer/gameLevel.js +67 -38
- package/examples/platformer/{gameLevelData.js → gameLevelData.json} +1 -11
- package/examples/platformer/gameObjects.js +70 -64
- package/examples/platformer/gamePlayer.js +12 -7
- package/examples/platformer/index.html +1 -9
- package/examples/puzzle/game.js +58 -42
- package/examples/puzzle/index.html +1 -3
- package/examples/shorts/base.html +2 -2
- package/examples/shorts/particles.js +1 -1
- package/examples/shorts/platformer.js +1 -1
- package/examples/shorts/tileLayer.js +5 -6
- package/examples/shorts/tiles.png +0 -0
- package/examples/starter/build.js +4 -4
- package/examples/starter/game.js +9 -12
- package/examples/starter/index.html +13 -13
- package/examples/stress/index.html +44 -43
- package/examples/typescript/build.js +17 -18
- package/examples/typescript/game.js +32 -34
- package/examples/typescript/game.ts +32 -34
- package/examples/typescript/index.html +1 -1
- package/examples/uiSystem/game.js +33 -36
- package/examples/uiSystem/index.html +1 -5
- package/package.json +3 -3
- package/plugins/box2d.js +1556 -640
- package/plugins/{Box2D_v2.3.1_min.wasm.js → box2d.wasm.js} +1 -1
- package/plugins/newgrounds.js +7 -8
- package/plugins/pluginExport.js +50 -0
- package/plugins/postProcess.js +94 -93
- package/plugins/uiSystem.js +145 -161
- package/plugins/zzfxm.js +163 -0
- package/reference.md +29 -27
- package/src/engine.js +15 -20
- package/src/engineAudio.js +74 -204
- package/src/engineBuild.js +29 -4
- package/src/engineDebug.js +105 -9
- package/src/engineDraw.js +27 -14
- package/src/engineExport.js +12 -8
- package/src/engineInput.js +3 -1
- package/src/engineObject.js +18 -14
- package/src/engineParticles.js +6 -1
- package/src/engineRelease.js +6 -1
- package/src/engineSettings.js +8 -8
- package/src/engineTileLayer.js +179 -96
- package/src/engineUtilities.js +5 -11
- package/src/engineWebGL.js +19 -7
- package/examples/starter/build/index.html +0 -2
- package/examples/starter/build/index.js +0 -1
- package/examples/starter/build/tiles.png +0 -0
- package/examples/starter/game.zip +0 -0
- package/examples/typescript/build/dist/littlejs.esm.js +0 -4834
- package/examples/typescript/build/examples/typescript/build.js +0 -24
- package/examples/typescript/build/examples/typescript/game.js +0 -102
- /package/plugins/{Box2D_v2.3.1_min.wasm.wasm → box2d.wasm.wasm} +0 -0
|
@@ -6,22 +6,22 @@
|
|
|
6
6
|
|
|
7
7
|
'use strict';
|
|
8
8
|
|
|
9
|
-
// import module
|
|
10
|
-
import * as
|
|
11
|
-
const {tile, vec2, hsl} =
|
|
9
|
+
// import LittleJS module
|
|
10
|
+
import * as LJS from '../../dist/littlejs.esm.js';
|
|
11
|
+
const {tile, vec2, hsl} = LJS;
|
|
12
12
|
|
|
13
13
|
// show the LittleJS splash screen
|
|
14
|
-
|
|
14
|
+
LJS.setShowSplashScreen(true);
|
|
15
15
|
|
|
16
16
|
// fix texture bleeding by shrinking tile slightly
|
|
17
|
-
|
|
17
|
+
LJS.setTileFixBleedScale(.5);
|
|
18
18
|
|
|
19
19
|
// sound effects
|
|
20
|
-
const sound_click = new
|
|
20
|
+
const sound_click = new LJS.Sound([1,.5]);
|
|
21
21
|
|
|
22
22
|
// medals
|
|
23
|
-
const medal_example = new
|
|
24
|
-
|
|
23
|
+
const medal_example = new LJS.Medal(0, 'Example Medal', 'Welcome to LittleJS!');
|
|
24
|
+
LJS.medalsInit('Hello World');
|
|
25
25
|
|
|
26
26
|
// game variables
|
|
27
27
|
let particleEmitter;
|
|
@@ -30,46 +30,44 @@ let particleEmitter;
|
|
|
30
30
|
function gameInit()
|
|
31
31
|
{
|
|
32
32
|
// create tile collision and visible tile layer
|
|
33
|
-
const tileCollisionSize = vec2(32, 16);
|
|
34
|
-
LittleJS.initTileCollision(tileCollisionSize);
|
|
35
33
|
const pos = vec2();
|
|
36
|
-
const tileLayer = new
|
|
34
|
+
const tileLayer = new LJS.TileCollisionLayer(pos, vec2(32,16));
|
|
37
35
|
|
|
38
36
|
// get level data from the tiles image
|
|
39
|
-
const mainContext =
|
|
40
|
-
const tileImage =
|
|
37
|
+
const mainContext = LJS.mainContext;
|
|
38
|
+
const tileImage = LJS.textureInfos[0].image;
|
|
41
39
|
mainContext.drawImage(tileImage, 0, 0);
|
|
42
40
|
const imageData = mainContext.getImageData(0,0,tileImage.width,tileImage.height).data;
|
|
43
|
-
for (pos.x =
|
|
44
|
-
for (pos.y =
|
|
41
|
+
for (pos.x = tileLayer.size.x; pos.x--;)
|
|
42
|
+
for (pos.y = tileLayer.size.y; pos.y--;)
|
|
45
43
|
{
|
|
46
44
|
// check if this pixel is set
|
|
47
|
-
const i = pos.x + tileImage.width*(15 +
|
|
45
|
+
const i = pos.x + tileImage.width*(15 + tileLayer.size.y - pos.y);
|
|
48
46
|
if (!imageData[4*i])
|
|
49
47
|
continue;
|
|
50
48
|
|
|
51
49
|
// set tile data
|
|
52
50
|
const tileIndex = 1;
|
|
53
|
-
const direction =
|
|
54
|
-
const mirror = !
|
|
55
|
-
const color =
|
|
56
|
-
const data = new
|
|
51
|
+
const direction = LJS.randInt(4)
|
|
52
|
+
const mirror = !LJS.randInt(2);
|
|
53
|
+
const color = LJS.randColor();
|
|
54
|
+
const data = new LJS.TileLayerData(tileIndex, direction, mirror, color);
|
|
57
55
|
tileLayer.setData(pos, data);
|
|
58
|
-
|
|
56
|
+
tileLayer.setCollisionData(pos);
|
|
59
57
|
}
|
|
60
58
|
|
|
61
59
|
// draw tile layer with new data
|
|
62
60
|
tileLayer.redraw();
|
|
63
61
|
|
|
64
62
|
// move camera to center of collision
|
|
65
|
-
|
|
66
|
-
|
|
63
|
+
LJS.setCameraPos(tileLayer.size.scale(.5));
|
|
64
|
+
LJS.setCameraScale(32);
|
|
67
65
|
|
|
68
66
|
// enable gravity
|
|
69
|
-
|
|
67
|
+
LJS.setGravity(vec2(0,-.01));
|
|
70
68
|
|
|
71
69
|
// create particle emitter
|
|
72
|
-
particleEmitter = new
|
|
70
|
+
particleEmitter = new LJS.ParticleEmitter(
|
|
73
71
|
vec2(16,9), 0, // emitPos, emitAngle
|
|
74
72
|
1, 0, 500, Math.PI, // emitSize, emitTime, emitRate, emitCone
|
|
75
73
|
tile(0, 16), // tileIndex, tileSize
|
|
@@ -86,14 +84,14 @@ function gameInit()
|
|
|
86
84
|
///////////////////////////////////////////////////////////////////////////////
|
|
87
85
|
function gameUpdate()
|
|
88
86
|
{
|
|
89
|
-
if (
|
|
87
|
+
if (LJS.mouseWasPressed(0))
|
|
90
88
|
{
|
|
91
89
|
// play sound when mouse is pressed
|
|
92
|
-
sound_click.play(
|
|
90
|
+
sound_click.play(LJS.mousePos);
|
|
93
91
|
|
|
94
92
|
// change particle color and set to fade out
|
|
95
93
|
particleEmitter.colorStartA = hsl();
|
|
96
|
-
particleEmitter.colorStartB =
|
|
94
|
+
particleEmitter.colorStartB = LJS.randColor();
|
|
97
95
|
particleEmitter.colorEndA = particleEmitter.colorStartA.scale(1,0);
|
|
98
96
|
particleEmitter.colorEndB = particleEmitter.colorStartB.scale(1,0);
|
|
99
97
|
|
|
@@ -102,8 +100,8 @@ function gameUpdate()
|
|
|
102
100
|
}
|
|
103
101
|
|
|
104
102
|
// move particles to mouse location if on screen
|
|
105
|
-
if (
|
|
106
|
-
particleEmitter.pos =
|
|
103
|
+
if (LJS.mousePosScreen.x)
|
|
104
|
+
particleEmitter.pos = LJS.mousePos;
|
|
107
105
|
}
|
|
108
106
|
|
|
109
107
|
///////////////////////////////////////////////////////////////////////////////
|
|
@@ -116,19 +114,19 @@ function gameUpdatePost()
|
|
|
116
114
|
function gameRender()
|
|
117
115
|
{
|
|
118
116
|
// draw a grey square in the background without using webgl
|
|
119
|
-
|
|
117
|
+
LJS.drawRect(vec2(16,8), vec2(20,14), hsl(0,0,.6), 0, false);
|
|
120
118
|
|
|
121
119
|
// draw the logo as a tile
|
|
122
|
-
|
|
120
|
+
LJS.drawTile(vec2(21,5), vec2(4.5), tile(3,128));
|
|
123
121
|
}
|
|
124
122
|
|
|
125
123
|
///////////////////////////////////////////////////////////////////////////////
|
|
126
124
|
function gameRenderPost()
|
|
127
125
|
{
|
|
128
126
|
// draw to overlay canvas for hud rendering
|
|
129
|
-
|
|
127
|
+
LJS.drawTextScreen('LittleJS with TypeScript', vec2(LJS.mainCanvasSize.x/2, 80), 80);
|
|
130
128
|
}
|
|
131
129
|
|
|
132
130
|
///////////////////////////////////////////////////////////////////////////////
|
|
133
131
|
// Startup LittleJS Engine
|
|
134
|
-
|
|
132
|
+
LJS.engineInit(gameInit, gameUpdate, gameUpdatePost, gameRender, gameRenderPost, ['tiles.png']);
|
|
@@ -6,11 +6,12 @@
|
|
|
6
6
|
|
|
7
7
|
'use strict';
|
|
8
8
|
|
|
9
|
-
//
|
|
10
|
-
|
|
9
|
+
// import LittleJS module
|
|
10
|
+
import * as LJS from '../../dist/littlejs.esm.js';
|
|
11
|
+
const {vec2, hsl, tile} = LJS;
|
|
11
12
|
|
|
12
13
|
// sound effects
|
|
13
|
-
const sound_ui = new Sound([1,0]);
|
|
14
|
+
const sound_ui = new LJS.Sound([1,0]);
|
|
14
15
|
|
|
15
16
|
// UI system
|
|
16
17
|
let uiRoot, uiMenu;
|
|
@@ -18,43 +19,43 @@ const getMenuVisible =()=> uiMenu.visible;
|
|
|
18
19
|
const setMenuVisible =(visible)=> uiMenu.visible = visible;
|
|
19
20
|
|
|
20
21
|
// use a fixed size canvas
|
|
21
|
-
|
|
22
|
-
|
|
22
|
+
LJS.setCanvasFixedSize(vec2(1920, 1080)); // 1080p
|
|
23
|
+
LJS.setCanvasPixelated(false);
|
|
23
24
|
|
|
24
25
|
function createUI()
|
|
25
26
|
{
|
|
26
27
|
// setup root to attach all ui elements to
|
|
27
|
-
uiRoot = new UIObject();
|
|
28
|
-
const uiInfo = new UIText(vec2(0,90), vec2(1e3, 70),
|
|
28
|
+
uiRoot = new LJS.UIObject();
|
|
29
|
+
const uiInfo = new LJS.UIText(vec2(0,90), vec2(1e3, 70),
|
|
29
30
|
'LittleJS UI System Example\nM = Toggle menu');
|
|
30
|
-
uiInfo.textColor = WHITE;
|
|
31
|
+
uiInfo.textColor = LJS.WHITE;
|
|
31
32
|
uiInfo.lineWidth = 8;
|
|
32
33
|
uiRoot.addChild(uiInfo);
|
|
33
34
|
|
|
34
35
|
// setup example menu
|
|
35
|
-
uiMenu = new UIObject(vec2(0,450));
|
|
36
|
+
uiMenu = new LJS.UIObject(vec2(0,450));
|
|
36
37
|
uiRoot.addChild(uiMenu);
|
|
37
|
-
const uiBackground = new UIObject(vec2(0,0), vec2(450,580));
|
|
38
|
+
const uiBackground = new LJS.UIObject(vec2(0,0), vec2(450,580));
|
|
38
39
|
uiBackground.lineWidth = 8;
|
|
39
40
|
uiMenu.addChild(uiBackground);
|
|
40
41
|
|
|
41
42
|
// example large text
|
|
42
|
-
const textTitle = new UIText(vec2(0,-220), vec2(500, 90), 'Test Title');
|
|
43
|
+
const textTitle = new LJS.UIText(vec2(0,-220), vec2(500, 90), 'Test Title');
|
|
43
44
|
uiMenu.addChild(textTitle);
|
|
44
|
-
textTitle.textColor = RED;
|
|
45
|
+
textTitle.textColor = LJS.RED;
|
|
45
46
|
textTitle.lineWidth = 4;
|
|
46
|
-
textTitle.lineColor = BLUE;
|
|
47
|
+
textTitle.lineColor = LJS.BLUE;
|
|
47
48
|
|
|
48
49
|
// example multiline text
|
|
49
|
-
const textTest = new UIText(vec2(-60,-140), vec2(300, 50), 'Test Text\nSecond text line.')
|
|
50
|
+
const textTest = new LJS.UIText(vec2(-60,-140), vec2(300, 50), 'Test Text\nSecond text line.')
|
|
50
51
|
uiMenu.addChild(textTest);
|
|
51
52
|
|
|
52
53
|
// example tile image
|
|
53
|
-
const tileTest = new UITile(vec2(150,-130), vec2(110), tile(3,128))
|
|
54
|
+
const tileTest = new LJS.UITile(vec2(150,-130), vec2(110), tile(3,128))
|
|
54
55
|
uiMenu.addChild(tileTest);
|
|
55
56
|
|
|
56
57
|
// example checkbox
|
|
57
|
-
const checkbox = new UICheckbox(vec2(-140,-20), vec2(40));
|
|
58
|
+
const checkbox = new LJS.UICheckbox(vec2(-140,-20), vec2(40));
|
|
58
59
|
uiMenu.addChild(checkbox);
|
|
59
60
|
checkbox.onPress = ()=>
|
|
60
61
|
{
|
|
@@ -64,18 +65,18 @@ function createUI()
|
|
|
64
65
|
}
|
|
65
66
|
|
|
66
67
|
// text attached to checkbox
|
|
67
|
-
const checkboxText = new UIText(vec2(170,0), vec2(300, 40), 'Test Checkbox');
|
|
68
|
+
const checkboxText = new LJS.UIText(vec2(170,0), vec2(300, 40), 'Test Checkbox');
|
|
68
69
|
checkbox.addChild(checkboxText);
|
|
69
70
|
|
|
70
71
|
// example scrollbar
|
|
71
|
-
const scrollbar = new UIScrollbar(vec2(0,60), vec2(350, 50));
|
|
72
|
+
const scrollbar = new LJS.UIScrollbar(vec2(0,60), vec2(350, 50));
|
|
72
73
|
uiMenu.addChild(scrollbar);
|
|
73
74
|
scrollbar.onChange = ()=> console.log('New scrollbar value:', scrollbar.value);
|
|
74
75
|
scrollbar.onPress = ()=> sound_ui.play(0,.3,2);
|
|
75
76
|
scrollbar.onRelease = ()=> sound_ui.play(0,.3,4);
|
|
76
77
|
|
|
77
78
|
// example button
|
|
78
|
-
const button1 = new UIButton(vec2(0,140), vec2(350, 50), 'Test Button');
|
|
79
|
+
const button1 = new LJS.UIButton(vec2(0,140), vec2(350, 50), 'Test Button');
|
|
79
80
|
uiMenu.addChild(button1);
|
|
80
81
|
button1.onPress = ()=>
|
|
81
82
|
{
|
|
@@ -84,7 +85,7 @@ function createUI()
|
|
|
84
85
|
}
|
|
85
86
|
|
|
86
87
|
// exit button
|
|
87
|
-
const button2 = new UIButton(vec2(0,220), vec2(350, 50), 'Exit Menu');
|
|
88
|
+
const button2 = new LJS.UIButton(vec2(0,220), vec2(350, 50), 'Exit Menu');
|
|
88
89
|
uiMenu.addChild(button2);
|
|
89
90
|
button2.onPress = ()=>
|
|
90
91
|
{
|
|
@@ -97,7 +98,7 @@ function createUI()
|
|
|
97
98
|
///////////////////////////////////////////////////////////////////////////////
|
|
98
99
|
function gameInit()
|
|
99
100
|
{
|
|
100
|
-
|
|
101
|
+
new LJS.UISystemPlugin;
|
|
101
102
|
createUI();
|
|
102
103
|
}
|
|
103
104
|
|
|
@@ -109,30 +110,26 @@ function gameUpdate()
|
|
|
109
110
|
///////////////////////////////////////////////////////////////////////////////
|
|
110
111
|
function gameUpdatePost()
|
|
111
112
|
{
|
|
112
|
-
//
|
|
113
|
-
|
|
113
|
+
// toggle menu visibility
|
|
114
|
+
if (LJS.keyWasPressed('KeyM'))
|
|
115
|
+
setMenuVisible(!getMenuVisible());
|
|
114
116
|
|
|
115
|
-
//
|
|
116
|
-
|
|
117
|
-
paused = menuVisible;
|
|
117
|
+
// center ui
|
|
118
|
+
uiRoot.pos.x = LJS.mainCanvasSize.x/2;
|
|
118
119
|
|
|
119
|
-
//
|
|
120
|
-
|
|
121
|
-
setMenuVisible(!menuVisible);
|
|
120
|
+
// pause when menu is visible
|
|
121
|
+
LJS.setPaused(getMenuVisible())
|
|
122
122
|
}
|
|
123
123
|
|
|
124
124
|
///////////////////////////////////////////////////////////////////////////////
|
|
125
125
|
function gameRender()
|
|
126
126
|
{
|
|
127
127
|
// test game rendering
|
|
128
|
-
drawRect(vec2(), vec2(1e3), hsl(0,0,.2));
|
|
129
|
-
|
|
130
|
-
// test game rendering
|
|
131
|
-
drawRect(vec2(), vec2(1e3), hsl(0,0,.2));
|
|
128
|
+
LJS.drawRect(vec2(), vec2(1e3), hsl(0,0,.2));
|
|
132
129
|
for(let i=0; i<1e3; ++i)
|
|
133
130
|
{
|
|
134
|
-
const pos = vec2(30*Math.sin(i+time/9),20*Math.sin(i*i+time/9));
|
|
135
|
-
drawTile(pos, vec2(2), tile(3,128), hsl(i/9,1,.4), time+i, !(i%2), hsl(i/9,1,.1,0));
|
|
131
|
+
const pos = vec2(30*Math.sin(i+LJS.time/9),20*Math.sin(i*i+LJS.time/9));
|
|
132
|
+
LJS.drawTile(pos, vec2(2), tile(3,128), hsl(i/9,1,.4), LJS.time+i, !(i%2), hsl(i/9,1,.1,0));
|
|
136
133
|
}
|
|
137
134
|
}
|
|
138
135
|
|
|
@@ -143,4 +140,4 @@ function gameRenderPost()
|
|
|
143
140
|
|
|
144
141
|
///////////////////////////////////////////////////////////////////////////////
|
|
145
142
|
// Startup LittleJS Engine
|
|
146
|
-
engineInit(gameInit, gameUpdate, gameUpdatePost, gameRender, gameRenderPost, ['tiles.png']);
|
|
143
|
+
LJS.engineInit(gameInit, gameUpdate, gameUpdatePost, gameRender, gameRenderPost, ['tiles.png']);
|
|
@@ -6,9 +6,5 @@
|
|
|
6
6
|
<link rel=icon type=image/png href=../favicon.png>
|
|
7
7
|
</head><body>
|
|
8
8
|
|
|
9
|
-
<!-- LittleJS Engine -->
|
|
10
|
-
<script src=../../dist/littlejs.js?1117></script>
|
|
11
|
-
|
|
12
9
|
<!-- Add your game scripts here -->
|
|
13
|
-
<script src
|
|
14
|
-
<script src=game.js?1117></script>
|
|
10
|
+
<script src=game.js type=module></script>
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "littlejsengine",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.12.4",
|
|
4
4
|
"description": "LittleJS - Tiny and Fast HTML5 Game Engine",
|
|
5
5
|
"main": "dist/littlejs.esm.js",
|
|
6
6
|
"types": "dist/littlejs.d.ts",
|
|
@@ -33,10 +33,10 @@
|
|
|
33
33
|
"build": "node src/engineBuild.js"
|
|
34
34
|
},
|
|
35
35
|
"devDependencies": {
|
|
36
|
+
"bestzip": "^2.2.1",
|
|
36
37
|
"google-closure-compiler": "~20230502.0.0",
|
|
37
38
|
"roadroller": "~2.1.0",
|
|
38
|
-
"uglify-js": "~3.17.4",
|
|
39
39
|
"typescript": "~5.1.6",
|
|
40
|
-
"
|
|
40
|
+
"uglify-js": "~3.17.4"
|
|
41
41
|
}
|
|
42
42
|
}
|