littlejsengine 1.14.23 → 1.14.28
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/dist/littlejs.d.ts +99 -20
- package/dist/littlejs.esm.js +378 -130
- package/dist/littlejs.esm.min.js +1 -1
- package/dist/littlejs.js +373 -130
- package/dist/littlejs.min.js +1 -1
- package/dist/littlejs.release.js +336 -130
- package/examples/box2d/gameObjects.js +6 -10
- package/examples/box2d/scenes.js +2 -2
- package/examples/breakout/gameObjects.js +1 -1
- package/examples/electron/index.html +2 -2
- package/examples/index.html +10 -7
- package/examples/platformer/gameCharacter.js +3 -2
- package/examples/platformer/gameObjects.js +3 -8
- package/examples/shorts/base.html +1 -1
- package/examples/shorts/box2d.js +2 -2
- package/examples/shorts/box2dCar.js +18 -7
- package/examples/shorts/box2dPool.js +108 -0
- package/examples/shorts/debugDraw.js +2 -3
- package/examples/shorts/flappyGame.js +1 -0
- package/examples/shorts/fps.js +1 -1
- package/examples/shorts/hillGlideGame.js +0 -2
- package/examples/shorts/input.js +59 -0
- package/examples/shorts/landerGame.js +1 -3
- package/examples/shorts/medals.js +15 -9
- package/examples/shorts/music.js +15 -17
- package/examples/shorts/musicPlayer.js +24 -24
- package/examples/shorts/platformer.js +0 -2
- package/examples/shorts/slidingPuzzle.js +1 -1
- package/examples/shorts/spaceGame.js +0 -2
- package/examples/shorts/spriteAtlas.js +0 -2
- package/examples/shorts/tiltedView.js +0 -3
- package/examples/shorts/timers.js +1 -2
- package/examples/shorts/topDown.js +0 -2
- package/examples/starter/index.html +2 -2
- package/package.json +1 -1
- package/plugins/box2d.js +170 -50
- package/plugins/pluginExport.js +2 -0
- package/plugins/uiSystem.js +55 -27
- package/src/engine.js +17 -14
- package/src/engineAudio.js +14 -2
- package/src/engineDebug.js +37 -0
- package/src/engineDraw.js +20 -12
- package/src/engineExport.js +3 -0
- package/src/engineInput.js +24 -12
- package/src/engineMedals.js +2 -2
- package/src/engineObject.js +24 -4
- package/src/engineParticles.js +1 -6
- package/src/engineTileLayer.js +2 -0
- package/src/engineUtilities.js +7 -1
package/src/engineObject.js
CHANGED
|
@@ -135,11 +135,10 @@ class EngineObject
|
|
|
135
135
|
}
|
|
136
136
|
|
|
137
137
|
/** Update the object physics, called automatically by engine once each frame */
|
|
138
|
-
|
|
138
|
+
updatePhysics()
|
|
139
139
|
{
|
|
140
140
|
// child objects do not have physics
|
|
141
|
-
|
|
142
|
-
return;
|
|
141
|
+
ASSERT(!this.parent);
|
|
143
142
|
|
|
144
143
|
if (this.clampSpeed)
|
|
145
144
|
{
|
|
@@ -189,7 +188,7 @@ class EngineObject
|
|
|
189
188
|
continue;
|
|
190
189
|
|
|
191
190
|
// check collision
|
|
192
|
-
if (!
|
|
191
|
+
if (!this.isOverlappingObject(o))
|
|
193
192
|
continue;
|
|
194
193
|
|
|
195
194
|
// notify objects of collision and check if should be resolved
|
|
@@ -337,6 +336,9 @@ class EngineObject
|
|
|
337
336
|
}
|
|
338
337
|
}
|
|
339
338
|
|
|
339
|
+
/** Update the object, called automatically by engine once each frame. Does nothing by default. */
|
|
340
|
+
update() {}
|
|
341
|
+
|
|
340
342
|
/** Render the object, draws a tile by default, automatically called each frame, sorted by renderOrder */
|
|
341
343
|
render()
|
|
342
344
|
{
|
|
@@ -402,6 +404,10 @@ class EngineObject
|
|
|
402
404
|
* @return {number} */
|
|
403
405
|
getAliveTime() { return time - this.spawnTime; }
|
|
404
406
|
|
|
407
|
+
/** Get the speed of this object
|
|
408
|
+
* @return {number} */
|
|
409
|
+
getSpeed() { return this.velocity.length(); }
|
|
410
|
+
|
|
405
411
|
/** Apply acceleration to this object (adjust velocity, not affected by mass)
|
|
406
412
|
* @param {Vector2} acceleration */
|
|
407
413
|
applyAcceleration(acceleration)
|
|
@@ -446,6 +452,20 @@ class EngineObject
|
|
|
446
452
|
child.parent = 0;
|
|
447
453
|
}
|
|
448
454
|
|
|
455
|
+
/** Check if overlapping another engine object
|
|
456
|
+
* Collisions are resoloved to prevent overlaps
|
|
457
|
+
* @param {EngineObject} object
|
|
458
|
+
* @return {boolean} */
|
|
459
|
+
isOverlappingObject(object)
|
|
460
|
+
{ return this.isOverlapping(object.pos, object.size); }
|
|
461
|
+
|
|
462
|
+
/** Check if overlapping a point or aligned bounding box
|
|
463
|
+
* @param {Vector2} pos - Center of box
|
|
464
|
+
* @param {Vector2} [size=(0,0)] - Size of box, uses a point if undefined
|
|
465
|
+
* @return {boolean} */
|
|
466
|
+
isOverlapping(pos, size=vec2())
|
|
467
|
+
{ return isOverlapping(this.pos, this.size, pos, size); }
|
|
468
|
+
|
|
449
469
|
/** Set how this object collides
|
|
450
470
|
* @param {boolean} [collideSolidObjects] - Does it collide with solid objects?
|
|
451
471
|
* @param {boolean} [isSolid] - Does it collide with and block other objects? (expensive in large numbers)
|
package/src/engineParticles.js
CHANGED
|
@@ -163,9 +163,6 @@ class ParticleEmitter extends EngineObject
|
|
|
163
163
|
/** Update the emitter to spawn particles, called automatically by engine once each frame */
|
|
164
164
|
update()
|
|
165
165
|
{
|
|
166
|
-
// only do default update to apply parent transforms
|
|
167
|
-
this.parent && super.update();
|
|
168
|
-
|
|
169
166
|
if (this.velocityInheritance)
|
|
170
167
|
{
|
|
171
168
|
// pass emitter velocity to particles
|
|
@@ -182,7 +179,7 @@ class ParticleEmitter extends EngineObject
|
|
|
182
179
|
if (!this.emitTime || this.getAliveTime() <= this.emitTime)
|
|
183
180
|
{
|
|
184
181
|
// emit particles
|
|
185
|
-
if (this.emitRate
|
|
182
|
+
if (this.emitRate && particleEmitRateScale)
|
|
186
183
|
{
|
|
187
184
|
const rate = 1/this.emitRate/particleEmitRateScale;
|
|
188
185
|
for (this.emitTimeBuffer += timeDelta; this.emitTimeBuffer > 0; this.emitTimeBuffer -= rate)
|
|
@@ -320,8 +317,6 @@ class Particle extends EngineObject
|
|
|
320
317
|
/** Update the object physics, called automatically by engine once each frame */
|
|
321
318
|
update()
|
|
322
319
|
{
|
|
323
|
-
super.update();
|
|
324
|
-
|
|
325
320
|
if (this.collideTiles || this.collideSolidObjects)
|
|
326
321
|
{
|
|
327
322
|
// only apply max circular speed if particle can collide
|
package/src/engineTileLayer.js
CHANGED
|
@@ -48,6 +48,7 @@ function tileCollisionTest(pos, size=vec2(), object, solidOnly=true)
|
|
|
48
48
|
}
|
|
49
49
|
|
|
50
50
|
/** Return the exact position of the boudnary of first tile hit, undefined if nothing was hit.
|
|
51
|
+
* The point will be inside the colliding tile if it hits (may have a tiny shift)
|
|
51
52
|
* @param {Vector2} posStart
|
|
52
53
|
* @param {Vector2} posEnd
|
|
53
54
|
* @param {EngineObject} [object] - An object or undefined for generic test
|
|
@@ -621,6 +622,7 @@ class TileCollisionLayer extends TileLayer
|
|
|
621
622
|
}
|
|
622
623
|
|
|
623
624
|
/** Return the exact position of the boudnary of first tile hit, undefined if nothing was hit.
|
|
625
|
+
* The point will be inside the colliding tile if it hits (may have a tiny shift)
|
|
624
626
|
* @param {Vector2} posStart
|
|
625
627
|
* @param {Vector2} posEnd
|
|
626
628
|
* @param {EngineObject} [object] - An object or undefined for generic test
|
package/src/engineUtilities.js
CHANGED
|
@@ -305,6 +305,13 @@ function isNumber(n) { return typeof n === 'number' && !isNaN(n); }
|
|
|
305
305
|
* @memberof Utilities */
|
|
306
306
|
function isString(s) { return s !== undefined && s !== null && typeof s.toString() === 'string'; }
|
|
307
307
|
|
|
308
|
+
/**
|
|
309
|
+
* Check if object is an array
|
|
310
|
+
* @param {any} a
|
|
311
|
+
* @return {boolean}
|
|
312
|
+
* @memberof Utilities */
|
|
313
|
+
function isArray(a) { return Array.isArray(a); }
|
|
314
|
+
|
|
308
315
|
/**
|
|
309
316
|
* @callback LineTestFunction - Checks if a position is colliding
|
|
310
317
|
* @param {Vector2} pos
|
|
@@ -1004,7 +1011,6 @@ class Color
|
|
|
1004
1011
|
* @return {string} */
|
|
1005
1012
|
toString(useAlpha = true)
|
|
1006
1013
|
{
|
|
1007
|
-
ASSERT(typeof useAlpha === 'boolean', 'Use alpha boolean is invalid.', useAlpha);
|
|
1008
1014
|
if (debug && !this.isValid())
|
|
1009
1015
|
return `#000`;
|
|
1010
1016
|
const toHex = (c)=> ((c=clamp(c)*255|0)<16 ? '0' : '') + c.toString(16);
|