littlejsengine 1.11.17 → 1.12.6

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 (73) hide show
  1. package/dist/box2d.wasm.js +630 -0
  2. package/dist/box2d.wasm.wasm +0 -0
  3. package/dist/littlejs.d.ts +158 -81
  4. package/dist/littlejs.esm.js +882 -793
  5. package/dist/littlejs.esm.min.js +1 -1
  6. package/dist/littlejs.js +3048 -175
  7. package/dist/littlejs.min.js +1 -1
  8. package/dist/littlejs.release.js +3047 -172
  9. package/examples/box2d/game.js +82 -56
  10. package/examples/box2d/gameObjects.js +114 -107
  11. package/examples/box2d/index.html +2 -7
  12. package/examples/box2d/scenes.js +72 -78
  13. package/examples/box2d/tiles.png +0 -0
  14. package/examples/breakout/game.js +63 -28
  15. package/examples/breakout/gameObjects.js +45 -47
  16. package/examples/breakout/index.html +1 -5
  17. package/examples/breakoutTutorial/game.js +36 -29
  18. package/examples/breakoutTutorial/index.html +1 -3
  19. package/examples/empty/game.js +5 -2
  20. package/examples/empty/index.html +1 -3
  21. package/examples/htmlMenu/game.js +24 -15
  22. package/examples/htmlMenu/index.html +5 -7
  23. package/examples/index.html +24 -17
  24. package/examples/module/game.js +32 -34
  25. package/examples/module/index.html +1 -1
  26. package/examples/particles/index.html +27 -22
  27. package/examples/platformer/game.js +62 -45
  28. package/examples/platformer/gameCharacter.js +42 -34
  29. package/examples/platformer/gameEffects.js +82 -75
  30. package/examples/platformer/gameLevel.js +67 -38
  31. package/examples/platformer/{gameLevelData.js → gameLevelData.json} +1 -11
  32. package/examples/platformer/gameObjects.js +70 -64
  33. package/examples/platformer/gamePlayer.js +12 -7
  34. package/examples/platformer/index.html +1 -9
  35. package/examples/puzzle/game.js +59 -40
  36. package/examples/puzzle/index.html +1 -3
  37. package/examples/shorts/base.html +3 -2
  38. package/examples/shorts/box2d.js +46 -0
  39. package/examples/shorts/box2dCar.js +49 -0
  40. package/examples/shorts/particles.js +1 -1
  41. package/examples/shorts/platformer.js +1 -1
  42. package/examples/shorts/postProcess.js +45 -0
  43. package/examples/shorts/tileLayer.js +5 -6
  44. package/examples/shorts/tiles.png +0 -0
  45. package/examples/shorts/uiSystem.js +39 -0
  46. package/examples/starter/game.js +9 -10
  47. package/examples/starter/index.html +13 -13
  48. package/examples/stress/index.html +44 -44
  49. package/examples/typescript/build.js +17 -18
  50. package/examples/typescript/game.js +32 -34
  51. package/examples/typescript/game.ts +32 -34
  52. package/examples/typescript/index.html +1 -1
  53. package/examples/uiSystem/game.js +34 -31
  54. package/examples/uiSystem/index.html +1 -5
  55. package/package.json +1 -1
  56. package/plugins/box2d.js +28 -30
  57. package/plugins/pluginExport.js +2 -3
  58. package/plugins/uiSystem.js +9 -3
  59. package/reference.md +29 -27
  60. package/src/engine.js +10 -11
  61. package/src/engineAudio.js +24 -15
  62. package/src/engineBuild.js +25 -8
  63. package/src/engineDebug.js +1 -3
  64. package/src/engineExport.js +3 -6
  65. package/src/engineInput.js +6 -4
  66. package/src/engineObject.js +18 -14
  67. package/src/engineSettings.js +6 -6
  68. package/src/engineTileLayer.js +179 -96
  69. package/src/engineUtilities.js +16 -0
  70. package/src/engineWebGL.js +13 -1
  71. package/examples/typescript/build/dist/littlejs.esm.js +0 -4834
  72. package/examples/typescript/build/examples/typescript/build.js +0 -24
  73. package/examples/typescript/build/examples/typescript/game.js +0 -102
@@ -6,97 +6,106 @@
6
6
 
7
7
  'use strict';
