littlejsengine 1.12.4 → 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 (88) hide show
  1. package/dist/box2d.wasm.js +630 -0
  2. package/dist/box2d.wasm.wasm +0 -0
  3. package/dist/littlejs.d.ts +437 -219
  4. package/dist/littlejs.esm.js +5950 -5307
  5. package/dist/littlejs.esm.min.js +4 -1
  6. package/dist/littlejs.js +5921 -5295
  7. package/dist/littlejs.min.js +4 -1
  8. package/dist/littlejs.release.js +5485 -4886
  9. package/examples/box2d/game.js +37 -42
  10. package/examples/box2d/gameObjects.js +41 -37
  11. package/examples/box2d/index.html +2 -2
  12. package/examples/box2d/scenes.js +24 -20
  13. package/examples/box2d/tiles.png +0 -0
  14. package/examples/breakout/game.js +1 -1
  15. package/examples/breakout/gameObjects.js +2 -2
  16. package/examples/breakout/index.html +1 -1
  17. package/examples/breakoutTutorial/README.md +2 -2
  18. package/examples/breakoutTutorial/game.js +1 -1
  19. package/examples/breakoutTutorial/index.html +1 -1
  20. package/examples/empty/index.html +1 -1
  21. package/examples/htmlMenu/index.html +1 -1
  22. package/examples/index.html +410 -159
  23. package/examples/module/game.js +1 -1
  24. package/examples/module/index.html +1 -1
  25. package/examples/platformer/game.js +6 -15
  26. package/examples/platformer/gameCharacter.js +6 -6
  27. package/examples/platformer/gameEffects.js +74 -57
  28. package/examples/platformer/gameLevel.js +61 -70
  29. package/examples/platformer/gameObjects.js +4 -4
  30. package/examples/platformer/index.html +1 -1
  31. package/examples/puzzle/index.html +1 -1
  32. package/examples/shorts/base.html +24 -3
  33. package/examples/shorts/box2d.js +46 -0
  34. package/examples/shorts/box2dCar.js +45 -0
  35. package/examples/shorts/flappyGame.js +52 -0
  36. package/examples/shorts/helloWorld.js +6 -3
  37. package/examples/shorts/hillGlideGame.js +56 -0
  38. package/examples/shorts/landerGame.js +32 -0
  39. package/examples/shorts/maze.js +47 -0
  40. package/examples/shorts/medals.js +42 -0
  41. package/examples/shorts/nineSlice.js +21 -0
  42. package/examples/shorts/piano.js +52 -0
  43. package/examples/shorts/platformer.js +24 -20
  44. package/examples/shorts/{pong.js → pongGame.js} +1 -1
  45. package/examples/shorts/postProcess.js +45 -0
  46. package/examples/shorts/raycasting.js +71 -0
  47. package/examples/shorts/slidingPuzzle.js +42 -0
  48. package/examples/shorts/spaceGame.js +56 -0
  49. package/examples/shorts/starfield.js +17 -0
  50. package/examples/shorts/tileLayer.js +3 -5
  51. package/examples/shorts/tiles.png +0 -0
  52. package/examples/shorts/tiltedView.js +8 -7
  53. package/examples/shorts/topDown.js +18 -26
  54. package/examples/shorts/uiSystem.js +36 -0
  55. package/examples/starter/build.bat +6 -1
  56. package/examples/starter/game.js +4 -2
  57. package/examples/starter/index.html +23 -13
  58. package/examples/stress/index.html +2 -3
  59. package/examples/style.css +136 -0
  60. package/examples/typescript/build.js +1 -2
  61. package/examples/typescript/game.js +2 -2
  62. package/examples/typescript/game.ts +1 -1
  63. package/examples/typescript/index.html +1 -1
  64. package/examples/uiSystem/game.js +9 -25
  65. package/examples/uiSystem/index.html +1 -1
  66. package/package.json +1 -1
  67. package/plugins/box2d.js +29 -35
  68. package/plugins/drawUtilities.js +126 -0
  69. package/plugins/newgrounds.js +1 -1
  70. package/plugins/pluginExport.js +8 -2
  71. package/plugins/postProcess.js +2 -2
  72. package/plugins/uiSystem.js +162 -68
  73. package/plugins/zzfxm.js +1 -1
  74. package/reference.md +10 -10
  75. package/src/engine.js +59 -39
  76. package/src/engineAudio.js +38 -20
  77. package/src/engineBuild.bat +6 -1
  78. package/src/engineBuild.js +32 -7
  79. package/src/engineDebug.js +53 -26
  80. package/src/engineDraw.js +108 -57
  81. package/src/engineExport.js +22 -9
  82. package/src/engineInput.js +112 -40
  83. package/src/engineObject.js +68 -67
  84. package/src/engineParticles.js +26 -9
  85. package/src/engineSettings.js +15 -16
  86. package/src/engineTileLayer.js +312 -153
  87. package/src/engineUtilities.js +198 -130
  88. package/src/engineWebGL.js +58 -35
