littlejsengine 1.9.9 → 1.10.2

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 (59) hide show
  1. package/README.md +6 -0
  2. package/dist/littlejs.d.ts +107 -14
  3. package/dist/littlejs.esm.js +250 -102
  4. package/dist/littlejs.esm.min.js +1 -1
  5. package/dist/littlejs.js +226 -98
  6. package/dist/littlejs.min.js +1 -1
  7. package/dist/littlejs.release.js +208 -95
  8. package/examples/box2d/game.js +29 -10
  9. package/examples/box2d/gameObjects.js +485 -0
  10. package/examples/box2d/index.html +7 -5
  11. package/examples/box2d/scenes.js +28 -247
  12. package/examples/box2d/tiles.png +0 -0
  13. package/examples/breakout/game.js +1 -1
  14. package/examples/breakout/index.html +5 -4
  15. package/examples/breakoutTutorial/index.html +4 -3
  16. package/examples/electron/game.js +1 -1
  17. package/examples/electron/index.html +4 -3
  18. package/examples/empty/game.js +1 -1
  19. package/examples/empty/index.html +2 -1
  20. package/examples/htmlMenu/game.js +67 -0
  21. package/examples/htmlMenu/index.html +56 -0
  22. package/examples/htmlMenu/tiles.png +0 -0
  23. package/examples/index.html +33 -0
  24. package/examples/js13k/game.js +1 -1
  25. package/examples/js13k/index.html +17 -14
  26. package/examples/module/game.js +1 -1
  27. package/examples/module/index.html +3 -2
  28. package/examples/particles/index.html +4 -3
  29. package/examples/platformer/game.js +1 -1
  30. package/examples/platformer/gameCharacter.js +1 -0
  31. package/examples/platformer/gameEffects.js +0 -2
  32. package/examples/platformer/gameLevel.js +2 -2
  33. package/examples/platformer/gameObjects.js +1 -2
  34. package/examples/platformer/index.html +10 -9
  35. package/examples/puzzle/game.js +1 -1
  36. package/examples/puzzle/index.html +4 -3
  37. package/examples/starter/game.js +5 -5
  38. package/examples/starter/index.html +15 -14
  39. package/examples/stress/index.html +3 -2
  40. package/examples/typescript/game.js +1 -1
  41. package/examples/typescript/index.html +3 -2
  42. package/examples/uiSystem/game.js +134 -0
  43. package/examples/uiSystem/index.html +25 -0
  44. package/examples/uiSystem/tiles.png +0 -0
  45. package/jsconfig.json +11 -0
  46. package/package.json +1 -1
  47. package/plugins/box2d.js +116 -42
  48. package/plugins/postProcess.js +6 -7
  49. package/plugins/uiSystem.js +243 -0
  50. package/src/engine.js +48 -20
  51. package/src/engineAudio.js +22 -25
  52. package/src/engineDebug.js +18 -3
  53. package/src/engineDraw.js +101 -27
  54. package/src/engineExport.js +23 -4
  55. package/src/engineInput.js +9 -5
  56. package/src/engineObject.js +15 -12
  57. package/src/engineSettings.js +1 -1
  58. package/src/engineUtilities.js +1 -1
  59. package/src/engineWebGL.js +11 -4
@@ -1,6 +1,18 @@
1
1
  /*
2
2
  LittleJS Box2D Example - Secenes
3
3
  - Each scene demonstrates a feature of Box2D
4
+ - Feel free to use tis code in your own projects
5
+ - 0 = Shapes: box, circle, poly, and edge
6
+ - 1 = Pyramid stack
7
+ - 2 = Dominoes chain reaction
8
+ - 3 = Car with controls
9
+ - 4 = Rope with box attached
10
+ - 5 = Raycasts in all directions
11
+ - 6 = Joints demo with every joint type
12
+ - 7 = Contacts begin and end callbacks
13
+ - 8 = Mobile object with multiple bodies
14
+ - 9 = Cloth object grid using rope joints
15
+ - 10 = Softbody object grid using weld joints
4
16
  */
5
17
 
6
18
  'use strict';
@@ -15,8 +27,8 @@ function loadScene(_scene)
15
27
 
16
28
  // destroy old scene
