littlejsengine 1.9.11 → 1.10.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 +9 -13
- package/dist/littlejs.d.ts +129 -10
- package/dist/littlejs.esm.js +220 -75
- package/dist/littlejs.esm.min.js +1 -1
- package/dist/littlejs.js +188 -73
- package/dist/littlejs.min.js +1 -1
- package/dist/littlejs.release.js +187 -72
- package/examples/box2d/game.js +4 -1
- package/examples/box2d/index.html +7 -6
- package/examples/breakout/game.js +1 -1
- package/examples/breakout/index.html +5 -4
- package/examples/breakoutTutorial/README.md +9 -7
- package/examples/breakoutTutorial/game.js +6 -6
- package/examples/breakoutTutorial/index.html +4 -3
- package/examples/electron/game.js +1 -1
- package/examples/electron/index.html +4 -3
- package/examples/empty/game.js +1 -1
- package/examples/empty/index.html +2 -1
- package/examples/htmlMenu/game.js +67 -0
- package/examples/htmlMenu/index.html +56 -0
- package/examples/htmlMenu/tiles.png +0 -0
- package/examples/index.html +33 -0
- package/examples/js13k/build/index.html +1 -0
- package/examples/js13k/build/index.js +1 -0
- package/examples/js13k/build/tiles.png +0 -0
- package/examples/js13k/game - Copy.zip +0 -0
- package/examples/js13k/game.js +1 -1
- package/examples/js13k/game.zip +0 -0
- package/examples/js13k/index.html +17 -14
- package/examples/module/game.js +1 -1
- package/examples/module/index.html +3 -2
- package/examples/particles/index.html +4 -3
- package/examples/platformer/game.js +7 -5
- package/examples/platformer/gameCharacter.js +12 -11
- package/examples/platformer/gameEffects.js +3 -4
- package/examples/platformer/gameLevel.js +18 -34
- package/examples/platformer/gameObjects.js +9 -15
- package/examples/platformer/index.html +10 -9
- package/examples/puzzle/game.js +1 -1
- package/examples/puzzle/index.html +4 -3
- package/examples/starter/build/index.html +2 -0
- package/examples/starter/build/index.js +1 -0
- package/examples/starter/build/tiles.png +0 -0
- package/examples/starter/game.js +4 -4
- package/examples/starter/game.zip +0 -0
- package/examples/starter/index.html +15 -14
- package/examples/stress/index.html +3 -2
- package/examples/typescript/build/build/littlejs.esm.js +4327 -0
- package/examples/typescript/build/dist/littlejs.esm.js +4425 -0
- package/examples/typescript/build/examples/typescript/build.js +24 -0
- package/examples/typescript/build/examples/typescript/game.js +100 -0
- package/examples/typescript/build/examples/typescript/test/build/littlejs.esm.js +3934 -0
- package/examples/typescript/build/examples/typescript/test/examples/typescript/build.js +86 -0
- package/examples/typescript/build/examples/typescript/test/examples/typescript/game.js +92 -0
- package/examples/typescript/game.js +1 -1
- package/examples/typescript/game.ts +1 -1
- package/examples/typescript/index.html +3 -2
- package/examples/uiSystem/game.js +134 -0
- package/examples/uiSystem/index.html +25 -0
- package/examples/uiSystem/tiles.png +0 -0
- package/jsconfig.json +11 -0
- package/package.json +1 -1
- package/plugins/box2d.js +2 -1
- package/plugins/postProcess.js +14 -8
- package/plugins/uiSystem.js +243 -0
- package/src/engine.js +42 -22
- package/src/engineAudio.js +10 -13
- package/src/engineDebug.js +1 -1
- package/src/engineDraw.js +102 -27
- package/src/engineExport.js +32 -2
- package/src/engineInput.js +1 -3
- package/src/engineObject.js +1 -0
- package/src/engineSettings.js +1 -1
- package/src/engineTileLayer.js +2 -1
- package/src/engineUtilities.js +2 -1
- package/src/engineWebGL.js +26 -4
|
@@ -0,0 +1,86 @@
|
|
|
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
|
+
;
|
|
@@ -0,0 +1,92 @@
|
|
|
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');
|
|
@@ -97,4 +97,4 @@ function gameRenderPost() {
|
|
|
97
97
|
}
|
|
98
98
|
///////////////////////////////////////////////////////////////////////////////
|
|
99
99
|
// Startup LittleJS Engine
|
|
100
|
-
LittleJS.engineInit(gameInit, gameUpdate, gameUpdatePost, gameRender, gameRenderPost);
|
|
100
|
+
LittleJS.engineInit(gameInit, gameUpdate, gameUpdatePost, gameRender, gameRenderPost, ['tiles.png']);
|
|
@@ -128,4 +128,4 @@ function gameRenderPost()
|
|
|
128
128
|
|
|
129
129
|
///////////////////////////////////////////////////////////////////////////////
|
|
130
130
|
// Startup LittleJS Engine
|
|
131
|
-
LittleJS.engineInit(gameInit, gameUpdate, gameUpdatePost, gameRender, gameRenderPost);
|
|
131
|
+
LittleJS.engineInit(gameInit, gameUpdate, gameUpdatePost, gameRender, gameRenderPost, ['tiles.png']);
|
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
<!DOCTYPE html><head>
|
|
2
|
-
<title>
|
|
2
|
+
<title>LittleJS TypeScript Demo</title>
|
|
3
|
+
<meta charset=utf-8>
|
|
3
4
|
<meta name=apple-mobile-web-app-capable content=yes>
|
|
4
5
|
<meta name=mobile-web-app-capable content=yes>
|
|
5
6
|
<link rel=icon type=image/png href=../favicon.png>
|
|
6
7
|
</head><body>
|
|
7
8
|
|
|
8
9
|
<!-- Add your game scripts here -->
|
|
9
|
-
<script src=game.js?
|
|
10
|
+
<script src=game.js?1100 type=module></script>
|
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
/*
|
|
2
|
+
Little JS UI System Example
|
|
3
|
+
- Shows how to use the LittleJS UI plugin
|
|
4
|
+
- Modal windows, buttons, text, checkboxes, and more
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
'use strict';
|
|
8
|
+
|
|
9
|
+
// show the LittleJS splash screen
|
|
10
|
+
setShowSplashScreen(true);
|
|
11
|
+
|
|
12
|
+
// sound effects
|
|
13
|
+
const sound_click = new Sound([1,0]);
|
|
14
|
+
|
|
15
|
+
// UI system
|
|
16
|
+
let uiRoot, uiMenu;
|
|
17
|
+
const getMenuVisible =()=> uiMenu.visible;
|
|
18
|
+
const setMenuVisible =(visible)=> uiMenu.visible = visible;
|
|
19
|
+
|
|
20
|
+
function createUI()
|
|
21
|
+
{
|
|
22
|
+
// setup root to attach all ui elements to
|
|
23
|
+
uiRoot = new UIObject(vec2(mainCanvasSize.x/2,0));
|
|
24
|
+
const uiInfo = new UIText(vec2(0,50), vec2(1e3, 70),
|
|
25
|
+
'LittleJS UI System Example\nM = Toggle menu');
|
|
26
|
+
uiInfo.textColor = WHITE;
|
|
27
|
+
uiInfo.lineWidth = 8;
|
|
28
|
+
uiRoot.addChild(uiInfo);
|
|
29
|
+
|
|
30
|
+
// setup example menu
|
|
31
|
+
uiMenu = new UIObject(vec2(0,450));
|
|
32
|
+
uiRoot.addChild(uiMenu);
|
|
33
|
+
const uiBackground = new UIObject(vec2(0,0), vec2(450,550));
|
|
34
|
+
uiMenu.addChild(uiBackground);
|
|
35
|
+
|
|
36
|
+
// example large text
|
|
37
|
+
const textTitle = new UIText(vec2(0,-200), vec2(500, 90), 'Test Title');
|
|
38
|
+
uiMenu.addChild(textTitle);
|
|
39
|
+
textTitle.textColor = RED;
|
|
40
|
+
textTitle.lineWidth = 4;
|
|
41
|
+
textTitle.lineColor = BLUE;
|
|
42
|
+
|
|
43
|
+
// example multiline text
|
|
44
|
+
const textTest = new UIText(vec2(-60,-120), vec2(300, 50), 'Test Text\nSecond text line.')
|
|
45
|
+
uiMenu.addChild(textTest);
|
|
46
|
+
|
|
47
|
+
// example tile image
|
|
48
|
+
const tileTest = new UITile(vec2(150,-110), vec2(110), tile(3,128))
|
|
49
|
+
uiMenu.addChild(tileTest);
|
|
50
|
+
|
|
51
|
+
// example checkbox
|
|
52
|
+
const checkbox = new UICheckbox(vec2(-160,0), vec2(50));
|
|
53
|
+
uiMenu.addChild(checkbox);
|
|
54
|
+
checkbox.onClick = ()=>
|
|
55
|
+
{
|
|
56
|
+
checkbox.checked = !checkbox.checked;
|
|
57
|
+
console.log('Checkbox clicked');
|
|
58
|
+
sound_click.play(0,.5,checkbox.checked?4:1);
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
// text attached to checkbox
|
|
62
|
+
const checkboxText = new UIText(vec2(200,0), vec2(300, 50), 'Test Checkbox');
|
|
63
|
+
checkbox.addChild(checkboxText);
|
|
64
|
+
|
|
65
|
+
// example button
|
|
66
|
+
const button1 = new UIButton(vec2(0,90), vec2(350, 70), 'Test Button', RED, 6, CYAN);
|
|
67
|
+
uiMenu.addChild(button1);
|
|
68
|
+
button1.onClick = ()=>
|
|
69
|
+
{
|
|
70
|
+
console.log('Button 1 clicked');
|
|
71
|
+
sound_click.play();
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
// exit button
|
|
75
|
+
const button2 = new UIButton(vec2(0,190), vec2(350, 70), 'Exit Menu', RED, 6, CYAN);
|
|
76
|
+
uiMenu.addChild(button2);
|
|
77
|
+
button2.onClick = ()=>
|
|
78
|
+
{
|
|
79
|
+
console.log('Button 2 clicked');
|
|
80
|
+
sound_click.play(0,.5,2);
|
|
81
|
+
setMenuVisible(false);
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
///////////////////////////////////////////////////////////////////////////////
|
|
86
|
+
function gameInit()
|
|
87
|
+
{
|
|
88
|
+
initUISystem();
|
|
89
|
+
createUI();
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
///////////////////////////////////////////////////////////////////////////////
|
|
93
|
+
function gameUpdate()
|
|
94
|
+
{
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
///////////////////////////////////////////////////////////////////////////////
|
|
98
|
+
function gameUpdatePost()
|
|
99
|
+
{
|
|
100
|
+
// center ui
|
|
101
|
+
uiRoot.pos.x = mainCanvasSize.x/2;
|
|
102
|
+
|
|
103
|
+
// menu system
|
|
104
|
+
const menuVisible = getMenuVisible();
|
|
105
|
+
paused = menuVisible;
|
|
106
|
+
|
|
107
|
+
// toggle menu visibility
|
|
108
|
+
if (keyWasPressed('KeyM'))
|
|
109
|
+
setMenuVisible(!menuVisible);
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
///////////////////////////////////////////////////////////////////////////////
|
|
113
|
+
function gameRender()
|
|
114
|
+
{
|
|
115
|
+
// test game rendering
|
|
116
|
+
drawRect(vec2(), vec2(1e3), hsl(0,0,.2));
|
|
117
|
+
|
|
118
|
+
// test game rendering
|
|
119
|
+
drawRect(vec2(), vec2(1e3), hsl(0,0,.2));
|
|
120
|
+
for(let i=0; i<1e3; ++i)
|
|
121
|
+
{
|
|
122
|
+
const pos = vec2(30*Math.sin(i+time/9),20*Math.sin(i*i+time/9));
|
|
123
|
+
drawTile(pos, vec2(2), tile(3,128), hsl(i/9,1,.4), time+i, !(i%2), hsl(i/9,1,.1,0));
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
///////////////////////////////////////////////////////////////////////////////
|
|
128
|
+
function gameRenderPost()
|
|
129
|
+
{
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
///////////////////////////////////////////////////////////////////////////////
|
|
133
|
+
// Startup LittleJS Engine
|
|
134
|
+
engineInit(gameInit, gameUpdate, gameUpdatePost, gameRender, gameRenderPost, ['tiles.png']);
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
<!DOCTYPE html><head>
|
|
2
|
+
<title>LittleJS Starter Project</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=../../src/engineDebug.js?1100></script>
|
|
11
|
+
<script src=../../src/engineUtilities.js?1100></script>
|
|
12
|
+
<script src=../../src/engineSettings.js?1100></script>
|
|
13
|
+
<script src=../../src/engineObject.js?1100></script>
|
|
14
|
+
<script src=../../src/engineDraw.js?1100></script>
|
|
15
|
+
<script src=../../src/engineInput.js?1100></script>
|
|
16
|
+
<script src=../../src/engineAudio.js?1100></script>
|
|
17
|
+
<script src=../../src/engineTileLayer.js?1100></script>
|
|
18
|
+
<script src=../../src/engineParticles.js?1100></script>
|
|
19
|
+
<script src=../../src/engineMedals.js?1100></script>
|
|
20
|
+
<script src=../../src/engineWebGL.js?1100></script>
|
|
21
|
+
<script src=../../src/engine.js?1100></script>
|
|
22
|
+
|
|
23
|
+
<!-- Add your game scripts here -->
|
|
24
|
+
<script src=../../plugins/uiSystem.js?1100></script>
|
|
25
|
+
<script src=game.js?1100></script>
|
|
Binary file
|
package/jsconfig.json
ADDED
package/package.json
CHANGED
package/plugins/box2d.js
CHANGED
|
@@ -875,7 +875,8 @@ function box2dEngineInit(gameInit, gameUpdate, gameUpdatePost, gameRender, gameR
|
|
|
875
875
|
engineAddPlugin(box2dUpdate, box2dRender);
|
|
876
876
|
function box2dUpdate()
|
|
877
877
|
{
|
|
878
|
-
|
|
878
|
+
if (!paused)
|
|
879
|
+
box2dWorld.Step(timeDelta, box2dStepIterations, box2dStepIterations);
|
|
879
880
|
}
|
|
880
881
|
function box2dRender()
|
|
881
882
|
{
|
package/plugins/postProcess.js
CHANGED
|
@@ -49,11 +49,6 @@ function initPostProcess(shaderCode, includeOverlay=false)
|
|
|
49
49
|
glPostTexture = glCreateTexture(undefined);
|
|
50
50
|
glPostIncludeOverlay = includeOverlay;
|
|
51
51
|
|
|
52
|
-
// hide the original 2d canvas
|
|
53
|
-
mainCanvas.style.visibility = 'hidden';
|
|
54
|
-
if (glPostIncludeOverlay)
|
|
55
|
-
overlayCanvas.style.visibility = 'hidden';
|
|
56
|
-
|
|
57
52
|
// Render the post processing shader, called automatically by the engine
|
|
58
53
|
engineAddPlugin(undefined, postProcessRender);
|
|
59
54
|
function postProcessRender()
|
|
@@ -72,8 +67,12 @@ function initPostProcess(shaderCode, includeOverlay=false)
|
|
|
72
67
|
glContext.viewport(0, 0, glCanvas.width = mainCanvas.width, glCanvas.height = mainCanvas.height);
|
|
73
68
|
}
|
|
74
69
|
|
|
75
|
-
|
|
76
|
-
|
|
70
|
+
if (glPostIncludeOverlay)
|
|
71
|
+
{
|
|
72
|
+
// copy overlay canvas so it will be included in post processing
|
|
73
|
+
mainContext.drawImage(overlayCanvas, 0, 0);
|
|
74
|
+
overlayCanvas.width |= 0;
|
|
75
|
+
}
|
|
77
76
|
|
|
78
77
|
// setup shader program to draw one triangle
|
|
79
78
|
glContext.useProgram(glPostShader);
|
|
@@ -99,4 +98,11 @@ function initPostProcess(shaderCode, includeOverlay=false)
|
|
|
99
98
|
glContext.uniform3f(uniformLocation('iResolution'), mainCanvas.width, mainCanvas.height, 1);
|
|
100
99
|
glContext.drawArrays(gl_TRIANGLE_STRIP, 0, 4);
|
|
101
100
|
}
|
|
102
|
-
}
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
export {
|
|
104
|
+
initPostProcess,
|
|
105
|
+
glPostShader,
|
|
106
|
+
glPostTexture,
|
|
107
|
+
glPostIncludeOverlay
|
|
108
|
+
};
|