littlejsengine 1.14.19 → 1.14.28

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 (70) hide show
  1. package/dist/littlejs.d.ts +217 -38
  2. package/dist/littlejs.esm.js +879 -324
  3. package/dist/littlejs.esm.min.js +1 -1
  4. package/dist/littlejs.js +861 -324
  5. package/dist/littlejs.min.js +1 -1
  6. package/dist/littlejs.release.js +799 -325
  7. package/examples/box2d/gameObjects.js +6 -10
  8. package/examples/box2d/scenes.js +2 -2
  9. package/examples/breakout/gameObjects.js +1 -1
  10. package/examples/electron/game.js +1 -41
  11. package/examples/electron/index.html +2 -2
  12. package/examples/htmlMenu/game.js +1 -1
  13. package/examples/index.html +19 -10
  14. package/examples/module/game.js +5 -7
  15. package/examples/particles/index.html +6 -9
  16. package/examples/platformer/gameCharacter.js +4 -3
  17. package/examples/platformer/gameEffects.js +7 -2
  18. package/examples/platformer/gameObjects.js +6 -11
  19. package/examples/shorts/animation.js +2 -2
  20. package/examples/shorts/base.html +4 -1
  21. package/examples/shorts/box2d.js +2 -2
  22. package/examples/shorts/box2dCar.js +18 -7
  23. package/examples/shorts/box2dPool.js +108 -0
  24. package/examples/shorts/cameraDrag.js +22 -0
  25. package/examples/shorts/debugDraw.js +37 -0
  26. package/examples/shorts/flappyGame.js +1 -0
  27. package/examples/shorts/fps.js +90 -0
  28. package/examples/shorts/helloWorld.js +1 -1
  29. package/examples/shorts/hillGlideGame.js +1 -3
  30. package/examples/shorts/input.js +59 -0
  31. package/examples/shorts/landerGame.js +1 -3
  32. package/examples/shorts/medals.js +15 -9
  33. package/examples/shorts/music.js +15 -17
  34. package/examples/shorts/musicPlayer.js +24 -24
  35. package/examples/shorts/platformer.js +0 -2
  36. package/examples/shorts/postProcess.js +1 -1
  37. package/examples/shorts/sequencer.js +3 -3
  38. package/examples/shorts/slidingPuzzle.js +1 -1
  39. package/examples/shorts/spaceGame.js +1 -3
  40. package/examples/shorts/spriteAtlas.js +6 -8
  41. package/examples/shorts/starfield.js +1 -1
  42. package/examples/shorts/tileRaycast.js +39 -0
  43. package/examples/shorts/tiles.png +0 -0
  44. package/examples/shorts/tiltedView.js +1 -4
  45. package/examples/shorts/timers.js +1 -2
  46. package/examples/shorts/topDown.js +0 -2
  47. package/examples/starter/game.js +5 -7
  48. package/examples/starter/index.html +2 -2
  49. package/examples/typescript/game.js +3 -2
  50. package/examples/typescript/game.ts +5 -7
  51. package/examples/uiSystem/game.js +2 -2
  52. package/package.json +1 -1
  53. package/plugins/box2d.js +170 -50
  54. package/plugins/pluginExport.js +2 -0
  55. package/plugins/uiSystem.js +55 -27
  56. package/src/engine.js +19 -16
  57. package/src/engineAudio.js +27 -15
  58. package/src/engineDebug.js +64 -0
  59. package/src/engineDraw.js +88 -32
  60. package/src/engineExport.js +16 -0
  61. package/src/engineInput.js +35 -25
  62. package/src/engineMedals.js +2 -2
  63. package/src/engineObject.js +55 -10
  64. package/src/engineParticles.js +36 -20
  65. package/src/engineRelease.js +2 -1
  66. package/src/engineSettings.js +20 -1
  67. package/src/engineTileLayer.js +64 -59
  68. package/src/engineUtilities.js +213 -59
  69. package/src/engineWebGL.js +13 -8
  70. package/examples/shorts/raycasting.js +0 -79
@@ -1,5 +1,3 @@
1
- let spriteAtlas;
2
-
3
1
  function gameInit()