17
29
  engineObjectsDestroy();
18
- carWheelJoint = 0;
19
30
  mouseJoint = 0;
31
+ car = 0;
20
32
 
21
33
  // create walls
22
34
  groundObject = spawnBox(vec2(0,-4), vec2(1e3,8), hsl(0,0,.2), box2dBodyTypeStatic);
@@ -54,7 +66,7 @@ function loadScene(_scene)
54
66
  if (scene == 3)
55
67
  {
56
68
  sceneName = 'Car';
57
- spawnCar(vec2(10,2));
69
+ car = new CarObject(vec2(10,2));
58
70
  spawnBox(vec2(20,0), vec2(10,2), randColor(), box2dBodyTypeStatic, false, -.2);
59
71
  spawnPyramid(vec2(32,0), 6);
60
72
  }
@@ -99,29 +111,11 @@ function loadScene(_scene)
99
111
  l1.renderOrder = l2.renderOrder = -2;
100
112
  }
101
113
  {
102
- // pulley object renders a rope to connected point
103
- class PulleyObjects extends Box2dObject
104
- {
105
- constructor(pos, size, color, connectionPos)
106
- {
107
- super(pos, size, tile(3), 0, color);
108
- this.addBox(size);
109
- this.connectionPos = connectionPos;
110
- }
111
- render()
112
- {
113
- // draw rope
114
- const topPos = this.localToWorld(vec2(0,this.size.y/2));
115
- drawLine(topPos, this.connectionPos, .2, BLACK);
116
- super.render();
117
- }
118
- }
119
-
120
114
  // pulley joint
121
115
  const anchorA = vec2(14,15);
122
116
  const anchorB = vec2(26,15);
123
- const oA = new PulleyObjects(vec2(15,8), vec2(1,2), randColor(), anchorA);
124
- const oB = new PulleyObjects(vec2(25,8), vec2(1,2), randColor(), anchorB);
117
+ const oA = new PulleyJointObjects(vec2(15,8), vec2(1,2), randColor(), anchorA);
118
+ const oB = new PulleyJointObjects(vec2(25,8), vec2(1,2), randColor(), anchorB);
125
119
  const aA = spawnCircle(anchorA, 2, randColor(), box2dBodyTypeStatic);
126
120
  const aB = spawnCircle(anchorB, 2, randColor(), box2dBodyTypeStatic);
127
121
  const oaA = oA.localToWorld(vec2(0,oA.size.y/2));
@@ -156,31 +150,10 @@ function loadScene(_scene)
156
150
  box2dCreateDistanceJoint(o1, o2);
157
151
  }
158
152
  {
159
- // motor object renders a rope to connected point
160
- class MotorObject extends Box2dObject
161
- {
162
- constructor(pos, size, color, otherObject)
163
- {
164
- super(pos, size, tile(4), 0, color);
165
- this.addCircle(size.x);
166
- this.connectionPos = pos;
167
- const joint = box2dCreateMotorJoint(otherObject, this);
168
- joint.SetMaxForce(500);
169
- joint.SetMaxTorque(500);
170
- }
171
- render()
172
- {
173
- // draw rope
174
- const width = 2/(1+this.pos.distance(this.connectionPos));
175
- drawLine(this.pos, this.connectionPos, width, BLACK);
176
- super.render();
177
- }
178
- }
179
-
180
153
  // motor joint
181
154
  const o = new Box2dObject(vec2(10,8), vec2(4), tile(2), 0, randColor(), box2dBodyTypeStatic);
182
155
  o.renderOrder = -2;
183
- new MotorObject(vec2(10,8), vec2(2), randColor(), o);
156
+ new MotorJointObject(vec2(10,8), vec2(2), randColor(), o);
184
157
  }
