littlejsengine 1.14.23 → 1.15.2

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/dist/littlejs.d.ts +184 -30
  2. package/dist/littlejs.esm.js +589 -147
  3. package/dist/littlejs.esm.min.js +1 -1
  4. package/dist/littlejs.js +583 -147
  5. package/dist/littlejs.min.js +1 -1
  6. package/dist/littlejs.release.js +546 -147
  7. package/examples/box2d/gameObjects.js +6 -10
  8. package/examples/box2d/scenes.js +2 -2
  9. package/examples/breakout/gameObjects.js +1 -1
  10. package/examples/electron/index.html +2 -2
  11. package/examples/index.html +11 -7
  12. package/examples/platformer/gameCharacter.js +3 -2
  13. package/examples/platformer/gameObjects.js +3 -8
  14. package/examples/shorts/base.html +2 -2
  15. package/examples/shorts/box2d.js +2 -2
  16. package/examples/shorts/box2dCar.js +18 -7
  17. package/examples/shorts/box2dPool.js +108 -0
  18. package/examples/shorts/debugDraw.js +2 -3
  19. package/examples/shorts/flappyGame.js +1 -0
  20. package/examples/shorts/fps.js +1 -1
  21. package/examples/shorts/hillGlideGame.js +0 -2
  22. package/examples/shorts/input.js +59 -0
  23. package/examples/shorts/landerGame.js +1 -3
  24. package/examples/shorts/medals.js +15 -9
  25. package/examples/shorts/music.js +15 -17
  26. package/examples/shorts/musicPlayer.js +24 -24
  27. package/examples/shorts/platformer.js +0 -2
  28. package/examples/shorts/slidingPuzzle.js +1 -1
  29. package/examples/shorts/song.mp3 +0 -0
  30. package/examples/shorts/spaceGame.js +0 -2
  31. package/examples/shorts/spriteAtlas.js +0 -2
  32. package/examples/shorts/tiltedView.js +0 -3
  33. package/examples/shorts/timers.js +1 -2
  34. package/examples/shorts/topDown.js +0 -2
  35. package/examples/shorts/video.webm +0 -0
  36. package/examples/shorts/videoPlayer.js +33 -0
  37. package/examples/starter/index.html +3 -3
  38. package/package.json +1 -1
  39. package/plugins/box2d.js +170 -50
  40. package/plugins/pluginExport.js +3 -0
  41. package/plugins/uiSystem.js +229 -27
  42. package/src/engine.js +21 -18
  43. package/src/engineAudio.js +14 -2
  44. package/src/engineDebug.js +37 -0
  45. package/src/engineDraw.js +21 -13
  46. package/src/engineExport.js +3 -0
  47. package/src/engineInput.js +24 -12
  48. package/src/engineMedals.js +2 -2
  49. package/src/engineObject.js +24 -4
  50. package/src/engineParticles.js +4 -6
  51. package/src/engineTileLayer.js +2 -0
  52. package/src/engineUtilities.js +35 -13
@@ -1,6 +1,5 @@
1
- let musicPlayer, playButton, stopButton, progressBar;
2
- let musicSound, music;
3
- let musicVolume = 1;
1
+
2
+ let musicVolume = 1, musicSound, musicInstance;
4
3
 
5
4
  function gameInit()
6
5
  {
@@ -13,7 +12,8 @@ function gameInit()
13
12
  canvasClearColor = hsl(.9,.3,.2);
14
13
 
15
14
  // setup music player UI
16
- musicPlayer = new UIObject(mainCanvasSize.scale(.5), vec2(500, 300));
15
+ const center = mainCanvasSize.scale(.5);
16
+ musicPlayer = new UIObject(center, vec2(500, 300));
17
17
  const title = new UIText(vec2(0, -100), vec2(500, 40),
18
18
  'LittleJS Music Player');
19
19
  musicPlayer.addChild(title);
@@ -21,7 +21,7 @@ function gameInit()
21
21
  // drop zone text
22
22
  const dropZoneText = new UIText(vec2(0, -60), vec2(450, 20),
23
23
  'Drag & Drop Audio Files Here!');
24
- dropZoneText.textColor = hsl(.9, .3, .8, .7);
24
+ dropZoneText.textColor = GRAY;
25
25
  musicPlayer.addChild(dropZoneText);
26
26
 
27
27
  // volume slider
@@ -31,8 +31,7 @@ function gameInit()
31
31
  volumeSlider.onChange = () =>
32
32
  {
33
33
  musicVolume = volumeSlider.value;
34
- if (music)
35
- music.setVolume(musicVolume);
34
+ musicInstance?.setVolume(musicVolume);
36
35
  };
37
36
 
38
37
  // play button
@@ -44,17 +43,17 @@ function gameInit()
44
43
  return;
45
44
 
46
45
  // handle play/pause toggle
47
- if (!music)
48
- music = musicSound.playMusic(musicVolume);
49
- else if (music.isPaused())
50
- music.resume();
46
+ if (!musicInstance)
47
+ musicInstance = musicSound.playMusic(musicVolume);
48
+ else if (musicInstance.isPaused())
49
+ musicInstance.resume();
51
50
  else
52
- music.pause();
51
+ musicInstance.pause();
53
52
  };
