littlejsengine 1.11.13 → 1.12.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 (79) hide show
  1. package/dist/littlejs.d.ts +1418 -109
  2. package/dist/littlejs.esm.js +3495 -581
  3. package/dist/littlejs.esm.min.js +1 -1
  4. package/dist/littlejs.js +3258 -399
  5. package/dist/littlejs.min.js +1 -1
  6. package/dist/littlejs.release.js +3147 -379
  7. package/examples/box2d/game.js +73 -45
  8. package/examples/box2d/gameObjects.js +96 -92
  9. package/examples/box2d/index.html +2 -7
  10. package/examples/box2d/scenes.js +82 -92
  11. package/examples/breakout/game.js +62 -30
  12. package/examples/breakout/gameObjects.js +45 -47
  13. package/examples/breakout/index.html +1 -5
  14. package/examples/breakoutTutorial/game.js +36 -29
  15. package/examples/breakoutTutorial/index.html +1 -3
  16. package/examples/empty/game.js +5 -2
  17. package/examples/empty/index.html +1 -3
  18. package/examples/htmlMenu/game.js +25 -19
  19. package/examples/htmlMenu/index.html +5 -7
  20. package/examples/index.html +2 -3
  21. package/examples/module/game.js +32 -34
  22. package/examples/module/index.html +1 -1
  23. package/examples/particles/index.html +27 -22
  24. package/examples/platformer/game.js +71 -48
  25. package/examples/platformer/gameCharacter.js +42 -34
  26. package/examples/platformer/gameEffects.js +82 -75
  27. package/examples/platformer/gameLevel.js +67 -38
  28. package/examples/platformer/{gameLevelData.js → gameLevelData.json} +1 -11
  29. package/examples/platformer/gameObjects.js +70 -64
  30. package/examples/platformer/gamePlayer.js +12 -7
  31. package/examples/platformer/index.html +1 -9
  32. package/examples/puzzle/game.js +58 -42
  33. package/examples/puzzle/index.html +1 -3
  34. package/examples/shorts/base.html +2 -2
  35. package/examples/shorts/particles.js +1 -1
  36. package/examples/shorts/platformer.js +1 -1
  37. package/examples/shorts/tileLayer.js +5 -6
  38. package/examples/shorts/tiles.png +0 -0
  39. package/examples/starter/build.js +4 -4
  40. package/examples/starter/game.js +9 -12
  41. package/examples/starter/index.html +13 -13
  42. package/examples/stress/index.html +44 -43
  43. package/examples/typescript/build.js +17 -18
  44. package/examples/typescript/game.js +32 -34
  45. package/examples/typescript/game.ts +32 -34
  46. package/examples/typescript/index.html +1 -1
  47. package/examples/uiSystem/game.js +33 -36
  48. package/examples/uiSystem/index.html +1 -5
  49. package/package.json +3 -3
  50. package/plugins/box2d.js +1556 -640
  51. package/plugins/{Box2D_v2.3.1_min.wasm.js → box2d.wasm.js} +1 -1
  52. package/plugins/newgrounds.js +7 -8
  53. package/plugins/pluginExport.js +50 -0
  54. package/plugins/postProcess.js +94 -93
  55. package/plugins/uiSystem.js +145 -161
  56. package/plugins/zzfxm.js +163 -0
  57. package/reference.md +29 -27
  58. package/src/engine.js +15 -20
  59. package/src/engineAudio.js +74 -204
  60. package/src/engineBuild.js +29 -4
  61. package/src/engineDebug.js +105 -9
  62. package/src/engineDraw.js +27 -14
  63. package/src/engineExport.js +12 -8
  64. package/src/engineInput.js +3 -1
  65. package/src/engineObject.js +18 -14
  66. package/src/engineParticles.js +6 -1
  67. package/src/engineRelease.js +6 -1
  68. package/src/engineSettings.js +8 -8
  69. package/src/engineTileLayer.js +179 -96
  70. package/src/engineUtilities.js +5 -11
  71. package/src/engineWebGL.js +19 -7
  72. package/examples/starter/build/index.html +0 -2
  73. package/examples/starter/build/index.js +0 -1
  74. package/examples/starter/build/tiles.png +0 -0
  75. package/examples/starter/game.zip +0 -0
  76. package/examples/typescript/build/dist/littlejs.esm.js +0 -4834
  77. package/examples/typescript/build/examples/typescript/build.js +0 -24
  78. package/examples/typescript/build/examples/typescript/game.js +0 -102
  79. /package/plugins/{Box2D_v2.3.1_min.wasm.wasm → box2d.wasm.wasm} +0 -0