185
158
  {
186
159
  // friction joint
@@ -194,26 +167,8 @@ function loadScene(_scene)
194
167
  if (scene == 7)
195
168
  {
196
169
  sceneName = 'Contacts';
197
- // changes objects color when touched
198
- class ContactTester extends Box2dObject
199
- {
200
- constructor(pos, size, color, contactColor, isSensor=false)
201
- {
202
- super(pos, size, 0, 0, color, box2dBodyTypeStatic);
203
- if (isSensor)
204
- {
205
- this.addCircle(size.x);
206
- this.setSensor(isSensor);
207
- }
208
- else
209
- this.addBox(size);
210
- this.contactColor = contactColor;
211
- }
212
- beginContact(other) { other.color = this.contactColor; }
213
- endContact(other) { other.color = WHITE; }
214
- }
215
- new ContactTester(vec2(15,8), vec2(5), hsl(0,0,0,.3), RED, true);
216
- new ContactTester(vec2(25,8), vec2(5), hsl(0,0,.1), GREEN);
170
+ new ContactTester(vec2(15,8), vec2(5), RED, RED);
171
+ new ContactTester(vec2(25,8), vec2(5), CYAN, CYAN, false, false);
217
172
  for (let i=200;i--;)
218
173
  spawnRandomObject(vec2(rand(1,39), rand(10,50)));
219
174
  }
@@ -221,192 +176,18 @@ function loadScene(_scene)
221
176
  {
222
177
  sceneName = 'Mobile';
223
178
  const pos = vec2(20, 16);
224
- const mobile = spawnMobile(pos, 12, 2, 5);
179
+ const mobile = new MobileObject(pos, 12, 2, 5);
225
180
  box2dCreateRevoluteJoint(groundObject, mobile, pos);
226
181
  }
227
-
228
- // helper functions
229
- function spawnRandomEdges()
230
- {
231
- // edge list along bottom
232
- const edgePoints = [];
233
- edgePoints.push(vec2(40,0));
234
- for (let i=40, y=0; i--;)
235
- edgePoints.push(vec2(i, y=clamp(y+rand(-2,2),0,5)));
236
- edgePoints.push(vec2(0,0));
237
- const o = new Box2dObject(vec2(), vec2(), 0, 0, BLACK, box2dBodyTypeStatic);
238
- o.addEdgeList(edgePoints);
239
- }
240
- function spawnRope(startPos, count, angle=PI, color=WHITE, size=vec2(.3,1))
241
- {
242
- let lastObject = groundObject;
243
- for (let i=0; i<count; ++i)
244
- {
245
- const pos = startPos.add(size.multiply(vec2(0,i+.5)).rotate(-angle));
246
- const o = spawnBox(pos, size, color, box2dBodyTypeDynamic, false, angle);
247
- o.setFilterData(2, 2);
248
- const anchorPos = pos.add(vec2(0,-size.y/2).rotate(-angle));
249
- box2dCreateRevoluteJoint(lastObject, o, anchorPos);
250
- lastObject = o;
251
- }
252
- const endPos = lastObject.localToWorld(vec2(0,-size.y/2));
253
- box2dCreateRopeJoint(groundObject, lastObject, startPos, endPos);
254
- return lastObject;
255
- }
256
- function spawnPyramid(pos, count)
257
- {
258
- for (let i=count+1;i--;)
259
- for (let j=i;j--;)
260
- spawnBox(pos.add(vec2(j-i/2+.5,count-i+.5)), 1, randColor());
261
- }
262
- function spawnDominoes(pos, count, size=vec2(.5,2))
263
- {
264
- for (let i=count; i--;)
265
- spawnBox(pos.add(vec2(i*size.y*.9,size.y/2)), size, randColor());
266
- }
267
- function spawnCar(pos)
268
- {
269
- // car object
270
- const car = new Box2dObject(pos, vec2(), 0, 0, randColor());
271
- const carPoints = [
272
- vec2(-1.5,-.5),
273
- vec2(1.5, -.5),
274
- vec2(1.5, 0),
275
- vec2(0, .9),
276
- vec2(-1.15,.9),
277
- vec2(-1.5, .2),
278
- ];
279
- car.addPoly(carPoints);
280
-
281
- // wheel settings
282
- const frequencyHz = 4;
283
- const dampingRatio = .7;
284
- const wheelDensity = 1;
285
- const wheelFriction = 2;
286
- const wheelRestitution = 0;
287
- const wheelSize = .8;
288
-
289
- // back wheel
290
- const wheel1Pos = pos.add(vec2(-1, -.65));
291
- const wheel1 = new Box2dObject(wheel1Pos, vec2(wheelSize), tile(4));
292
- wheel1.addCircle(wheelSize,vec2(),wheelDensity,wheelFriction,wheelRestitution);
293
- const joint1 = box2dCreateWheelJoint(car,wheel1);
294
- joint1.SetSpringDampingRatio(dampingRatio);
295
- joint1.SetSpringFrequencyHz(frequencyHz);
296
- joint1.SetMaxMotorTorque(50);
297
- joint1.EnableMotor(true);
298
- carWheelJoint = joint1;
299
-
300
- // front wheel
301
- const wheel2Pos = pos.add(vec2(1, -.6));
302
- const wheel2 = new Box2dObject(wheel2Pos, vec2(wheelSize), tile(4));
303
- wheel2.addCircle(wheelSize,vec2(),wheelDensity,wheelFriction,wheelRestitution);
304
- const joint2 = box2dCreateWheelJoint(car,wheel2);
305
- joint2.SetSpringDampingRatio(dampingRatio);
306
- joint2.SetSpringFrequencyHz(frequencyHz);
307
- }
308
- function spawnMobile(anchor, w, h, depth)
309
- {
310
- // tall box
311
- const pos = anchor.add(vec2(0,-h/2));
312
- const o = spawnBox(pos, vec2(h/4, h), randColor(), box2dBodyTypeDynamic, false);
313
- if (--depth)
314
- {
315
- // long box on bottom
316
- o.addBox(vec2(w, h/4), vec2(0, -h/2));
317
-
318
- // spawn smaller mobiles attached to each side
319
- for(let i=2; i--;)
320
- {
321
- const a = anchor.add(vec2( w/2*(i?1:-1), -h));
322
- const o2 = spawnMobile(a, w/2, h, depth);
323
- box2dCreateRevoluteJoint(o, o2, a);
324
- }
325
- }
326
- return o;
327
- }
328
- }
329
-
330
- ///////////////////////////////////////////////////////////////////////////////
331
- // Spawn object functions
332
-
333
- function spawnBox(pos, size=1, color=WHITE, type=box2dBodyTypeDynamic, applyTexture=true, angle=0)
334
- {
335
- size = typeof size == 'number' ? vec2(size) : size; // square
336
- const o = new Box2dObject(pos, size, applyTexture && tile(3), angle, color, type);
337
- o.addBox(size);
338
- return o;
339
- }
340
-
341
- function spawnCircle(pos, diameter=1, color=WHITE, type=box2dBodyTypeDynamic, applyTexture=true, angle=0)
342
- {
343
- const size = vec2(diameter);
344
- const o = new Box2dObject(pos, size, applyTexture && tile(2), angle, color, type);
345
- o.addCircle(diameter);
346
- return o;
347
- }
348
-
349
- function spawnRandomPoly(pos, diameter=1, color=WHITE, type=box2dBodyTypeDynamic, angle=0)
350
- {
351
- const o = new Box2dObject(pos, vec2(), 0, angle, color, type);
352
- o.addRandomPoly(diameter);
353
- return o;
354
- }
355
-
356
- function spawnRandomObject(pos, scale=1, type=box2dBodyTypeDynamic, angle=0)
357
- {
358
- if (randInt(2))
182
+ if (scene == 9)
359
183
  {
360
- const size = vec2(scale*rand(.5,1), scale*rand(.5,1));
361
- return spawnBox(pos, size, randColor(), type, true, angle);
184
+ sceneName = 'Cloth';
185
+ new ClothObject(vec2(20, 9), vec2(15), vec2(24), randColor());
362
186
  }
363
- else
364
- {
365
- const diameter = scale*rand(.5,1);
366
- return spawnCircle(pos, diameter, randColor(), type, true, angle);
367
- }
368
- }
369
-
370
- ///////////////////////////////////////////////////////////////////////////////
371
- // Effects
372
-
373
- const sound_click = new Sound([,.1]);
374
- const sound_explosion = new Sound([,.2,72,.01,.01,.2,4,,,,,,,1,,.5,.1,.5,.02]);
375
-
376
- function explosion(pos, radius=3, strength=300)
377
- {
378
- sound_explosion.play(pos);
379
- const objects = box2dCircleCastAll(pos, (radius*2));
380
- const newColor = randColor();
381
- for (const o of objects)
187
+ if (scene == 10)
382
188
  {
383
- const p = percent(o.pos.distance(pos), 2*radius, radius);
384
- const force = o.pos.subtract(pos).normalize(p*radius*strength);
385
- o.applyForce(force);
386
- o.color = newColor;
189
+ sceneName = 'Softbodies';
190
+ for(let i=3;i--;)
191
+ new SoftBodyObject(vec2(20, 3+i*7), vec2(6-i), vec2(9-i), randColor());
387
192
  }
388
-
389
- // smoke
390
- new ParticleEmitter(
391
- pos, 0, // pos, angle
392
- radius/2, .2, 50*radius, PI,// emitSize, emitTime, emitRate, emiteCone
393
- tile(1), // tileInfo
394
- hsl(0,0,0), hsl(0,0,0), // colorStartA, colorStartB
395
- hsl(0,0,0,0), hsl(0,0,0,0), // colorEndA, colorEndB
396
- 1, 1, 2, .1, .1, // time, sizeStart, sizeEnd, speed, angleSpeed
397
- .9, 1, -.5, PI, .1, // damp, angleDamp, gravity, particleCone, fade
398
- 1, 0, 0, 0, 1e8 // randomness, collide, additive, colorLinear, renderOrder
399
- );
400
-
401
- // fire
402
- new ParticleEmitter(
403
- pos, 0, // pos, angle
404
- radius, .1, 100*radius, PI, // emitSize, emitTime, emitRate, emiteCone
405
- tile(1), // tileInfo
406
- hsl(0,1,.5), hsl(.15,1,.5), // colorStartA, colorStartB
407
- hsl(0,1,.5,0), hsl(.1, 1,.5,0), // colorEndA, colorEndB
408
- .7, 1, .5, .1, .1, // time, sizeStart, sizeEnd, speed, angleSpeed
409
- .9, 1, 0, PI, .05, // damp, angleDamp, gravity, particleCone, fade
410
- 1, 0, 1, 0, 1e9 // randomness, collide, additive, colorLinear, renderOrder
411
- );
412
- }
193
+ }
Binary file
@@ -135,4 +135,4 @@ function setupPostProcess()
135
135
 