54
53
 
55
54
  // stop button
56
55
  stopButton = new UIButton(vec2(90, 50), vec2(140, 50), 'Stop');
57
- stopButton.onClick = ()=> music && music.stop();
56
+ stopButton.onClick = ()=> musicInstance?.stop();
58
57
  musicPlayer.addChild(stopButton);
59
58
 
60
59
  // progress bar and scrollbar for seeking
@@ -63,14 +62,14 @@ function gameInit()
63
62
  progressBar.onChange = ()=>
64
63
  {
65
64
  // control music seek position
66
- const wasPlaying = music && music.isPlaying();
67
- if (!music)
68
- music = musicSound.playMusic(musicVolume, true, true);
65
+ const wasPlaying = musicInstance?.isPlaying();
66
+ if (!musicInstance)
67
+ musicInstance = musicSound.playMusic(musicVolume, 1, 1);
69
68
  progressBar.value = min(progressBar.value, .999); // prevent wrap
70
69
  const seekTime = progressBar.value * musicSound.getDuration();
71
- music.start(seekTime);
70
+ musicInstance.start(seekTime);
72
71
  if (!wasPlaying)
73
- music.pause();
72
+ musicInstance.pause();
74
73
  };
75
74
  musicPlayer.addChild(progressBar);
76
75
 
@@ -93,8 +92,8 @@ function gameInit()
93
92
  dropZoneText.text = file.name;
94
93
 
95
94
  // reset UI
96
- music && music.stop();
97
- music = undefined;
95
+ musicInstance?.stop();
96
+ musicInstance = undefined;
98
97
  progressBar.value = 0;
99
98
  }
100
99
  uiSystem.setupDragAndDrop(onDrop, onDragEnter, onDragLeave);
@@ -124,12 +123,13 @@ function gameUpdate()
124
123
  else
125
124
  {
126
125
  // update ui text
127
- const isPlaying = music && music.isPlaying();
126
+ const isPlaying = musicInstance?.isPlaying();
128
127
  playButton.text = isPlaying ? 'Pause' : 'Play';
129
- const current = music ? music.getCurrentTime() : 0;
128
+ const current = musicInstance?.getCurrentTime() || 0;
130
129
  const duration = musicSound.getDuration();
131
- progressBar.text = formatTime(current) +' / '+ formatTime(duration);
132
- if (!progressBar.mouseIsHeld)
130
+ progressBar.text = formatTime(current) +
131
+ ' / ' + formatTime(duration);
132
+ if (!progressBar.isActiveObject())
133
133
  progressBar.value = current / duration;
134
134
  }
135
135
  }
@@ -8,8 +8,6 @@ class Player extends EngineObject
8
8
 
9
9
  update()
