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.
- package/dist/littlejs.d.ts +184 -30
- package/dist/littlejs.esm.js +589 -147
- package/dist/littlejs.esm.min.js +1 -1
- package/dist/littlejs.js +583 -147
- package/dist/littlejs.min.js +1 -1
- package/dist/littlejs.release.js +546 -147
- package/examples/box2d/gameObjects.js +6 -10
- package/examples/box2d/scenes.js +2 -2
- package/examples/breakout/gameObjects.js +1 -1
- package/examples/electron/index.html +2 -2
- package/examples/index.html +11 -7
- package/examples/platformer/gameCharacter.js +3 -2
- package/examples/platformer/gameObjects.js +3 -8
- package/examples/shorts/base.html +2 -2
- package/examples/shorts/box2d.js +2 -2
- package/examples/shorts/box2dCar.js +18 -7
- package/examples/shorts/box2dPool.js +108 -0
- package/examples/shorts/debugDraw.js +2 -3
- package/examples/shorts/flappyGame.js +1 -0
- package/examples/shorts/fps.js +1 -1
- package/examples/shorts/hillGlideGame.js +0 -2
- package/examples/shorts/input.js +59 -0
- package/examples/shorts/landerGame.js +1 -3
- package/examples/shorts/medals.js +15 -9
- package/examples/shorts/music.js +15 -17
- package/examples/shorts/musicPlayer.js +24 -24
- package/examples/shorts/platformer.js +0 -2
- package/examples/shorts/slidingPuzzle.js +1 -1
- package/examples/shorts/song.mp3 +0 -0
- package/examples/shorts/spaceGame.js +0 -2
- package/examples/shorts/spriteAtlas.js +0 -2
- package/examples/shorts/tiltedView.js +0 -3
- package/examples/shorts/timers.js +1 -2
- package/examples/shorts/topDown.js +0 -2
- package/examples/shorts/video.webm +0 -0
- package/examples/shorts/videoPlayer.js +33 -0
- package/examples/starter/index.html +3 -3
- package/package.json +1 -1
- package/plugins/box2d.js +170 -50
- package/plugins/pluginExport.js +3 -0
- package/plugins/uiSystem.js +229 -27
- package/src/engine.js +21 -18
- package/src/engineAudio.js +14 -2
- package/src/engineDebug.js +37 -0
- package/src/engineDraw.js +21 -13
- package/src/engineExport.js +3 -0
- package/src/engineInput.js +24 -12
- package/src/engineMedals.js +2 -2
- package/src/engineObject.js +24 -4
- package/src/engineParticles.js +4 -6
- package/src/engineTileLayer.js +2 -0
- package/src/engineUtilities.js +35 -13
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
let musicSound,
|
|
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
|
-
|
|
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 =
|
|
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
|
-
|
|
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 (!
|
|
48
|
-
|
|
49
|
-
else if (
|
|
50
|
-
|
|
46
|
+
if (!musicInstance)
|
|
47
|
+
musicInstance = musicSound.playMusic(musicVolume);
|
|
48
|
+
else if (musicInstance.isPaused())
|
|
49
|
+
musicInstance.resume();
|
|
51
50
|
else
|
|
52
|
-
|
|
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 = ()=>
|
|
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 =
|
|
67
|
-
if (!
|
|
68
|
-
|
|
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
|
-
|
|
70
|
+
musicInstance.start(seekTime);
|
|
72
71
|
if (!wasPlaying)
|
|
73
|
-
|
|
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
|
-
|
|
97
|
-
|
|
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 =
|
|
126
|
+
const isPlaying = musicInstance?.isPlaying();
|
|
128
127
|
playButton.text = isPlaying ? 'Pause' : 'Play';
|
|
129
|
-
const current =
|
|
128
|
+
const current = musicInstance?.getCurrentTime() || 0;
|
|
130
129
|
const duration = musicSound.getDuration();
|
|
131
|
-
progressBar.text = formatTime(current) +
|
|
132
|
-
|
|
130
|
+
progressBar.text = formatTime(current) +
|
|
131
|
+
' / ' + formatTime(duration);
|
|
132
|
+
if (!progressBar.isActiveObject())
|
|
133
133
|
progressBar.value = current / duration;
|
|
134
134
|
}
|
|
135
135
|
}
|
|
@@ -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(
|
|
23
|
+
if (this.isOverlapping(mousePos))
|
|
24
24
|
if (abs(deltaX) + abs(deltaY) === 1)
|
|
25
25
|
{
|
|
26
26
|
// swap with empty space when clicked on
|
package/examples/shorts/song.mp3
CHANGED
|
Binary file
|
|
@@ -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);
|
|
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.
|
|
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.
|
|
34
|
+
<script src=game.js?1.15.2></script>
|