136
136
  ///////////////////////////////////////////////////////////////////////////////
137
137
  // Startup LittleJS Engine
138
- engineInit(gameInit, gameUpdate, gameUpdatePost, gameRender, gameRenderPost);
138
+ engineInit(gameInit, gameUpdate, gameUpdatePost, gameRender, gameRenderPost, ['tiles.png']);
@@ -1,11 +1,12 @@
1
1
  <!DOCTYPE html><head>
2
- <title>Little JS Breakout Game</title>
2
+ <title>LittleJS Breakout Game</title>
3
+ <meta charset=utf-8>
3
4
  <meta name=apple-mobile-web-app-capable content=yes>
4
5
  <meta name=mobile-web-app-capable content=yes>
5
6
  <link rel=icon type=image/png href=../favicon.png>
6
7
  </head><body>
7
8
 
8
- <script src=../../dist/littlejs.js?197></script>
9
+ <script src=../../dist/littlejs.js?1100></script>
9
10
  <script src=../../plugins/postProcess.js></script>
10
- <script src=gameObjects.js?197></script>
11
- <script src=game.js?197></script>
11
+ <script src=gameObjects.js?1100></script>
12
+ <script src=game.js?1100></script>
@@ -1,9 +1,10 @@
1
1
  <!DOCTYPE html><head>
