littlejsengine 1.11.2 → 1.11.5
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/.vscode/launch.json +14 -0
- package/README.md +16 -18
- package/dist/littlejs.d.ts +41 -30
- package/dist/littlejs.esm.js +165 -143
- package/dist/littlejs.esm.min.js +1 -1
- package/dist/littlejs.js +161 -142
- package/dist/littlejs.min.js +1 -1
- package/dist/littlejs.release.js +157 -135
- package/examples/box2d/gameObjects.js +4 -4
- package/examples/box2d/scenes.js +2 -2
- package/examples/breakout/game.js +1 -1
- package/examples/breakout/gameObjects.js +28 -29
- package/examples/breakout/index.html +1 -1
- package/examples/breakoutTutorial/game.js +1 -1
- package/examples/index.html +1 -7
- package/examples/logo.png +0 -0
- package/examples/module/game.js +1 -1
- package/examples/platformer/game.js +2 -2
- package/examples/platformer/gameCharacter.js +5 -5
- package/examples/platformer/gameEffects.js +4 -4
- package/examples/platformer/gameObjects.js +2 -2
- package/examples/puzzle/game.js +3 -3
- package/examples/starter/game.js +11 -45
- package/examples/starter/tiles.png +0 -0
- package/jsconfig.json +1 -0
- package/package.json +1 -1
- package/plugins/box2d.js +10 -10
- package/plugins/newgrounds.js +1 -1
- package/plugins/postProcess.js +8 -8
- package/shortExamples/base.html +36 -0
- package/shortExamples/code/blending.js +12 -0
- package/shortExamples/code/helloWorld.js +7 -0
- package/shortExamples/code/particles.js +28 -0
- package/shortExamples/code/playSound.js +36 -0
- package/shortExamples/code/pong.js +40 -0
- package/shortExamples/code/shapes.js +24 -0
- package/shortExamples/code/spriteAtlas.js +27 -0
- package/shortExamples/code/systemFont.js +14 -0
- package/shortExamples/code/texture.js +12 -0
- package/shortExamples/code/tileLayer.js +50 -0
- package/shortExamples/index.html +242 -0
- package/shortExamples/tiles.png +0 -0
- package/src/engine.js +17 -3
- package/src/engineAudio.js +4 -4
- package/src/engineBuild.js +2 -1
- package/src/engineDebug.js +4 -7
- package/src/engineDraw.js +50 -25
- package/src/engineExport.js +4 -1
- package/src/engineInput.js +1 -1
- package/src/engineObject.js +8 -8
- package/src/engineParticles.js +7 -7
- package/src/engineSettings.js +5 -5
- package/src/engineTileLayer.js +6 -2
- package/src/engineUtilities.js +5 -5
- package/src/engineWebGL.js +52 -74
- package/examples/electron/build.js +0 -107
- package/examples/electron/electron.js +0 -43
- package/examples/electron/game.js +0 -131
- package/examples/electron/index.html +0 -13
- package/examples/electron/package.json +0 -22
- package/examples/electron/tiles.png +0 -0
- package/examples/js13k/build.bat +0 -2
- package/examples/js13k/build.js +0 -131
- package/examples/js13k/game.js +0 -118
- package/examples/js13k/index.html +0 -21
- package/examples/js13k/tiles.png +0 -0
- package/examples/typescript/build.bat +0 -5
- package/examples/typescript/build.js +0 -33
- package/examples/typescript/game.js +0 -102
- package/examples/typescript/game.ts +0 -134
- package/examples/typescript/index.html +0 -10
- package/examples/typescript/tiles.png +0 -0
- package/examples/typescript/tsconfig.json +0 -8
|
@@ -1,107 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* LittleJS Build System
|
|
5
|
-
*/
|
|
6
|
-
|
|
7
|
-
'use strict';
|
|
8
|
-
|
|
9
|
-
const PROGRAM_NAME = 'game';
|
|
10
|
-
const BUILD_FOLDER = 'build';
|
|
11
|
-
const sourceFiles =
|
|
12
|
-
[
|
|
13
|
-
'../../dist/littlejs.release.js',
|
|
14
|
-
'game.js',
|
|
15
|
-
// add your game's files here
|
|
16
|
-
];
|
|
17
|
-
const dataFiles =
|
|
18
|
-
[
|
|
19
|
-
'tiles.png',
|
|
20
|
-
// add your game's data files here
|
|
21
|
-
];
|
|
22
|
-
|
|
23
|
-
console.log(`Building ${PROGRAM_NAME} with electron...`);
|
|
24
|
-
const startTime = Date.now();
|
|
25
|
-
const fs = require('node:fs');
|
|
26
|
-
const child_process = require('node:child_process');
|
|
27
|
-
|
|
28
|
-
// remove old files and setup build folder
|
|
29
|
-
fs.rmSync(BUILD_FOLDER, { recursive: true, force: true });
|
|
30
|
-
fs.rmSync(`${PROGRAM_NAME}.zip`, { force: true });
|
|
31
|
-
fs.mkdirSync(BUILD_FOLDER);
|
|
32
|
-
|
|
33
|
-
// copy data files
|
|
34
|
-
for(const file of dataFiles)
|
|
35
|
-
fs.copyFileSync(file, `${BUILD_FOLDER}/${file}`);
|
|
36
|
-
|
|
37
|
-
Build
|
|
38
|
-
(
|
|
39
|
-
`${BUILD_FOLDER}/index.js`,
|
|
40
|
-
sourceFiles,
|
|
41
|
-
[closureCompilerStep, uglifyBuildStep, htmlBuildStep, electronBuildStep]
|
|
42
|
-
);
|
|
43
|
-
|
|
44
|
-
console.log(`Build Completed in ${((Date.now() - startTime)/1e3).toFixed(2)} seconds!`);
|
|
45
|
-
|
|
46
|
-
///////////////////////////////////////////////////////////////////////////////
|
|
47
|
-
|
|
48
|
-
// A single build with its own source files, build steps, and output file
|
|
49
|
-
// - each build step is a callback that accepts a single filename
|
|
50
|
-
function Build(outputFile, files=[], buildSteps=[])
|
|
51
|
-
{
|
|
52
|
-
// copy files into a buffer
|
|
53
|
-
let buffer = '';
|
|
54
|
-
for (const file of files)
|
|
55
|
-
buffer += fs.readFileSync(file) + '\n';
|
|
56
|
-
|
|
57
|
-
// output file
|
|
58
|
-
fs.writeFileSync(outputFile, buffer, {flag: 'w+'});
|
|
59
|
-
|
|
60
|
-
// execute build steps in order
|
|
61
|
-
for (const buildStep of buildSteps)
|
|
62
|
-
buildStep(outputFile);
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
function closureCompilerStep(filename)
|
|
66
|
-
{
|
|
67
|
-
console.log(`Running closure compiler...`);
|
|
68
|
-
|
|
69
|
-
const filenameTemp = filename + '.tmp';
|
|
70
|
-
fs.copyFileSync(filename, filenameTemp);
|
|
71
|
-
child_process.execSync(`npx google-closure-compiler --js=${filenameTemp} --js_output_file=${filename} --compilation_level=ADVANCED --warning_level=VERBOSE --jscomp_off=* --assume_function_wrapper`, {stdio: 'inherit'});
|
|
72
|
-
fs.rmSync(filenameTemp);
|
|
73
|
-
};
|
|
74
|
-
|
|
75
|
-
function uglifyBuildStep(filename)
|
|
76
|
-
{
|
|
77
|
-
console.log(`Running uglify...`);
|
|
78
|
-
child_process.execSync(`npx uglifyjs ${filename} -c -m -o ${filename}`, {stdio: 'inherit'});
|
|
79
|
-
};
|
|
80
|
-
|
|
81
|
-
function htmlBuildStep(filename)
|
|
82
|
-
{
|
|
83
|
-
console.log(`Building html...`);
|
|
84
|
-
|
|
85
|
-
// create html file
|
|
86
|
-
let buffer = '<!DOCTYPE html>';
|
|
87
|
-
buffer += '<script>';
|
|
88
|
-
buffer += fs.readFileSync(filename) + '\n';
|
|
89
|
-
buffer += '</script>';
|
|
90
|
-
|
|
91
|
-
// output html file
|
|
92
|
-
fs.writeFileSync(`${BUILD_FOLDER}/index.html`, buffer, {flag: 'w+'});
|
|
93
|
-
};
|
|
94
|
-
|
|
95
|
-
function electronBuildStep(filename)
|
|
96
|
-
{
|
|
97
|
-
console.log(`Building executable with electron...`);
|
|
98
|
-
|
|
99
|
-
// delete intermediate files
|
|
100
|
-
fs.rmSync(filename);
|
|
101
|
-
|
|
102
|
-
// copy elecron files to build folder
|
|
103
|
-
fs.copyFileSync('electron.js', `${BUILD_FOLDER}/electron.js`);
|
|
104
|
-
fs.copyFileSync('package.json', `${BUILD_FOLDER}/package.json`);
|
|
105
|
-
|
|
106
|
-
child_process.execSync(`npx electron-packager ./${BUILD_FOLDER} --overwrite`, {stdio: 'inherit'});
|
|
107
|
-
};
|
|
@@ -1,43 +0,0 @@
|
|
|
1
|
-
// Modules to control application life and create native browser window
|
|
2
|
-
const { app, BrowserWindow } = require('electron')
|
|
3
|
-
|
|
4
|
-
const createWindow = () => {
|
|
5
|
-
// Create the browser window.
|
|
6
|
-
const mainWindow = new BrowserWindow({
|
|
7
|
-
width: 800,
|
|
8
|
-
height: 600
|
|
9
|
-
})
|
|
10
|
-
|
|
11
|
-
// hide menu
|
|
12
|
-
mainWindow.setMenu(null);
|
|
13
|
-
//mainWindow.setFullScreen(true);
|
|
14
|
-
|
|
15
|
-
// and load the index.html of the app.
|
|
16
|
-
mainWindow.loadFile('index.html')
|
|
17
|
-
|
|
18
|
-
// Open the DevTools.
|
|
19
|
-
// mainWindow.webContents.openDevTools()
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
// This method will be called when Electron has finished
|
|
23
|
-
// initialization and is ready to create browser windows.
|
|
24
|
-
// Some APIs can only be used after this event occurs.
|
|
25
|
-
app.whenReady().then(() => {
|
|
26
|
-
createWindow()
|
|
27
|
-
|
|
28
|
-
app.on('activate', () => {
|
|
29
|
-
// On macOS it's common to re-create a window in the app when the
|
|
30
|
-
// dock icon is clicked and there are no other windows open.
|
|
31
|
-
if (BrowserWindow.getAllWindows().length === 0) createWindow()
|
|
32
|
-
})
|
|
33
|
-
})
|
|
34
|
-
|
|
35
|
-
// Quit when all windows are closed, except on macOS. There, it's common
|
|
36
|
-
// for applications and their menu bar to stay active until the user quits
|
|
37
|
-
// explicitly with Cmd + Q.
|
|
38
|
-
app.on('window-all-closed', () => {
|
|
39
|
-
if (process.platform !== 'darwin') app.quit()
|
|
40
|
-
})
|
|
41
|
-
|
|
42
|
-
// In this file you can include the rest of your app's specific main process
|
|
43
|
-
// code. You can also put them in separate files and require them here.
|
|
@@ -1,131 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
Little JS Electron Starter Project
|
|
3
|
-
- A simple starter project for LittleJS
|
|
4
|
-
- Demos all the main engine features
|
|
5
|
-
- Builds to an Electron app
|
|
6
|
-
*/
|
|
7
|
-
|
|
8
|
-
'use strict';
|
|
9
|
-
|
|
10
|
-
// show the LittleJS splash screen
|
|
11
|
-
setShowSplashScreen(true);
|
|
12
|
-
|
|
13
|
-
// fix texture bleeding by shrinking tile slightly
|
|
14
|
-
tileFixBleedScale = .5;
|
|
15
|
-
|
|
16
|
-
// sound effects
|
|
17
|
-
const sound_click = new Sound([1,.5]);
|
|
18
|
-
|
|
19
|
-
// medals
|
|
20
|
-
const medal_example = new Medal(0, 'Example Medal', 'Welcome to LittleJS!');
|
|
21
|
-
medalsInit('Hello World');
|
|
22
|
-
|
|
23
|
-
// game variables
|
|
24
|
-
let particleEmitter;
|
|
25
|
-
|
|
26
|
-
///////////////////////////////////////////////////////////////////////////////
|
|
27
|
-
function gameInit()
|
|
28
|
-
{
|
|
29
|
-
// create tile collision and visible tile layer
|
|
30
|
-
initTileCollision(vec2(32,16));
|
|
31
|
-
const pos = vec2();
|
|
32
|
-
const tileLayer = new TileLayer(pos, tileCollisionSize);
|
|
33
|
-
|
|
34
|
-
// get level data from the tiles image
|
|
35
|
-
const tileImage = textureInfos[0].image;
|
|
36
|
-
mainContext.drawImage(tileImage,0,0);
|
|
37
|
-
const imageData = mainContext.getImageData(0,0,tileImage.width,tileImage.height).data;
|
|
38
|
-
for (pos.x = tileCollisionSize.x; pos.x--;)
|
|
39
|
-
for (pos.y = tileCollisionSize.y; pos.y--;)
|
|
40
|
-
{
|
|
41
|
-
// check if this pixel is set
|
|
42
|
-
const i = pos.x + tileImage.width*(15 + tileCollisionSize.y - pos.y);
|
|
43
|
-
if (!imageData[4*i])
|
|
44
|
-
continue;
|
|
45
|
-
|
|
46
|
-
// set tile data
|
|
47
|
-
const tileIndex = 1;
|
|
48
|
-
const direction = randInt(4)
|
|
49
|
-
const mirror = randInt(2);
|
|
50
|
-
const color = randColor();
|
|
51
|
-
const data = new TileLayerData(tileIndex, direction, mirror, color);
|
|
52
|
-
tileLayer.setData(pos, data);
|
|
53
|
-
setTileCollisionData(pos, 1);
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
// draw tile layer with new data
|
|
57
|
-
tileLayer.redraw();
|
|
58
|
-
|
|
59
|
-
// setup camera
|
|
60
|
-
cameraPos = vec2(16,8);
|
|
61
|
-
cameraScale = 48;
|
|
62
|
-
|
|
63
|
-
// enable gravity
|
|
64
|
-
gravity = -.01;
|
|
65
|
-
|
|
66
|
-
// create particle emitter
|
|
67
|
-
particleEmitter = new ParticleEmitter(
|
|
68
|
-
vec2(16,9), 0, // emitPos, emitAngle
|
|
69
|
-
1, 0, 500, PI, // emitSize, emitTime, emitRate, emiteCone
|
|
70
|
-
tile(0, 16), // tileIndex, tileSize
|
|
71
|
-
hsl(1,1,1), hsl(0,0,0), // colorStartA, colorStartB
|
|
72
|
-
hsl(0,0,0,0), hsl(0,0,0,0), // colorEndA, colorEndB
|
|
73
|
-
2, .2, .2, .1, .05, // time, sizeStart, sizeEnd, speed, angleSpeed
|
|
74
|
-
.99, 1, 1, PI, // damping, angleDamping, gravityScale, cone
|
|
75
|
-
.05, .5, 1, 1 // fadeRate, randomness, collide, additive
|
|
76
|
-
);
|
|
77
|
-
particleEmitter.elasticity = .3; // bounce when it collides
|
|
78
|
-
particleEmitter.trailScale = 2; // stretch in direction of motion
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
///////////////////////////////////////////////////////////////////////////////
|
|
82
|
-
function gameUpdate()
|
|
83
|
-
{
|
|
84
|
-
if (mouseWasPressed(0))
|
|
85
|
-
{
|
|
86
|
-
// play sound when mouse is pressed
|
|
87
|
-
sound_click.play(mousePos);
|
|
88
|
-
|
|
89
|
-
// change particle color and set to fade out
|
|
90
|
-
particleEmitter.colorStartA = hsl();
|
|
91
|
-
particleEmitter.colorStartB = randColor();
|
|
92
|
-
particleEmitter.colorEndA = particleEmitter.colorStartA.scale(1,0);
|
|
93
|
-
particleEmitter.colorEndB = particleEmitter.colorStartB.scale(1,0);
|
|
94
|
-
|
|
95
|
-
// unlock medals
|
|
96
|
-
medal_example.unlock();
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
// move particles to mouse location if on screen
|
|
100
|
-
if (mousePosScreen.x)
|
|
101
|
-
particleEmitter.pos = mousePos;
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
///////////////////////////////////////////////////////////////////////////////
|
|
105
|
-
function gameUpdatePost()
|
|
106
|
-
{
|
|
107
|
-
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
///////////////////////////////////////////////////////////////////////////////
|
|
111
|
-
function gameRender()
|
|
112
|
-
{
|
|
113
|
-
// draw a grey square in the background without using webgl
|
|
114
|
-
drawRect(vec2(16,8), vec2(20,14), hsl(0,0,.6), 0, 0);
|
|
115
|
-
|
|
116
|
-
// draw the logo as a tile
|
|
117
|
-
drawTile(vec2(21,5), vec2(4.5), tile(3,128));
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
///////////////////////////////////////////////////////////////////////////////
|
|
121
|
-
function gameRenderPost()
|
|
122
|
-
{
|
|
123
|
-
// draw to overlay canvas for hud rendering
|
|
124
|
-
drawTextScreen('LittleJS Electron Demo',
|
|
125
|
-
vec2(mainCanvasSize.x/2, 70), 80, // position, size
|
|
126
|
-
hsl(0,0,1), 6, hsl(0,0,0)); // color, outline size and color
|
|
127
|
-
}
|
|
128
|
-
|
|
129
|
-
///////////////////////////////////////////////////////////////////////////////
|
|
130
|
-
// Startup LittleJS Engine
|
|
131
|
-
engineInit(gameInit, gameUpdate, gameUpdatePost, gameRender, gameRenderPost, ['tiles.png']);
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
<!DOCTYPE html><head>
|
|
2
|
-
<title>LittleJS Electron Demo</title>
|
|
3
|
-
<meta charset=utf-8>
|
|
4
|
-
<meta name=apple-mobile-web-app-capable content=yes>
|
|
5
|
-
<meta name=mobile-web-app-capable content=yes>
|
|
6
|
-
<link rel=icon type=image/png href=../favicon.png>
|
|
7
|
-
</head><body>
|
|
8
|
-
|
|
9
|
-
<!-- LittleJS Engine -->
|
|
10
|
-
<script src=../../dist/littlejs.js?1105></script>
|
|
11
|
-
|
|
12
|
-
<!-- Add your game scripts here -->
|
|
13
|
-
<script src=game.js?1105></script>
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "LittleJSGame",
|
|
3
|
-
"version": "1.0.0",
|
|
4
|
-
"description": "A minimal Electron application",
|
|
5
|
-
"main": "electron.js",
|
|
6
|
-
"scripts": {
|
|
7
|
-
"build": "node build.js"
|
|
8
|
-
},
|
|
9
|
-
"repository": "https://github.com/electron/electron-quick-start",
|
|
10
|
-
"keywords": [
|
|
11
|
-
"Electron",
|
|
12
|
-
"LittleJS",
|
|
13
|
-
"Game"
|
|
14
|
-
],
|
|
15
|
-
"author": "Frank Force",
|
|
16
|
-
"license": "MIT",
|
|
17
|
-
"devDependencies": {
|
|
18
|
-
"electron": "~25.2.0",
|
|
19
|
-
"electron-packager": "~17.1.1"
|
|
20
|
-
},
|
|
21
|
-
"dependencies": {}
|
|
22
|
-
}
|
|
Binary file
|
package/examples/js13k/build.bat
DELETED
package/examples/js13k/build.js
DELETED
|
@@ -1,131 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* LittleJS Build System
|
|
5
|
-
*/
|
|
6
|
-
|
|
7
|
-
'use strict';
|
|
8
|
-
|
|
9
|
-
const PROGRAM_NAME = 'game';
|
|
10
|
-
const BUILD_FOLDER = 'build';
|
|
11
|
-
const sourceFiles =
|
|
12
|
-
[
|
|
13
|
-
'../../dist/littlejs.release.js',
|
|
14
|
-
'game.js',
|
|
15
|
-
// add your game's files here
|
|
16
|
-
];
|
|
17
|
-
const dataFiles =
|
|
18
|
-
[
|
|
19
|
-
'tiles.png',
|
|
20
|
-
// add your game's data files here
|
|
21
|
-
];
|
|
22
|
-
|
|
23
|
-
console.log(`Building ${PROGRAM_NAME}...`);
|
|
24
|
-
const startTime = Date.now();
|
|
25
|
-
const fs = require('node:fs');
|
|
26
|
-
const child_process = require('node:child_process');
|
|
27
|
-
|
|
28
|
-
// rebuild engine
|
|
29
|
-
//child_process.execSync(`npm run build`, { stdio: 'inherit' });
|
|
30
|
-
|
|
31
|
-
// remove old files and setup build folder
|
|
32
|
-
fs.rmSync(BUILD_FOLDER, { recursive: true, force: true });
|
|
33
|
-
fs.rmSync(`${PROGRAM_NAME}.zip`, { force: true });
|
|
34
|
-
fs.mkdirSync(BUILD_FOLDER);
|
|
35
|
-
|
|
36
|
-
// copy data files
|
|
37
|
-
for(const file of dataFiles)
|
|
38
|
-
fs.copyFileSync(file, `${BUILD_FOLDER}/${file}`);
|
|
39
|
-
|
|
40
|
-
Build
|
|
41
|
-
(
|
|
42
|
-
`${BUILD_FOLDER}/index.js`,
|
|
43
|
-
sourceFiles,
|
|
44
|
-
[closureCompilerStep, uglifyBuildStep, roadrollerBuildStep, htmlBuildStep, zipBuildStep]
|
|
45
|
-
//[closureCompilerSimpleStep, htmlBuildStep] // for build debugging
|
|
46
|
-
);
|
|
47
|
-
|
|
48
|
-
console.log(``);
|
|
49
|
-
console.log(`Build Completed in ${((Date.now() - startTime)/1e3).toFixed(2)} seconds!`);
|
|
50
|
-
console.log(`Size of ${PROGRAM_NAME}.zip: ${fs.statSync(`${PROGRAM_NAME}.zip`).size} bytes`);
|
|
51
|
-
|
|
52
|
-
///////////////////////////////////////////////////////////////////////////////
|
|
53
|
-
|
|
54
|
-
// A single build with its own source files, build steps, and output file
|
|
55
|
-
// - each build step is a callback that accepts a single filename
|
|
56
|
-
function Build(outputFile, files=[], buildSteps=[])
|
|
57
|
-
{
|
|
58
|
-
// copy files into a buffer
|
|
59
|
-
let buffer = '';
|
|
60
|
-
for (const file of files)
|
|
61
|
-
buffer += fs.readFileSync(file) + '\n';
|
|
62
|
-
|
|
63
|
-
// output file
|
|
64
|
-
fs.writeFileSync(outputFile, buffer, {flag: 'w+'});
|
|
65
|
-
|
|
66
|
-
// execute build steps in order
|
|
67
|
-
for (const buildStep of buildSteps)
|
|
68
|
-
buildStep(outputFile);
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
function closureCompilerStep(filename)
|
|
72
|
-
{
|
|
73
|
-
console.log(`Running closure compiler...`);
|
|
74
|
-
|
|
75
|
-
const filenameTemp = filename + '.tmp';
|
|
76
|
-
fs.copyFileSync(filename, filenameTemp);
|
|
77
|
-
child_process.execSync(`npx google-closure-compiler --js=${filenameTemp} --js_output_file=${filename} --compilation_level=ADVANCED --warning_level=VERBOSE --jscomp_off=* --assume_function_wrapper`, {stdio: 'inherit'});
|
|
78
|
-
fs.rmSync(filenameTemp);
|
|
79
|
-
};
|
|
80
|
-
|
|
81
|
-
function closureCompilerSimpleStep(filename)
|
|
82
|
-
{
|
|
83
|
-
console.log(`Running closure compiler in simple mode...`);
|
|
84
|
-
|
|
85
|
-
const filenameTemp = filename + '.tmp';
|
|
86
|
-
fs.copyFileSync(filename, filenameTemp);
|
|
87
|
-
child_process.execSync(`npx google-closure-compiler --js=${filenameTemp} --js_output_file=${filename} --compilation_level=SIMPLE --warning_level=VERBOSE --jscomp_off=* --assume_function_wrapper`, {stdio: 'inherit'});
|
|
88
|
-
fs.rmSync(filenameTemp);
|
|
89
|
-
};
|
|
90
|
-
|
|
91
|
-
function uglifyBuildStep(filename)
|
|
92
|
-
{
|
|
93
|
-
console.log(`Running uglify...`);
|
|
94
|
-
child_process.execSync(`npx uglifyjs ${filename} -c -m -o ${filename}`, {stdio: 'inherit'});
|
|
95
|
-
};
|
|
96
|
-
|
|
97
|
-
function roadrollerBuildStep(filename)
|
|
98
|
-
{
|
|
99
|
-
console.log(`Running roadroller...`);
|
|
100
|
-
child_process.execSync(`npx roadroller ${filename} -o ${filename}`, {stdio: 'inherit'});
|
|
101
|
-
};
|
|
102
|
-
|
|
103
|
-
function roadrollerExtremeBuildStep(filename)
|
|
104
|
-
{
|
|
105
|
-
// this takes over a minute to run but might be a little smaller
|
|
106
|
-
console.log(`Running roadroller extreme...`);
|
|
107
|
-
child_process.execSync(`npx roadroller ${filename} -o ${filename} --optimize 2`, {stdio: 'inherit'});
|
|
108
|
-
};
|
|
109
|
-
|
|
110
|
-
function htmlBuildStep(filename)
|
|
111
|
-
{
|
|
112
|
-
console.log(`Building html...`);
|
|
113
|
-
|
|
114
|
-
// create html file
|
|
115
|
-
let buffer = '';
|
|
116
|
-
buffer += '<body>';
|
|
117
|
-
buffer += '<script>';
|
|
118
|
-
buffer += fs.readFileSync(filename);
|
|
119
|
-
buffer += '</script>';
|
|
120
|
-
|
|
121
|
-
// output html file
|
|
122
|
-
fs.writeFileSync(`${BUILD_FOLDER}/index.html`, buffer, {flag: 'w+'});
|
|
123
|
-
};
|
|
124
|
-
|
|
125
|
-
function zipBuildStep(filename)
|
|
126
|
-
{
|
|
127
|
-
console.log(`Zipping...`);
|
|
128
|
-
const ect = '../../../node_modules/ect-bin/vendor/win32/ect.exe';
|
|
129
|
-
const args = ['-9', '-strip', '-zip', `../${PROGRAM_NAME}.zip`, 'index.html', ...dataFiles];
|
|
130
|
-
child_process.spawnSync(ect, args, {stdio: 'inherit', cwd: BUILD_FOLDER});
|
|
131
|
-
};
|
package/examples/js13k/game.js
DELETED
|
@@ -1,118 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
LittleJS JS13K Starter Game
|
|
3
|
-
- For size limited projects
|
|
4
|
-
- Includes all core engine features
|
|
5
|
-
- Builds to 7kb zip file
|
|
6
|
-
*/
|
|
7
|
-
|
|
8
|
-
'use strict';
|
|
9
|
-
|
|
10
|
-
// fix texture bleeding by shrinking tile slightly
|
|
11
|
-
tileFixBleedScale = .5;
|
|
12
|
-
|
|
13
|
-
// sound effects
|
|
14
|
-
const sound_click = new Sound([1,.5]);
|
|
15
|
-
|
|
16
|
-
// game variables
|
|
17
|
-
let particleEmitter;
|
|
18
|
-
|
|
19
|
-
// webgl can be disabled to save even more space
|
|
20
|
-
//glEnable = false;
|
|
21
|
-
|
|
22
|
-
///////////////////////////////////////////////////////////////////////////////
|
|
23
|
-
function gameInit()
|
|
24
|
-
{
|
|
25
|
-
// create tile collision and visible tile layer
|
|
26
|
-
initTileCollision(vec2(32,16));
|
|
27
|
-
const pos = vec2();
|
|
28
|
-
const tileLayer = new TileLayer(pos, tileCollisionSize);
|
|
29
|
-
|
|
30
|
-
// get level data from the tiles image
|
|
31
|
-
const tileImage = textureInfos[0].image;
|
|
32
|
-
mainContext.drawImage(tileImage,0,0);
|
|
33
|
-
const imageData = mainContext.getImageData(0,0,tileImage.width,tileImage.height).data;
|
|
34
|
-
for (pos.x = tileCollisionSize.x; pos.x--;)
|
|
35
|
-
for (pos.y = tileCollisionSize.y; pos.y--;)
|
|
36
|
-
{
|
|
37
|
-
// check if this pixel is set
|
|
38
|
-
const i = pos.x + tileImage.width*(15 + tileCollisionSize.y - pos.y);
|
|
39
|
-
if (!imageData[4*i])
|
|
40
|
-
continue;
|
|
41
|
-
|
|
42
|
-
// set tile data
|
|
43
|
-
const tileIndex = 1;
|
|
44
|
-
const direction = randInt(4)
|
|
45
|
-
const mirror = randInt(2);
|
|
46
|
-
const color = randColor();
|
|
47
|
-
const data = new TileLayerData(tileIndex, direction, mirror, color);
|
|
48
|
-
tileLayer.setData(pos, data);
|
|
49
|
-
setTileCollisionData(pos, 1);
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
// draw tile layer with new data
|
|
53
|
-
tileLayer.redraw();
|
|
54
|
-
|
|
55
|
-
// setup camera
|
|
56
|
-
cameraPos = vec2(16,8);
|
|
57
|
-
|
|
58
|
-
// enable gravity
|
|
59
|
-
gravity = -.01;
|
|
60
|
-
|
|
61
|
-
// create particle emitter
|
|
62
|
-
particleEmitter = new ParticleEmitter(
|
|
63
|
-
vec2(16,9), 0, // emitPos, emitAngle
|
|
64
|
-
1, 0, 500, PI, // emitSize, emitTime, emitRate, emiteCone
|
|
65
|
-
tile(0, 16), // tileIndex, tileSize
|
|
66
|
-
new Color(1,1,1), new Color(0,0,0), // colorStartA, colorStartB
|
|
67
|
-
new Color(0,0,0,0), new Color(0,0,0,0), // colorEndA, colorEndB
|
|
68
|
-
2, .2, .2, .1, .05, // time, sizeStart, sizeEnd, speed, angleSpeed
|
|
69
|
-
.99, 1, 1, PI, // damping, angleDamping, gravityScale, cone
|
|
70
|
-
.05, .5, 1, 1 // fadeRate, randomness, collide, additive
|
|
71
|
-
);
|
|
72
|
-
particleEmitter.elasticity = .3; // bounce when it collides
|
|
73
|
-
particleEmitter.trailScale = 2; // stretch in direction of motion
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
///////////////////////////////////////////////////////////////////////////////
|
|
77
|
-
function gameUpdate()
|
|
78
|
-
{
|
|
79
|
-
if (mouseWasPressed(0))
|
|
80
|
-
{
|
|
81
|
-
// play sound when mouse is pressed
|
|
82
|
-
sound_click.play(mousePos);
|
|
83
|
-
|
|
84
|
-
// change particle color and set to fade out
|
|
85
|
-
particleEmitter.colorStartA = new Color;
|
|
86
|
-
particleEmitter.colorStartB = randColor();
|
|
87
|
-
particleEmitter.colorEndA = particleEmitter.colorStartA.scale(1,0);
|
|
88
|
-
particleEmitter.colorEndB = particleEmitter.colorStartB.scale(1,0);
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
// move particles to mouse location if on screen
|
|
92
|
-
if (mousePosScreen.x)
|
|
93
|
-
particleEmitter.pos = mousePos;
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
///////////////////////////////////////////////////////////////////////////////
|
|
97
|
-
function gameUpdatePost()
|
|
98
|
-
{
|
|
99
|
-
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
///////////////////////////////////////////////////////////////////////////////
|
|
103
|
-
function gameRender()
|
|
104
|
-
{
|
|
105
|
-
// draw a grey square in the background without using webgl
|
|
106
|
-
drawRect(vec2(16,8), vec2(20,14), new Color(.6,.6,.6), 0, 0);
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
///////////////////////////////////////////////////////////////////////////////
|
|
110
|
-
function gameRenderPost()
|
|
111
|
-
{
|
|
112
|
-
// draw to overlay canvas for hud rendering
|
|
113
|
-
drawTextScreen('LittleJS JS13K Demo', vec2(mainCanvasSize.x/2, 70), 80);
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
///////////////////////////////////////////////////////////////////////////////
|
|
117
|
-
// Startup LittleJS Engine
|
|
118
|
-
engineInit(gameInit, gameUpdate, gameUpdatePost, gameRender, gameRenderPost, ['tiles.png']);
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
<head>
|
|
2
|
-
<title>LittleJS JS13K Project</title>
|
|
3
|
-
<meta charset=utf-8>
|
|
4
|
-
</head><body>
|
|
5
|
-
|
|
6
|
-
<!-- LittleJS Engine -->
|
|
7
|
-
<script src=../../src/engineDebug.js?1105></script>
|
|
8
|
-
<script src=../../src/engineUtilities.js?1105></script>
|
|
9
|
-
<script src=../../src/engineSettings.js?1105></script>
|
|
10
|
-
<script src=../../src/engineObject.js?1105></script>
|
|
11
|
-
<script src=../../src/engineDraw.js?1105></script>
|
|
12
|
-
<script src=../../src/engineInput.js?1105></script>
|
|
13
|
-
<script src=../../src/engineAudio.js?1105></script>
|
|
14
|
-
<script src=../../src/engineTileLayer.js?1105></script>
|
|
15
|
-
<script src=../../src/engineParticles.js?1105></script>
|
|
16
|
-
<script src=../../src/engineMedals.js?1105></script>
|
|
17
|
-
<script src=../../src/engineWebGL.js?1105></script>
|
|
18
|
-
<script src=../../src/engine.js?1105></script>
|
|
19
|
-
|
|
20
|
-
<!-- Add your game scripts here -->
|
|
21
|
-
<script src=game.js?1105></script>
|
package/examples/js13k/tiles.png
DELETED
|
Binary file
|
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* LittleJS Build System
|
|
5
|
-
*/
|
|
6
|
-
|
|
7
|
-
'use strict';
|
|
8
|
-
|
|
9
|
-
const PROGRAM_NAME = 'game';
|
|
10
|
-
const BUILD_FOLDER = 'build';
|
|
11
|
-
const ROOT_FOLDER = 'examples/typescript';
|
|
12
|
-
const sourceFiles =
|
|
13
|
-
[
|
|
14
|
-
'game.js',
|
|
15
|
-
// add your game's scripts here
|
|
16
|
-
];
|
|
17
|
-
|
|
18
|
-
console.log(`Building TypeScript for ${PROGRAM_NAME}...`);
|
|
19
|
-
const startTime = Date.now();
|
|
20
|
-
const fs = require('node:fs');
|
|
21
|
-
const child_process = require('node:child_process');
|
|
22
|
-
|
|
23
|
-
console.log(`Removing old build filder...`);
|
|
24
|
-
fs.rmSync(BUILD_FOLDER, { recursive: true, force: true });
|
|
25
|
-
|
|
26
|
-
console.log(`Compiling TypeScript...`);
|
|
27
|
-
child_process.execSync(`npx tsc --outDir "./${BUILD_FOLDER}"`, {stdio: 'inherit'});
|
|
28
|
-
|
|
29
|
-
console.log(`Moving js files to root...`);
|
|
30
|
-
for(const file of sourceFiles)
|
|
31
|
-
fs.copyFileSync(`${BUILD_FOLDER}/${ROOT_FOLDER}/${file}`, `${file}`);
|
|
32
|
-
|
|
33
|
-
console.log(`TypeScript built in ${((Date.now() - startTime)/1e3).toFixed(2)} seconds!`);
|