littlejsengine 1.17.1 → 1.17.10
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/LICENSE +10 -10
- package/dist/littlejs.d.ts +254 -171
- package/dist/littlejs.esm.js +892 -628
- package/dist/littlejs.esm.min.js +1 -1
- package/dist/littlejs.js +889 -626
- package/dist/littlejs.min.js +1 -1
- package/dist/littlejs.release.js +885 -622
- package/examples/box2d/gameObjects.js +3 -3
- package/examples/electron/index.html +2 -2
- package/examples/index.html +10 -9
- package/examples/logo.png +0 -0
- package/examples/logo2.png +0 -0
- package/examples/module/build.bat +7 -0
- package/examples/module/build.js +121 -0
- package/examples/particles/index.html +1 -1
- package/examples/platformer/game.js +1 -1
- package/examples/platformer/gameEffects.js +5 -10
- package/examples/platformer/gameLevel.js +3 -3
- package/examples/puzzle/game.js +2 -2
- package/examples/shorts/base.html +4 -1
- package/examples/shorts/box2dPool.js +2 -2
- package/examples/shorts/box2dTileLayer.js +48 -0
- package/examples/shorts/colors.js +1 -1
- package/examples/shorts/fps.js +1 -1
- package/examples/shorts/music.js +5 -4
- package/examples/shorts/musicPlayer.js +4 -3
- package/examples/shorts/parallax.js +2 -2
- package/examples/shorts/tiltedView.js +1 -1
- package/examples/starter/index.html +2 -2
- package/package.json +5 -5
- package/plugins/box2d.js +166 -63
- package/plugins/pluginExport.js +1 -1
- package/plugins/postProcess.js +1 -1
- package/plugins/uiSystem.js +33 -20
- package/plugins/zzfxm.js +2 -2
- package/reference.md +9 -8
- package/src/engine.js +111 -134
- package/src/engineAudio.js +44 -58
- package/src/engineDebug.js +4 -4
- package/src/engineDraw.js +7 -4
- package/src/engineExport.js +2 -1
- package/src/engineInput.js +5 -5
- package/src/engineMath.js +9 -9
- package/src/engineObject.js +25 -25
- package/src/engineParticles.js +241 -118
- package/src/engineTileLayer.js +117 -88
- package/src/engineUtilities.js +105 -78
- package/src/engineWebGL.js +2 -2
- package/plugins/Box2D_License.txt +0 -17
package/src/engineMath.js
CHANGED
|
@@ -16,25 +16,25 @@
|
|
|
16
16
|
const PI = Math.PI;
|
|
17
17
|
|
|
18
18
|
/** Returns absolute value of value passed in
|
|
19
|
-
* @param {number}
|
|
19
|
+
* @param {number} x
|
|
20
20
|
* @return {number}
|
|
21
21
|
* @memberof Math */
|
|
22
22
|
const abs = Math.abs;
|
|
23
23
|
|
|
24
24
|
/** Returns floored value of value passed in
|
|
25
|
-
* @param {number}
|
|
25
|
+
* @param {number} x
|
|
26
26
|
* @return {number}
|
|
27
27
|
* @memberof Math */
|
|
28
28
|
const floor = Math.floor;
|
|
29
29
|
|
|
30
30
|
/** Returns ceiled value of value passed in
|
|
31
|
-
* @param {number}
|
|
31
|
+
* @param {number} x
|
|
32
32
|
* @return {number}
|
|
33
33
|
* @memberof Math */
|
|
34
34
|
const ceil = Math.ceil;
|
|
35
35
|
|
|
36
36
|
/** Returns rounded value passed in
|
|
37
|
-
* @param {number}
|
|
37
|
+
* @param {number} x
|
|
38
38
|
* @return {number}
|
|
39
39
|
* @memberof Math */
|
|
40
40
|
const round = Math.round;
|
|
@@ -52,7 +52,7 @@ const min = Math.min;
|
|
|
52
52
|
const max = Math.max;
|
|
53
53
|
|
|
54
54
|
/** Returns the sign of value passed in
|
|
55
|
-
* @param {number}
|
|
55
|
+
* @param {number} x
|
|
56
56
|
* @return {number}
|
|
57
57
|
* @memberof Math */
|
|
58
58
|
const sign = Math.sign;
|
|
@@ -64,25 +64,25 @@ const sign = Math.sign;
|
|
|
64
64
|
const hypot = Math.hypot;
|
|
65
65
|
|
|
66
66
|
/** Returns log2 of value passed in
|
|
67
|
-
* @param {number}
|
|
67
|
+
* @param {number} x
|
|
68
68
|
* @return {number}
|
|
69
69
|
* @memberof Math */
|
|
70
70
|
const log2 = Math.log2;
|
|
71
71
|
|
|
72
72
|
/** Returns sin of value passed in
|
|
73
|
-
* @param {number}
|
|
73
|
+
* @param {number} x
|
|
74
74
|
* @return {number}
|
|
75
75
|
* @memberof Math */
|
|
76
76
|
const sin = Math.sin;
|
|
77
77
|
|
|
78
78
|
/** Returns cos of value passed in
|
|
79
|
-
* @param {number}
|
|
79
|
+
* @param {number} x
|
|
80
80
|
* @return {number}
|
|
81
81
|
* @memberof Math */
|
|
82
82
|
const cos = Math.cos;
|
|
83
83
|
|
|
84
84
|
/** Returns tan of value passed in
|
|
85
|
-
* @param {number}
|
|
85
|
+
* @param {number} x
|
|
86
86
|
* @return {number}
|
|
87
87
|
* @memberof Math */
|
|
88
88
|
const tan = Math.tan;
|
package/src/engineObject.js
CHANGED
|
@@ -66,17 +66,19 @@ class EngineObject
|
|
|
66
66
|
this.additiveColor = undefined;
|
|
67
67
|
/** @property {boolean} - Should it flip along y axis when rendered */
|
|
68
68
|
this.mirror = false;
|
|
69
|
+
/** @property {boolean} - Has object been destroyed? */
|
|
70
|
+
this.destroyed = false;
|
|
69
71
|
|
|
70
72
|
// physical properties
|
|
71
|
-
/** @property {number}
|
|
73
|
+
/** @property {number} - How heavy the object is, static if 0 */
|
|
72
74
|
this.mass = objectDefaultMass;
|
|
73
|
-
/** @property {number}
|
|
75
|
+
/** @property {number} - How much to slow down velocity each frame (0-1) */
|
|
74
76
|
this.damping = objectDefaultDamping;
|
|
75
|
-
/** @property {number}
|
|
77
|
+
/** @property {number} - How much to slow down rotation each frame (0-1) */
|
|
76
78
|
this.angleDamping = objectDefaultAngleDamping;
|
|
77
|
-
/** @property {number}
|
|
79
|
+
/** @property {number} - How bouncy the object is when colliding (0-1) */
|
|
78
80
|
this.restitution = objectDefaultRestitution;
|
|
79
|
-
/** @property {number}
|
|
81
|
+
/** @property {number} - How much friction to apply when sliding (0-1) */
|
|
80
82
|
this.friction = objectDefaultFriction;
|
|
81
83
|
/** @property {number} - How much to scale gravity by for this object */
|
|
82
84
|
this.gravityScale = 1;
|
|
@@ -277,7 +279,7 @@ class EngineObject
|
|
|
277
279
|
if (this.collideTiles)
|
|
278
280
|
{
|
|
279
281
|
// check collision against tiles
|
|
280
|
-
const hitLayer = tileCollisionTest(this.pos, this.size, this)
|
|
282
|
+
const hitLayer = tileCollisionTest(this.pos, this.size, this);
|
|
281
283
|
if (hitLayer)
|
|
282
284
|
{
|
|
283
285
|
// if already was stuck in collision, don't do anything
|
|
@@ -285,10 +287,10 @@ class EngineObject
|
|
|
285
287
|
if (!tileCollisionTest(oldPos, this.size, this))
|
|
286
288
|
{
|
|
287
289
|
// test which side we bounced off (or both if a corner)
|
|
288
|
-
const
|
|
289
|
-
const
|
|
290
|
-
|
|
291
|
-
if (
|
|
290
|
+
const isBlockedX = tileCollisionTest(vec2(this.pos.x, oldPos.y), this.size, this);
|
|
291
|
+
const isBlockedY = tileCollisionTest(vec2(oldPos.x, this.pos.y), this.size, this);
|
|
292
|
+
const restitution = max(this.restitution, hitLayer.restitution);
|
|
293
|
+
if (isBlockedX)
|
|
292
294
|
{
|
|
293
295
|
// try to move up a tiny bit
|
|
294
296
|
const epsilon = 1e-3;
|
|
@@ -304,16 +306,12 @@ class EngineObject
|
|
|
304
306
|
return;
|
|
305
307
|
}
|
|
306
308
|
|
|
307
|
-
// move to previous position and bounce
|
|
309
|
+
// move to previous X position and bounce
|
|
308
310
|
this.pos.x = oldPos.x;
|
|
309
|
-
this.velocity.x *= -
|
|
311
|
+
this.velocity.x *= -restitution;
|
|
310
312
|
}
|
|
311
|
-
if (
|
|
313
|
+
if (isBlockedY || !isBlockedX)
|
|
312
314
|
{
|
|
313
|
-
// bounce velocity
|
|
314
|
-
const restitution = max(this.restitution, hitLayer.restitution);
|
|
315
|
-
this.velocity.y *= -restitution;
|
|
316
|
-
|
|
317
315
|
if (wasFalling)
|
|
318
316
|
{
|
|
319
317
|
// adjust position to slightly away from nearest tile
|
|
@@ -329,10 +327,12 @@ class EngineObject
|
|
|
329
327
|
}
|
|
330
328
|
else
|
|
331
329
|
{
|
|
332
|
-
// move to previous position
|
|
330
|
+
// move to previous Y position
|
|
333
331
|
this.pos.y = oldPos.y;
|
|
334
332
|
this.groundObject = undefined;
|
|
335
333
|
}
|
|
334
|
+
// bounce velocity
|
|
335
|
+
this.velocity.y *= -restitution;
|
|
336
336
|
}
|
|
337
337
|
debugPhysics && debugRect(this.pos, this.size, '#f00');
|
|
338
338
|
}
|
|
@@ -350,19 +350,19 @@ class EngineObject
|
|
|
350
350
|
drawTile(this.pos, this.drawSize || this.size, this.tileInfo, this.color, this.angle, this.mirror, this.additiveColor);
|
|
351
351
|
}
|
|
352
352
|
|
|
353
|
-
/** Destroy this object, destroy its children, detach its parent, and mark it for removal
|
|
354
|
-
|
|
353
|
+
/** Destroy this object, destroy its children, detach its parent, and mark it for removal
|
|
354
|
+
* @param {boolean} [immediate] - should attached effects be allowed to die off? */
|
|
355
|
+
destroy(immediate=false)
|
|
355
356
|
{
|
|
356
|
-
if (this.destroyed)
|
|
357
|
-
return;
|
|
357
|
+
if (this.destroyed) return;
|
|
358
358
|
|
|
359
359
|
// disconnect from parent and destroy children
|
|
360
|
-
this.destroyed =
|
|
360
|
+
this.destroyed = true;
|
|
361
361
|
this.parent?.removeChild(this);
|
|
362
362
|
for (const child of this.children)
|
|
363
363
|
{
|
|
364
364
|
child.parent = undefined;
|
|
365
|
-
child.destroy();
|
|
365
|
+
child.destroy(immediate);
|
|
366
366
|
}
|
|
367
367
|
}
|
|
368
368
|
|
|
@@ -461,7 +461,7 @@ class EngineObject
|
|
|
461
461
|
}
|
|
462
462
|
|
|
463
463
|
/** Check if overlapping another engine object
|
|
464
|
-
* Collisions are
|
|
464
|
+
* Collisions are resolved to prevent overlaps
|
|
465
465
|
* @param {EngineObject} object
|
|
466
466
|
* @return {boolean} */
|
|
467
467
|
isOverlappingObject(object)
|