littlejsengine 1.11.9 → 1.11.13

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 (44) hide show
  1. package/README.md +3 -3
  2. package/dist/littlejs.d.ts +485 -492
  3. package/dist/littlejs.esm.js +548 -529
  4. package/dist/littlejs.esm.min.js +1 -1
  5. package/dist/littlejs.js +546 -525
  6. package/dist/littlejs.min.js +1 -1
  7. package/dist/littlejs.release.js +502 -484
  8. package/examples/htmlMenu/game.js +11 -1
  9. package/examples/htmlMenu/index.html +1 -10
  10. package/examples/module/game.js +2 -2
  11. package/examples/shorts/base.html +1 -1
  12. package/examples/starter/build/index.html +2 -0
  13. package/examples/starter/build/index.js +1 -0
  14. package/examples/starter/build/tiles.png +0 -0
  15. package/examples/starter/build.js +13 -3
  16. package/examples/starter/game.js +8 -1
  17. package/examples/starter/game.zip +0 -0
  18. package/examples/typescript/build/dist/littlejs.esm.js +4834 -0
  19. package/examples/typescript/build/examples/typescript/build.js +24 -0
  20. package/examples/typescript/build/examples/typescript/game.js +102 -0
  21. package/examples/typescript/build.bat +5 -0
  22. package/examples/typescript/build.js +33 -0
  23. package/examples/typescript/game.js +102 -0
  24. package/examples/typescript/game.ts +134 -0
  25. package/examples/typescript/index.html +10 -0
  26. package/examples/typescript/tiles.png +0 -0
  27. package/examples/typescript/tsconfig.json +8 -0
  28. package/package.json +1 -1
  29. package/plugins/newgrounds.js +44 -35
  30. package/plugins/postProcess.js +18 -4
  31. package/plugins/uiSystem.js +196 -30
  32. package/src/engine.js +21 -20
  33. package/src/engineAudio.js +59 -59
  34. package/src/engineDebug.js +44 -41
  35. package/src/engineDraw.js +58 -58
  36. package/src/engineExport.js +2 -4
  37. package/src/engineInput.js +40 -35
  38. package/src/engineMedals.js +21 -11
  39. package/src/engineObject.js +42 -35
  40. package/src/engineParticles.js +10 -10
  41. package/src/engineSettings.js +77 -82
  42. package/src/engineTileLayer.js +21 -21
  43. package/src/engineUtilities.js +150 -150
  44. package/src/engineWebGL.js +3 -3
@@ -35,9 +35,9 @@ class EngineObject
35
35
  * @param {Vector2} [pos=(0,0)] - World space position of the object
36
36
  * @param {Vector2} [size=(1,1)] - World space size of the object
37
37
  * @param {TileInfo} [tileInfo] - Tile info to render object (undefined is untextured)
38
- * @param {Number} [angle] - Angle the object is rotated by
38
+ * @param {number} [angle] - Angle the object is rotated by
39
39
  * @param {Color} [color=(1,1,1,1)] - Color to apply to tile when rendered
40
- * @param {Number} [renderOrder] - Objects sorted by renderOrder before being rendered
40
+ * @param {number} [renderOrder] - Objects sorted by renderOrder before being rendered
41
41
  */
42
42
  constructor(pos=vec2(), size=vec2(1), tileInfo, angle=0, color=new Color, renderOrder=0)
