littlejsengine 1.7.21 → 1.8.3

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 (52) hide show
  1. package/README.md +28 -55
  2. package/build/littlejs.d.ts +595 -552
  3. package/build/littlejs.esm.js +626 -535
  4. package/build/littlejs.esm.min.js +1 -1
  5. package/build/littlejs.js +542 -264
  6. package/build/littlejs.min.js +1 -1
  7. package/build/littlejs.release.js +542 -264
  8. package/examples/breakout/game.js +17 -14
  9. package/examples/breakout/gameObjects.js +29 -8
  10. package/examples/breakout/index.html +3 -3
  11. package/examples/breakoutTutorial/README.md +3 -3
  12. package/examples/breakoutTutorial/game.js +4 -4
  13. package/examples/breakoutTutorial/index.html +2 -2
  14. package/examples/electron/game.js +3 -2
  15. package/examples/electron/index.html +2 -2
  16. package/examples/empty/game.js +1 -1
  17. package/examples/favicon.png +0 -0
  18. package/examples/js13k/game.js +20 -15
  19. package/examples/js13k/index.html +14 -14
  20. package/examples/module/game.js +5 -4
  21. package/examples/module/index.html +1 -1
  22. package/examples/particles/index.html +19 -22
  23. package/examples/platformer/game.js +3 -3
  24. package/examples/platformer/gameEffects.js +21 -19
  25. package/examples/platformer/gameLevel.js +6 -6
  26. package/examples/platformer/gameObjects.js +18 -18
  27. package/examples/platformer/gamePlayer.js +4 -3
  28. package/examples/platformer/index.html +6 -6
  29. package/examples/platformer/tiles.png +0 -0
  30. package/examples/platformer/tilesLevel.png +0 -0
  31. package/examples/puzzle/game.js +10 -8
  32. package/examples/puzzle/index.html +2 -2
  33. package/examples/screenshot.jpg +0 -0
  34. package/examples/starter/game.js +32 -21
  35. package/examples/starter/index.html +13 -13
  36. package/examples/starter/tiles.png +0 -0
  37. package/examples/stress/index.html +4 -4
  38. package/examples/typescript/game.js +4 -3
  39. package/examples/typescript/game.ts +5 -4
  40. package/examples/typescript/index.html +1 -1
  41. package/package.json +2 -1
  42. package/src/engine.js +59 -52
  43. package/src/engineAudio.js +2 -1
  44. package/src/engineDraw.js +171 -55
  45. package/src/engineExport.js +84 -271
  46. package/src/engineMedals.js +13 -45
  47. package/src/engineObject.js +13 -13
  48. package/src/engineParticles.js +17 -17
  49. package/src/engineSettings.js +195 -2
  50. package/src/engineTileLayer.js +23 -22
  51. package/src/engineUtilities.js +6 -6
  52. package/src/engineWebGL.js +43 -50
@@ -60,7 +60,7 @@ function gameRender()
60
60
  {
61
61
  // draw a the background
62
62
  drawRect(cameraPos, levelSize.scale(2), new Color(.5,.5,.5));
63
- drawRect(cameraPos, levelSize, new Color(.05,.05,.05));
63
+ drawRect(cameraPos, levelSize, new Color(.02,.02,.02));
64
64
  }
65
65
 
66
66
  ///////////////////////////////////////////////////////////////////////////////
@@ -68,7 +68,7 @@ function gameRenderPost()
68
68
  {
69
69
  // use built in image font for text
70
70
  const font = new FontImage;
71
- font.drawText('Score: ' + score, cameraPos.add(vec2(0,9.6)), .1, 1);
71
+ font.drawText('Score: ' + score, cameraPos.add(vec2(0,9.6)), .15, 1);
72
72
  if (!brickCount)
73
73
  font.drawText('You Win!', cameraPos.add(vec2(0,-5)), .2, 1);
74
74
  else if (!ball)
@@ -93,34 +93,37 @@ function initPostProcess()
93
93
  }
94
94
  void mainImage(out vec4 c, vec2 p)