@@ -17,24 +17,21 @@ import * as GameObjects from './gameObjects.js';
17
17
  import * as Scenes from './scenes.js';
18
18
  const {vec2, hsl} = LJS;
19
19
 
20
+ // use HD textures
21
+ LJS.setCanvasPixelated(false);
22
+ LJS.setTilesPixelated(false);
23
+
20
24
  ///////////////////////////////////////////////////////////////////////////////
21
25
  // game variables
22
26
 
23
- //LJS.box2dSetDebug(true); // enable box2d debug draw
24
-
25
27
  const maxScenes = 11;
26
- export let scene = 0, sceneName;
27
- export let spriteAtlas, groundObject, car, mouseJoint, repeatSpawnTimer = new LJS.Timer;
28
+ const startScene = 0;
29
+ export let spriteAtlas, groundObject, mouseJoint, repeatSpawnTimer = new LJS.Timer;
28
30
  const sound_click = new LJS.Sound([.2,.1,,,,.01,,,,,,,,,,,,,,,-500]);
29
31
 
30
- export function setSceneName(name) { sceneName = name; }
31
- export function setCarObject(carObject) { car = carObject; }
32
-
33
32
  ///////////////////////////////////////////////////////////////////////////////
34
- function setScene(_scene)
33
+ function setScene(scene)
35
34
  {
36
- scene = _scene;
37
-
38
35
  // setup
39
36
  LJS.setCameraPos(vec2(20,10));
40
37
  LJS.setGravity(vec2(0,-20));
@@ -42,7 +39,6 @@ function setScene(_scene)
42
39
  // destroy old scene
43
40
  LJS.engineObjectsDestroy();
44
41
  mouseJoint = 0;
45
- car = 0;
46
42
 
47
43
  // create walls
48
44
  groundObject = GameObjects.spawnBox(vec2(0,-4), vec2(1e3,8), hsl(0,0,.2), LJS.box2d.bodyTypeStatic);
@@ -55,10 +51,14 @@ function setScene(_scene)
55
51
  }
56
52
 
57
53
  ///////////////////////////////////////////////////////////////////////////////
58
- function gameInit()
54
+ async function gameInit()
59
55
  {
56
+ // start up LittleJS Box2D plugin
57
+ await LJS.box2dInit();
58
+ //LJS.box2dSetDebug(true); // enable box2d debug draw
59
+
60
60
  // create a table of all sprites
61
- const gameTile = (i)=> LJS.tile(i, 16, 0, 1);
61
+ const gameTile = (i)=> LJS.tile(i, 496, 0, 8);
62
62
  spriteAtlas =
63
63
  {
64
64
  circle: gameTile(0),
@@ -70,7 +70,7 @@ function gameInit()
70
70
  squareOutline2: gameTile(6),
71
71
  };
72
72
 
73
- setScene(scene);
73
+ setScene(startScene);
74
74
  }
75
75
 
76
76
  ///////////////////////////////////////////////////////////////////////////////
@@ -80,7 +80,19 @@ function gameUpdate()
80
80
  LJS.setCameraScale(LJS.mainCanvasSize.y * 48 / 1080);
81
81
 
82
82
  // mouse controls