43
43
  {
@@ -53,57 +53,59 @@ class EngineObject
53
53
  this.drawSize = undefined;
54
54
  /** @property {TileInfo} - Tile info to render object (undefined is untextured) */
55
55
  this.tileInfo = tileInfo;
56
- /** @property {Number} - Angle to rotate the object */
56
+ /** @property {number} - Angle to rotate the object */
57
57
  this.angle = angle;
58
58
  /** @property {Color} - Color to apply when rendered */
59
59
  this.color = color;
60
60
  /** @property {Color} - Additive color to apply when rendered */
61
61
  this.additiveColor = undefined;
62
- /** @property {Boolean} - Should it flip along y axis when rendered */
62
+ /** @property {boolean} - Should it flip along y axis when rendered */
63
63
  this.mirror = false;
64
64
 
65
65
  // physical properties
66
- /** @property {Number} [mass=objectDefaultMass] - How heavy the object is, static if 0 */
66
+ /** @property {number} [mass=objectDefaultMass] - How heavy the object is, static if 0 */
67
67
  this.mass = objectDefaultMass;
68
- /** @property {Number} [damping=objectDefaultDamping] - How much to slow down velocity each frame (0-1) */
68
+ /** @property {number} [damping=objectDefaultDamping] - How much to slow down velocity each frame (0-1) */
69
69
  this.damping = objectDefaultDamping;
70
- /** @property {Number} [angleDamping=objectDefaultAngleDamping] - How much to slow down rotation each frame (0-1) */
70
+ /** @property {number} [angleDamping=objectDefaultAngleDamping] - How much to slow down rotation each frame (0-1) */
71
71
  this.angleDamping = objectDefaultAngleDamping;
72
- /** @property {Number} [elasticity=objectDefaultElasticity] - How bouncy the object is when colliding (0-1) */
72
+ /** @property {number} [elasticity=objectDefaultElasticity] - How bouncy the object is when colliding (0-1) */
73
73
  this.elasticity = objectDefaultElasticity;
74
- /** @property {Number} [friction=objectDefaultFriction] - How much friction to apply when sliding (0-1) */
74
+ /** @property {number} [friction=objectDefaultFriction] - How much friction to apply when sliding (0-1) */
75
75
  this.friction = objectDefaultFriction;
76
- /** @property {Number} - How much to scale gravity by for this object */
76
+ /** @property {number} - How much to scale gravity by for this object */
77
77
  this.gravityScale = 1;
78
- /** @property {Number} - Objects are sorted by render order */
78
+ /** @property {number} - Objects are sorted by render order */
79
79
  this.renderOrder = renderOrder;
80
80
  /** @property {Vector2} - Velocity of the object */
81
81
  this.velocity = vec2();
82
- /** @property {Number} - Angular velocity of the object */
82
+ /** @property {number} - Angular velocity of the object */
83
83
  this.angleVelocity = 0;
84
- /** @property {Number} - Track when object was created */
84
+ /** @property {number} - Track when object was created */
85
85
  this.spawnTime = time;
86
- /** @property {Array} - List of children of this object */
86
+ /** @property {Array<EngineObject>} - List of children of this object */
87
87
  this.children = [];
88
- /** @property {Boolean} - Limit object speed using linear or circular math */
88
+ /** @property {boolean} - Limit object speed using linear or circular math */
89
89
  this.clampSpeedLinear = true;
90
+ /** @property {EngineObject} - Object we are standing on, if any */
91
+ this.groundObject = undefined;
90
92
 
91
93
  // parent child system
92
94
  /** @property {EngineObject} - Parent of object if in local space */
93
95
  this.parent = undefined;
94
96
  /** @property {Vector2} - Local position if child */
95
97
  this.localPos = vec2();
96
- /** @property {Number} - Local angle if child */
98
+ /** @property {number} - Local angle if child */
97
99
  this.localAngle = 0;
98
100
 
99
101
  // collision flags
100
- /** @property {Boolean} - Object collides with the tile collision */
102
+ /** @property {boolean} - Object collides with the tile collision */
101
103
  this.collideTiles = false;
102
- /** @property {Boolean} - Object collides with solid objects */
104
+ /** @property {boolean} - Object collides with solid objects */
103
105
  this.collideSolidObjects = false;
104
- /** @property {Boolean} - Object collides with and blocks other objects */
106
+ /** @property {boolean} - Object collides with and blocks other objects */
105
107
  this.isSolid = false;
106
- /** @property {Boolean} - Object collides with raycasts */
108
+ /** @property {boolean} - Object collides with raycasts */
107
109
  this.collideRaycast = false;
108
110
 
109
111
  // add to list of objects
@@ -171,9 +173,10 @@ class EngineObject
171
173
  if (this.groundObject)
172
174
  {
173
175
  // apply friction in local space of ground object
174
- const groundSpeed = this.groundObject.velocity ? this.groundObject.velocity.x : 0;
176
+ const groundSpeed = this.groundObject != this && this.groundObject.velocity ?
177
+ this.groundObject.velocity.x : 0;
175
178
  this.velocity.x = groundSpeed + (this.velocity.x - groundSpeed) * this.friction;
176
- this.groundObject = 0;
179
+ this.groundObject = undefined;
177
180
  //debugOverlay && debugPhysics && debugPoint(this.pos.subtract(vec2(0,this.size.y/2)), '#0f0');
178
181
  }
179
182
 
@@ -290,18 +293,22 @@ class EngineObject
290
293
  // bounce velocity
291
294
  this.velocity.y *= -this.elasticity;
292
295
 
293
- // set if landed on ground
294
- if (this.groundObject = wasMovingDown)
296
+ if (wasMovingDown)
295
297
  {
296
298
  // adjust position to slightly above nearest tile boundary
297
299
  // this prevents gap between object and ground
298
300
  const epsilon = .0001;
299
301
  this.pos.y = (oldPos.y-this.size.y/2|0)+this.size.y/2+epsilon;
302
+
303
+ // set ground object to self for tile collision
304
+ // TODO: rework system so tile collision is its own object
305
+ this.groundObject = this;
300
306
  }
301
307
  else
302
308
  {
303
309
  // move to previous position
304
310
  this.pos.y = oldPos.y;
311
+ this.groundObject = undefined;
305
312
  }
306
313
  }
