littlejsengine 1.14.11 → 1.14.16

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 (74) hide show
  1. package/dist/littlejs.d.ts +252 -109
  2. package/dist/littlejs.esm.js +559 -252
  3. package/dist/littlejs.esm.min.js +1 -1
  4. package/dist/littlejs.js +557 -251
  5. package/dist/littlejs.min.js +1 -1
  6. package/dist/littlejs.release.js +482 -206
  7. package/examples/box2d/gameObjects.js +2 -2
  8. package/examples/breakout/gameObjects.js +2 -2
  9. package/examples/breakoutTutorial/README.md +32 -32
  10. package/examples/breakoutTutorial/game.js +1 -1
  11. package/examples/electron/game.js +3 -3
  12. package/examples/electron/index.html +2 -2
  13. package/examples/electron/package.json +1 -8
  14. package/examples/index.html +10 -7
  15. package/examples/module/game.js +3 -3
  16. package/examples/platformer/gameEffects.js +4 -4
  17. package/examples/platformer/gameLevel.js +1 -1
  18. package/examples/platformer/gameObjects.js +4 -4
  19. package/examples/puzzle/game.js +1 -1
  20. package/examples/shorts/animation.js +1 -1
  21. package/examples/shorts/base.html +1 -1
  22. package/examples/shorts/blending.js +8 -14
  23. package/examples/shorts/box2d.js +7 -3
  24. package/examples/shorts/box2dCar.js +2 -1
  25. package/examples/shorts/empty.js +30 -0
  26. package/examples/shorts/helloWorld.js +1 -1
  27. package/examples/shorts/hillGlideGame.js +10 -4
  28. package/examples/shorts/landerGame.js +11 -8
  29. package/examples/shorts/medals.js +4 -4
  30. package/examples/shorts/music.js +29 -56
  31. package/examples/shorts/musicPlayer.js +134 -0
  32. package/examples/shorts/nineSlice.js +34 -15
  33. package/examples/shorts/parallax.js +4 -3
  34. package/examples/shorts/particles.js +15 -15
  35. package/examples/shorts/piano.js +15 -21
  36. package/examples/shorts/pongGame.js +6 -4
  37. package/examples/shorts/raycasting.js +9 -4
  38. package/examples/shorts/sequencer.js +122 -0
  39. package/examples/shorts/shapes.js +7 -4
  40. package/examples/shorts/slidingPuzzle.js +4 -2
  41. package/examples/shorts/sound.js +18 -9
  42. package/examples/shorts/spaceGame.js +12 -8
  43. package/examples/shorts/spriteAtlas.js +7 -7
  44. package/examples/shorts/starfield.js +1 -1
  45. package/examples/shorts/systemFont.js +2 -2
  46. package/examples/shorts/texture.js +2 -2
  47. package/examples/shorts/tileLayer.js +10 -10
  48. package/examples/shorts/tiltedView.js +14 -3
  49. package/examples/shorts/timers.js +10 -0
  50. package/examples/shorts/topDown.js +4 -1
  51. package/examples/shorts/uiSystem.js +8 -5
  52. package/examples/starter/game.js +3 -3
  53. package/examples/starter/index.html +2 -2
  54. package/examples/typescript/game.js +3 -3
  55. package/examples/typescript/game.ts +3 -3
  56. package/examples/uiSystem/game.js +3 -3
  57. package/package.json +4 -2
  58. package/plugins/box2d.js +17 -2
  59. package/plugins/newgrounds.js +7 -5
  60. package/plugins/postProcess.js +5 -2
  61. package/plugins/uiSystem.js +120 -34
  62. package/plugins/zzfxm.js +5 -1
  63. package/reference.md +1 -1
  64. package/src/engine.js +35 -12
  65. package/src/engineAudio.js +31 -14
  66. package/src/engineDebug.js +75 -45
  67. package/src/engineDraw.js +60 -31
  68. package/src/engineExport.js +2 -1
  69. package/src/engineMedals.js +10 -2
  70. package/src/engineObject.js +14 -10
  71. package/src/engineParticles.js +59 -46
  72. package/src/engineSettings.js +7 -7
  73. package/src/engineTileLayer.js +45 -20
  74. package/src/engineUtilities.js +67 -20
