littlejsengine 1.12.6 → 1.13.4
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/README.md +15 -12
- package/dist/littlejs.d.ts +466 -236
- package/dist/littlejs.esm.js +6126 -5370
- package/dist/littlejs.esm.min.js +4 -1
- package/dist/littlejs.js +6093 -5359
- package/dist/littlejs.min.js +4 -1
- package/dist/littlejs.release.js +5614 -4907
- package/examples/box2d/game.js +2 -2
- package/examples/box2d/gameObjects.js +8 -7
- package/examples/box2d/index.html +1 -1
- package/examples/box2d/scenes.js +8 -8
- 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 +46 -43
- package/examples/breakoutTutorial/game.js +3 -3
- package/examples/breakoutTutorial/index.html +1 -1
- package/examples/electron/build.bat +7 -0
- package/examples/electron/build.js +124 -0
- package/examples/electron/electron.js +35 -0
- package/examples/electron/game.js +140 -0
- package/examples/electron/index.html +13 -0
- package/examples/electron/package.json +12 -0
- package/examples/electron/tiles.png +0 -0
- package/examples/empty/game.js +1 -0
- package/examples/empty/index.html +1 -1
- package/examples/htmlMenu/game.js +1 -1
- package/examples/htmlMenu/index.html +1 -1
- package/examples/index.html +486 -182
- package/examples/module/game.js +6 -3
- package/examples/module/index.html +1 -1
- package/examples/particles/index.html +12 -3
- package/examples/platformer/game.js +4 -4
- 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 +23 -3
- package/examples/shorts/blending.js +9 -5
- package/examples/shorts/box2d.js +1 -1
- package/examples/shorts/box2dCar.js +9 -13
- package/examples/shorts/clock.js +1 -1
- package/examples/shorts/colors.js +2 -2
- 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/raycasting.js +71 -0
- package/examples/shorts/shapes.js +9 -9
- package/examples/shorts/slidingPuzzle.js +42 -0
- package/examples/shorts/spaceGame.js +56 -0
- package/examples/shorts/starfield.js +15 -0
- package/examples/shorts/systemFont.js +1 -1
- 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 +5 -7
- package/examples/starter/build.bat +6 -1
- package/examples/starter/build.js +9 -8
- package/examples/starter/game.js +7 -4
- package/examples/starter/index.html +23 -13
- package/examples/stress/index.html +7 -8
- package/examples/style.css +139 -0
- package/examples/typescript/build.js +2 -3
- package/examples/typescript/game.js +4 -4
- package/examples/typescript/game.ts +6 -3
- package/examples/typescript/index.html +1 -1
- package/examples/uiSystem/game.js +10 -25
- package/examples/uiSystem/index.html +1 -1
- package/package.json +2 -2
- package/plugins/box2d.js +22 -97
- package/plugins/drawUtilities.js +132 -0
- package/plugins/newgrounds.js +1 -1
- package/plugins/pluginExport.js +7 -1
- package/plugins/postProcess.js +9 -2
- package/plugins/uiSystem.js +155 -67
- package/plugins/zzfxm.js +1 -1
- package/reference.md +10 -10
- package/src/engine.js +56 -30
- package/src/engineAudio.js +15 -6
- package/src/engineBuild.bat +6 -1
- package/src/engineBuild.js +20 -5
- package/src/engineDebug.js +55 -28
- package/src/engineDraw.js +321 -177
- package/src/engineExport.js +27 -9
- package/src/engineInput.js +110 -38
- package/src/engineMedals.js +4 -4
- package/src/engineObject.js +71 -70
- package/src/engineParticles.js +33 -9
- package/src/engineSettings.js +69 -23
- package/src/engineTileLayer.js +312 -153
- package/src/engineUtilities.js +187 -135
- package/src/engineWebGL.js +70 -39
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
class Player extends EngineObject
|
|
2
|
+
{
|
|
3
|
+
constructor(pos)
|
|
4
|
+
{
|
|
5
|
+
super(pos, vec2(1,2), tile(8), 0, CYAN);
|
|
6
|
+
this.damping = .97;
|
|
7
|
+
this.angleDamping = .95;
|
|
8
|
+
this.shootTimer = new Timer;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
update()
|
|
12
|
+
{
|
|
13
|
+
super.update();
|
|
14
|
+
|
|
15
|
+
// space ship controls
|
|
16
|
+
const moveInput = keyDirection();
|
|
17
|
+
this.applyAngularAcceleration(moveInput.x * .005);
|
|
18
|
+
this.applyAcceleration(vec2().setAngle(this.angle, moveInput.y*.02));
|
|
19
|
+
if (!this.shootTimer.active() && (keyIsDown('Space') || mouseIsDown(0)))
|
|
20
|
+
{
|
|
21
|
+
// shoot bullet
|
|
22
|
+
const pos = this.pos.add(vec2(0,1).rotate(cameraAngle));
|
|
23
|
+
const bullet = new EngineObject(pos, vec2(.2,.5), 0, this.angle, YELLOW);
|
|
24
|
+
bullet.velocity = this.velocity.add(vec2(0,.5).rotate(this.angle));
|
|
25
|
+
this.shootTimer.set(.1);
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
// move camera with player
|
|
29
|
+
cameraPos = this.pos;
|
|
30
|
+
cameraAngle = this.angle;
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
function gameInit()
|
|
35
|
+
{
|
|
36
|
+
new Player(vec2(0,4));
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
function gameRender()
|
|
40
|
+
{
|
|
41
|
+
// draw wrapped starfield with parallax
|
|
42
|
+
const range = 32, halfRange = range/2;
|
|
43
|
+
|
|
44
|
+
// precreate variables to avoid overhead
|
|
45
|
+
const pos = vec2(), size = vec2(), color = WHITE;
|
|
46
|
+
for (let i=1e3; i--;)
|
|
47
|
+
{
|
|
48
|
+
// use math to generate random star positions
|
|
49
|
+
const parallax = i%.13-1;
|
|
50
|
+
pos.x = mod(i**2.1 + cameraPos.x*parallax, range) + cameraPos.x - halfRange;
|
|
51
|
+
pos.y = mod(i**3.1 + cameraPos.y*parallax, range) + cameraPos.y - halfRange;
|
|
52
|
+
size.x = size.y = i%.07+.03;
|
|
53
|
+
color.a = .1+i%.9;
|
|
54
|
+
drawRect(pos, size, color);
|
|
55
|
+
}
|
|
56
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
function gameRender()
|
|
2
|
+
{
|
|
3
|
+
// precreate variables to avoid overhead
|
|
4
|
+
const pos = vec2(), size = vec2(), color = WHITE;
|
|
5
|
+
for (let i=2e3; i--;)
|
|
6
|
+
{
|
|
7
|
+
// use math to generate random star positions
|
|
8
|
+
const offset = time*(9+i**2.1%15) + i**2.3;
|
|
9
|
+
pos.x = offset%70 - 35;
|
|
10
|
+
pos.y = i/110 - 9;
|
|
11
|
+
size.x = size.y = i%.11 + .07;
|
|
12
|
+
color.set(1,1,1,Math.sin(i)**4);
|
|
13
|
+
drawRect(pos, size, color);
|
|
14
|
+
}
|
|
15
|
+
}
|
|
@@ -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
|
}
|
|
@@ -6,6 +6,9 @@ function gameInit()
|
|
|
6
6
|
{
|
|
7
7
|
// load ui system plugin
|
|
8
8
|
new UISystemPlugin;
|
|
9
|
+
uiSystem.defaultSoundPress = new Sound([1,0,220]);
|
|
10
|
+
uiSystem.defaultSoundClick = new Sound([1,0,440]);
|
|
11
|
+
uiSystem.defaultCornerRadius = 8;
|
|
9
12
|
|
|
10
13
|
// setup example menu
|
|
11
14
|
uiMenu = new UIObject(mainCanvasSize.scale(.5));
|
|
@@ -20,20 +23,15 @@ function gameInit()
|
|
|
20
23
|
const button1 = new UIButton(vec2(70,40), vec2(100), 'Test');
|
|
21
24
|
button1.textHeight = 40;
|
|
22
25
|
uiMenu.addChild(button1);
|
|
23
|
-
button1.
|
|
26
|
+
button1.onClick = ()=> uiBackground.color = randColor();
|
|
24
27
|
|
|
25
28
|
// example checkbox
|
|
26
29
|
const checkbox = new UICheckbox(vec2(-70,40), vec2(50));
|
|
27
30
|
uiMenu.addChild(checkbox);
|
|
28
|
-
checkbox.onChange = ()=> sound_ui.play(0,1,checkbox.checked?4:1);
|
|
29
31
|
|
|
30
32
|
// exit button
|
|
31
33
|
const button2 = new UIButton(vec2(0,140), vec2(300, 50), 'Exit Menu');
|
|
32
34
|
button2.textHeight = 40;
|
|
33
35
|
uiMenu.addChild(button2);
|
|
34
|
-
button2.
|
|
35
|
-
{
|
|
36
|
-
uiMenu.visible = false;
|
|
37
|
-
sound_ui.play(0,1,2);
|
|
38
|
-
}
|
|
36
|
+
button2.onClick = ()=> uiMenu.visible = false;
|
|
39
37
|
}
|
|
@@ -36,7 +36,7 @@ fs.rmSync(`${PROGRAM_NAME}.zip`, { force: true });
|
|
|
36
36
|
fs.mkdirSync(BUILD_FOLDER);
|
|
37
37
|
|
|
38
38
|
// copy data files
|
|
39
|
-
for(const file of dataFiles)
|
|
39
|
+
for (const file of dataFiles)
|
|
40
40
|
fs.copyFileSync(file, `${BUILD_FOLDER}/${file}`);
|
|
41
41
|
|
|
42
42
|
Build
|
|
@@ -50,7 +50,6 @@ Build
|
|
|
50
50
|
|
|
51
51
|
console.log('');
|
|
52
52
|
console.log(`Build Completed in ${((Date.now() - startTime)/1e3).toFixed(2)} seconds!`);
|
|
53
|
-
console.log(`Size of ${PROGRAM_NAME}.zip: ${fs.statSync(`${PROGRAM_NAME}.zip`).size} bytes`);
|
|
54
53
|
|
|
55
54
|
///////////////////////////////////////////////////////////////////////////////
|
|
56
55
|
|
|
@@ -73,7 +72,7 @@ function Build(outputFile, files=[], buildSteps=[])
|
|
|
73
72
|
|
|
74
73
|
function closureCompilerStep(filename)
|
|
75
74
|
{
|
|
76
|
-
console.log(
|
|
75
|
+
console.log('Running closure compiler...');
|
|
77
76
|
|
|
78
77
|
// use closer compiler to minify the code
|
|
79
78
|
const filenameTemp = filename + '.tmp';
|
|
@@ -84,22 +83,23 @@ function closureCompilerStep(filename)
|
|
|
84
83
|
|
|
85
84
|
function uglifyBuildStep(filename)
|
|
86
85
|
{
|
|
87
|
-
console.log(
|
|
86
|
+
console.log('Running uglify...');
|
|
88
87
|
child_process.execSync(`npx uglifyjs ${filename} -c -m -o ${filename}`, {stdio: 'inherit'});
|
|
89
88
|
};
|
|
90
89
|
|
|
91
90
|
function roadrollerBuildStep(filename)
|
|
92
91
|
{
|
|
93
|
-
console.log(
|
|
92
|
+
console.log('Running roadroller...');
|
|
94
93
|
child_process.execSync(`npx roadroller ${filename} -o ${filename}`, {stdio: 'inherit'});
|
|
95
94
|
};
|
|
96
95
|
|
|
97
96
|
function htmlBuildStep(filename)
|
|
98
97
|
{
|
|
99
|
-
console.log(
|
|
98
|
+
console.log('Building html...');
|
|
100
99
|
|
|
101
100
|
// create html file
|
|
102
|
-
let buffer = '
|
|
101
|
+
let buffer = ''
|
|
102
|
+
buffer += '<!DOCTYPE html>';
|
|
103
103
|
buffer += '<head>';
|
|
104
104
|
buffer += `<title>${PROGRAM_TITLE}</title>`;
|
|
105
105
|
buffer += '<meta charset=utf-8>';
|
|
@@ -115,8 +115,9 @@ function htmlBuildStep(filename)
|
|
|
115
115
|
|
|
116
116
|
function zipBuildStep(filename)
|
|
117
117
|
{
|
|
118
|
-
console.log(
|
|
118
|
+
console.log('Zipping...');
|
|
119
119
|
const sources = ['index.html', ...dataFiles];
|
|
120
120
|
const sourceList = sources.join(' ');
|
|
121
121
|
child_process.execSync(`npx bestzip ../${PROGRAM_NAME}.zip ${sourceList}`, {cwd:BUILD_FOLDER, stdio: 'inherit'});
|
|
122
|
+
console.log(`Size of ${PROGRAM_NAME}.zip: ${fs.statSync(`${PROGRAM_NAME}.zip`).size} bytes`);
|
|
122
123
|
};
|
package/examples/starter/game.js
CHANGED
|
@@ -45,7 +45,7 @@ function gameInit()
|
|
|
45
45
|
// set tile data
|
|
46
46
|
const tileIndex = 1;
|
|
47
47
|
const direction = randInt(4)
|
|
48
|
-
const mirror =
|
|
48
|
+
const mirror = randBool();
|
|
49
49
|
const color = randColor();
|
|
50
50
|
const data = new TileLayerData(tileIndex, direction, mirror, color);
|
|
51
51
|
tileLayer.setData(pos, data);
|
|
@@ -73,7 +73,7 @@ function gameInit()
|
|
|
73
73
|
.99, 1, 1, PI, // damping, angleDamping, gravityScale, cone
|
|
74
74
|
.05, .5, true, true // fadeRate, randomness, collide, additive
|
|
75
75
|
);
|
|
76
|
-
particleEmitter.
|
|
76
|
+
particleEmitter.restitution = .3; // bounce when it collides
|
|
77
77
|
particleEmitter.trailScale = 2; // stretch in direction of motion
|
|
78
78
|
}
|
|
79
79
|
|
|
@@ -104,7 +104,10 @@ function gameUpdate()
|
|
|
104
104
|
|
|
105
105
|
// move particles to mouse location if on screen
|
|
106
106
|
if (mousePosScreen.x)
|
|
107
|
+
{
|
|
107
108
|
particleEmitter.pos = mousePos;
|
|
109
|
+
particleEmitter.velocity = mouseDelta.scale(.3*timeDelta);
|
|
110
|
+
}
|
|
108
111
|
}
|
|
109
112
|
|
|
110
113
|
///////////////////////////////////////////////////////////////////////////////
|
|
@@ -116,8 +119,8 @@ function gameUpdatePost()
|
|
|
116
119
|
///////////////////////////////////////////////////////////////////////////////
|
|
117
120
|
function gameRender()
|
|
118
121
|
{
|
|
119
|
-
// draw a grey square in the background
|
|
120
|
-
drawRect(vec2(16,8), vec2(20,14), hsl(0,0,.6)
|
|
122
|
+
// draw a grey square in the background
|
|
123
|
+
drawRect(vec2(16,8), vec2(20,14), hsl(0,0,.6));
|
|
121
124
|
|
|
122
125
|
// draw the logo as a tile
|
|
123
126
|
drawTile(vec2(21,5), vec2(4.5), tile(3,128));
|
|
@@ -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?1133></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?1133></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
|
|
@@ -123,23 +123,23 @@ function gameRender()
|
|
|
123
123
|
// update sprites
|
|
124
124
|
for (const sprite of sprites)
|
|
125
125
|
{
|
|
126
|
-
// keep sprites above 0
|
|
127
|
-
sprite.pos.y = LJS.max(sprite.pos.y, 0);
|
|
128
|
-
|
|
129
126
|
// apply velocity and gravity
|
|
130
127
|
sprite.pos.x += sprite.velocity.x;
|
|
131
128
|
sprite.pos.y += sprite.velocity.y += LJS.gravity.y;
|
|
132
129
|
|
|
133
130
|
// bounce
|
|
134
131
|
if (sprite.pos.y < 0)
|
|
132
|
+
{
|
|
133
|
+
sprite.pos.y = 0;
|
|
135
134
|
sprite.velocity.y = LJS.rand(.3,.8);
|
|
135
|
+
}
|
|
136
136
|
if (sprite.pos.x < 0)
|
|
137
137
|
sprite.pos.x = 0, sprite.velocity.x *= -1;
|
|
138
138
|
if (sprite.pos.x > tileLayer.size.x)
|
|
139
139
|
sprite.pos.x = tileLayer.size.x, sprite.velocity.x *= -1;
|
|
140
140
|
|
|
141
141
|
// rotate sprite
|
|
142
|
-
sprite.angle +=
|
|
142
|
+
sprite.angle += sprite.velocity.x > 0 ? .02 : -.02;
|
|
143
143
|
|
|
144
144
|
// draw the sprite directly using glDraw for extra speed
|
|
145
145
|
LJS.glDraw(sprite.pos.x, sprite.pos.y, 1, 1, sprite.angle, 0, 0, 1, 1,
|
|
@@ -162,6 +162,5 @@ LJS.engineInit(gameInit, gameUpdate, gameUpdatePost, gameRender, gameRenderPost,
|
|
|
162
162
|
|
|
163
163
|
///////////////////////////////////////////////////////////////////////////////
|
|
164
164
|
// music - Depp Loop
|
|
165
|
-
const music = new LJS.ZzFXMusic([[[.6,0,
|
|
166
|
-
|
|
167
|
-
</script>
|
|
165
|
+
const music = new LJS.ZzFXMusic([[[.6,0,43,,,1,1,.5,,,,,.1,,,.05,,.5,.4,.2],[,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
|
+
</script>
|
|
@@ -0,0 +1,139 @@
|
|
|
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
|
+
input[type='checkbox']:disabled
|
|
113
|
+
{
|
|
114
|
+
opacity: 0.5;
|
|
115
|
+
}
|
|
116
|
+
.error-line
|
|
117
|
+
{
|
|
118
|
+
background-color: #f004 !important;
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
/* LittleJS CodeMirror Theme */
|
|
122
|
+
.cm-s-littlejs.CodeMirror { background: #080808; color: #aef; }
|
|
123
|
+
.cm-s-littlejs div.CodeMirror-selected { background: #068; }
|
|
124
|
+
.cm-s-littlejs .CodeMirror-gutters {background: #222; border-right: 0px;}
|
|
125
|
+
.cm-s-littlejs .CodeMirror-linenumber { color: #aaa; }
|
|
126
|
+
.cm-s-littlejs .CodeMirror-cursor { border-left: 2px solid #fff; }
|
|
127
|
+
.cm-s-littlejs .cm-keyword { color: #6e1; }
|
|
128
|
+
.cm-s-littlejs .cm-def { color: #fab; }
|
|
129
|
+
.cm-s-littlejs .cm-operator { color: #1be; }
|
|
130
|
+
.cm-s-littlejs .cm-property,
|
|
131
|
+
.cm-s-littlejs span.cm-variable,
|
|
132
|
+
.cm-s-littlejs span.cm-variable-2,
|
|
133
|
+
.cm-s-littlejs span.cm-variable-3 { color: #ddd; }
|
|
134
|
+
.cm-s-littlejs .cm-builtin,
|
|
135
|
+
.cm-s-littlejs .cm-number { color: #e15; }
|
|
136
|
+
.cm-s-littlejs .cm-comment { color:#888; font-style:italic; }
|
|
137
|
+
.cm-s-littlejs .cm-string,
|
|
138
|
+
.cm-s-littlejs .cm-string-2 { color:#fda; }
|
|
139
|
+
.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 = [
|
|
@@ -28,5 +27,5 @@ child_process.execSync(`npx tsc ${tsFiles} --outDir "./${BUILD_FOLDER}" --target
|
|
|
28
27
|
console.log(`TypeScript built in ${((Date.now() - startTime)/1e3).toFixed(2)} seconds!`);
|
|
29
28
|
|
|
30
29
|
console.log(`Moving js files back to root...`);
|
|
31
|
-
for(const file of jsSourceFiles)
|
|
32
|
-
fs.copyFileSync(`${BUILD_FOLDER}/${file}`, file);
|
|
30
|
+
for (const file of jsSourceFiles)
|
|
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
|
///////////////////////////////////////////////////////////////////////////////
|
|
@@ -85,8 +85,8 @@ function gameUpdatePost() {
|
|
|
85
85
|
}
|
|
86
86
|
///////////////////////////////////////////////////////////////////////////////
|
|
87
87
|
function gameRender() {
|
|
88
|
-
// draw a grey square in the background
|
|
89
|
-
LJS.drawRect(vec2(16, 8), vec2(20, 14), hsl(0, 0, .6)
|
|
88
|
+
// draw a grey square in the background
|
|
89
|
+
LJS.drawRect(vec2(16, 8), vec2(20, 14), hsl(0, 0, .6));
|
|
90
90
|
// draw the logo as a tile
|
|
91
91
|
LJS.drawTile(vec2(21, 5), vec2(4.5), tile(3, 128));
|
|
92
92
|
}
|
|
@@ -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']);
|