95
95
  {
96
+ // put uv in texture pixel space
96
97
  p /= iResolution.xy;
97
98
 
98
99
  // apply fuzz as horizontal offset
99
- const float fuzz = .001;
100
+ const float fuzz = .0005;
100
101
  const float fuzzScale = 800.;
101
- p.x += fuzz*(noise(vec2(p.y*fuzzScale, iTime*9.))*2.-1.);
102
+ const float fuzzSpeed = 9.;
103
+ p.x += fuzz*(noise(vec2(p.y*fuzzScale, iTime*fuzzSpeed))*2.-1.);
102
104
 
103
105
  // init output color
104
- c = texture2D(iChannel0, p);
106
+ c = texture(iChannel0, p);
105
107
 
106
108
  // chromatic aberration
107
- const float chromatic = .003;
108
- c.r = texture2D(iChannel0, p - vec2(chromatic, 0)).r;
109
- c.b = texture2D(iChannel0, p + vec2(chromatic, 0)).b;
109
+ const float chromatic = .002;
110
+ c.r = texture(iChannel0, p - vec2(chromatic,0)).r;
111
+ c.b = texture(iChannel0, p + vec2(chromatic,0)).b;
110
112
 
111
113
  // tv static noise
112
114
  const float staticNoise = .1;
113
- c += staticNoise * hash(vec2(p + mod(iTime, 1e3)));
115
+ c += staticNoise * hash(p + mod(iTime, 1e3));
114
116
 
115
117
  // scan lines
116
- const float scanlineScale = 800.;
118
+ const float scanlineScale = 1e3;
117
119
  const float scanlineAlpha = .1;
118
120
  c *= 1. + scanlineAlpha*sin(p.y*scanlineScale);
119
121
 
120
- // black vignette around the outside
122
+ // black vignette around edges
121
123
  const float vignette = 2.;
122
- float dx = 2.*p.x - 1., dy = 2.*p.y - 1.;
123
- c *= 1.-pow((dx*dx + dy*dy)/vignette, 6.);
124
+ const float vignettePow = 6.;
125
+ float dx = 2.*p.x-1., dy = 2.*p.y-1.;
126
+ c *= 1.-pow((dx*dx + dy*dy)/vignette, vignettePow);
124
127
  }`;
125
128
 
126
129
  const includeOverlay = true;
@@ -129,4 +132,4 @@ function initPostProcess()
129
132
 
130
133
  ///////////////////////////////////////////////////////////////////////////////
131
134
  // Startup LittleJS Engine
132
- engineInit(gameInit, gameUpdate, gameUpdatePost, gameRender, gameRenderPost, 'tiles.png');
135
+ engineInit(gameInit, gameUpdate, gameUpdatePost, gameRender, gameRenderPost);
@@ -43,7 +43,7 @@ class Brick extends EngineObject
43
43
  {
44
44
  constructor(pos)
45
45
  {
46
- super(pos, vec2(2,1), 1, vec2(32,16), 0, randColor());
46
+ super(pos, vec2(2,1), tile(1, vec2(32,16)), 0, randColor());
47
47
  ++brickCount;
48
48
 
49
49
  this.mass = 0; // make object have static physics
@@ -62,15 +62,22 @@ class Brick extends EngineObject
62
62
  const color1 = this.color;
63
63
  const color2 = color1.lerp(new Color, .5);
64
64
  new ParticleEmitter(
65
- this.pos, 0, // emitPos, emitAngle
65
+ this.pos, 0, // pos, angle
66
66
  this.size, .1, 200, PI, // emitSize, emitTime, emitRate, emiteCone
67
- 0, vec2(16), // tileIndex, tileSize
67
+ tile(0, 16), // tileIndex, tileSize
68
68
  color1, color2, // colorStartA, colorStartB
69
69
  color1.scale(1,0), color2.scale(1,0), // colorEndA, colorEndB
70
- .1, .3, 1, .05, .05,// time, sizeStart, sizeEnd, speed, angleSpeed
71
- .99, .95, .4, PI, // damping, angleDamping, gravityScale, cone
72
- .1, .5, 0, 1 // fadeRate, randomness, collide, additive
70
+ .3, .8, .3, .05, .05,// time, sizeStart, sizeEnd, speed, angleSpeed
71
+ .99, .95, .4, PI, // damp, angleDamp, gravity, cone
72
+ .1, .8, 0, 1 // fade, randomness, collide, additive
73
73
  );
74
+
75
+ // set ball trail color
76
+ if (o.trailEffect)
77
+ {
78
+ o.trailEffect.colorStartA = this.color;
79
+ o.trailEffect.colorStartB = this.color.lerp(new Color, .5);
80
+ }
74
81
 
75
82
  return 1;
76
83
  }
@@ -81,12 +88,26 @@ class Ball extends EngineObject
81
88
  {
82
89
  constructor(pos)
83
90
  {
84
- super(pos, vec2(.5), 0);
91
+ super(pos, vec2(.5), tile(0));
85
92
 
86
93
  // make a bouncy ball
87
94
  this.setCollision();
88
- this.velocity = vec2(randSign(), -1).scale(.1);
95
+ this.velocity = vec2(0, -.1);
89
96
  this.elasticity = 1;
97
+
98
+ // attach a trail effect
99
+ const color = hsl(0,0,.2);
100
+ this.trailEffect = new ParticleEmitter(
101
+ this.pos, 0, // pos, angle
102
+ this.size, 0, 80, PI, // emitSize, emitTime, emitRate, emiteCone
103
+ tile(0, 16), // tileIndex, tileSize
104
+ color, color, // colorStartA, colorStartB
105
+ color.scale(0), color.scale(0), // colorEndA, colorEndB
106
+ 2, .4, 1, .001, .05,// time, sizeStart, sizeEnd, speed, angleSpeed
107
+ .99, .95, 0, PI, // damp, angleDamp, gravity, cone
108
+ .1, .5, 0, 1 // fade, randomness, collide, additive
109
+ );
110
+ this.addChild(this.trailEffect);
90
111
  }
91
112
 
92
113
  update()
@@ -6,6 +6,6 @@
6
6
  <link rel=icon type=image/png href=../favicon.png>
7
7
  </head><body>
8
8
 
9
- <script src=../../build/littlejs.js?1713></script>
10
- <script src=gameObjects.js?1713></script>
11
- <script src=game.js?1713></script>
9
+ <script src=../../build/littlejs.js?183></script>
10
+ <script src=gameObjects.js?183></script>
11
+ <script src=game.js?183></script>
@@ -237,7 +237,7 @@ this.color = new Color(0,0,0,0); // make object invisible
237
237
 
238
238
  ## Debug Display
239
239
 
240
- This is a good time to try opening up the debug info by pressing ~. This feature will allow for a selection of debug overlays while also showing all game objects with more info displayed for the object closest to the mouse. It can be really useful when trying to diagnose bugs and understand what is going on.
240
+ This is a good time to try opening up the debug info by pressing escape. This feature will allow for a selection of debug overlays while also showing all game objects with more info displayed for the object closest to the mouse. It can be really useful when trying to diagnose bugs and understand what is going on.
241
241
 
242
242
  ![LittleJS Screenshot](images/7.png)
243
243
 
@@ -409,7 +409,7 @@ Make sure you replace the first parameter, vec2(), with this.pos so the effect a
409
409
 
410
410
  ```javascript