@@ -0,0 +1,122 @@
1
+ const stepCount = 8, trackCount = 12, sequencer = [];
2
+ let currentStep = 0, stepTime = 0, tempo = 240;
3
+ let isPlaying = false, eraseMode = false;
4
+
5
+ // sound sequencer instruments
6
+ const sound_piano = new Sound([.4,0,220,,.1]);
7
+ const sound_drumKick = new Sound([,,99,,,.02,,,,,,,,2]);
8
+ const sound_drumHat = new Sound([,,1e3,,,.01,4,,,,,,,,,,,,,,4e3]);
9
+
10
+ // musical note scales
11
+ const majorScale = [0,2,4,5,7,9,11];
12
+ const minorScale = [0,2,3,5,7,8,10];
13
+ const pentatonicScale = [0,3,5,7,10];
14
+ const scale = majorScale;
15
+
16
+ class UISequencerButton extends UIButton
17
+ {
18
+ constructor(step, track)
19
+ {
20
+ const size = vec2(68, 35);
21
+ let pos = vec2(step, trackCount-1-track);
22
+ pos = pos.multiply(size);
23
+ pos = pos.add(vec2(240, 40));
24
+ super(pos, size);
25
+
26
+ this.step = step;
27
+ this.track = track;
28
+ this.cornerRadius = 0;
29
+ this.dragActivate = true;
30
+ this.isOn = false;
31
+
32
+ // set instrument and color based on track
33
+ const pianoStart = 2;
34
+ this.hue = track*.15;
35
+ if (track >= pianoStart)
36
+ {
37
+ const octave = Math.floor((track-pianoStart) / scale.length);
38
+ const scaleNote = (track-pianoStart) % scale.length;
39
+ this.semitone = scale[scaleNote] + 12*octave;
40
+ this.sound = sound_piano;
41
+ this.hue = .6 - scaleNote/40 + octave*.2;
42
+ }
43
+ else
44
+ this.sound = [sound_drumKick, sound_drumHat][track];
45
+ }
46
+ onPress()
47
+ {
48
+ // set the button on/off and update sequencer table
49
+ if (mouseWasPressed(0))
50
+ eraseMode = this.isOn;
51
+ this.isOn = !eraseMode;
52
+ eraseMode || this.playSound();
53
+ const index = this.step + this.track*stepCount;
54
+ sequencer[index] = eraseMode ? 0 : this;
55
+ }
56
+ render()
57
+ {
58
+ this.activeColor = eraseMode ? RED : WHITE;
59
+ this.color = this.isActiveObject() ? BLACK :
60
+ hsl(this.hue, this.isOn ? 1 : .5, this.isOn ? .5 : .1);
61
+ if (isPlaying && this.step == currentStep)
62
+ this.color = this.color.lerp(WHITE, .5);
63
+ super.render();
64
+ }
65
+ playSound() { this.sound.playNote(this.semitone); }
66
+ }
67
+
68
+ function gameInit()
69
+ {
70
+ // initialize UI system
71
+ new UISystemPlugin;
72
+ uiSystem.defaultCornerRadius = 8;
73
+ canvasClearColor = hsl(0,0,.3);
74
+
75
+ // create sequencer buttons
76
+ for (let step=stepCount; step--;)
77
+ for (let track=trackCount; track--;)
78
+ new UISequencerButton(step, track);
79
+
80
+ // create play/stop button
81
+ const playButton = new UIButton(vec2(660,500), vec2(180,60), 'PLAY');
82
+ playButton.onClick = ()=>
83
+ {
84
+ isPlaying = !isPlaying;
85
+ currentStep = stepTime = 0;
86
+ playButton.text = isPlaying ? 'STOP' : 'PLAY';
87
+ };
88
+
89
+ // create tempo slider
90
+ const minTempo = 120, maxTempo = 480;
91
+ const tempoPercent = percent(tempo, minTempo, maxTempo);
92
+ const tempoSlider = new UIScrollbar(vec2(380,500), vec2(340,40), tempoPercent);
93
+ tempoSlider.onChange = ()=>
94
+ {
95
+ tempo = lerp(minTempo, maxTempo, tempoSlider.value);
96
+ tempo = Math.floor(tempo/10) * 10; // round to nearest 10th
97
+ tempoSlider.text = `${tempo} BPM`;
98
+ };
99
+ tempoSlider.onChange();
100
+ }
101
+
102
+ function gameUpdate()
103
+ {
104
+ if (!isPlaying)
105
+ return;
106
+
107
+ // update step time based on tempo
108
+ const lastStepTime = stepTime;
109
+ const lastStep = currentStep;
110
+ stepTime += timeDelta*tempo/60;
111
+ currentStep = Math.floor(stepTime) % stepCount;
112
+ if (currentStep == lastStep && lastStepTime)
113
+ return;
114
+
115
+ // play sounds when step changes
116
+ for (let i=trackCount; i--;)
117
+ {
118
+ const index = currentStep + i*stepCount;
119
+ const noteButton = sequencer[index];
120
+ noteButton && noteButton.playSound();
121
+ }
122
+ }
@@ -7,12 +7,15 @@ function gameRender()
7
7
 