@@ -7,22 +7,26 @@
7
7
 
8
8
  'use strict';
9
9
 
10
+ // import LittleJS module
11
+ import * as LJS from '../../dist/littlejs.esm.js';
12
+ const {vec2, rgb} = LJS;
13
+
10
14
  ///////////////////////////////////////////////////////////////////////////////
11
15
 
12
16
  // globals
13
17
  const levelSize = vec2(38, 20); // size of play area
14
18
  let score = 0; // start score at 0
15
19
  let ball; // keep track of ball object
16
- let paddle; // keep track of player's paddle
20
+ let paddle; // keep track of player paddle
17
21
 
18
22
  // sound effects
19
- const sound_bounce = new Sound([,,1e3,,.03,.02,1,2,,,940,.03,,,,,.2,.6,,.06], 0);
20
- const sound_break = new Sound([,,90,,.01,.03,4,,,,,,,9,50,.2,,.2,.01], 0);
21
- const sound_start = new Sound([,0,500,,.04,.3,1,2,,,570,.02,.02,,,,.04]);
23
+ const sound_bounce = new LJS.Sound([,,1e3,,.03,.02,1,2,,,940,.03,,,,,.2,.6,,.06], 0);
24
+ const sound_break = new LJS.Sound([,,90,,.01,.03,4,,,,,,,9,50,.2,,.2,.01], 0);
25
+ const sound_start = new LJS.Sound([,0,500,,.04,.3,1,2,,,570,.02,.02,,,,.04]);
22
26
 
23
27
  ///////////////////////////////////////////////////////////////////////////////
24
28
 