83
- if (LJS.mouseWasPressed(0))
83
+ if (mouseJoint)
84
+ {
85
+ // update mouse joint
86
+ mouseJoint.setTarget(LJS.mousePos);
87
+ if (LJS.mouseWasReleased(0))
88
+ {
89
+ // release object
90
+ sound_click.play(LJS.mousePos, 1, .5);
91
+ mouseJoint.destroy();
92
+ mouseJoint = 0;
93
+ }
94
+ }
95
+ else if (LJS.mouseWasPressed(0))
84
96
  {
85
97
  // grab object
86
98
  sound_click.play(LJS.mousePos);
@@ -88,16 +100,8 @@ function gameUpdate()
88
100
  if (object)
89
101
  mouseJoint = new LJS.Box2dTargetJoint(object, groundObject, LJS.mousePos);
90
102
  }
91
- if (LJS.mouseWasReleased(0))
92
- {
93
- // release object
94
- sound_click.play(LJS.mousePos, 1, .5);
95
- if (mouseJoint)
96
- {
97
- mouseJoint.destroy();
98
- mouseJoint = 0;
99
- }
100
- }
103
+
104
+ // controls
101
105
  if (LJS.mouseIsDown(1) || LJS.mouseIsDown('KeyZ'))
102
106
  {
103
107
  const isSet = repeatSpawnTimer.isSet();
@@ -112,23 +116,14 @@ function gameUpdate()
112
116
  repeatSpawnTimer.unset();
113
117
  if (LJS.mouseWasPressed(2) || LJS.keyWasPressed('KeyX'))
114
118
  GameObjects.explosion(LJS.mousePos);
115
- if (mouseJoint)
116
- mouseJoint.setTarget(LJS.mousePos);
117
119
 
118
120
  if (LJS.keyWasPressed('KeyR'))
119
- setScene(scene); // reset scene
121
+ setScene(Scenes.scene); // reset scene
120
122
  if (LJS.keyWasPressed('ArrowUp') || LJS.keyWasPressed('ArrowDown'))
121
123
  {
122
124
  // change scene
123
- scene += LJS.keyWasPressed('ArrowUp') ? 1 : -1;
124
- scene = LJS.mod(scene, maxScenes);
125
- setScene(scene);
126
- }
127
- if (car)
128
- {
129
- // update car controls
130
- const input = LJS.keyDirection();
131
- car.applyMotorInput(-input.x);
125
+ const upPressed = LJS.keyWasPressed('ArrowUp');
126
+ setScene(LJS.mod(Scenes.scene + (upPressed?1:-1), maxScenes));
132
127
  }
133
128
  }
134
129
 
@@ -144,7 +139,7 @@ function gameRender()
144
139
  // draw a grey square in the background without using webgl
145
140
  LJS.drawRect(vec2(20,8), vec2(100), hsl(0,0,.8), 0, 0);
146
141
 