8
8
  // polygon shapes
9
9
  drawRectGradient(vec2(-6,0), vec2(5,4), RED, BLUE)
10
- drawRegularPoly(vec2(0,0), vec2(4), 3, PURPLE, .2, WHITE, time);
11
- const starPath = [vec2(0,2), vec2(2,-2), vec2(-3,.5), vec2(3,.5), vec2(-2,-2), vec2(0,2)];
12
- drawLineList(starPath, .2, GREEN, true, vec2(6, 0));
10
+ drawRegularPoly(vec2(0,0), vec2(4), 3, PURPLE, .3, WHITE, time);
11
+ let starPath = []
12
+ for (let i=10; i--;)
13
+ starPath.push(vec2(0,2*(i%2?.4:1)).rotate(i/10*PI*2));
14
+ drawPoly(starPath, BLUE, .1, GREEN, vec2(6, 0));
13
15
 
14
16
  // rects and lines
15
17
  drawRect(vec2(0,-5), vec2(4,3), ORANGE, time);
16
18
  drawLine(vec2(-5,-7), vec2(5,-3), 1, hsl(0,0,1,.5));
17
- drawLineList([vec2(5,-3), vec2(-5,-3), vec2(5,-7), vec2(-5,-7)], .2, MAGENTA);
19
+ const zPath = [vec2(5,-3), vec2(-5,-3), vec2(5,-7), vec2(-5,-7)];
20
+ drawLineList(zPath, .4, MAGENTA);
18
21
  }