8
8
 
9
+ // import LittleJS module
10
+ import * as LJS from '../../dist/littlejs.esm.js';
11
+ import * as Game from './game.js';
12
+ const {vec2, hsl} = LJS;
13
+
9
14
  ///////////////////////////////////////////////////////////////////////////////
10
15
  // spawn object functions
11
16
 
12
- function spawnBox(pos, size=1, color=WHITE, type=box2d.bodyTypeDynamic, applyTexture=true, angle=0)
17
+ const density = 1;
18
+ const friction = .5;
19
+ const restitution = .2;
20
+
21
+ export function spawnBox(pos, size=1, color=LJS.WHITE, type=LJS.box2d.bodyTypeDynamic, applyTexture=true, angle=0)
13
22
  {
14
23
  size = typeof size == 'number' ? vec2(size) : size; // square
15
- const o = new Box2dObject(pos, size, applyTexture && spriteAtlas.squareOutline, angle, color, type);
24
+ const o = new LJS.Box2dObject(pos, size, applyTexture && Game.spriteAtlas.squareOutline, angle, color, type);
16
25
  o.drawSize = size.scale(1.02); // slightly enlarge to cover gaps
17
- o.addBox(size);
26
+ o.addBox(size, vec2(), 0, density, friction, restitution);
18
27
  return o;
19
28
  }
20
29
 
21
- function spawnCircle(pos, diameter=1, color=WHITE, type=box2d.bodyTypeDynamic, applyTexture=true, angle=0)
30
+ export function spawnCircle(pos, diameter=1, color=LJS.WHITE, type=LJS.box2d.bodyTypeDynamic, applyTexture=true, angle=0)
22
31
  {
23
32
  const size = vec2(diameter);
24
- const o = new Box2dObject(pos, size, applyTexture && spriteAtlas.circleOutline, angle, color, type);
25
- o.addCircle(diameter);
33
+ const o = new LJS.Box2dObject(pos, size, applyTexture && Game.spriteAtlas.circleOutline, angle, color, type);
34
+ o.addCircle(diameter, vec2(), density, friction, restitution);
26
35
  return o;
27
36
  }
28
37
 
29
- function spawnRandomPoly(pos, diameter=1, color=WHITE, type=box2d.bodyTypeDynamic, angle=0)
38
+ export function spawnRandomPoly(pos, diameter=1, color=LJS.WHITE, type=LJS.box2d.bodyTypeDynamic, angle=0)
30
39
  {
31
- const o = new Box2dObject(pos, vec2(), 0, angle, color, type);
32
- o.addRandomPoly(diameter);
40
+ const o = new LJS.Box2dObject(pos, vec2(), 0, angle, color, type);
41
+ o.addRandomPoly(diameter, vec2(), 0, density, friction, restitution);
33
42
  return o;
34
43
  }
35
44
 
36
- function spawnRandomObject(pos, scale=1, type=box2d.bodyTypeDynamic, angle=0)
45
+ export function spawnRandomObject(pos, scale=1, type=LJS.box2d.bodyTypeDynamic, angle=0)
37
46
  {
38
- if (randInt(2))
47
+ if (LJS.randInt(2))
39
48
  {
40
- const size = vec2(scale*rand(.5,1), scale*rand(.5,1));
41
- return spawnBox(pos, size, randColor(), type, true, angle);
49
+ const size = vec2(scale*LJS.rand(.5,1), scale*LJS.rand(.5,1));
50
+ return spawnBox(pos, size, LJS.randColor(), type, true, angle);
42
51
  }
43
52
  else
44
53
  {
45
- const diameter = scale*rand(.5,1);
46
- return spawnCircle(pos, diameter, randColor(), type, true, angle);
54
+ const diameter = scale*LJS.rand(.5,1);
55
+ return spawnCircle(pos, diameter, LJS.randColor(), type, true, angle);
47
56
  }
48
57
  }
49
58
 
50
- function spawnPyramid(pos, count)
59
+ export function spawnPyramid(pos, count)
51
60
  {
52
61
  for (let i=count+1;i--;)
53
62
  for (let j=i;j--;)
54
- spawnBox(pos.add(vec2(j-i/2+.5,count-i+.5)), 1, randColor());
63
+ spawnBox(pos.add(vec2(j-i/2+.5,count-i+.5)), 1, LJS.randColor());
55
64
  }