147
- if (scene == 5)
142
+ if (Scenes.scene == 5)
148
143
  {
149
144
  // raycast test
150
145
  const count = 100;
@@ -174,15 +169,15 @@ function gameRenderPost()
174
169
  // draw to overlay canvas for hud rendering
175
170
  const pos = vec2(LJS.mainCanvasSize.x/2, 50);
176
171
  drawText('LittleJS Box2D Demo', 80, 80);
177
- drawText(sceneName, 60, 100);
178
- if (scene == 0)
172
+ drawText(Scenes.sceneName, 60, 100);
173
+ if (Scenes.scene == 0)
179
174
  {
180
175
  drawText('Mouse Left = Grab');
181
176
  drawText('Mouse Middle or Z = Spawn');
182
177
  drawText('Mouse Right or X = Explode');
183
178
  drawText('Arrows Up/Down = Change Scene');
184
179
  }
185
- if (scene == 3)
180
+ if (Scenes.scene == 3)
186
181
  {
187
182
  drawText('Right = Accelerate');
188
183
  drawText('Left = Reverse');
@@ -195,4 +190,4 @@ function gameRenderPost()
195
190
  ///////////////////////////////////////////////////////////////////////////////
196
191
  // Startup LittleJS Engine with Box2D
197
192
 
198
- LJS.box2dEngineInit(gameInit, gameUpdate, gameUpdatePost, gameRender, gameRenderPost, ['tiles.png']);
193
+ LJS.engineInit(gameInit, gameUpdate, gameUpdatePost, gameRender, gameRenderPost, ['tiles.png']);
@@ -14,12 +14,16 @@ const {vec2, hsl} = LJS;
14
14
  ///////////////////////////////////////////////////////////////////////////////
15
15
  // spawn object functions
16
16
 
17
+ const density = 1;
18
+ const friction = .5;
19
+ const restitution = .2;
20
+
17
21
  export function spawnBox(pos, size=1, color=LJS.WHITE, type=LJS.box2d.bodyTypeDynamic, applyTexture=true, angle=0)
18
22
  {
19
23
  size = typeof size == 'number' ? vec2(size) : size; // square
20
24
  const o = new LJS.Box2dObject(pos, size, applyTexture && Game.spriteAtlas.squareOutline, angle, color, type);
21
25
  o.drawSize = size.scale(1.02); // slightly enlarge to cover gaps
22
- o.addBox(size);
26
+ o.addBox(size, vec2(), 0, density, friction, restitution);
23
27
  return o;
24
28
  }
25
29
 
@@ -27,14 +31,14 @@ export function spawnCircle(pos, diameter=1, color=LJS.WHITE, type=LJS.box2d.bod
27
31
  {
28
32
  const size = vec2(diameter);
29
33
  const o = new LJS.Box2dObject(pos, size, applyTexture && Game.spriteAtlas.circleOutline, angle, color, type);
30
- o.addCircle(diameter);
34
+ o.addCircle(diameter, vec2(), density, friction, restitution);
31
35
  return o;
32
36
  }
33
37
 
34
38
  export function spawnRandomPoly(pos, diameter=1, color=LJS.WHITE, type=LJS.box2d.bodyTypeDynamic, angle=0)
35
39
  {
36
40
  const o = new LJS.Box2dObject(pos, vec2(), 0, angle, color, type);
37
- o.addRandomPoly(diameter);
41
+ o.addRandomPoly(diameter, vec2(), 0, density, friction, restitution);
38
42
  return o;
39
43
  }
40
44
 
@@ -59,7 +63,7 @@ export function spawnPyramid(pos, count)
59
63
  spawnBox(pos.add(vec2(j-i/2+.5,count-i+.5)), 1, LJS.randColor());
60
64
  }
61
65
 
62
- export function spawnDominoes(pos, count, size=vec2(.5,2))
66
+ export function spawnDominoes(pos, count, size=vec2(.5,3))
63
67
  {
64
68
  for (let i=count; i--;)
65
69
  spawnBox(pos.add(vec2(i*size.y*.9,size.y/2)), size, LJS.randColor());
@@ -112,50 +116,49 @@ export class CarObject extends LJS.Box2dObject
112
116
  ];
113
117
  this.addPoly(carPoints);
114
118
 
119
+ // create wheels
120
+ const diameter = 1;
121
+ const density = 1;
122
+ const friction = 1;
123
+ const restitution = 0;
124
+ const damping = .7;
125
+ const frequency = 4;
126
+ const maxTorque = 35;
127
+ const sprite = Game.spriteAtlas.wheel;
128
+ this.wheels = [];
129
+ const makeWheel = (pos, isMotor) =>
115
130
  {
116
- // wheel settings
117
- const diameter = .8;
118
- const density = 1;
119
- const friction = 2;
120
- const restitution = 0;
121
- const damping = .7;
122
- const frequencyHz = 4;
123
- const maxTorque = 50;
124
- const sprite = Game.spriteAtlas.wheel;
125
-
126
- // create wheels
127
- this.wheels = [];
128
- const makeWheel = (pos, isMotor) =>
131
+ const wheel = new LJS.Box2dObject(pos, vec2(diameter), sprite);
132
+ const joint = new LJS.Box2dWheelJoint(this, wheel);
133
+ joint.setSpringDampingRatio(damping);
134
+ joint.setSpringFrequencyHz(frequency);
135
+ if (isMotor)
129
136
  {
130
- const wheel = new LJS.Box2dObject(pos, vec2(diameter), sprite);
131
- wheel.addCircle(diameter, vec2(), density, friction, restitution);
132
- this.wheels.push(wheel);
133
- const joint = new LJS.Box2dWheelJoint(this, wheel);
134
- joint.setSpringDampingRatio(damping);
135
- joint.setSpringFrequencyHz(frequencyHz);
136
- if (isMotor)
137
- {
138
- joint.setMaxMotorTorque(maxTorque);
139
- joint.enableMotor(true);
140
- this.wheelMotorJoint = joint;
141
- }
137
+ joint.enableMotor();
138
+ joint.setMaxMotorTorque(maxTorque);
139
+ this.wheelMotorJoint = joint;
142
140
  }
143
-
144
- makeWheel(pos.add(vec2( 1, -.6)));
145
- makeWheel(pos.add(vec2(-1, -.65)), true);
141
+ wheel.addCircle(diameter, vec2(), density, friction, restitution);
142
+ this.wheels.push(wheel);
146
143
  }
144
+
145
+ makeWheel(pos.add(vec2( 1, -.6)));
146
+ makeWheel(pos.add(vec2(-1, -.65)), true);
147
147
  }
148
- applyMotorInput(input)
148
+ update()
149
149
  {
150
+ super.update();
151
+
152
+ // car controls
150
153
  const maxSpeed = 40;
151
- const brakeAmount = .8;
154
+ const input = LJS.keyDirection().x;
152
155
  let s = this.wheelMotorJoint.getMotorSpeed();
153
- s = input ? LJS.clamp(s + input, -maxSpeed, maxSpeed) : s * brakeAmount;
156
+ s = input ? LJS.clamp(s - input, -maxSpeed, maxSpeed) : 0;
154
157
  this.wheelMotorJoint.setMotorSpeed(s);
155
158
  }
156
159
  destroy()
157
160
  {
158
- this.wheels.forEach(o=>o && o.destroy());
161
+ this.wheels.forEach(o=>o.destroy());
159
162
  super.destroy();
160
163
  }
161
164
  }
