littlejsengine 1.12.6 → 1.13.1

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 (83) hide show
  1. package/dist/littlejs.d.ts +387 -177
  2. package/dist/littlejs.esm.js +5934 -5294
  3. package/dist/littlejs.esm.min.js +4 -1
  4. package/dist/littlejs.js +5887 -5263
  5. package/dist/littlejs.min.js +4 -1
  6. package/dist/littlejs.release.js +5426 -4829
  7. package/examples/box2d/game.js +1 -1
  8. package/examples/box2d/gameObjects.js +7 -6
  9. package/examples/box2d/index.html +1 -1
  10. package/examples/box2d/scenes.js +7 -7
  11. package/examples/breakout/game.js +1 -1
  12. package/examples/breakout/gameObjects.js +2 -2
  13. package/examples/breakout/index.html +1 -1
  14. package/examples/breakoutTutorial/README.md +2 -2
  15. package/examples/breakoutTutorial/game.js +1 -1
  16. package/examples/breakoutTutorial/index.html +1 -1
  17. package/examples/empty/index.html +1 -1
  18. package/examples/htmlMenu/index.html +1 -1
  19. package/examples/index.html +396 -153
  20. package/examples/module/game.js +1 -1
  21. package/examples/module/index.html +1 -1
  22. package/examples/platformer/game.js +4 -4
  23. package/examples/platformer/gameCharacter.js +6 -6
  24. package/examples/platformer/gameEffects.js +74 -57
  25. package/examples/platformer/gameLevel.js +61 -70
  26. package/examples/platformer/gameObjects.js +4 -4
  27. package/examples/platformer/index.html +1 -1
  28. package/examples/puzzle/index.html +1 -1
  29. package/examples/shorts/base.html +23 -3
  30. package/examples/shorts/box2dCar.js +8 -12
  31. package/examples/shorts/flappyGame.js +52 -0
  32. package/examples/shorts/helloWorld.js +6 -3
  33. package/examples/shorts/hillGlideGame.js +56 -0
  34. package/examples/shorts/landerGame.js +32 -0
  35. package/examples/shorts/maze.js +47 -0
  36. package/examples/shorts/medals.js +42 -0
  37. package/examples/shorts/nineSlice.js +21 -0
  38. package/examples/shorts/piano.js +52 -0
  39. package/examples/shorts/platformer.js +24 -20
  40. package/examples/shorts/{pong.js → pongGame.js} +1 -1
  41. package/examples/shorts/raycasting.js +71 -0
  42. package/examples/shorts/slidingPuzzle.js +42 -0
  43. package/examples/shorts/spaceGame.js +56 -0
  44. package/examples/shorts/starfield.js +17 -0
  45. package/examples/shorts/tileLayer.js +3 -5
  46. package/examples/shorts/tiles.png +0 -0
  47. package/examples/shorts/tiltedView.js +8 -7
  48. package/examples/shorts/topDown.js +18 -26
  49. package/examples/shorts/uiSystem.js +4 -7
  50. package/examples/starter/build.bat +6 -1
  51. package/examples/starter/game.js +2 -2
  52. package/examples/starter/index.html +23 -13
  53. package/examples/stress/index.html +2 -3
  54. package/examples/style.css +136 -0
  55. package/examples/typescript/build.js +1 -2
  56. package/examples/typescript/game.js +2 -2
  57. package/examples/typescript/game.ts +1 -1
  58. package/examples/typescript/index.html +1 -1
  59. package/examples/uiSystem/game.js +8 -24
  60. package/examples/uiSystem/index.html +1 -1
  61. package/package.json +1 -1
  62. package/plugins/box2d.js +8 -8
  63. package/plugins/drawUtilities.js +126 -0
  64. package/plugins/newgrounds.js +1 -1
  65. package/plugins/pluginExport.js +7 -1
  66. package/plugins/postProcess.js +2 -2
  67. package/plugins/uiSystem.js +153 -65
  68. package/plugins/zzfxm.js +1 -1
  69. package/reference.md +10 -10
  70. package/src/engine.js +50 -29
  71. package/src/engineAudio.js +14 -5
  72. package/src/engineBuild.bat +6 -1
  73. package/src/engineBuild.js +20 -5
  74. package/src/engineDebug.js +53 -26
  75. package/src/engineDraw.js +108 -57
  76. package/src/engineExport.js +21 -9
  77. package/src/engineInput.js +109 -37
  78. package/src/engineObject.js +68 -67
  79. package/src/engineParticles.js +26 -9
  80. package/src/engineSettings.js +15 -16
  81. package/src/engineTileLayer.js +312 -153
  82. package/src/engineUtilities.js +182 -130
  83. package/src/engineWebGL.js +47 -36
