littlejsengine 1.13.4 → 1.14.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +4 -3
- package/dist/littlejs.d.ts +395 -249
- package/dist/littlejs.esm.js +1550 -754
- package/dist/littlejs.esm.min.js +1 -1
- package/dist/littlejs.js +1528 -744
- package/dist/littlejs.min.js +1 -1
- package/dist/littlejs.release.js +1504 -720
- package/examples/box2d/game.js +4 -4
- package/examples/box2d/gameObjects.js +1 -1
- package/examples/breakout/game.js +30 -25
- package/examples/breakoutTutorial/README.md +1 -1
- package/examples/breakoutTutorial/game.js +1 -1
- package/examples/electron/build.js +1 -1
- package/examples/electron/index.html +2 -2
- package/examples/empty/game.js +1 -1
- package/examples/htmlMenu/index.html +7 -7
- package/examples/index.html +208 -97
- package/examples/platformer/gameEffects.js +20 -25
- package/examples/platformer/gameLevel.js +6 -1
- package/examples/shorts/base.html +1 -1
- package/examples/shorts/flappyGame.js +2 -1
- package/examples/shorts/helloWorld.js +1 -1
- package/examples/shorts/music.js +106 -0
- package/examples/shorts/parallax.js +71 -0
- package/examples/shorts/piano.js +7 -8
- package/examples/shorts/postProcess.js +25 -8
- package/examples/shorts/shapes.js +12 -18
- package/examples/shorts/song.mp3 +0 -0
- package/examples/shorts/uiSystem.js +15 -8
- package/examples/starter/index.html +2 -2
- package/examples/stress/index.html +14 -7
- package/examples/style.css +14 -4
- package/examples/typescript/build.js +1 -1
- package/examples/uiSystem/game.js +11 -11
- package/package.json +1 -1
- package/plugins/box2d.js +12 -10
- package/plugins/drawUtilities.js +5 -5
- package/plugins/newgrounds.js +6 -6
- package/plugins/pluginExport.js +1 -1
- package/plugins/uiSystem.js +103 -79
- package/plugins/zzfxm.js +10 -10
- package/reference.md +94 -56
- package/src/engine.js +28 -24
- package/src/engineAudio.js +284 -109
- package/src/engineBuild.js +11 -11
- package/src/engineDebug.js +29 -29
- package/src/engineDraw.js +285 -112
- package/src/engineExport.js +28 -16
- package/src/engineInput.js +57 -67
- package/src/engineMedals.js +25 -25
- package/src/engineObject.js +28 -25
- package/src/engineParticles.js +59 -59
- package/src/engineRelease.js +1 -1
- package/src/engineSettings.js +20 -13
- package/src/engineTileLayer.js +34 -35
- package/src/engineUtilities.js +66 -59
- package/src/engineWebGL.js +466 -66
- /package/examples/shorts/{playSound.js → sound.js} +0 -0
package/examples/box2d/game.js
CHANGED
|
@@ -136,8 +136,8 @@ function gameUpdatePost()
|
|
|
136
136
|
///////////////////////////////////////////////////////////////////////////////
|
|
137
137
|
function gameRender()
|
|
138
138
|
{
|
|
139
|
-
// draw a grey square in the background
|
|
140
|
-
LJS.drawRect(vec2(20,8), vec2(100), hsl(0,0,.8)
|
|
139
|
+
// draw a grey square in the background
|
|
140
|
+
LJS.drawRect(vec2(20,8), vec2(100), hsl(0,0,.8));
|
|
141
141
|
|
|
142
142
|
if (Scenes.scene == 5)
|
|
143
143
|
{
|
|
@@ -168,8 +168,8 @@ function gameRenderPost()
|
|
|
168
168
|
|
|
169
169
|
// draw to overlay canvas for hud rendering
|
|
170
170
|
const pos = vec2(LJS.mainCanvasSize.x/2, 50);
|
|
171
|
-
drawText('LittleJS Box2D Demo',
|
|
172
|
-
drawText(Scenes.sceneName,
|
|
171
|
+
drawText('LittleJS Box2D Demo', 65, 70);
|
|
172
|
+
drawText(Scenes.sceneName, 50, 100);
|
|
173
173
|
if (Scenes.scene == 0)
|
|
174
174
|
{
|
|
175
175
|
drawText('Mouse Left = Grab');
|
|
@@ -20,7 +20,7 @@ const restitution = .2;
|
|
|
20
20
|
|
|
21
21
|
export function spawnBox(pos, size=1, color=LJS.WHITE, type=LJS.box2d.bodyTypeDynamic, applyTexture=true, angle=0)
|
|
22
22
|
{
|
|
23
|
-
size = typeof size
|
|
23
|
+
size = typeof size === 'number' ? vec2(size) : size; // square
|
|
24
24
|
const o = new LJS.Box2dObject(pos, size, applyTexture && Game.spriteAtlas.squareOutline, angle, color, type);
|
|
25
25
|
o.drawSize = size.scale(1.02); // slightly enlarge to cover gaps
|
|
26
26
|
o.addBox(size, vec2(), 0, density, friction, restitution);
|
|
@@ -122,38 +122,43 @@ function setupPostProcess()
|
|
|
122
122
|
p=fract(p*.3197);
|
|
123
123
|
return fract(1.+sin(51.*p.x+73.*p.y)*13753.3);
|
|
124
124
|
}
|
|
125
|
-
|
|
126
|
-
{
|
|
127
|
-
vec2 i=floor(p),f=fract(p),u=f*f*(3.-2.*f);
|
|
128
|
-
return mix(mix(hash(i),hash(i+vec2(1,0)),u.x),mix(hash(i+vec2(0,1)),hash(i+1.),u.x),u.y);
|
|
129
|
-
}
|
|
125
|
+
|
|
130
126
|
void mainImage(out vec4 c, vec2 p)
|
|
131
127
|
{
|
|
132
|
-
//
|
|
128
|
+
// setup the shader
|
|
129
|
+
vec2 uv = p;
|
|
133
130
|
p /= iResolution.xy;
|
|
134
|
-
|
|
135
|
-
// apply fuzz as horizontal offset
|
|
136
|
-
const float fuzz = .0005;
|
|
137
|
-
const float fuzzScale = 800.;
|
|
138
|
-
const float fuzzSpeed = 9.;
|
|
139
|
-
p.x += fuzz*(noise(vec2(p.y*fuzzScale, iTime*fuzzSpeed))*2.-1.);
|
|
140
|
-
|
|
141
|
-
// init output color
|
|
142
131
|
c = texture(iChannel0, p);
|
|
143
132
|
|
|
144
|
-
//
|
|
145
|
-
const float
|
|
146
|
-
|
|
147
|
-
c
|
|
148
|
-
|
|
149
|
-
// tv static noise
|
|
150
|
-
const float staticNoise = .1;
|
|
151
|
-
c += staticNoise * hash(p + mod(iTime, 1e3));
|
|
133
|
+
// static noise
|
|
134
|
+
const float staticAlpha = .1;
|
|
135
|
+
const float staticScale = .002;
|
|
136
|
+
c += staticAlpha * hash(floor(p/staticScale) + mod(iTime*500., 1e3));
|
|
152
137
|
|
|
153
138
|
// scan lines
|
|
154
|
-
const float scanlineScale =
|
|
155
|
-
const float scanlineAlpha = .
|
|
156
|
-
c *= 1.
|
|
139
|
+
const float scanlineScale = 2.;
|
|
140
|
+
const float scanlineAlpha = .3;
|
|
141
|
+
c *= 1. - scanlineAlpha*cos(p.y*2.*iResolution.y/scanlineScale);
|
|
142
|
+
|
|
143
|
+
{
|
|
144
|
+
// bloom effect
|
|
145
|
+
const float blurSize = .002;
|
|
146
|
+
const float bloomIntensity = .2;
|
|
147
|
+
|
|
148
|
+
// 5-tap Gaussian blur
|
|
149
|
+
vec4 bloom = vec4(0);
|
|
150
|
+
bloom += texture(iChannel0, p + vec2(-2.*blurSize, 0)) * .12;
|
|
151
|
+
bloom += texture(iChannel0, p + vec2( -blurSize, 0)) * .24;
|
|
152
|
+
bloom += texture(iChannel0, p) * .28;
|
|
153
|
+
bloom += texture(iChannel0, p + vec2( blurSize, 0)) * .24;
|
|
154
|
+
bloom += texture(iChannel0, p + vec2( 2.*blurSize, 0)) * .12;
|
|
155
|
+
bloom += texture(iChannel0, p + vec2(0, -2.*blurSize)) * .12;
|
|
156
|
+
bloom += texture(iChannel0, p + vec2(0, -blurSize)) * .24;
|
|
157
|
+
bloom += texture(iChannel0, p) * .28;
|
|
158
|
+
bloom += texture(iChannel0, p + vec2(0, blurSize)) * .24;
|
|
159
|
+
bloom += texture(iChannel0, p + vec2(0, 2.*blurSize)) * .12;
|
|
160
|
+
c += bloom * bloomIntensity;
|
|
161
|
+
}
|
|
157
162
|
|
|
158
163
|
// black vignette around edges
|
|
159
164
|
const float vignette = 2.;
|
|
@@ -336,7 +336,7 @@ Then increment it in the Brick.collideWithObject function.
|
|
|
336
336
|
And change that drawTextScreen code we had commented out in gameRenderPost to display the score. We can adjust the position and size of the text to fit at the top of the screen.
|
|
337
337
|
|
|
338
338
|
```javascript
|
|
339
|
-
LJS.drawTextScreen(
|
|
339
|
+
LJS.drawTextScreen('Score ' + score, vec2(LJS.mainCanvasSize.x/2, 70), 50); // show score
|
|
340
340
|
```
|
|
341
341
|
|
|
342
342
|

|
|
@@ -183,7 +183,7 @@ function gameRender()
|
|
|
183
183
|
///////////////////////////////////////////////////////////////////////////////
|
|
184
184
|
function gameRenderPost()
|
|
185
185
|
{
|
|
186
|
-
LJS.drawTextScreen(
|
|
186
|
+
LJS.drawTextScreen('Score ' + score, vec2(LJS.mainCanvasSize.x/2, 70), 50); // show score
|
|
187
187
|
}
|
|
188
188
|
|
|
189
189
|
///////////////////////////////////////////////////////////////////////////////
|
|
@@ -105,7 +105,7 @@ function htmlBuildStep(filename)
|
|
|
105
105
|
buffer += '<meta charset=utf-8>';
|
|
106
106
|
buffer += '</head>';
|
|
107
107
|
buffer += '<body>';
|
|
108
|
-
buffer +=
|
|
108
|
+
buffer += `<script src='index.js'></script>`;
|
|
109
109
|
|
|
110
110
|
// output html file
|
|
111
111
|
fs.writeFileSync(`${BUILD_FOLDER}/index.html`, buffer, {flag: 'w+'});
|
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
</head><body>
|
|
8
8
|
|
|
9
9
|
<!-- LittleJS Engine -->
|
|
10
|
-
<script src=../../dist/littlejs.js?
|
|
10
|
+
<script src=../../dist/littlejs.js?1136></script>
|
|
11
11
|
|
|
12
12
|
<!-- Add your game scripts here -->
|
|
13
|
-
<script src=game.js?
|
|
13
|
+
<script src=game.js?1136></script>
|
package/examples/empty/game.js
CHANGED
|
@@ -30,14 +30,14 @@
|
|
|
30
30
|
</head><body>
|
|
31
31
|
|
|
32
32
|
<!-- setup html menu system -->
|
|
33
|
-
<div class=
|
|
34
|
-
<div id=
|
|
35
|
-
<b style=
|
|
33
|
+
<div class=topDiv>
|
|
34
|
+
<div id=menu class=menuDiv>
|
|
35
|
+
<b style=font-size:50px>Test Menu</b>
|
|
36
36
|
This is an example menu using html elements.
|
|
37
|
-
<input id=
|
|
38
|
-
<input id=
|
|
39
|
-
<button id=
|
|
40
|
-
<button id=
|
|
37
|
+
<input id=input_test value='Test Input'>
|
|
38
|
+
<input id=input_rangeTest type=range>
|
|
39
|
+
<button id=button_test>Test Button</button>
|
|
40
|
+
<button id=button_exitMenu>Exit Menu</button>
|
|
41
41
|
</div>
|
|
42
42
|
</div>
|
|
43
43
|
|