littlejsengine 1.18.15 → 1.18.17

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.
@@ -139,10 +139,10 @@ class EngineObject
139
139
  if (pa)
140
140
  {
141
141
  const c = cos(-pa), s = sin(-pa);
142
- this.pos = new Vector2(lx*c - ly*s + pp.x, lx*s + ly*c + pp.y);
142
+ this.pos.set(lx*c - ly*s + pp.x, lx*s + ly*c + pp.y);
143
143
  }
144
144
  else
145
- this.pos = new Vector2(lx + pp.x, ly + pp.y);
145
+ this.pos.set(lx + pp.x, ly + pp.y);
146
146
  this.angle = mirror*this.localAngle + pa;
147
147
  }
148
148
 
@@ -374,6 +374,9 @@ class EngineObject
374
374
  drawTile(this.pos, this.drawSize || this.size, this.tileInfo, this.color, this.angle, this.mirror, this.additiveColor);
375
375
  }
376
376
 
377
+ /** Optional hook called during the light system plugin's lightmap pass to draw this object's lightmap contribution. Does nothing by default. */
378
+ renderLight() {}
379
+
377
380
  /** Destroy this object, destroy its children, detach its parent, and mark it for removal
378
381
  * @param {boolean} [immediate] - should attached effects be allowed to die off? */
379
382
  destroy(immediate=false)
@@ -62,10 +62,10 @@ class ParticleEmitter extends EngineObject
62
62
  * @param {number} [particleTime] - How long particles live
63
63
  * @param {number} [sizeStart] - How big are particles at start
64
64
  * @param {number} [sizeEnd] - How big are particles at end
65
- * @param {number} [speed] - How fast are particles when spawned
66
- * @param {number} [angleSpeed] - How fast are particles rotating
67
- * @param {number} [damping] - How much to dampen particle speed
68
- * @param {number} [angleDamping] - How much to dampen particle angular speed
65
+ * @param {number} [speed] - How fast are particles when spawned, in world units per frame (at 60fps, so multiply units/sec by 1/60)
66
+ * @param {number} [angleSpeed] - How fast are particles rotating, in radians per frame (at 60fps)
67
+ * @param {number} [damping] - How much to dampen particle speed, per-frame velocity multiplier (1 = no damping, .9 = lose 10% speed each frame)
68
+ * @param {number} [angleDamping] - How much to dampen particle angular speed, per-frame multiplier (1 = no damping)
69
69
  * @param {number} [gravityScale] - How much gravity effect particles
70
70
  * @param {number} [particleConeAngle] - Cone for start particle angle
71
71
  * @param {number} [fadeRate] - Fraction of life spent fading: half at fade-in (start), half at fade-out (end). e.g. .2 = 10% fade-in, 80% full opacity, 10% fade-out
@@ -140,13 +140,13 @@ class ParticleEmitter extends EngineObject
140
140
  this.sizeStart = sizeStart;
141
141
  /** @property {number} - How big are particles at end */
142
142
  this.sizeEnd = sizeEnd;
143
- /** @property {number} - How fast are particles when spawned */
143
+ /** @property {number} - Particle speed when spawned, in world units per frame (at 60fps) */
144
144
  this.speed = speed;
145
- /** @property {number} - How fast are particles rotating */
145
+ /** @property {number} - Particle angular speed when spawned, in radians per frame (at 60fps) */
146
146
  this.angleSpeed = angleSpeed;
147
- /** @property {number} - How much to dampen particle speed */
147
+ /** @property {number} - Per-frame velocity multiplier (1 = no damping, .9 = lose 10% speed each frame) */
148
148
  this.damping = damping;
149
- /** @property {number} - How much to dampen particle angular speed */
149
+ /** @property {number} - Per-frame angular velocity multiplier (1 = no damping) */
150
150
  this.angleDamping = angleDamping;
151
151
  /** @property {number} - How much gravity affects particles */
152
152
  this.gravityScale = gravityScale;
@@ -215,12 +215,16 @@ class ParticleEmitter extends EngineObject
215
215
  else if (this.particles.length === 0)