@@ -118,7 +118,7 @@ function gameUpdate()
118
118
  GameObjects.explosion(LJS.mousePos);
119
119
 
120
120
  if (LJS.keyWasPressed('KeyR'))
121
- setScene(scene); // reset scene
121
+ setScene(Scenes.scene); // reset scene
122
122
  if (LJS.keyWasPressed('ArrowUp') || LJS.keyWasPressed('ArrowDown'))
123
123
  {
124
124
  // change scene
@@ -63,7 +63,7 @@ export function spawnPyramid(pos, count)
63
63
  spawnBox(pos.add(vec2(j-i/2+.5,count-i+.5)), 1, LJS.randColor());
64
64
  }
65
65
 
66
- export function spawnDominoes(pos, count, size=vec2(.5,2))
66
+ export function spawnDominoes(pos, count, size=vec2(.5,3))
67
67
  {
68
68
  for (let i=count; i--;)
69
69
  spawnBox(pos.add(vec2(i*size.y*.9,size.y/2)), size, LJS.randColor());
@@ -105,7 +105,7 @@ export class CarObject extends LJS.Box2dObject
105
105
  {
106
106
  constructor(pos)
107
107
  {
108
- super(pos, vec2(), 0, 0, LJS.RED);
108
+ super(pos, vec2(), 0, 0, LJS.randColor());
109
109
  const carPoints = [
110
110
  vec2(-1.5,-.5),
111
111
  vec2(1.5, -.5),
@@ -147,14 +147,14 @@ export class CarObject extends LJS.Box2dObject
147
147
  }
148
148
  update()
149
149
  {
150
+ super.update();
151
+
150
152
  // car controls
151
153
  const maxSpeed = 40;
152
- const brakeAmount = .8;
153
154
  const input = LJS.keyDirection().x;
154
155
  let s = this.wheelMotorJoint.getMotorSpeed();
155
- s = input ? LJS.clamp(s - input, -maxSpeed, maxSpeed) : s * brakeAmount;
156
+ s = input ? LJS.clamp(s - input, -maxSpeed, maxSpeed) : 0;
156
157
  this.wheelMotorJoint.setMotorSpeed(s);
157
- super.update();
158
158
  }
159
159
  destroy()
160
160
  {
@@ -393,6 +393,8 @@ export class ClothObject extends LJS.Box2dObject
393
393
  }
394
394
  update()
395
395
  {
396
+ super.update();
397
+
396
398
  for (let y=this.sizeCount.y; y--;)
397
399
  for (let x=this.sizeCount.x; x--;)
398
400
  {
@@ -425,7 +427,6 @@ export class ClothObject extends LJS.Box2dObject
425
427
  this.nodes[y*this.sizeCount.x+x] = 0;
426
428
  }
427
429
  }
428
- super.update();
429
430
  }
430
431
  render()
431
432
  {
@@ -6,4 +6,4 @@
6
6
  <link rel=icon type=image/png href=../favicon.png>
7
7
  </head><body>
8
8
  <script src=../../dist/box2d.wasm.js></script>
9
- <script src=game.js type=module></script>
9
+ <script src=game.js type=module></script>
@@ -35,7 +35,7 @@ export function loadScene(_scene)
35
35
  GameObjects.spawnRandomEdges();
36
36
  GameObjects.spawnBox(vec2(11,8), 4, LJS.randColor(), LJS.box2d.bodyTypeStatic, false);
37
37
  GameObjects.spawnCircle(vec2(20,8), 4, LJS.randColor(), LJS.box2d.bodyTypeStatic, false);
38
- GameObjects.spawnRandomPoly(vec2(29,8), 4, LJS.randColor(), LJS.box2d.bodyTypeStatic, false);
38
+ GameObjects.spawnRandomPoly(vec2(29,8), 4, LJS.randColor(), LJS.box2d.bodyTypeStatic);
39
39
  for (let i=500;i--;)
40
40
  GameObjects.spawnRandomObject(vec2(LJS.rand(1,39), LJS.rand(10,50)));
41
41
  }
@@ -49,12 +49,12 @@ export function loadScene(_scene)
49
49
  if (scene == 2)
50
50
  {
51
51
  sceneName = 'Dominoes';
52
- GameObjects.spawnDominoes(vec2(11,11), 11);
53
- GameObjects.spawnDominoes(vec2(2,0), 13, vec2(1,3));
54
- GameObjects.spawnCircle(vec2(10,20), 2, LJS.randColor());
55
- GameObjects.spawnCircle(vec2(31.7,12), 2, LJS.randColor());
56
- GameObjects.spawnBox(vec2(16,11), vec2(32,1), LJS.randColor(), LJS.box2d.bodyTypeStatic, false);
57
- GameObjects.spawnBox(vec2(24,6.5), vec2(32,1), LJS.randColor(), LJS.box2d.bodyTypeStatic, false, -.15);
52
+ GameObjects.spawnDominoes(vec2(11,13), 8);
53
+ GameObjects.spawnDominoes(vec2(3,0), 10, vec2(1,4));
54
+ GameObjects.spawnCircle(vec2(10.2,20), 1.5, LJS.randColor());
55
+ GameObjects.spawnCircle(vec2(31.9,15), 2.5, LJS.randColor());
56
+ GameObjects.spawnBox(vec2(16,13), vec2(32,1), LJS.randColor(), LJS.box2d.bodyTypeStatic, false);
57
+ GameObjects.spawnBox(vec2(24,8), vec2(34,1), LJS.randColor(), LJS.box2d.bodyTypeStatic, false, -.15);
58
58
  }
59
59
  if (scene == 3)
60
60
  {
@@ -104,7 +104,7 @@ function gameRenderPost()
104
104
  {
105
105
  // use built in image font for text
106
106
  const font = new LJS.FontImage;
107
- font.drawText('Score: ' + score, LJS.cameraPos.add(vec2(0,10)), .15, true);
107
+ font.drawText('Score: ' + score, LJS.cameraPos.add(vec2(0,9.7)), .15, true);
108
108
  if (!brickCount)
109
109
  font.drawText('You Win!', LJS.cameraPos.add(vec2(0,-5)), .2, true);
110
110
  else if (!ball)
@@ -31,7 +31,7 @@ export class Wall extends PhysicsObject
31
31
  {
32
32
  constructor(pos, size)
33
33
  {
34
- super(pos, size, 0, 0, hsl(0,0,0));
34
+ super(pos, size, 0, 0, hsl(0,0,0,0));
35
35
  }
36
36
  }
37
37
 
@@ -103,7 +103,7 @@ export class Ball extends PhysicsObject
103
103
 
104
104
  // make a bouncy ball
105
105
  this.velocity = vec2(0, -.1);
106
- this.elasticity = 1;
106
+ this.restitution = 1;
107
107
  this.mass = 1;
108
108
 
109
109
  // attach a trail effect
@@ -5,4 +5,4 @@
5
5
  <meta name=mobile-web-app-capable content=yes>
6
6
  <link rel=icon type=image/png href=../favicon.png>
7
7
  </head><body>
8
- <script src=game.js type=module></script>
8
+ <script src=game.js type=module></script>
@@ -189,10 +189,10 @@ Now the ball collides but unfortunately also pushes the paddle away, not quite w
189
189
  this.mass = 0; // make object have static physics
190
190
  ```
191
191
 
192
- Getting closer, the paddle is not pushed away but the ball doesn’t bounce either. To make it bounce, we need to set the ball’s elasticity which controls how much it will bounce.
192
+ Getting closer, the paddle is not pushed away but the ball doesn’t bounce either. To make it bounce, we need to set the ball’s restitution which controls how much it will bounce.
193
193
 
194
194
  ```javascript
195
- this.elasticity = 1; // make object bounce
195
+ this.restitution = 1; // make object bounce
196
196
  ```
197
197
 
198
198
  ![LittleJS Screenshot](images/5.png)
@@ -52,7 +52,7 @@ class Ball extends LJS.EngineObject
52
52
 
53
53
  this.velocity = vec2(-.1, -.1); // give ball some movement
54
54
  this.setCollision(); // make object collide
55
- this.elasticity = 1; // make object bounce
55
+ this.restitution = 1; // make object bounce
56
56
  }
57
57
  collideWithObject(o)
58
58
  {
@@ -5,4 +5,4 @@
5
5
  <meta name=mobile-web-app-capable content=yes>
6
6
  <link rel=icon type=image/png href=../favicon.png>
7
7
  </head><body>
8
- <script src=game.js type=module></script>
8
+ <script src=game.js type=module></script>
@@ -2,4 +2,4 @@
2
2
  <title>LittleJS Hello World Demo</title>
3
3
  <meta charset=utf-8>
4
4
  </head><body>
5
- <script src=game.js type=module></script>
5
+ <script src=game.js type=module></script>
@@ -42,4 +42,4 @@ This is an example menu using html elements.
42
42
  </div>
43
43
 
44
44
  <!-- Add your game scripts here -->
45
- <script src=game.js type=module></script>
45
+ <script src=game.js type=module></script>