littlejsengine 1.11.7 → 1.11.9

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.
@@ -164,7 +164,8 @@ for (const example of exampleList)
164
164
  }
165
165
 
166
166
  // select first option
167
- selectExample.selectedIndex = 1;
167
+ selectExample.selectedIndex = location.hash.split`#`[1] | 0
168
+
168
169
  setExample();
169
170
 
170
171
  onresize = () =>
@@ -182,12 +183,17 @@ onresize();
182
183
 
183
184
  function setExample()
184
185
  {
185
- const example = exampleList[selectExample.selectedIndex];
186
+ if (selectExample.selectedIndex < 1 || selectExample.selectedIndex >= exampleList.length)
187
+ selectExample.selectedIndex = 1; // reset to default
188
+ let example = exampleList[selectExample.selectedIndex];
189
+ if (!example.filename)
190
+ example = exampleList[selectExample.selectedIndex = 1]; // reset to default
186
191
  exampleInfo.innerText = example.name + (example.description ? ' - ' + example.description : '');
187
192
  const filename = 'examples/' + example.filename;
188
193
  exampleLink.href = 'https://github.com/KilledByAPixel/LittleJS/tree/main/' + filename;
189
194
  exampleLink.innerText = filename;
190
195
  loadFile(example.filename, example.fullExample);
196
+ location.hash = selectExample.selectedIndex;
191
197
  }
192
198
 
193
199
  function codeInput()
@@ -267,7 +273,7 @@ function setCode(code, largeExample)
267
273
  iframeContent.console.assert = function (condition, output)
268
274
  {
269
275
  if (!condition)
270
- setErrorMessage('Assertion failed: ' + (output || ''));
276
+ setErrorMessage('Assertion failed!\n' + (output || '') + '\n' + (new Error).stack);
271
277
  originalAssert.apply(this, arguments);
272
278
  };
273
279
 
@@ -13,9 +13,9 @@ function gameRender()
13
13
  }
14
14
 
15
15
  // circles and ellipses
16
- drawCircle(vec2(0,5), 1, 0, hsl(.15,1,.5));
16
+ drawCircle(vec2(0,5), 1, hsl(.15,1,.5));
17
17
  drawEllipse(vec2(-5,5), 2, 1, 0, hsl(0,1,.5));
18
- drawEllipse(vec2(5,5), 1, .5, 0, hsl(.55,1,.5));
18
+ drawEllipse(vec2(5,5), .5, 2, .5, hsl(.55,1,.5));
19
19
 
20
20
  // rects and lines
21
21
  drawRect(vec2(0,-5), vec2(13,2), hsl(.6,1,.5));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "littlejsengine",
3
- "version": "1.11.7",
3
+ "version": "1.11.9",
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/reference.md CHANGED
@@ -1,11 +1,11 @@
1
1
  # LittleJS Engine Quick Reference Sheet
2
2
 