2
- <title>Little JS Breakout Tutorial</title>
2
+ <title>LittleJS Breakout Tutorial</title>
3
+ <meta charset=utf-8>
3
4
  <meta name=apple-mobile-web-app-capable content=yes>
4
5
  <meta name=mobile-web-app-capable content=yes>
5
6
  <link rel=icon type=image/png href=../favicon.png>
6
7
  </head><body>
7
8
 
8
- <script src=../../dist/littlejs.js?197></script>
9
- <script src=game.js?197></script>
9
+ <script src=../../dist/littlejs.js?1100></script>
10
+ <script src=game.js?1100></script>
@@ -125,4 +125,4 @@ function gameRenderPost()
125
125
 
126
126
  ///////////////////////////////////////////////////////////////////////////////
127
127
  // Startup LittleJS Engine
128
- engineInit(gameInit, gameUpdate, gameUpdatePost, gameRender, gameRenderPost);
128
+ engineInit(gameInit, gameUpdate, gameUpdatePost, gameRender, gameRenderPost, ['tiles.png']);
@@ -1,12 +1,13 @@
1
1
  <!DOCTYPE html><head>
2
- <title>Little JS Electron Demo</title>
2
+ <title>LittleJS Electron Demo</title>
3
+ <meta charset=utf-8>
3
4
  <meta name=apple-mobile-web-app-capable content=yes>