56
65
 
57
- function spawnDominoes(pos, count, size=vec2(.5,2))
66
+ export function spawnDominoes(pos, count, size=vec2(.5,2))
58
67
  {
59
68
  for (let i=count; i--;)
60
- spawnBox(pos.add(vec2(i*size.y*.9,size.y/2)), size, randColor());
69
+ spawnBox(pos.add(vec2(i*size.y*.9,size.y/2)), size, LJS.randColor());
61
70
  }
62
71
 
63
- function spawnRandomEdges()
72
+ export function spawnRandomEdges()
64
73
  {
65
74
  // edge list along bottom
66
75
  const edgePoints = [];
67
76
  edgePoints.push(vec2(40,0));
68
77
  for (let i=40, y=0; i--;)
69
- edgePoints.push(vec2(i, y=clamp(y+rand(-2,2),0,5)));
78
+ edgePoints.push(vec2(i, y=LJS.clamp(y+LJS.rand(-2,2),0,5)));
70
79
  edgePoints.push(vec2(0,0));
71
- const o = new Box2dObject(vec2(), vec2(), 0, 0, BLACK, box2d.bodyTypeStatic);
80
+ const o = new LJS.Box2dObject(vec2(), vec2(), 0, 0, LJS.BLACK, LJS.box2d.bodyTypeStatic);
72
81
  o.addEdgeList(edgePoints);
73
82
  }
74
83
 
75
- function spawnRope(startPos, count, angle=PI, color=WHITE, size=vec2(.3,1))
84
+ export function spawnRope(startPos, count, angle=PI, color=LJS.WHITE, size=vec2(.3,1))
76
85
  {
77
- let lastObject = groundObject;
86
+ let lastObject = Game.groundObject;
78
87
  for (let i=0; i<count; ++i)
79
88
  {
80
89
  const pos = startPos.add(size.multiply(vec2(0,i+.5)).rotate(-angle));
81
- const o = spawnBox(pos, size, color, box2d.bodyTypeDynamic, false, angle);
90
+ const o = spawnBox(pos, size, color, LJS.box2d.bodyTypeDynamic, false, angle);
82
91
  o.setFilterData(2, 2);
83
92
  const anchorPos = pos.add(vec2(0,-size.y/2).rotate(-angle));
84
- new Box2dRevoluteJoint(lastObject, o, anchorPos);
93
+ new LJS.Box2dRevoluteJoint(lastObject, o, anchorPos);
85
94
  lastObject = o;
86
95
  }
87
96
  const endPos = lastObject.localToWorld(vec2(0,-size.y/2));
88
- new Box2dRopeJoint(groundObject, lastObject, startPos, endPos);
97
+ new LJS.Box2dRopeJoint(Game.groundObject, lastObject, startPos, endPos);
89
98
  return lastObject;
90
99
  }
91
100
 
92
101
  ///////////////////////////////////////////////////////////////////////////////
93
102
 
94
103
  // simple car vehicle using wheel joints
95
- class CarObject extends Box2dObject
104
+ export class CarObject extends LJS.Box2dObject
96
105
  {
97
106
  constructor(pos)
98
107
  {
99
- super(pos, vec2(), 0, 0, randColor());
108
+ super(pos, vec2(), 0, 0, LJS.RED);
100
109
  const carPoints = [
101
110
  vec2(-1.5,-.5),
102
111
  vec2(1.5, -.5),
@@ -107,50 +116,49 @@ class CarObject extends Box2dObject
107
116
  ];
108
117
  this.addPoly(carPoints);
109
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) =>
110
130
  {
111
- // wheel settings
112
- const diameter = .8;
113
- const density = 1;
114
- const friction = 2;
115
- const restitution = 0;
116
- const damping = .7;
117
- const frequencyHz = 4;
118
- const maxTorque = 50;
119
- const sprite = spriteAtlas.wheel;
120
-
121
- // create wheels
122
- this.wheels = [];
123
- 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)
124
136
  {
125
- const wheel = new Box2dObject(pos, vec2(diameter), sprite);
126
- wheel.addCircle(diameter, vec2(), density, friction, restitution);
127
- this.wheels.push(wheel);
128
- const joint = new Box2dWheelJoint(this, wheel);
129
- joint.setSpringDampingRatio(damping);
130
- joint.setSpringFrequencyHz(frequencyHz);
131
- if (isMotor)
132
- {
133
- joint.setMaxMotorTorque(maxTorque);
134
- joint.enableMotor(true);
135
- this.wheelMotorJoint = joint;
136
- }
137
+ joint.enableMotor();
138
+ joint.setMaxMotorTorque(maxTorque);
139
+ this.wheelMotorJoint = joint;
137
140
  }
138
-
139
- makeWheel(pos.add(vec2( 1, -.6)));
140
- makeWheel(pos.add(vec2(-1, -.65)), true);
141
+ wheel.addCircle(diameter, vec2(), density, friction, restitution);
142
+ this.wheels.push(wheel);
141
143
  }