@@ -19,7 +19,8 @@ class PuzzlePiece extends EngineObject
19
19
  {
20
20
  const deltaX = emptyGridPos.x - this.gridPos.x;
21
21
  const deltaY = emptyGridPos.y - this.gridPos.y;
22
- if (mouseWasPressed(0) && isOverlapping(this.pos, this.size, mousePos))
22
+ if (mouseWasPressed(0))
23
+ if (isOverlapping(this.pos, this.size, mousePos))
23
24
  if (abs(deltaX) + abs(deltaY) === 1)
24
25
  {
25
26
  // swap with empty space when clicked on
@@ -32,7 +33,8 @@ class PuzzlePiece extends EngineObject
32
33
 
33
34
  render()
34
35
  {
35
- const pos = this.lastPos.lerp(this.pos, this.moveTimer.getPercent());
36
+ const movePercent = this.moveTimer.getPercent();
37
+ const pos = this.lastPos.lerp(this.pos, movePercent);
36
38
  drawRect(pos, this.size, this.color);
37
39
  drawTextOverlay(this.text, pos, 2.5, BLACK);
38
40
  }
@@ -14,13 +14,22 @@ function gameInit()
14
14
  button.textHeight = 100;
15
15
  button.onClick = ()=> sound.play();
16
16
  }
17
- makeSoundButton(vec2(-1, 1),'💰', new Sound([,,1675,,.06,.24,1,1.82,,,837,.06]));
18
- makeSoundButton(vec2( 0, 1),'🥊', new Sound([,,925,.04,.3,.6,1,.3,,6.27,-184,.09,.17]));
19
- makeSoundButton(vec2( 1, 1),'✨', new Sound([,,539,0,.04,.29,1,1.92,,,567,.02,.02,,,,.04]));
20
- makeSoundButton(vec2(-1, 0),'🐁', new Sound([,.2,1e3,.02,,.01,2,,18,,475,.01,.01]));
21
- makeSoundButton(vec2( 0, 0),'🎹', new Sound([1.5,.5,270,,.1,,1,1.5,,,,,,,,.1,.01]));
22
- makeSoundButton(vec2( 1, 0),'🏌️', new Sound([,,150,.05,,.05,,1.3,,,,,,3]));
23
- makeSoundButton(vec2(-1,-1),'🌊', new Sound([,.2,40,.5,,1.5,,11,,,,,,199]));
24
- makeSoundButton(vec2( 0,-1),'🛰️', new Sound([,.5,847,.02,.3,.9,1,1.67,,,-294,.04,.13,,,,.1]));
25
- makeSoundButton(vec2( 1,-1),'⚡', new Sound([,,471,,.09,.47,4,1.06,-6.7,,,,,.9,61,.1,,.82,.1]));
17
+ makeSoundButton(vec2(-1, 1),'💰',
18
+ new Sound([,,1675,,.06,.24,1,1.82,,,837,.06]));
19
+ makeSoundButton(vec2( 0, 1),'🥊',
20
+ new Sound([,,925,.04,.3,.6,1,.3,,6.27,-184,.09,.17]));
21
+ makeSoundButton(vec2( 1, 1),'✨',
22
+ new Sound([,,539,0,.04,.29,1,1.92,,,567,.02,.02,,,,.04]));
23
+ makeSoundButton(vec2(-1, 0),'🐁',
24
+ new Sound([,.2,1e3,.02,,.01,2,,18,,475,.01,.01]));
25
+ makeSoundButton(vec2( 0, 0),'🎹',
26
+ new Sound([1.5,.5,270,,.1,,1,1.5,,,,,,,,.1,.01]));
27
+ makeSoundButton(vec2( 1, 0),'🏌️',
28
+ new Sound([,,150,.05,,.05,,1.3,,,,,,3]));
29
+ makeSoundButton(vec2(-1,-1),'🌊',
30
+ new Sound([,.2,40,.5,,1.5,,11,,,,,,199]));
31
+ makeSoundButton(vec2( 0,-1),'🛰️',
32
+ new Sound([,.5,847,.02,.3,.9,1,1.67,,,-294,.04,.13,,,,.1]));
33
+ makeSoundButton(vec2( 1,-1),'⚡',
34
+ new Sound([,,471,,.09,.47,4,1.06,-6.7,,,,,.9,61,.1,,.82,.1]));
26
35
  }
@@ -15,13 +15,16 @@ class Player extends EngineObject
15
15
  // space ship controls
16
16
  const moveInput = keyDirection();
17
17
  this.applyAngularAcceleration(moveInput.x * .005);
18
- this.applyAcceleration(vec2().setAngle(this.angle, moveInput.y*.02));
19
- if (!this.shootTimer.active() && (keyIsDown('Space') || mouseIsDown(0)))
18
+ const accel = vec2().setAngle(this.angle, moveInput.y*.02);
19
+ this.applyAcceleration(accel);
20
+ if (!this.shootTimer.active())
21
+ if (keyIsDown('Space') || mouseIsDown(0))
20
22
  {
21
23
  // shoot bullet
22
24
  const pos = this.pos.add(vec2(0,1).rotate(cameraAngle));
23
- const bullet = new EngineObject(pos, vec2(.2,.5), 0, this.angle, YELLOW);
24
- bullet.velocity = this.velocity.add(vec2(0,.5).rotate(this.angle));
25
+ const bullet = new EngineObject(pos, vec2(.2,.5), 0, this.angle);
26
+ bullet.velocity = vec2(0,.5).rotate(this.angle);
27
+ bullet.velocity = bullet.velocity.add(this.velocity);
25
28
  this.shootTimer.set(.1);
26
29
  }
27
30
 
@@ -42,14 +45,15 @@ function gameRender()
42
45
  const range = 32, halfRange = range/2;
43
46
 
44
47
  // precreate variables to avoid overhead