25
- class Paddle extends EngineObject
29
+ class Paddle extends LJS.EngineObject
26
30
  {
27
31
  constructor()
28
32
  {
@@ -33,14 +37,14 @@ class Paddle extends EngineObject
33
37
 
34
38
  update()
35
39
  {
36
- this.pos.x = mousePos.x; // move paddle to mouse
40
+ this.pos.x = LJS.mousePos.x; // move paddle to mouse
37
41
 
38
42
  // clamp paddle to level size
39
- this.pos.x = clamp(this.pos.x, this.size.x/2, levelSize.x - this.size.x/2);
43
+ this.pos.x = LJS.clamp(this.pos.x, this.size.x/2, levelSize.x - this.size.x/2);
40
44
  }
41
45
  }
42
46
 
43
- class Ball extends EngineObject
47
+ class Ball extends LJS.EngineObject
44
48
  {
45
49
  constructor(pos)
46
50
  {
@@ -57,7 +61,7 @@ class Ball extends EngineObject
57
61
  return false;
58
62
 
59
63
  // speed up
60
- const speed = min(1.04*this.velocity.length(), .5);
64
+ const speed = LJS.min(1.04*this.velocity.length(), .5);
61
65
  this.velocity = this.velocity.normalize(speed);
62
66
 
63
67
  // play bounce sound with pitch scaled by speed
@@ -70,7 +74,7 @@ class Ball extends EngineObject
70
74
  this.velocity = this.velocity.rotate(.3 * deltaX);
71
75
 
72
76
  // make sure ball is moving upwards with a minimum speed
73
- this.velocity.y = max(-this.velocity.y, .2);
77
+ this.velocity.y = LJS.max(-this.velocity.y, .2);
74
78
 
75
79
  // prevent default collision code
76
80
  return false;
@@ -80,7 +84,7 @@ class Ball extends EngineObject
80
84
  }
81
85
  }
82
86
 
83
- class Wall extends EngineObject
87
+ class Wall extends LJS.EngineObject
84
88
  {
85
89
  constructor(pos, size)
86
90
  {
@@ -88,11 +92,11 @@ class Wall extends EngineObject
88
92
 
89
93
  this.setCollision(); // make object collide
90
94
  this.mass = 0; // make object have static physics
91
- this.color = new Color(0,0,0,0); // make object invisible
95
+ this.color = rgb(0,0,0,0); // make object invisible
92
96
  }
93
97
  }
94
98
 
95
- class Brick extends EngineObject
99
+ class Brick extends LJS.EngineObject
96
100
  {
97
101
  constructor(pos, size)
98
102
  {
@@ -100,7 +104,7 @@ class Brick extends EngineObject
100
104
 
101
105
  this.setCollision(); // make object collide
102
106
  this.mass = 0; // make object have static physics
103
- this.color = randColor(); // give brick a random color
107
+ this.color = LJS.randColor(); // give brick a random color
104
108
  }
105
109
 
106
110
  collideWithObject(o)
@@ -111,14 +115,14 @@ class Brick extends EngineObject
111
115
 
112
116
  // create explosion effect
113
117
  const color = this.color;
114
- new ParticleEmitter(
115
- this.pos, 0, // pos, angle
116
- this.size, .1, 200, PI, // emitSize, emitTime, emitRate, emitCone
117
- undefined, // tileInfo
118
+ new LJS.ParticleEmitter(
119
+ this.pos, 0, // pos, angle
120
+ this.size, .1, 200, 3.14,// emitSize, emitTime, emitRate, emitCone
121
+ undefined, // tileInfo
118
122
  color, color, // colorStartA, colorStartB
119
123
  color.scale(1,0), color.scale(1,0), // colorEndA, colorEndB
120
124
  .2, .5, 1, .1, .1, // time, sizeStart, sizeEnd, speed, angleSpeed
121
- .99, .95, .4, PI, // damp, angleDamp, gravity, cone
125
+ .99, .95, .4, 3.14, // damp, angleDamp, gravity, cone
122
126
  .1, .5, false, true // fade, randomness, collide, additive
123
127
  );
124
128
 
@@ -129,15 +133,17 @@ class Brick extends EngineObject
129
133
  ///////////////////////////////////////////////////////////////////////////////
130
134
  function gameInit()
131
135
  {
136
+ // setup camera and canvas
137
+ LJS.setCameraPos(levelSize.scale(.5)); // center camera in level
138
+ LJS.setCanvasFixedSize(vec2(1280, 720)); // use a 720p fixed size canvas
139
+
132
140
  // create bricks
133
141
  for(let x=2; x<=levelSize.x-2; x+=2)
134
142
  for(let y=12; y<=levelSize.y-2; y+=1)
135
143
  new Brick(vec2(x,y), vec2(2,1)); // create a brick
136
144
 
137
- cameraPos = levelSize.scale(.5); // center camera in level
138
- canvasFixedSize = vec2(1280, 720); // use a 720p fixed size canvas
139
-
140
- paddle = new Paddle; // create player's paddle
145
+ // create player paddle
146
+ paddle = new Paddle;
141
147
 
142
148
  // create walls
143
149
  new Wall(vec2(-.5,levelSize.y/2), vec2(1,100)) // top
@@ -154,9 +160,10 @@ function gameUpdate()
154
160
  ball.destroy();
155
161
  ball = 0;
156
162
  }
157
- if (!ball && mouseWasPressed(0)) // if there is no ball and left mouse is pressed
163
+ if (!ball && LJS.mouseWasPressed(0))
158
164
  {
159
- ball = new Ball(cameraPos); // create a ball
165
+ // spawn new ball if there is no ball and left mouse pressed
166
+ ball = new Ball(LJS.cameraPos); // create a ball
160
167
  sound_start.play(); // play start sound
161
168
  }
162
169
  }
@@ -169,16 +176,16 @@ function gameUpdatePost()
169
176
  ///////////////////////////////////////////////////////////////////////////////
170
177
  function gameRender()
171
178
  {
172
- drawRect(cameraPos, vec2(100), new Color(.5,.5,.5)); // draw background
173
- drawRect(cameraPos, levelSize, new Color(.1,.1,.1)); // draw level boundary
179
+ LJS.drawRect(LJS.cameraPos, vec2(100), rgb(.5,.5,.5)); // draw background
180
+ LJS.drawRect(LJS.cameraPos, levelSize, rgb(.1,.1,.1)); // draw level boundary
174
181
  }
175
182
 
176
183
  ///////////////////////////////////////////////////////////////////////////////
177
184
  function gameRenderPost()
178
185
  {
179
- drawTextScreen("Score " + score, vec2(mainCanvasSize.x/2, 70), 50); // show score
186
+ LJS.drawTextScreen("Score " + score, vec2(LJS.mainCanvasSize.x/2, 70), 50); // show score
180
187
  }
181
188
 
182
189
  ///////////////////////////////////////////////////////////////////////////////
183
190
  // Startup LittleJS Engine
184
- engineInit(gameInit, gameUpdate, gameUpdatePost, gameRender, gameRenderPost);
191
+ LJS.engineInit(gameInit, gameUpdate, gameUpdatePost, gameRender, gameRenderPost);
@@ -5,6 +5,4 @@
5
5
  <meta name=mobile-web-app-capable content=yes>
6
6
  <link rel=icon type=image/png href=../favicon.png>
7
7
  </head><body>
8
-
9
- <script src=../../dist/littlejs.js?1117></script>
10
- <script src=game.js?1117></script>
8
+ <script src=game.js type=module></script>
@@ -6,6 +6,9 @@
6
6
 
7
7
  'use strict';
8
8
 
9
+ // import LittleJS module
10
+ import * as LJS from '../../dist/littlejs.esm.js';
11
+
9
12
  ///////////////////////////////////////////////////////////////////////////////
10
13
  function gameInit()
11
14
  {
@@ -39,9 +42,9 @@ function gameRenderPost()
39
42
  {
40
43
  // called after objects are rendered
41
44
  // draw effects or hud that appear above all objects
42
- drawTextScreen('Hello World!', mainCanvasSize.scale(.5), 80);
45
+ LJS.drawTextScreen('Hello World!', LJS.mainCanvasSize.scale(.5), 80);
43
46
  }
44
47
 
45
48
  ///////////////////////////////////////////////////////////////////////////////
46
49
  // Startup LittleJS Engine
47
- engineInit(gameInit, gameUpdate, gameUpdatePost, gameRender, gameRenderPost, ['tiles.png']);
50
+ LJS.engineInit(gameInit, gameUpdate, gameUpdatePost, gameRender, gameRenderPost, ['tiles.png']);
@@ -2,6 +2,4 @@
2
2
  <title>LittleJS Hello World Demo</title>
3
3
  <meta charset=utf-8>
4
4
  </head><body>
5
-
6
- <script src=../../dist/littlejs.js></script>
7
- <script src=game.js></script>
5
+ <script src=game.js type=module></script>
@@ -1,18 +1,19 @@
1
1
  /*
2
2
  Little JS HTML Menu Example Project
3
3
  - Setup a simple html menu system
4
- - Menu can be toggled
4
+ - Menu can be opened and closed
5
5
  - Pauses game when menu is visible
6
6
  - Shows several input types
7
7
  */
8
8
 
9
9
  'use strict';
10
10
 
11
- // show the LittleJS splash screen
12
- setShowSplashScreen(true);
11
+ // import LittleJS module
12
+ import * as LJS from '../../dist/littlejs.esm.js';
13
+ const {vec2, hsl, tile} = LJS;
13
14
 
14
15
  // sound effects
15
- const sound_click = new Sound([1,.5]);
16
+ const sound_click = new LJS.Sound([1,.5]);
16
17
 
17
18
  ///////////////////////////////////////////////////////////////////////////////
18
19
 
@@ -21,12 +22,17 @@ const getMenuVisible = ()=> menu.style.visibility != 'hidden';
21
22
  function setMenuVisible(visible)
22
23
  {
23
24
  menu.style.visibility = visible ? 'visible' : 'hidden';
24
- setInputPreventDefault(!visible); // don't prevent default when menu is visible
25
+ LJS.setInputPreventDefault(!visible); // don't prevent default when menu is visible
25
26
  }
26
27
 
27
28
  ///////////////////////////////////////////////////////////////////////////////
28
29
  function gameInit()
29
30
  {
31
+ button_test.onclick = function() { alert('Button was clicked!'); }
32
+ button_exitMenu.onclick = function() { setMenuVisible(false); }
33
+ input_test.onchange = function() { alert('New text: ' + this.value); }
34
+ input_rangeTest.onchange = function() { alert('New value: ' + this.value); }
35
+
30
36
  // show menu for demo
31
37
  setMenuVisible(true);
32
38
  }
@@ -35,31 +41,31 @@ function gameInit()
35
41
  function gameUpdate()
36
42
  {
37
43
  // play sound when mouse is pressed
38
- if (mouseWasPressed(0))
39
- sound_click.play(mousePos);
44
+ if (LJS.mouseWasPressed(0))
45
+ sound_click.play(LJS.mousePos);
40
46
  }
41
47
 
42
48
  ///////////////////////////////////////////////////////////////////////////////
43
49
  function gameUpdatePost()
44
50
  {
45
- // pause game when menu is visible
46
- const menuVisible = getMenuVisible();
47
- paused = menuVisible;
48
-
49
- // toggle menu visibility
50
- if (keyWasPressed('KeyM'))
51
+ // open menu visibility
52
+ if (LJS.keyWasPressed('KeyM'))
51
53
  setMenuVisible(true);
54
+
55
+ // pause game when menu is visible
56
+ LJS.setPaused(getMenuVisible());
52
57
  }
53
58
 
54
59
  ///////////////////////////////////////////////////////////////////////////////
55
60
  function gameRender()
56
61
  {
57
62
  // test game rendering
58
- drawRect(vec2(), vec2(1e3), hsl(0,0,.2));
63
+ LJS.drawRect(vec2(), vec2(1e3), hsl(0,0,.2));
59
64
  for(let i=0; i<1e3; ++i)
60
65
  {
66
+ const time = LJS.time;
61
67
  const pos = vec2(30*Math.sin(i+time/9),20*Math.sin(i*i+time/9));
62
- drawTile(pos, vec2(2), tile(3,128), hsl(i/9,1,.4), time+i, !(i%2), hsl(i/9,1,.1,0));
68
+ LJS.drawTile(pos, vec2(2), tile(3,128), hsl(i/9,1,.4), time+i, !(i%2), hsl(i/9,1,.1,0));
63
69
  }
64
70
  }
65
71
 
@@ -67,11 +73,11 @@ function gameRender()
67
73
  function gameRenderPost()
68
74
  {
69
75
  // draw to overlay canvas for hud rendering
70
- drawTextScreen('LittleJS HTML Menu Example\nM = Toggle menu',
71
- vec2(mainCanvasSize.x/2, 70), 60, // position, size
72
- hsl(0,0,1), 6, hsl(0,0,0)); // color, outline size and color
76
+ LJS.drawTextScreen('LittleJS HTML Menu Example\nM = Open menu',
77
+ vec2(LJS.mainCanvasSize.x/2, 70), 60, // position, size
78
+ hsl(0,0,1), 6, hsl(0,0,0)); // color, outline size and color
73
79
  }
74
80
 
75
81
  ///////////////////////////////////////////////////////////////////////////////
76
82
  // Startup LittleJS Engine
77
- engineInit(gameInit, gameUpdate, gameUpdatePost, gameRender, gameRenderPost, ['tiles.png']);
83
+ LJS.engineInit(gameInit, gameUpdate, gameUpdatePost, gameRender, gameRenderPost, ['tiles.png']);
@@ -27,7 +27,6 @@
27
27
  visibility: hidden;
28
28
  }
29
29
  </style>
30
-
31
30
  </head><body>
32
31
 
33
32
  <!-- setup html menu system -->
@@ -35,13 +34,12 @@
35
34
  <div id="menu" class="menuDiv">
36
35
  <b style="font-size:50px">Test Menu</b>
37
36
  This is an example menu using html elements.
38
- <input value="Test Input" onchange="alert('New text: ' + this.value)">
39
- <input type="range" onchange="alert('New value: ' + this.value)">
40
- <button onclick="alert('Button was clicked!')">Test Button</button>
41
- <button onclick="setMenuVisible(false)">Exit Menu</button>
37
+ <input id="input_test" value="Test Input">
38
+ <input id="input_rangeTest" type="range">
39
+ <button id="button_test">Test Button</button>
40
+ <button id="button_exitMenu">Exit Menu</button>
42
41
  </div>
43
42
  </div>
44
43
 
45
44
  <!-- Add your game scripts here -->
46
- <script src=../../dist/littlejs.js?1117></script>
47
- <script src=game.js?1117></script>
45
+ <script src=game.js type=module></script>
@@ -163,9 +163,8 @@ for (const example of exampleList)
163
163
  selectExample.add(o);
164
164
  }
165
165
 
166
- // select first option
166
+ // set the selected example from the URL hash
167
167
  selectExample.selectedIndex = location.hash.split`#`[1] | 0
168
-
169
168
  setExample();
170
169
 
171
170
  onresize = () =>
@@ -305,4 +304,4 @@ function setErrorMessage(message='')
305
304
 
306
305
  </script>
307
306
  </body>
308
- </html>
307
+ </html>
@@ -6,22 +6,22 @@
6
6
 
7
7
  'use strict';
8
8
 
9
- // import module
10
- import * as LittleJS from '../../dist/littlejs.esm.js';
11
- const {tile, vec2, hsl} = LittleJS;
9
+ // import LittleJS module
10
+ import * as LJS from '../../dist/littlejs.esm.js';
11
+ const {tile, vec2, hsl} = LJS;
12
12
 
13
13
  // show the LittleJS splash screen
14
- LittleJS.setShowSplashScreen(true);
14
+ LJS.setShowSplashScreen(true);
15
15
 
16
16
  // fix texture bleeding by shrinking tile slightly
17
- LittleJS.setTileFixBleedScale(.5);
17
+ LJS.setTileFixBleedScale(.5);
18
18
 
19
19
  // sound effects
20
- const sound_click = new LittleJS.Sound([1,.5]);
20
+ const sound_click = new LJS.Sound([1,.5]);
21
21
 
22
22
  // medals
23
- const medal_example = new LittleJS.Medal(0, 'Example Medal', 'Welcome to LittleJS!');
24
- LittleJS.medalsInit('Hello World');
23
+ const medal_example = new LJS.Medal(0, 'Example Medal', 'Welcome to LittleJS!');
24
+ LJS.medalsInit('Hello World');
25
25
 
26
26
  // game variables
27
27
  let particleEmitter;
@@ -30,46 +30,44 @@ let particleEmitter;
30
30
  function gameInit()
31
31
  {
32
32
  // create tile collision and visible tile layer
33
- const tileCollisionSize = vec2(32, 16);
34
- LittleJS.initTileCollision(tileCollisionSize);
35
33
  const pos = vec2();
36
- const tileLayer = new LittleJS.TileLayer(pos, tileCollisionSize);
34
+ const tileLayer = new LJS.TileCollisionLayer(pos, vec2(32,16));
37
35
 
38
36
  // get level data from the tiles image
39
- const mainContext = LittleJS.mainContext;
40
- const tileImage = LittleJS.textureInfos[0].image;
37
+ const mainContext = LJS.mainContext;
38
+ const tileImage = LJS.textureInfos[0].image;
41
39
  mainContext.drawImage(tileImage, 0, 0);
42
40
  const imageData = mainContext.getImageData(0,0,tileImage.width,tileImage.height).data;
43
- for (pos.x = tileCollisionSize.x; pos.x--;)
44
- for (pos.y = tileCollisionSize.y; pos.y--;)
41
+ for (pos.x = tileLayer.size.x; pos.x--;)
42
+ for (pos.y = tileLayer.size.y; pos.y--;)
45
43
  {
46
44
  // check if this pixel is set
47
- const i = pos.x + tileImage.width*(15 + tileCollisionSize.y - pos.y);
45
+ const i = pos.x + tileImage.width*(15 + tileLayer.size.y - pos.y);
48
46
  if (!imageData[4*i])
49
47
  continue;
50
48
 
51
49
  // set tile data
52
50
  const tileIndex = 1;
53
- const direction = LittleJS.randInt(4)
54
- const mirror = !LittleJS.randInt(2);
55
- const color = LittleJS.randColor();
56
- const data = new LittleJS.TileLayerData(tileIndex, direction, mirror, color);
51
+ const direction = LJS.randInt(4)
52
+ const mirror = !LJS.randInt(2);
53
+ const color = LJS.randColor();
54
+ const data = new LJS.TileLayerData(tileIndex, direction, mirror, color);
57
55
  tileLayer.setData(pos, data);
58
- LittleJS.setTileCollisionData(pos, 1);
56
+ tileLayer.setCollisionData(pos);
59
57
  }
60
58
 
61
59
  // draw tile layer with new data
62
60
  tileLayer.redraw();
63
61
 
64
62
  // move camera to center of collision
65
- LittleJS.setCameraPos(tileCollisionSize.scale(.5));
66
- LittleJS.setCameraScale(32);
63
+ LJS.setCameraPos(tileLayer.size.scale(.5));
64
+ LJS.setCameraScale(32);
67
65
 
68
66
  // enable gravity
69
- LittleJS.setGravity(-.01);
67
+ LJS.setGravity(vec2(0,-.01));
70
68
 
71
69
  // create particle emitter
72
- particleEmitter = new LittleJS.ParticleEmitter(
70
+ particleEmitter = new LJS.ParticleEmitter(
73
71
  vec2(16,9), 0, // emitPos, emitAngle
74
72
  1, 0, 500, Math.PI, // emitSize, emitTime, emitRate, emitCone
75
73
  tile(0, 16), // tileIndex, tileSize
@@ -86,14 +84,14 @@ function gameInit()
86
84
  ///////////////////////////////////////////////////////////////////////////////
87
85
  function gameUpdate()
88
86
  {
89
- if (LittleJS.mouseWasPressed(0))
87
+ if (LJS.mouseWasPressed(0))
90
88
  {
91
89
  // play sound when mouse is pressed
92
- sound_click.play(LittleJS.mousePos);
90
+ sound_click.play(LJS.mousePos);
93
91
 
94
92
  // change particle color and set to fade out
95
93
  particleEmitter.colorStartA = hsl();
96
- particleEmitter.colorStartB = LittleJS.randColor();
94
+ particleEmitter.colorStartB = LJS.randColor();
97
95
  particleEmitter.colorEndA = particleEmitter.colorStartA.scale(1,0);
98
96
  particleEmitter.colorEndB = particleEmitter.colorStartB.scale(1,0);
99
97
 
@@ -102,8 +100,8 @@ function gameUpdate()
102
100
  }
103
101
 
104
102
  // move particles to mouse location if on screen
105
- if (LittleJS.mousePosScreen.x)
106
- particleEmitter.pos = LittleJS.mousePos;
103
+ if (LJS.mousePosScreen.x)
104
+ particleEmitter.pos = LJS.mousePos;
107
105
  }
108
106
 
109
107
  ///////////////////////////////////////////////////////////////////////////////
@@ -116,19 +114,19 @@ function gameUpdatePost()
116
114
  function gameRender()
117
115
  {
118
116
  // draw a grey square in the background without using webgl
119
- LittleJS.drawRect(vec2(16,8), vec2(20,14), hsl(0,0,.6), 0, false);
117
+ LJS.drawRect(vec2(16,8), vec2(20,14), hsl(0,0,.6), 0, false);
120
118
 
121
119
  // draw the logo as a tile
122
- LittleJS.drawTile(vec2(21,5), vec2(4.5), tile(3,128));
120
+ LJS.drawTile(vec2(21,5), vec2(4.5), tile(3,128));
123
121
  }
124
122
 
125
123
  ///////////////////////////////////////////////////////////////////////////////
126
124
  function gameRenderPost()
127
125
  {
128
126
  // draw to overlay canvas for hud rendering
129
- LittleJS.drawTextScreen('LittleJS with Modules', vec2(LittleJS.mainCanvasSize.x/2, 80), 80);
127
+ LJS.drawTextScreen('LittleJS with Modules', vec2(LJS.mainCanvasSize.x/2, 80), 80);
130
128
  }
131
129
 
132
130
  ///////////////////////////////////////////////////////////////////////////////
133
131
  // Startup LittleJS Engine
134
- LittleJS.engineInit(gameInit, gameUpdate, gameUpdatePost, gameRender, gameRenderPost, ['tiles.png']);
132
+ LJS.engineInit(gameInit, gameUpdate, gameUpdatePost, gameRender, gameRenderPost, ['tiles.png']);
@@ -7,4 +7,4 @@
7
7
  </head><body>
8
8
 
9
9
  <!-- Add your game scripts here -->
10
- <script src=game.js?1117 type=module></script>
10
+ <script src=game.js type=module></script>
@@ -9,18 +9,20 @@ input { width:99px; }
9
9
  button { margin:1px; }
10
10
  </style>
11
11
  </head><body>
12
+ <script type=module>
12
13
 
13
- <script src=../../dist/littlejs.js?1117></script>
14
- <script>
14
+ // import LittleJS module
15
+ import * as LJS from '../../dist/littlejs.esm.js';
16
+ const {vec2} = LJS;
15
17
 
16
18
  'use strict';
17
19
 
18
20
  // fix texture bleeding by shrinking tiles slightly
19
- tileFixBleedScale = .5;
21
+ LJS.setTileFixBleedScale(.5);
20
22
 
21
23
  let particleEditor = 0, particleSystem, particleSystemDiv, particleSystemCode;
22
24
  let inputExpand;
23
- let restartTimer = new Timer();
25
+ let restartTimer = new LJS.Timer();
24
26
  const storagePrefix = 'particles_';
25
27
 
26
28
  const particleSettings = [];
@@ -62,8 +64,8 @@ function makeEmitter()
62
64
  {
63
65
  if (particleSystem)
64
66
  particleSystem.destroy();
65
- particleSystem = new ParticleEmitter(cameraPos);
66
- particleSystem.tileInfo = tile();
67
+ particleSystem = new LJS.ParticleEmitter(LJS.cameraPos);
68
+ particleSystem.tileInfo = LJS.tile();
67
69
  particleSystem.emitConeAngle =
68
70
  particleSystem.particleConeAngle = 3.14;
69
71
  }
@@ -72,8 +74,8 @@ function makeEmitter()
72
74
  function gameInit()
73
75
  {
74
76
  makeEmitter();
75
- gravity = -.01;
76
- cameraScale = 64;
77
+ LJS.setGravity(vec2(0,-.01));
78
+ LJS.setCameraScale(64);
77
79
 
78
80
  const div = particleSystemDiv = document.createElement('div');
79
81
  div.innerHTML = '<big><b>LittleJS Particle Tool';
@@ -164,7 +166,7 @@ function gameInit()
164
166
  return;
165
167
  makeEmitter();
166
168
  updateInputs();
167
- cameraScale = 50;
169
+ LJS.setCameraScale(50);
168
170
  }
169
171
  }
170
172
  {
@@ -214,7 +216,7 @@ function updateParticles(shouldUpdateInput)
214
216
  const inputFloat = parseFloat(input.value) || 0;
215
217
  if (type == 'color')
216
218
  {
217
- const color = new Color().setHex(input.value);
219
+ const color = new LJS.Color().setHex(input.value);
218
220
  particleSystem[name].r = color.r;
219
221
  particleSystem[name].g = color.g;
220
222
  particleSystem[name].b = color.b;
@@ -222,28 +224,28 @@ function updateParticles(shouldUpdateInput)
222
224
  else if (type == 'alpha')
223
225
  {
224
226
  if (name == 'colorStartA_alpha')
225
- particleSystem.colorStartA.a = clamp(inputFloat);
227
+ particleSystem.colorStartA.a = LJS.clamp(inputFloat);
226
228
  else if (name == 'colorStartB_alpha')
227
- particleSystem.colorStartB.a = clamp(inputFloat);
229
+ particleSystem.colorStartB.a = LJS.clamp(inputFloat);
228
230
  else if (name == 'colorEndA_alpha')
229
- particleSystem.colorEndA.a = clamp(inputFloat);
231
+ particleSystem.colorEndA.a = LJS.clamp(inputFloat);
230
232
  else if (name == 'colorEndB_alpha')
231
- particleSystem.colorEndB.a = clamp(inputFloat);
233
+ particleSystem.colorEndB.a = LJS.clamp(inputFloat);
232
234
  }
233
235
  else if (name == 'tileIndex')
234
236
  {
235
237
  const tileIndex = parseInt(input.value);
236
238
  particleSystem.tileIndex = tileIndex
237
- particleSystem.tileInfo = tile(tileIndex, particleSystem.tileInfo.size);
239
+ particleSystem.tileInfo = LJS.tile(tileIndex, particleSystem.tileInfo.size);
238
240
  }
239
241
  else if (name == 'tileSize')
240
242
  particleSystem.tileInfo.size = vec2(parseInt(input.value));
241
243
  else if (type == 'checkbox')
242
244
  particleSystem[name] = input.checked ? 1 : 0;
243
245
  else if (name == 'emitRate')
244
- particleSystem[name] = min(inputFloat,1e3);
246
+ particleSystem[name] = LJS.min(inputFloat,1e4);
245
247
  else
246
- particleSystem[name] = clamp(inputFloat, setting.min, setting.max);
248
+ particleSystem[name] = LJS.clamp(inputFloat, setting.min, setting.max);
247
249
  }
248
250
  shouldUpdateInput && updateInputs()
249
251
  }
@@ -367,11 +369,14 @@ function gameUpdate()
367
369
 
368
370
  if (document.activeElement == document.body)
369
371
  {
370
- particleSystem.pos = mouseIsDown(0) ? mousePos : vec2();
371
- if (mouseWheel)
372
+ particleSystem.pos = LJS.mouseIsDown(0) ? LJS.mousePos : vec2();
373
+ if (LJS.mouseWheel)
372
374
  {
373
- cameraScale -= sign(mouseWheel)*cameraScale/5;
374
- cameraScale = clamp(cameraScale, 10, 300);
375
+ // zoom camera
376
+ let cameraScale = LJS.cameraScale;
377
+ cameraScale -= LJS.sign(LJS.mouseWheel)*cameraScale/5;
378
+ cameraScale = LJS.clamp(cameraScale, 10, 300);
379
+ LJS.setCameraScale(cameraScale);
375
380
  }
376
381
  }
377
382
  }
@@ -394,6 +399,6 @@ function gameRenderPost()
394
399
 
395
400
  ///////////////////////////////////////////////////////////////////////////////
396
401
  // Startup LittleJS Engine
397
- engineInit(gameInit, gameUpdate, gameUpdatePost, gameRender, gameRenderPost, ['tiles.png']);
402
+ LJS.engineInit(gameInit, gameUpdate, gameUpdatePost, gameRender, gameRenderPost, ['tiles.png']);
398
403
 
399
404
  </script>