144
+
145
+ makeWheel(pos.add(vec2( 1, -.6)));
146
+ makeWheel(pos.add(vec2(-1, -.65)), true);
142
147
  }
143
- applyMotorInput(input)
148
+ update()
144
149
  {
150
+ // car controls
145
151
  const maxSpeed = 40;
146
152
  const brakeAmount = .8;
153
+ const input = LJS.keyDirection().x;
147
154
  let s = this.wheelMotorJoint.getMotorSpeed();
148
- s = input ? clamp(s + input, -maxSpeed, maxSpeed) : s * brakeAmount;
155
+ s = input ? LJS.clamp(s - input, -maxSpeed, maxSpeed) : s * brakeAmount;
149
156
  this.wheelMotorJoint.setMotorSpeed(s);
157
+ super.update();
150
158
  }
151
159
  destroy()
152
160
  {
153
- this.wheels.forEach(o=>o && o.destroy());
161
+ this.wheels.forEach(o=>o.destroy());
154
162
  super.destroy();
155
163
  }
156
164
  }
@@ -158,27 +166,27 @@ class CarObject extends Box2dObject
158
166
  ///////////////////////////////////////////////////////////////////////////////
159
167
 
160
168
  // changes objects color when touched
161
- class ContactTester extends Box2dObject
169
+ export class ContactTester extends LJS.Box2dObject
162
170
  {
163
171
  constructor(pos, size, color, contactColor, isCircle=true, isSensor=true)
164
172
  {
165
- super(pos, size, 0, 0, color, box2d.bodyTypeStatic);
173
+ super(pos, size, 0, 0, color, LJS.box2d.bodyTypeStatic);
166
174
  isCircle ? this.addCircle(size.x) : this.addBox(size);
167
175
  this.setSensor(isSensor);
168
176
  this.contactColor = contactColor;
169
177
  }
170
178
  beginContact(other) { other.color = this.contactColor; }
171
- endContact(other) { other.color = WHITE; }
179
+ endContact(other) { other.color = LJS.WHITE; }
172
180
  }
173
181
 
174
182
  ///////////////////////////////////////////////////////////////////////////////
175
183
 
176
184
  // balanced recursive mobile object with revolve joints
177
- class MobileObject extends Box2dObject
185
+ export class MobileObject extends LJS.Box2dObject
178
186
  {
179
187
  constructor(anchor, w, h, depth)
180
188
  {
181
- super(anchor, vec2(w, h), 0, 0, randColor());
189
+ super(anchor, vec2(w, h), 0, 0, LJS.randColor());
182
190
  this.addBox(vec2(h/4, h), vec2(0, -h/2));
183
191
  this.childMobiles = [];
184
192
  if (--depth)
@@ -190,7 +198,7 @@ class MobileObject extends Box2dObject
190
198
  // spawn smaller mobiles attached to each side
191
199
  const a = anchor.add(vec2( w/(i?2:-2), -h));
192
200
  const o = new MobileObject(a, w/2, h, depth);
193
- new Box2dRevoluteJoint(this, o, a);
201
+ new LJS.Box2dRevoluteJoint(this, o, a);
194
202
  this.childMobiles.push(o);
195
203
  }
196
204
  }
@@ -205,11 +213,11 @@ class MobileObject extends Box2dObject
205
213
  ///////////////////////////////////////////////////////////////////////////////
206
214
 
207
215
  // pulley object renders a rope to connected point
