littlejsengine 1.14.16 → 1.14.23

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 (62) hide show
  1. package/dist/littlejs.d.ts +173 -50
  2. package/dist/littlejs.esm.js +892 -419
  3. package/dist/littlejs.esm.min.js +1 -1
  4. package/dist/littlejs.js +879 -419
  5. package/dist/littlejs.min.js +1 -1
  6. package/dist/littlejs.release.js +854 -420
  7. package/examples/box2d/game.js +3 -2
  8. package/examples/box2d/tiles.png +0 -0
  9. package/examples/breakout/game.js +5 -5
  10. package/examples/electron/game.js +1 -41
  11. package/examples/electron/index.html +2 -2
  12. package/examples/htmlMenu/game.js +1 -1
  13. package/examples/index.html +69 -55
  14. package/examples/module/game.js +6 -8
  15. package/examples/particles/index.html +6 -9
  16. package/examples/platformer/gameCharacter.js +1 -1
  17. package/examples/platformer/gameEffects.js +8 -3
  18. package/examples/platformer/gameObjects.js +3 -3
  19. package/examples/shorts/animation.js +2 -2
  20. package/examples/shorts/base.html +4 -1
  21. package/examples/shorts/cameraDrag.js +22 -0
  22. package/examples/shorts/debugDraw.js +38 -0
  23. package/examples/shorts/fps.js +90 -0
  24. package/examples/shorts/helloWorld.js +1 -1
  25. package/examples/shorts/hillGlideGame.js +1 -1
  26. package/examples/shorts/landerGame.js +1 -1
  27. package/examples/shorts/musicPlayer.js +1 -0
  28. package/examples/shorts/parallax.js +1 -1
  29. package/examples/shorts/postProcess.js +1 -1
  30. package/examples/shorts/sequencer.js +5 -5
  31. package/examples/shorts/shader.js +29 -0
  32. package/examples/shorts/spaceGame.js +1 -1
  33. package/examples/shorts/spriteAtlas.js +6 -6
  34. package/examples/shorts/starfield.js +1 -1
  35. package/examples/shorts/tileLayer.js +1 -1
  36. package/examples/shorts/tileRaycast.js +39 -0
  37. package/examples/shorts/tiles.png +0 -0
  38. package/examples/shorts/tiltedView.js +14 -6
  39. package/examples/shorts/topDown.js +1 -1
  40. package/examples/starter/game.js +6 -8
  41. package/examples/starter/index.html +2 -2
  42. package/examples/style.css +1 -0
  43. package/examples/typescript/game.js +5 -4
  44. package/examples/typescript/game.ts +5 -7
  45. package/examples/uiSystem/game.js +3 -2
  46. package/package.json +1 -1
  47. package/plugins/postProcess.js +71 -51
  48. package/plugins/uiSystem.js +76 -23
  49. package/src/engine.js +30 -16
  50. package/src/engineAudio.js +33 -23
  51. package/src/engineDebug.js +27 -0
  52. package/src/engineDraw.js +103 -49
  53. package/src/engineExport.js +13 -0
  54. package/src/engineInput.js +14 -16
  55. package/src/engineObject.js +31 -6
  56. package/src/engineParticles.js +37 -16
  57. package/src/engineRelease.js +2 -1
  58. package/src/engineSettings.js +20 -1
  59. package/src/engineTileLayer.js +89 -94
  60. package/src/engineUtilities.js +206 -58
  61. package/src/engineWebGL.js +145 -69
  62. package/examples/shorts/raycasting.js +0 -79