4
2
  {
5
3
  // create a table of all sprites
@@ -18,12 +16,12 @@ function gameInit()
18
16
  function gameRender()
19
17
  {
20
18
  // draw a sprite from the atlas
21
- let pos = vec2(Math.sin(time)*5,-3);// world position
22
- let angle = 0; // world space angle
23
- let size = vec2(9); // world space size
24
- let mirror = 0; // should tile be mirrored?
25
- let color = hsl(0,0,1); // color to multiply by
26
- let additive = hsl(0,0,0,0); // color to add to
19
+ let pos = vec2(sin(time)*5,-3);// world position
20
+ let angle = 0; // world space angle
21
+ let size = vec2(9); // world space size
22
+ let mirror = 0; // should tile be mirrored?
23
+ let color = hsl(0,0,1); // color to multiply by
24
+ let additive = hsl(0,0,0,0); // color to add to
27
25
  drawTile(pos, size, spriteAtlas.iconBig, color, angle, mirror, additive);
28
26
 
29
27
  // draw more sprites from the atlas
@@ -9,7 +9,7 @@ function gameRender()
9
9
  pos.x = offset%70 - 35;
10
10
  pos.y = i/110 - 9;
11
11
  size.x = size.y = i%.11 + .07;
12
- color.set(1,1,1,Math.sin(i)**4);
12
+ color.set(1,1,1,sin(i)**4);
13
13
  drawRect(pos, size, color);
14
14
  }
15
15
  }
@@ -0,0 +1,39 @@
1
+ function gameInit()
2
+ {
3
+ // create tile layer
4
+ const pos = vec2();
5
+ const tileLayer = new TileCollisionLayer(pos, vec2(28,16), 0);
6
+ cameraPos = tileLayer.size.scale(.5); // setup camera
7
+ for (pos.x = tileLayer.size.x; pos.x--;)
8
+ for (pos.y = tileLayer.size.y; pos.y--;)
9
+ {
10
+ // create random solid tiles away from level center
11
+ if (rand() < .7 || cameraPos.distanceSquared(pos) < 9)
12
+ continue;
13
+
14
+ // set tile data
15
+ const data = new TileLayerData(1);
16
+ tileLayer.setData(pos, data);
17
+ tileLayer.setCollisionData(pos);
18
+ }
19
+ tileLayer.redraw();
20
+ }
21
+
22
+ function gameRenderPost()
23
+ {
24
+ // cast ray from camera center to mouse
25
+ drawLine(cameraPos, mousePos, .1, CYAN);
26
+ const normal = vec2();
27
+ const hit = tileCollisionRaycast(cameraPos, mousePos, 0, normal);
28
+ if (hit)
29
+ {
30
+ // draw hit tile
31
+ const tilePos = hit.floor().add(vec2(.5));
32
+ drawRect(tilePos, vec2(1), RED);
33
+
34
+ // draw hit point and normal
35
+ drawRect(hit, vec2(.2), GREEN);
36
+ drawLine(cameraPos, hit, .1, RED);
37
+ drawLine(hit, hit.add(normal), .1, YELLOW);
38
+ }
39
+ }
Binary file
@@ -3,14 +3,13 @@ class GameObject extends EngineObject
3
3
  update()
4
4
  {
5
5
  this.renderOrder = -this.pos.y; // sort by y position
6
- super.update();
7
6
  }
8
7
 
9
8
  render()
10
9
  {
11
10
  // adjust draw postion to be at the bottom of the object
12
11
  const drawSize = this.drawSize || this.size;
13
- const offset = vec2(0,drawSize.y/2).rotate(this.angle);
12
+ const offset = this.getUp(drawSize.y/2);
14
13
  const pos = this.pos.add(offset);
15
14
  drawTile(pos, drawSize, this.tileInfo, this.color, this.angle);
16
15
  }
