littlejsengine 1.17.5 → 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.
@@ -7,7 +7,7 @@
7
7
  </head><body>
8
8
 
9
9
  <!-- LittleJS Engine -->
10
- <script src=../../dist/littlejs.js?1.17.5></script>
10
+ <script src=../../dist/littlejs.js?1.17.10></script>
11
11
 
12
12
  <!-- Add your game scripts here -->
13
- <script src=game.js?1.17.5></script>
13
+ <script src=game.js?1.17.10></script>
@@ -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 mose', false, 'ui, input, control'),
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('--- MINI GAMES ---'),
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
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 addtive blend?');
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, 1, .1, amount/.1, 3.14, // pos, angle, size, time, rate, cone
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 positonOffset = vec2(0, 2-depth);
272
+ const positionOffset = vec2(0, 2-depth);
273
273
  const cameraOffset = cameraDeltaFromCenter.scale(1/LJS.cameraScale);
274
- this.pos = LJS.cameraPos.add(positonOffset).add(cameraOffset);
274
+ this.pos = LJS.cameraPos.add(positionOffset).add(cameraOffset);
275
275
  this.size = canvasSize.scale(scale);
276
276
  super.render();
277
277
  }
@@ -1,5 +1,5 @@
1
1
  <!DOCTYPE html><meta charset=utf-8><body>
2
- <script src=../../dist/littlejs.js?1.17.5></script>
2
+ <script src=../../dist/littlejs.js?1.17.10></script>
3
3
  <script src=../../dist/box2d.wasm.js></script>
4
4
 
5
5
  <!-- LittleJS Engine Source
@@ -14,7 +14,7 @@ function gameRender()
14
14
  drawRect(vec2( 4, 0), vec2(3), hsl(.6,.5,.5));
15
15
  drawRect(vec2( 8, 0), vec2(3), hsl(0,0,1));
16
16
 
17
- // color lerpping
17
+ // color lerping
18
18
  for (let i=5; i--;)
19
19
  {
20
20
  const color1 = RED;
@@ -33,7 +33,7 @@ function gameUpdate()
33
33
  function gameRender()
34
34
  {
35
35
  {
36
- // draw horizontal slizes to create floor and ceiling
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)
@@ -1,5 +1,5 @@
1
1
  const musicSound = new Sound('song.mp3');
2
- let musicVolume = 1, musicInstance;
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
- // infomation text
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 = 1, musicSound, musicInstance;
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 positonOffset = vec2(0, 4-depth*3);
68
- this.pos = cameraDeltaFromCenter.add(positonOffset)
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 postion to be at the bottom of the object
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.5></script>
10
+ <script src=../../dist/littlejs.js?1.17.9></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.5></script>
35
+ <script src=game.js?1.17.10></script>
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "littlejsengine",
3
- "version": "1.17.5",
3
+ "version": "1.17.10",
4
4
  "description": "LittleJS - Tiny and Fast HTML5 Game Engine",
5
5
  "main": "dist/littlejs.esm.js",
6
6
  "types": "dist/littlejs.d.ts",
package/plugins/box2d.js CHANGED
@@ -612,11 +612,11 @@ class Box2dStaticObject extends Box2dObject
612
612
 
613
613
  ///////////////////////////////////////////////////////////////////////////////
614
614
  /**
615
- * Box2D Kiematic Object - Box2d with a kinematic physics body
615
+ * Box2D Kinematic Object - Box2d with a kinematic physics body
616
616
  * @extends Box2dObject
617
617
  * @memberof Box2D
618
618
  */
619
- class Box2dKiematicObject extends Box2dObject
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
 
@@ -37,7 +37,7 @@ export
37
37
  Box2dPlugin,
38
38
  Box2dObject,
39
39
  Box2dStaticObject,
40
- Box2dKiematicObject,
40
+ Box2dKinematicObject,
41
41
  Box2dRaycastResult,
42
42
  Box2dJoint,
43
43
  Box2dTargetJoint,
@@ -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 mainCanvs onto glCanvas
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
@@ -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} - Cooldown timer for navigation inputs */
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 axies for navigation
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 objecct */
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 handleSize = isHorizontal ? this.size.y : this.size.x;
1194
- const barSize = isHorizontal ? this.size.x : this.size.y;
1195
- const centerPos = isHorizontal ? this.pos.x : this.pos.y;
1196
-
1197
- // draw the scrollbar handle
1198
- const handleWidth = barSize - handleSize;
1199
- const p1 = centerPos - handleWidth/2;
1200
- const p2 = centerPos + handleWidth/2;
1201
- const handlePos = isHorizontal ?
1202
- vec2(lerp(p1, p2, this.value), this.pos.y) :
1203
- vec2(this.pos.x, lerp(p2, p1, this.value))
1204
- const handleColor = this.disabled ? this.disabledColor : this.handleColor;
1205
- uiSystem.drawRect(handlePos, vec2(handleSize), handleColor, this.lineWidth, this.lineColor, this.cornerRadius, this.gradientColor);
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 = 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), 'cutscene.mp4', true);
1240
+ * const video = new VideoPlayerUIObject(vec2(400, 300), vec2(320, 240), 'video.mp4', true);
1228
1241
  * video.play();
1229
1242
  * @memberof UISystem
1230
1243
  */
package/reference.md CHANGED
@@ -371,14 +371,14 @@ engineObjectsDestroy()
371
371
  ```javascript
372
372
 
373
373
  // Canvas Layer
374
- CanvasLayer(position, size) // Create a canvas layer object
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(position, size, tileInfo, scale) // Create a tile layer object
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(position, size, tileInfo=tile()) // Create a tile collision layer object
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) // Load tile layers from exported data
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(position, angle, ...settings) // Create a particle system
412
- ParticleEmitter.emitParticle() // Spawn one particle
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