@@ -0,0 +1,90 @@
1
+ let playerPos = vec2(), playerAngle = 0;
2
+ setTileFixBleedScale(0);
3
+
4
+ // a simple function to create the level
5
+ const levelTest = (p)=> (floor(p.x)**3&floor(p.y)**2)%30>5;
6
+
7
+ function gameUpdate()
8
+ {
9
+ // update camera angle with mouse pointer lock
10
+ if (mouseWasPressed(0))
11
+ pointerLockRequest();
12
+ if (keyWasPressed('Escape'))
13
+ pointerLockExit()
14
+ if (pointerLockIsActive() || isTouchDevice)
15
+ playerAngle += mouseDelta.x * .003;
16
+
17
+ // update player movement, prevent walking through walls
18
+ const velocity = keyDirection().rotate(playerAngle).scale(.05);
19
+ const normal = vec2();
20
+ let newPos = playerPos.add(velocity);
21
+ if (lineTest(playerPos, newPos, levelTest, normal))
22
+ {
23
+ // adjust velocity to slide along wall
24
+ const d = velocity.dot(normal);
25
+ newPos = newPos.subtract(vec2(d*normal.x, d*normal.y));
26
+ if (!levelTest(newPos))
27
+ playerPos = newPos;
28
+ }
29
+ else
30
+ playerPos = newPos;
31
+ }
32
+
33
+ function gameRender()
34
+ {
35
+ {
36
+ // draw horizontal slizes to create floor and ceiling
37
+ const h = 9;
38
+ let pos = vec2(), size = vec2(39, .15), color = rgb();
39
+ for (let y=-h; y<h; y+=.1)
40
+ {
41
+ const p = 1.01 - abs(y/h)
42
+ color.setHSLA(.1, y>0?0:.5, .7-p*.7);
43
+ pos.y = y;
44
+ drawRect(pos, size, color);
45
+ }
46
+ }
47
+ {
48
+ // draw vertical slices to create the walls
49
+ // create objects in advance for optimal performance
50
+ const w = 15;
51
+ const maxDistance = 50;
52
+ const pos = vec2(), endPos = vec2(), size = vec2(.15);
53
+ const tileInfo = new TileInfo(vec2(), vec2(0,16));
54
+ const normal = vec2(), light = vec2().setAngle(2);
55
+ const color = rgb();
56
+ for (pos.x=-w; pos.x<w; pos.x+=.1)
57
+ {
58
+ // cast ray for this slice
59
+ const angle = playerAngle + pos.x/w/2;
60
+ endPos.setAngle(angle, maxDistance);
61
+ endPos.x += playerPos.x;
62
+ endPos.y += playerPos.y;
63
+ const p = lineTest(playerPos, endPos, levelTest, normal);
64
+ if (!p) continue;
65
+
66
+ // get texture coordinate
67
+ const t = mod(p.x+p.y, 1);
68
+ tileInfo.pos.x = 161 + 14*t;
69
+
70
+ // apply fog and lighting
71
+ const d = p.distance(playerPos)/maxDistance;
72
+ const l = max(0, normal.dot(light));
73
+ size.y = .5/d;
74
+ color.setHSLA(.6, 1-d, .7-d+l*.3);
75
+
76
+ // draw the section the wall
77
+ drawTile(pos, size, tileInfo, color);
78
+ }
79
+ }
80
+
81
+ // draw instructions and pointer lock status
82
+ const instructions = pointerLockIsActive() ?
83
+ 'Mouse Control Active - ESC To Exit' :
84
+ 'Click To Enable Mouse Control';
85
+ const textPos = vec2(mainCanvasSize.x/2, 50);
86
+ const textSize = 30;
87
+ const textColor = pointerLockIsActive() ? GREEN : WHITE;
88
+ if (!isTouchDevice)
89
+ drawTextScreen(instructions, textPos, textSize, textColor);
90
+ }
@@ -7,5 +7,5 @@ function gameRender()
7
7
  drawTextOverlay('LittleJS Engine', vec2(0,3), 3);
8
8
 
9
9
  // draw a tile
10
- drawTile(vec2(Math.sin(time)*3,-2), vec2(7), tile(3,128));
10
+ drawTile(vec2(sin(time)*3,-2), vec2(7), tile(3,128));
11
11
  }
@@ -35,7 +35,7 @@ class Player extends EngineObject
35
35
 
36
36
  function getGroundHeight(x)
37
37
  {
38
- return Math.sin(x/4)*2 + Math.sin(x/17);
38
+ return sin(x/4)*2 + sin(x/17);
39
39
  }
40
40
 
41
41
  function gameInit()
@@ -14,7 +14,7 @@ class Player extends EngineObject
14
14
  // space ship controls
