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.
- package/dist/littlejs.d.ts +252 -109
- package/dist/littlejs.esm.js +559 -252
- package/dist/littlejs.esm.min.js +1 -1
- package/dist/littlejs.js +557 -251
- package/dist/littlejs.min.js +1 -1
- package/dist/littlejs.release.js +482 -206
- package/examples/box2d/gameObjects.js +2 -2
- package/examples/breakout/gameObjects.js +2 -2
- package/examples/breakoutTutorial/README.md +32 -32
- package/examples/breakoutTutorial/game.js +1 -1
- package/examples/electron/game.js +3 -3
- package/examples/electron/index.html +2 -2
- package/examples/electron/package.json +1 -8
- package/examples/index.html +10 -7
- package/examples/module/game.js +3 -3
- package/examples/platformer/gameEffects.js +4 -4
- package/examples/platformer/gameLevel.js +1 -1
- package/examples/platformer/gameObjects.js +4 -4
- package/examples/puzzle/game.js +1 -1
- package/examples/shorts/animation.js +1 -1
- package/examples/shorts/base.html +1 -1
- package/examples/shorts/blending.js +8 -14
- package/examples/shorts/box2d.js +7 -3
- package/examples/shorts/box2dCar.js +2 -1
- package/examples/shorts/empty.js +30 -0
- package/examples/shorts/helloWorld.js +1 -1
- package/examples/shorts/hillGlideGame.js +10 -4
- package/examples/shorts/landerGame.js +11 -8
- package/examples/shorts/medals.js +4 -4
- package/examples/shorts/music.js +29 -56
- package/examples/shorts/musicPlayer.js +134 -0
- package/examples/shorts/nineSlice.js +34 -15
- package/examples/shorts/parallax.js +4 -3
- package/examples/shorts/particles.js +15 -15
- package/examples/shorts/piano.js +15 -21
- package/examples/shorts/pongGame.js +6 -4
- package/examples/shorts/raycasting.js +9 -4
- package/examples/shorts/sequencer.js +122 -0
- package/examples/shorts/shapes.js +7 -4
- package/examples/shorts/slidingPuzzle.js +4 -2
- package/examples/shorts/sound.js +18 -9
- package/examples/shorts/spaceGame.js +12 -8
- package/examples/shorts/spriteAtlas.js +7 -7
- package/examples/shorts/starfield.js +1 -1
- package/examples/shorts/systemFont.js +2 -2
- package/examples/shorts/texture.js +2 -2
- package/examples/shorts/tileLayer.js +10 -10
- package/examples/shorts/tiltedView.js +14 -3
- package/examples/shorts/timers.js +10 -0
- package/examples/shorts/topDown.js +4 -1
- package/examples/shorts/uiSystem.js +8 -5
- package/examples/starter/game.js +3 -3
- package/examples/starter/index.html +2 -2
- package/examples/typescript/game.js +3 -3
- package/examples/typescript/game.ts +3 -3
- package/examples/uiSystem/game.js +3 -3
- package/package.json +4 -2
- package/plugins/box2d.js +17 -2
- package/plugins/newgrounds.js +7 -5
- package/plugins/postProcess.js +5 -2
- package/plugins/uiSystem.js +120 -34
- package/plugins/zzfxm.js +5 -1
- package/reference.md +1 -1
- package/src/engine.js +35 -12
- package/src/engineAudio.js +31 -14
- package/src/engineDebug.js +75 -45
- package/src/engineDraw.js +60 -31
- package/src/engineExport.js +2 -1
- package/src/engineMedals.js +10 -2
- package/src/engineObject.js +14 -10
- package/src/engineParticles.js +59 -46
- package/src/engineSettings.js +7 -7
- package/src/engineTileLayer.js +45 -20
- 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, .
|
|
11
|
-
|
|
12
|
-
|
|
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
|
-
|
|
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)
|
|
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
|
|
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
|
}
|
package/examples/shorts/sound.js
CHANGED
|
@@ -14,13 +14,22 @@ function gameInit()
|
|
|
14
14
|
button.textHeight = 100;
|
|
15
15
|
button.onClick = ()=> sound.play();
|
|
16
16
|
}
|
|
17
|
-
makeSoundButton(vec2(-1, 1),'💰',
|
|
18
|
-
|
|
19
|
-
makeSoundButton(vec2(
|
|
20
|
-
|
|
21
|
-
makeSoundButton(vec2(
|
|
22
|
-
|
|
23
|
-
makeSoundButton(vec2(-1
|
|
24
|
-
|
|
25
|
-
makeSoundButton(vec2(
|
|
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
|
-
|
|
19
|
-
|
|
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
|
|
24
|
-
bullet.velocity =
|
|
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 =
|
|
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 +
|
|
51
|
-
pos.y = mod(i**3.1 +
|
|
52
|
-
size.x = size.y = i%.07
|
|
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
|
|
22
|
-
let angle = 0; // world space angle
|
|
23
|
-
let size = vec2(9); // world size
|
|
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
|
|
26
|
-
let
|
|
27
|
-
drawTile(pos, size, spriteAtlas.iconBig, color, angle, mirror,
|
|
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);
|
|
@@ -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
|
|
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
|
|
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
|
|
8
|
-
let tileSize = vec2(256); // size
|
|
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,
|
|
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
|
|
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
|
|
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
|
|
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
|
-
|
|
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
|
-
|
|
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
|
|
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([
|
|
6
|
-
uiSystem.defaultSoundClick = new Sound([
|
|
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),
|
|
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),
|
|
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,
|
|
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
|
|
package/examples/starter/game.js
CHANGED
|
@@ -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,
|
|
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
|
|
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 =
|
|
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?
|
|
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?
|
|
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,
|
|
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
|
|
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 =
|
|
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,
|
|
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
|
|
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 =
|
|
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([
|
|
25
|
-
LJS.uiSystem.defaultSoundClick = new LJS.Sound([
|
|
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 = ()=>
|
|
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.
|
|
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
|
}
|