216
216
  this.destroy(true);
217
217
 
218
- // update and remove destroyed particles
219
- this.particles = this.particles.filter((p)=>
218
+ // update and remove destroyed particles in place to avoid per-frame array allocation
219
+ const particles = this.particles;
220
+ let alive = 0;
221
+ for (let i = 0; i < particles.length; ++i)
220
222
  {
223
+ const p = particles[i];
221
224
  p.update();
222
- return !p.destroyed;
223
- });
225
+ if (!p.destroyed) particles[alive++] = p;
226
+ }
227
+ particles.length = alive;
224
228
 
225
229
  if (debugParticles)
226
230
  {
@@ -502,7 +506,7 @@ class Particle
502
506
  {
503
507
  // in local space of emitter
504
508
  const a = emitter.angle;
505
- const c = cos(a), s = sin(a);
509
+ const c = cos(-a), s = sin(-a);
506
510
  pos.set(emitter.pos.x + pos.x*c - pos.y*s,
507
511
  emitter.pos.y + pos.x*s + pos.y*c);
508
512
  angle += a;
@@ -510,8 +514,8 @@ class Particle
510
514
  if (trailScale)
511
515
  {
512
516
  // trail style particles
513
- const velocity = localSpace ?
514
- this.velocity.rotate(-emitter.angle) : this.velocity;
517
+ const velocity = localSpace ?
518
+ this.velocity.rotate(emitter.angle) : this.velocity;
515
519
  const speed = velocity.length();
516
520
  if (speed)
517
521
  {
@@ -18,6 +18,7 @@ const debugPhysics = 0;
18
18
  const debugParticles = 0;
19
19
  const debugRaycast = 0;
20
20
  const debugGamepads = 0;
21
+ const debugSound = 0;
21
22
  const debugPointSize = .5;
22
23
 
23
24
  // debug commands are automatically removed from the final build
@@ -244,35 +244,78 @@ let touchInputEnable = true;
244
244
  * - Supports left analog stick, 4 face buttons and start button (button 9)
245
245
  * - setTouchGamepadButtonCount(1) to use face buttons as right analog stick
246
246
  * - Analog stick buttons 10 and 11 are also activated when virtual sticks are touched
247
-
247
+ * - Rendered as a full-viewport HTML/SVG overlay, so controls may sit outside the game canvas
248
248
  * @type {boolean}
249
249
  * @default
250
250
  * @memberof Settings */
251
251
  let touchGamepadEnable = false;
252
252
 
253
- /** True if touch gamepad should have start button in the center
254
- * - Prevents activating within 2*touchGamepadSize of the virtual stick or face buttons
255
- * (one radius for the visible control + one radius of buffer beyond its edge)
253
+ /** True if touches outside the gamepad controls should still drive mouse/touch input
254
+ * - When false (the default), enabling the touch gamepad suppresses touch-to-mouse input entirely
255
+ * - Set true to also pass touches outside the controls through to the game as mouse/touch input
256
+ * - Touches on the gamepad controls never drive the mouse regardless of this setting
257
+ * @type {boolean}
258
+ * @default
259
+ * @memberof Settings */
260
+ let touchGamepadPassthrough = false;
261
+
262
+ /** Size of center button if touch gamepad should have start button in the center
263
+ * - Prevents activating when pressed near virtual stick or face buttons
256
264
  * - When the game is paused, any touch will press the button
257
- * - Set size to enable the center button
265
+ * - Measured in viewport CSS pixels
258
266
  * @type {number}
259
267
  * @default
260
268
  * @memberof Settings */
261
- let touchGamepadCenterButtonSize = 300;
269
+ let touchGamepadCenterButtonSize = 0;
262
270
 
263
- /** Number of buttons on touch gamepad (0-4), if 1 also acts as right analog stick
271
+ /** Number of buttons on the right side of the touch gamepad (0-4), using gamepad buttons 0-3
272
+ * - A count of 1 is a single large button (the size of a stick)
273
+ * - Ignored when touchGamepadRightStick is set (the right side is a stick instead)
264
274
  * @type {number}
265
275
  * @default
266
276
  * @memberof Settings */
267
277
  let touchGamepadButtonCount = 4;
268
278
 
279
+ /** True if the touch gamepad should have a left analog stick (or dpad)
280
+ * - When false, the left side is face buttons (touchGamepadLeftButtonCount) or nothing
281
+ * @type {boolean}
282
+ * @default
283
+ * @memberof Settings */
284
+ let touchGamepadLeftStick = true;
285
+
286
+ /** Number of buttons on the left side of the touch gamepad (0-4), using gamepad buttons 4-7
287
+ * - Only used when touchGamepadLeftStick is false (otherwise the left side is a stick)
288
+ * - A count of 1 is a single large button (the size of a stick)
289
+ * @type {number}
290
+ * @default
291
+ * @memberof Settings */
292
+ let touchGamepadLeftButtonCount = 0;
293
+
294
+ /** True if the touch gamepad right side should be an analog stick (or dpad) instead of face buttons
295
+ * - When set, touchGamepadButtonCount is ignored and the right side is a stick
296
+ * - Uses an analog stick when touchGamepadAnalog is true, otherwise an 8 way dpad
297
+ * @type {boolean}
298
+ * @default
299
+ * @memberof Settings */
300
+ let touchGamepadRightStick = false;
301
+
269
302
  /** True if touch gamepad should be analog stick or false to use if 8 way dpad
270
303
  * @type {boolean}
271
304
  * @default
272
305
  * @memberof Settings */
273
306
  let touchGamepadAnalog = true;
274
307
 
275
- /** Size of virtual gamepad for touch devices in pixels
308
+ /** True if touch gamepad directional controls should float to where you press
309
+ * - Only affects analog sticks and dpads, not face buttons
310
+ * - Directional controls re-anchor to where you press within the bottom ~60% of their screen half; the top ~40% passes through to the game
311
+ * - The right side floats only when it acts as the right analog stick (touchGamepadRightStick is set)
312
+ * - A center button (touchGamepadCenterButtonSize) still works since it ignores touches near the sticks
313
+ * @type {boolean}
314
+ * @default
315
+ * @memberof Settings */
316
+ let touchGamepadFloating = false;
317
+
318
+ /** Size of virtual gamepad for touch devices in viewport CSS pixels
276
319
  * @type {number}
277
320
  * @default
278
321
  * @memberof Settings */
@@ -290,6 +333,13 @@ let touchGamepadAlpha = .3;
290
333
  * @memberof Settings */
291
334
  let touchGamepadDisplayTime = 3;
292
335
 
336
+ /** Duration in ms to vibrate when a touch gamepad face button or start button is pressed
337
+ * - Set to 0 to disable, also requires vibrateEnable and hardware support (ignored on iOS)
338
+ * @type {number}
339
+ * @default
340
+ * @memberof Settings */
341
+ let touchGamepadVibration = 0;
342
+
293
343
  /** Allow vibration hardware if it exists
294
344
  * @type {boolean}
295
345
  * @default
@@ -522,6 +572,11 @@ function setTouchInputEnable(enable) { touchInputEnable = enable; }
522
572
  * @memberof Settings */
523
573
  function setTouchGamepadEnable(enable) { touchGamepadEnable = enable; }
524
574
 
575
+ /** Set if touches outside the gamepad controls should still drive mouse/touch input
576
+ * @param {boolean} passthrough
577
+ * @memberof Settings */
578
+ function setTouchGamepadPassthrough(passthrough) { touchGamepadPassthrough = passthrough; }
579
+
525
580
  /** Set if touch gamepad should have start button in the center
526
581
  * - Set size to enable the center button
527
582
  * - When the game is paused, any touch will press the button
@@ -529,16 +584,57 @@ function setTouchGamepadEnable(enable) { touchGamepadEnable = enable; }
529
584
  * @memberof Settings */
530
585
  function setTouchGamepadCenterButtonSize(size) { touchGamepadCenterButtonSize = size; }
531
586
 
532
- /** Set number of buttons on touch gamepad (0-4), if 1 also acts as right analog stick
587
+ /** Set number of buttons on the right side of the touch gamepad (0-4, gamepad buttons 0-3)
588
+ * @param {number} count
589
+ * @memberof Settings */
590
+ function setTouchGamepadButtonCount(count)
591
+ {
592
+ touchGamepadButtonCount = count;
593
+ if (count > 0)
594
+ touchGamepadRightStick = false;
595
+ }
596
+
597
+ /** Set if the touch gamepad should have a left analog stick (or dpad)
598
+ * @param {boolean} enable
599
+ * @memberof Settings */
600
+ function setTouchGamepadLeftStick(enable)
601
+ {
602
+ touchGamepadLeftStick = enable;
603
+ if (enable)
604
+ touchGamepadLeftButtonCount = 0;
605
+ }
606
+
607
+ /** Set number of buttons on the left side of the touch gamepad (0-4, gamepad buttons 4-7)
608
+ * - Only used when touchGamepadLeftStick is false
533
609
  * @param {number} count
534
610
  * @memberof Settings */
535
- function setTouchGamepadButtonCount(count) { touchGamepadButtonCount = count; }
611
+ function setTouchGamepadLeftButtonCount(count)
612
+ {
613
+ touchGamepadLeftButtonCount = count;
614
+ if (count > 0)
615
+ touchGamepadLeftStick = false;
616
+ }
617
+
618
+ /** Set if the touch gamepad right side is an analog stick (or dpad) instead of face buttons
619
+ * @param {boolean} rightStick
620
+ * @memberof Settings */
621
+ function setTouchGamepadRightStick(rightStick)
622
+ {
623
+ touchGamepadRightStick = rightStick;
624
+ if (rightStick)
625
+ touchGamepadButtonCount = 0;
626
+ }
536
627
 
537
628
  /** Set if touch gamepad should be analog stick or 8 way dpad
538
629
  * @param {boolean} analog
539
630
  * @memberof Settings */
540
631
  function setTouchGamepadAnalog(analog) { touchGamepadAnalog = analog; }
541
632
 
633
+ /** Set if touch gamepad directional controls should float to where you press
634
+ * @param {boolean} floating
635
+ * @memberof Settings */
636
+ function setTouchGamepadFloating(floating) { touchGamepadFloating = floating; }
637
+
542
638
  /** Set size of virtual gamepad for touch devices in pixels
543
639
  * @param {number} size
544
640
  * @memberof Settings */
@@ -554,6 +650,11 @@ function setTouchGamepadAlpha(alpha) { touchGamepadAlpha = alpha; }
554
650
  * @memberof Settings */
555
651
  function setTouchGamepadDisplayTime(time) { touchGamepadDisplayTime = time; }
556
652
 
653
+ /** Set duration in ms to vibrate when a touch gamepad face or start button is pressed (0 disables)
654
+ * @param {number} ms
655
+ * @memberof Settings */
656
+ function setTouchGamepadVibration(ms) { touchGamepadVibration = ms; }
657
+
557
658
  /** Set to allow vibration hardware if it exists
558
659
  * @param {boolean} enable
559
660
  * @memberof Settings */
@@ -675,6 +675,11 @@ class TileCollisionLayer extends TileLayer
675
675
  // check any tiles in the area for collision
676
676
  const posX = pos.x - this.pos.x;
677
677
  const posY = pos.y - this.pos.y;
678
+ // reject AABBs entirely past either edge; without this, the negative
679
+ // side leaks into row/col 0 because minX/minY clamp to 0 and the
680
+ // point-test floor below forces maxX/maxY up to 1
681
+ if (posX + size.x/2 < 0 || posX - size.x/2 > this.size.x) return false;
682
+ if (posY + size.y/2 < 0 || posY - size.y/2 > this.size.y) return false;
678
683
  const minX = max(posX - size.x/2|0, 0);
679
684
  const minY = max(posY - size.y/2|0, 0);
680
685
  // ensure at least one cell is visited even when size is 0 and pos