10
10
  {
11
- super.update();
12
-
13
11
  // apply movement controls
14
12
  const moveInput = keyDirection();
15
13
  this.velocity.x += moveInput.x * (this.groundObject ? .1: .01);
@@ -20,7 +20,7 @@ class PuzzlePiece extends EngineObject
20
20
  const deltaX = emptyGridPos.x - this.gridPos.x;
21
21
  const deltaY = emptyGridPos.y - this.gridPos.y;
22
22
  if (mouseWasPressed(0))
23
- if (isOverlapping(this.pos, this.size, mousePos))
23
+ if (this.isOverlapping(mousePos))
24
24
  if (abs(deltaX) + abs(deltaY) === 1)
25
25
  {
26
26
  // swap with empty space when clicked on
Binary file
@@ -10,8 +10,6 @@ class Player extends EngineObject
10
10
 
11
11
  update()
12
12
  {
13
- super.update();
14
-
15
13
  // space ship controls
16
14
  const moveInput = keyDirection();
17
15
  this.applyAngularAcceleration(moveInput.x * .005);
@@ -1,5 +1,3 @@
1
- let spriteAtlas;
2
-
3
1
  function gameInit()
4
2
  {
5
3
  // create a table of all sprites
@@ -3,7 +3,6 @@ class GameObject extends EngineObject
3
3
  update()
4
4
  {
5
5
  this.renderOrder = -this.pos.y; // sort by y position
6
- super.update();
7
6
  }
8
7
 
9
8
  render()
@@ -20,8 +19,6 @@ class Player extends GameObject
20
19
  {
21
20
  update()
22
21
  {
23
- super.update();
24
-
25
22
  // apply movement controls
26
23
  const moveInput = keyDirection().clampLength(1).scale(.2);
27
24
  this.velocity = this.velocity.add(moveInput);
@@ -1,5 +1,4 @@
1
- let timerButton, timerSlider;
2
- let timerSound = new Sound([2,0,999,,,,,1.5,,.3,-99,.1,1.63,,,.11]);
1
+ const timerSound = new Sound([2,0,999,,,,,1.5,,.3,-99,.1,1.63,,,.11]);
3
2
 
4
3
  function gameInit()
5
4
  {
@@ -9,8 +9,6 @@ class Player extends EngineObject
9
9
 
10
10
  update()
11
11
  {
12
- super.update();
13
-
14
12
  // apply movement controls
15
13
  const moveInput = keyDirection().clampLength(1).scale(.2);
16
14
  this.velocity = this.velocity.add(moveInput);
Binary file
@@ -0,0 +1,33 @@
1
+ function gameInit()
2
+ {
3
+ new UISystemPlugin;
4
+ canvasClearColor = hsl(0,0,.1);
5
+ uiSystem.defaultCornerRadius = 20;
6
+
7
+ // video player
8
+ const center = mainCanvasSize.scale(.5);
9
+ const videoPos = center.add(vec2(0, -50));
10
+ const videoSize = vec2(480, 270);
11
+ const filename = 'video.webm';
12
+ const autoplay = true;
13
+ videoPlayer = new UIVideo(videoPos, videoSize, filename, autoplay);
14
+ videoPlayer.lineWidth = 5;
15
+ videoPlayer.lineColor = WHITE;
16
+
17
+ // play/pause button
18
+ const buttonSize = vec2(200, 100);
19
+ const playButtonPos = center.add(vec2(-130, 170));
20
+ const playButton = new UIButton(playButtonPos, buttonSize);
21
+ playButton.onClick = ()=> videoPlayer.isPaused() ?
22
+ videoPlayer.play() : videoPlayer.pause();
23
+ playButton.onUpdate = ()=> playButton.text =
24
+ videoPlayer.isPaused() ? 'Play' : 'Pause';
25
+
26
+ // status text
27
+ const statusTextPos = center.add(vec2(130, 170));
28
+ const statusText = new UIText(statusTextPos, vec2(250, 90));
29
+ statusText.textColor = WHITE;
30
+ statusText.onUpdate = ()=> statusText.text =
31
+ videoPlayer.hasEnded() ? 'Ended' :
32
+ videoPlayer.isPlaying() ? 'Playing' : 'Paused';
33
+ }
@@ -7,9 +7,10 @@
7
7
  </head><body>
8
8
 
9
9
  <!-- LittleJS Engine -->
10
- <script src=../../dist/littlejs.js?1.14.24></script>
10
+ <script src=../../dist/littlejs.js?1.15.2></script>
11
11
 
12
12
  <!-- LittleJS Engine Source
13
+ <script src=../../src/engine.js></script>
13
14
  <script src=../../src/engineDebug.js></script>
14
15
  <script src=../../src/engineUtilities.js></script>
15
16
  <script src=../../src/engineSettings.js></script>
@@ -21,7 +22,6 @@
21
22
  <script src=../../src/engineParticles.js></script>
22
23
  <script src=../../src/engineMedals.js></script>
23
24
  <script src=../../src/engineWebGL.js></script>
24
- <script src=../../src/engine.js></script>
25
25
  <script src=../../plugins/box2d.js></script>
26
26
  <script src=../../plugins/box2d.wasm.js></script>
27
27
  <script src=../../plugins/drawUtilities.js></script>
@@ -31,4 +31,4 @@
31
31
  -->
32
32
 
33
33
  <!-- Add your game scripts here -->
34
- <script src=game.js?1.14.24></script>
34
+ <script src=game.js?1.15.2></script>
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "littlejsengine",
3
- "version": "1.14.23",
3
+ "version": "1.15.2",
4
4
  "description": "LittleJS - Tiny and Fast HTML5 Game Engine",
5
5
  "main": "dist/littlejs.esm.js",
6
6
  "types": "dist/littlejs.d.ts",