littlejsengine 1.13.1 → 1.13.4

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.
Files changed (66) hide show
  1. package/README.md +15 -12
  2. package/dist/littlejs.d.ts +94 -74
  3. package/dist/littlejs.esm.js +422 -306
  4. package/dist/littlejs.esm.min.js +1 -1
  5. package/dist/littlejs.js +416 -306
  6. package/dist/littlejs.min.js +1 -1
  7. package/dist/littlejs.release.js +414 -304
  8. package/examples/box2d/game.js +1 -1
  9. package/examples/box2d/gameObjects.js +1 -1
  10. package/examples/box2d/scenes.js +1 -1
  11. package/examples/breakoutTutorial/README.md +44 -41
  12. package/examples/breakoutTutorial/game.js +2 -2
  13. package/examples/electron/build.bat +7 -0
  14. package/examples/electron/build.js +124 -0
  15. package/examples/electron/electron.js +35 -0
  16. package/examples/electron/game.js +140 -0
  17. package/examples/electron/index.html +13 -0
  18. package/examples/electron/package.json +12 -0
  19. package/examples/electron/tiles.png +0 -0
  20. package/examples/empty/game.js +1 -0
  21. package/examples/htmlMenu/game.js +1 -1
  22. package/examples/index.html +154 -93
  23. package/examples/module/game.js +5 -2
  24. package/examples/particles/index.html +12 -3
  25. package/examples/platformer/gameEffects.js +3 -3
  26. package/examples/shorts/base.html +1 -1
  27. package/examples/shorts/blending.js +9 -5
  28. package/examples/shorts/box2d.js +1 -1
  29. package/examples/shorts/box2dCar.js +1 -1
  30. package/examples/shorts/clock.js +1 -1
  31. package/examples/shorts/colors.js +2 -2
  32. package/examples/shorts/maze.js +1 -1
  33. package/examples/shorts/nineSlice.js +9 -9
  34. package/examples/shorts/piano.js +2 -2
  35. package/examples/shorts/raycasting.js +2 -2
  36. package/examples/shorts/shapes.js +9 -9
  37. package/examples/shorts/slidingPuzzle.js +2 -2
  38. package/examples/shorts/starfield.js +5 -7
  39. package/examples/shorts/systemFont.js +1 -1
  40. package/examples/shorts/uiSystem.js +1 -0
  41. package/examples/starter/build.js +9 -8
  42. package/examples/starter/game.js +5 -2
  43. package/examples/starter/index.html +2 -2
  44. package/examples/stress/index.html +5 -5
  45. package/examples/style.css +5 -2
  46. package/examples/typescript/build.js +1 -1
  47. package/examples/typescript/game.js +2 -2
  48. package/examples/typescript/game.ts +5 -2
  49. package/examples/uiSystem/game.js +2 -1
  50. package/package.json +2 -2
  51. package/plugins/box2d.js +19 -94
  52. package/plugins/drawUtilities.js +24 -18
  53. package/plugins/postProcess.js +7 -0
  54. package/plugins/uiSystem.js +4 -4
  55. package/src/engine.js +7 -2
  56. package/src/engineAudio.js +1 -1
  57. package/src/engineDebug.js +2 -2
  58. package/src/engineDraw.js +243 -150
  59. package/src/engineExport.js +6 -0
  60. package/src/engineInput.js +2 -2
  61. package/src/engineMedals.js +4 -4
  62. package/src/engineObject.js +3 -3
  63. package/src/engineParticles.js +8 -1
  64. package/src/engineSettings.js +55 -8
  65. package/src/engineUtilities.js +7 -7
  66. package/src/engineWebGL.js +25 -5
@@ -1,24 +1,24 @@
1
1
  function gameRender()
2
2
  {
3
3
  // polygon shapes
4
- for(let j=3; j<7; ++j)
4
+ for (let j=3; j<7; ++j)
5
5
  {
6
6
  let points = [];
7
- for(let i=0; i<j; ++i)
7
+ for (let i=0; i<j; ++i)
8
8
  {
9
9
  let angle = i * Math.PI * 2 / j;
10
- points.push(vec2(j*4-18,0).add(vec2(Math.sin(angle), Math.cos(angle))));
10
+ points.push(vec2(j*4-18,0).add(vec2(0,1).rotate(angle)));
11
11
  }
12
- drawPoly(points, hsl(j/4,1,.5)); // draw a star
12
+ drawPoly(points, hsl(j/4+time/9,1,.5)); // draw a regular polygon
13
13
  }
14
14
 
15
15
  // circles and ellipses
16
- drawCircle(vec2(0,5), 1, hsl(.15,1,.5));
17
- drawEllipse(vec2(-5,5), 2, 1, 0, hsl(0,1,.5));
18
- drawEllipse(vec2(5,5), .5, 2, .5, hsl(.55,1,.5));
16
+ drawCircle(vec2(0,5), 1+wave(.5), hsl(.15,1,.5));
17
+ drawEllipse(vec2(-5,5), vec2(2,1), hsl(0,1,.5));
18
+ drawEllipse(vec2(5,5), vec2(.5,2), hsl(.55,1,.5), .5);
19
19
 
20
20
  // rects and lines
21
- drawRect(vec2(0,-5), vec2(13,2), hsl(.6,1,.5));
22
- drawLine(vec2(-5,-7), vec2(5,-3), 1, hsl(0,0,1));
21
+ drawRect(vec2(0,-5), vec2(4,3), hsl(.6,1,.5), time);
22
+ drawLine(vec2(-5,-7), vec2(5,-3), 1, hsl(0,0,1, .5));
23
23
  drawLine(vec2(-5,-3), vec2(5,-7), .2, hsl(1,1,.5));
24
24
  }