@@ -390,6 +393,8 @@ export class ClothObject extends LJS.Box2dObject
390
393
  }
391
394
  update()
392
395
  {
396
+ super.update();
397
+
393
398
  for (let y=this.sizeCount.y; y--;)
394
399
  for (let x=this.sizeCount.x; x--;)
395
400
  {
@@ -422,7 +427,6 @@ export class ClothObject extends LJS.Box2dObject
422
427
  this.nodes[y*this.sizeCount.x+x] = 0;
423
428
  }
424
429
  }
425
- super.update();
426
430
  }
427
431
  render()
428
432
  {
@@ -5,5 +5,5 @@
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=../../plugins/box2d.wasm.js></script>
9
- <script src=game.js type=module></script>
8
+ <script src=../../dist/box2d.wasm.js></script>
9
+ <script src=game.js type=module></script>
@@ -23,45 +23,49 @@ import * as GameObjects from './gameObjects.js';
23
23
  import * as Game from './game.js';
24
24
  const {vec2} = LJS;
25
25
 
26
- export function loadScene(scene)
26
+ export let scene, sceneName;
27
+
28
+ export function loadScene(_scene)
27
29
  {
30
+ scene = _scene;
31
+
28
32
  if (scene == 0)
29
33
  {
30
- Game.setSceneName('Shapes');
34
+ sceneName = 'Shapes';
31
35
  GameObjects.spawnRandomEdges();
32
36
  GameObjects.spawnBox(vec2(11,8), 4, LJS.randColor(), LJS.box2d.bodyTypeStatic, false);
33
37
  GameObjects.spawnCircle(vec2(20,8), 4, LJS.randColor(), LJS.box2d.bodyTypeStatic, false);
34
- GameObjects.spawnRandomPoly(vec2(29,8), 4, LJS.randColor(), LJS.box2d.bodyTypeStatic, false);
38
+ GameObjects.spawnRandomPoly(vec2(29,8), 4, LJS.randColor(), LJS.box2d.bodyTypeStatic);
35
39
  for (let i=500;i--;)
36
40
  GameObjects.spawnRandomObject(vec2(LJS.rand(1,39), LJS.rand(10,50)));
37
41
  }
38
42
  if (scene == 1)
39
43
  {
40
- Game.setSceneName('Pyramid');
44
+ sceneName = 'Pyramid';
41
45
  GameObjects.spawnPyramid(vec2(20,0), 15);
42
46
  GameObjects.spawnBox(vec2(10,2), 4, LJS.randColor());
43
47
  GameObjects.spawnCircle(vec2(30,2), 4, LJS.randColor());
44
48
  }
45
49
  if (scene == 2)
46
50
  {
47
- Game.setSceneName('Dominoes');
48
- GameObjects.spawnDominoes(vec2(11,11), 11);
49
- GameObjects.spawnDominoes(vec2(2,0), 13, vec2(1,3));
50
- GameObjects.spawnCircle(vec2(10,20), 2, LJS.randColor());
51
- GameObjects.spawnCircle(vec2(31.7,12), 2, LJS.randColor());
52
- GameObjects.spawnBox(vec2(16,11), vec2(32,1), LJS.randColor(), LJS.box2d.bodyTypeStatic, false);
53
- GameObjects.spawnBox(vec2(24,6.5), vec2(32,1), LJS.randColor(), LJS.box2d.bodyTypeStatic, false, -.15);
51
+ sceneName = 'Dominoes';
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);
54
58
  }
55
59
  if (scene == 3)
56
60
  {
57
- Game.setSceneName('Car');
58
- Game.setCarObject(new GameObjects.CarObject(vec2(10,2)));
61
+ sceneName = 'Car';
62
+ new GameObjects.CarObject(vec2(10,2));
59
63
  GameObjects.spawnBox(vec2(20,0), vec2(10,2), LJS.randColor(), LJS.box2d.bodyTypeStatic, false, -.2);
60
64
  GameObjects.spawnPyramid(vec2(32,0), 6);
61
65
  }
62
66
  if (scene == 4)
63
67
  {
64
- Game.setSceneName('Rope');
68
+ sceneName = 'Rope';
65
69
  const startPos = vec2(20, 14);
66
70
  const angle = LJS.PI/2;
67
71
  const color = LJS.randColor();
@@ -78,14 +82,14 @@ export function loadScene(scene)
78
82
  }
79
83
  if (scene == 5)
80
84
  {
81
- Game.setSceneName('Raycasts');
85
+ sceneName = 'Raycasts';
82
86
  GameObjects.spawnRandomEdges();
83
87
  for (let i=100;i--;)
84
88
  GameObjects.spawnRandomObject(vec2(LJS.rand(1,39), LJS.rand(20)), 2, LJS.box2d.bodyTypeStatic, LJS.rand(LJS.PI*2));
85
89
  }
86
90
  if (scene == 6)
87
91
  {
88
- Game.setSceneName('Joints');
92
+ sceneName = 'Joints';
89
93
  {
90
94
  // prismatic joint
91
95
  const o1 = GameObjects.spawnBox(vec2(20,8), vec2(3,2), LJS.randColor());
@@ -156,7 +160,7 @@ export function loadScene(scene)
156
160
  }
157
161
  if (scene == 7)
158
162
  {
159
- Game.setSceneName('Contacts');
163
+ sceneName = 'Contacts';
160
164
  new GameObjects.ContactTester(vec2(15,8), vec2(5), LJS.RED, LJS.RED);
161
165
  new GameObjects.ContactTester(vec2(25,8), vec2(5), LJS.CYAN, LJS.CYAN, false, false);
162
166
  for (let i=200;i--;)
@@ -164,19 +168,19 @@ export function loadScene(scene)
164
168
  }
165
169
  if (scene == 8)
166
170
  {
167
- Game.setSceneName('Mobile');
171
+ sceneName = 'Mobile';
168
172
  const pos = vec2(20, 16);
169
173
  const mobile = new GameObjects.MobileObject(pos, 12, 2, 5);
170
174
  new LJS.Box2dRevoluteJoint(Game.groundObject, mobile, pos);
171
175
  }
172
176
  if (scene == 9)
173
177
  {
174
- Game.setSceneName('Cloth');
178
+ sceneName = 'Cloth'
175
179
  new GameObjects.ClothObject(vec2(20, 9), vec2(15), vec2(24), LJS.randColor());
176
180
  }
177
181
  if (scene == 10)
178
182
  {
179
- Game.setSceneName('Softbodies');
183
+ sceneName = 'Softbodies';
180
184
  for(let i=3;i--;)
181
185
  new GameObjects.SoftBodyObject(vec2(20, 3+i*7), vec2(6-i), vec2(9-i), LJS.randColor());
182
186
  }
Binary file
@@ -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>