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.
- package/README.md +4 -4
- package/dist/littlejs.d.ts +198 -17
- package/dist/littlejs.esm.js +1180 -257
- package/dist/littlejs.esm.min.js +1 -1
- package/dist/littlejs.js +1160 -257
- package/dist/littlejs.min.js +1 -1
- package/dist/littlejs.release.js +1134 -241
- package/package.json +1 -1
- package/plugins/box2d.js +9 -13
- package/plugins/drawUtilities.js +63 -0
- package/plugins/lightSystem.js +330 -0
- package/plugins/medalSystem.js +36 -5
- package/plugins/pluginExport.js +8 -0
- package/src/engine.js +1 -1
- package/src/engineAudio.js +21 -3
- package/src/engineBuild.mjs +1 -0
- package/src/engineDebug.js +27 -16
- package/src/engineDraw.js +9 -6
- package/src/engineExport.js +12 -0
- package/src/engineInput.js +528 -189
- package/src/engineObject.js +5 -2
- package/src/engineParticles.js +19 -15
- package/src/engineRelease.js +1 -0
- package/src/engineSettings.js +111 -10
- package/src/engineTileLayer.js +5 -0
package/src/engineObject.js
CHANGED
|
@@ -139,10 +139,10 @@ class EngineObject
|
|
|
139
139
|
if (pa)
|
|
140
140
|
{
|
|
141
141
|
const c = cos(-pa), s = sin(-pa);
|
|
142
|
-
this.pos
|
|
142
|
+
this.pos.set(lx*c - ly*s + pp.x, lx*s + ly*c + pp.y);
|
|
143
143
|
}
|
|
144
144
|
else
|
|
145
|
-
this.pos
|
|
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)
|
package/src/engineParticles.js
CHANGED
|
@@ -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} -
|
|
143
|
+
/** @property {number} - Particle speed when spawned, in world units per frame (at 60fps) */
|
|
144
144
|
this.speed = speed;
|
|
145
|
-
/** @property {number} -
|
|
145
|
+
/** @property {number} - Particle angular speed when spawned, in radians per frame (at 60fps) */
|
|
146
146
|
this.angleSpeed = angleSpeed;
|
|
147
|
-
/** @property {number} -
|
|
147
|
+
/** @property {number} - Per-frame velocity multiplier (1 = no damping, .9 = lose 10% speed each frame) */
|
|
148
148
|
this.damping = damping;
|
|
149
|
-
/** @property {number} -
|
|
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
|
-
|
|
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
|
-
|
|
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(
|
|
517
|
+
const velocity = localSpace ?
|
|
518
|
+
this.velocity.rotate(emitter.angle) : this.velocity;
|
|
515
519
|
const speed = velocity.length();
|
|
516
520
|
if (speed)
|
|
517
521
|
{
|
package/src/engineRelease.js
CHANGED
package/src/engineSettings.js
CHANGED
|
@@ -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
|
|
254
|
-
* -
|
|
255
|
-
*
|
|
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
|
-
* -
|
|
265
|
+
* - Measured in viewport CSS pixels
|
|
258
266
|
* @type {number}
|
|
259
267
|
* @default
|
|
260
268
|
* @memberof Settings */
|
|
261
|
-
let touchGamepadCenterButtonSize =
|
|
269
|
+
let touchGamepadCenterButtonSize = 0;
|
|
262
270
|
|
|
263
|
-
/** Number of buttons on touch gamepad (0-4),
|
|
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
|
-
/**
|
|
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
|
|
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
|
|
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 */
|
package/src/engineTileLayer.js
CHANGED
|
@@ -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
|