littlejsengine 1.17.5 → 1.17.11
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 +189 -97
- package/dist/littlejs.esm.js +637 -477
- package/dist/littlejs.esm.min.js +1 -1
- package/dist/littlejs.js +633 -476
- package/dist/littlejs.min.js +1 -1
- package/dist/littlejs.release.js +631 -474
- package/examples/electron/index.html +2 -2
- package/examples/games.jpg +0 -0
- package/examples/index.html +2 -2
- package/examples/logo.png +0 -0
- package/examples/logo2.png +0 -0
- package/examples/particles/index.html +1 -1
- package/examples/platformer/gameEffects.js +3 -3
- package/examples/screenshot.jpg +0 -0
- package/examples/shorts/base.html +1 -1
- package/examples/shorts/colors.js +1 -1
- package/examples/shorts/fontImage.js +1 -1
- package/examples/shorts/fps.js +1 -1
- package/examples/shorts/music.js +3 -2
- package/examples/shorts/musicPlayer.js +2 -1
- package/examples/shorts/parallax.js +2 -2
- package/examples/shorts/tiltedView.js +1 -1
- package/examples/starter/index.html +2 -2
- package/package.json +1 -1
- package/plugins/box2d.js +6 -7
- package/plugins/pluginExport.js +2 -1
- package/plugins/postProcess.js +1 -1
- package/plugins/uiSystem.js +33 -21
- package/reference.md +6 -6
- package/src/engine.js +106 -152
- package/src/engineAudio.js +5 -5
- package/src/engineDebug.js +1 -1
- package/src/engineDraw.js +36 -14
- package/src/engineExport.js +2 -0
- package/src/engineInput.js +1 -1
- package/src/engineMath.js +6 -4
- package/src/engineObject.js +24 -24
- package/src/engineParticles.js +241 -118
- package/src/engineTileLayer.js +66 -48
- package/src/engineUtilities.js +105 -78
- package/plugins/Box2D_License.txt +0 -17
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
</head><body>
|
|
8
8
|
|
|
9
9
|
<!-- LittleJS Engine -->
|
|
10
|
-
<script src=../../dist/littlejs.js?1.17.
|
|
10
|
+
<script src=../../dist/littlejs.js?1.17.11></script>
|
|
11
11
|
|
|
12
12
|
<!-- Add your game scripts here -->
|
|
13
|
-
<script src=game.js?1.17.
|
|
13
|
+
<script src=game.js?1.17.11></script>
|
|
Binary file
|
package/examples/index.html
CHANGED
|
@@ -103,7 +103,7 @@ const exampleList =
|
|
|
103
103
|
new ExampleInfo('Font Image', 'fontImage.js', 'Bitmap font system with built-in system font', false, 'text, characters'),
|
|
104
104
|
new ExampleInfo('Medals', 'medals.js', 'Achievement system', false, 'unlock, progress, newgrounds'),
|
|
105
105
|
new ExampleInfo('Tile Raycast', 'tileRaycast.js', 'Example of the tile layer raycast collision', false, 'level, map, grid'),
|
|
106
|
-
new ExampleInfo('Camera Mouse Drag', 'cameraDrag.js', 'Example of how to control camera with
|
|
106
|
+
new ExampleInfo('Camera Mouse Drag', 'cameraDrag.js', 'Example of how to control camera with mouse', false, 'ui, input, control'),
|
|
107
107
|
new ExampleInfo('Debug Drawing', 'debugDraw.js', 'Debug drawing system', false, 'debug, circle, line, rectangle'),
|
|
108
108
|
new ExampleInfo('--- ADVANCED ---'),
|
|
109
109
|
new ExampleInfo('Clock', 'clock.js', 'Animated analog clock', false, 'time, rotation, lines, rectangle'),
|
|
@@ -113,7 +113,7 @@ const exampleList =
|
|
|
113
113
|
new ExampleInfo('Piano', 'piano.js', 'Interactive piano keyboard', false, 'music, sound, audio, notes, ui, instrument'),
|
|
114
114
|
new ExampleInfo('Step Sequencer', 'sequencer.js', 'Simple music loop creation tool', false, 'music, sound, audio, notes, ui, instrument'),
|
|
115
115
|
new ExampleInfo('Music Player', 'musicPlayer.js', 'Music player with audio seeking and drag and drop', false, 'sound, loading, audio, ui'),
|
|
116
|
-
new ExampleInfo('---
|
|
116
|
+
new ExampleInfo('--- GAMES ---'),
|
|
117
117
|
new ExampleInfo('Pong Game', 'pongGame.js', 'Classic paddle ball bouncing', false, 'objects, collision'),
|
|
118
118
|
new ExampleInfo('Platformer Game', 'platformer.js', 'Jump and run side view', false, 'objects, gravity, level, tiles, camera'),
|
|
119
119
|
new ExampleInfo('Top Down Game', 'topDown.js', 'Top-down style camera', false, 'objects, movement, exploration'),
|
package/examples/logo.png
CHANGED
|
Binary file
|
package/examples/logo2.png
CHANGED
|
Binary file
|
|
@@ -72,7 +72,7 @@ addSetting('gravityScale', '', -1e9, 1e9, .1, 'How much does gravity effect
|
|
|
72
72
|
addSetting('particleConeAngle','', 0, 1e9, .1, 'Cone for start particle angle');
|
|
73
73
|
addSetting('fadeRate', '', 0, 1, .01,'How quickly particles fade in percent of life');
|
|
74
74
|
addSetting('randomness', '', 0, 1, .01,'Apply extra randomness percent');
|
|
75
|
-
addSetting('additive', 'checkbox',0,0,0, 'Should particles use
|
|
75
|
+
addSetting('additive', 'checkbox',0,0,0, 'Should particles use additive blend?');
|
|
76
76
|
addSetting('randomColorLinear','checkbox',0,0,0, 'Should color be randomized linearly?');
|
|
77
77
|
|
|
78
78
|
function makeEmitter()
|
|
@@ -46,7 +46,7 @@ export function makeDebris(pos, color = hsl(), amount = 50, size=.2, restitution
|
|
|
46
46
|
{
|
|
47
47
|
const color2 = color.lerp(hsl(), .5);
|
|
48
48
|
const emitter = new LJS.ParticleEmitter(
|
|
49
|
-
pos, 0,
|
|
49
|
+
pos, 0, .5, .1, amount/.1, 3.14, // pos, angle, size, time, rate, cone
|
|
50
50
|
0, // tileInfo
|
|
51
51
|
color, color2, // colorStartA, colorStartB
|
|
52
52
|
color, color2, // colorEndA, colorEndB
|
|
@@ -269,9 +269,9 @@ export class ParallaxLayer extends LJS.CanvasLayer
|
|
|
269
269
|
const cameraDeltaFromCenter = LJS.cameraPos.subtract(levelCenter)
|
|
270
270
|
.divide(levelCenter.scale(-1).divide(parallax));
|
|
271
271
|
const scale = distance/LJS.cameraScale;
|
|
272
|
-
const
|
|
272
|
+
const positionOffset = vec2(0, 2-depth);
|
|
273
273
|
const cameraOffset = cameraDeltaFromCenter.scale(1/LJS.cameraScale);
|
|
274
|
-
this.pos = LJS.cameraPos.add(
|
|
274
|
+
this.pos = LJS.cameraPos.add(positionOffset).add(cameraOffset);
|
|
275
275
|
this.size = canvasSize.scale(scale);
|
|
276
276
|
super.render();
|
|
277
277
|
}
|
package/examples/screenshot.jpg
CHANGED
|
Binary file
|
package/examples/shorts/fps.js
CHANGED
|
@@ -33,7 +33,7 @@ function gameUpdate()
|
|
|
33
33
|
function gameRender()
|
|
34
34
|
{
|
|
35
35
|
{
|
|
36
|
-
// draw horizontal
|
|
36
|
+
// draw horizontal slices to create floor and ceiling
|
|
37
37
|
const h = 9;
|
|
38
38
|
let pos = vec2(), size = vec2(39, .15), color = rgb();
|
|
39
39
|
for (let y=-h; y<h; y+=.1)
|
package/examples/shorts/music.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
const musicSound = new Sound('song.mp3');
|
|
2
|
-
let musicVolume =
|
|
2
|
+
let musicVolume = .8, musicInstance;
|
|
3
3
|
|
|
4
4
|
function gameInit()
|
|
5
5
|
{
|
|
@@ -15,13 +15,14 @@ function gameInit()
|
|
|
15
15
|
const center = mainCanvasSize.scale(.5);
|
|
16
16
|
musicPlayer = new UIObject(center, vec2(500, 220));
|
|
17
17
|
|
|
18
|
-
//
|
|
18
|
+
// information text
|
|
19
19
|
infoText = new UIText(vec2(0, -70), vec2(400, 50));
|
|
20
20
|
musicPlayer.addChild(infoText);
|
|
21
21
|
|
|
22
22
|
// volume slider
|
|
23
23
|
const volumeSlider = new UIScrollbar(vec2(0, -20), vec2(400, 30),
|
|
24
24
|
musicVolume, 'Music Volume');
|
|
25
|
+
volumeSlider.fillMode = true;
|
|
25
26
|
musicPlayer.addChild(volumeSlider);
|
|
26
27
|
volumeSlider.onChange = ()=>
|
|
27
28
|
{
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
|
|
2
|
-
let musicVolume =
|
|
2
|
+
let musicVolume = .8, musicSound, musicInstance;
|
|
3
3
|
|
|
4
4
|
function gameInit()
|
|
5
5
|
{
|
|
@@ -28,6 +28,7 @@ function gameInit()
|
|
|
28
28
|
// volume slider
|
|
29
29
|
const volumeSlider = new UIScrollbar(vec2(0, -20), vec2(400, 30),
|
|
30
30
|
musicVolume, 'Music Volume');
|
|
31
|
+
volumeSlider.fillMode = true;
|
|
31
32
|
musicPlayer.addChild(volumeSlider);
|
|
32
33
|
volumeSlider.onChange = ()=>
|
|
33
34
|
{
|
|
@@ -64,8 +64,8 @@ class ParallaxLayer extends CanvasLayer
|
|
|
64
64
|
const distance = 3 + depth;
|
|
65
65
|
const parallax = vec2(.2, .05).scale(depth**2+1);
|
|
66
66
|
const cameraDeltaFromCenter = viewerPos.multiply(parallax);
|
|
67
|
-
const
|
|
68
|
-
this.pos = cameraDeltaFromCenter.add(
|
|
67
|
+
const positionOffset = vec2(0, 4-depth*3);
|
|
68
|
+
this.pos = cameraDeltaFromCenter.add(positionOffset)
|
|
69
69
|
this.size = canvasSize.scale(distance/cameraScale);
|
|
70
70
|
super.render();
|
|
71
71
|
}
|
|
@@ -7,7 +7,7 @@ class GameObject extends EngineObject
|
|
|
7
7
|
|
|
8
8
|
render()
|
|
9
9
|
{
|
|
10
|
-
// adjust draw
|
|
10
|
+
// adjust draw position to be at the bottom of the object
|
|
11
11
|
const drawSize = this.drawSize || this.size;
|
|
12
12
|
const offset = this.getUp(drawSize.y/2);
|
|
13
13
|
const pos = this.pos.add(offset);
|
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
</head><body>
|
|
8
8
|
|
|
9
9
|
<!-- LittleJS Engine -->
|
|
10
|
-
<script src=../../dist/littlejs.js?1.17.
|
|
10
|
+
<script src=../../dist/littlejs.js?1.17.11></script>
|
|
11
11
|
|
|
12
12
|
<!-- LittleJS Engine Source
|
|
13
13
|
<script src=../../src/engine.js></script>
|
|
@@ -32,4 +32,4 @@
|
|
|
32
32
|
-->
|
|
33
33
|
|
|
34
34
|
<!-- Add your game scripts here -->
|
|
35
|
-
<script src=game.js?1.17.
|
|
35
|
+
<script src=game.js?1.17.11></script>
|
package/package.json
CHANGED
package/plugins/box2d.js
CHANGED
|
@@ -612,11 +612,11 @@ class Box2dStaticObject extends Box2dObject
|
|
|
612
612
|
|
|
613
613
|
///////////////////////////////////////////////////////////////////////////////
|
|
614
614
|
/**
|
|
615
|
-
* Box2D
|
|
615
|
+
* Box2D Kinematic Object - Box2d with a kinematic physics body
|
|
616
616
|
* @extends Box2dObject
|
|
617
617
|
* @memberof Box2D
|
|
618
618
|
*/
|
|
619
|
-
class
|
|
619
|
+
class Box2dKinematicObject extends Box2dObject
|
|
620
620
|
{
|
|
621
621
|
/** Create a LittleJS object with Box2d physics
|
|
622
622
|
* @param {Vector2} [pos]
|
|
@@ -668,20 +668,19 @@ class Box2dTileLayer extends Box2dStaticObject
|
|
|
668
668
|
this.destroyAllFixtures();
|
|
669
669
|
|
|
670
670
|
// create box2d object for this layer
|
|
671
|
-
const size = this.tileLayer.size;
|
|
672
671
|
this.pos = this.tileLayer.pos.copy();
|
|
673
|
-
this.size = size.copy();
|
|
672
|
+
this.size = this.tileLayer.size.copy();
|
|
674
673
|
|
|
675
674
|
// track which tiles have been processed
|
|
676
675
|
const processed = [];
|
|
677
|
-
const getIndex = (x, y)=> x + y * size.x;
|
|
676
|
+
const getIndex = (x, y)=> x + y * this.size.x;
|
|
678
677
|
const isSolidUnprocessed = (x, y)=>
|
|
679
678
|
!processed[getIndex(x, y)] &&
|
|
680
679
|
this.tileLayer.getCollisionData(vec2(x, y)) > 0;
|
|
681
680
|
|
|
682
681
|
// combine tiles into larger boxes
|
|
683
|
-
for (let x = 0; x < size.x; ++x)
|
|
684
|
-
for (let y = 0; y < size.y; ++y)
|
|
682
|
+
for (let x = 0; x < this.size.x; ++x)
|
|
683
|
+
for (let y = 0; y < this.size.y; ++y)
|
|
685
684
|
{
|
|
686
685
|
if (!isSolidUnprocessed(x, y)) continue;
|
|
687
686
|
|
package/plugins/pluginExport.js
CHANGED
package/plugins/postProcess.js
CHANGED
|
@@ -24,7 +24,7 @@ class PostProcessPlugin
|
|
|
24
24
|
{
|
|
25
25
|
/** Create global post processing shader
|
|
26
26
|
* @param {string} shaderCode
|
|
27
|
-
* @param {boolean} [includeMainCanvas] - combine
|
|
27
|
+
* @param {boolean} [includeMainCanvas] - combine mainCanvas onto glCanvas
|
|
28
28
|
* @param {boolean} [feedbackTexture] - use glCanvas from previous frame as the texture
|
|
29
29
|
* @example
|
|
30
30
|
* // create the post process plugin object
|
package/plugins/uiSystem.js
CHANGED
|
@@ -96,7 +96,7 @@ class UISystemPlugin
|
|
|
96
96
|
// navigation properties
|
|
97
97
|
/** @property {UIObject} - Object currently selected by navigation (gamepad or keyboard) */
|
|
98
98
|
this.navigationObject = undefined;
|
|
99
|
-
/** @property {Timer} -
|
|
99
|
+
/** @property {Timer} - Cool down timer for navigation inputs */
|
|
100
100
|
this.navigationTimer = new Timer(undefined, true);
|
|
101
101
|
/** @property {number} - Time between navigation inputs in seconds */
|
|
102
102
|
this.navigationDelay = .2;
|
|
@@ -562,7 +562,7 @@ class UISystemPlugin
|
|
|
562
562
|
|
|
563
563
|
const savedNavigationDirection = uiSystem.navigationDirection;
|
|
564
564
|
|
|
565
|
-
// allow both
|
|
565
|
+
// allow both axes for navigation
|
|
566
566
|
uiSystem.navigationDirection = 2;
|
|
567
567
|
|
|
568
568
|
// confirm menu
|
|
@@ -657,7 +657,7 @@ class UIObject
|
|
|
657
657
|
this.lineWidth = uiSystem.defaultLineWidth;
|
|
658
658
|
/** @property {number} - Corner radius for rounded rects */
|
|
659
659
|
this.cornerRadius = uiSystem.defaultCornerRadius;
|
|
660
|
-
/** @property {string} - Font for this
|
|
660
|
+
/** @property {string} - Font for this object */
|
|
661
661
|
this.font = uiSystem.defaultFont;
|
|
662
662
|
/** @property {string} - Font style for this object or undefined */
|
|
663
663
|
this.fontStyle = undefined;
|
|
@@ -1145,6 +1145,8 @@ class UIScrollbar extends UIObject
|
|
|
1145
1145
|
this.value = value;
|
|
1146
1146
|
/** @property {Color} - Color for the handle part of the scrollbar */
|
|
1147
1147
|
this.handleColor = handleColor.copy();
|
|
1148
|
+
/** @property {boolean} - Should it fill up like a progress bar? */
|
|
1149
|
+
this.fillMode = false;
|
|
1148
1150
|
|
|
1149
1151
|
// set properties
|
|
1150
1152
|
this.text = text;
|
|
@@ -1190,19 +1192,30 @@ class UIScrollbar extends UIObject
|
|
|
1190
1192
|
|
|
1191
1193
|
// handle horizontal or vertical scrollbar
|
|
1192
1194
|
const isHorizontal = this.size.x > this.size.y;
|
|
1193
|
-
const
|
|
1194
|
-
const
|
|
1195
|
-
|
|
1196
|
-
|
|
1197
|
-
|
|
1198
|
-
|
|
1199
|
-
|
|
1200
|
-
|
|
1201
|
-
|
|
1202
|
-
|
|
1203
|
-
|
|
1204
|
-
|
|
1205
|
-
|
|
1195
|
+
const barWidth = isHorizontal ? this.size.x : this.size.y;
|
|
1196
|
+
const handleWidth = isHorizontal ? this.size.y : this.size.x;
|
|
1197
|
+
if (this.fillMode)
|
|
1198
|
+
{
|
|
1199
|
+
// draw progress bar
|
|
1200
|
+
const minWidth = min(handleWidth, this.cornerRadius * 2);
|
|
1201
|
+
const progressWidth = lerp(minWidth, barWidth, this.value);
|
|
1202
|
+
const p = (progressWidth - barWidth) * (isHorizontal ? .5 : -.5);
|
|
1203
|
+
const pos = this.pos.add(isHorizontal ? vec2(p, 0) : vec2(0, p));
|
|
1204
|
+
const color = this.disabled ? this.disabledColor : this.handleColor;
|
|
1205
|
+
const drawSize = isHorizontal ?
|
|
1206
|
+
vec2(progressWidth, this.size.y) : vec2(this.size.x, progressWidth);
|
|
1207
|
+
uiSystem.drawRect(pos, drawSize, color, this.lineWidth, this.lineColor, this.cornerRadius, this.gradientColor);
|
|
1208
|
+
}
|
|
1209
|
+
else
|
|
1210
|
+
{
|
|
1211
|
+
// draw the scrollbar handle
|
|
1212
|
+
const value = clamp(isHorizontal ? this.value : 1 - this.value);
|
|
1213
|
+
const p = (barWidth - handleWidth) * (value - .5);
|
|
1214
|
+
const pos = this.pos.add(isHorizontal ? vec2(p, 0) : vec2(0, p));
|
|
1215
|
+
const color = this.disabled ? this.disabledColor : this.handleColor;
|
|
1216
|
+
const drawSize = vec2(handleWidth);
|
|
1217
|
+
uiSystem.drawRect(pos, drawSize, color, this.lineWidth, this.lineColor, this.cornerRadius, this.gradientColor);
|
|
1218
|
+
}
|
|
1206
1219
|
|
|
1207
1220
|
// draw the text scaled to fit on the scrollbar
|
|
1208
1221
|
const textSize = this.getTextSize();
|
|
@@ -1224,7 +1237,7 @@ class UIScrollbar extends UIObject
|
|
|
1224
1237
|
* @extends UIObject
|
|
1225
1238
|
* @example
|
|
1226
1239
|
* // Create a video player UI object
|
|
1227
|
-
* const video = new VideoPlayerUIObject(vec2(400, 300), vec2(320, 240), '
|
|
1240
|
+
* const video = new VideoPlayerUIObject(vec2(400, 300), vec2(320, 240), 'video.mp4', true);
|
|
1228
1241
|
* video.play();
|
|
1229
1242
|
* @memberof UISystem
|
|
1230
1243
|
*/
|
|
@@ -1265,12 +1278,11 @@ class UIVideo extends UIObject
|
|
|
1265
1278
|
|
|
1266
1279
|
/** Play or resume the video
|
|
1267
1280
|
* @return {Promise} Promise that resolves when playback starts */
|
|
1268
|
-
play()
|
|
1281
|
+
async play()
|
|
1269
1282
|
{
|
|
1270
1283
|
// try to play the video, catch any errors (autoplay may be blocked)
|
|
1271
|
-
|
|
1272
|
-
|
|
1273
|
-
return promise;
|
|
1284
|
+
try { await this.video.play(); }
|
|
1285
|
+
catch(e) {}
|
|
1274
1286
|
}
|
|
1275
1287
|
|
|
1276
1288
|
/** Pause the video */
|
package/reference.md
CHANGED
|
@@ -371,14 +371,14 @@ engineObjectsDestroy()
|
|
|
371
371
|
```javascript
|
|
372
372
|
|
|
373
373
|
// Canvas Layer
|
|
374
|
-
CanvasLayer(
|
|
374
|
+
CanvasLayer(pos, size) // Create a canvas layer object
|
|
375
375
|
CanvasLayer.canvas // The canvas used by this layer
|
|
376
376
|
CanvasLayer.context // The 2D context of the canvas
|
|
377
377
|
CanvasLayer.getImageData() // Get image data from canvas
|
|
378
378
|
CanvasLayer.updateWebGL() // Creates or updates WebGL texture
|
|
379
379
|
|
|
380
380
|
// LittleJS Layer System
|
|
381
|
-
TileLayer(
|
|
381
|
+
TileLayer(pos, size, tileInfo, scale) // Create a tile layer object
|
|
382
382
|
TileLayer.setData(layerPos, data, redraw) // Set data at position
|
|
383
383
|
TileLayer.clearData(layerPos, redraw) // Clear data at position
|
|
384
384
|
TileLayer.getData(layerPos) // Get data at position
|
|
@@ -393,12 +393,12 @@ TileLayerData(tile, direction=0, mirror=false, color=WHITE) // Create tile data
|
|
|
393
393
|
TileLayerData.clear() // Clear this tile data
|
|
394
394
|
|
|
395
395
|
// Tile Collision Layer
|
|
396
|
-
TileCollisionLayer(
|
|
396
|
+
TileCollisionLayer(pos, size, tileInfo=tile()) // Create a tile collision layer object
|
|
397
397
|
TileCollisionLayer.setCollisionData(pos, data=1) // Set tile collision data at pos
|
|
398
398
|
tileCollisionGetData(pos) // Get tile collision data at pos
|
|
399
399
|
tileCollisionTest(pos, size=(0,0), object) // Check if collision should occur
|
|
400
400
|
tileCollisionRaycast(posStart, posEnd, object) // Return the center of tile if hit
|
|
401
|
-
tileLayersLoad(tileMapData, tileInfo)
|
|
401
|
+
tileLayersLoad(tileMapData, tileInfo) // Load tile layers from exported data
|
|
402
402
|
|
|
403
403
|
```
|
|
404
404
|
|
|
@@ -408,8 +408,8 @@ tileLayersLoad(tileMapData, tileInfo) // Load tile layers from export
|
|
|
408
408
|
|
|
409
409
|
```javascript
|
|
410
410
|
// Particle Emitter Object
|
|
411
|
-
ParticleEmitter(
|
|
412
|
-
ParticleEmitter.emitParticle()
|
|
411
|
+
ParticleEmitter(pos, angle, ...settings) // Create a particle system
|
|
412
|
+
ParticleEmitter.emitParticle() // Spawn one particle
|
|
413
413
|
|
|
414
414
|
// Particle Settings
|
|
415
415
|
particleEmitRateScale = 1 // Scales particles emit rate
|