@@ -20,8 +19,6 @@ class Player extends GameObject
20
19
  {
21
20
  update()
22
21
  {
23
- super.update();
24
-
25
22
  // apply movement controls
26
23
  const moveInput = keyDirection().clampLength(1).scale(.2);
27
24
  this.velocity = this.velocity.add(moveInput);
@@ -1,5 +1,4 @@
1
- let timerButton, timerSlider;
2
- let timerSound = new Sound([2,0,999,,,,,1.5,,.3,-99,.1,1.63,,,.11]);
1
+ const timerSound = new Sound([2,0,999,,,,,1.5,,.3,-99,.1,1.63,,,.11]);
3
2
 
4
3
  function gameInit()
5
4
  {
@@ -9,8 +9,6 @@ class Player extends EngineObject
9
9
 
10
10
  update()
11
11
  {
12
- super.update();
13
-
14
12
  // apply movement controls
15
13
  const moveInput = keyDirection().clampLength(1).scale(.2);
16
14
  this.velocity = this.velocity.add(moveInput);
@@ -65,16 +65,17 @@ function gameInit()
65
65
  // create particle emitter
66
66
  particleEmitter = new ParticleEmitter(
67
67
  vec2(16,9), 0, // emitPos, emitAngle
68
- 0, 0, 500, PI, // emitSize, emitTime, rate, cone
68
+ 0, 0, 500, 3.14, // emitSize, emitTime, rate, cone
69
69
  tile(0, 16), // tileIndex, tileSize
70
70
  hsl(1,1,1), hsl(0,0,0), // colorStartA, colorStartB
71
71
  hsl(0,0,0,0), hsl(0,0,0,0), // colorEndA, colorEndB
72
- 1, .2, .2, .1, .05, // time, sizeStart, sizeEnd, speed, angleSpeed
73
- .99, 1, 1, PI, // damping, angleDamping, gravityScale, cone
74
- .05, .5, true, true // fadeRate, randomness, collide, additive
72
+ 1, .2, .2, .1, .05, // time, sizeStart, sizeEnd, speed, angleSpeed
73
+ .99, 1, 1, 3.14, // damping, angleDamping, gravityScale, cone
74
+ .05, .5, true, true // fadeRate, randomness, collide, additive
75
75
  );
76
76
  particleEmitter.restitution = .3; // bounce when it collides
77
77
  particleEmitter.trailScale = 2; // stretch as it moves
78
+ particleEmitter.velocityInheritance = .3; // inherit emitter velocity
78
79
  }
79
80
 
80
81
  ///////////////////////////////////////////////////////////////////////////////
@@ -104,10 +105,7 @@ function gameUpdate()
104
105
 
105
106
  // move particles to mouse location if on screen
106
107
  if (mousePosScreen.x)
107
- {
108
108
  particleEmitter.pos = mousePos;
109
- particleEmitter.velocity = mouseDelta.scale(.3*timeDelta);
110
- }
111
109
  }
112
110
 
113
111
  ///////////////////////////////////////////////////////////////////////////////
@@ -7,7 +7,7 @@
7
7
  </head><body>
8
8
 
9
9
  <!-- LittleJS Engine -->
10
- <script src=../../dist/littlejs.js?11417></script>
10
+ <script src=../../dist/littlejs.js?1.15.0></script>
11
11
 
12
12
  <!-- LittleJS Engine Source
13
13
  <script src=../../src/engineDebug.js></script>
@@ -31,4 +31,4 @@
31
31
  -->
32
32
 
33
33
  <!-- Add your game scripts here -->
34
- <script src=game.js?11417></script>
34
+ <script src=game.js?1.15.0></script>
@@ -52,16 +52,17 @@ function gameInit() {
52
52
  LJS.setGravity(vec2(0, -.01));
53
53
  // create particle emitter
54
54
  particleEmitter = new LJS.ParticleEmitter(vec2(16, 9), 0, // emitPos, emitAngle
55
- 1, 0, 500, Math.PI, // emitSize, emitTime, rate, cone
55
+ 0, 0, 500, 3.14, // emitSize, emitTime, rate, cone
56
56
  tile(0, 16), // tileIndex, tileSize
57
57
  hsl(1, 1, 1), hsl(0, 0, 0), // colorStartA, colorStartB
58
58
  hsl(0, 0, 0, 0), hsl(0, 0, 0, 0), // colorEndA, colorEndB
59
59
  1, .2, .2, .1, .05, // time, sizeStart, sizeEnd, speed, angleSpeed
60
- .99, 1, 1, Math.PI, // damping, angleDamping, gravityScale, cone
60
+ .99, 1, 1, 3.14, // damping, angleDamping, gravityScale, cone
61
61
  .05, .5, true, true // fadeRate, randomness, collide, additive
62
62
  );
63
63
  particleEmitter.restitution = .3; // bounce when it collides
64
64
  particleEmitter.trailScale = 2; // stretch as it moves
65
+ particleEmitter.velocityInheritance = .3; // inherit emitter velocity
65
66
  }
66
67
  ///////////////////////////////////////////////////////////////////////////////
67
68
  function gameUpdate() {
@@ -69,16 +69,17 @@ function gameInit()
69
69
  // create particle emitter
70
70
  particleEmitter = new LJS.ParticleEmitter(
71
71
  vec2(16,9), 0, // emitPos, emitAngle
72
- 1, 0, 500, Math.PI, // emitSize, emitTime, rate, cone
72
+ 0, 0, 500, 3.14, // emitSize, emitTime, rate, cone
73
73
  tile(0, 16), // tileIndex, tileSize
74
74
  hsl(1,1,1), hsl(0,0,0), // colorStartA, colorStartB
75
75
  hsl(0,0,0,0), hsl(0,0,0,0), // colorEndA, colorEndB
76
- 1, .2, .2, .1, .05, // time, sizeStart, sizeEnd, speed, angleSpeed
77
- .99, 1, 1, Math.PI, // damping, angleDamping, gravityScale, cone
78
- .05, .5, true, true // fadeRate, randomness, collide, additive
76
+ 1, .2, .2, .1, .05, // time, sizeStart, sizeEnd, speed, angleSpeed
77
+ .99, 1, 1, 3.14, // damping, angleDamping, gravityScale, cone
78
+ .05, .5, true, true // fadeRate, randomness, collide, additive
79
79
  );
80
80
  particleEmitter.restitution = .3; // bounce when it collides
81
81
  particleEmitter.trailScale = 2; // stretch stretch as it moves
82
+ particleEmitter.velocityInheritance = .3; // inherit emitter velocity
82
83
  }
83
84
 
84
85
  ///////////////////////////////////////////////////////////////////////////////
@@ -101,10 +102,7 @@ function gameUpdate()
101
102
 
102
103
  // move particles to mouse location if on screen
103
104
  if (LJS.mousePosScreen.x)
104
- {
105
105
  particleEmitter.pos = LJS.mousePos;
106
- particleEmitter.velocity = LJS.mouseDelta.scale(.3*LJS.timeDelta);
107
- }
108
106
  }
109
107
 
110
108
  ///////////////////////////////////////////////////////////////////////////////
@@ -64,7 +64,7 @@ function createUI()
64
64
  // example button
65
65
  const button1 = new LJS.UIButton(vec2(0,140), vec2(350, 50), 'Test Button');
66
66
  uiMenu.addChild(button1);
67
- button1.onClick = ()=> uiBackground.color = hsl(Math.random(),1,.7);
67
+ button1.onClick = ()=> uiBackground.color = hsl(LJS.rand(),1,.7);
68
68
 
69
69
  // example checkbox
70
70
  const checkbox = new LJS.UICheckbox(vec2(-140,-20), vec2(40));
@@ -114,7 +114,7 @@ function gameRender()
114
114
  // test game rendering
115
115
  for (let i=0; i<1e3; ++i)
116
116
  {
117
- const pos = vec2(30*Math.sin(i+LJS.time/9),20*Math.sin(i*i+LJS.time/9));
117
+ const pos = vec2(30*LJS.sin(i+LJS.time/9),20*LJS.sin(i*i+LJS.time/9));
118
118
  LJS.drawTile(pos, vec2(2), tile(3,128), hsl(i/9,1,.4), LJS.time+i, !(i%2), hsl(i/9,1,.1,0));
119
119
  }
120
120
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "littlejsengine",
3
- "version": "1.14.19",
3
+ "version": "1.14.28",
4
4
  "description": "LittleJS - Tiny and Fast HTML5 Game Engine",
5
5
  "main": "dist/littlejs.esm.js",
6
6
  "types": "dist/littlejs.d.ts",