littlejsengine 1.14.11 → 1.14.19
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 +303 -137
- package/dist/littlejs.esm.js +936 -463
- package/dist/littlejs.esm.min.js +1 -1
- package/dist/littlejs.js +934 -462
- package/dist/littlejs.min.js +1 -1
- package/dist/littlejs.release.js +859 -417
- package/examples/box2d/game.js +3 -2
- package/examples/box2d/gameObjects.js +2 -2
- package/examples/box2d/tiles.png +0 -0
- package/examples/breakout/game.js +5 -5
- 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 +4 -4
- package/examples/electron/index.html +2 -2
- package/examples/electron/package.json +1 -8
- package/examples/index.html +67 -56
- package/examples/module/game.js +4 -4
- package/examples/platformer/gameEffects.js +5 -5
- 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 +135 -0
- package/examples/shorts/nineSlice.js +34 -15
- package/examples/shorts/parallax.js +5 -4
- 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/shader.js +29 -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 +24 -5
- 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 +4 -4
- package/examples/starter/index.html +2 -2
- package/examples/style.css +1 -0
- package/examples/typescript/game.js +4 -4
- package/examples/typescript/game.ts +4 -4
- package/examples/uiSystem/game.js +4 -3
- package/package.json +4 -2
- package/plugins/box2d.js +17 -2
- package/plugins/newgrounds.js +7 -5
- package/plugins/postProcess.js +76 -53
- package/plugins/uiSystem.js +192 -53
- package/plugins/zzfxm.js +5 -1
- package/reference.md +1 -1
- package/src/engine.js +60 -23
- package/src/engineAudio.js +44 -17
- package/src/engineDebug.js +75 -45
- package/src/engineDraw.js +94 -59
- package/src/engineExport.js +2 -1
- package/src/engineMedals.js +10 -2
- package/src/engineObject.js +14 -10
- package/src/engineParticles.js +60 -47
- package/src/engineSettings.js +7 -7
- package/src/engineTileLayer.js +73 -56
- package/src/engineUtilities.js +67 -20
- package/src/engineWebGL.js +134 -63
|
@@ -9,8 +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
|
|
13
|
-
|
|
12
|
+
const drawSize = this.drawSize || this.size;
|
|
13
|
+
const offset = vec2(0,drawSize.y/2).rotate(this.angle);
|
|
14
|
+
const pos = this.pos.add(offset);
|
|
15
|
+
drawTile(pos, drawSize, this.tileInfo, this.color, this.angle);
|
|
14
16
|
}
|
|
15
17
|
}
|
|
16
18
|
|
|
@@ -23,6 +25,7 @@ class Player extends GameObject
|
|
|
23
25
|
// apply movement controls
|
|
24
26
|
const moveInput = keyDirection().clampLength(1).scale(.2);
|
|
25
27
|
this.velocity = this.velocity.add(moveInput);
|
|
28
|
+
this.setCollision(); // make object collide
|
|
26
29
|
|
|
27
30
|
// move camera with player
|
|
28
31
|
cameraPos = this.pos.add(vec2(0,2));
|
|
@@ -33,13 +36,29 @@ function gameInit()
|
|
|
33
36
|
{
|
|
34
37
|
// setup level
|
|
35
38
|
objectDefaultDamping = .7;
|
|
36
|
-
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);
|
|
37
41
|
|
|
38
42
|
// create background objects
|
|
39
43
|
for (let i=1; i<300; ++i)
|
|
40
|
-
|
|
44
|
+
{
|
|
45
|
+
const pos = randInCircle(90);
|
|
46
|
+
const size = vec2(rand(59), rand(59));
|
|
47
|
+
const color = hsl(.4,.2,rand(.4,.5),.8);
|
|
48
|
+
new EngineObject(pos, size, 0, 0, color, -1e5);
|
|
49
|
+
}
|
|
41
50
|
|
|
42
51
|
// create world objects
|
|
43
52
|
for (let i=1; i<1e3; ++i)
|
|
44
|
-
|
|
53
|
+
{
|
|
54
|
+
const pos = randInCircle(7+i,7);
|
|
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));
|
|
63
|
+
}
|
|
45
64
|
}
|
|
@@ -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));
|
|
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,16 +65,16 @@ 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
|
|
72
|
-
|
|
72
|
+
1, .2, .2, .1, .05, // time, sizeStart, sizeEnd, speed, angleSpeed
|
|
73
73
|
.99, 1, 1, PI, // damping, angleDamping, gravityScale, cone
|
|
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;
|
|
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?11417></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?11417></script>
|
package/examples/style.css
CHANGED
|
@@ -52,16 +52,16 @@ 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
|
|
59
|
-
|
|
59
|
+
1, .2, .2, .1, .05, // time, sizeStart, sizeEnd, speed, angleSpeed
|
|
60
60
|
.99, 1, 1, Math.PI, // 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;
|
|
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,16 +69,16 @@ 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
|
|
76
|
-
|
|
76
|
+
1, .2, .2, .1, .05, // time, sizeStart, sizeEnd, speed, angleSpeed
|
|
77
77
|
.99, 1, 1, Math.PI, // damping, angleDamping, gravityScale, cone
|
|
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,9 +21,10 @@ 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
|
+
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 = ()=>
|
|
67
|
+
button1.onClick = ()=> uiBackground.color = hsl(Math.random(),1,.7);
|
|
67
68
|
|
|
68
69
|
// example checkbox
|
|
69
70
|
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.19",
|
|
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
|
}
|
package/plugins/box2d.js
CHANGED
|
@@ -39,6 +39,7 @@ function box2dSetDebug(enable) { box2dDebug = enable; }
|
|
|
39
39
|
* - Each object has a Box2D body which can have multiple fixtures and joints
|
|
40
40
|
* - Provides interface for Box2D body and fixture functions
|
|
41
41
|
* @extends EngineObject
|
|
42
|
+
* @memberof Box2D
|
|
42
43
|
*/
|
|
43
44
|
class Box2dObject extends EngineObject
|
|
44
45
|
{
|
|
@@ -50,7 +51,7 @@ class Box2dObject extends EngineObject
|
|
|
50
51
|
* @param {Color} [color]
|
|
51
52
|
* @param {number} [bodyType]
|
|
52
53
|
* @param {number} [renderOrder] */
|
|
53
|
-
constructor(pos
|
|
54
|
+
constructor(pos, size, tileInfo, angle=0, color, bodyType=box2d.bodyTypeDynamic, renderOrder=0)
|
|
54
55
|
{
|
|
55
56
|
super(pos, size, tileInfo, angle, color, renderOrder);
|
|
56
57
|
|
|
@@ -64,7 +65,7 @@ class Box2dObject extends EngineObject
|
|
|
64
65
|
this.lineColor = BLACK;
|
|
65
66
|
}
|
|
66
67
|
|
|
67
|
-
/** Destroy this object and
|
|
68
|
+
/** Destroy this object and its physics body */
|
|
68
69
|
destroy()
|
|
69
70
|
{
|
|
70
71
|
// destroy physics body, fixtures, and joints
|
|
@@ -548,6 +549,7 @@ class Box2dRaycastResult
|
|
|
548
549
|
* Box2D Joint
|
|
549
550
|
* - Base class for Box2D joints
|
|
550
551
|
* - A joint is used to connect objects together
|
|
552
|
+
* @memberof Box2D
|
|
551
553
|
*/
|
|
552
554
|
class Box2dJoint
|
|
553
555
|
{
|
|
@@ -603,6 +605,7 @@ class Box2dJoint
|
|
|
603
605
|
* - This a soft constraint with a max force
|
|
604
606
|
* - This allows the constraint to stretch and without applying huge forces
|
|
605
607
|
* @extends Box2dJoint
|
|
608
|
+
* @memberof Box2D
|
|
606
609
|
*/
|
|
607
610
|
class Box2dTargetJoint extends Box2dJoint
|
|
608
611
|
{
|
|
@@ -652,6 +655,7 @@ class Box2dTargetJoint extends Box2dJoint
|
|
|
652
655
|
* - Constrains two points on two objects to remain at a fixed distance
|
|
653
656
|
* - You can view this as a massless, rigid rod
|
|
654
657
|
* @extends Box2dJoint
|
|
658
|
+
* @memberof Box2D
|
|
655
659
|
*/
|
|
656
660
|
class Box2dDistanceJoint extends Box2dJoint
|
|
657
661
|
{
|
|
@@ -715,6 +719,7 @@ class Box2dDistanceJoint extends Box2dJoint
|
|
|
715
719
|
* Box2D Pin Joint
|
|
716
720
|
* - Pins two objects together at a point
|
|
717
721
|
* @extends Box2dDistanceJoint
|
|
722
|
+
* @memberof Box2D
|
|
718
723
|
*/
|
|
719
724
|
class Box2dPinJoint extends Box2dDistanceJoint
|
|
720
725
|
{
|
|
@@ -734,6 +739,7 @@ class Box2dPinJoint extends Box2dDistanceJoint
|
|
|
734
739
|
* Box2D Rope Joint
|
|
735
740
|
* - Enforces a maximum distance between two points on two objects
|
|
736
741
|
* @extends Box2dJoint
|
|
742
|
+
* @memberof Box2D
|
|
737
743
|
*/
|
|
738
744
|
class Box2dRopeJoint extends Box2dJoint
|
|
739
745
|
{
|
|
@@ -786,6 +792,7 @@ class Box2dRopeJoint extends Box2dJoint
|
|
|
786
792
|
* - You can use a motor to drive the relative rotation about the shared point
|
|
787
793
|
* - A maximum motor torque is provided so that infinite forces are not generated
|
|
788
794
|
* @extends Box2dJoint
|
|
795
|
+
* @memberof Box2D
|
|
789
796
|
*/
|
|
790
797
|
class Box2dRevoluteJoint extends Box2dJoint
|
|
791
798
|
{
|
|
@@ -887,6 +894,7 @@ class Box2dRevoluteJoint extends Box2dJoint
|
|
|
887
894
|
* - Either joint can be a revolute or prismatic joint
|
|
888
895
|
* - You specify a gear ratio to bind the motions together
|
|
889
896
|
* @extends Box2dJoint
|
|
897
|
+
* @memberof Box2D
|
|
890
898
|
*/
|
|
891
899
|
class Box2dGearJoint extends Box2dJoint
|
|
892
900
|
{
|
|
@@ -935,6 +943,7 @@ class Box2dGearJoint extends Box2dJoint
|
|
|
935
943
|
* - You can use a joint limit to restrict the range of motion
|
|
936
944
|
* - You can use a joint motor to drive the motion or to model joint friction
|
|
937
945
|
* @extends Box2dJoint
|
|
946
|
+
* @memberof Box2D
|
|
938
947
|
*/
|
|
939
948
|
class Box2dPrismaticJoint extends Box2dJoint
|
|
940
949
|
{
|
|
@@ -1044,6 +1053,7 @@ class Box2dPrismaticJoint extends Box2dJoint
|
|
|
1044
1053
|
* - You can use a joint motor to drive the motion or to model joint friction
|
|
1045
1054
|
* - This joint is designed for vehicle suspensions
|
|
1046
1055
|
* @extends Box2dJoint
|
|
1056
|
+
* @memberof Box2D
|
|
1047
1057
|
*/
|
|
1048
1058
|
class Box2dWheelJoint extends Box2dJoint
|
|
1049
1059
|
{
|
|
@@ -1139,6 +1149,7 @@ class Box2dWheelJoint extends Box2dJoint
|
|
|
1139
1149
|
* Box2D Weld Joint
|
|
1140
1150
|
* - Glues two objects together
|
|
1141
1151
|
* @extends Box2dJoint
|
|
1152
|
+
* @memberof Box2D
|
|
1142
1153
|
*/
|
|
1143
1154
|
class Box2dWeldJoint extends Box2dJoint
|
|
1144
1155
|
{
|
|
@@ -1197,6 +1208,7 @@ class Box2dWeldJoint extends Box2dJoint
|
|
|
1197
1208
|
* - Used to apply top-down friction
|
|
1198
1209
|
* - Provides 2D translational friction and angular friction
|
|
1199
1210
|
* @extends Box2dJoint
|
|
1211
|
+
* @memberof Box2D
|
|
1200
1212
|
*/
|
|
1201
1213
|
class Box2dFrictionJoint extends Box2dJoint
|
|
1202
1214
|
{
|
|
@@ -1251,6 +1263,7 @@ class Box2dFrictionJoint extends Box2dJoint
|
|
|
1251
1263
|
* - The pulley supports a ratio such that: length1 + ratio * length2 <= constant
|
|
1252
1264
|
* - The force transmitted is scaled by the ratio
|
|
1253
1265
|
* @extends Box2dJoint
|
|
1266
|
+
* @memberof Box2D
|
|
1254
1267
|
*/
|
|
1255
1268
|
class Box2dPulleyJoint extends Box2dJoint
|
|
1256
1269
|
{
|
|
@@ -1318,6 +1331,7 @@ class Box2dPulleyJoint extends Box2dJoint
|
|
|
1318
1331
|
* - Controls the relative motion between two objects
|
|
1319
1332
|
* - Typical usage is to control the movement of a object with respect to the ground
|
|
1320
1333
|
* @extends Box2dJoint
|
|
1334
|
+
* @memberof Box2D
|
|
1321
1335
|
*/
|
|
1322
1336
|
class Box2dMotorJoint extends Box2dJoint
|
|
1323
1337
|
{
|
|
@@ -1381,6 +1395,7 @@ class Box2dMotorJoint extends Box2dJoint
|
|
|
1381
1395
|
/**
|
|
1382
1396
|
* Box2D Global Object
|
|
1383
1397
|
* - Wraps Box2d world and provides global functions
|
|
1398
|
+
* @memberof Box2D
|
|
1384
1399
|
*/
|
|
1385
1400
|
class Box2dPlugin
|
|
1386
1401
|
{
|
package/plugins/newgrounds.js
CHANGED
|
@@ -1,24 +1,25 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* LittleJS Newgrounds
|
|
2
|
+
* LittleJS Newgrounds Plugin
|
|
3
3
|
* - NewgroundsMedal extends Medal with Newgrounds API functionality
|
|
4
|
-
* - Call new NewgroundsPlugin() to setup Newgrounds
|
|
4
|
+
* - Call new NewgroundsPlugin(app_id) to setup Newgrounds
|
|
5
5
|
* - Uses CryptoJS for encryption if optional cipher is provided
|
|
6
|
+
* - provides functions to interact with medals scoreboards
|
|
6
7
|
* - Keeps connection alive and logs views
|
|
7
|
-
*
|
|
8
|
-
* - Functions to unlock medals
|
|
8
|
+
* @namespace Newgrounds
|
|
9
9
|
*/
|
|
10
10
|
|
|
11
11
|
'use strict';
|
|
12
12
|
|
|
13
13
|
/** Global Newgrounds object
|
|
14
14
|
* @type {NewgroundsPlugin}
|
|
15
|
-
* @memberof
|
|
15
|
+
* @memberof Newgrounds */
|
|
16
16
|
let newgrounds;
|
|
17
17
|
|
|
18
18
|
///////////////////////////////////////////////////////////////////////////////
|
|
19
19
|
/**
|
|
20
20
|
* Newgrounds medal auto unlocks in newgrounds API
|
|
21
21
|
* @extends Medal
|
|
22
|
+
* @memberof Newgrounds
|
|
22
23
|
*/
|
|
23
24
|
class NewgroundsMedal extends Medal
|
|
24
25
|
{
|
|
@@ -43,6 +44,7 @@ class NewgroundsMedal extends Medal
|
|
|
43
44
|
///////////////////////////////////////////////////////////////////////////////
|
|
44
45
|
/**
|
|
45
46
|
* Newgrounds API object
|
|
47
|
+
* @memberof Newgrounds
|
|
46
48
|
*/
|
|
47
49
|
class NewgroundsPlugin
|
|
48
50
|
{
|
package/plugins/postProcess.js
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* LittleJS Post Processing Plugin
|
|
3
3
|
* - Supports shadertoy style post processing shaders
|
|
4
|
-
* - call new
|
|
4
|
+
* - call new PostProcessPlugin() to setup post processing
|
|
5
5
|
* - can be enabled to pass other canvases through a final shader
|
|
6
|
+
* @namespace PostProcess
|
|
6
7
|
*/
|
|
7
8
|
|
|
8
9
|
'use strict';
|
|
@@ -10,92 +11,111 @@
|
|
|
10
11
|
///////////////////////////////////////////////////////////////////////////////
|
|
11
12
|
|
|
12
13
|
/** Global Post Process plugin object
|
|
13
|
-
* @type {PostProcessPlugin}
|
|
14
|
+
* @type {PostProcessPlugin}
|
|
15
|
+
* @memberof PostProcess */
|
|
14
16
|
let postProcess;
|
|
15
17
|
|
|
16
18
|
/////////////////////////////////////////////////////////////////////////
|
|
17
19
|
/**
|
|
18
20
|
* UI System Global Object
|
|
21
|
+
* @memberof PostProcess
|
|
19
22
|
*/
|
|
20
23
|
class PostProcessPlugin
|
|
21
24
|
{
|
|
22
25
|
/** Create global post processing shader
|
|
23
26
|
* @param {string} shaderCode
|
|
24
27
|
* @param {boolean} [includeOverlay]
|
|
28
|
+
* @param {boolean} [includeMainCanvas]
|
|
25
29
|
* @example
|
|
26
30
|
* // create the post process plugin object
|
|
27
31
|
* new PostProcessPlugin(shaderCode);
|
|
28
32
|
*/
|
|
29
|
-
constructor(shaderCode, includeOverlay=false)
|
|
33
|
+
constructor(shaderCode, includeOverlay=false, includeMainCanvas=true)
|
|
30
34
|
{
|
|
31
35
|
ASSERT(!postProcess, 'Post process already initialized');
|
|
32
36
|
postProcess = this;
|
|
33
37
|
|
|
34
|
-
if (headlessMode) return;
|
|
35
|
-
|
|
36
|
-
if (!glEnable)
|
|
37
|
-
{
|
|
38
|
-
console.warn('PostProcessPlugin: WebGL not enabled!');
|
|
39
|
-
return;
|
|
40
|
-
}
|
|
41
|
-
|
|
42
38
|
if (!shaderCode) // default shader pass through
|
|
43
39
|
shaderCode = 'void mainImage(out vec4 c,vec2 p){c=texture(iChannel0,p/iResolution.xy);}';
|
|
44
40
|
|
|
45
41
|
/** @property {WebGLProgram} - Shader for post processing */
|
|
46
|
-
this.shader =
|
|
47
|
-
'#version 300 es\n' + // specify GLSL ES version
|
|
48
|
-
'precision highp float;'+ // use highp for better accuracy
|
|
49
|
-
'in vec2 p;'+ // position
|
|
50
|
-
'void main(){'+ // shader entry point
|
|
51
|
-
'gl_Position=vec4(p+p-1.,1,1);'+ // set position
|
|
52
|
-
'}' // end of shader
|
|
53
|
-
,
|
|
54
|
-
'#version 300 es\n' + // specify GLSL ES version
|
|
55
|
-
'precision highp float;'+ // use highp for better accuracy
|
|
56
|
-
'uniform sampler2D iChannel0;'+ // input texture
|
|
57
|
-
'uniform vec3 iResolution;'+ // size of output texture
|
|
58
|
-
'uniform float iTime;'+ // time
|
|
59
|
-
'out vec4 c;'+ // out color
|
|
60
|
-
'\n' + shaderCode + '\n'+ // insert custom shader code
|
|
61
|
-
'void main(){'+ // shader entry point
|
|
62
|
-
'mainImage(c,gl_FragCoord.xy);'+ // call post process function
|
|
63
|
-
'c.a=1.;'+ // always use full alpha
|
|
64
|
-
'}' // end of shader
|
|
65
|
-
);
|
|
42
|
+
this.shader = undefined;
|
|
66
43
|
|
|
67
44
|
/** @property {WebGLTexture} - Texture for post processing */
|
|
68
|
-
this.texture =
|
|
45
|
+
this.texture = undefined;
|
|
69
46
|
|
|
70
|
-
|
|
71
|
-
|
|
47
|
+
// setup the post processing plugin
|
|
48
|
+
initPostProcess();
|
|
49
|
+
engineAddPlugin(undefined, postProcessRender, postProcessContextLost, postProcessContextRestored);
|
|
72
50
|
|
|
73
|
-
|
|
74
|
-
engineAddPlugin(undefined, postProcessRender);
|
|
75
|
-
function postProcessRender()
|
|
51
|
+
function initPostProcess()
|
|
76
52
|
{
|
|
77
53
|
if (headlessMode) return;
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
if (glEnable)
|
|
81
|
-
{
|
|
82
|
-
glFlush(); // clear out the buffer
|
|
83
|
-
mainContext.drawImage(glCanvas, 0, 0); // copy to the main canvas
|
|
84
|
-
}
|
|
85
|
-
else
|
|
54
|
+
|
|
55
|
+
if (!glEnable)
|
|
86
56
|
{
|
|
87
|
-
|
|
88
|
-
|
|
57
|
+
console.warn('PostProcessPlugin: WebGL not enabled!');
|
|
58
|
+
return;
|
|
89
59
|
}
|
|
90
60
|
|
|
91
|
-
|
|
61
|
+
// create resources
|
|
62
|
+
postProcess.texture = glCreateTexture();
|
|
63
|
+
postProcess.shader = glCreateProgram(
|
|
64
|
+
'#version 300 es\n' + // specify GLSL ES version
|
|
65
|
+
'precision highp float;'+ // use highp for better accuracy
|
|
66
|
+
'in vec2 p;'+ // position
|
|
67
|
+
'void main(){'+ // shader entry point
|
|
68
|
+
'gl_Position=vec4(p+p-1.,1,1);'+ // set position
|
|
69
|
+
'}' // end of shader
|
|
70
|
+
,
|
|
71
|
+
'#version 300 es\n' + // specify GLSL ES version
|
|
72
|
+
'precision highp float;'+ // use highp for better accuracy
|
|
73
|
+
'uniform sampler2D iChannel0;'+ // input texture
|
|
74
|
+
'uniform vec3 iResolution;'+ // size of output texture
|
|
75
|
+
'uniform float iTime;'+ // time
|
|
76
|
+
'out vec4 c;'+ // out color
|
|
77
|
+
'\n' + shaderCode + '\n'+ // insert custom shader code
|
|
78
|
+
'void main(){'+ // shader entry point
|
|
79
|
+
'mainImage(c,gl_FragCoord.xy);'+ // call post process function
|
|
80
|
+
'c.a=1.;'+ // always use full alpha
|
|
81
|
+
'}' // end of shader
|
|
82
|
+
);
|
|
83
|
+
}
|
|
84
|
+
function postProcessContextLost()
|
|
85
|
+
{
|
|
86
|
+
postProcess.shader = undefined;
|
|
87
|
+
postProcess.texture = undefined;
|
|
88
|
+
LOG('PostProcessPlugin: WebGL context lost');
|
|
89
|
+
}
|
|
90
|
+
function postProcessContextRestored()
|
|
91
|
+
{
|
|
92
|
+
initPostProcess();
|
|
93
|
+
LOG('PostProcessPlugin: WebGL context restored');
|
|
94
|
+
}
|
|
95
|
+
function postProcessRender()
|
|
96
|
+
{
|
|
97
|
+
if (headlessMode) return;
|
|
98
|
+
|
|
99
|
+
if (!glEnable)
|
|
100
|
+
return;
|
|
101
|
+
|
|
102
|
+
// clear out the buffer
|
|
103
|
+
glFlush();
|
|
104
|
+
|
|
105
|
+
if (includeMainCanvas || includeOverlay)
|
|
92
106
|
{
|
|
93
|
-
// copy
|
|
94
|
-
mainContext.drawImage(
|
|
95
|
-
|
|
107
|
+
// copy WebGL to the main canvas
|
|
108
|
+
mainContext.drawImage(glCanvas, 0, 0);
|
|
109
|
+
|
|
110
|
+
if (includeOverlay)
|
|
111
|
+
{
|
|
112
|
+
// copy overlay canvas so it will be included in post processing
|
|
113
|
+
mainContext.drawImage(overlayCanvas, 0, 0);
|
|
114
|
+
overlayCanvas.width |= 0; // clear overlay canvas
|
|
115
|
+
}
|
|
96
116
|
}
|
|
97
117
|
|
|
98
|
-
// setup shader program to draw
|
|
118
|
+
// setup shader program to draw a quad
|
|
99
119
|
glContext.useProgram(postProcess.shader);
|
|
100
120
|
glContext.bindBuffer(glContext.ARRAY_BUFFER, glGeometryBuffer);
|
|
101
121
|
glContext.pixelStorei(glContext.UNPACK_FLIP_Y_WEBGL, 1);
|
|
@@ -104,7 +124,10 @@ class PostProcessPlugin
|
|
|
104
124
|
// set textures, pass in the 2d canvas and gl canvas in separate texture channels
|
|
105
125
|
glContext.activeTexture(glContext.TEXTURE0);
|
|
106
126
|
glContext.bindTexture(glContext.TEXTURE_2D, postProcess.texture);
|
|
107
|
-
|
|
127
|
+
if (includeMainCanvas || includeOverlay)
|
|
128
|
+
{
|
|
129
|
+
glContext.texImage2D(glContext.TEXTURE_2D, 0, glContext.RGBA, glContext.RGBA, glContext.UNSIGNED_BYTE, mainCanvas);
|
|
130
|
+
}
|
|
108
131
|
|
|
109
132
|
// set vertex position attribute
|
|
110
133
|
const vertexByteStride = 8;
|