littlejsengine 1.10.4 → 1.10.7
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 +8 -78
- package/dist/littlejs.d.ts +31 -17
- package/dist/littlejs.esm.js +121 -55
- package/dist/littlejs.esm.min.js +1 -1
- package/dist/littlejs.js +121 -55
- package/dist/littlejs.min.js +1 -1
- package/dist/littlejs.release.js +121 -55
- package/examples/box2d/game.js +15 -4
- package/examples/box2d/gameObjects.js +10 -9
- package/examples/box2d/index.html +5 -5
- package/examples/box2d/scenes.js +4 -4
- package/examples/box2d/tiles.png +0 -0
- package/examples/breakout/index.html +3 -3
- package/examples/breakoutTutorial/index.html +2 -2
- package/examples/electron/game.js +3 -0
- package/examples/electron/index.html +2 -2
- package/examples/htmlMenu/index.html +3 -3
- package/examples/js13k/game.js +3 -0
- package/examples/js13k/index.html +13 -13
- package/examples/module/game.js +3 -0
- package/examples/module/index.html +1 -1
- package/examples/particles/index.html +4 -1
- package/examples/platformer/game.js +19 -15
- package/examples/platformer/gameCharacter.js +3 -3
- package/examples/platformer/gameLevel.js +1 -0
- package/examples/platformer/index.html +8 -8
- package/examples/platformer/tiles.png +0 -0
- package/examples/puzzle/index.html +2 -2
- package/examples/starter/game.js +3 -0
- package/examples/starter/index.html +13 -13
- package/examples/stress/index.html +1 -1
- package/examples/typescript/game.js +2 -0
- package/examples/typescript/game.ts +3 -0
- package/examples/typescript/index.html +1 -1
- package/examples/uiSystem/game.js +23 -16
- package/examples/uiSystem/index.html +3 -14
- package/package.json +1 -1
- package/plugins/postProcess.js +2 -9
- package/plugins/uiSystem.js +84 -24
- package/src/engine.js +11 -11
- package/src/engineAudio.js +7 -13
- package/src/engineDraw.js +1 -1
- package/src/engineInput.js +7 -3
- package/src/engineMedals.js +19 -5
- package/src/engineObject.js +8 -5
- package/src/engineTileLayer.js +8 -7
- package/src/engineUtilities.js +59 -10
- package/examples/js13k/build/index.html +0 -1
- package/examples/js13k/build/index.js +0 -1
- package/examples/js13k/build/tiles.png +0 -0
- package/examples/js13k/game - Copy.zip +0 -0
- package/examples/js13k/game.zip +0 -0
- package/examples/starter/build/index.html +0 -2
- package/examples/starter/build/index.js +0 -1
- package/examples/starter/build/tiles.png +0 -0
- package/examples/starter/game.zip +0 -0
- package/examples/typescript/build/build/littlejs.esm.js +0 -4327
- package/examples/typescript/build/dist/littlejs.esm.js +0 -4425
- package/examples/typescript/build/examples/typescript/build.js +0 -24
- package/examples/typescript/build/examples/typescript/game.js +0 -100
- package/examples/typescript/build/examples/typescript/test/build/littlejs.esm.js +0 -3934
- package/examples/typescript/build/examples/typescript/test/examples/typescript/build.js +0 -86
- package/examples/typescript/build/examples/typescript/test/examples/typescript/game.js +0 -92
|
@@ -1,86 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
/**
|
|
3
|
-
* LittleJS Build System
|
|
4
|
-
* - Combine input files
|
|
5
|
-
* - Run custom build steps
|
|
6
|
-
* - Check for errors
|
|
7
|
-
* - Output to build folder
|
|
8
|
-
* @namespace Build
|
|
9
|
-
*/
|
|
10
|
-
const PROGRAM_NAME = 'game';
|
|
11
|
-
const BUILD_FOLDER = 'build';
|
|
12
|
-
const sourceFiles = [
|
|
13
|
-
'../../build/littlejs.release.js',
|
|
14
|
-
'game.js',
|
|
15
|
-
// add your game's files here
|
|
16
|
-
];
|
|
17
|
-
const dataFiles = [
|
|
18
|
-
'tiles.png',
|
|
19
|
-
// add your game's data files here
|
|
20
|
-
];
|
|
21
|
-
console.log(`Building ${PROGRAM_NAME}...`);
|
|
22
|
-
const startTime = Date.now();
|
|
23
|
-
const fs = require('node:fs');
|
|
24
|
-
const child_process = require('node:child_process');
|
|
25
|
-
// rebuild engine
|
|
26
|
-
child_process.execSync(`npm run build`, { stdio: 'inherit' });
|
|
27
|
-
console.log('');
|
|
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
|
-
// copy data files
|
|
33
|
-
for (const file of dataFiles)
|
|
34
|
-
fs.copyFileSync(file, `${BUILD_FOLDER}/${file}`);
|
|
35
|
-
Build(`${BUILD_FOLDER}/index.js`, sourceFiles, [closureCompilerStep, uglifyBuildStep, roadrollerBuildStep, htmlBuildStep, zipBuildStep]);
|
|
36
|
-
console.log(`Build Completed in ${((Date.now() - startTime) / 1e3).toFixed(2)} seconds!`);
|
|
37
|
-
///////////////////////////////////////////////////////////////////////////////
|
|
38
|
-
// A single build with its own source files, build steps, and output file
|
|
39
|
-
// - each build step is a callback that accepts a single filename
|
|
40
|
-
function Build(outputFile, files = [], buildSteps = []) {
|
|
41
|
-
// copy files into a buffer
|
|
42
|
-
let buffer = '';
|
|
43
|
-
for (const file of files)
|
|
44
|
-
buffer += fs.readFileSync(file) + '\n';
|
|
45
|
-
// output file
|
|
46
|
-
fs.writeFileSync(outputFile, buffer, { flag: 'w+' });
|
|
47
|
-
// execute build steps in order
|
|
48
|
-
for (const buildStep of buildSteps)
|
|
49
|
-
buildStep(outputFile);
|
|
50
|
-
}
|
|
51
|
-
function closureCompilerStep(filename) {
|
|
52
|
-
console.log(`Running closure compiler...`);
|
|
53
|
-
const filenameTemp = filename + '.tmp';
|
|
54
|
-
fs.copyFileSync(filename, filenameTemp);
|
|
55
|
-
child_process.execSync(`npx google-closure-compiler --js=${filenameTemp} --js_output_file=${filename} --compilation_level=ADVANCED --language_out=ECMASCRIPT_2021 --warning_level=VERBOSE --jscomp_off=* --assume_function_wrapper`, { stdio: 'inherit' });
|
|
56
|
-
fs.rmSync(filenameTemp);
|
|
57
|
-
}
|
|
58
|
-
;
|
|
59
|
-
function uglifyBuildStep(filename) {
|
|
60
|
-
console.log(`Running uglify...`);
|
|
61
|
-
child_process.execSync(`npx uglifyjs ${filename} -c -m -o ${filename}`, { stdio: 'inherit' });
|
|
62
|
-
}
|
|
63
|
-
;
|
|
64
|
-
function roadrollerBuildStep(filename) {
|
|
65
|
-
console.log(`Running roadroller...`);
|
|
66
|
-
child_process.execSync(`npx roadroller ${filename} -o ${filename}`, { stdio: 'inherit' });
|
|
67
|
-
}
|
|
68
|
-
;
|
|
69
|
-
function htmlBuildStep(filename) {
|
|
70
|
-
console.log(`Building html...`);
|
|
71
|
-
// copy files into a buffer
|
|
72
|
-
let buffer = '';
|
|
73
|
-
buffer += '<script>';
|
|
74
|
-
buffer += fs.readFileSync(filename) + '\n';
|
|
75
|
-
buffer += '</script>';
|
|
76
|
-
// output html file
|
|
77
|
-
fs.writeFileSync(`${BUILD_FOLDER}/index.html`, buffer, { flag: 'w+' });
|
|
78
|
-
}
|
|
79
|
-
;
|
|
80
|
-
function zipBuildStep(filename) {
|
|
81
|
-
console.log(`Zipping...`);
|
|
82
|
-
const ect = '../../../node_modules/ect-bin/vendor/win32/ect.exe';
|
|
83
|
-
const args = ['-9', '-strip', '-zip', `../${PROGRAM_NAME}.zip`, 'index.html', ...dataFiles];
|
|
84
|
-
child_process.spawnSync(ect, args, { stdio: 'inherit', cwd: BUILD_FOLDER });
|
|
85
|
-
}
|
|
86
|
-
;
|
|
@@ -1,92 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
LittleJS Hello World Starter Game
|
|
3
|
-
*/
|
|
4
|
-
'use strict';
|
|
5
|
-
// import module
|
|
6
|
-
import * as LittleJS from '../../build/littlejs.esm.js';
|
|
7
|
-
const { Vector2, Color, Timer, vec2 } = LittleJS;
|
|
8
|
-
// sound effects
|
|
9
|
-
const sound_click = new LittleJS.Sound([1, .5]);
|
|
10
|
-
// medals
|
|
11
|
-
const medal_example = new LittleJS.Medal(0, 'Example Medal', 'Welcome to LittleJS!');
|
|
12
|
-
LittleJS.medalsInit('Hello World');
|
|
13
|
-
// game variables
|
|
14
|
-
let particleEmitter;
|
|
15
|
-
let gameTimer = new Timer;
|
|
16
|
-
///////////////////////////////////////////////////////////////////////////////
|
|
17
|
-
function gameInit() {
|
|
18
|
-
// create tile collision and visible tile layer
|
|
19
|
-
LittleJS.initTileCollision(vec2(32, 16));
|
|
20
|
-
const pos = new Vector2;
|
|
21
|
-
const tileLayer = new LittleJS.TileLayer(pos, LittleJS.tileCollisionSize);
|
|
22
|
-
// get level data from the tiles image
|
|
23
|
-
const imageLevelDataRow = 1;
|
|
24
|
-
const mainContext = LittleJS.mainContext;
|
|
25
|
-
mainContext.drawImage(LittleJS.tileImage, 0, 0);
|
|
26
|
-
for (pos.x = LittleJS.tileCollisionSize.x; pos.x--;)
|
|
27
|
-
for (pos.y = LittleJS.tileCollisionSize.y; pos.y--;) {
|
|
28
|
-
const imageData = mainContext.getImageData(pos.x, 16 * (imageLevelDataRow + 1) - pos.y - 1, 1, 1).data;
|
|
29
|
-
if (imageData[0]) {
|
|
30
|
-
const tileIndex = 1;
|
|
31
|
-
const direction = LittleJS.randInt(4);
|
|
32
|
-
const mirror = LittleJS.randInt(2) ? true : false;
|
|
33
|
-
const color = LittleJS.randColor();
|
|
34
|
-
const data = new LittleJS.TileLayerData(tileIndex, direction, mirror, color);
|
|
35
|
-
tileLayer.setData(pos, data);
|
|
36
|
-
LittleJS.setTileCollisionData(pos, 1);
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
tileLayer.redraw();
|
|
40
|
-
// move camera to center of collision
|
|
41
|
-
LittleJS.setCameraPos(LittleJS.tileCollisionSize.scale(.5));
|
|
42
|
-
// enable gravity
|
|
43
|
-
LittleJS.setGravity(-.01);
|
|
44
|
-
// create particle emitter
|
|
45
|
-
const center = LittleJS.tileCollisionSize.scale(.5).add(vec2(0, 9));
|
|
46
|
-
particleEmitter = new LittleJS.ParticleEmitter(center, 0, // emitPos, emitAngle
|
|
47
|
-
1, 0, 500, Math.PI, // emitSize, emitTime, emitRate, emiteCone
|
|
48
|
-
0, vec2(16), // tileIndex, tileSize
|
|
49
|
-
new Color(1, 1, 1), new Color(0, 0, 0), // colorStartA, colorStartB
|
|
50
|
-
new Color(1, 1, 1, 0), new Color(0, 0, 0, 0), // colorEndA, colorEndB
|
|
51
|
-
2, .2, .2, .1, .05, // time, sizeStart, sizeEnd, speed, angleSpeed
|
|
52
|
-
.99, 1, 1, Math.PI, // damping, angleDamping, gravityScale, cone
|
|
53
|
-
.05, .5, true, true // fadeRate, randomness, collide, additive
|
|
54
|
-
);
|
|
55
|
-
particleEmitter.elasticity = .3; // bounce when it collides
|
|
56
|
-
particleEmitter.trailScale = 2; // stretch in direction of motion
|
|
57
|
-
// start the game timer
|
|
58
|
-
gameTimer.set();
|
|
59
|
-
}
|
|
60
|
-
///////////////////////////////////////////////////////////////////////////////
|
|
61
|
-
function gameUpdate() {
|
|
62
|
-
if (LittleJS.mouseWasPressed(0)) {
|
|
63
|
-
// play sound when mouse is pressed
|
|
64
|
-
sound_click.play(LittleJS.mousePos);
|
|
65
|
-
// change particle color and set to fade out
|
|
66
|
-
particleEmitter.colorStartA = new Color;
|
|
67
|
-
particleEmitter.colorStartB = LittleJS.randColor();
|
|
68
|
-
particleEmitter.colorEndA = particleEmitter.colorStartA.scale(1, 0);
|
|
69
|
-
particleEmitter.colorEndB = particleEmitter.colorStartB.scale(1, 0);
|
|
70
|
-
// unlock medals
|
|
71
|
-
medal_example.unlock();
|
|
72
|
-
}
|
|
73
|
-
// move particles to mouse location if on screen
|
|
74
|
-
if (LittleJS.mousePosScreen.x)
|
|
75
|
-
particleEmitter.pos = LittleJS.mousePos;
|
|
76
|
-
}
|
|
77
|
-
///////////////////////////////////////////////////////////////////////////////
|
|
78
|
-
function gameUpdatePost() {
|
|
79
|
-
}
|
|
80
|
-
///////////////////////////////////////////////////////////////////////////////
|
|
81
|
-
function gameRender() {
|
|
82
|
-
// draw a grey square in the background without using webgl
|
|
83
|
-
LittleJS.drawRect(LittleJS.cameraPos, LittleJS.tileCollisionSize.add(vec2(5)), new Color(.2, .2, .2), 0, false);
|
|
84
|
-
}
|
|
85
|
-
///////////////////////////////////////////////////////////////////////////////
|
|
86
|
-
function gameRenderPost() {
|
|
87
|
-
// draw to overlay canvas for hud rendering
|
|
88
|
-
LittleJS.drawTextScreen('LittleJS with TypeScript', vec2(LittleJS.mainCanvasSize.x / 2, 80), 80);
|
|
89
|
-
}
|
|
90
|
-
///////////////////////////////////////////////////////////////////////////////
|
|
91
|
-
// Startup LittleJS Engine
|
|
92
|
-
LittleJS.engineInit(gameInit, gameUpdate, gameUpdatePost, gameRender, gameRenderPost, 'tiles.png');
|