208
- class PulleyJointObjects extends Box2dObject
216
+ export class PulleyJointObjects extends LJS.Box2dObject
209
217
  {
210
218
  constructor(pos, size, color, connectionPos)
211
219
  {
212
- super(pos, size, spriteAtlas.squareOutline, 0, color);
220
+ super(pos, size, Game.spriteAtlas.squareOutline, 0, color);
213
221
  this.addBox(size);
214
222
  this.connectionPos = connectionPos;
215
223
  }
@@ -217,7 +225,7 @@ class PulleyJointObjects extends Box2dObject
217
225
  {
218
226
  // draw rope
219
227
  const topPos = this.localToWorld(vec2(0,this.size.y/2));
220
- drawLine(topPos, this.connectionPos, .2, BLACK);
228
+ LJS.drawLine(topPos, this.connectionPos, .2, LJS.BLACK);
221
229
  super.render();
222
230
  }
223
231
  }
@@ -225,14 +233,14 @@ class PulleyJointObjects extends Box2dObject
225
233
  ///////////////////////////////////////////////////////////////////////////////
226
234
 
227
235
  // motor object renders a rope to connected point
228
- class MotorJointObject extends Box2dObject
236
+ export class MotorJointObject extends LJS.Box2dObject
229
237
  {
230
238
  constructor(pos, size, color, otherObject)
231
239
  {
232
- super(pos, size, spriteAtlas.wheel, 0, color);
240
+ super(pos, size, Game.spriteAtlas.wheel, 0, color);
233
241
  this.addCircle(size.x);
234
242
  this.connectionPos = pos;
235
- const joint = new Box2dMotorJoint(otherObject, this);
243
+ const joint = new LJS.Box2dMotorJoint(otherObject, this);
236
244
  joint.setMaxForce(500);
237
245
  joint.setMaxTorque(500);
238
246
  }
@@ -240,7 +248,7 @@ class MotorJointObject extends Box2dObject
240
248
  {
241
249
  // draw rope
242
250
  const width = 2/(1+this.pos.distance(this.connectionPos));
243
- drawLine(this.pos, this.connectionPos, width, BLACK);
251
+ LJS.drawLine(this.pos, this.connectionPos, width, LJS.BLACK);
244
252
  super.render();
245
253
  }
246
254
  }
@@ -248,14 +256,14 @@ class MotorJointObject extends Box2dObject
248
256
  ///////////////////////////////////////////////////////////////////////////////
249
257
 
250
258
  // soft body sim using grid of weld joints