3
- ## This cheat sheet contains all LittleJS essentials.
3
+ ## This cheat sheet contains all LittleJS essentials.
4
4
  - [LittleJS on GitHub](https://github.com/KilledByAPixel/LittleJS) - Official LittleJS website with more info
5
5
  - [LittleJS Documentation](https://killedbyapixel.github.io/LittleJS/docs) - LittleJS documentation browser
6
6
  - [Particle System Designer](https://killedbyapixel.github.io/LittleJS/examples/particles) - Editor for LittleJS Particle Systems
7
7
  - [Sound Effect Designer](https://killedbyapixel.github.io/ZzFX) - Tool for creating ZzFX sound effects
8
- - [Starter Project](https://killedbyapixel.github.io/LittleJS/examples/starter) - Simple LittleJS demo to start with
8
+ - [Starter Project](https://killedbyapixel.github.io/LittleJS/examples/starter) - Simple LittleJS demo to start with
9
9
 
10
10
  ## LittleJS Setup
11
11
 
@@ -32,7 +32,7 @@ hsl(h=0, s=0, l=1, a=1) // Create a color object with HSLA
32
32
  tile(pos=(0,0), size, textureIndex=0) // Create a tile info object
33
33
 
34
34
  // Helper functions
35
- abs(value) // Get absoulte value
35
+ abs(value) // Get absolute value
36
36
  min(valueA, valueB) // Get lowest of values
37
37
  max(valueA, valueB) // Get highest of values
38
38
  sign(value) // Get the sign of value
package/src/engine.js CHANGED
@@ -30,7 +30,7 @@ const engineName = 'LittleJS';
30
30
  * @type {String}
31
31
  * @default
32
32
  * @memberof Engine */
33
- const engineVersion = '1.11.7';
33
+ const engineVersion = '1.11.9';
34
34
 
35
35
  /** Frames per second to update
36
36
  * @type {Number}
package/src/engineDraw.js CHANGED
@@ -216,6 +216,8 @@ function drawTile(pos, size=vec2(1), tileInfo, color=new Color,
216
216
  ASSERT(!context || !useWebGL, 'context only supported in canvas 2D mode');
217
217
  ASSERT(typeof tileInfo !== 'number' || !tileInfo,
218
218
  'this is an old style calls, to fix replace it with tile(tileIndex, tileSize)');
219
+ ASSERT(isVector2(pos) && isVector2(size));
220
+ ASSERT(isColor(color) && isColor(additiveColor));
219
221
 
220
222
  const textureInfo = tileInfo && tileInfo.getTextureInfo();
221
223
  if (useWebGL)
@@ -269,7 +271,7 @@ function drawTile(pos, size=vec2(1), tileInfo, color=new Color,
269
271
  else
270
272
  {
271
273
  // if no tile info, force untextured
272
- context.fillStyle = color;
274
+ context.fillStyle = color.toString();
273
275
  context.fillRect(-.5, -.5, 1, 1);
274
276
  }
275
277
  }, screenSpace, context);
@@ -316,6 +318,7 @@ function drawLine(posA, posB, thickness=.1, color, useWebGL, screenSpace, contex
316
318
  * @memberof Draw */
317
319
  function drawPoly(points, color=new Color, lineWidth=0, lineColor=new Color(0,0,0), screenSpace, context=mainContext)
318
320
  {
321
+ ASSERT(isColor(color) && isColor(lineColor));
319
322
  context.fillStyle = color.toString();
320
323
  context.beginPath();
321
324
  for (const point of screenSpace ? points : points.map(worldToScreen))
@@ -343,6 +346,7 @@ function drawPoly(points, color=new Color, lineWidth=0, lineColor=new Color(0,0,
343
346
  * @memberof Draw */
344
347
  function drawEllipse(pos, width=1, height=1, angle=0, color=new Color, lineWidth=0, lineColor=new Color(0,0,0), screenSpace, context=mainContext)
345
348
  {
349
+ ASSERT(isColor(color) && isColor(lineColor));
346
350
  if (!screenSpace)
347
351
  {
348
352
  pos = worldToScreen(pos);
@@ -252,7 +252,6 @@ export {
252
252
  gamepadWasPressed,
253
253
  gamepadWasReleased,
254
254
  gamepadStick,
255
- mouseToScreen,
256
255
  gamepadsUpdate,
257
256
  vibrate,
258
257
  vibrateStop,
@@ -118,7 +118,7 @@ class EngineObject
118
118
  {
119
119
  // copy parent pos/angle
120
120
  const mirror = parent.getMirrorSign();
121
- this.pos = this.localPos.multiply(vec2(mirror,1)).rotate(-parent.angle).add(parent.pos);
121
+ this.pos = this.localPos.multiply(vec2(mirror,1)).rotate(parent.angle).add(parent.pos);
122
122
  this.angle = mirror*this.localAngle + parent.angle;
123
123
  }
124
124
 
@@ -346,11 +346,11 @@ class EngineObject
346
346
 
347
347
  /** Convert from local space to world space for a vector (rotation only)
348
348
  * @param {Vector2} vec - local space vector */
349
- localToWorldVector(vec) { return vec.rotate(-this.angle); }
349
+ localToWorldVector(vec) { return vec.rotate(this.angle); }
350
350
 
351
351
  /** Convert from world space to local space for a vector (rotation only)
352
352
  * @param {Vector2} vec - world space vector */
353
- worldToLocalVector(vec) { return vec.rotate(this.angle); }
353
+ worldToLocalVector(vec) { return vec.rotate(-this.angle); }
354
354
 
355
355
  /** Called to check if a tile collision should be resolved
356
356
  * @param {Number} tileData - the value of the tile at the position
@@ -272,7 +272,7 @@ class RandomGenerator
272
272
  this.seed ^= this.seed << 13;
273
273
  this.seed ^= this.seed >>> 17;
274
274
  this.seed ^= this.seed << 5;
275
- return valueB + (valueA - valueB) * abs(this.seed % 1e8) / 1e8;
275
+ return valueB + (valueA - valueB) * ((this.seed >>> 0) / 2**32);
276
276
  }
277
277
 
278
278
  /** Returns a floored seeded random value the two values passed in
@@ -461,11 +461,11 @@ class Vector2
461
461
  return this.x*v.y - this.y*v.x;
462
462
  }
463
463
 
464
- /** Returns the angle of this vector, up is angle 0
464
+ /** Returns the clockwise angle of this vector, up is angle 0
465
465
  * @return {Number} */
466
466
  angle() { return Math.atan2(this.x, this.y); }
467
467
 
468
- /** Sets this vector with angle and length passed in
468
+ /** Sets this vector with clockwise angle and length passed in
469
469
  * @param {Number} [angle]
470
470
  * @param {Number} [length]
471
471
  * @return {Vector2} */
@@ -476,13 +476,13 @@ class Vector2
476
476
  return this;
477
477
  }
478
478
 
479
- /** Returns copy of this vector rotated by the angle passed in
479
+ /** Returns copy of this vector rotated by the clockwise angle passed in
480
480
  * @param {Number} angle
481
481
  * @return {Vector2} */
482
482
  rotate(angle)
483
483
  {
484
- const c = Math.cos(angle), s = Math.sin(angle);
485
- return new Vector2(this.x*c + this.y*s, this.x*s + this.y*c);
484
+ const c = Math.cos(-angle), s = Math.sin(-angle);
485
+ return new Vector2(this.x*c - this.y*s, this.x*s + this.y*c);
486
486
  }
487
487
 
488
488
  /** Set the integer direction of this vector, corresponding to multiples of 90 degree rotation (0-3)
@@ -817,57 +817,57 @@ class Color
817
817
  ///////////////////////////////////////////////////////////////////////////////
818
818
  // default colors
819
819
 
820
- /** Color - White
820
+ /** Color - White #ffffff
821
821
  * @type {Color}
822
822
  * @memberof Utilities */
823
- const WHITE = rgb();
823
+ const WHITE = rgb();
824
824
 
825
- /** Color - Black
825
+ /** Color - Black #000000
826
826
  * @type {Color}
827
827
  * @memberof Utilities */
828
828
  const BLACK = rgb(0,0,0);
829
829
 
830
- /** Color - Gray
830
+ /** Color - Gray #808080
831
831
  * @type {Color}
832
832
  * @memberof Utilities */
833
833
  const GRAY = rgb(.5,.5,.5);
834
834
 
835
- /** Color - Red
835
+ /** Color - Red #ff0000
836
836
  * @type {Color}
837
837
  * @memberof Utilities */
838
838
  const RED = rgb(1,0,0);
839
839
 
840
- /** Color - Orange
840
+ /** Color - Orange #ff8000
841
841
  * @type {Color}
842
842
  * @memberof Utilities */
843
843
  const ORANGE = rgb(1,.5,0);
844
844
 
845
- /** Color - Yellow
845
+ /** Color - Yellow #ffff00
846
846
  * @type {Color}
847
847
  * @memberof Utilities */
848
848
  const YELLOW = rgb(1,1,0);
849
849
 
850
- /** Color - Green
850
+ /** Color - Green #00ff00
851
851
  * @type {Color}
852
852
  * @memberof Utilities */
853
853
  const GREEN = rgb(0,1,0);
854
854
 
855
- /** Color - Cyan
855
+ /** Color - Cyan #00ffff
856
856
  * @type {Color}
857
857
  * @memberof Utilities */
858
858
  const CYAN = rgb(0,1,1);
859
859
 
860
- /** Color - Blue
860
+ /** Color - Blue #0000ff
861
861
  * @type {Color}
862
862
  * @memberof Utilities */
863
863
  const BLUE = rgb(0,0,1);
864
864
 
865
- /** Color - Purple
865
+ /** Color - Purple #8000ff
866
866
  * @type {Color}
867
867
  * @memberof Utilities */
868
868
  const PURPLE = rgb(.5,0,1);
869
869
 
870
- /** Color - Magenta
870
+ /** Color - Magenta #ff00ff
871
871
  * @type {Color}
872
872
  * @memberof Utilities */
873
873
  const MAGENTA = rgb(1,0,1);
@@ -1,14 +0,0 @@
1
- {
2
- // Use IntelliSense to learn about possible attributes.
3
- // Hover to view descriptions of existing attributes.
4
- // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
5
- "version": "0.2.0",
6
- "configurations": [
7
- {
8
- "type": "chrome",
9
- "request": "launch",
10
- "name": "Open index.html",
11
- "file": "c:\\dev\\FrankGames\\html5\\LittleJS\\LittleJS\\shortExamples\\index.html"
12
- }
13
- ]
14
- }