307
314
  if (isBlockedX)
@@ -353,19 +360,19 @@ class EngineObject
353
360
  worldToLocalVector(vec) { return vec.rotate(-this.angle); }
354
361
 
355
362
  /** Called to check if a tile collision should be resolved
356
- * @param {Number} tileData - the value of the tile at the position
363
+ * @param {number} tileData - the value of the tile at the position
357
364
  * @param {Vector2} pos - tile where the collision occurred
358
- * @return {Boolean} - true if the collision should be resolved */
365
+ * @return {boolean} - true if the collision should be resolved */
359
366
  collideWithTile(tileData, pos) { return tileData > 0; }
360
367
 
361
368
  /** Called to check if a object collision should be resolved
362
369
  * @param {EngineObject} object - the object to test against
363
- * @return {Boolean} - true if the collision should be resolved
370
+ * @return {boolean} - true if the collision should be resolved
364
371
  */
365
372
  collideWithObject(object) { return true; }
366
373
 
367
374
  /** How long since the object was created
368
- * @return {Number} */
375
+ * @return {number} */
369
376
  getAliveTime() { return time - this.spawnTime; }
370
377
 
371
378
  /** Apply acceleration to this object (adjust velocity, not affected by mass)
@@ -377,13 +384,13 @@ class EngineObject
377
384
  applyForce(force) { this.applyAcceleration(force.scale(1/this.mass)); }
378
385
 
379
386
  /** Get the direction of the mirror
380
- * @return {Number} -1 if this.mirror is true, or 1 if not mirrored */
387
+ * @return {number} -1 if this.mirror is true, or 1 if not mirrored */
381
388
  getMirrorSign() { return this.mirror ? -1 : 1; }
382
389
 
383
390
  /** Attaches a child to this with a given local transform
384
391
  * @param {EngineObject} child
385
392
  * @param {Vector2} [localPos=(0,0)]
386
- * @param {Number} [localAngle] */
393
+ * @param {number} [localAngle] */
387
394
  addChild(child, localPos=vec2(), localAngle=0)
388
395
  {
389
396
  ASSERT(!child.parent && !this.children.includes(child));
@@ -403,10 +410,10 @@ class EngineObject
403
410
  }
404
411
 
405
412
  /** Set how this object collides
406
- * @param {Boolean} [collideSolidObjects] - Does it collide with solid objects?
407
- * @param {Boolean} [isSolid] - Does it collide with and block other objects? (expensive in large numbers)
408
- * @param {Boolean} [collideTiles] - Does it collide with the tile collision?
409
- * @param {Boolean} [collideRaycast] - Does it collide with raycasts? */
413
+ * @param {boolean} [collideSolidObjects] - Does it collide with solid objects?
414
+ * @param {boolean} [isSolid] - Does it collide with and block other objects? (expensive in large numbers)
415
+ * @param {boolean} [collideTiles] - Does it collide with the tile collision?
416
+ * @param {boolean} [collideRaycast] - Does it collide with raycasts? */
410
417
  setCollision(collideSolidObjects=true, isSolid=true, collideTiles=true, collideRaycast=true)