251
- class SoftBodyObject extends Box2dObject
259
+ export class SoftBodyObject extends LJS.Box2dObject
252
260
  {
253
261
  constructor(pos, scale, sizeCount, color)
254
262
  {
255
263
  super(pos, vec2());
256
264
  const nodeSize = sizeCount.subtract(vec2(1));
257
265
  const spacing = scale.divide(nodeSize);
258
- const objectDiameter = min(spacing.x, spacing.y);
266
+ const objectDiameter = LJS.min(spacing.x, spacing.y);
259
267
  this.sizeCount = sizeCount.copy();
260
268
 
261
269
  // create nodes
@@ -266,7 +274,7 @@ class SoftBodyObject extends Box2dObject
266
274
  const mass = .1;
267
275
  const center = vec2(x-nodeSize.x/2, y-nodeSize.y/2);
268
276
  const p = pos.add(center.multiply(spacing));
269
- const o = new Box2dObject(p, vec2(objectDiameter*1.1), spriteAtlas.circle, 0, color);
277
+ const o = new LJS.Box2dObject(p, vec2(objectDiameter*1.1), Game.spriteAtlas.circle, 0, color);
270
278
  o.addCircle(objectDiameter);
271
279
  o.setMass(mass);
272
280
  o.setAngularDamping(10);
@@ -281,7 +289,7 @@ class SoftBodyObject extends Box2dObject
281
289
  const tryAddJoint = (xo, yo) =>
282
290
  {
283
291
  const o2 = this.getNode(x+xo, y+yo);
284
- const joint = o2 ? new Box2dWeldJoint(o, o2) : 0;
292
+ const joint = o2 ? new LJS.Box2dWeldJoint(o, o2) : 0;
285
293
  o.joints.push(joint);
286
294
  }
287
295
 
@@ -300,7 +308,7 @@ class SoftBodyObject extends Box2dObject
300
308
  for (let y = 0; y < sy.y; ++y) poly.push(this.getNode(sx-1, y).pos);
301
309
  for (let x = sx; x--;) poly.push(this.getNode(x, sy-1).pos);
302
310
  for (let y = sy; y--;) poly.push(this.getNode(0, y).pos);
303
- box2d.drawPoly(vec2(), 0, poly, BLACK)
311
+ LJS.box2d.drawPoly(vec2(), 0, poly, LJS.BLACK)
304
312
  }
305
313
  getNode(x, y)
306
314
  {
@@ -317,14 +325,14 @@ class SoftBodyObject extends Box2dObject
317
325
  ///////////////////////////////////////////////////////////////////////////////
318
326
 
319
327
  // cloth sim using grid of rope joints
320
- class ClothObject extends Box2dObject
328
+ export class ClothObject extends LJS.Box2dObject
321
329
  {
322
330
  constructor(pos, scale, sizeCount, color, maxJointStress=10)
323
331
  {
324
- super(pos, vec2(), 0, 0, color, box2d.bodyTypeStatic);
332
+ super(pos, vec2(), 0, 0, color, LJS.box2d.bodyTypeStatic);
325
333
  const nodeSize = sizeCount.subtract(vec2(1));
326
334
  const spacing = scale.divide(nodeSize);
327
- const objectDiameter = min(spacing.x, spacing.y);
335
+ const objectDiameter = LJS.min(spacing.x, spacing.y);
328
336
  this.sizeCount = sizeCount.copy();
329
337
  this.maxJointStress = maxJointStress;
330
338
  this.lineWidth = .1;
@@ -337,7 +345,7 @@ class ClothObject extends Box2dObject
337
345
  const mass = .5;
338
346
  const center = vec2(x-nodeSize.x/2, y-nodeSize.y/2);
339
347
  const p = pos.add(center.multiply(spacing));
340
- const o = new Box2dObject(p, vec2(.4), spriteAtlas.circle, 0, color);
348
+ const o = new LJS.Box2dObject(p, vec2(.4), Game.spriteAtlas.circle, 0, color);
341
349
  o.addCircle(objectDiameter);
342
350
  o.setFilterData(2, 2);
343
351
  o.setLinearDamping(1);
@@ -357,7 +365,7 @@ class ClothObject extends Box2dObject
357
365
  const tryAddJoint = (xo, yo) =>
358
366
  {
359
367
  const o2 = this.getNode(x2+xo, y+yo);
360
- const joint = o2 ? new Box2dRopeJoint(o, o2) : 0;
368
+ const joint = o2 ? new LJS.Box2dRopeJoint(o, o2) : 0;
361
369
  o.joints.push(joint);
362
370
  }
363
371
 
@@ -374,7 +382,7 @@ class ClothObject extends Box2dObject
374
382
  tryAddJoint( d, 1);
375
383
 
376
384
  // attach pin joint to top row
377
- y || new Box2dPinJoint(this.getNode(x, y), this);
385
+ y || new LJS.Box2dPinJoint(this.getNode(x, y), this);
378
386
  }
379
387
  }
380
388
  }
@@ -430,7 +438,7 @@ class ClothObject extends Box2dObject
430
438
  if (!joint) continue;
431
439
  const oA = joint.getObjectA();
432
440
  const oB = joint.getObjectB();
433
- drawLine(oA.pos, oB.pos, this.lineWidth, BLACK);
441
+ LJS.drawLine(oA.pos, oB.pos, this.lineWidth, LJS.BLACK);
434
442
  }
435
443
  }
436
444
  }
@@ -444,43 +452,42 @@ class ClothObject extends Box2dObject
444
452
  ///////////////////////////////////////////////////////////////////////////////
445
453
  // Effects
446
454
 
447
- const sound_click = new Sound([.2,.1,,,,.01,,,,,,,,,,,,,,,-500]); // Loaded Sound 0
448
- const sound_explosion = new Sound([.5,.2,72,.01,.01,.2,4,,,,,,,1,,.5,.1,.5,.02]);
455
+ const sound_explosion = new LJS.Sound([.5,.2,72,.01,.01,.2,4,,,,,,,1,,.5,.1,.5,.02]);
449
456
 