45
- const pos = vec2(), size = vec2(), color = WHITE;
48
+ const pos = vec2(), size = vec2(), color = rgb();
49
+ const x = cameraPos.x, y = cameraPos.y;
46
50
  for (let i=1e3; i--;)
47
51
  {
48
52
  // use math to generate random star positions
49
53
  const parallax = i%.13-1;
50
- pos.x = mod(i**2.1 + cameraPos.x*parallax, range) + cameraPos.x - halfRange;
51
- pos.y = mod(i**3.1 + cameraPos.y*parallax, range) + cameraPos.y - halfRange;
52
- size.x = size.y = i%.07+.03;
54
+ pos.x = mod(i**2.1 + x*parallax, range) + x - halfRange;
55
+ pos.y = mod(i**3.1 + y*parallax, range) + y - halfRange;
56
+ size.x = size.y = i%.07 + .03;
53
57
  color.a = .1+i%.9;
54
58
  drawRect(pos, size, color);
55
59
  }
@@ -1,5 +1,4 @@
1
1
  let spriteAtlas;
2
- canvasClearColor = GRAY;
3
2
 
4
3
  function gameInit()
5
4
  {
@@ -13,18 +12,19 @@ function gameInit()
13
12
  circleBig: gameTile(2, 128),
14
13
  iconBig: gameTile(3, 128),
15
14
  };
15
+ canvasClearColor = GRAY;
16
16
  }
17
17
 
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 to draw
22
- let angle = 0; // world space angle to draw the tile
23
- let size = vec2(9); // world size of the tile
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
24
  let mirror = 0; // should tile be mirrored?
25
- let color = hsl(0,0,1); // color to multiply the tile by
26
- let additiveColor = hsl(0,0,0,0); // color to add to
27
- drawTile(pos, size, spriteAtlas.iconBig, color, angle, mirror, additiveColor);
25
+ let color = hsl(0,0,1); // color to multiply by
26
+ let additive = hsl(0,0,0,0); // color to add to
27
+ drawTile(pos, size, spriteAtlas.iconBig, color, angle, mirror, additive);
28
28
 
29
29
  // draw more sprites from the atlas
30
30
  drawTile(vec2(-7,4), vec2(5), spriteAtlas.crate);
@@ -1,7 +1,7 @@
1
1
  function gameRender()
