littlejsengine 1.12.4 → 1.13.1
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/box2d.wasm.js +630 -0
- package/dist/box2d.wasm.wasm +0 -0
- package/dist/littlejs.d.ts +437 -219
- package/dist/littlejs.esm.js +5950 -5307
- package/dist/littlejs.esm.min.js +4 -1
- package/dist/littlejs.js +5921 -5295
- package/dist/littlejs.min.js +4 -1
- package/dist/littlejs.release.js +5485 -4886
- package/examples/box2d/game.js +37 -42
- package/examples/box2d/gameObjects.js +41 -37
- package/examples/box2d/index.html +2 -2
- package/examples/box2d/scenes.js +24 -20
- package/examples/box2d/tiles.png +0 -0
- package/examples/breakout/game.js +1 -1
- package/examples/breakout/gameObjects.js +2 -2
- package/examples/breakout/index.html +1 -1
- package/examples/breakoutTutorial/README.md +2 -2
- package/examples/breakoutTutorial/game.js +1 -1
- package/examples/breakoutTutorial/index.html +1 -1
- package/examples/empty/index.html +1 -1
- package/examples/htmlMenu/index.html +1 -1
- package/examples/index.html +410 -159
- package/examples/module/game.js +1 -1
- package/examples/module/index.html +1 -1
- package/examples/platformer/game.js +6 -15
- package/examples/platformer/gameCharacter.js +6 -6
- package/examples/platformer/gameEffects.js +74 -57
- package/examples/platformer/gameLevel.js +61 -70
- package/examples/platformer/gameObjects.js +4 -4
- package/examples/platformer/index.html +1 -1
- package/examples/puzzle/index.html +1 -1
- package/examples/shorts/base.html +24 -3
- package/examples/shorts/box2d.js +46 -0
- package/examples/shorts/box2dCar.js +45 -0
- package/examples/shorts/flappyGame.js +52 -0
- package/examples/shorts/helloWorld.js +6 -3
- package/examples/shorts/hillGlideGame.js +56 -0
- package/examples/shorts/landerGame.js +32 -0
- package/examples/shorts/maze.js +47 -0
- package/examples/shorts/medals.js +42 -0
- package/examples/shorts/nineSlice.js +21 -0
- package/examples/shorts/piano.js +52 -0
- package/examples/shorts/platformer.js +24 -20
- package/examples/shorts/{pong.js → pongGame.js} +1 -1
- package/examples/shorts/postProcess.js +45 -0
- package/examples/shorts/raycasting.js +71 -0
- package/examples/shorts/slidingPuzzle.js +42 -0
- package/examples/shorts/spaceGame.js +56 -0
- package/examples/shorts/starfield.js +17 -0
- package/examples/shorts/tileLayer.js +3 -5
- package/examples/shorts/tiles.png +0 -0
- package/examples/shorts/tiltedView.js +8 -7
- package/examples/shorts/topDown.js +18 -26
- package/examples/shorts/uiSystem.js +36 -0
- package/examples/starter/build.bat +6 -1
- package/examples/starter/game.js +4 -2
- package/examples/starter/index.html +23 -13
- package/examples/stress/index.html +2 -3
- package/examples/style.css +136 -0
- package/examples/typescript/build.js +1 -2
- package/examples/typescript/game.js +2 -2
- package/examples/typescript/game.ts +1 -1
- package/examples/typescript/index.html +1 -1
- package/examples/uiSystem/game.js +9 -25
- package/examples/uiSystem/index.html +1 -1
- package/package.json +1 -1
- package/plugins/box2d.js +29 -35
- package/plugins/drawUtilities.js +126 -0
- package/plugins/newgrounds.js +1 -1
- package/plugins/pluginExport.js +8 -2
- package/plugins/postProcess.js +2 -2
- package/plugins/uiSystem.js +162 -68
- package/plugins/zzfxm.js +1 -1
- package/reference.md +10 -10
- package/src/engine.js +59 -39
- package/src/engineAudio.js +38 -20
- package/src/engineBuild.bat +6 -1
- package/src/engineBuild.js +32 -7
- package/src/engineDebug.js +53 -26
- package/src/engineDraw.js +108 -57
- package/src/engineExport.js +22 -9
- package/src/engineInput.js +112 -40
- package/src/engineObject.js +68 -67
- package/src/engineParticles.js +26 -9
- package/src/engineSettings.js +15 -16
- package/src/engineTileLayer.js +312 -153
- package/src/engineUtilities.js +198 -130
- package/src/engineWebGL.js +58 -35
|
@@ -3,11 +3,9 @@ function gameInit()
|
|
|
3
3
|
cameraPos = vec2(16); // setup camera
|
|
4
4
|
gravity.y = -.01; // enable gravity
|
|
5
5
|
|
|
6
|
-
// create tile
|
|
6
|
+
// create tile layer
|
|
7
7
|
const pos = vec2();
|
|
8
8
|
const tileLayer = new TileCollisionLayer(pos, vec2(32));
|
|
9
|
-
|
|
10
|
-
// init the tile layer
|
|
11
9
|
for (pos.x = tileLayer.size.x; pos.x--;)
|
|
12
10
|
for (pos.y = tileLayer.size.y; pos.y--;)
|
|
13
11
|
{
|
|
@@ -18,7 +16,7 @@ function gameInit()
|
|
|
18
16
|
// set tile data
|
|
19
17
|
const tileIndex = 1;
|
|
20
18
|
const direction = randInt(4)
|
|
21
|
-
const mirror =
|
|
19
|
+
const mirror = randBool();
|
|
22
20
|
const color = randColor(WHITE, hsl(0,0,.2));
|
|
23
21
|
const data = new TileLayerData(tileIndex, direction, mirror, color);
|
|
24
22
|
tileLayer.setData(pos, data);
|
|
@@ -43,7 +41,7 @@ function gameUpdate()
|
|
|
43
41
|
.99, 1, 1, PI, // damping, angleDamping, gravityScale, cone
|
|
44
42
|
.05, .8, true, false // fadeRate, randomness, collide, additive
|
|
45
43
|
);
|
|
46
|
-
particleEmitter.
|
|
44
|
+
particleEmitter.restitution = .5; // bounce when it collides
|
|
47
45
|
particleEmitter.trailScale = 2; // stretch in direction of motion
|
|
48
46
|
}
|
|
49
47
|
}
|
|
Binary file
|
|
@@ -18,16 +18,17 @@ class Player extends GameObject
|
|
|
18
18
|
{
|
|
19
19
|
update()
|
|
20
20
|
{
|
|
21
|
+
super.update();
|
|
22
|
+
|
|
21
23
|
// apply movement controls
|
|
22
|
-
const moveInput = keyDirection().clampLength(1).scale(.2);
|
|
23
|
-
this.velocity = this.velocity.add(moveInput);
|
|
24
|
+
const moveInput = keyDirection().clampLength(1).scale(.2);
|
|
25
|
+
this.velocity = this.velocity.add(moveInput);
|
|
24
26
|
|
|
25
|
-
|
|
26
|
-
cameraPos = this.pos.add(vec2(0,2));
|
|
27
|
+
// move camera with player
|
|
28
|
+
cameraPos = this.pos.add(vec2(0,2));
|
|
27
29
|
}
|
|
28
30
|
}
|
|
29
31
|
|
|
30
|
-
|
|
31
32
|
function gameInit()
|
|
32
33
|
{
|
|
33
34
|
// setup level
|
|
@@ -35,10 +36,10 @@ function gameInit()
|
|
|
35
36
|
new Player(vec2(), vec2(3), tile(5), 0, RED);
|
|
36
37
|
|
|
37
38
|
// create background objects
|
|
38
|
-
for (let i
|
|
39
|
+
for (let i=1; i<300; ++i)
|
|
39
40
|
new EngineObject(randInCircle(90), vec2(rand(59),rand(59)), 0, 0, hsl(.4,.3,rand(.1,.2),.8), -1e5);
|
|
40
41
|
|
|
41
42
|
// create world objects
|
|
42
|
-
for (let i
|
|
43
|
+
for (let i=1; i<1e3; ++i)
|
|
43
44
|
new GameObject(randInCircle(7+i,7), vec2(rand(1,2),rand(4,9)), 0, 0, hsl(.1,.5,rand(.2,.3)));
|
|
44
45
|
}
|
|
@@ -1,30 +1,22 @@
|
|
|
1
|
-
class
|
|
2
|
-
{
|
|
3
|
-
constructor(pos, size, color)
|
|
4
|
-
{
|
|
5
|
-
super(pos, size, 0, 0, color);
|
|
6
|
-
this.setCollision(); // make object collide
|
|
7
|
-
this.mass = 0; // make object have static physics
|
|
8
|
-
}
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
class Player extends PhysicsObject
|
|
1
|
+
class Player extends EngineObject
|
|
12
2
|
{
|
|
13
3
|
constructor(pos)
|
|
14
4
|
{
|
|
15
|
-
super(pos, vec2(2), RED);
|
|
16
|
-
this.
|
|
17
|
-
this.renderOrder = 1; // render player on top
|
|
5
|
+
super(pos, vec2(2), tile(5), 0, RED);
|
|
6
|
+
this.setCollision(); // make object collide
|
|
7
|
+
this.renderOrder = 1; // render player on top
|
|
18
8
|
}
|
|
19
9
|
|
|
20
10
|
update()
|
|
21
11
|
{
|
|
12
|
+
super.update();
|
|
13
|
+
|
|
22
14
|
// apply movement controls
|
|
23
|
-
const moveInput = keyDirection().clampLength(1).scale(.2);
|
|
24
|
-
this.velocity = this.velocity.add(moveInput);
|
|
15
|
+
const moveInput = keyDirection().clampLength(1).scale(.2);
|
|
16
|
+
this.velocity = this.velocity.add(moveInput);
|
|
25
17
|
|
|
26
|
-
|
|
27
|
-
cameraPos = this.pos;
|
|
18
|
+
// move camera with player
|
|
19
|
+
cameraPos = this.pos;
|
|
28
20
|
}
|
|
29
21
|
}
|
|
30
22
|
|
|
@@ -32,13 +24,13 @@ function gameInit()
|
|
|
32
24
|
{
|
|
33
25
|
// setup level
|
|
34
26
|
objectDefaultDamping = .7;
|
|
35
|
-
new Player
|
|
36
|
-
|
|
37
|
-
// create background objects
|
|
38
|
-
for (let i = 1; i < 300; ++i)
|
|
39
|
-
new EngineObject(randInCircle(90), vec2(rand(59),rand(59)), 0, rand(), hsl(.4,.5,rand(.2)));
|
|
27
|
+
new Player;
|
|
40
28
|
|
|
41
|
-
// create
|
|
42
|
-
for (let i
|
|
43
|
-
|
|
29
|
+
// create collision objects
|
|
30
|
+
for (let i=300; i--;)
|
|
31
|
+
{
|
|
32
|
+
const o = new EngineObject(randInCircle(15+i,7), vec2(rand(4,9),rand(4,9)), 0, 0, hsl(0,0,rand(.8,1)));
|
|
33
|
+
o.setCollision(); // make object collide
|
|
34
|
+
o.mass = 0; // make object have static physics
|
|
35
|
+
}
|
|
44
36
|
}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
// globals objects
|
|
2
|
+
const sound_ui = new Sound([1,0]);
|
|
3
|
+
let uiMenu;
|
|
4
|
+
|
|
5
|
+
function gameInit()
|
|
6
|
+
{
|
|
7
|
+
// load ui system plugin
|
|
8
|
+
new UISystemPlugin;
|
|
9
|
+
uiSystem.defaultSoundPress = new Sound([1,0,220]);
|
|
10
|
+
uiSystem.defaultSoundClick = new Sound([1,0,440]);
|
|
11
|
+
|
|
12
|
+
// setup example menu
|
|
13
|
+
uiMenu = new UIObject(mainCanvasSize.scale(.5));
|
|
14
|
+
const uiBackground = new UIObject(vec2(), vec2(400));
|
|
15
|
+
uiMenu.addChild(uiBackground);
|
|
16
|
+
|
|
17
|
+
// example text
|
|
18
|
+
const textTitle = new UIText(vec2(0,-100), vec2(400, 60), 'LittleJS UI\nSystem Demo');
|
|
19
|
+
uiMenu.addChild(textTitle);
|
|
20
|
+
|
|
21
|
+
// example button
|
|
22
|
+
const button1 = new UIButton(vec2(70,40), vec2(100), 'Test');
|
|
23
|
+
button1.textHeight = 40;
|
|
24
|
+
uiMenu.addChild(button1);
|
|
25
|
+
button1.onClick = ()=> uiBackground.color = randColor();
|
|
26
|
+
|
|
27
|
+
// example checkbox
|
|
28
|
+
const checkbox = new UICheckbox(vec2(-70,40), vec2(50));
|
|
29
|
+
uiMenu.addChild(checkbox);
|
|
30
|
+
|
|
31
|
+
// exit button
|
|
32
|
+
const button2 = new UIButton(vec2(0,140), vec2(300, 50), 'Exit Menu');
|
|
33
|
+
button2.textHeight = 40;
|
|
34
|
+
uiMenu.addChild(button2);
|
|
35
|
+
button2.onClick = ()=> uiMenu.visible = false;
|
|
36
|
+
}
|
package/examples/starter/game.js
CHANGED
|
@@ -7,6 +7,8 @@
|
|
|
7
7
|
|
|
8
8
|
'use strict';
|
|
9
9
|
|
|
10
|
+
// show the LittleJS splash screen
|
|
11
|
+
setShowSplashScreen(true);
|
|
10
12
|
|
|
11
13
|
// fix texture bleeding by shrinking tile slightly
|
|
12
14
|
setTileFixBleedScale(.5);
|
|
@@ -43,7 +45,7 @@ function gameInit()
|
|
|
43
45
|
// set tile data
|
|
44
46
|
const tileIndex = 1;
|
|
45
47
|
const direction = randInt(4)
|
|
46
|
-
const mirror =
|
|
48
|
+
const mirror = randBool();
|
|
47
49
|
const color = randColor();
|
|
48
50
|
const data = new TileLayerData(tileIndex, direction, mirror, color);
|
|
49
51
|
tileLayer.setData(pos, data);
|
|
@@ -71,7 +73,7 @@ function gameInit()
|
|
|
71
73
|
.99, 1, 1, PI, // damping, angleDamping, gravityScale, cone
|
|
72
74
|
.05, .5, true, true // fadeRate, randomness, collide, additive
|
|
73
75
|
);
|
|
74
|
-
particleEmitter.
|
|
76
|
+
particleEmitter.restitution = .3; // bounce when it collides
|
|
75
77
|
particleEmitter.trailScale = 2; // stretch in direction of motion
|
|
76
78
|
}
|
|
77
79
|
|
|
@@ -7,18 +7,28 @@
|
|
|
7
7
|
</head><body>
|
|
8
8
|
|
|
9
9
|
<!-- LittleJS Engine -->
|
|
10
|
-
<script src=../../
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
<script src=../../src/
|
|
14
|
-
<script src=../../src/
|
|
15
|
-
<script src=../../src/
|
|
16
|
-
<script src=../../src/
|
|
17
|
-
<script src=../../src/
|
|
18
|
-
<script src=../../src/
|
|
19
|
-
<script src=../../src/
|
|
20
|
-
<script src=../../src/
|
|
21
|
-
<script src=../../src/
|
|
10
|
+
<script src=../../dist/littlejs.js?11212></script>
|
|
11
|
+
|
|
12
|
+
<!-- LittleJS Engine Source
|
|
13
|
+
<script src=../../src/engineDebug.js></script>
|
|
14
|
+
<script src=../../src/engineUtilities.js></script>
|
|
15
|
+
<script src=../../src/engineSettings.js></script>
|
|
16
|
+
<script src=../../src/engineObject.js></script>
|
|
17
|
+
<script src=../../src/engineDraw.js></script>
|
|
18
|
+
<script src=../../src/engineInput.js></script>
|
|
19
|
+
<script src=../../src/engineAudio.js></script>
|
|
20
|
+
<script src=../../src/engineTileLayer.js></script>
|
|
21
|
+
<script src=../../src/engineParticles.js></script>
|
|
22
|
+
<script src=../../src/engineMedals.js></script>
|
|
23
|
+
<script src=../../src/engineWebGL.js></script>
|
|
24
|
+
<script src=../../src/engine.js></script>
|
|
25
|
+
<script src=../../plugins/box2d.js></script>
|
|
26
|
+
<script src=../../plugins/box2d.wasm.js></script>
|
|
27
|
+
<script src=../../plugins/drawUtilities.js></script>
|
|
28
|
+
<script src=../../plugins/postProcess.js></script>
|
|
29
|
+
<script src=../../plugins/uiSystem.js></script>
|
|
30
|
+
<script src=../../plugins/zzfxm.js></script>
|
|
31
|
+
-->
|
|
22
32
|
|
|
23
33
|
<!-- Add your game scripts here -->
|
|
24
|
-
<script src=game.js?
|
|
34
|
+
<script src=game.js?11212></script>
|
|
@@ -102,7 +102,7 @@ function gameRender()
|
|
|
102
102
|
{
|
|
103
103
|
// track fps and update stats
|
|
104
104
|
const frameTimeMS = Date.now();
|
|
105
|
-
fpsDisplay = LJS.lerp(
|
|
105
|
+
fpsDisplay = LJS.lerp(fpsDisplay||0, 1e3/(frameTimeMS - timeMS||1), .05);
|
|
106
106
|
timeMS = frameTimeMS;
|
|
107
107
|
|
|
108
108
|
// show stats
|
|
@@ -163,5 +163,4 @@ LJS.engineInit(gameInit, gameUpdate, gameUpdatePost, gameRender, gameRenderPost,
|
|
|
163
163
|
///////////////////////////////////////////////////////////////////////////////
|
|
164
164
|
// music - Depp Loop
|
|
165
165
|
const music = new LJS.ZzFXMusic([[[.6,0,76,,,1,1,.5,,,,,.1,,,.06,,.5,.2,,-700],[,0,43,.01,,.2,2,,,,,,,,,,.01],[,0,170,.003,,.008,,.97,-35,53,,,,,,.1],[.8,0,270,,,.12,3,1.65,-2,,,,,4.5,,.02],[,0,86,,,.1,,.7,,,,.5,,6.7,1,.05],[,0,41,,.05,.4,2,0,,,9,.01,,,,.08,.02],[,0,2200,,,.04,3,2,,,800,.02,,4.8,,.01,.1],[.3,0,16,,,.3,3]],[[[1,-1,21,21,33,21,21,33,21,21,33,21,21,33,21,21,33,33,21,21,33,21,21,33,21,21,33,21,21,33,21,21,33,33,21,21,33,21,21,33,21,21,33,21,21,33,21,21,33,33,21,21,33,21,21,33,21,21,33,21,21,33,21,21,33,33],[3,1,22,,,,,,,,,,,,,,,,,,,,,,,,,,,,24,,,,24,,,,,,,,,,,,,,,,,,,,,,,,22,,22,,22,,,,],[5,-1,21,,,,,,,,,,,,,,,,,,,,,,,,,,,,24,,,,23,,,,,,,,,,,,,,,,,,,,,,,,24,,23,,21,,,,],[,1,21,,,,,,,,,,,,,,,,,,,,,,,,,,,,24,,,,23,,,,,,,,,,,,,,,,,,,,,,,,24,,23,,21,,,,]],[[1,-1,21,21,33,21,21,33,21,21,33,21,21,33,21,21,33,33,21,21,33,21,21,33,21,21,33,21,21,33,21,21,33,33,21,21,33,21,21,33,21,21,33,21,21,33,21,21,33,33,21,21,33,21,21,33,21,21,33,21,21,33,21,21,33,33],[3,1,24,,,,,,,,27,,,,,,,,,,,,,,,,27,,,,24,,,,24,,,,,,,,27,,,,,,,,,,,,,,,,24,,24,,24,,,,],[5,-1,21,,,,,,,,,,,,,,,,,,,,,,,,,,,,24,,,,23,,,,,,,,,,,,,,,,,,,,,,,,24,,23,,21,,,,],[,1,21,,,,,,,,,,,,,,,,,,,,,,,,,,,,24,,,,23,,,,,,,,,,,,,,,,,,,,,,,,24,,23,,21,,,,],[6,1,,,34,34,34,,,,,,34,34,,,,,34,,,,34,34,,,,,34,,,,34,,,,34,34,34,,,,,,34,,,,,,34,34,,,34,34,,,,,,,,,34,34],[4,1,,,,,,,24,,,,,,24,,24,,,,24,,,,24,,,,,,,,,,,,,,,,24,,,,,,24,,24,,,,24,,,,24,,,,,,,,,,]],[[1,-1,21,21,33,21,21,33,21,21,33,21,21,33,21,21,33,33,21,21,33,21,21,33,21,21,33,21,21,33,21,21,33,33,23,23,35,23,23,36,23,23,35,23,23,36,23,23,35,35,23,23,35,23,23,35,23,23,36,23,23,35,23,23,36,36],[5,-1,21,,,19,,,21,,,,,,,,,,21,,,19,,,17,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,],[3,1,24,,,24,,,24,,,,,,,,,,24,,,24,,,24,,,,24.75,24.5,24.26,24.01,24.01,24.01,,,,,25,,,,,,,,25,,,,,,,,25,,,,,,,,25,25,25,25],[4,-1,,,,,,,,,,,,,,,,,,,,,,,,,,,24.75,24.5,24.26,24.01,24.01,24.01,24.01,24,,24,24,,24,24,24,24,,24,24,,24,,24,24,,24,24,,24,24,24,24,,24,24,,24,24],[7,-1,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,23,,21,23,,35,,23,,21,23,,35,,35,,23,,21,23,,35,,21,23,,35,,21,23,,,],[6,1,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,34,36,34,,33,34,34,36,31,36,34,,31,34,32,,33,36,34,,31,34,34,36,33,36,33,,31,,,]],[[1,-1,21,21,33,21,21,33,21,21,33,21,21,33,21,21,33,33,21,21,33,21,21,33,21,21,33,21,21,33,21,21,33,33,17,17,29,17,17,29,17,17,29,17,17,29,17,17,29,29,17,17,29,17,17,29,17,17,29,17,17,29,17,17,29,29],[4,1,24,24,,24,24,,24,24,24,24,,24,24,,24,,24,24,,24,24,,24,24,24,24,,24,24,,24,24,24,24,,24,24,,24,24,24,,,24,24,,24,,24,24,,24,24,,24,24,24,24,,24,24,,24,24],[7,-1,21,,19,21,,33,,21,,19,21,,33,,33,,21,,19,21,,33,,21,,19,21,,33,,33,,17,,17,17,29,17,17,29,17,,17,17,29,17,17,29,17,,17,17,29,17,17,29,17,,17,17,29,17,17,29],[2,1,,34,34,34,,34,34,34,,34,34,34,,34,34,34,,34,34,34,,34,34,34,,34,34,34,,34,,,,34,34,34,,34,34,34,,34,34,34,,34,34,34,,34,34,34,,34,34,34,,34,34,34,,34,,,],[6,1,,,36,,,,,,36,,36,,,,,,,,36,,,,,,36,,36,,,,,,,,36,,,,,,,,,,,,,,,,36,,,,,,36,,36,,,,,,],[3,1,,,,,25,,,,,,,,25,,,,,,,,25,,,,,,,,25,25,25,25,,,,,25,,,,,25,,,25,,,,,,,,25,,,,,,,,25,25,25,25]],[[1,-1,14,14,26,14,14,26,14,14,26,14,14,26,14,14,26,26,14,14,26,14,14,26,14,14,26,14,14,26,14,14,26,26,17,17,29,17,17,29,17,17,29,17,17,29,17,17,29,29,19,19,31,19,19,31,19,19,31,19,19,31,19,19,31,31],[4,1,24,24,,24,24,,24,24,24,24,,24,24,,24,,24,24,,24,24,,24,24,24,24,,24,24,,24,24,24,24,,24,24,,24,24,24,24,,24,24,,36,,24,24,,24,24,,24,24,24,24,,24,24,,24,24],[7,-1,14,,14,14,26,14,14,26,14,,14,14,26,14,14,26,14,,14,14,26,14,14,26,14,,14,14,26,14,14,26,17,,17,17,29,17,17,29,17,,17,17,29,17,17,29,19,,19,19,31,19,19,31,19,,19,19,31,19,19,31],[2,1,,36,36,36,,36,36,36,,36,36,36,,36,36,36,,36,36,36,,36,36,36,,36,36,36,,36,,,,36,36,36,,36,36,36,,36,36,36,,36,36,36,,36,36,36,,36,36,36,,36,36,36,,36,,,],[3,1,,,,,25,,,,,,,,25,,,,,,,,25,,,,,,,,25,25,25,25,,,,,25,,,,,,,,25,,,,,,,,25,,,,,,,,25,25,25,25],[6,1,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,34,,,,,,34,,34,,,,,,,,34,,,,,,34,,34,,,,,,]]],[0,1,1,2,3,4,4]]);
|
|
166
|
-
|
|
167
|
-
</script>
|
|
166
|
+
</script>
|
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
html, body
|
|
2
|
+
{
|
|
3
|
+
height: 100%;
|
|
4
|
+
display: flex;
|
|
5
|
+
flex-direction: column;
|
|
6
|
+
}
|
|
7
|
+
#container1
|
|
8
|
+
{
|
|
9
|
+
height: 100%;
|
|
10
|
+
display: flex;
|
|
11
|
+
gap: 4px;
|
|
12
|
+
}
|
|
13
|
+
#container2
|
|
14
|
+
{
|
|
15
|
+
display: flex;
|
|
16
|
+
flex-direction: column;
|
|
17
|
+
gap: 4px;
|
|
18
|
+
}
|
|
19
|
+
#iframeContainer
|
|
20
|
+
{
|
|
21
|
+
border: 2px solid;
|
|
22
|
+
background: #000;
|
|
23
|
+
}
|
|
24
|
+
iframe
|
|
25
|
+
{
|
|
26
|
+
width: 100%;
|
|
27
|
+
height: 100%;
|
|
28
|
+
border: none;
|
|
29
|
+
}
|
|
30
|
+
#selectExample
|
|
31
|
+
{
|
|
32
|
+
flex-grow: 1;
|
|
33
|
+
}
|
|
34
|
+
.CodeMirror,
|
|
35
|
+
#textareaCode
|
|
36
|
+
{
|
|
37
|
+
flex-grow: 1;
|
|
38
|
+
padding: 5px;
|
|
39
|
+
resize: none;
|
|
40
|
+
color: #fff;
|
|
41
|
+
background: #000;
|
|
42
|
+
font-size: 20px;
|
|
43
|
+
}
|
|
44
|
+
#textareaConsole,
|
|
45
|
+
#textareaError
|
|
46
|
+
{
|
|
47
|
+
flex-grow: .3;
|
|
48
|
+
padding: 5px;
|
|
49
|
+
resize: none;
|
|
50
|
+
display: none;
|
|
51
|
+
color:#f22;
|
|
52
|
+
background: #111;
|
|
53
|
+
}
|
|
54
|
+
#textareaConsole
|
|
55
|
+
{
|
|
56
|
+
color: #ff0;
|
|
57
|
+
}
|
|
58
|
+
#container3
|
|
59
|
+
{
|
|
60
|
+
width: 100%;
|
|
61
|
+
height: 100%;
|
|
62
|
+
display: flex;
|
|
63
|
+
flex-direction: column;
|
|
64
|
+
gap: 2px;
|
|
65
|
+
}
|
|
66
|
+
#titleInfo
|
|
67
|
+
{
|
|
68
|
+
margin: 5px;
|
|
69
|
+
text-align: center;
|
|
70
|
+
font-size: 40px;
|
|
71
|
+
}
|
|
72
|
+
#exampleInfo
|
|
73
|
+
{
|
|
74
|
+
margin: 0px;
|
|
75
|
+
text-align: center;
|
|
76
|
+
font-size: 20px;
|
|
77
|
+
}
|
|
78
|
+
#exampleLink
|
|
79
|
+
{
|
|
80
|
+
margin: 0px;
|
|
81
|
+
text-align: center;
|
|
82
|
+
font-size: 20px;
|
|
83
|
+
display: inline-block;
|
|
84
|
+
align-self: center;
|
|
85
|
+
}
|
|
86
|
+
select
|
|
87
|
+
{
|
|
88
|
+
color:#fff;
|
|
89
|
+
background-color: #111;
|
|
90
|
+
width:100%;
|
|
91
|
+
}
|
|
92
|
+
hr
|
|
93
|
+
{
|
|
94
|
+
border: 1px solid #555;
|
|
95
|
+
margin:9px;
|
|
96
|
+
}
|
|
97
|
+
button
|
|
98
|
+
{
|
|
99
|
+
color:#fff;
|
|
100
|
+
background-color: #111;
|
|
101
|
+
border: 1px solid #555;
|
|
102
|
+
margin:0px 4px;
|
|
103
|
+
padding: 2px 8px;
|
|
104
|
+
cursor: pointer;
|
|
105
|
+
}
|
|
106
|
+
button:disabled
|
|
107
|
+
{
|
|
108
|
+
color: #aaa;
|
|
109
|
+
background-color: #666;
|
|
110
|
+
border-color: #666;
|
|
111
|
+
}
|
|
112
|
+
.error-line
|
|
113
|
+
{
|
|
114
|
+
background-color: rgba(255, 0, 0, 0.15) !important;
|
|
115
|
+
border-left: 3px solid #ff0000 !important;
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
/* LittleJS CodeMirror Theme */
|
|
119
|
+
.cm-s-littlejs.CodeMirror { background: #080808; color: #aef; }
|
|
120
|
+
.cm-s-littlejs div.CodeMirror-selected { background: #068; }
|
|
121
|
+
.cm-s-littlejs .CodeMirror-gutters {background: #222; border-right: 0px;}
|
|
122
|
+
.cm-s-littlejs .CodeMirror-linenumber { color: #aaa; }
|
|
123
|
+
.cm-s-littlejs .CodeMirror-cursor { border-left: 2px solid #fff; }
|
|
124
|
+
.cm-s-littlejs .cm-keyword { color: #6e1; }
|
|
125
|
+
.cm-s-littlejs .cm-def { color: #fab; }
|
|
126
|
+
.cm-s-littlejs .cm-operator { color: #1be; }
|
|
127
|
+
.cm-s-littlejs .cm-property,
|
|
128
|
+
.cm-s-littlejs span.cm-variable,
|
|
129
|
+
.cm-s-littlejs span.cm-variable-2,
|
|
130
|
+
.cm-s-littlejs span.cm-variable-3 { color: #ddd; }
|
|
131
|
+
.cm-s-littlejs .cm-builtin,
|
|
132
|
+
.cm-s-littlejs .cm-number { color: #e15; }
|
|
133
|
+
.cm-s-littlejs .cm-comment { color:#888; font-style:italic; }
|
|
134
|
+
.cm-s-littlejs .cm-string,
|
|
135
|
+
.cm-s-littlejs .cm-string-2 { color:#fda; }
|
|
136
|
+
.cm-s-littlejs .CodeMirror-matchingbracket { background-color: #381 !important; }
|
|
@@ -2,7 +2,6 @@
|
|
|
2
2
|
|
|
3
3
|
const PROGRAM_NAME = 'game';
|
|
4
4
|
const BUILD_FOLDER = 'build';
|
|
5
|
-
const ROOT_FOLDER = 'examples/typescript';
|
|
6
5
|
|
|
7
6
|
// Define TypeScript source files
|
|
8
7
|
const tsSourceFiles = [
|
|
@@ -29,4 +28,4 @@ console.log(`TypeScript built in ${((Date.now() - startTime)/1e3).toFixed(2)} se
|
|
|
29
28
|
|
|
30
29
|
console.log(`Moving js files back to root...`);
|
|
31
30
|
for(const file of jsSourceFiles)
|
|
32
|
-
fs.copyFileSync(`${BUILD_FOLDER}/${file}`, file);
|
|
31
|
+
fs.copyFileSync(`${BUILD_FOLDER}/${file}`, file);
|
|
@@ -60,7 +60,7 @@ function gameInit() {
|
|
|
60
60
|
.99, 1, 1, Math.PI, // damping, angleDamping, gravityScale, cone
|
|
61
61
|
.05, .5, true, true // fadeRate, randomness, collide, additive
|
|
62
62
|
);
|
|
63
|
-
particleEmitter.
|
|
63
|
+
particleEmitter.restitution = .3; // bounce when it collides
|
|
64
64
|
particleEmitter.trailScale = 2; // stretch in direction of motion
|
|
65
65
|
}
|
|
66
66
|
///////////////////////////////////////////////////////////////////////////////
|
|
@@ -97,4 +97,4 @@ function gameRenderPost() {
|
|
|
97
97
|
}
|
|
98
98
|
///////////////////////////////////////////////////////////////////////////////
|
|
99
99
|
// Startup LittleJS Engine
|
|
100
|
-
LJS.engineInit(gameInit, gameUpdate, gameUpdatePost, gameRender, gameRenderPost, ['tiles.png']);
|
|
100
|
+
LJS.engineInit(gameInit, gameUpdate, gameUpdatePost, gameRender, gameRenderPost, ['tiles.png']);
|
|
@@ -77,7 +77,7 @@ function gameInit()
|
|
|
77
77
|
.99, 1, 1, Math.PI, // damping, angleDamping, gravityScale, cone
|
|
78
78
|
.05, .5, true, true // fadeRate, randomness, collide, additive
|
|
79
79
|
);
|
|
80
|
-
particleEmitter.
|
|
80
|
+
particleEmitter.restitution = .3; // bounce when it collides
|
|
81
81
|
particleEmitter.trailScale = 2; // stretch in direction of motion
|
|
82
82
|
}
|
|
83
83
|
|
|
@@ -10,9 +10,6 @@
|
|
|
10
10
|
import * as LJS from '../../dist/littlejs.esm.js';
|
|
11
11
|
const {vec2, hsl, tile} = LJS;
|
|
12
12
|
|
|
13
|
-
// sound effects
|
|
14
|
-
const sound_ui = new LJS.Sound([1,0]);
|
|
15
|
-
|
|
16
13
|
// UI system
|
|
17
14
|
let uiRoot, uiMenu;
|
|
18
15
|
const getMenuVisible =()=> uiMenu.visible;
|
|
@@ -24,8 +21,11 @@ LJS.setCanvasPixelated(false);
|
|
|
24
21
|
|
|
25
22
|
function createUI()
|
|
26
23
|
{
|
|
24
|
+
LJS.uiSystem.defaultSoundPress = new LJS.Sound([1,0,220]);
|
|
25
|
+
LJS.uiSystem.defaultSoundClick = new LJS.Sound([1,0,440]);
|
|
26
|
+
|
|
27
27
|
// setup root to attach all ui elements to
|
|
28
|
-
uiRoot = new LJS.UIObject
|
|
28
|
+
uiRoot = new LJS.UIObject;
|
|
29
29
|
const uiInfo = new LJS.UIText(vec2(0,90), vec2(1e3, 70),
|
|
30
30
|
'LittleJS UI System Example\nM = Toggle menu');
|
|
31
31
|
uiInfo.textColor = LJS.WHITE;
|
|
@@ -33,7 +33,7 @@ function createUI()
|
|
|
33
33
|
uiRoot.addChild(uiInfo);
|
|
34
34
|
|
|
35
35
|
// setup example menu
|
|
36
|
-
uiMenu = new LJS.UIObject(vec2(0,
|
|
36
|
+
uiMenu = new LJS.UIObject(vec2(0,500));
|
|
37
37
|
uiRoot.addChild(uiMenu);
|
|
38
38
|
const uiBackground = new LJS.UIObject(vec2(0,0), vec2(450,580));
|
|
39
39
|
uiBackground.lineWidth = 8;
|
|
@@ -47,7 +47,7 @@ function createUI()
|
|
|
47
47
|
textTitle.lineColor = LJS.BLUE;
|
|
48
48
|
|
|
49
49
|
// example multiline text
|
|
50
|
-
const textTest = new LJS.UIText(vec2(-60,-
|
|
50
|
+
const textTest = new LJS.UIText(vec2(-60,-120), vec2(300, 50), 'Test Text\nSecond text line.')
|
|
51
51
|
uiMenu.addChild(textTest);
|
|
52
52
|
|
|
53
53
|
// example tile image
|
|
@@ -57,12 +57,7 @@ function createUI()
|
|
|
57
57
|
// example checkbox
|
|
58
58
|
const checkbox = new LJS.UICheckbox(vec2(-140,-20), vec2(40));
|
|
59
59
|
uiMenu.addChild(checkbox);
|
|
60
|
-
checkbox.
|
|
61
|
-
{
|
|
62
|
-
checkbox.checked = !checkbox.checked;
|
|
63
|
-
console.log('Checkbox clicked');
|
|
64
|
-
sound_ui.play(0,.5,checkbox.checked?4:1);
|
|
65
|
-
}
|
|
60
|
+
checkbox.onChange = ()=> console.log('Checkbox clicked');
|
|
66
61
|
|
|
67
62
|
// text attached to checkbox
|
|
68
63
|
const checkboxText = new LJS.UIText(vec2(170,0), vec2(300, 40), 'Test Checkbox');
|
|
@@ -72,27 +67,16 @@ function createUI()
|
|
|
72
67
|
const scrollbar = new LJS.UIScrollbar(vec2(0,60), vec2(350, 50));
|
|
73
68
|
uiMenu.addChild(scrollbar);
|
|
74
69
|
scrollbar.onChange = ()=> console.log('New scrollbar value:', scrollbar.value);
|
|
75
|
-
scrollbar.onPress = ()=> sound_ui.play(0,.3,2);
|
|
76
|
-
scrollbar.onRelease = ()=> sound_ui.play(0,.3,4);
|
|
77
70
|
|
|
78
71
|
// example button
|
|
79
72
|
const button1 = new LJS.UIButton(vec2(0,140), vec2(350, 50), 'Test Button');
|
|
80
73
|
uiMenu.addChild(button1);
|
|
81
|
-
button1.
|
|
82
|
-
{
|
|
83
|
-
console.log('Button 1 clicked');
|
|
84
|
-
sound_ui.play();
|
|
85
|
-
}
|
|
74
|
+
button1.onClick = ()=> console.log('Button 1 clicked');
|
|
86
75
|
|
|
87
76
|
// exit button
|
|
88
77
|
const button2 = new LJS.UIButton(vec2(0,220), vec2(350, 50), 'Exit Menu');
|
|
89
78
|
uiMenu.addChild(button2);
|
|
90
|
-
button2.
|
|
91
|
-
{
|
|
92
|
-
console.log('Button 2 clicked');
|
|
93
|
-
sound_ui.play(0,.5,2);
|
|
94
|
-
setMenuVisible(false);
|
|
95
|
-
}
|
|
79
|
+
button2.onClick = ()=> setMenuVisible(false);
|
|
96
80
|
}
|
|
97
81
|
|
|
98
82
|
///////////////////////////////////////////////////////////////////////////////
|