4
5
  <meta name=mobile-web-app-capable content=yes>
5
6
  <link rel=icon type=image/png href=../favicon.png>
6
7
  </head><body>
7
8
 
8
9
  <!-- LittleJS Engine -->
9
- <script src=../../dist/littlejs.js?197></script>
10
+ <script src=../../dist/littlejs.js?1100></script>
10
11
 
11
12
  <!-- Add your game scripts here -->
12
- <script src=game.js?197></script>
13
+ <script src=game.js?1100></script>
@@ -44,4 +44,4 @@ function gameRenderPost()
44
44
 
45
45
  ///////////////////////////////////////////////////////////////////////////////
46
46
  // Startup LittleJS Engine
47
- engineInit(gameInit, gameUpdate, gameUpdatePost, gameRender, gameRenderPost);
47
+ engineInit(gameInit, gameUpdate, gameUpdatePost, gameRender, gameRenderPost, ['tiles.png']);
@@ -1,5 +1,6 @@
1
1
  <!DOCTYPE html><head>
2
- <title>Little JS Hello World Demo</title>
2
+ <title>LittleJS Hello World Demo</title>
3
+ <meta charset=utf-8>
3
4
  </head><body>
4
5
 
5
6
  <script src=../../dist/littlejs.js></script>
@@ -0,0 +1,67 @@
1
+ /*
2
+ Little JS HTML Menu Example Project
3
+ - Setup a simple html menu system
4
+ - Menu can be toggled
5
+ - Pauses game when menu is visible
6
+ - Shows several input types
7
+ */
8
+
9
+ 'use strict';
10
+
11
+ // show the LittleJS splash screen
12
+ setShowSplashScreen(true);
13
+
14
+ // sound effects
15
+ const sound_click = new Sound([1,.5]);
16
+
17
+ ///////////////////////////////////////////////////////////////////////////////
18
+ function gameInit()
19
+ {
20
+ // show menu for demo
21
+ setMenuVisible(true);
22
+ }
23
+
24
+ ///////////////////////////////////////////////////////////////////////////////
25
+ function gameUpdate()
26
+ {
27
+ // play sound when mouse is pressed
28
+ if (mouseWasPressed(0))
29
+ sound_click.play(mousePos);
30
+ }
31
+
32
+ ///////////////////////////////////////////////////////////////////////////////
33
+ function gameUpdatePost()
34
+ {
35
+ // pause game when menu is visible
36
+ const menuVisible = getMenuVisible();
37
+ paused = menuVisible;
38
+
39
+ // toggle menu visibility
40
+ if (keyWasPressed('KeyM'))
41
+ setMenuVisible(!menuVisible);
42
+ }
43
+
44
+ ///////////////////////////////////////////////////////////////////////////////
45
+ function gameRender()
46
+ {
47
+ // test game rendering
48
+ drawRect(vec2(), vec2(1e3), hsl(0,0,.2));
49
+ for(let i=0; i<1e3; ++i)
50
+ {
51
+ const pos = vec2(30*Math.sin(i+time/9),20*Math.sin(i*i+time/9));
52
+ drawTile(pos, vec2(2), tile(3,128), hsl(i/9,1,.4), time+i, !(i%2), hsl(i/9,1,.1,0));
53
+ }
54
+ }
55
+
56
+ ///////////////////////////////////////////////////////////////////////////////
57
+ function gameRenderPost()
58
+ {
59
+ // draw to overlay canvas for hud rendering
60
+ drawTextScreen('LittleJS HTML Menu Example\nM = Toggle menu',
61
+ vec2(mainCanvasSize.x/2, 70), 60, // position, size
62
+ hsl(0,0,1), 6, hsl(0,0,0)); // color, outline size and color
63
+ }
64
+
65
+ ///////////////////////////////////////////////////////////////////////////////
66
+ // Startup LittleJS Engine
67
+ engineInit(gameInit, gameUpdate, gameUpdatePost, gameRender, gameRenderPost, ['tiles.png']);
@@ -0,0 +1,56 @@
1
+ <!DOCTYPE html><head>
2
+ <title>LittleJS HTML Menu Example</title>
3
+ <meta charset=utf-8>
4
+ <meta name=apple-mobile-web-app-capable content=yes>
5
+ <meta name=mobile-web-app-capable content=yes>
6
+ <link rel=icon type=image/png href=../favicon.png>
7
+ <style>
8
+ .topDiv
9
+ {
10
+ position: absolute;
11
+ z-index: 1;
12
+ width: 100%;
13
+ height: 100%;
14
+ display: flex;
15
+ align-items: center;
16
+ justify-content: center;
17
+ }
18
+ .menuDiv
19
+ {
20
+ gap: 20px;
21
+ padding: 30px;
22
+ display: flex;
23
+ align-items: center;
24
+ flex-direction: column;
25
+ border: 3px solid black;
26
+ background-color: white;
27
+ }
28
+ </style>
29
+
30
+ </head><body>
31
+
32
+ <!-- setup html menu system -->
33
+ <div class="topDiv">
34
+ <div id="menu" class="menuDiv">
35
+ <h1><i style="font-size:30px">Test Menu</i></h1>
36
+ This is an example menu using html elements.
37
+ <input value="Test Input" onchange="alert('New text: ' + this.value)">
38
+ <input type="range" onchange="alert('New value: ' + this.value)">
39
+ <button onclick="alert('Button was clicked!')">Test Button</button>
40
+ <button onclick="setMenuVisible(false)">Exit Menu</button>
41
+ </div>
42
+ </div>
43
+ <script>
44
+
45
+ // html menu system
46
+ const getMenuVisible =()=> menu.style.visibility != 'hidden';
47
+ const setMenuVisible =(visible)=> menu.style.visibility = visible ? '' : 'hidden';
48
+
49
+ // hide menu at start
50
+ setMenuVisible(false);
51
+
52
+ </script>
53
+
54
+ <!-- Add your game scripts here -->
55
+ <script src=../../dist/littlejs.js?1100></script>
56
+ <script src=game.js?1100></script>
Binary file
@@ -0,0 +1,33 @@
1
+ <head>
2
+ <title>LittleJS Examples</title>
3
+ <link rel=icon type=image/png href=../favicon.png>
4
+ <body>
5
+ <h1>All LittleJS Engine Examples</h1>
6
+ <p>
7
+ <img src=screenshot.jpg width=500>
8
+ </p>
9
+ <h2>Main Demos</h2>
10
+ <p>
11
+ <a href="starter">Starter</a> - Clean example with only a few things to get you started<br>
12
+ <a href="stress">Stress</a> - Max sprite/object test and music system demo<br>
13
+ <a href="platformer">Platformer</a> - Platformer/shooter with level data from Tiled Editor<br>
14
+ <a href="breakout">Breakout</a> - Block breaking game with post-processing effects<br>
15
+ <a href="breakoutTutorial">Breakout Tutorial</a> - Tutorial Breakout example<br>
16
+ <a href="puzzle">Puzzle</a> - Match 3 puzzle game with HD rendering and high score tracking<br>
17
+ <a href="particles">Particle Designer</a> - Particle system editor and visualizer<br>
18
+ <a href="js13k">JS13K Starter</a> - Special small size demo for JS13K Games<br>
19
+ <a href="empty">Empty</a> - A blank hello world project for LittleJS<br>
20
+ </p>
21
+ <h2>Plugin Demos</h2>
22
+ <p>
23
+ <a href="box2d">Box2D</a> - Box2D plugin demonstration and testbed<br>
24
+ <a href="uiSystem">UI System</a> - A simple hierarchical UI system using LittleJS rendering<br>
25
+ <a href="htmlMenu">HTML UI Menu</a> - Example using html to create an overlay menu<br>
26
+ </p>
27
+ <h2>Environment Demos</h2>
28
+ <p>
29
+ <a href="module">LittleJS using modules</a> - Loads LittleJS as a module<br>
30
+ <a href="typescript">LittleJS using TypeScript</a> - Uses LittleJS type definitions<br>
31
+ <a href="electron">LittleJS building with Electron</a> - Builds to an executable<br>
32
+ </p>
33
+ </body>
@@ -112,4 +112,4 @@ function gameRenderPost()
112
112
 