450
- function explosion(pos, radius=3, strength=300)
457
+ export function explosion(pos, radius=3, strength=300)
451
458
  {
452
459
  sound_explosion.play(pos);
453
- const objects = box2d.circleCastAll(pos, (radius*2));
454
- const newColor = randColor();
460
+ const objects = LJS.box2d.circleCastAll(pos, (radius*2));
461
+ const newColor = LJS.randColor();
455
462
  for (const o of objects)
456
463
  {
457
- const p = percent(o.pos.distance(pos), 2*radius, radius);
464
+ const p = LJS.percent(o.pos.distance(pos), 2*radius, radius);
458
465
  const force = o.pos.subtract(pos).normalize(p*radius*strength);
459
466
  o.applyForce(force);
460
467
  o.color = newColor;
461
468
  }
462
469
 
463
470
  // smoke
464
- new ParticleEmitter(
465
- pos, 0, // pos, angle
466
- radius/2, .2, 50*radius, PI,// emitSize, emitTime, emitRate, emitCone
467
- spriteAtlas.dot, // tileInfo
468
- hsl(0,0,0), hsl(0,0,0), // colorStartA, colorStartB
469
- hsl(0,0,0,0), hsl(0,0,0,0), // colorEndA, colorEndB
470
- 1, 1, 2, .1, .1, // time, sizeStart, sizeEnd, speed, angleSpeed
471
- .9, 1, -.5, PI, .1, // damp, angleDamp, gravity, particleCone, fade
472
- 1, 0, 0, 0, 1e8 // randomness, collide, additive, colorLinear, renderOrder
471
+ new LJS.ParticleEmitter(
472
+ pos, 0, // pos, angle
473
+ radius/2, .2, 50*radius, 3.14,// emitSize, emitTime, emitRate, emitCone
474
+ Game.spriteAtlas.dot, // tileInfo
475
+ hsl(0,0,0), hsl(0,0,0), // colorStartA, colorStartB
476
+ hsl(0,0,0,0), hsl(0,0,0,0), // colorEndA, colorEndB
477
+ 1, 1, 2, .1, .1, // time, sizeStart, sizeEnd, speed, angleSpeed
478
+ .9, 1, -.5, 3.14, .1, // damp, angleDamp, gravity, particleCone, fade
479
+ 1, 0, 0, 0, 1e8 // randomness, collide, additive, colorLinear, renderOrder
473
480
  );
474
481
 
475
482
  // fire
476
- new ParticleEmitter(
483
+ new LJS.ParticleEmitter(
477
484
  pos, 0, // pos, angle
478
- radius, .1, 100*radius, PI, // emitSize, emitTime, emitRate, emitCone
479
- spriteAtlas.dot, // tileInfo
485
+ radius, .1, 100*radius, 3.14, // emitSize, emitTime, emitRate, emitCone
486
+ Game.spriteAtlas.dot, // tileInfo
480
487
  hsl(0,1,.5), hsl(.15,1,.5), // colorStartA, colorStartB
481
488
  hsl(0,1,.5,0), hsl(.1, 1,.5,0), // colorEndA, colorEndB
482
- .7, 1, .5, .1, .1, // time, sizeStart, sizeEnd, speed, angleSpeed
483
- .9, 1, 0, PI, .05, // damp, angleDamp, gravity, particleCone, fade
484
- 1, 0, 1, 0, 1e9 // randomness, collide, additive, colorLinear, renderOrder
489
+ .7, 1, .5, .1, .1, // time, sizeStart, sizeEnd, speed, angleSpeed
490
+ .9, 1, 0, 3.14, .05, // damp, angleDamp, gravity, particleCone, fade
491
+ 1, 0, 1, 0, 1e9 // randomness, collide, additive, colorLinear, renderOrder
485
492
  );
486
- }
493
+ }
@@ -5,10 +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
-
9
- <script src=../../dist/littlejs.js?11115></script>
10
- <script src=../../plugins/box2d.wasm.js?11115></script>
11
- <script src=../../plugins/box2d.js?11115></script>
12
- <script src=scenes.js?11115></script>
13
- <script src=gameObjects.js?11115></script>
14
- <script src=game.js?11115></script>
8
+ <script src=../../dist/box2d.wasm.js></script>
9
+ <script src=game.js type=module></script>