411
418
  {
412
419
  ASSERT(collideSolidObjects || !isSolid, 'solid objects must be set to collide');
@@ -418,7 +425,7 @@ class EngineObject
418
425
  }
419
426
 
420
427
  /** Returns string containing info about this object for debugging
421
- * @return {String} */
428
+ * @return {string} */
422
429
  toString()
423
430
  {
424
431
  if (debug)
@@ -46,11 +46,11 @@ class ParticleEmitter extends EngineObject
46
46
  * @param {Number} [particleConeAngle] - Cone for start particle angle
47
47
  * @param {Number} [fadeRate] - How quick to fade particles at start/end in percent of life
48
48
  * @param {Number} [randomness] - Apply extra randomness percent
49
- * @param {Boolean} [collideTiles] - Do particles collide against tiles
50
- * @param {Boolean} [additive] - Should particles use additive blend
51
- * @param {Boolean} [randomColorLinear] - Should color be randomized linearly or across each component
49
+ * @param {boolean} [collideTiles] - Do particles collide against tiles
50
+ * @param {boolean} [additive] - Should particles use additive blend
51
+ * @param {boolean} [randomColorLinear] - Should color be randomized linearly or across each component
52
52
  * @param {Number} [renderOrder] - Render order for particles (additive is above other stuff by default)
53
- * @param {Boolean} [localSpace] - Should it be in local space of emitter (world space is default)
53
+ * @param {boolean} [localSpace] - Should it be in local space of emitter (world space is default)
54
54
  */
55
55
  constructor
56
56
  (
@@ -104,7 +104,7 @@ class ParticleEmitter extends EngineObject
104
104
  this.colorEndA = colorEndA;
105
105
  /** @property {Color} - Color at end of life 2, randomized between end colors */
106
106
  this.colorEndB = colorEndB;
107
- /** @property {Boolean} - Should color be randomized linearly or across each component */
107
+ /** @property {boolean} - Should color be randomized linearly or across each component */
108
108
  this.randomColorLinear = randomColorLinear;
109
109
 
110
110
  // particle settings
@@ -130,11 +130,11 @@ class ParticleEmitter extends EngineObject
130
130
  this.fadeRate = fadeRate;
131
131
  /** @property {Number} - Apply extra randomness percent */
132
132
  this.randomness = randomness;
133
- /** @property {Boolean} - Do particles collide against tiles */
133
+ /** @property {boolean} - Do particles collide against tiles */
134
134
  this.collideTiles = collideTiles;
135
- /** @property {Boolean} - Should particles use additive blend */
135
+ /** @property {boolean} - Should particles use additive blend */
136
136
  this.additive = additive;
137
- /** @property {Boolean} - Should it be in local space of emitter */
137
+ /** @property {boolean} - Should it be in local space of emitter */
138
138
  this.localSpace = localSpace;
139
139
  /** @property {Number} - If non zero the particle is drawn as a trail, stretched in the direction of velocity */
140
140
  this.trailScale = 0;
@@ -244,7 +244,7 @@ class Particle extends EngineObject
244
244
  * @param {Number} sizeStart - Size at start of life
245
245
  * @param {Number} sizeEnd - Size at end of life
246
246
  * @param {Number} fadeRate - How quick to fade in/out
247
- * @param {Boolean} additive - Does it use additive blend mode
247
+ * @param {boolean} additive - Does it use additive blend mode
248
248
  * @param {Number} trailScale - If a trail, how long to make it
249
249
  * @param {ParticleEmitter} [localSpaceEmitter] - Parent emitter if local space
250
250
  * @param {Function} [destroyCallback] - Callback when particle dies
@@ -266,7 +266,7 @@ class Particle extends EngineObject
266
266
  this.sizeEndDelta = sizeEnd - sizeStart;
267
267
  /** @property {Number} - How quick to fade in/out */
268
268
  this.fadeRate = fadeRate;
269
- /** @property {Boolean} - Is it additive */
269
+ /** @property {boolean} - Is it additive */
270
270
  this.additive = additive;
271
271
  /** @property {Number} - If a trail, how long to make it */
272
272
  this.trailScale = trailScale;