113
113
  ///////////////////////////////////////////////////////////////////////////////
114
114
  // Startup LittleJS Engine
115
- engineInit(gameInit, gameUpdate, gameUpdatePost, gameRender, gameRenderPost);
115
+ engineInit(gameInit, gameUpdate, gameUpdatePost, gameRender, gameRenderPost, ['tiles.png']);
@@ -1,18 +1,21 @@
1
- <head><title>LittleJS JS13K Project</title></head><body>
1
+ <head>
2
+ <title>LittleJS JS13K Project</title>
3
+ <meta charset=utf-8>
4
+ </head><body>
2
5
 
3
6
  <!-- LittleJS Engine -->
4
- <script src=../../src/engineDebug.js?197></script>
5
- <script src=../../src/engineUtilities.js?197></script>
6
- <script src=../../src/engineSettings.js?197></script>
7
- <script src=../../src/engineObject.js?197></script>
8
- <script src=../../src/engineDraw.js?197></script>
9
- <script src=../../src/engineInput.js?197></script>
10
- <script src=../../src/engineAudio.js?197></script>
11
- <script src=../../src/engineTileLayer.js?197></script>
12
- <script src=../../src/engineParticles.js?197></script>
13
- <script src=../../src/engineMedals.js?197></script>
14
- <script src=../../src/engineWebGL.js?197></script>
15
- <script src=../../src/engine.js?197></script>
7
+ <script src=../../src/engineDebug.js?1100></script>
8
+ <script src=../../src/engineUtilities.js?1100></script>
9
+ <script src=../../src/engineSettings.js?1100></script>
10
+ <script src=../../src/engineObject.js?1100></script>
11
+ <script src=../../src/engineDraw.js?1100></script>
12
+ <script src=../../src/engineInput.js?1100></script>
13
+ <script src=../../src/engineAudio.js?1100></script>
14
+ <script src=../../src/engineTileLayer.js?1100></script>
15
+ <script src=../../src/engineParticles.js?1100></script>
16
+ <script src=../../src/engineMedals.js?1100></script>
17
+ <script src=../../src/engineWebGL.js?1100></script>
18
+ <script src=../../src/engine.js?1100></script>
16
19
 
17
20
  <!-- Add your game scripts here -->
18
- <script src=game.js?197></script>
21
+ <script src=game.js?1100></script>
@@ -128,4 +128,4 @@ function gameRenderPost()
128
128
 
129
129
  ///////////////////////////////////////////////////////////////////////////////
130
130
  // Startup LittleJS Engine
131
- LittleJS.engineInit(gameInit, gameUpdate, gameUpdatePost, gameRender, gameRenderPost);
131
+ LittleJS.engineInit(gameInit, gameUpdate, gameUpdatePost, gameRender, gameRenderPost, ['tiles.png']);
@@ -1,9 +1,10 @@
1
1
  <!DOCTYPE html><head>
2
- <title>Little JS Module Demo</title>
2
+ <title>LittleJS Module Demo</title>
3
+ <meta charset=utf-8>
3
4
  <meta name=apple-mobile-web-app-capable content=yes>
4
5
  <meta name=mobile-web-app-capable content=yes>
5
6
  <link rel=icon type=image/png href=../favicon.png>
6
7
  </head><body>
7
8
 
8
9
  <!-- Add your game scripts here -->
9
- <script src=game.js?197 type=module></script>
10
+ <script src=game.js?1100 type=module></script>