2
2
  {
3
3
  // precreate variables to avoid overhead
4
- const pos = vec2(), size = vec2(), color = new Color;
4
+ const pos = vec2(), size = vec2(), color = rgb();
5
5
  for (let i=2e3; i--;)
6
6
  {
7
7
  // use math to generate random star positions
@@ -2,7 +2,7 @@ function gameRender()
2
2
  {
3
3
  // draw text with built in font image system font
4
4
  const font = new FontImage;
5
- font.drawText('System Font Test', cameraPos.add(vec2(0,3)), .2, true);
5
+ font.drawText('System Font Test', cameraPos.add(vec2(0,3)), .2);
6
6
 
7
7
  // show every character in the system font
8
8
  let s = '';
@@ -12,5 +12,5 @@ function gameRender()
12
12
  s += '\n';
13
13
  s += String.fromCharCode(i);
14
14
  }
15
- font.drawText(s, cameraPos, .1, true);
15
+ font.drawText(s, cameraPos, .1);
16
16
  }
@@ -4,8 +4,8 @@ function gameRender()
4
4
  let pos = vec2(0,0); // world position to draw
5
5
  let size = vec2(15); // world size of the tile
6
6
  let color = hsl(0,0,1); // color to multiply the tile by
7
- let tilePos = vec2(0,0); // top left corner of tile in pixels
8
- let tileSize = vec2(256); // size of tile in pixels
7
+ let tilePos = vec2(0,0); // top left corner in pixels
8
+ let tileSize = vec2(256); // source size in pixels
9
9
  let tileInfo = new TileInfo(tilePos, tileSize); // tile info
10
10
  drawRect(pos, size, GRAY); // draw background
11
11
  drawTile(pos, size, tileInfo, color);
@@ -30,19 +30,19 @@ function gameUpdate()
30
30
  {
31
31
  if (mouseWasPressed(0))
32
32
  {
33
- // create particle emitter
33
+ // create particle emitter to test the collision
34
34
  const hue = rand();
35
35
  const particleEmitter = new ParticleEmitter(
36
- mousePos, 0, // emitPos, emitAngle
37
- 0, 0.1, 500, PI, // emitSize, emitTime, emitRate, emitCone
38
- tile(0, 16), // tileIndex, tileSize
39
- hsl(hue,1,.5), hsl(hue,1,1), // colorStartA, colorStartB
40
- hsl(hue,1,.5,0), hsl(hue,1,1,0), // colorEndA, colorEndB
41
- 2, .2, .2, .2, .05, // time, sizeStart, sizeEnd, speed, angleSpeed
42
- .99, 1, 1, PI, // damping, angleDamping, gravityScale, cone
43
- .05, .8, true, false // fadeRate, randomness, collide, additive
36
+ mousePos, 0,
37
+ 0, 0.1, 500, PI,
38
+ tile(0, 16),
39
+ hsl(hue,1,.5), hsl(hue,1,1),
40
+ hsl(hue,1,.5,0), hsl(hue,1,1,0),
41
+ 2, .2, .2, .2, .05,
42
+ .99, 1, 1, PI,
43
+ .05, .8, true
44
44
  );
45
45
  particleEmitter.restitution = .5; // bounce when it collides
46
- particleEmitter.trailScale = 2; // stretch in direction of motion
46
+ particleEmitter.trailScale = 2; // stretch as it moves
47
47
  }
48
48
  }
@@ -9,7 +9,8 @@ class GameObject extends EngineObject
9
9
  render()
10
10
  {
11
11
  // adjust draw postion to be at the bottom of the object
12
- const pos = this.pos.add(vec2(0,this.size.y/2).rotate(this.angle));
12
+ const offset = vec2(0,this.size.y/2).rotate(this.angle);
13
+ const pos = this.pos.add(offset);
13
14
  drawTile(pos, this.size, this.tileInfo, this.color, this.angle);
14
15
  }
15
16
  }
@@ -37,9 +38,19 @@ function gameInit()
37
38
 
38
39
  // create background objects
39
40
  for (let i=1; i<300; ++i)
40
- new EngineObject(randInCircle(90), vec2(rand(59),rand(59)), 0, 0, hsl(.4,.2,rand(.4,.5),.8), -1e5);
41
+ {
42
+ const pos = randInCircle(90);
43
+ const size = vec2(rand(59), rand(59));
44
+ const color = hsl(.4,.2,rand(.4,.5),.8);
45
+ new EngineObject(pos, size, 0, 0, color, -1e5);
46
+ }
41
47
 
42
48
  // create world objects
43
49
  for (let i=1; i<1e3; ++i)
44
- new GameObject(randInCircle(7+i,7), vec2(rand(1,2),rand(4,9)), 0, 0, hsl(.1,.5,rand(.2,.3)));
50
+ {
51
+ 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
+ }
45
56
  }
@@ -1,4 +1,5 @@
1
1
  let timerButton, timerSlider;
2
+ let timerSound = new Sound([2,0,999,,,,,1.5,,.3,-99,.1,1.63,,,.11]);
2
3
 
3
4
  function gameInit()