15
15
  const moveInput = keyDirection();
16
16
  this.applyAngularAcceleration(moveInput.x * .002);
17
- const accel = vec2(0, moveInput.y*.002).rotate(this.angle);
17
+ const accel = this.getRight(moveInput.y*.002);
18
18
  this.applyAcceleration(accel);
19
19
  }
20
20
 
@@ -9,6 +9,7 @@ function gameInit()
9
9
  uiSystem.defaultSoundPress = new Sound([.5,0,220]);
10
10
  uiSystem.defaultSoundClick = new Sound([.5,0,440]);
11
11
  uiSystem.defaultCornerRadius = 20;
12
+ uiSystem.defaultGradientColor = WHITE;
12
13
  canvasClearColor = hsl(.9,.3,.2);
13
14
 
14
15
  // setup music player UI
@@ -53,7 +53,7 @@ class ParallaxLayer extends CanvasLayer
53
53
  this.context.clearRect(0,0,1,h);
54
54
 
55
55
  // make WebGL texture
56
- this.useWebGL(glEnable);
56
+ this.useWebGL();
57
57
  }
58
58
 
59
59
  render()
@@ -6,7 +6,7 @@ function gameInit()
6
6
  function gameRender()
7
7
  {
8
8
  drawRect(vec2(), vec2(99), GRAY);
9
- drawTile(vec2(Math.sin(time)*3, 0), vec2(12), tile(3,128));
9
+ drawTile(vec2(sin(time)*3, 0), vec2(12), tile(3,128));
10
10
  }
11
11
 
