littlejsengine 1.16.1 → 1.17.1
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 +287 -240
- package/dist/littlejs.esm.js +1419 -1259
- package/dist/littlejs.esm.min.js +1 -1
- package/dist/littlejs.js +1076 -910
- package/dist/littlejs.min.js +1 -1
- package/dist/littlejs.release.js +977 -815
- package/examples/box2d/gameObjects.js +6 -6
- package/examples/breakout/game.js +5 -6
- package/examples/electron/index.html +2 -2
- package/examples/electron/tiles.png +0 -0
- package/examples/htmlMenu/tiles.png +0 -0
- package/examples/index.html +1 -1
- package/examples/logo.png +0 -0
- package/examples/logo2.png +0 -0
- package/examples/module/tiles.png +0 -0
- package/examples/platformer/gameEffects.js +24 -23
- package/examples/platformer/gameLevel.js +24 -25
- package/examples/shorts/base.html +2 -1
- package/examples/shorts/clock.js +3 -3
- package/examples/shorts/fontImage.js +4 -3
- package/examples/shorts/parallax.js +1 -1
- package/examples/shorts/sequencer.js +1 -1
- package/examples/shorts/shapes.js +1 -1
- package/examples/shorts/texture.js +10 -6
- package/examples/shorts/tiles.png +0 -0
- package/examples/shorts/tiltedView.js +2 -0
- package/examples/starter/index.html +3 -2
- package/examples/starter/tiles.png +0 -0
- package/examples/typescript/tiles.png +0 -0
- package/examples/uiSystem/game.js +1 -1
- package/examples/uiSystem/tiles.png +0 -0
- package/package.json +1 -1
- package/plugins/postProcess.js +47 -28
- package/plugins/uiSystem.js +16 -16
- package/reference.md +6 -6
- package/src/engine.js +186 -198
- package/src/engineAudio.js +6 -10
- package/src/engineBuild.js +1 -0
- package/src/engineDebug.js +100 -98
- package/src/engineDraw.js +185 -148
- package/src/engineExport.js +327 -333
- package/src/engineFont.png +0 -0
- package/src/engineInput.js +17 -26
- package/src/engineMath.js +1112 -0
- package/src/engineMedals.js +4 -4
- package/src/engineObject.js +27 -27
- package/src/engineParticles.js +2 -2
- package/src/engineRelease.js +1 -3
- package/src/engineSettings.js +2 -2
- package/src/engineTileLayer.js +200 -176
- package/src/engineUtilities.js +48 -1097
- package/src/engineWebGL.js +127 -79
package/src/engineMedals.js
CHANGED
|
@@ -32,10 +32,11 @@ function medalsInit(saveName)
|
|
|
32
32
|
|
|
33
33
|
// engine automatically renders medals
|
|
34
34
|
engineAddPlugin(undefined, medalsRender);
|
|
35
|
+
|
|
36
|
+
// plugin functions
|
|
35
37
|
function medalsRender()
|
|
36
38
|
{
|
|
37
|
-
if (!medalsDisplayQueue.length)
|
|
38
|
-
return;
|
|
39
|
+
if (!medalsDisplayQueue.length) return;
|
|
39
40
|
|
|
40
41
|
// update first medal in queue
|
|
41
42
|
const medal = medalsDisplayQueue[0];
|
|
@@ -125,8 +126,7 @@ class Medal
|
|
|
125
126
|
/** Unlocks a medal if not already unlocked */
|
|
126
127
|
unlock()
|
|
127
128
|
{
|
|
128
|
-
if (medalsPreventUnlock || this.unlocked)
|
|
129
|
-
return;
|
|
129
|
+
if (medalsPreventUnlock || this.unlocked) return;
|
|
130
130
|
|
|
131
131
|
// save the medal
|
|
132
132
|
ASSERT(medalsSaveName, 'save name must be set');
|
package/src/engineObject.js
CHANGED
|
@@ -33,10 +33,10 @@
|
|
|
33
33
|
class EngineObject
|
|
34
34
|
{
|
|
35
35
|
/** Create an engine object and adds it to the list of objects
|
|
36
|
-
* @param {Vector2} [pos=(
|
|
37
|
-
* @param {Vector2} [size=(1
|
|
38
|
-
* @param {TileInfo} [tileInfo]
|
|
39
|
-
* @param {number} [angle]
|
|
36
|
+
* @param {Vector2} [pos=vec2()] - World space position of the object
|
|
37
|
+
* @param {Vector2} [size=vec2(1)] - World space size of the object
|
|
38
|
+
* @param {TileInfo} [tileInfo] - Tile info to render object (undefined is untextured)
|
|
39
|
+
* @param {number} [angle] - Angle the object is rotated by
|
|
40
40
|
* @param {Color} [color=WHITE] - Color to apply to tile when rendered
|
|
41
41
|
* @param {number} [renderOrder] - Objects sorted by renderOrder before being rendered
|
|
42
42
|
*/
|
|
@@ -164,15 +164,16 @@ class EngineObject
|
|
|
164
164
|
// physics sanity checks
|
|
165
165
|
ASSERT(this.angleDamping >= 0 && this.angleDamping <= 1);
|
|
166
166
|
ASSERT(this.damping >= 0 && this.damping <= 1);
|
|
167
|
-
|
|
168
|
-
|
|
167
|
+
|
|
168
|
+
// don't do collision for static objects or if solver disabled
|
|
169
|
+
if (!enablePhysicsSolver || !this.mass) return;
|
|
169
170
|
|
|
170
171
|
const wasFalling = this.velocity.y < 0 && gravity.y < 0 || this.velocity.y > 0 && gravity.y > 0;
|
|
171
172
|
if (this.groundObject)
|
|
172
173
|
{
|
|
173
174
|
// apply friction in local space of ground object
|
|
174
175
|
const friction = max(this.friction, this.groundObject.friction);
|
|
175
|
-
const groundSpeed = this.groundObject.velocity
|
|
176
|
+
const groundSpeed = this.groundObject.velocity.x;
|
|
176
177
|
this.velocity.x = groundSpeed + (this.velocity.x - groundSpeed) * friction;
|
|
177
178
|
this.groundObject = undefined;
|
|
178
179
|
}
|
|
@@ -183,19 +184,19 @@ class EngineObject
|
|
|
183
184
|
const epsilon = .001; // necessary to push slightly outside of the collision
|
|
184
185
|
for (const o of engineObjectsCollide)
|
|
185
186
|
{
|
|
187
|
+
// skip destroyed, child objects, or self collision
|
|
188
|
+
if (o.destroyed || o.parent || o === this) continue;
|
|
189
|
+
|
|
186
190
|
// non solid objects don't collide with each other
|
|
187
|
-
if (
|
|
188
|
-
continue;
|
|
191
|
+
if (!this.isSolid && !o.isSolid) continue;
|
|
189
192
|
|
|
190
193
|
// check collision
|
|
191
|
-
if (!this.isOverlappingObject(o))
|
|
192
|
-
continue;
|
|
194
|
+
if (!this.isOverlappingObject(o)) continue;
|
|
193
195
|
|
|
194
196
|
// notify objects of collision and check if should be resolved
|
|
195
197
|
const collide1 = this.collideWithObject(o);
|
|
196
198
|
const collide2 = o.collideWithObject(this);
|
|
197
|
-
if (!collide1 || !collide2)
|
|
198
|
-
continue;
|
|
199
|
+
if (!collide1 || !collide2) continue;
|
|
199
200
|
|
|
200
201
|
if (isOverlapping(oldPos, this.size, o.pos, o.size))
|
|
201
202
|
{
|
|
@@ -297,7 +298,7 @@ class EngineObject
|
|
|
297
298
|
const delta = y - this.pos.y;
|
|
298
299
|
if (delta < maxMoveUp)
|
|
299
300
|
if (!tileCollisionTest(vec2(this.pos.x, y), this.size, this))
|
|
300
|
-
{
|
|
301
|
+
{
|
|
301
302
|
this.pos.y = y;
|
|
302
303
|
debugPhysics && debugRect(this.pos, this.size, '#ff0');
|
|
303
304
|
return;
|
|
@@ -357,10 +358,10 @@ class EngineObject
|
|
|
357
358
|
|
|
358
359
|
// disconnect from parent and destroy children
|
|
359
360
|
this.destroyed = 1;
|
|
360
|
-
this.parent
|
|
361
|
+
this.parent?.removeChild(this);
|
|
361
362
|
for (const child of this.children)
|
|
362
363
|
{
|
|
363
|
-
child.parent =
|
|
364
|
+
child.parent = undefined;
|
|
364
365
|
child.destroy();
|
|
365
366
|
}
|
|
366
367
|
}
|
|
@@ -381,15 +382,15 @@ class EngineObject
|
|
|
381
382
|
* @param {Vector2} vec - world space vector */
|
|
382
383
|
worldToLocalVector(vec) { return vec.rotate(-this.angle); }
|
|
383
384
|
|
|
384
|
-
/** Called to check if a tile collision should be resolved
|
|
385
|
+
/** Called to check if a tile collision should be resolved. Return true for physics to resolve the collision or false to ignore and resolve it manually.
|
|
385
386
|
* @param {number} tileData - the value of the tile at the position
|
|
386
|
-
* @param {Vector2} pos
|
|
387
|
-
* @return {boolean}
|
|
387
|
+
* @param {Vector2} pos - tile where the collision occurred
|
|
388
|
+
* @return {boolean} - true if the collision should be resolved by modifying it's position and velocity */
|
|
388
389
|
collideWithTile(tileData, pos) { return tileData > 0; }
|
|
389
390
|
|
|
390
|
-
/** Called to check if
|
|
391
|
+
/** Called by the engine to check if an object collision should be resolved. Return true for physics to resolve the collision or false to ignore and resolve it manually.
|
|
391
392
|
* @param {EngineObject} object - the object to test against
|
|
392
|
-
* @return {boolean}
|
|
393
|
+
* @return {boolean} - true if the collision should be resolved by modifying it's position and velocity
|
|
393
394
|
*/
|
|
394
395
|
collideWithObject(object) { return true; }
|
|
395
396
|
|
|
@@ -430,9 +431,9 @@ class EngineObject
|
|
|
430
431
|
* @return {number} -1 if this.mirror is true, or 1 if not mirrored */
|
|
431
432
|
getMirrorSign() { return this.mirror ? -1 : 1; }
|
|
432
433
|
|
|
433
|
-
/** Attaches a child to this with a local transform, returns child for chaining
|
|
434
|
+
/** Attaches a child to this with a local transform, returns child for chaining
|
|
434
435
|
* @param {EngineObject} child
|
|
435
|
-
* @param {Vector2} [localPos=(
|
|
436
|
+
* @param {Vector2} [localPos=vec2()]
|
|
436
437
|
* @param {number} [localAngle]
|
|
437
438
|
* @return {EngineObject} The child object added */
|
|
438
439
|
addChild(child, localPos=vec2(), localAngle=0)
|
|
@@ -456,7 +457,7 @@ class EngineObject
|
|
|
456
457
|
const index = this.children.indexOf(child);
|
|
457
458
|
ASSERT(index >= 0, 'child not found in children array');
|
|
458
459
|
index >= 0 && this.children.splice(index, 1);
|
|
459
|
-
child.parent =
|
|
460
|
+
child.parent = undefined;
|
|
460
461
|
}
|
|
461
462
|
|
|
462
463
|
/** Check if overlapping another engine object
|
|
@@ -468,7 +469,7 @@ class EngineObject
|
|
|
468
469
|
|
|
469
470
|
/** Check if overlapping a point or aligned bounding box
|
|
470
471
|
* @param {Vector2} pos - Center of box
|
|
471
|
-
* @param {Vector2} [size=(
|
|
472
|
+
* @param {Vector2} [size=vec2()] - Size of box, uses a point if undefined
|
|
472
473
|
* @return {boolean} */
|
|
473
474
|
isOverlapping(pos, size=vec2())
|
|
474
475
|
{ return isOverlapping(this.pos, this.size, pos, size); }
|
|
@@ -511,8 +512,7 @@ class EngineObject
|
|
|
511
512
|
/** Render debug info for this object */
|
|
512
513
|
renderDebugInfo()
|
|
513
514
|
{
|
|
514
|
-
if (!debug)
|
|
515
|
-
return;
|
|
515
|
+
if (!debug) return;
|
|
516
516
|
|
|
517
517
|
// show object info for debugging
|
|
518
518
|
const size = vec2(max(this.size.x, .2), max(this.size.y, .2));
|
package/src/engineParticles.js
CHANGED
|
@@ -255,7 +255,7 @@ class ParticleEmitter extends EngineObject
|
|
|
255
255
|
particle.mirror = randBool();
|
|
256
256
|
|
|
257
257
|
// call particle create callback
|
|
258
|
-
this.particleCreateCallback
|
|
258
|
+
this.particleCreateCallback?.(particle);
|
|
259
259
|
|
|
260
260
|
// return the newly created particle
|
|
261
261
|
return particle;
|
|
@@ -340,7 +340,7 @@ class Particle extends EngineObject
|
|
|
340
340
|
const c = this.colorEnd;
|
|
341
341
|
this.color.set(c.r, c.g, c.b, c.a);
|
|
342
342
|
this.size.set(this.sizeEnd, this.sizeEnd);
|
|
343
|
-
this.destroyCallback
|
|
343
|
+
this.destroyCallback?.(this);
|
|
344
344
|
this.destroyed = 1;
|
|
345
345
|
}
|
|
346
346
|
}
|
package/src/engineRelease.js
CHANGED
|
@@ -22,6 +22,7 @@ function LOG (){}
|
|
|
22
22
|
function debugInit (){}
|
|
23
23
|
function debugUpdate (){}
|
|
24
24
|
function debugRender (){}
|
|
25
|
+
function debugRenderPost (){}
|
|
25
26
|
function debugRect (){}
|
|
26
27
|
function debugPoly (){}
|
|
27
28
|
function debugCircle (){}
|
|
@@ -31,9 +32,6 @@ function debugOverlap (){}
|
|
|
31
32
|
function debugText (){}
|
|
32
33
|
function debugClear (){}
|
|
33
34
|
function debugScreenshot (){}
|
|
34
|
-
function debugSaveCanvas (){}
|
|
35
|
-
function debugSaveText (){}
|
|
36
|
-
function debugSaveDataURL(){}
|
|
37
35
|
function debugShowErrors(){}
|
|
38
36
|
function debugVideoCaptureIsActive(){ return false; }
|
|
39
37
|
function debugVideoCaptureStart (){}
|
package/src/engineSettings.js
CHANGED
|
@@ -37,7 +37,7 @@ let cameraScale = 32;
|
|
|
37
37
|
* @memberof Settings */
|
|
38
38
|
let canvasColorTiles = true;
|
|
39
39
|
|
|
40
|
-
/** Color to clear the canvas to before render
|
|
40
|
+
/** Color to clear the canvas to before render, does not clear if alpha is 0
|
|
41
41
|
* @type {Color}
|
|
42
42
|
* @memberof Draw */
|
|
43
43
|
let canvasClearColor = CLEAR_BLACK;
|
|
@@ -346,7 +346,7 @@ function setCameraScale(scale) { cameraScale = scale; }
|
|
|
346
346
|
* @memberof Settings */
|
|
347
347
|
function setCanvasColorTiles(colorTiles) { canvasColorTiles = colorTiles; }
|
|
348
348
|
|
|
349
|
-
/** Set color to clear the canvas to before render
|
|
349
|
+
/** Set color to clear the canvas to before render, does not clear if alpha is 0
|
|
350
350
|
* @param {Color} color
|
|
351
351
|
* @memberof Settings */
|
|
352
352
|
function setCanvasClearColor(color) { canvasClearColor = color.copy(); }
|