@@ -33,8 +33,8 @@ class PuzzlePiece extends EngineObject
33
33
  function gameInit()
34
34
  {
35
35
  // create puzzle pieces
36
- for(let x=gridSize.x; x--;)
37
- for(let y=gridSize.y; y--;)
36
+ for (let x=gridSize.x; x--;)
37
+ for (let y=gridSize.y; y--;)
38
38
  (x||y) && new PuzzlePiece(vec2(x,y), pieceSize);
39
39
 
40
40
  // center camera on grid
@@ -1,17 +1,15 @@
1
1
  function gameRender()
2
2
  {
3
- setBlendMode(1);
4
3
  // precreate variables to avoid overhead
5
4
  const pos = vec2(), size = vec2(), color = WHITE;
6
- for(let i=2e3; i--;)
5
+ for (let i=2e3; i--;)
7
6
  {
8
7
  // use math to generate random star positions
9
8
  const offset = time*(9+i**2.1%15) + i**2.3;
10
- pos.x = offset%70-35;
11
- pos.y = i/120-8;
12
- size.x = size.y = i%.11+.07;
13
- color.setHSLA(0, 0, Math.sin(i)**4);
9
+ pos.x = offset%70 - 35;
10
+ pos.y = i/110 - 9;
11
+ size.x = size.y = i%.11 + .07;
12
+ color.set(1,1,1,Math.sin(i)**4);
14
13
  drawRect(pos, size, color);
15
14
  }
16
- setBlendMode(0);
17
15
  }
@@ -6,7 +6,7 @@ function gameRender()
6
6
 
7
7
  // show every character in the system font
8
8
  let s = '';
9
- for(let i=32; i<128; ++i)
9
+ for (let i=32; i<128; ++i)
10
10
  {
11
11
  if (i%32 == 0)
12
12
  s += '\n';
@@ -8,6 +8,7 @@ function gameInit()
8
8
  new UISystemPlugin;
9
9
  uiSystem.defaultSoundPress = new Sound([1,0,220]);
10
10
  uiSystem.defaultSoundClick = new Sound([1,0,440]);
11
+ uiSystem.defaultCornerRadius = 8;
11
12
 
12
13
  // setup example menu
13
14
  uiMenu = new UIObject(mainCanvasSize.scale(.5));
@@ -36,7 +36,7 @@ fs.rmSync(`${PROGRAM_NAME}.zip`, { force: true });
36
36
  fs.mkdirSync(BUILD_FOLDER);
37
37
 
38
38
  // copy data files
39
- for(const file of dataFiles)
39
+ for (const file of dataFiles)
40
40
  fs.copyFileSync(file, `${BUILD_FOLDER}/${file}`);
41
41
 
42
42
  Build
@@ -50,7 +50,6 @@ Build
50
50
 
51
51
  console.log('');
52
52
  console.log(`Build Completed in ${((Date.now() - startTime)/1e3).toFixed(2)} seconds!`);
53
- console.log(`Size of ${PROGRAM_NAME}.zip: ${fs.statSync(`${PROGRAM_NAME}.zip`).size} bytes`);
54
53
 
55
54
  ///////////////////////////////////////////////////////////////////////////////
56
55
 
@@ -73,7 +72,7 @@ function Build(outputFile, files=[], buildSteps=[])
73
72
 
74
73
  function closureCompilerStep(filename)
75
74
  {
76
- console.log(`Running closure compiler...`);
75
+ console.log('Running closure compiler...');
77
76
 
78
77
  // use closer compiler to minify the code
79
78
  const filenameTemp = filename + '.tmp';
@@ -84,22 +83,23 @@ function closureCompilerStep(filename)
84
83
 
85
84
  function uglifyBuildStep(filename)
86
85
  {
87
- console.log(`Running uglify...`);
86
+ console.log('Running uglify...');
88
87
  child_process.execSync(`npx uglifyjs ${filename} -c -m -o ${filename}`, {stdio: 'inherit'});
89
88
  };
90
89
 
91
90
  function roadrollerBuildStep(filename)
92
91
  {
93
- console.log(`Running roadroller...`);
92
+ console.log('Running roadroller...');
94
93
  child_process.execSync(`npx roadroller ${filename} -o ${filename}`, {stdio: 'inherit'});
95
94
  };
96
95
 
97
96
  function htmlBuildStep(filename)
98
97
  {
99
- console.log(`Building html...`);
98
+ console.log('Building html...');
100
99
 
101
100
  // create html file
102
- let buffer = '<!DOCTYPE html>';
101
+ let buffer = ''
102
+ buffer += '<!DOCTYPE html>';
103
103
  buffer += '<head>';
104
104
  buffer += `<title>${PROGRAM_TITLE}</title>`;
105
105
  buffer += '<meta charset=utf-8>';
@@ -115,8 +115,9 @@ function htmlBuildStep(filename)
115
115
 
116
116
  function zipBuildStep(filename)
117
117
  {
118
- console.log(`Zipping...`);
118
+ console.log('Zipping...');
119
119
  const sources = ['index.html', ...dataFiles];
120
120
  const sourceList = sources.join(' ');
121
121
  child_process.execSync(`npx bestzip ../${PROGRAM_NAME}.zip ${sourceList}`, {cwd:BUILD_FOLDER, stdio: 'inherit'});
122
+ console.log(`Size of ${PROGRAM_NAME}.zip: ${fs.statSync(`${PROGRAM_NAME}.zip`).size} bytes`);
122
123
  };
@@ -104,7 +104,10 @@ function gameUpdate()
104
104
 
105
105
  // move particles to mouse location if on screen
106
106
  if (mousePosScreen.x)
107
+ {
107
108
  particleEmitter.pos = mousePos;
109
+ particleEmitter.velocity = mouseDelta.scale(.3*timeDelta);
110
+ }
108
111
  }
109
112
 
110
113
  ///////////////////////////////////////////////////////////////////////////////
@@ -116,8 +119,8 @@ function gameUpdatePost()
116
119
  ///////////////////////////////////////////////////////////////////////////////
117
120
  function gameRender()
118
121
  {
119
- // draw a grey square in the background without using webgl
120
- drawRect(vec2(16,8), vec2(20,14), hsl(0,0,.6), 0, false);
122
+ // draw a grey square in the background
123
+ drawRect(vec2(16,8), vec2(20,14), hsl(0,0,.6));
121
124
 
122
125
  // draw the logo as a tile
123
126
  drawTile(vec2(21,5), vec2(4.5), tile(3,128));
@@ -7,7 +7,7 @@
7
7
  </head><body>
8
8
 
9
9
  <!-- LittleJS Engine -->
10
- <script src=../../dist/littlejs.js?11212></script>
10
+ <script src=../../dist/littlejs.js?1133></script>
11
11
 
12
12
  <!-- LittleJS Engine Source
13
13
  <script src=../../src/engineDebug.js></script>
@@ -31,4 +31,4 @@
31
31
  -->
32
32
 
33
33
  <!-- Add your game scripts here -->
34
- <script src=game.js?11212></script>
34
+ <script src=game.js?1133></script>
@@ -123,23 +123,23 @@ function gameRender()
123
123
  // update sprites
124
124
  for (const sprite of sprites)
125
125
  {
126
- // keep sprites above 0
127
- sprite.pos.y = LJS.max(sprite.pos.y, 0);
128
-
129
126
  // apply velocity and gravity
130
127
  sprite.pos.x += sprite.velocity.x;
131
128
  sprite.pos.y += sprite.velocity.y += LJS.gravity.y;
132
129
 
133
130
  // bounce
134
131
  if (sprite.pos.y < 0)
132
+ {
133
+ sprite.pos.y = 0;
135
134
  sprite.velocity.y = LJS.rand(.3,.8);
135
+ }
136
136
  if (sprite.pos.x < 0)
137
137
  sprite.pos.x = 0, sprite.velocity.x *= -1;
138
138
  if (sprite.pos.x > tileLayer.size.x)
139
139
  sprite.pos.x = tileLayer.size.x, sprite.velocity.x *= -1;
140
140
 
141
141
  // rotate sprite
142
- sprite.angle += .02*LJS.sign(sprite.velocity.x);
142
+ sprite.angle += sprite.velocity.x > 0 ? .02 : -.02;
143
143
 
144
144
  // draw the sprite directly using glDraw for extra speed
145
145
  LJS.glDraw(sprite.pos.x, sprite.pos.y, 1, 1, sprite.angle, 0, 0, 1, 1,
@@ -162,5 +162,5 @@ LJS.engineInit(gameInit, gameUpdate, gameUpdatePost, gameRender, gameRenderPost,
162
162
 
163
163
  ///////////////////////////////////////////////////////////////////////////////
164
164
  // music - Depp Loop
165
- const music = new LJS.ZzFXMusic([[[.6,0,76,,,1,1,.5,,,,,.1,,,.06,,.5,.2,,-700],[,0,43,.01,,.2,2,,,,,,,,,,.01],[,0,170,.003,,.008,,.97,-35,53,,,,,,.1],[.8,0,270,,,.12,3,1.65,-2,,,,,4.5,,.02],[,0,86,,,.1,,.7,,,,.5,,6.7,1,.05],[,0,41,,.05,.4,2,0,,,9,.01,,,,.08,.02],[,0,2200,,,.04,3,2,,,800,.02,,4.8,,.01,.1],[.3,0,16,,,.3,3]],[[[1,-1,21,21,33,21,21,33,21,21,33,21,21,33,21,21,33,33,21,21,33,21,21,33,21,21,33,21,21,33,21,21,33,33,21,21,33,21,21,33,21,21,33,21,21,33,21,21,33,33,21,21,33,21,21,33,21,21,33,21,21,33,21,21,33,33],[3,1,22,,,,,,,,,,,,,,,,,,,,,,,,,,,,24,,,,24,,,,,,,,,,,,,,,,,,,,,,,,22,,22,,22,,,,],[5,-1,21,,,,,,,,,,,,,,,,,,,,,,,,,,,,24,,,,23,,,,,,,,,,,,,,,,,,,,,,,,24,,23,,21,,,,],[,1,21,,,,,,,,,,,,,,,,,,,,,,,,,,,,24,,,,23,,,,,,,,,,,,,,,,,,,,,,,,24,,23,,21,,,,]],[[1,-1,21,21,33,21,21,33,21,21,33,21,21,33,21,21,33,33,21,21,33,21,21,33,21,21,33,21,21,33,21,21,33,33,21,21,33,21,21,33,21,21,33,21,21,33,21,21,33,33,21,21,33,21,21,33,21,21,33,21,21,33,21,21,33,33],[3,1,24,,,,,,,,27,,,,,,,,,,,,,,,,27,,,,24,,,,24,,,,,,,,27,,,,,,,,,,,,,,,,24,,24,,24,,,,],[5,-1,21,,,,,,,,,,,,,,,,,,,,,,,,,,,,24,,,,23,,,,,,,,,,,,,,,,,,,,,,,,24,,23,,21,,,,],[,1,21,,,,,,,,,,,,,,,,,,,,,,,,,,,,24,,,,23,,,,,,,,,,,,,,,,,,,,,,,,24,,23,,21,,,,],[6,1,,,34,34,34,,,,,,34,34,,,,,34,,,,34,34,,,,,34,,,,34,,,,34,34,34,,,,,,34,,,,,,34,34,,,34,34,,,,,,,,,34,34],[4,1,,,,,,,24,,,,,,24,,24,,,,24,,,,24,,,,,,,,,,,,,,,,24,,,,,,24,,24,,,,24,,,,24,,,,,,,,,,]],[[1,-1,21,21,33,21,21,33,21,21,33,21,21,33,21,21,33,33,21,21,33,21,21,33,21,21,33,21,21,33,21,21,33,33,23,23,35,23,23,36,23,23,35,23,23,36,23,23,35,35,23,23,35,23,23,35,23,23,36,23,23,35,23,23,36,36],[5,-1,21,,,19,,,21,,,,,,,,,,21,,,19,,,17,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,],[3,1,24,,,24,,,24,,,,,,,,,,24,,,24,,,24,,,,24.75,24.5,24.26,24.01,24.01,24.01,,,,,25,,,,,,,,25,,,,,,,,25,,,,,,,,25,25,25,25],[4,-1,,,,,,,,,,,,,,,,,,,,,,,,,,,24.75,24.5,24.26,24.01,24.01,24.01,24.01,24,,24,24,,24,24,24,24,,24,24,,24,,24,24,,24,24,,24,24,24,24,,24,24,,24,24],[7,-1,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,23,,21,23,,35,,23,,21,23,,35,,35,,23,,21,23,,35,,21,23,,35,,21,23,,,],[6,1,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,34,36,34,,33,34,34,36,31,36,34,,31,34,32,,33,36,34,,31,34,34,36,33,36,33,,31,,,]],[[1,-1,21,21,33,21,21,33,21,21,33,21,21,33,21,21,33,33,21,21,33,21,21,33,21,21,33,21,21,33,21,21,33,33,17,17,29,17,17,29,17,17,29,17,17,29,17,17,29,29,17,17,29,17,17,29,17,17,29,17,17,29,17,17,29,29],[4,1,24,24,,24,24,,24,24,24,24,,24,24,,24,,24,24,,24,24,,24,24,24,24,,24,24,,24,24,24,24,,24,24,,24,24,24,,,24,24,,24,,24,24,,24,24,,24,24,24,24,,24,24,,24,24],[7,-1,21,,19,21,,33,,21,,19,21,,33,,33,,21,,19,21,,33,,21,,19,21,,33,,33,,17,,17,17,29,17,17,29,17,,17,17,29,17,17,29,17,,17,17,29,17,17,29,17,,17,17,29,17,17,29],[2,1,,34,34,34,,34,34,34,,34,34,34,,34,34,34,,34,34,34,,34,34,34,,34,34,34,,34,,,,34,34,34,,34,34,34,,34,34,34,,34,34,34,,34,34,34,,34,34,34,,34,34,34,,34,,,],[6,1,,,36,,,,,,36,,36,,,,,,,,36,,,,,,36,,36,,,,,,,,36,,,,,,,,,,,,,,,,36,,,,,,36,,36,,,,,,],[3,1,,,,,25,,,,,,,,25,,,,,,,,25,,,,,,,,25,25,25,25,,,,,25,,,,,25,,,25,,,,,,,,25,,,,,,,,25,25,25,25]],[[1,-1,14,14,26,14,14,26,14,14,26,14,14,26,14,14,26,26,14,14,26,14,14,26,14,14,26,14,14,26,14,14,26,26,17,17,29,17,17,29,17,17,29,17,17,29,17,17,29,29,19,19,31,19,19,31,19,19,31,19,19,31,19,19,31,31],[4,1,24,24,,24,24,,24,24,24,24,,24,24,,24,,24,24,,24,24,,24,24,24,24,,24,24,,24,24,24,24,,24,24,,24,24,24,24,,24,24,,36,,24,24,,24,24,,24,24,24,24,,24,24,,24,24],[7,-1,14,,14,14,26,14,14,26,14,,14,14,26,14,14,26,14,,14,14,26,14,14,26,14,,14,14,26,14,14,26,17,,17,17,29,17,17,29,17,,17,17,29,17,17,29,19,,19,19,31,19,19,31,19,,19,19,31,19,19,31],[2,1,,36,36,36,,36,36,36,,36,36,36,,36,36,36,,36,36,36,,36,36,36,,36,36,36,,36,,,,36,36,36,,36,36,36,,36,36,36,,36,36,36,,36,36,36,,36,36,36,,36,36,36,,36,,,],[3,1,,,,,25,,,,,,,,25,,,,,,,,25,,,,,,,,25,25,25,25,,,,,25,,,,,,,,25,,,,,,,,25,,,,,,,,25,25,25,25],[6,1,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,34,,,,,,34,,34,,,,,,,,34,,,,,,34,,34,,,,,,]]],[0,1,1,2,3,4,4]]);
165
+ const music = new LJS.ZzFXMusic([[[.6,0,43,,,1,1,.5,,,,,.1,,,.05,,.5,.4,.2],[,0,43,.01,,.2,2,,,,,,,,,,.01],[,0,170,.003,,.008,,.97,-35,53,,,,,,.1],[.8,0,270,,,.12,3,1.65,-2,,,,,4.5,,.02],[,0,86,,,.1,,.7,,,,.5,,6.7,1,.05],[,0,41,,.05,.4,2,0,,,9,.01,,,,.08,.02],[,0,2200,,,.04,3,2,,,800,.02,,4.8,,.01,.1],[.3,0,16,,,.3,3]],[[[1,-1,21,21,33,21,21,33,21,21,33,21,21,33,21,21,33,33,21,21,33,21,21,33,21,21,33,21,21,33,21,21,33,33,21,21,33,21,21,33,21,21,33,21,21,33,21,21,33,33,21,21,33,21,21,33,21,21,33,21,21,33,21,21,33,33],[3,1,22,,,,,,,,,,,,,,,,,,,,,,,,,,,,24,,,,24,,,,,,,,,,,,,,,,,,,,,,,,22,,22,,22,,,,],[5,-1,21,,,,,,,,,,,,,,,,,,,,,,,,,,,,24,,,,23,,,,,,,,,,,,,,,,,,,,,,,,24,,23,,21,,,,],[,1,21,,,,,,,,,,,,,,,,,,,,,,,,,,,,24,,,,23,,,,,,,,,,,,,,,,,,,,,,,,24,,23,,21,,,,]],[[1,-1,21,21,33,21,21,33,21,21,33,21,21,33,21,21,33,33,21,21,33,21,21,33,21,21,33,21,21,33,21,21,33,33,21,21,33,21,21,33,21,21,33,21,21,33,21,21,33,33,21,21,33,21,21,33,21,21,33,21,21,33,21,21,33,33],[3,1,24,,,,,,,,27,,,,,,,,,,,,,,,,27,,,,24,,,,24,,,,,,,,27,,,,,,,,,,,,,,,,24,,24,,24,,,,],[5,-1,21,,,,,,,,,,,,,,,,,,,,,,,,,,,,24,,,,23,,,,,,,,,,,,,,,,,,,,,,,,24,,23,,21,,,,],[,1,21,,,,,,,,,,,,,,,,,,,,,,,,,,,,24,,,,23,,,,,,,,,,,,,,,,,,,,,,,,24,,23,,21,,,,],[6,1,,,34,34,34,,,,,,34,34,,,,,34,,,,34,34,,,,,34,,,,34,,,,34,34,34,,,,,,34,,,,,,34,34,,,34,34,,,,,,,,,34,34],[4,1,,,,,,,24,,,,,,24,,24,,,,24,,,,24,,,,,,,,,,,,,,,,24,,,,,,24,,24,,,,24,,,,24,,,,,,,,,,]],[[1,-1,21,21,33,21,21,33,21,21,33,21,21,33,21,21,33,33,21,21,33,21,21,33,21,21,33,21,21,33,21,21,33,33,23,23,35,23,23,36,23,23,35,23,23,36,23,23,35,35,23,23,35,23,23,35,23,23,36,23,23,35,23,23,36,36],[5,-1,21,,,19,,,21,,,,,,,,,,21,,,19,,,17,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,],[3,1,24,,,24,,,24,,,,,,,,,,24,,,24,,,24,,,,24.75,24.5,24.26,24.01,24.01,24.01,,,,,25,,,,,,,,25,,,,,,,,25,,,,,,,,25,25,25,25],[4,-1,,,,,,,,,,,,,,,,,,,,,,,,,,,24.75,24.5,24.26,24.01,24.01,24.01,24.01,24,,24,24,,24,24,24,24,,24,24,,24,,24,24,,24,24,,24,24,24,24,,24,24,,24,24],[7,-1,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,23,,21,23,,35,,23,,21,23,,35,,35,,23,,21,23,,35,,21,23,,35,,21,23,,,],[6,1,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,34,36,34,,33,34,34,36,31,36,34,,31,34,32,,33,36,34,,31,34,34,36,33,36,33,,31,,,]],[[1,-1,21,21,33,21,21,33,21,21,33,21,21,33,21,21,33,33,21,21,33,21,21,33,21,21,33,21,21,33,21,21,33,33,17,17,29,17,17,29,17,17,29,17,17,29,17,17,29,29,17,17,29,17,17,29,17,17,29,17,17,29,17,17,29,29],[4,1,24,24,,24,24,,24,24,24,24,,24,24,,24,,24,24,,24,24,,24,24,24,24,,24,24,,24,24,24,24,,24,24,,24,24,24,,,24,24,,24,,24,24,,24,24,,24,24,24,24,,24,24,,24,24],[7,-1,21,,19,21,,33,,21,,19,21,,33,,33,,21,,19,21,,33,,21,,19,21,,33,,33,,17,,17,17,29,17,17,29,17,,17,17,29,17,17,29,17,,17,17,29,17,17,29,17,,17,17,29,17,17,29],[2,1,,34,34,34,,34,34,34,,34,34,34,,34,34,34,,34,34,34,,34,34,34,,34,34,34,,34,,,,34,34,34,,34,34,34,,34,34,34,,34,34,34,,34,34,34,,34,34,34,,34,34,34,,34,,,],[6,1,,,36,,,,,,36,,36,,,,,,,,36,,,,,,36,,36,,,,,,,,36,,,,,,,,,,,,,,,,36,,,,,,36,,36,,,,,,],[3,1,,,,,25,,,,,,,,25,,,,,,,,25,,,,,,,,25,25,25,25,,,,,25,,,,,25,,,25,,,,,,,,25,,,,,,,,25,25,25,25]],[[1,-1,14,14,26,14,14,26,14,14,26,14,14,26,14,14,26,26,14,14,26,14,14,26,14,14,26,14,14,26,14,14,26,26,17,17,29,17,17,29,17,17,29,17,17,29,17,17,29,29,19,19,31,19,19,31,19,19,31,19,19,31,19,19,31,31],[4,1,24,24,,24,24,,24,24,24,24,,24,24,,24,,24,24,,24,24,,24,24,24,24,,24,24,,24,24,24,24,,24,24,,24,24,24,24,,24,24,,36,,24,24,,24,24,,24,24,24,24,,24,24,,24,24],[7,-1,14,,14,14,26,14,14,26,14,,14,14,26,14,14,26,14,,14,14,26,14,14,26,14,,14,14,26,14,14,26,17,,17,17,29,17,17,29,17,,17,17,29,17,17,29,19,,19,19,31,19,19,31,19,,19,19,31,19,19,31],[2,1,,36,36,36,,36,36,36,,36,36,36,,36,36,36,,36,36,36,,36,36,36,,36,36,36,,36,,,,36,36,36,,36,36,36,,36,36,36,,36,36,36,,36,36,36,,36,36,36,,36,36,36,,36,,,],[3,1,,,,,25,,,,,,,,25,,,,,,,,25,,,,,,,,25,25,25,25,,,,,25,,,,,,,,25,,,,,,,,25,,,,,,,,25,25,25,25],[6,1,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,34,,,,,,34,,34,,,,,,,,34,,,,,,34,,34,,,,,,]]],[0,1,1,2,3,4,4]]);
166
166
  </script>
@@ -109,10 +109,13 @@ button:disabled
109
109
  background-color: #666;
110
110
  border-color: #666;
111
111
  }
112
+ input[type='checkbox']:disabled
113
+ {
114
+ opacity: 0.5;
115
+ }
112
116
  .error-line
113
117
  {
114
- background-color: rgba(255, 0, 0, 0.15) !important;
115
- border-left: 3px solid #ff0000 !important;
118
+ background-color: #f004 !important;
116
119
  }
117
120
 
118
121
  /* LittleJS CodeMirror Theme */
@@ -27,5 +27,5 @@ child_process.execSync(`npx tsc ${tsFiles} --outDir "./${BUILD_FOLDER}" --target
27
27
  console.log(`TypeScript built in ${((Date.now() - startTime)/1e3).toFixed(2)} seconds!`);
28
28
 
29
29
  console.log(`Moving js files back to root...`);
30
- for(const file of jsSourceFiles)
30
+ for (const file of jsSourceFiles)
31
31
  fs.copyFileSync(`${BUILD_FOLDER}/${file}`, file);
@@ -85,8 +85,8 @@ function gameUpdatePost() {
85
85
  }
86
86
  ///////////////////////////////////////////////////////////////////////////////
87
87
  function gameRender() {
88
- // draw a grey square in the background without using webgl
89
- LJS.drawRect(vec2(16, 8), vec2(20, 14), hsl(0, 0, .6), 0, false);
88
+ // draw a grey square in the background
89
+ LJS.drawRect(vec2(16, 8), vec2(20, 14), hsl(0, 0, .6));
90
90
  // draw the logo as a tile
91
91
  LJS.drawTile(vec2(21, 5), vec2(4.5), tile(3, 128));
92
92
  }
@@ -101,7 +101,10 @@ function gameUpdate()
101
101
 
102
102
  // move particles to mouse location if on screen
103
103
  if (LJS.mousePosScreen.x)
104
+ {
104
105
  particleEmitter.pos = LJS.mousePos;
106
+ particleEmitter.velocity = LJS.mouseDelta.scale(.3*LJS.timeDelta);
107
+ }
105
108
  }
106
109
 
107
110
  ///////////////////////////////////////////////////////////////////////////////
@@ -113,8 +116,8 @@ function gameUpdatePost()
113
116
  ///////////////////////////////////////////////////////////////////////////////
114
117
  function gameRender()
115
118
  {
116
- // draw a grey square in the background without using webgl
117
- LJS.drawRect(vec2(16,8), vec2(20,14), hsl(0,0,.6), 0, false);
119
+ // draw a grey square in the background
120
+ LJS.drawRect(vec2(16,8), vec2(20,14), hsl(0,0,.6));
118
121
 
119
122
  // draw the logo as a tile
120
123
  LJS.drawTile(vec2(21,5), vec2(4.5), tile(3,128));
@@ -23,6 +23,7 @@ function createUI()
23
23
  {
24
24
  LJS.uiSystem.defaultSoundPress = new LJS.Sound([1,0,220]);
25
25
  LJS.uiSystem.defaultSoundClick = new LJS.Sound([1,0,440]);
26
+ LJS.uiSystem.defaultCornerRadius = 8;
26
27
 
27
28
  // setup root to attach all ui elements to
28
29
  uiRoot = new LJS.UIObject;
@@ -110,7 +111,7 @@ function gameRender()
110
111
  {
111
112
  // test game rendering
112
113
  LJS.drawRect(vec2(), vec2(1e3), hsl(0,0,.2));
113
- for(let i=0; i<1e3; ++i)
114
+ for (let i=0; i<1e3; ++i)
114
115
  {
115
116
  const pos = vec2(30*Math.sin(i+LJS.time/9),20*Math.sin(i*i+LJS.time/9));
116
117
  LJS.drawTile(pos, vec2(2), tile(3,128), hsl(i/9,1,.4), LJS.time+i, !(i%2), hsl(i/9,1,.1,0));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "littlejsengine",
3
- "version": "1.13.1",
3
+ "version": "1.13.4",
4
4
  "description": "LittleJS - Tiny and Fast HTML5 Game Engine",
5
5
  "main": "dist/littlejs.esm.js",
6
6
  "types": "dist/littlejs.d.ts",
@@ -39,4 +39,4 @@
39
39
  "typescript": "~5.1.6",
40
40
  "uglify-js": "~3.17.4"
41
41
  }
42
- }
42
+ }
package/plugins/box2d.js CHANGED
@@ -61,7 +61,7 @@ class Box2dObject extends EngineObject
61
61
  bodyDef.set_angle(-angle);
62
62
  this.body = box2d.world.CreateBody(bodyDef);
63
63
  this.body.object = this;
64
- this.outlineColor = BLACK;
64
+ this.lineColor = BLACK;
65
65
  }
66
66
 
67
67
  /** Destroy this object and it's physics body */
@@ -88,7 +88,7 @@ class Box2dObject extends EngineObject
88
88
  if (this.tileInfo)
89
89
  super.render();
90
90
  else
91
- this.drawFixtures(this.color, this.outlineColor, this.lineWidth, mainContext);
91
+ this.drawFixtures(this.color, this.lineColor, this.lineWidth, mainContext);
92
92
  }
93
93
 
94
94
  /** Render debug info */
@@ -102,13 +102,13 @@ class Box2dObject extends EngineObject
102
102
 
103
103
  /** Draws all this object's fixtures
104
104
  * @param {Color} [color]
105
- * @param {Color} [outlineColor]
105
+ * @param {Color} [lineColor]
106
106
  * @param {number} [lineWidth]
107
107
  * @param {CanvasRenderingContext2D} [context] */
108
- drawFixtures(color=WHITE, outlineColor, lineWidth=.1, context)
108
+ drawFixtures(color=WHITE, lineColor, lineWidth=.1, context)
109
109
  {
110
110
  this.getFixtureList().forEach(fixture=>
111
- box2d.drawFixture(fixture, this.pos, this.angle, color, outlineColor, lineWidth, context));
111
+ box2d.drawFixture(fixture, this.pos, this.angle, color, lineColor, lineWidth, context));
112
112
  }
113
113
 
114
114
  ///////////////////////////////////////////////////////////////////////////////
@@ -1589,10 +1589,10 @@ class Box2dPlugin
1589
1589
  * @param {Vector2} pos
1590
1590
  * @param {number} angle
1591
1591
  * @param {Color} [color]
1592
- * @param {Color} [outlineColor]
1592
+ * @param {Color} [lineColor]
1593
1593
  * @param {number} [lineWidth]
1594
1594
  * @param {CanvasRenderingContext2D} [context] */
1595
- drawFixture(fixture, pos, angle, color=WHITE, outlineColor=BLACK, lineWidth=.1, context=drawContext)
1595
+ drawFixture(fixture, pos, angle, color=WHITE, lineColor=BLACK, lineWidth=.1, context=drawContext)
1596
1596
  {
1597
1597
  const shape = box2d.castObjectType(fixture.GetShape());
1598
1598
  switch (shape.GetType())
@@ -1602,101 +1602,25 @@ class Box2dPlugin
1602
1602
  let points = [];
1603
1603
  for (let i=shape.GetVertexCount(); i--;)
1604
1604
  points.push(box2d.vec2From(shape.GetVertex(i)));
1605
- box2d.drawPoly(pos, angle, points, color, outlineColor, lineWidth, context);
1605
+ drawPoly(points, color, lineWidth, lineColor, pos, angle, false, false, context);
1606
1606
  break;
1607
1607
  }
1608
1608
  case box2d.instance.b2Shape.e_circle:
1609
1609
  {
1610
1610
  const radius = shape.get_m_radius();
1611
- box2d.drawCircle(pos, radius, color, outlineColor, lineWidth, context);
1611
+ drawCircle(pos, radius, color, lineWidth, lineColor, false, false, context);
1612
1612
  break;
1613
1613
  }
1614
1614
  case box2d.instance.b2Shape.e_edge:
1615
1615
  {
1616
1616
  const v1 = box2d.vec2From(shape.get_m_vertex1());
1617
1617
  const v2 = box2d.vec2From(shape.get_m_vertex2());
1618
- box2d.drawLine(pos, angle, v1, v2, color, lineWidth, context);
1618
+ drawLine(v1, v2, lineWidth, lineColor, pos, angle, false, false, context);
1619
1619
  break;
1620
1620
  }
1621
1621
  }
1622
1622
  }
1623
1623
 
1624
- /** draws a circle
1625
- * @param {Vector2} pos
1626
- * @param {number} radius
1627
- * @param {Color} [color]
1628
- * @param {Color} [outlineColor]
1629
- * @param {number} [lineWidth]
1630
- * @param {CanvasRenderingContext2D} [context] */
1631
- drawCircle(pos, radius, color=WHITE, outlineColor=BLACK, lineWidth=.1, context=drawContext)
1632
- {
1633
- drawCanvas2D(pos, vec2(1), 0, 0, context=>
1634
- {
1635
- context.beginPath();
1636
- context.arc(0, 0, radius, 0, 9);
1637
- box2d.drawFillStroke(color, outlineColor, lineWidth, context);
1638
- }, 0, context);
1639
- }
1640
-
1641
- /** draws a polygon
1642
- * @param {Vector2} pos
1643
- * @param {number} angle
1644
- * @param {Array<Vector2>} points
1645
- * @param {Color} [color]
1646
- * @param {Color} [outlineColor]
1647
- * @param {number} [lineWidth]
1648
- * @param {CanvasRenderingContext2D} [context] */
1649
- drawPoly(pos, angle, points, color=WHITE, outlineColor=BLACK, lineWidth=.1, context=drawContext)
1650
- {
1651
- drawCanvas2D(pos, vec2(1), angle, 0, context=>
1652
- {
1653
- context.beginPath();
1654
- points.forEach(p=>context.lineTo(p.x, p.y));
1655
- context.closePath();
1656
- box2d.drawFillStroke(color, outlineColor, lineWidth, context);
1657
- }, 0, context);
1658
- }
1659
-
1660
- /** draws a line
1661
- * @param {Vector2} pos
1662
- * @param {number} angle
1663
- * @param {Vector2} posA
1664
- * @param {Vector2} posB
1665
- * @param {Color} [color]
1666
- * @param {number} [lineWidth]
1667
- * @param {CanvasRenderingContext2D} [context] */
1668
- drawLine(pos, angle, posA, posB, color=WHITE, lineWidth=.1, context=drawContext)
1669
- {
1670
- drawCanvas2D(pos, vec2(1), angle, 0, context=>
1671
- {
1672
- context.beginPath();
1673
- context.lineTo(posA.x, posA.y);
1674
- context.lineTo(posB.x, posB.y);
1675
- box2d.drawFillStroke(0, color, lineWidth, context);
1676
- }, 0, context);
1677
- }
1678
-
1679
- /** performs a fill or stroke as a helper to the other draw functions
1680
- * @param {Color} [color]
1681
- * @param {Color} [outlineColor]
1682
- * @param {number} [lineWidth]
1683
- * @param {CanvasRenderingContext2D} [context] */
1684
- drawFillStroke(color=WHITE, outlineColor=BLACK, lineWidth=.1, context=drawContext)
1685
- {
1686
- if (color)
1687
- {
1688
- context.fillStyle = color.toString();
1689
- context.fill();
1690
- }
1691
- if (outlineColor && lineWidth)
1692
- {
1693
- context.lineWidth = lineWidth;
1694
- context.lineJoin = context.lineCap = 'round';
1695
- context.strokeStyle = outlineColor.toString();
1696
- context.stroke();
1697
- }
1698
- }
1699
-
1700
1624
  ///////////////////////////////////////////////////////////////////////////////
1701
1625
  // helper functions
1702
1626
 
@@ -1797,6 +1721,7 @@ async function box2dInit()
1797
1721
  function setupDebugDraw()
1798
1722
  {
1799
1723
  // setup debug draw
1724
+ const debugLineWidth = .1;
1800
1725
  const debugDraw = new box2d.instance.JSDraw();
1801
1726
  const box2dColor = (c)=> new Color(c.get_r(), c.get_g(), c.get_b());
1802
1727
  const box2dColorPointer = (c)=>
@@ -1814,33 +1739,33 @@ async function box2dInit()
1814
1739
  color = getDebugColor(color);
1815
1740
  point1 = box2d.vec2FromPointer(point1);
1816
1741
  point2 = box2d.vec2FromPointer(point2);
1817
- box2d.drawLine(vec2(), 0, point1, point2, color, undefined, overlayContext);
1742
+ drawLine(point1, point2, debugLineWidth, color, vec2(), 0, false, false, overlayContext);
1818
1743
  };
1819
1744
  debugDraw.DrawPolygon = function(vertices, vertexCount, color)
1820
1745
  {
1821
1746
  color = getDebugColor(color);
1822
1747
  const points = getPointsList(vertices, vertexCount);
1823
- box2d.drawPoly(vec2(), 0, points, undefined, color, undefined, overlayContext);
1748
+ drawPoly(points, CLEAR_WHITE, debugLineWidth, color, vec2(), 0, false, false, overlayContext);
1824
1749
  };
1825
1750
  debugDraw.DrawSolidPolygon = function(vertices, vertexCount, color)
1826
1751
  {
1827
1752
  color = getDebugColor(color);
1828
1753
  const points = getPointsList(vertices, vertexCount);
1829
- box2d.drawPoly(vec2(), 0, points, color, color, undefined, overlayContext);
1754
+ drawPoly(points, color, 0, color, vec2(), 0, false, false, overlayContext);
1830
1755
  };
1831
1756
  debugDraw.DrawCircle = function(center, radius, color)
1832
1757
  {
1833
1758
  color = getDebugColor(color);
1834
1759
  center = box2d.vec2FromPointer(center);
1835
- box2d.drawCircle(center, radius, undefined, color, undefined, overlayContext);
1760
+ drawCircle(center, radius, CLEAR_WHITE, debugLineWidth, color, false, false, overlayContext);
1836
1761
  };
1837
1762
  debugDraw.DrawSolidCircle = function(center, radius, axis, color)
1838
1763
  {
1839
1764
  color = getDebugColor(color);
1840
1765
  center = box2d.vec2FromPointer(center);
1841
1766
  axis = box2d.vec2FromPointer(axis).scale(radius);
1842
- box2d.drawCircle(center, radius, color, color, undefined, overlayContext);
1843
- box2d.drawLine(center, 0, vec2(), axis, color, undefined, overlayContext);
1767
+ drawCircle(center, radius, color, debugLineWidth, color, false, false, overlayContext);
1768
+ drawLine(vec2(), axis, debugLineWidth, color, center, 0, false, false, overlayContext);
1844
1769
  };
1845
1770
  debugDraw.DrawTransform = function(transform)
1846
1771
  {
@@ -1849,8 +1774,8 @@ async function box2dInit()
1849
1774
  const angle = -transform.get_q().GetAngle();
1850
1775
  const p1 = vec2(1,0), c1 = rgb(.75,0,0,.8);
1851
1776
  const p2 = vec2(0,1), c2 = rgb(0,.75,0,.8);
1852
- box2d.drawLine(pos, angle, vec2(), p1, c1, undefined, overlayContext);
1853
- box2d.drawLine(pos, angle, vec2(), p2, c2, undefined, overlayContext);
1777
+ drawLine(vec2(), p1, debugLineWidth, c1, pos, angle, false, false, overlayContext);
1778
+ drawLine(vec2(), p2, debugLineWidth, c2, pos, angle, false, false, overlayContext);
1854
1779
  }
1855
1780
 
1856
1781
  debugDraw.AppendFlags(box2d.instance.b2Draw.e_shapeBit);