12
12
  const tvShader = `
@@ -3,7 +3,7 @@ let currentStep = 0, stepTime = 0, tempo = 240;
3
3
  let isPlaying = false, eraseMode = false;
4
4
 
5
5
  // sound sequencer instruments
6
- const sound_piano = new Sound([.4,0,220,,.1]);
6
+ const sound_piano = new Sound([.3,0,220,,.1]);
7
7
  const sound_drumKick = new Sound([,,99,,,.02,,,,,,,,2]);
8
8
  const sound_drumHat = new Sound([,,1e3,,,.01,4,,,,,,,,,,,,,,4e3]);
9
9
 
@@ -34,7 +34,7 @@ class UISequencerButton extends UIButton
34
34
  this.hue = track*.15;
35
35
  if (track >= pianoStart)
36
36
  {
37
- const octave = Math.floor((track-pianoStart) / scale.length);
37
+ const octave = floor((track-pianoStart) / scale.length);
38
38
  const scaleNote = (track-pianoStart) % scale.length;
39
39
  this.semitone = scale[scaleNote] + 12*octave;
40
40
  this.sound = sound_piano;
@@ -57,7 +57,7 @@ class UISequencerButton extends UIButton
57
57
  {
58
58
  this.activeColor = eraseMode ? RED : WHITE;
59
59
  this.color = this.isActiveObject() ? BLACK :
60
- hsl(this.hue, this.isOn ? 1 : .5, this.isOn ? .5 : .1);
60
+ hsl(this.hue, this.isOn ? 1 : .5, this.isOn ? .5 : .15);
61
61
  if (isPlaying && this.step == currentStep)
62
62
  this.color = this.color.lerp(WHITE, .5);
63
63
  super.render();
@@ -93,7 +93,7 @@ function gameInit()
93
93
  tempoSlider.onChange = ()=>
94
94
  {
95
95
  tempo = lerp(minTempo, maxTempo, tempoSlider.value);
96
- tempo = Math.floor(tempo/10) * 10; // round to nearest 10th
96
+ tempo = floor(tempo/10) * 10; // round to nearest 10th
97
97
  tempoSlider.text = `${tempo} BPM`;
98
98
  };
99
99
  tempoSlider.onChange();
@@ -108,7 +108,7 @@ function gameUpdate()
108
108
  const lastStepTime = stepTime;
109
109
  const lastStep = currentStep;
110
110
  stepTime += timeDelta*tempo/60;
111
- currentStep = Math.floor(stepTime) % stepCount;
111
+ currentStep = floor(stepTime) % stepCount;
112
112
  if (currentStep == lastStep && lastStepTime)
113
113
  return;
114
114
 
@@ -0,0 +1,29 @@
1
+ const shader = `
2
+ void mainImage(out vec4 c, vec2 p)
3
+ {
4
+ // normalize coordinates
5
+ vec2 uv = (p - iResolution.xy * .5) / iResolution.y;
6
+
7
+ // get distance and angle from center
8
+ float distance = length(uv);
9
+ float angle = atan(uv.y, uv.x);
10
+
11
+ // color based on angle and distance
12
+ c.rgb = vec3(
13
+ .5 + .5 * sin(angle + iTime),
14
+ .5 + .5 * sin(angle + iTime * 2.),
15
+ .5 + .5 * sin(distance * 5. - iTime)
16
+ );
17
+
18
+ // apply glow in center
19
+ c += .1 / (distance + .1);
20
+
21
+ // apply sine wave brightness
22
+ c *= .5 + .5 * sin(distance * 20. - iTime * 3.);
23
+ }
24
+ `;
25
+
26
+ function gameInit()
27
+ {
28
+ new PostProcessPlugin(shader);
29
+ }
@@ -23,7 +23,7 @@ class Player extends EngineObject
23
23
  // shoot bullet
24
24
  const pos = this.pos.add(vec2(0,1).rotate(cameraAngle));
25
25
  const bullet = new EngineObject(pos, vec2(.2,.5), 0, this.angle);
26
- bullet.velocity = vec2(0,.5).rotate(this.angle);
26
+ bullet.velocity = this.getUp(.5);
27
27
  bullet.velocity = bullet.velocity.add(this.velocity);
28
28
  this.shootTimer.set(.1);
29
29
  }
@@ -18,12 +18,12 @@ function gameInit()
18
18
  function gameRender()
19
19
  {
20
20
  // draw a sprite from the atlas
21
- let pos = vec2(Math.sin(time)*5,-3);// world position
22
- let angle = 0; // world space angle
23
- let size = vec2(9); // world space size
24
- let mirror = 0; // should tile be mirrored?
25
- let color = hsl(0,0,1); // color to multiply by
26
- let additive = hsl(0,0,0,0); // color to add to
21
+ let pos = vec2(sin(time)*5,-3);// world position
22
+ let angle = 0; // world space angle
23
+ let size = vec2(9); // world space size
24
+ let mirror = 0; // should tile be mirrored?
25
+ let color = hsl(0,0,1); // color to multiply by
26
+ let additive = hsl(0,0,0,0); // color to add to
27
27
  drawTile(pos, size, spriteAtlas.iconBig, color, angle, mirror, additive);
28
28
 
29
29
  // draw more sprites from the atlas
@@ -9,7 +9,7 @@ function gameRender()
9
9
  pos.x = offset%70 - 35;
10
10
  pos.y = i/110 - 9;
11
11
  size.x = size.y = i%.11 + .07;
12
- color.set(1,1,1,Math.sin(i)**4);
12
+ color.set(1,1,1,sin(i)**4);
13
13
  drawRect(pos, size, color);
14
14
  }
15
15
  }
@@ -43,6 +43,6 @@ function gameUpdate()
43
43
  .05, .8, true
44
44
  );
45
45
  particleEmitter.restitution = .5; // bounce when it collides
46
- particleEmitter.trailScale = 2; // stretch as it moves
46
+ particleEmitter.trailScale = 2; // stretch as it moves
47
47
  }
48
48
  }
@@ -0,0 +1,39 @@
1
+ function gameInit()
2
+ {
3
+ // create tile layer
4
+ const pos = vec2();
5
+ const tileLayer = new TileCollisionLayer(pos, vec2(28,16), 0);
6
+ cameraPos = tileLayer.size.scale(.5); // setup camera
7
+ for (pos.x = tileLayer.size.x; pos.x--;)
8
+ for (pos.y = tileLayer.size.y; pos.y--;)
9
+ {
10
+ // create random solid tiles away from level center
11
+ if (rand() < .7 || cameraPos.distanceSquared(pos) < 9)
12
+ continue;
13
+
14
+ // set tile data
15
+ const data = new TileLayerData(1);
16
+ tileLayer.setData(pos, data);
17
+ tileLayer.setCollisionData(pos);
18
+ }
19
+ tileLayer.redraw();
20
+ }
21
+
22
+ function gameRenderPost()
23
+ {
24
+ // cast ray from camera center to mouse
25
+ drawLine(cameraPos, mousePos, .1, CYAN);
26
+ const normal = vec2();
27
+ const hit = tileCollisionRaycast(cameraPos, mousePos, 0, normal);
28
+ if (hit)
29
+ {
30
+ // draw hit tile
31
+ const tilePos = hit.floor().add(vec2(.5));
32
+ drawRect(tilePos, vec2(1), RED);
33
+
34
+ // draw hit point and normal
35
+ drawRect(hit, vec2(.2), GREEN);
36
+ drawLine(cameraPos, hit, .1, RED);
37
+ drawLine(hit, hit.add(normal), .1, YELLOW);
38
+ }
39
+ }
Binary file
@@ -9,9 +9,10 @@ class GameObject extends EngineObject
9
9
  render()
10
10
  {
11
11
  // adjust draw postion to be at the bottom of the object
12
- const offset = vec2(0,this.size.y/2).rotate(this.angle);
12
+ const drawSize = this.drawSize || this.size;
13
+ const offset = this.getUp(drawSize.y/2);
13
14
  const pos = this.pos.add(offset);
14
- drawTile(pos, this.size, this.tileInfo, this.color, this.angle);
15
+ drawTile(pos, drawSize, this.tileInfo, this.color, this.angle);
15
16
  }
16
17
  }
17
18
 
@@ -24,6 +25,7 @@ class Player extends GameObject
24
25
  // apply movement controls
25
26
  const moveInput = keyDirection().clampLength(1).scale(.2);
26
27
  this.velocity = this.velocity.add(moveInput);
28
+ this.setCollision(); // make object collide
27
29
 
28
30
  // move camera with player
29
31
  cameraPos = this.pos.add(vec2(0,2));
@@ -34,7 +36,8 @@ function gameInit()
34
36
  {
35
37
  // setup level
36
38
  objectDefaultDamping = .7;
37
- new Player(vec2(), vec2(3), tile(5), 0, RED);
39
+ const player = new Player(vec2(), vec2(3,1), tile(5), 0, RED);
40
+ player.drawSize = vec2(3);
38
41
 
39
42
  // create background objects
40
43
  for (let i=1; i<300; ++i)
@@ -49,8 +52,13 @@ function gameInit()
49
52
  for (let i=1; i<1e3; ++i)
50
53
  {
51
54
  const pos = randInCircle(7+i,7);
52
- const size = vec2(rand(1,2),rand(4,9));
53
- const color = hsl(.1,.5,rand(.2,.3));
54
- new GameObject(pos, size, 0, 0, color);
55
+ const isRock = randBool();
56
+ const size = vec2(isRock ? rand(2,4) : rand(1,2));
57
+ const color = hsl(.1,isRock ? 0 : .5,rand(.2,.3));
58
+ const o = new GameObject(pos, size, 0, 0, color);
59
+ o.setCollision(); // make object collide
60
+ o.mass = 0; // make object have static physics
61
+ o.angle = rand(-.1,.1); // random tilt
62
+ o.drawSize = vec2(size.x, isRock ? rand(2,4) : rand(5,10));
55
63
  }
56
64
  }
@@ -32,7 +32,7 @@ function gameInit()
32
32
  {
33
33
  const pos = randInCircle(15+i,7);
34
34
  const size = vec2(rand(4,9),rand(4,9));
35
- const color = hsl(.1,.5,rand(.2,.3));
35
+ const color = hsl(.1,.5,rand(.2));
36
36
  const o = new EngineObject(pos, size, 0, 0, color);
37
37
  o.setCollision(); // make object collide
38
38
  o.mass = 0; // make object have static physics
@@ -65,16 +65,17 @@ function gameInit()
65
65
  // create particle emitter
66
66
  particleEmitter = new ParticleEmitter(
67
67
  vec2(16,9), 0, // emitPos, emitAngle
68
- 0, 0, 500, PI, // emitSize, emitTime, rate, cone
68
+ 0, 0, 500, 3.14, // emitSize, emitTime, rate, cone
69
69
  tile(0, 16), // tileIndex, tileSize
70
70
  hsl(1,1,1), hsl(0,0,0), // colorStartA, colorStartB
71
71
  hsl(0,0,0,0), hsl(0,0,0,0), // colorEndA, colorEndB
72
- 2, .2, .2, .1, .05, // time, sizeStart, sizeEnd, speed, angleSpeed
73
- .99, 1, 1, PI, // damping, angleDamping, gravityScale, cone
74
- .05, .5, true, true // fadeRate, randomness, collide, additive
72
+ 1, .2, .2, .1, .05, // time, sizeStart, sizeEnd, speed, angleSpeed
73
+ .99, 1, 1, 3.14, // damping, angleDamping, gravityScale, cone
74
+ .05, .5, true, true // fadeRate, randomness, collide, additive
75
75
  );
76
76
  particleEmitter.restitution = .3; // bounce when it collides
77
- particleEmitter.trailScale = 2; // stretch as it moves
77
+ particleEmitter.trailScale = 2; // stretch as it moves
78
+ particleEmitter.velocityInheritance = .3; // inherit emitter velocity
78
79
  }
79
80
 
80
81
  ///////////////////////////////////////////////////////////////////////////////
@@ -104,10 +105,7 @@ function gameUpdate()
104
105
 
105
106
  // move particles to mouse location if on screen
106
107
  if (mousePosScreen.x)
107
- {
108
108
  particleEmitter.pos = mousePos;
109
- particleEmitter.velocity = mouseDelta.scale(.3*timeDelta);
110
- }
111
109
  }
112
110
 
113
111
  ///////////////////////////////////////////////////////////////////////////////
@@ -7,7 +7,7 @@
7
7
  </head><body>
8
8
 
9
9
  <!-- LittleJS Engine -->
10
- <script src=../../dist/littlejs.js?11416></script>
10
+ <script src=../../dist/littlejs.js?1.14.24></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?11416></script>
34
+ <script src=game.js?1.14.24></script>
@@ -73,6 +73,7 @@ iframe
73
73
  margin: 5px;
74
74
  text-align: center;
75
75
  font-size: 40px;
76
+ font-weight: bold;
76
77
  }
77
78
  #exampleInfo
78
79
  {
@@ -52,16 +52,17 @@ function gameInit() {
52
52
  LJS.setGravity(vec2(0, -.01));
53
53
  // create particle emitter
54
54
  particleEmitter = new LJS.ParticleEmitter(vec2(16, 9), 0, // emitPos, emitAngle
55
- 1, 0, 500, Math.PI, // emitSize, emitTime, rate, cone
55
+ 0, 0, 500, 3.14, // emitSize, emitTime, rate, cone
56
56
  tile(0, 16), // tileIndex, tileSize
57
57
  hsl(1, 1, 1), hsl(0, 0, 0), // colorStartA, colorStartB
58
58
  hsl(0, 0, 0, 0), hsl(0, 0, 0, 0), // colorEndA, colorEndB
59
- 2, .2, .2, .1, .05, // time, sizeStart, sizeEnd, speed, angleSpeed
60
- .99, 1, 1, Math.PI, // damping, angleDamping, gravityScale, cone
59
+ 1, .2, .2, .1, .05, // time, sizeStart, sizeEnd, speed, angleSpeed
60
+ .99, 1, 1, 3.14, // damping, angleDamping, gravityScale, cone
61
61
  .05, .5, true, true // fadeRate, randomness, collide, additive
62
62
  );
63
63
  particleEmitter.restitution = .3; // bounce when it collides
64
- particleEmitter.trailScale = 2; // stretch as it moves
64
+ particleEmitter.trailScale = 2; // stretch as it moves
65
+ particleEmitter.velocityInheritance = .3; // inherit emitter velocity
65
66
  }
66
67
  ///////////////////////////////////////////////////////////////////////////////
67
68
  function gameUpdate() {
@@ -69,16 +69,17 @@ function gameInit()
69
69
  // create particle emitter
70
70
  particleEmitter = new LJS.ParticleEmitter(
71
71
  vec2(16,9), 0, // emitPos, emitAngle
72
- 1, 0, 500, Math.PI, // emitSize, emitTime, rate, cone
72
+ 0, 0, 500, 3.14, // emitSize, emitTime, rate, cone
73
73
  tile(0, 16), // tileIndex, tileSize
74
74
  hsl(1,1,1), hsl(0,0,0), // colorStartA, colorStartB
75
75
  hsl(0,0,0,0), hsl(0,0,0,0), // colorEndA, colorEndB
76
- 2, .2, .2, .1, .05, // time, sizeStart, sizeEnd, speed, angleSpeed
77
- .99, 1, 1, Math.PI, // damping, angleDamping, gravityScale, cone
78
- .05, .5, true, true // fadeRate, randomness, collide, additive
76
+ 1, .2, .2, .1, .05, // time, sizeStart, sizeEnd, speed, angleSpeed
77
+ .99, 1, 1, 3.14, // damping, angleDamping, gravityScale, cone
78
+ .05, .5, true, true // fadeRate, randomness, collide, additive
79
79
  );
80
80
  particleEmitter.restitution = .3; // bounce when it collides
81
81
  particleEmitter.trailScale = 2; // stretch stretch as it moves
82
+ particleEmitter.velocityInheritance = .3; // inherit emitter velocity
82
83
  }
83
84
 
84
85
  ///////////////////////////////////////////////////////////////////////////////
@@ -101,10 +102,7 @@ function gameUpdate()
101
102
 
102
103
  // move particles to mouse location if on screen
103
104
  if (LJS.mousePosScreen.x)
104
- {
105
105
  particleEmitter.pos = LJS.mousePos;
106
- particleEmitter.velocity = LJS.mouseDelta.scale(.3*LJS.timeDelta);
107
- }
108
106
  }
109
107
 
110
108
  ///////////////////////////////////////////////////////////////////////////////
@@ -24,6 +24,7 @@ function createUI()
24
24
  LJS.uiSystem.defaultSoundPress = new LJS.Sound([.5,0,220]);
25
25
  LJS.uiSystem.defaultSoundClick = new LJS.Sound([.5,0,440]);
26
26
  LJS.uiSystem.defaultCornerRadius = 8;
27
+ LJS.uiSystem.defaultGradientColor = LJS.WHITE;
27
28
 
28
29
  // setup root to attach all ui elements to
29
30
  uiRoot = new LJS.UIObject;
@@ -63,7 +64,7 @@ function createUI()
63
64
  // example button
64
65
  const button1 = new LJS.UIButton(vec2(0,140), vec2(350, 50), 'Test Button');
65
66
  uiMenu.addChild(button1);
66
- button1.onClick = ()=> uiBackground.color = hsl(Math.random(),1,.7);
67
+ button1.onClick = ()=> uiBackground.color = hsl(LJS.rand(),1,.7);
67
68
 
68
69
  // example checkbox
69
70
  const checkbox = new LJS.UICheckbox(vec2(-140,-20), vec2(40));
@@ -113,7 +114,7 @@ function gameRender()
113
114
  // test game rendering
114
115
  for (let i=0; i<1e3; ++i)
115
116
  {
116
- const pos = vec2(30*Math.sin(i+LJS.time/9),20*Math.sin(i*i+LJS.time/9));
117
+ const pos = vec2(30*LJS.sin(i+LJS.time/9),20*LJS.sin(i*i+LJS.time/9));
117
118
  LJS.drawTile(pos, vec2(2), tile(3,128), hsl(i/9,1,.4), LJS.time+i, !(i%2), hsl(i/9,1,.1,0));
118
119
  }
119
120
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "littlejsengine",
3
- "version": "1.14.16",
3
+ "version": "1.14.23",
4
4
  "description": "LittleJS - Tiny and Fast HTML5 Game Engine",
5
5
  "main": "dist/littlejs.esm.js",
6
6
  "types": "dist/littlejs.d.ts",