411
411
  // create explosion effect
412
- new ParticleEmitter(this.pos, 0, 0, 0.1, 100, 3.14, -1, vec2(16, 16), new Color(1, 1, 1, 1), new Color(1, 1, 1, 1), new Color(1, 1, 1, 0), new Color(1, 1, 1, 0), 0.5, 0.1, 1, 0.1, 0.05, 1, 1, 0, 3.14, 0.1, 0.2, 0, 0, 1);
412
+ new ParticleEmitter(this.pos, 0, 0, 0.1, 100, 3.14, 0, new Color(1, 1, 1, 1), new Color(1, 1, 1, 1), new Color(1, 1, 1, 0), new Color(1, 1, 1, 0), 0.5, 0.1, 1, 0.1, 0.05, 1, 1, 0, 3.14, 0.1, 0.2, 0, 0, 1);
413
413
  ```
414
414
 
415
415
  Now you should see this simple particle effect play wherever a brick breaks. You can continue tweaking the parameters to make your own effect or use the one I made which also uses this.color to change the particle’s color so it matches the brick.
@@ -420,7 +420,7 @@ const color = this.color;
420
420
  new ParticleEmitter(
421
421
  this.pos, 0, // pos, angle
422
422
  this.size, .1, 200, PI, // emitSize, emitTime, emitRate, emiteCone
423
- -1, vec2(16), // tileIndex, tileSize
423
+ 0, // tileInfo
424
424
  color, color, // colorStartA, colorStartB
425
425
  color.scale(1,0), color.scale(1,0), // colorEndA, colorEndB
426
426
  .2, .5, 1, .1, .1, // time, sizeStart, sizeEnd, speed, angleSpeed
@@ -114,12 +114,12 @@ class Brick extends EngineObject
114
114
  new ParticleEmitter(
115
115
  this.pos, 0, // pos, angle
116
116
  this.size, .1, 200, PI, // emitSize, emitTime, emitRate, emiteCone
117
- -1, vec2(16), // tileIndex, tileSize
118
- color, color, // colorStartA, colorStartB
117
+ 0, // tileInfo
118
+ color, color, // colorStartA, colorStartB
119
119
  color.scale(1,0), color.scale(1,0), // colorEndA, colorEndB
120
120
  .2, .5, 1, .1, .1, // time, sizeStart, sizeEnd, speed, angleSpeed
121
- .99, .95, .4, PI, // damping, angleDamping, gravityScale, cone
122
- .1, .5, 0, 1 // fadeRate, randomness, collide, additive
121
+ .99, .95, .4, PI, // damp, angleDamp, gravity, cone
122
+ .1, .5, 0, 1 // fade, randomness, collide, additive
123
123
  );
124
124
 
125
125
  return 1; // allow object to collide
@@ -6,5 +6,5 @@
6
6
  <link rel=icon type=image/png href=../favicon.png>
7
7
  </head><body>
8
8
 
9
- <script src=../../build/littlejs.js?1713></script>
10
- <script src=game.js?1713></script>
9
+ <script src=../../build/littlejs.js?183></script>
10
+ <script src=game.js?183></script>
@@ -26,6 +26,7 @@ function gameInit()
26
26
 
27
27
  // get level data from the tiles image
28
28
  const imageLevelDataRow = 1;
29
+ const tileImage = textureInfos[0].image;
29
30
  mainContext.drawImage(tileImage, 0, 0);
30
31
  for (pos.x = tileCollisionSize.x; pos.x--;)
31
32
  for (pos.y = tileCollisionSize.y; pos.y--;)
@@ -54,7 +55,7 @@ function gameInit()
54
55
  particleEmiter = new ParticleEmitter(
55
56
  vec2(16), 0, // emitPos, emitAngle
56
57
  1, 0, 500, PI, // emitSize, emitTime, emitRate, emiteCone
57
- 0, vec2(16), // tileIndex, tileSize
58
+ tile(0, 16), // tileIndex, tileSize
58
59
  new Color(1,1,1), new Color(0,0,0), // colorStartA, colorStartB
59
60
  new Color(1,1,1,0), new Color(0,0,0,0), // colorEndA, colorEndB
60
61
  2, .2, .2, .1, .05, // time, sizeStart, sizeEnd, speed, angleSpeed
@@ -110,4 +111,4 @@ function gameRenderPost()
110
111
 
111
112
  ///////////////////////////////////////////////////////////////////////////////
112
113
  // Startup LittleJS Engine
113
- engineInit(gameInit, gameUpdate, gameUpdatePost, gameRender, gameRenderPost, 'tiles.png');
114
+ engineInit(gameInit, gameUpdate, gameUpdatePost, gameRender, gameRenderPost);
@@ -7,7 +7,7 @@
7
7
  </head><body>
8
8
 
9
9
  <!-- LittleJS Engine -->
10
- <script src=../../build/littlejs.js?1713></script>
10
+ <script src=../../build/littlejs.js?183></script>
11
11
 
12
12
  <!-- Add your game scripts here -->
13
- <script src=game.js?1713></script>
13
+ <script src=game.js?183></script>
@@ -44,4 +44,4 @@ function gameRenderPost()
44
44
 
45
45
  ///////////////////////////////////////////////////////////////////////////////
46
46
  // Startup LittleJS Engine
47
- engineInit(gameInit, gameUpdate, gameUpdatePost, gameRender, gameRenderPost, 'tiles.png');
47
+ engineInit(gameInit, gameUpdate, gameUpdatePost, gameRender, gameRenderPost);
Binary file
@@ -24,23 +24,28 @@ function gameInit()
24
24
  const tileLayer = new TileLayer(pos, tileCollisionSize);
25
25
 
26
26
  // get level data from the tiles image
27
- const imageLevelDataRow = 1;
28
- mainContext.drawImage(tileImage, 0, 0);
27
+ const tileImage = textureInfos[0].image;
28
+ mainContext.drawImage(tileImage,0,0);
29
+ const imageData = mainContext.getImageData(0,0,tileImage.width,tileImage.height).data;
29
30
  for (pos.x = tileCollisionSize.x; pos.x--;)
30
31
  for (pos.y = tileCollisionSize.y; pos.y--;)
31
32
  {
32
- const imageData = mainContext.getImageData(pos.x, 16*(imageLevelDataRow+1)-pos.y-1, 1, 1).data;
33
- if (imageData[0])
34
- {
35
- const tileIndex = 1;
36
- const direction = randInt(4)
37
- const mirror = randInt(2);
38
- const color = randColor();
39
- const data = new TileLayerData(tileIndex, direction, mirror, color);
40
- tileLayer.setData(pos, data);
41
- setTileCollisionData(pos, 1);
42
- }
33
+ // check if this pixel is set
34
+ const i = pos.x + tileImage.width*(15 + tileCollisionSize.y - pos.y);
35
+ if (!imageData[4*i])
36
+ continue;
37
+
38
+ // set tile data
39
+ const tileIndex = 1;
40
+ const direction = randInt(4)
41
+ const mirror = randInt(2);
42
+ const color = randColor();
43
+ const data = new TileLayerData(tileIndex, direction, mirror, color);
44
+ tileLayer.setData(pos, data);
45
+ setTileCollisionData(pos, 1);
43
46
  }
47
+
48
+ // draw tile layer with new data
44
49
  tileLayer.redraw();
45
50
 
46
51
  // move camera to center of collision
@@ -53,7 +58,7 @@ function gameInit()
53
58
  particleEmitter = new ParticleEmitter(
54
59
  vec2(16), 0, // emitPos, emitAngle
55
60
  1, 0, 500, PI, // emitSize, emitTime, emitRate, emiteCone
56
- 0, vec2(16), // tileIndex, tileSize
61
+ tile(0, 16), // tileIndex, tileSize
57
62
  new Color(1,1,1), new Color(0,0,0), // colorStartA, colorStartB
58
63
  new Color(1,1,1,0), new Color(0,0,0,0), // colorEndA, colorEndB
59
64
  2, .2, .2, .1, .05, // time, sizeStart, sizeEnd, speed, angleSpeed
@@ -106,4 +111,4 @@ function gameRenderPost()
106
111
 
107
112
  ///////////////////////////////////////////////////////////////////////////////
108
113
  // Startup LittleJS Engine
109
- engineInit(gameInit, gameUpdate, gameUpdatePost, gameRender, gameRenderPost, 'tiles.png');
114
+ engineInit(gameInit, gameUpdate, gameUpdatePost, gameRender, gameRenderPost);
@@ -1,18 +1,18 @@
1
- <head><title>LittleJS JS13K Project</title></head>
1
+ <head><title>LittleJS JS13K Project</title></head><body>
2
2
 
3
3
  <!-- LittleJS Engine -->
4
- <script src=../../src/engineDebug.js?1713></script>
5
- <script src=../../src/engineUtilities.js?1713></script>
6
- <script src=../../src/engineSettings.js?1713></script>
7
- <script src=../../src/engineObject.js?1713></script>
8
- <script src=../../src/engineDraw.js?1713></script>
9
- <script src=../../src/engineInput.js?1713></script>
10
- <script src=../../src/engineAudio.js?1713></script>
11
- <script src=../../src/engineTileLayer.js?1713></script>
12
- <script src=../../src/engineParticles.js?1713></script>
13
- <script src=../../src/engineMedals.js?1713></script>
14
- <script src=../../src/engineWebGL.js?1713></script>
15
- <script src=../../src/engine.js?1713></script>
4
+ <script src=../../src/engineDebug.js?183></script>
5
+ <script src=../../src/engineUtilities.js?183></script>
6
+ <script src=../../src/engineSettings.js?183></script>
7
+ <script src=../../src/engineObject.js?183></script>
8
+ <script src=../../src/engineDraw.js?183></script>
9
+ <script src=../../src/engineInput.js?183></script>
10
+ <script src=../../src/engineAudio.js?183></script>
11
+ <script src=../../src/engineTileLayer.js?183></script>
12
+ <script src=../../src/engineParticles.js?183></script>
13
+ <script src=../../src/engineMedals.js?183></script>
14
+ <script src=../../src/engineWebGL.js?183></script>
15
+ <script src=../../src/engine.js?183></script>
16
16
 
17
17
  <!-- Add your game scripts here -->
18
- <script src=game.js?1713></script>
18
+ <script src=game.js?183></script>
@@ -8,7 +8,7 @@
8
8
 
9
9
  // import module
10
10
  import * as LittleJS from '../../build/littlejs.esm.js';
11
- const {Vector2, Color, Timer, vec2} = LittleJS;
11
+ const {Vector2, Color, Timer, vec2, tile} = LittleJS;
12
12
 
13
13
  // sound effects
14
14
  const sound_click = new LittleJS.Sound([1,.5]);
@@ -31,7 +31,8 @@ function gameInit()
31
31
  // get level data from the tiles image
32
32
  const imageLevelDataRow = 1;
33
33
  const mainContext = LittleJS.mainContext;
34
- mainContext.drawImage(LittleJS.tileImage, 0, 0);
34
+ const tileImage = LittleJS.textureInfos[0].image;
35
+ mainContext.drawImage(tileImage, 0, 0);
35
36
  for (pos.x = LittleJS.tileCollisionSize.x; pos.x--;)
36
37
  for (pos.y = LittleJS.tileCollisionSize.y; pos.y--;)
37
38
  {
@@ -60,7 +61,7 @@ function gameInit()
60
61
  particleEmiter = new LittleJS.ParticleEmitter(
61
62
  center, 0, // emitPos, emitAngle
62
63
  1, 0, 500, Math.PI, // emitSize, emitTime, emitRate, emiteCone
63
- 0, vec2(16), // tileIndex, tileSize
64
+ LittleJS.tile(0, 16), // tileIndex, tileSize
64
65
  new Color(1,1,1), new Color(0,0,0), // colorStartA, colorStartB
65
66
  new Color(1,1,1,0), new Color(0,0,0,0), // colorEndA, colorEndB
66
67
  2, .2, .2, .1, .05, // time, sizeStart, sizeEnd, speed, angleSpeed
@@ -120,4 +121,4 @@ function gameRenderPost()
120
121
 
121
122
  ///////////////////////////////////////////////////////////////////////////////
122
123
  // Startup LittleJS Engine
123
- LittleJS.engineInit(gameInit, gameUpdate, gameUpdatePost, gameRender, gameRenderPost, 'tiles.png');
124
+ LittleJS.engineInit(gameInit, gameUpdate, gameUpdatePost, gameRender, gameRenderPost);
@@ -7,4 +7,4 @@
7
7
  </head><body>
8
8
 
9
9
  <!-- Add your game scripts here -->
10
- <script src=game.js?1713 type=module></script>
10
+ <script src=game.js?183 type=module></script>
@@ -10,7 +10,7 @@ button { margin:1px; }
10
10
  </style>
11
11
  </head><body>
12
12
 
13
- <script src=../../build/littlejs.js?1713></script>
13
+ <script src=../../build/littlejs.js?183></script>
14
14
  <script>
15
15
 
16
16
  'use strict';
@@ -31,8 +31,7 @@ addSetting('emitTime', '', 0, 1e9, .1, 'How long to stay alive (0 is for
31
31
  addSetting('emitRate', '', 0, 1e9, 1, 'How many particles per second to spawn, does not emit if 0');
32
32
  addSetting('emitConeAngle', '', 0, 1e9, .01,'Local angle to apply velocity to particles from emitter');
33
33
  addSetting('tileIndex', '', -1, 1e9, 1, 'Tile to use to render object (-1 is untextured)');
34
- addSetting('tileSizeX', '', 0, 1e9, 1, 'X Size of texture tile in source pixelss');
35
- addSetting('tileSizeY', '', 0, 1e9, 1, 'Y Size of texture tile in source pixelss');
34
+ addSetting('tileSize', '', 0, 1e9, 1, 'Size of texture tile in source pixels');
36
35
  addSetting('colorStartA', 'color',0,0,0, 'Color at start of life 1');
37
36
  addSetting('colorStartA_alpha', 'alpha', 0, 1, .01, 'Alpha at start of life 1');
38
37
  addSetting('colorStartB', 'color',0,0,0, 'Color at start of life 2');
@@ -61,6 +60,7 @@ function makeEmitter()
61
60
  if (particleSystem)
62
61
  particleSystem.destroy();
63
62
  particleSystem = new ParticleEmitter(cameraPos);
63
+ particleSystem.tileInfo = tile();
64
64
  particleSystem.emitConeAngle =
65
65
  particleSystem.particleConeAngle = 3.14;
66
66
  }
@@ -102,10 +102,8 @@ function gameInit()
102
102
  else if (name == 'colorEndB_alpha')
103
103
  defaultValue = particleSystem.colorEndB.a;
104
104
  }
105
- else if (name == 'tileSizeX')
106
- defaultValue = particleSystem.tileSize.x;
107
- else if (name == 'tileSizeY')
108
- defaultValue = particleSystem.tileSize.y;
105
+ else if (name == 'tileSize')
106
+ defaultValue = particleSystem.tileInfo.size.x;
109
107
  else if (type == 'checkbox')
110
108
  defaultValue = particleSystem[name];
111
109
  else
@@ -162,7 +160,7 @@ function gameInit()
162
160
  if (!confirm('Reset to default?'))
163
161
  return;
164
162
  makeEmitter();
165
- updateInputs(0);
163
+ updateInputs();
166
164
  cameraScale = 50;
167
165
  }
168
166
  }
@@ -200,6 +198,7 @@ function gameInit()
200
198
  }
201
199
 
202
200
  updateParticles();
201
+ particleSystemCode.value = getCode();
203
202
  }
204
203
 
205
204
  function updateParticles(shouldUpdateInput)
@@ -228,14 +227,14 @@ function updateParticles(shouldUpdateInput)
228
227
  else if (name == 'colorEndB_alpha')
229
228
  particleSystem.colorEndB.a = clamp(inputFloat);
230
229
  }
231
- else if (name == 'tileSizeX')
232
- {
233
- particleSystem.tileSize = vec2(parseInt(input.value), particleSystem.tileSize.y);
234
- }
235
- else if (name == 'tileSizeY')
230
+ else if (name == 'tileIndex')
236
231
  {
237
- particleSystem.tileSize = vec2(particleSystem.tileSize.x, parseInt(input.value));
232
+ const tileIndex = parseInt(input.value);
233
+ particleSystem.tileIndex = tileIndex
234
+ particleSystem.tileInfo = tile(tileIndex, particleSystem.tileInfo.size);
238
235
  }
236
+ else if (name == 'tileSize')
237
+ particleSystem.tileInfo.size = vec2(parseInt(input.value));
239
238
  else if (type == 'checkbox')
240
239
  particleSystem[name] = input.checked ? 1 : 0;
241
240
  else if (name == 'emitRate')
@@ -275,10 +274,8 @@ function updateSetting(setting, save=1)
275
274
  else if (name == 'colorEndB_alpha')
276
275
  input.value = particleSystem.colorEndB.a;
277
276
  }
278
- else if (name == 'tileSizeX')
279
- input.value = particleSystem.tileSize.x;
280
- else if (name == 'tileSizeY')
281
- input.value = particleSystem.tileSize.y;
277
+ else if (name == 'tileSize')
278
+ input.value = particleSystem.tileInfo.size.x;
282
279
  else if (type == 'checkbox')
283
280
  input.checked = particleSystem[name];
284
281
  else
@@ -315,11 +312,11 @@ function getCode()
315
312
  const name = setting.name;
316
313
  const type = setting.type;
317
314
  let value;
318
- if (name == 'tileSizeX' || type == 'alpha')
315
+ if (name == 'tileSize' || type == 'alpha')
319
316
  continue;
320
317
 
321
- if (name == 'tileSizeY')
322
- value = `vec2(${particleSystem.tileSize.x}, ${particleSystem.tileSize.y})`;
318
+ if (name == 'tileIndex')
319
+ value = `tile(${particleSystem.tileIndex}, ${particleSystem.tileInfo.size.x})`;
323
320
  else if (type == 'color')
324
321
  {
325
322
  const c = particleSystem[name];
@@ -394,6 +391,6 @@ function gameRenderPost()
394
391
 
395
392
  ///////////////////////////////////////////////////////////////////////////////
396
393
  // Startup LittleJS Engine
397
- engineInit(gameInit, gameUpdate, gameUpdatePost, gameRender, gameRenderPost, 'tiles.png');
394
+ engineInit(gameInit, gameUpdate, gameUpdatePost, gameRender, gameRenderPost);
398
395
 
399
396
  </script>
@@ -78,13 +78,13 @@ function gameRender()
78
78
  function gameRenderPost()
79
79
  {
80
80
  // draw to overlay canvas for hud rendering
81
- const drawText = (text, x, y, size=50) =>
81
+ const drawText = (text, x, y, size=40) =>
82
82
  {
83
83
  overlayContext.textAlign = 'center';
84
84
  overlayContext.textBaseline = 'top';
85
85
  overlayContext.font = size + 'px arial';
86
86
  overlayContext.fillStyle = '#fff';
87
- overlayContext.lineWidth = 2;
87
+ overlayContext.lineWidth = 3;
88
88
  overlayContext.strokeText(text, x, y);
89
89
  overlayContext.fillText(text, x, y);
90
90
  }
@@ -94,4 +94,4 @@ function gameRenderPost()
94
94
 
95
95
  ///////////////////////////////////////////////////////////////////////////////
96
96
  // Startup LittleJS Engine
97
- engineInit(gameInit, gameUpdate, gameUpdatePost, gameRender, gameRenderPost, 'tiles.png');
97
+ engineInit(gameInit, gameUpdate, gameUpdatePost, gameRender, gameRenderPost, ['tiles.png', 'tilesLevel.png']);
@@ -29,9 +29,9 @@ const sound_killEnemy = new Sound([,,783,,.03,.02,1,2,,,940,.03,,,,,.2,.6,,.0
29
29
  const persistentParticleDestroyCallback = (particle)=>
30
30
  {
31
31
  // copy particle to tile layer on death
32
- ASSERT(particle.tileIndex < 0); // quick draw to tile layer uses canvas 2d so must be untextured
32
+ ASSERT(!particle.tileInfo); // quick draw to tile layer uses canvas 2d so must be untextured
33
33
  if (particle.groundObject)
34
- tileLayer.drawTile(particle.pos, particle.size, particle.tileIndex, particle.tileSize, particle.color, particle.angle, particle.mirror);
34
+ tileLayer.drawTile(particle.pos, particle.size, particle.tileInfo, particle.color, particle.angle, particle.mirror);
35
35
  }
36
36
 
37
37
  function makeBlood(pos, amount) { makeDebris(pos, new Color(1,0,0), 50, .1, 0); }
@@ -40,12 +40,12 @@ function makeDebris(pos, color = new Color, amount = 100, size=.2, elasticity =
40
40
  const color2 = color.lerp(new Color, .5);
41
41
  const emitter = new ParticleEmitter(
42
42
  pos, 0, 1, .1, 100, PI, // pos, angle, emitSize, emitTime, emitRate, emiteCone
43
- undefined, undefined, // tileIndex, tileSize
44
- color, color2, // colorStartA, colorStartB
45
- color, color2, // colorEndA, colorEndB
46
- 3, size,size, .1, .05, // particleTime, sizeStart, sizeEnd, particleSpeed, particleAngleSpeed
47
- 1, .95, .4, PI, 0, // damping, angleDamping, gravityScale, particleCone, fadeRate,
48
- .5, 1 // randomness, collide, additive, randomColorLinear, renderOrder
43
+ 0, // tileInfo
44
+ color, color2, // colorStartA, colorStartB
45
+ color, color2, // colorEndA, colorEndB
46
+ 3, size,size, .1, .05, // time, sizeStart, sizeEnd, speed, angleSpeed
47
+ 1, .95, .4, PI, 0, // damp, angleDamp, gravity, particleCone, fade
48
+ .5, 1 // randomness, collide, additive, colorLinear, renderOrder
49
49
  );
50
50
  emitter.elasticity = elasticity;
51
51
  emitter.particleDestroyCallback = persistentParticleDestroyCallback;
@@ -99,24 +99,26 @@ function explosion(pos, radius=3)
99
99
 
100
100
  // smoke
101
101
  new ParticleEmitter(
102
- pos, 0, radius/2, .2, 50*radius, PI, // pos, angle, emitSize, emitTime, emitRate, emiteCone
103
- 0, undefined, // tileIndex, tileSize
104
- new Color(0,0,0), new Color(0,0,0), // colorStartA, colorStartB
102
+ pos, 0, // pos, angle
103
+ radius/2, .2, 50*radius, PI, // emitSize, emitTime, emitRate, emiteCone
104
+ 0, // tileInfo
105
+ new Color(0,0,0), new Color(0,0,0), // colorStartA, colorStartB
105
106
  new Color(0,0,0,0), new Color(0,0,0,0), // colorEndA, colorEndB
106
- 1, .5, 2, .1, .05, // particleTime, sizeStart, sizeEnd, particleSpeed, particleAngleSpeed
107
- .9, 1, -.3, PI, .1, // damping, angleDamping, gravityScale, particleCone, fadeRate,
108
- .5, 0, 0, 0, 1e8 // randomness, collide, additive, randomColorLinear, renderOrder
107
+ 1, .5, 2, .2, .05, // time, sizeStart, sizeEnd, speed, angleSpeed
108
+ .9, 1, -.3, PI, .1, // damp, angleDamp, gravity, particleCone, fade
109
+ .5, 0, 0, 0, 1e8 // randomness, collide, additive, colorLinear, renderOrder
109
110
  );
110
111
 
111
112
  // fire
112
113
  new ParticleEmitter(
113
- pos, 0, radius/2, .1, 100*radius, PI, // pos, angle, emitSize, emitTime, emitRate, emiteCone
114
- 0, undefined, // tileIndex, tileSize
114
+ pos, 0, // pos, angle
115
+ radius/2, .1, 100*radius, PI, // emitSize, emitTime, emitRate, emiteCone
116
+ 0, // tileInfo
115
117
  new Color(1,.5,.1), new Color(1,.1,.1), // colorStartA, colorStartB
116
118
  new Color(1,.5,.1,0), new Color(1,.1,.1,0), // colorEndA, colorEndB
117
- .5, .5, 2, .1, .05, // particleTime, sizeStart, sizeEnd, particleSpeed, particleAngleSpeed
118
- .9, 1, 0, PI, .05, // damping, angleDamping, gravityScale, particleCone, fadeRate,
119
- .5, 0, 1, 0, 1e9 // randomness, collide, additive, randomColorLinear, renderOrder
119
+ .7, .8, .2, .2, .05, // time, sizeStart, sizeEnd, speed, angleSpeed
120
+ .9, 1, -.2, PI, .05, // damp, angleDamp, gravity, particleCone, fade
121
+ .5, 0, 1, 0, 1e9 // randomness, collide, additive, colorLinear, renderOrder
120
122
  );
121
123
  }
122
124
 
@@ -143,9 +143,9 @@ function generateLevel()
143
143
  function makeTileLayers()
144
144
  {
145
145
  // create tile layers
146
- tileLayer = new TileLayer(vec2(), levelSize);
146
+ tileLayer = new TileLayer(vec2(), levelSize, tile(0,16,1));
147
147
  tileLayer.renderOrder = -1e3;
148
- tileBackgroundLayer = new TileLayer(vec2(), levelSize);
148
+ tileBackgroundLayer = new TileLayer(vec2(), levelSize, tile(0,16,1));
149
149
  tileBackgroundLayer.renderOrder = -2e3;
150
150
 
151
151
  const pos = vec2();
@@ -159,13 +159,13 @@ function makeTileLayers()
159
159
  let direction, mirror, tileIndex, color;
160
160
  if (tileType == tileType_solid)
161
161
  {
162
- tileIndex = 5 + rand()**3*2|0;
162
+ tileIndex = 1 + rand()**3*2|0;
163
163
  color = levelColor.mutate(.03);
164
164
  direction = randInt(4);
165
165
  mirror = randInt(2);
166
166
  }
167
167
  else if (tileType == tileType_ladder)
168
- tileIndex = 7;
168
+ tileIndex = 3;
169
169
 
170
170
  const data = new TileLayerData(tileIndex, direction, mirror, color);
171
171
  tileLayer.setData(pos, data);
@@ -175,7 +175,7 @@ function makeTileLayers()
175
175
  tileType = getTileBackgroundData(pos);
176
176
  if (tileType)
177
177
  {
178
- const data = new TileLayerData(5 + rand()**3*2|0, randInt(4), randInt(2), levelColor.mutate().scale(.4,1));
178
+ const data = new TileLayerData(1 + rand()**3*2|0, randInt(4), randInt(2), levelColor.mutate().scale(.4,1));
179
179
  tileBackgroundLayer.setData(pos, data);
180
180
  }
181
181
  }
@@ -212,7 +212,7 @@ function buildLevel()
212
212
 
213
213
  // warm up level
214
214
  warmup = 1;
215
- for (let i=5*frameRate; i--;)
215
+ for (let i = 500; i--;)
216
216
  engineObjectsUpdate();
217
217
  warmup = 0;
218
218