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.
Files changed (58) hide show
  1. package/README.md +4 -3
  2. package/dist/littlejs.d.ts +395 -249
  3. package/dist/littlejs.esm.js +1550 -754
  4. package/dist/littlejs.esm.min.js +1 -1
  5. package/dist/littlejs.js +1528 -744
  6. package/dist/littlejs.min.js +1 -1
  7. package/dist/littlejs.release.js +1504 -720
  8. package/examples/box2d/game.js +4 -4
  9. package/examples/box2d/gameObjects.js +1 -1
  10. package/examples/breakout/game.js +30 -25
  11. package/examples/breakoutTutorial/README.md +1 -1
  12. package/examples/breakoutTutorial/game.js +1 -1
  13. package/examples/electron/build.js +1 -1
  14. package/examples/electron/index.html +2 -2
  15. package/examples/empty/game.js +1 -1
  16. package/examples/htmlMenu/index.html +7 -7
  17. package/examples/index.html +208 -97
  18. package/examples/platformer/gameEffects.js +20 -25
  19. package/examples/platformer/gameLevel.js +6 -1
  20. package/examples/shorts/base.html +1 -1
  21. package/examples/shorts/flappyGame.js +2 -1
  22. package/examples/shorts/helloWorld.js +1 -1
  23. package/examples/shorts/music.js +106 -0
  24. package/examples/shorts/parallax.js +71 -0
  25. package/examples/shorts/piano.js +7 -8
  26. package/examples/shorts/postProcess.js +25 -8
  27. package/examples/shorts/shapes.js +12 -18
  28. package/examples/shorts/song.mp3 +0 -0
  29. package/examples/shorts/uiSystem.js +15 -8
  30. package/examples/starter/index.html +2 -2
  31. package/examples/stress/index.html +14 -7
  32. package/examples/style.css +14 -4
  33. package/examples/typescript/build.js +1 -1
  34. package/examples/uiSystem/game.js +11 -11
  35. package/package.json +1 -1
  36. package/plugins/box2d.js +12 -10
  37. package/plugins/drawUtilities.js +5 -5
  38. package/plugins/newgrounds.js +6 -6
  39. package/plugins/pluginExport.js +1 -1
  40. package/plugins/uiSystem.js +103 -79
  41. package/plugins/zzfxm.js +10 -10
  42. package/reference.md +94 -56
  43. package/src/engine.js +28 -24
  44. package/src/engineAudio.js +284 -109
  45. package/src/engineBuild.js +11 -11
  46. package/src/engineDebug.js +29 -29
  47. package/src/engineDraw.js +285 -112
  48. package/src/engineExport.js +28 -16
  49. package/src/engineInput.js +57 -67
  50. package/src/engineMedals.js +25 -25
  51. package/src/engineObject.js +28 -25
  52. package/src/engineParticles.js +59 -59
  53. package/src/engineRelease.js +1 -1
  54. package/src/engineSettings.js +20 -13
  55. package/src/engineTileLayer.js +34 -35
  56. package/src/engineUtilities.js +66 -59
  57. package/src/engineWebGL.js +466 -66
  58. /package/examples/shorts/{playSound.js → sound.js} +0 -0
@@ -136,8 +136,8 @@ function gameUpdatePost()
136
136
  ///////////////////////////////////////////////////////////////////////////////
137
137
  function gameRender()
138
138
  {
139
- // draw a grey square in the background without using webgl
140
- LJS.drawRect(vec2(20,8), vec2(100), hsl(0,0,.8), 0, false);
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', 80, 80);
172
- drawText(Scenes.sceneName, 60, 100);
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 == 'number' ? vec2(size) : size; // square
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
- float noise(vec2 p)
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
- // put uv in texture pixel space
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
- // chromatic aberration
145
- const float chromatic = .002;
146
- c.r = texture(iChannel0, p - vec2(chromatic,0)).r;
147
- c.b = texture(iChannel0, p + vec2(chromatic,0)).b;
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 = 1e3;
155
- const float scanlineAlpha = .1;
156
- c *= 1. + scanlineAlpha*sin(p.y*scanlineScale);
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("Score " + score, vec2(LJS.mainCanvasSize.x/2, 70), 50); // show score
339
+ LJS.drawTextScreen('Score ' + score, vec2(LJS.mainCanvasSize.x/2, 70), 50); // show score
340
340
  ```
341
341
 
342
342
  ![LittleJS Screenshot](images/9.png)
@@ -183,7 +183,7 @@ function gameRender()
183
183
  ///////////////////////////////////////////////////////////////////////////////
184
184
  function gameRenderPost()
185
185
  {
186
- LJS.drawTextScreen("Score " + score, vec2(LJS.mainCanvasSize.x/2, 70), 50); // show score
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 += '<script src="index.js"></script>';
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?1133></script>
10
+ <script src=../../dist/littlejs.js?1136></script>
11
11
 
12
12
  <!-- Add your game scripts here -->
13
- <script src=game.js?1133></script>
13
+ <script src=game.js?1136></script>
@@ -1,6 +1,6 @@
1
1
  /*
2
2
  Little JS Hello World Demo
3
- - Just prints "Hello World!"
3
+ - Just prints 'Hello World!'
4
4
  - A good starting point for new projects
5
5
  */
6
6
 
@@ -30,14 +30,14 @@
30
30
  </head><body>
31
31
 
32
32
  <!-- setup html menu system -->
33
- <div class="topDiv">
34
- <div id="menu" class="menuDiv">
35
- <b style="font-size:50px">Test Menu</b>
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="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>
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