littlejsengine 1.18.2 → 1.18.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/COPYRIGHT.txt +38 -0
- package/FAQ.md +633 -0
- package/LICENSE +5 -27
- package/README.md +19 -1
- package/dist/littlejs.d.ts +550 -57
- package/dist/littlejs.esm.js +2208 -492
- package/dist/littlejs.esm.min.js +1 -1
- package/dist/littlejs.js +2165 -480
- package/dist/littlejs.min.js +1 -1
- package/dist/littlejs.release.js +2166 -481
- package/package.json +8 -1
- package/plugins/box2d.js +36 -9
- package/{src/engineMedals.js → plugins/medalSystem.js} +248 -196
- package/plugins/pathFinder.js +758 -0
- package/plugins/pluginExport.js +26 -0
- package/plugins/tween.js +509 -0
- package/plugins/tweenSystem.js +509 -0
- package/plugins/uiSystem.js +151 -12
- package/src/engine.js +9 -145
- package/src/engineAudio.js +8 -5
- package/src/engineBuild.mjs +4 -1
- package/src/engineDebug.js +1 -1
- package/src/engineDraw.js +154 -5
- package/src/engineExport.js +17 -12
- package/src/engineInput.js +27 -1
- package/src/engineLogo.js +146 -0
- package/src/engineMath.js +10 -3
- package/src/engineObject.js +11 -5
- package/src/engineParticles.js +6 -3
- package/src/engineRelease.js +1 -1
- package/src/engineSettings.js +17 -47
- package/src/engineUtilities.js +7 -2
- package/src/engineWebGL.js +31 -8
- package/src/jsconfig.json +3 -1
- package/.claude/settings.local.json +0 -7
- package/.github/workflows/test.yml +0 -17
- package/AI.md +0 -172
- package/CLAUDE.md +0 -1
- package/examples/box2d/game.js +0 -192
- package/examples/box2d/gameObjects.js +0 -564
- package/examples/box2d/index.html +0 -9
- package/examples/box2d/scenes.js +0 -194
- package/examples/box2d/tiles.png +0 -0
- package/examples/breakout/game.js +0 -175
- package/examples/breakout/gameObjects.js +0 -147
- package/examples/breakout/index.html +0 -8
- package/examples/breakout/tiles.png +0 -0
- package/examples/breakoutTutorial/README.md +0 -521
- package/examples/breakoutTutorial/game.js +0 -191
- package/examples/breakoutTutorial/images/1.png +0 -0
- package/examples/breakoutTutorial/images/10.png +0 -0
- package/examples/breakoutTutorial/images/11.png +0 -0
- package/examples/breakoutTutorial/images/2.png +0 -0
- package/examples/breakoutTutorial/images/3.png +0 -0
- package/examples/breakoutTutorial/images/4.png +0 -0
- package/examples/breakoutTutorial/images/5.png +0 -0
- package/examples/breakoutTutorial/images/6.png +0 -0
- package/examples/breakoutTutorial/images/7.png +0 -0
- package/examples/breakoutTutorial/images/8.png +0 -0
- package/examples/breakoutTutorial/images/9.png +0 -0
- package/examples/breakoutTutorial/index.html +0 -8
- package/examples/electron/build.mjs +0 -127
- package/examples/electron/electron.js +0 -35
- package/examples/electron/game.js +0 -54
- package/examples/electron/index.html +0 -13
- package/examples/electron/package.json +0 -5
- package/examples/electron/tiles.png +0 -0
- package/examples/empty/game.js +0 -51
- package/examples/empty/index.html +0 -5
- package/examples/empty/tiles.png +0 -0
- package/examples/favicon.png +0 -0
- package/examples/games.jpg +0 -0
- package/examples/htmlMenu/game.js +0 -82
- package/examples/htmlMenu/index.html +0 -45
- package/examples/htmlMenu/tiles.png +0 -0
- package/examples/index.html +0 -800
- package/examples/logo.png +0 -0
- package/examples/logo2.png +0 -0
- package/examples/module/build.mjs +0 -124
- package/examples/module/game.js +0 -132
- package/examples/module/index.html +0 -10
- package/examples/module/tiles.png +0 -0
- package/examples/particles/index.html +0 -426
- package/examples/particles/tiles.png +0 -0
- package/examples/platformer/data/gameLevelData.tmx +0 -143
- package/examples/platformer/data/gameLevelData.tsx +0 -4
- package/examples/platformer/game.js +0 -147
- package/examples/platformer/gameCharacter.js +0 -309
- package/examples/platformer/gameEffects.js +0 -278
- package/examples/platformer/gameLevel.js +0 -205
- package/examples/platformer/gameLevelData.json +0 -171
- package/examples/platformer/gameObjects.js +0 -378
- package/examples/platformer/gamePlayer.js +0 -35
- package/examples/platformer/index.html +0 -9
- package/examples/platformer/tiles.png +0 -0
- package/examples/platformer/tilesLevel.png +0 -0
- package/examples/puzzle/game.js +0 -331
- package/examples/puzzle/index.html +0 -8
- package/examples/puzzle/tiles.png +0 -0
- package/examples/screenshot.jpg +0 -0
- package/examples/shorts/animation.js +0 -18
- package/examples/shorts/base.html +0 -54
- package/examples/shorts/blending.js +0 -14
- package/examples/shorts/box2d.js +0 -51
- package/examples/shorts/box2dCar.js +0 -59
- package/examples/shorts/box2dPool.js +0 -107
- package/examples/shorts/box2dTileLayer.js +0 -48
- package/examples/shorts/cameraDrag.js +0 -22
- package/examples/shorts/clock.js +0 -21
- package/examples/shorts/colors.js +0 -25
- package/examples/shorts/debugDraw.js +0 -37
- package/examples/shorts/empty.js +0 -30
- package/examples/shorts/flappyGame.js +0 -55
- package/examples/shorts/fontImage.js +0 -17
- package/examples/shorts/fps.js +0 -90
- package/examples/shorts/helloWorld.js +0 -11
- package/examples/shorts/hillGlideGame.js +0 -63
- package/examples/shorts/input.js +0 -64
- package/examples/shorts/landerGame.js +0 -57
- package/examples/shorts/maze.js +0 -48
- package/examples/shorts/medals.js +0 -51
- package/examples/shorts/music.js +0 -78
- package/examples/shorts/musicPlayer.js +0 -137
- package/examples/shorts/nineSlice.js +0 -40
- package/examples/shorts/parallax.js +0 -72
- package/examples/shorts/particles.js +0 -28
- package/examples/shorts/piano.js +0 -44
- package/examples/shorts/platformer.js +0 -45
- package/examples/shorts/pongGame.js +0 -41
- package/examples/shorts/postProcess.js +0 -62
- package/examples/shorts/sequencer.js +0 -124
- package/examples/shorts/shader.js +0 -29
- package/examples/shorts/shapes.js +0 -21
- package/examples/shorts/slidingPuzzle.js +0 -52
- package/examples/shorts/song.mp3 +0 -0
- package/examples/shorts/sound.js +0 -36
- package/examples/shorts/spaceGame.js +0 -58
- package/examples/shorts/spriteAtlas.js +0 -31
- package/examples/shorts/starfield.js +0 -15
- package/examples/shorts/texture.js +0 -16
- package/examples/shorts/tileLayer.js +0 -48
- package/examples/shorts/tileRaycast.js +0 -39
- package/examples/shorts/tiles.png +0 -0
- package/examples/shorts/tiltedView.js +0 -63
- package/examples/shorts/timers.js +0 -53
- package/examples/shorts/topDown.js +0 -38
- package/examples/shorts/uiSystem.js +0 -61
- package/examples/shorts/video.webm +0 -0
- package/examples/shorts/videoPlayer.js +0 -34
- package/examples/starter/build.bat +0 -7
- package/examples/starter/build.mjs +0 -126
- package/examples/starter/game.js +0 -137
- package/examples/starter/index.html +0 -35
- package/examples/starter/tiles.png +0 -0
- package/examples/stress/index.html +0 -173
- package/examples/style.css +0 -150
- package/examples/typescript/build.mjs +0 -60
- package/examples/typescript/game.js +0 -100
- package/examples/typescript/game.ts +0 -132
- package/examples/typescript/index.html +0 -10
- package/examples/typescript/tiles.png +0 -0
- package/examples/typescript/tsconfig.json +0 -17
- package/examples/uiSystem/game.js +0 -139
- package/examples/uiSystem/index.html +0 -10
- package/examples/uiSystem/tiles.png +0 -0
- package/jsconfig.json +0 -12
- package/plugins/desktop.ini +0 -2
- package/reference.md +0 -447
- package/test/math.test.mjs +0 -774
- package/test/setup.mjs +0 -22
- package/test/smoke.test.mjs +0 -258
- package/test/util.test.mjs +0 -80
package/examples/logo.png
DELETED
|
Binary file
|
package/examples/logo2.png
DELETED
|
Binary file
|
|
@@ -1,124 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* LittleJS Build System
|
|
3
|
-
*/
|
|
4
|
-
|
|
5
|
-
'use strict';
|
|
6
|
-
|
|
7
|
-
import { fileURLToPath } from 'node:url';
|
|
8
|
-
import { dirname, join } from 'node:path';
|
|
9
|
-
import fs from 'node:fs';
|
|
10
|
-
import { execSync } from 'node:child_process';
|
|
11
|
-
|
|
12
|
-
const __dirname = dirname(fileURLToPath(import.meta.url));
|
|
13
|
-
|
|
14
|
-
const PROGRAM_TITLE = 'Little JS Starter Project';
|
|
15
|
-
const PROGRAM_NAME = 'game';
|
|
16
|
-
const BUILD_FOLDER = join(__dirname, 'build');
|
|
17
|
-
const sourceFiles =
|
|
18
|
-
[
|
|
19
|
-
'game.js',
|
|
20
|
-
// add your game's source files here
|
|
21
|
-
];
|
|
22
|
-
const engineFile = join(__dirname, '../../dist/littlejs.esm.min.js'); // Use the minified ES module
|
|
23
|
-
const dataFiles =
|
|
24
|
-
[
|
|
25
|
-
'tiles.png',
|
|
26
|
-
// add your game's data files here
|
|
27
|
-
];
|
|
28
|
-
|
|
29
|
-
console.log(`Building ${PROGRAM_NAME}...`);
|
|
30
|
-
const startTime = Date.now();
|
|
31
|
-
|
|
32
|
-
// rebuild engine
|
|
33
|
-
//execSync(`npm run build`, { stdio: 'inherit' });
|
|
34
|
-
|
|
35
|
-
// remove old files and setup build folder
|
|
36
|
-
fs.rmSync(BUILD_FOLDER, { recursive: true, force: true });
|
|
37
|
-
fs.rmSync(join(__dirname, `${PROGRAM_NAME}.zip`), { force: true });
|
|
38
|
-
fs.mkdirSync(BUILD_FOLDER);
|
|
39
|
-
|
|
40
|
-
// copy data files
|
|
41
|
-
for (const file of dataFiles)
|
|
42
|
-
fs.copyFileSync(join(__dirname, file), join(BUILD_FOLDER, file));
|
|
43
|
-
|
|
44
|
-
// copy engine module
|
|
45
|
-
fs.copyFileSync(engineFile, join(BUILD_FOLDER, 'littlejs.esm.min.js'));
|
|
46
|
-
|
|
47
|
-
Build
|
|
48
|
-
(
|
|
49
|
-
sourceFiles,
|
|
50
|
-
[htmlBuildStep, zipBuildStep]
|
|
51
|
-
);
|
|
52
|
-
|
|
53
|
-
console.log('');
|
|
54
|
-
console.log(`Build Completed in ${((Date.now() - startTime)/1e3).toFixed(2)} seconds!`);
|
|
55
|
-
|
|
56
|
-
///////////////////////////////////////////////////////////////////////////////
|
|
57
|
-
|
|
58
|
-
// A single build with its own source files, build steps, and output file
|
|
59
|
-
// - each build step is a callback that accepts a single filename
|
|
60
|
-
function Build(files=[], buildSteps=[])
|
|
61
|
-
{
|
|
62
|
-
// process each source file separately (don't concatenate modules!)
|
|
63
|
-
for (const file of files)
|
|
64
|
-
{
|
|
65
|
-
const outputFile = join(BUILD_FOLDER, file);
|
|
66
|
-
fs.copyFileSync(join(__dirname, file), outputFile);
|
|
67
|
-
moduleFixStep(outputFile);
|
|
68
|
-
uglifyBuildStep(outputFile);
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
// execute build steps in order
|
|
72
|
-
for (const buildStep of buildSteps)
|
|
73
|
-
buildStep();
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
function moduleFixStep(filename)
|
|
77
|
-
{
|
|
78
|
-
console.log(`Fixing module imports in ${filename}...`);
|
|
79
|
-
|
|
80
|
-
let code = fs.readFileSync(filename, 'utf8');
|
|
81
|
-
|
|
82
|
-
// update the import path to use the local minified version
|
|
83
|
-
code = code.replace(/import \* as LJS from ['"].*littlejs\.esm(?:\.min)?\.js['"];?/g,
|
|
84
|
-
"import * as LJS from './littlejs.esm.min.js';");
|
|
85
|
-
|
|
86
|
-
// also fix relative imports to other game modules
|
|
87
|
-
code = code.replace(/from ['"]\.\.\//g, "from './");
|
|
88
|
-
|
|
89
|
-
fs.writeFileSync(filename, code);
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
function uglifyBuildStep(filename)
|
|
93
|
-
{
|
|
94
|
-
console.log('Running uglify...');
|
|
95
|
-
execSync(`npx uglifyjs ${filename} -c -m -o ${filename}`, {stdio: 'inherit'});
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
function htmlBuildStep()
|
|
99
|
-
{
|
|
100
|
-
console.log('Building html...');
|
|
101
|
-
|
|
102
|
-
// create html file with module script tag pointing to main game file
|
|
103
|
-
let buffer = ''
|
|
104
|
-
buffer += '<!DOCTYPE html>';
|
|
105
|
-
buffer += '<head>';
|
|
106
|
-
buffer += `<title>${PROGRAM_TITLE}</title>`;
|
|
107
|
-
buffer += '<meta charset=utf-8>';
|
|
108
|
-
buffer += '</head>';
|
|
109
|
-
buffer += '<body>';
|
|
110
|
-
buffer += '<script src="game.js" type="module"></script>';
|
|
111
|
-
buffer += '</body>';
|
|
112
|
-
|
|
113
|
-
// output html file
|
|
114
|
-
fs.writeFileSync(join(BUILD_FOLDER, 'index.html'), buffer, {flag: 'w+'});
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
function zipBuildStep()
|
|
118
|
-
{
|
|
119
|
-
console.log('Zipping...');
|
|
120
|
-
const sources = ['index.html', 'littlejs.esm.min.js', ...sourceFiles, ...dataFiles];
|
|
121
|
-
const sourceList = sources.join(' ');
|
|
122
|
-
execSync(`npx bestzip ../${PROGRAM_NAME}.zip ${sourceList}`, {cwd:BUILD_FOLDER, stdio: 'inherit'});
|
|
123
|
-
console.log(`Size of ${PROGRAM_NAME}.zip: ${fs.statSync(join(__dirname, `${PROGRAM_NAME}.zip`)).size} bytes`);
|
|
124
|
-
}
|
package/examples/module/game.js
DELETED
|
@@ -1,132 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
Little JS Module Demo
|
|
3
|
-
- A simple starter project
|
|
4
|
-
- Shows how to use LittleJS with modules
|
|
5
|
-
*/
|
|
6
|
-
|
|
7
|
-
'use strict';
|
|
8
|
-
|
|
9
|
-
// import LittleJS module
|
|
10
|
-
import * as LJS from '../../dist/littlejs.esm.js';
|
|
11
|
-
const {tile, vec2, hsl} = LJS;
|
|
12
|
-
|
|
13
|
-
// show the LittleJS splash screen
|
|
14
|
-
LJS.setShowSplashScreen(true);
|
|
15
|
-
|
|
16
|
-
// fix texture bleeding by shrinking tile slightly
|
|
17
|
-
LJS.setTileDefaultBleed(.5);
|
|
18
|
-
|
|
19
|
-
// sound effects
|
|
20
|
-
const sound_click = new LJS.Sound([1,.5]);
|
|
21
|
-
|
|
22
|
-
// medals
|
|
23
|
-
const medal_example = new LJS.Medal(0, 'Example Medal', 'Welcome to LittleJS!');
|
|
24
|
-
LJS.medalsInit('Hello World');
|
|
25
|
-
|
|
26
|
-
// game variables
|
|
27
|
-
let particleEmitter;
|
|
28
|
-
|
|
29
|
-
///////////////////////////////////////////////////////////////////////////////
|
|
30
|
-
function gameInit()
|
|
31
|
-
{
|
|
32
|
-
// create tile collision and visible tile layer
|
|
33
|
-
const pos = vec2();
|
|
34
|
-
const tileLayer = new LJS.TileCollisionLayer(pos, vec2(32,16));
|
|
35
|
-
|
|
36
|
-
// get level data from the tiles image
|
|
37
|
-
const mainContext = LJS.mainContext;
|
|
38
|
-
const tileImage = LJS.textureInfos[0].image;
|
|
39
|
-
mainContext.drawImage(tileImage, 0, 0);
|
|
40
|
-
const imageData = mainContext.getImageData(0,0,tileImage.width,tileImage.height).data;
|
|
41
|
-
for (pos.x = tileLayer.size.x; pos.x--;)
|
|
42
|
-
for (pos.y = tileLayer.size.y; pos.y--;)
|
|
43
|
-
{
|
|
44
|
-
// check if this pixel is set
|
|
45
|
-
const i = pos.x + tileImage.width*(15 + tileLayer.size.y - pos.y);
|
|
46
|
-
if (!imageData[4*i])
|
|
47
|
-
continue;
|
|
48
|
-
|
|
49
|
-
// set tile data
|
|
50
|
-
const tileIndex = 1;
|
|
51
|
-
const direction = LJS.randInt(4)
|
|
52
|
-
const mirror = !LJS.randInt(2);
|
|
53
|
-
const color = LJS.randColor();
|
|
54
|
-
const data = new LJS.TileLayerData(tileIndex, direction, mirror, color);
|
|
55
|
-
tileLayer.setData(pos, data);
|
|
56
|
-
tileLayer.setCollisionData(pos);
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
// draw tile layer with new data
|
|
60
|
-
tileLayer.redraw();
|
|
61
|
-
|
|
62
|
-
// move camera to center of collision
|
|
63
|
-
LJS.setCameraPos(tileLayer.size.scale(.5));
|
|
64
|
-
LJS.setCameraScale(32);
|
|
65
|
-
|
|
66
|
-
// enable gravity
|
|
67
|
-
LJS.setGravity(vec2(0,-.01));
|
|
68
|
-
|
|
69
|
-
// create particle emitter
|
|
70
|
-
particleEmitter = new LJS.ParticleEmitter(
|
|
71
|
-
vec2(16,9), 0, // emitPos, emitAngle
|
|
72
|
-
0, 0, 500, 3.14, // emitSize, emitTime, rate, cone
|
|
73
|
-
tile(0, 16), // tileIndex, tileSize
|
|
74
|
-
hsl(1,1,1), hsl(0,0,0), // colorStartA, colorStartB
|
|
75
|
-
hsl(0,0,0,0), hsl(0,0,0,0), // colorEndA, colorEndB
|
|
76
|
-
1, .2, .2, .1, .05, // time, sizeStart, sizeEnd, speed, angleSpeed
|
|
77
|
-
.99, 1, 1, 3.14, // damping, angleDamping, gravityScale, cone
|
|
78
|
-
.05, .5, true, true // fadeRate, randomness, collide, additive
|
|
79
|
-
);
|
|
80
|
-
particleEmitter.restitution = .3; // bounce when it collides
|
|
81
|
-
particleEmitter.trailScale = 2; // stretch as it moves
|
|
82
|
-
particleEmitter.velocityInheritance = .3; // inherit emitter velocity
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
///////////////////////////////////////////////////////////////////////////////
|
|
86
|
-
function gameUpdate()
|
|
87
|
-
{
|
|
88
|
-
if (LJS.mouseWasPressed(0))
|
|
89
|
-
{
|
|
90
|
-
// play sound when mouse is pressed
|
|
91
|
-
sound_click.play(LJS.mousePos);
|
|
92
|
-
|
|
93
|
-
// change particle color and set to fade out
|
|
94
|
-
particleEmitter.colorStartA = LJS.randColor();
|
|
95
|
-
particleEmitter.colorStartB = LJS.randColor();
|
|
96
|
-
particleEmitter.colorEndA = particleEmitter.colorStartA.scale(1,0);
|
|
97
|
-
particleEmitter.colorEndB = particleEmitter.colorStartB.scale(1,0);
|
|
98
|
-
|
|
99
|
-
// unlock medals
|
|
100
|
-
medal_example.unlock();
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
// move particles to mouse location if on screen
|
|
104
|
-
if (LJS.mousePosScreen.x)
|
|
105
|
-
particleEmitter.pos = LJS.mousePos;
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
///////////////////////////////////////////////////////////////////////////////
|
|
109
|
-
function gameUpdatePost()
|
|
110
|
-
{
|
|
111
|
-
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
///////////////////////////////////////////////////////////////////////////////
|
|
115
|
-
function gameRender()
|
|
116
|
-
{
|
|
117
|
-
// draw a grey square in the background
|
|
118
|
-
LJS.drawRect(vec2(16,8), vec2(20,14), hsl(0,0,.6));
|
|
119
|
-
|
|
120
|
-
// draw the logo as a tile
|
|
121
|
-
LJS.drawTile(vec2(21,5), vec2(4.5), tile(3,128));
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
///////////////////////////////////////////////////////////////////////////////
|
|
125
|
-
function gameRenderPost()
|
|
126
|
-
{
|
|
127
|
-
LJS.drawTextScreen('LittleJS with Modules', vec2(LJS.mainCanvasSize.x/2, 80), 80);
|
|
128
|
-
}
|
|
129
|
-
|
|
130
|
-
///////////////////////////////////////////////////////////////////////////////
|
|
131
|
-
// Startup LittleJS Engine
|
|
132
|
-
LJS.engineInit(gameInit, gameUpdate, gameUpdatePost, gameRender, gameRenderPost, ['tiles.png']);
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
<!DOCTYPE html><head>
|
|
2
|
-
<title>LittleJS Module 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
|
-
<!-- Add your game scripts here -->
|
|
10
|
-
<script src=game.js type=module></script>
|
|
Binary file
|