4
5
  {
@@ -13,13 +14,16 @@ function gameInit()
13
14
  timerButton.timer = new Timer;
14
15
  timerButton.onClick = ()=>
15
16
  {
17
+ timerButton.isSet = true;
16
18
  if (timerButton.timer.isSet())
17
19
  {
20
+ timerSound.play(0, .5, 2);
18
21
  timerButton.timer.unset();
19
22
  timerButton.text = 'Start';
20
23
  }
21
24
  else
22
25
  {
26
+ timerSound.play(0, .5, .5);
23
27
  timerButton.timer.set(3);
24
28
  timerButton.text = 'Stop';
25
29
  }
@@ -30,6 +34,12 @@ function gameInit()
30
34
  timerSlider.interactive = false;
31
35
  timerSlider.update = ()=>
32
36
  {
37
+ if (timerButton.isSet && timerButton.timer.elapsed())
38
+ {
39
+ timerSound.play();
40
+ timerButton.isSet = 0;
41
+ }
42
+
33
43
  // update the timer display
34
44
  const t = timerButton.timer.get();
35
45
  const timeText = t.toFixed(2) + 's';
@@ -30,7 +30,10 @@ function gameInit()
30
30
  // create collision objects
31
31
  for (let i=300; i--;)
32
32
  {
33
- const o = new EngineObject(randInCircle(15+i,7), vec2(rand(4,9),rand(4,9)), 0, 0, hsl(0,0,rand(.1,.3)));
33
+ const pos = randInCircle(15+i,7);
34
+ const size = vec2(rand(4,9),rand(4,9));
35
+ const color = hsl(.1,.5,rand(.2,.3));
36
+ const o = new EngineObject(pos, size, 0, 0, color);
34
37
  o.setCollision(); // make object collide
35
38
  o.mass = 0; // make object have static physics
36
39
  }
@@ -2,12 +2,13 @@ function gameInit()
2
2
  {
3
3
  // setup ui system plugin
4
4
  new UISystemPlugin;
5
- uiSystem.defaultSoundPress = new Sound([1,0,220]);
6
- uiSystem.defaultSoundClick = new Sound([1,0,440]);
5
+ uiSystem.defaultSoundPress = new Sound([.5,0,220]);
6
+ uiSystem.defaultSoundClick = new Sound([.5,0,440]);
7
7
  uiSystem.defaultCornerRadius = 8;
8
8
 
9
9
  // example button that returns to menu
10
- const buttonBack = new UIButton(mainCanvasSize.scale(.5), vec2(200), 'Back\nto\nMenu');
10
+ const buttonBack = new UIButton(mainCanvasSize.scale(.5), vec2(200),
11
+ 'Back\nto\nMenu');
11
12
  buttonBack.textHeight = 60;
12
13
  buttonBack.onClick = ()=> uiMenu.visible = true;
13
14
 
@@ -16,7 +17,8 @@ function gameInit()
16
17
  canvasClearColor = hsl(0,0,.8);
17
18
 
18
19
  // example text
19
- uiMenu.addChild(new UIText(vec2(-80,-120), vec2(500, 80), 'LittleJS UI\nSystem Demo'));
20
+ uiMenu.addChild(new UIText(vec2(-80,-120), vec2(500, 80),
21
+ 'LittleJS UI\nSystem Demo'));
20
22
 
21
23
  // example image
22
24
  uiMenu.addChild(new UITile(vec2(200,-140), vec2(128), tile(3, 128)));
@@ -33,7 +35,8 @@ function gameInit()
33
35
  uiMenu.addChild(checkbox);
34
36
 
35
37
  // example scrollbar
36
- const scrollbar = new UIScrollbar(vec2(0,90), vec2(300, 50), soundVolume, 'Volume');
38
+ const scrollbar = new UIScrollbar(vec2(0,90), vec2(300, 50), soundVolume,
39
+ 'Volume');
37
40
  uiMenu.addChild(scrollbar);
38
41
  scrollbar.onChange = ()=> setSoundVolume(scrollbar.value);
39
42
 
@@ -65,7 +65,7 @@ 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, emitRate, emitCone
68
+ 0, 0, 500, PI, // 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
@@ -74,7 +74,7 @@ function gameInit()
74
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 in direction of motion
77
+ particleEmitter.trailScale = 2; // stretch as it moves
78
78
  }
79
79
 
80
80
  ///////////////////////////////////////////////////////////////////////////////
@@ -86,7 +86,7 @@ function gameUpdate()
86
86
  sound_click.play(mousePos);
87
87
 
88
88
  // change particle color and set to fade out
89
- particleEmitter.colorStartA = hsl();
89
+ particleEmitter.colorStartA = randColor();
90
90
  particleEmitter.colorStartB = randColor();
91
91
  particleEmitter.colorEndA = particleEmitter.colorStartA.scale(1,0);
92
92
  particleEmitter.colorEndB = particleEmitter.colorStartB.scale(1,0);
@@ -7,7 +7,7 @@
7
7
  </head><body>
8
8
 
9
9
  <!-- LittleJS Engine -->
10
- <script src=../../dist/littlejs.js?1136></script>
10
+ <script src=../../dist/littlejs.js?11416></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?1136></script>
34
+ <script src=game.js?11416></script>
@@ -52,7 +52,7 @@ 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, emitRate, emitCone
55
+ 1, 0, 500, Math.PI, // 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
@@ -61,7 +61,7 @@ function gameInit() {
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 in direction of motion
64
+ particleEmitter.trailScale = 2; // stretch as it moves
65
65
  }
66
66
  ///////////////////////////////////////////////////////////////////////////////
67
67
  function gameUpdate() {
@@ -69,7 +69,7 @@ function gameUpdate() {
69
69
  // play sound when mouse is pressed
70
70
  sound_click.play(LJS.mousePos);
71
71
  // change particle color and set to fade out
72
- particleEmitter.colorStartA = hsl();
72
+ particleEmitter.colorStartA = LJS.randColor();
73
73
  particleEmitter.colorStartB = LJS.randColor();
74
74
  particleEmitter.colorEndA = particleEmitter.colorStartA.scale(1, 0);
75
75
  particleEmitter.colorEndB = particleEmitter.colorStartB.scale(1, 0);
@@ -69,7 +69,7 @@ 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, emitRate, emitCone
72
+ 1, 0, 500, Math.PI, // 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
@@ -78,7 +78,7 @@ function gameInit()
78
78
  .05, .5, true, true // fadeRate, randomness, collide, additive
79
79
  );
80
80
  particleEmitter.restitution = .3; // bounce when it collides
81
- particleEmitter.trailScale = 2; // stretch in direction of motion
81
+ particleEmitter.trailScale = 2; // stretch stretch as it moves
82
82
  }
83
83
 
84
84
  ///////////////////////////////////////////////////////////////////////////////
@@ -90,7 +90,7 @@ function gameUpdate()
90
90
  sound_click.play(LJS.mousePos);
91
91
 
92
92
  // change particle color and set to fade out
93
- particleEmitter.colorStartA = hsl();
93
+ particleEmitter.colorStartA = LJS.randColor();
94
94
  particleEmitter.colorStartB = LJS.randColor();
95
95
  particleEmitter.colorEndA = particleEmitter.colorStartA.scale(1,0);
96
96
  particleEmitter.colorEndB = particleEmitter.colorStartB.scale(1,0);
@@ -21,8 +21,8 @@ LJS.setCanvasPixelated(false);
21
21
 
22
22
  function createUI()
23
23
  {
24
- LJS.uiSystem.defaultSoundPress = new LJS.Sound([1,0,220]);
25
- LJS.uiSystem.defaultSoundClick = new LJS.Sound([1,0,440]);
24
+ LJS.uiSystem.defaultSoundPress = new LJS.Sound([.5,0,220]);
25
+ LJS.uiSystem.defaultSoundClick = new LJS.Sound([.5,0,440]);
26
26
  LJS.uiSystem.defaultCornerRadius = 8;
27
27
 
28
28
  // setup root to attach all ui elements to
@@ -63,7 +63,7 @@ function createUI()
63
63
  // example button
64
64
  const button1 = new LJS.UIButton(vec2(0,140), vec2(350, 50), 'Test Button');
65
65
  uiMenu.addChild(button1);
66
- button1.onClick = ()=> LOG('Button 1 clicked');
66
+ button1.onClick = ()=> uiBackground.color = hsl(Math.random(),1,.7);
67
67
 
68
68
  // example checkbox
69
69
  const checkbox = new LJS.UICheckbox(vec2(-140,-20), vec2(40));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "littlejsengine",
3
- "version": "1.14.11",
3
+ "version": "1.14.16",
4
4
  "description": "LittleJS - Tiny and Fast HTML5 Game Engine",
5
5
  "main": "dist/littlejs.esm.js",
6
6
  "types": "dist/littlejs.d.ts",
@@ -37,6 +37,8 @@
37
37
  "google-closure-compiler": "~20230502.0.0",
38
38
  "roadroller": "~2.1.0",
39
39
  "typescript": "~5.1.6",
40
- "uglify-js": "~3.17.4"
40
+ "uglify-js": "~3.17.4",
41
+ "electron": "^38.2.0",
42
+ "electron-packager": "^17.1.2"
41
43
  }
42
44
  }