littlejsengine 1.11.9 → 1.11.13
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 +3 -3
- package/dist/littlejs.d.ts +485 -492
- package/dist/littlejs.esm.js +548 -529
- package/dist/littlejs.esm.min.js +1 -1
- package/dist/littlejs.js +546 -525
- package/dist/littlejs.min.js +1 -1
- package/dist/littlejs.release.js +502 -484
- package/examples/htmlMenu/game.js +11 -1
- package/examples/htmlMenu/index.html +1 -10
- package/examples/module/game.js +2 -2
- package/examples/shorts/base.html +1 -1
- 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/build.js +13 -3
- package/examples/starter/game.js +8 -1
- package/examples/starter/game.zip +0 -0
- package/examples/typescript/build/dist/littlejs.esm.js +4834 -0
- package/examples/typescript/build/examples/typescript/build.js +24 -0
- package/examples/typescript/build/examples/typescript/game.js +102 -0
- package/examples/typescript/build.bat +5 -0
- package/examples/typescript/build.js +33 -0
- package/examples/typescript/game.js +102 -0
- package/examples/typescript/game.ts +134 -0
- package/examples/typescript/index.html +10 -0
- package/examples/typescript/tiles.png +0 -0
- package/examples/typescript/tsconfig.json +8 -0
- package/package.json +1 -1
- package/plugins/newgrounds.js +44 -35
- package/plugins/postProcess.js +18 -4
- package/plugins/uiSystem.js +196 -30
- package/src/engine.js +21 -20
- package/src/engineAudio.js +59 -59
- package/src/engineDebug.js +44 -41
- package/src/engineDraw.js +58 -58
- package/src/engineExport.js +2 -4
- package/src/engineInput.js +40 -35
- package/src/engineMedals.js +21 -11
- package/src/engineObject.js +42 -35
- package/src/engineParticles.js +10 -10
- package/src/engineSettings.js +77 -82
- package/src/engineTileLayer.js +21 -21
- package/src/engineUtilities.js +150 -150
- package/src/engineWebGL.js +3 -3
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
/**
|
|
3
|
+
* LittleJS Build System
|
|
4
|
+
*/
|
|
5
|
+
'use strict';
|
|
6
|
+
const PROGRAM_NAME = 'game';
|
|
7
|
+
const BUILD_FOLDER = 'build';
|
|
8
|
+
const ROOT_FOLDER = 'examples/typescript';
|
|
9
|
+
const sourceFiles = [
|
|
10
|
+
'game.js',
|
|
11
|
+
// add your game's scripts here
|
|
12
|
+
];
|
|
13
|
+
console.log(`Building TypeScript for ${PROGRAM_NAME}...`);
|
|
14
|
+
const startTime = Date.now();
|
|
15
|
+
const fs = require('node:fs');
|
|
16
|
+
const child_process = require('node:child_process');
|
|
17
|
+
console.log(`Removing old build filder...`);
|
|
18
|
+
fs.rmSync(BUILD_FOLDER, { recursive: true, force: true });
|
|
19
|
+
console.log(`Compiling TypeScript...`);
|
|
20
|
+
child_process.execSync(`npx tsc --outDir "./${BUILD_FOLDER}"`, { stdio: 'inherit' });
|
|
21
|
+
console.log(`Moving js files to root...`);
|
|
22
|
+
for (const file of sourceFiles)
|
|
23
|
+
fs.copyFileSync(`${BUILD_FOLDER}/${ROOT_FOLDER}/${file}`, `${file}`);
|
|
24
|
+
console.log(`TypeScript built in ${((Date.now() - startTime) / 1e3).toFixed(2)} seconds!`);
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
/*
|
|
2
|
+
Little JS TypeScript Demo
|
|
3
|
+
- A simple starter project
|
|
4
|
+
- Shows how to use LittleJS with modules
|
|
5
|
+
*/
|
|
6
|
+
'use strict';
|
|
7
|
+
// import module
|
|
8
|
+
import * as LittleJS from '../../dist/littlejs.esm.js';
|
|
9
|
+
const { tile, vec2, hsl } = LittleJS;
|
|
10
|
+
// show the LittleJS splash screen
|
|
11
|
+
LittleJS.setShowSplashScreen(true);
|
|
12
|
+
// fix texture bleeding by shrinking tile slightly
|
|
13
|
+
LittleJS.setTileFixBleedScale(.5);
|
|
14
|
+
// sound effects
|
|
15
|
+
const sound_click = new LittleJS.Sound([1, .5]);
|
|
16
|
+
// medals
|
|
17
|
+
const medal_example = new LittleJS.Medal(0, 'Example Medal', 'Welcome to LittleJS!');
|
|
18
|
+
LittleJS.medalsInit('Hello World');
|
|
19
|
+
// game variables
|
|
20
|
+
let particleEmitter;
|
|
21
|
+
///////////////////////////////////////////////////////////////////////////////
|
|
22
|
+
function gameInit() {
|
|
23
|
+
// create tile collision and visible tile layer
|
|
24
|
+
const tileCollisionSize = vec2(32, 16);
|
|
25
|
+
LittleJS.initTileCollision(tileCollisionSize);
|
|
26
|
+
const pos = vec2();
|
|
27
|
+
const tileLayer = new LittleJS.TileLayer(pos, tileCollisionSize);
|
|
28
|
+
// get level data from the tiles image
|
|
29
|
+
const mainContext = LittleJS.mainContext;
|
|
30
|
+
const tileImage = LittleJS.textureInfos[0].image;
|
|
31
|
+
mainContext.drawImage(tileImage, 0, 0);
|
|
32
|
+
const imageData = mainContext.getImageData(0, 0, tileImage.width, tileImage.height).data;
|
|
33
|
+
for (pos.x = tileCollisionSize.x; pos.x--;)
|
|
34
|
+
for (pos.y = tileCollisionSize.y; pos.y--;) {
|
|
35
|
+
// check if this pixel is set
|
|
36
|
+
const i = pos.x + tileImage.width * (15 + tileCollisionSize.y - pos.y);
|
|
37
|
+
if (!imageData[4 * i])
|
|
38
|
+
continue;
|
|
39
|
+
// set tile data
|
|
40
|
+
const tileIndex = 1;
|
|
41
|
+
const direction = LittleJS.randInt(4);
|
|
42
|
+
const mirror = !LittleJS.randInt(2);
|
|
43
|
+
const color = LittleJS.randColor();
|
|
44
|
+
const data = new LittleJS.TileLayerData(tileIndex, direction, mirror, color);
|
|
45
|
+
tileLayer.setData(pos, data);
|
|
46
|
+
LittleJS.setTileCollisionData(pos, 1);
|
|
47
|
+
}
|
|
48
|
+
// draw tile layer with new data
|
|
49
|
+
tileLayer.redraw();
|
|
50
|
+
// move camera to center of collision
|
|
51
|
+
LittleJS.setCameraPos(tileCollisionSize.scale(.5));
|
|
52
|
+
LittleJS.setCameraScale(32);
|
|
53
|
+
// enable gravity
|
|
54
|
+
LittleJS.setGravity(-.01);
|
|
55
|
+
// create particle emitter
|
|
56
|
+
particleEmitter = new LittleJS.ParticleEmitter(vec2(16, 9), 0, // emitPos, emitAngle
|
|
57
|
+
1, 0, 500, Math.PI, // emitSize, emitTime, emitRate, emitCone
|
|
58
|
+
tile(0, 16), // tileIndex, tileSize
|
|
59
|
+
hsl(1, 1, 1), hsl(0, 0, 0), // colorStartA, colorStartB
|
|
60
|
+
hsl(0, 0, 0, 0), hsl(0, 0, 0, 0), // colorEndA, colorEndB
|
|
61
|
+
2, .2, .2, .1, .05, // time, sizeStart, sizeEnd, speed, angleSpeed
|
|
62
|
+
.99, 1, 1, Math.PI, // damping, angleDamping, gravityScale, cone
|
|
63
|
+
.05, .5, true, true // fadeRate, randomness, collide, additive
|
|
64
|
+
);
|
|
65
|
+
particleEmitter.elasticity = .3; // bounce when it collides
|
|
66
|
+
particleEmitter.trailScale = 2; // stretch in direction of motion
|
|
67
|
+
}
|
|
68
|
+
///////////////////////////////////////////////////////////////////////////////
|
|
69
|
+
function gameUpdate() {
|
|
70
|
+
if (LittleJS.mouseWasPressed(0)) {
|
|
71
|
+
// play sound when mouse is pressed
|
|
72
|
+
sound_click.play(LittleJS.mousePos);
|
|
73
|
+
// change particle color and set to fade out
|
|
74
|
+
particleEmitter.colorStartA = hsl();
|
|
75
|
+
particleEmitter.colorStartB = LittleJS.randColor();
|
|
76
|
+
particleEmitter.colorEndA = particleEmitter.colorStartA.scale(1, 0);
|
|
77
|
+
particleEmitter.colorEndB = particleEmitter.colorStartB.scale(1, 0);
|
|
78
|
+
// unlock medals
|
|
79
|
+
medal_example.unlock();
|
|
80
|
+
}
|
|
81
|
+
// move particles to mouse location if on screen
|
|
82
|
+
if (LittleJS.mousePosScreen.x)
|
|
83
|
+
particleEmitter.pos = LittleJS.mousePos;
|
|
84
|
+
}
|
|
85
|
+
///////////////////////////////////////////////////////////////////////////////
|
|
86
|
+
function gameUpdatePost() {
|
|
87
|
+
}
|
|
88
|
+
///////////////////////////////////////////////////////////////////////////////
|
|
89
|
+
function gameRender() {
|
|
90
|
+
// draw a grey square in the background without using webgl
|
|
91
|
+
LittleJS.drawRect(vec2(16, 8), vec2(20, 14), hsl(0, 0, .6), 0, false);
|
|
92
|
+
// draw the logo as a tile
|
|
93
|
+
LittleJS.drawTile(vec2(21, 5), vec2(4.5), tile(3, 128));
|
|
94
|
+
}
|
|
95
|
+
///////////////////////////////////////////////////////////////////////////////
|
|
96
|
+
function gameRenderPost() {
|
|
97
|
+
// draw to overlay canvas for hud rendering
|
|
98
|
+
LittleJS.drawTextScreen('LittleJS with TypeScript', vec2(LittleJS.mainCanvasSize.x / 2, 80), 80);
|
|
99
|
+
}
|
|
100
|
+
///////////////////////////////////////////////////////////////////////////////
|
|
101
|
+
// Startup LittleJS Engine
|
|
102
|
+
LittleJS.engineInit(gameInit, gameUpdate, gameUpdatePost, gameRender, gameRenderPost, ['tiles.png']);
|
|
@@ -0,0 +1,33 @@
|
|
|
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!`);
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
/*
|
|
2
|
+
Little JS TypeScript Demo
|
|
3
|
+
- A simple starter project
|
|
4
|
+
- Shows how to use LittleJS with modules
|
|
5
|
+
*/
|
|
6
|
+
'use strict';
|
|
7
|
+
// import module
|
|
8
|
+
import * as LittleJS from '../../dist/littlejs.esm.js';
|
|
9
|
+
const { tile, vec2, hsl } = LittleJS;
|
|
10
|
+
// show the LittleJS splash screen
|
|
11
|
+
LittleJS.setShowSplashScreen(true);
|
|
12
|
+
// fix texture bleeding by shrinking tile slightly
|
|
13
|
+
LittleJS.setTileFixBleedScale(.5);
|
|
14
|
+
// sound effects
|
|
15
|
+
const sound_click = new LittleJS.Sound([1, .5]);
|
|
16
|
+
// medals
|
|
17
|
+
const medal_example = new LittleJS.Medal(0, 'Example Medal', 'Welcome to LittleJS!');
|
|
18
|
+
LittleJS.medalsInit('Hello World');
|
|
19
|
+
// game variables
|
|
20
|
+
let particleEmitter;
|
|
21
|
+
///////////////////////////////////////////////////////////////////////////////
|
|
22
|
+
function gameInit() {
|
|
23
|
+
// create tile collision and visible tile layer
|
|
24
|
+
const tileCollisionSize = vec2(32, 16);
|
|
25
|
+
LittleJS.initTileCollision(tileCollisionSize);
|
|
26
|
+
const pos = vec2();
|
|
27
|
+
const tileLayer = new LittleJS.TileLayer(pos, tileCollisionSize);
|
|
28
|
+
// get level data from the tiles image
|
|
29
|
+
const mainContext = LittleJS.mainContext;
|
|
30
|
+
const tileImage = LittleJS.textureInfos[0].image;
|
|
31
|
+
mainContext.drawImage(tileImage, 0, 0);
|
|
32
|
+
const imageData = mainContext.getImageData(0, 0, tileImage.width, tileImage.height).data;
|
|
33
|
+
for (pos.x = tileCollisionSize.x; pos.x--;)
|
|
34
|
+
for (pos.y = tileCollisionSize.y; pos.y--;) {
|
|
35
|
+
// check if this pixel is set
|
|
36
|
+
const i = pos.x + tileImage.width * (15 + tileCollisionSize.y - pos.y);
|
|
37
|
+
if (!imageData[4 * i])
|
|
38
|
+
continue;
|
|
39
|
+
// set tile data
|
|
40
|
+
const tileIndex = 1;
|
|
41
|
+
const direction = LittleJS.randInt(4);
|
|
42
|
+
const mirror = !LittleJS.randInt(2);
|
|
43
|
+
const color = LittleJS.randColor();
|
|
44
|
+
const data = new LittleJS.TileLayerData(tileIndex, direction, mirror, color);
|
|
45
|
+
tileLayer.setData(pos, data);
|
|
46
|
+
LittleJS.setTileCollisionData(pos, 1);
|
|
47
|
+
}
|
|
48
|
+
// draw tile layer with new data
|
|
49
|
+
tileLayer.redraw();
|
|
50
|
+
// move camera to center of collision
|
|
51
|
+
LittleJS.setCameraPos(tileCollisionSize.scale(.5));
|
|
52
|
+
LittleJS.setCameraScale(32);
|
|
53
|
+
// enable gravity
|
|
54
|
+
LittleJS.setGravity(-.01);
|
|
55
|
+
// create particle emitter
|
|
56
|
+
particleEmitter = new LittleJS.ParticleEmitter(vec2(16, 9), 0, // emitPos, emitAngle
|
|
57
|
+
1, 0, 500, Math.PI, // emitSize, emitTime, emitRate, emitCone
|
|
58
|
+
tile(0, 16), // tileIndex, tileSize
|
|
59
|
+
hsl(1, 1, 1), hsl(0, 0, 0), // colorStartA, colorStartB
|
|
60
|
+
hsl(0, 0, 0, 0), hsl(0, 0, 0, 0), // colorEndA, colorEndB
|
|
61
|
+
2, .2, .2, .1, .05, // time, sizeStart, sizeEnd, speed, angleSpeed
|
|
62
|
+
.99, 1, 1, Math.PI, // damping, angleDamping, gravityScale, cone
|
|
63
|
+
.05, .5, true, true // fadeRate, randomness, collide, additive
|
|
64
|
+
);
|
|
65
|
+
particleEmitter.elasticity = .3; // bounce when it collides
|
|
66
|
+
particleEmitter.trailScale = 2; // stretch in direction of motion
|
|
67
|
+
}
|
|
68
|
+
///////////////////////////////////////////////////////////////////////////////
|
|
69
|
+
function gameUpdate() {
|
|
70
|
+
if (LittleJS.mouseWasPressed(0)) {
|
|
71
|
+
// play sound when mouse is pressed
|
|
72
|
+
sound_click.play(LittleJS.mousePos);
|
|
73
|
+
// change particle color and set to fade out
|
|
74
|
+
particleEmitter.colorStartA = hsl();
|
|
75
|
+
particleEmitter.colorStartB = LittleJS.randColor();
|
|
76
|
+
particleEmitter.colorEndA = particleEmitter.colorStartA.scale(1, 0);
|
|
77
|
+
particleEmitter.colorEndB = particleEmitter.colorStartB.scale(1, 0);
|
|
78
|
+
// unlock medals
|
|
79
|
+
medal_example.unlock();
|
|
80
|
+
}
|
|
81
|
+
// move particles to mouse location if on screen
|
|
82
|
+
if (LittleJS.mousePosScreen.x)
|
|
83
|
+
particleEmitter.pos = LittleJS.mousePos;
|
|
84
|
+
}
|
|
85
|
+
///////////////////////////////////////////////////////////////////////////////
|
|
86
|
+
function gameUpdatePost() {
|
|
87
|
+
}
|
|
88
|
+
///////////////////////////////////////////////////////////////////////////////
|
|
89
|
+
function gameRender() {
|
|
90
|
+
// draw a grey square in the background without using webgl
|
|
91
|
+
LittleJS.drawRect(vec2(16, 8), vec2(20, 14), hsl(0, 0, .6), 0, false);
|
|
92
|
+
// draw the logo as a tile
|
|
93
|
+
LittleJS.drawTile(vec2(21, 5), vec2(4.5), tile(3, 128));
|
|
94
|
+
}
|
|
95
|
+
///////////////////////////////////////////////////////////////////////////////
|
|
96
|
+
function gameRenderPost() {
|
|
97
|
+
// draw to overlay canvas for hud rendering
|
|
98
|
+
LittleJS.drawTextScreen('LittleJS with TypeScript', vec2(LittleJS.mainCanvasSize.x / 2, 80), 80);
|
|
99
|
+
}
|
|
100
|
+
///////////////////////////////////////////////////////////////////////////////
|
|
101
|
+
// Startup LittleJS Engine
|
|
102
|
+
LittleJS.engineInit(gameInit, gameUpdate, gameUpdatePost, gameRender, gameRenderPost, ['tiles.png']);
|
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
/*
|
|
2
|
+
Little JS TypeScript Demo
|
|
3
|
+
- A simple starter project
|
|
4
|
+
- Shows how to use LittleJS with modules
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
'use strict';
|
|
8
|
+
|
|
9
|
+
// import module
|
|
10
|
+
import * as LittleJS from '../../dist/littlejs.esm.js';
|
|
11
|
+
const {tile, vec2, hsl} = LittleJS;
|
|
12
|
+
|
|
13
|
+
// show the LittleJS splash screen
|
|
14
|
+
LittleJS.setShowSplashScreen(true);
|
|
15
|
+
|
|
16
|
+
// fix texture bleeding by shrinking tile slightly
|
|
17
|
+
LittleJS.setTileFixBleedScale(.5);
|
|
18
|
+
|
|
19
|
+
// sound effects
|
|
20
|
+
const sound_click = new LittleJS.Sound([1,.5]);
|
|
21
|
+
|
|
22
|
+
// medals
|
|
23
|
+
const medal_example = new LittleJS.Medal(0, 'Example Medal', 'Welcome to LittleJS!');
|
|
24
|
+
LittleJS.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 tileCollisionSize = vec2(32, 16);
|
|
34
|
+
LittleJS.initTileCollision(tileCollisionSize);
|
|
35
|
+
const pos = vec2();
|
|
36
|
+
const tileLayer = new LittleJS.TileLayer(pos, tileCollisionSize);
|
|
37
|
+
|
|
38
|
+
// get level data from the tiles image
|
|
39
|
+
const mainContext = LittleJS.mainContext;
|
|
40
|
+
const tileImage = LittleJS.textureInfos[0].image;
|
|
41
|
+
mainContext.drawImage(tileImage, 0, 0);
|
|
42
|
+
const imageData = mainContext.getImageData(0,0,tileImage.width,tileImage.height).data;
|
|
43
|
+
for (pos.x = tileCollisionSize.x; pos.x--;)
|
|
44
|
+
for (pos.y = tileCollisionSize.y; pos.y--;)
|
|
45
|
+
{
|
|
46
|
+
// check if this pixel is set
|
|
47
|
+
const i = pos.x + tileImage.width*(15 + tileCollisionSize.y - pos.y);
|
|
48
|
+
if (!imageData[4*i])
|
|
49
|
+
continue;
|
|
50
|
+
|
|
51
|
+
// set tile data
|
|
52
|
+
const tileIndex = 1;
|
|
53
|
+
const direction = LittleJS.randInt(4)
|
|
54
|
+
const mirror = !LittleJS.randInt(2);
|
|
55
|
+
const color = LittleJS.randColor();
|
|
56
|
+
const data = new LittleJS.TileLayerData(tileIndex, direction, mirror, color);
|
|
57
|
+
tileLayer.setData(pos, data);
|
|
58
|
+
LittleJS.setTileCollisionData(pos, 1);
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
// draw tile layer with new data
|
|
62
|
+
tileLayer.redraw();
|
|
63
|
+
|
|
64
|
+
// move camera to center of collision
|
|
65
|
+
LittleJS.setCameraPos(tileCollisionSize.scale(.5));
|
|
66
|
+
LittleJS.setCameraScale(32);
|
|
67
|
+
|
|
68
|
+
// enable gravity
|
|
69
|
+
LittleJS.setGravity(-.01);
|
|
70
|
+
|
|
71
|
+
// create particle emitter
|
|
72
|
+
particleEmitter = new LittleJS.ParticleEmitter(
|
|
73
|
+
vec2(16,9), 0, // emitPos, emitAngle
|
|
74
|
+
1, 0, 500, Math.PI, // emitSize, emitTime, emitRate, emitCone
|
|
75
|
+
tile(0, 16), // tileIndex, tileSize
|
|
76
|
+
hsl(1,1,1), hsl(0,0,0), // colorStartA, colorStartB
|
|
77
|
+
hsl(0,0,0,0), hsl(0,0,0,0), // colorEndA, colorEndB
|
|
78
|
+
2, .2, .2, .1, .05, // time, sizeStart, sizeEnd, speed, angleSpeed
|
|
79
|
+
.99, 1, 1, Math.PI, // damping, angleDamping, gravityScale, cone
|
|
80
|
+
.05, .5, true, true // fadeRate, randomness, collide, additive
|
|
81
|
+
);
|
|
82
|
+
particleEmitter.elasticity = .3; // bounce when it collides
|
|
83
|
+
particleEmitter.trailScale = 2; // stretch in direction of motion
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
///////////////////////////////////////////////////////////////////////////////
|
|
87
|
+
function gameUpdate()
|
|
88
|
+
{
|
|
89
|
+
if (LittleJS.mouseWasPressed(0))
|
|
90
|
+
{
|
|
91
|
+
// play sound when mouse is pressed
|
|
92
|
+
sound_click.play(LittleJS.mousePos);
|
|
93
|
+
|
|
94
|
+
// change particle color and set to fade out
|
|
95
|
+
particleEmitter.colorStartA = hsl();
|
|
96
|
+
particleEmitter.colorStartB = LittleJS.randColor();
|
|
97
|
+
particleEmitter.colorEndA = particleEmitter.colorStartA.scale(1,0);
|
|
98
|
+
particleEmitter.colorEndB = particleEmitter.colorStartB.scale(1,0);
|
|
99
|
+
|
|
100
|
+
// unlock medals
|
|
101
|
+
medal_example.unlock();
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
// move particles to mouse location if on screen
|
|
105
|
+
if (LittleJS.mousePosScreen.x)
|
|
106
|
+
particleEmitter.pos = LittleJS.mousePos;
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
///////////////////////////////////////////////////////////////////////////////
|
|
110
|
+
function gameUpdatePost()
|
|
111
|
+
{
|
|
112
|
+
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
///////////////////////////////////////////////////////////////////////////////
|
|
116
|
+
function gameRender()
|
|
117
|
+
{
|
|
118
|
+
// draw a grey square in the background without using webgl
|
|
119
|
+
LittleJS.drawRect(vec2(16,8), vec2(20,14), hsl(0,0,.6), 0, false);
|
|
120
|
+
|
|
121
|
+
// draw the logo as a tile
|
|
122
|
+
LittleJS.drawTile(vec2(21,5), vec2(4.5), tile(3,128));
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
///////////////////////////////////////////////////////////////////////////////
|
|
126
|
+
function gameRenderPost()
|
|
127
|
+
{
|
|
128
|
+
// draw to overlay canvas for hud rendering
|
|
129
|
+
LittleJS.drawTextScreen('LittleJS with TypeScript', vec2(LittleJS.mainCanvasSize.x/2, 80), 80);
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
///////////////////////////////////////////////////////////////////////////////
|
|
133
|
+
// Startup LittleJS Engine
|
|
134
|
+
LittleJS.engineInit(gameInit, gameUpdate, gameUpdatePost, gameRender, gameRenderPost, ['tiles.png']);
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
<!DOCTYPE html><head>
|
|
2
|
+
<title>LittleJS TypeScript 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
|
package/package.json
CHANGED
package/plugins/newgrounds.js
CHANGED
|
@@ -10,12 +10,26 @@
|
|
|
10
10
|
|
|
11
11
|
'use strict';
|
|
12
12
|
|
|
13
|
-
|
|
13
|
+
/** Global Newgrounds object
|
|
14
|
+
* @type {Newgrounds}
|
|
15
|
+
* @memberof Medal */
|
|
16
|
+
let newgrounds;
|
|
14
17
|
|
|
15
|
-
|
|
18
|
+
///////////////////////////////////////////////////////////////////////////////
|
|
19
|
+
/**
|
|
20
|
+
* Newgrounds medal auto unlocks in newgrounds API
|
|
21
|
+
* Particle Emitter - Spawns particles with the given settings
|
|
22
|
+
* @extends Medal
|
|
23
|
+
*/
|
|
16
24
|
class NewgroundsMedal extends Medal
|
|
17
25
|
{
|
|
18
|
-
/** Create a medal object and adds it to the list of medals
|
|
26
|
+
/** Create a newgrounds medal object and adds it to the list of medals
|
|
27
|
+
* @param {Number} id - The unique identifier of the medal
|
|
28
|
+
* @param {String} name - Name of the medal
|
|
29
|
+
* @param {String} [description] - Description of the medal
|
|
30
|
+
* @param {String} [icon] - Icon for the medal
|
|
31
|
+
* @param {String} [src] - Image location for the medal
|
|
32
|
+
*/
|
|
19
33
|
constructor(id, name, description, icon, src)
|
|
20
34
|
{ super(id, name, description, icon, src); }
|
|
21
35
|
|
|
@@ -28,36 +42,26 @@ class NewgroundsMedal extends Medal
|
|
|
28
42
|
}
|
|
29
43
|
|
|
30
44
|
///////////////////////////////////////////////////////////////////////////////
|
|
31
|
-
|
|
32
|
-
/** Global Newgrounds object */
|
|
33
|
-
let newgrounds;
|
|
34
|
-
|
|
35
|
-
/** This can used to enable Newgrounds functionality
|
|
36
|
-
* @param {Number} app_id - The newgrounds App ID
|
|
37
|
-
* @param {String} [cipher] - The encryption Key (AES-128/Base64)
|
|
38
|
-
* @param {Object} [cryptoJS] - An instance of CryptoJS, if there is a cipher
|
|
39
|
-
* @memberof Medals */
|
|
40
|
-
function newgroundsInit(app_id, cipher, cryptoJS)
|
|
41
|
-
{ newgrounds = new Newgrounds(app_id, cipher, cryptoJS); }
|
|
42
|
-
|
|
43
45
|
/**
|
|
44
|
-
* Newgrounds API
|
|
45
|
-
* @example
|
|
46
|
-
* // create a newgrounds object, replace the app id with your own
|
|
47
|
-
* const app_id = '52123:1ZuSTQ7l';
|
|
48
|
-
* newgrounds = new Newgrounds(app_id);
|
|
46
|
+
* Newgrounds API object
|
|
49
47
|
*/
|
|
50
48
|
class Newgrounds
|
|
51
49
|
{
|
|
52
|
-
/** Create
|
|
53
|
-
* @param {
|
|
54
|
-
* @param {
|
|
55
|
-
* @param {Object} [cryptoJS] - An instance of CryptoJS, if there is a cipher
|
|
50
|
+
/** Create the global newgrounds object
|
|
51
|
+
* @param {string} app_id - The newgrounds App ID
|
|
52
|
+
* @param {string} [cipher] - The encryption Key (AES-128/Base64)
|
|
53
|
+
* @param {Object} [cryptoJS] - An instance of CryptoJS, if there is a cipher
|
|
54
|
+
* @example
|
|
55
|
+
* // create the newgrounds object, replace the app id with your own
|
|
56
|
+
* const app_id = 'your_app_id_here';
|
|
57
|
+
* new Newgrounds(app_id);
|
|
58
|
+
*/
|
|
56
59
|
constructor(app_id, cipher, cryptoJS)
|
|
57
60
|
{
|
|
58
61
|
ASSERT(!newgrounds, 'there can only be one newgrounds object');
|
|
59
62
|
ASSERT(!cipher || cryptoJS, 'must provide cryptojs if there is a cipher');
|
|
60
63
|
|
|
64
|
+
newgrounds = this; // set global newgrounds object
|
|
61
65
|
this.app_id = app_id;
|
|
62
66
|
this.cipher = cipher;
|
|
63
67
|
this.cryptoJS = cryptoJS;
|
|
@@ -104,20 +108,20 @@ class Newgrounds
|
|
|
104
108
|
}
|
|
105
109
|
|
|
106
110
|
/** Send message to unlock a medal by id
|
|
107
|
-
* @param {
|
|
111
|
+
* @param {number} id - The medal id */
|
|
108
112
|
unlockMedal(id) { return this.call('Medal.unlock', {'id':id}, true); }
|
|
109
113
|
|
|
110
114
|
/** Send message to post score
|
|
111
|
-
* @param {
|
|
112
|
-
* @param {
|
|
115
|
+
* @param {number} id - The scoreboard id
|
|
116
|
+
* @param {number} value - The score value */
|
|
113
117
|
postScore(id, value) { return this.call('ScoreBoard.postScore', {'id':id, 'value':value}, true); }
|
|
114
118
|
|
|
115
119
|
/** Get scores from a scoreboard
|
|
116
|
-
* @param {
|
|
117
|
-
* @param {
|
|
118
|
-
* @param {
|
|
119
|
-
* @param {
|
|
120
|
-
* @param {
|
|
120
|
+
* @param {number} id - The scoreboard id
|
|
121
|
+
* @param {string} [user] - A user's id or name
|
|
122
|
+
* @param {number} [social] - If true, only social scores will be loaded
|
|
123
|
+
* @param {number} [skip] - Number of scores to skip before start
|
|
124
|
+
* @param {number} [limit] - Number of scores to include in the list
|
|
121
125
|
* @return {Object} - The response JSON object
|
|
122
126
|
*/
|
|
123
127
|
getScores(id, user, social=0, skip=0, limit=10)
|
|
@@ -127,9 +131,9 @@ class Newgrounds
|
|
|
127
131
|
logView() { return this.call('App.logView', {'host':this.host}, true); }
|
|
128
132
|
|
|
129
133
|
/** Send a message to call a component of the Newgrounds API
|
|
130
|
-
* @param {
|
|
134
|
+
* @param {string} component - Name of the component
|
|
131
135
|
* @param {Object} [parameters] - Parameters to use for call
|
|
132
|
-
* @param {
|
|
136
|
+
* @param {boolean} [async] - If true, don't wait for response before continuing
|
|
133
137
|
* @return {Object} - The response JSON object
|
|
134
138
|
*/
|
|
135
139
|
call(component, parameters, async=false)
|
|
@@ -162,7 +166,12 @@ class Newgrounds
|
|
|
162
166
|
const xmlHttp = new XMLHttpRequest();
|
|
163
167
|
const url = 'https://newgrounds.io/gateway_v3.php';
|
|
164
168
|
xmlHttp.open('POST', url, !debugMedals && async);
|
|
165
|
-
xmlHttp.send(formData);
|
|
169
|
+
try { xmlHttp.send(formData); }
|
|
170
|
+
catch(e)
|
|
171
|
+
{
|
|
172
|
+
debugMedals && console.log('newgrounds call failed', e);
|
|
173
|
+
return;
|
|
174
|
+
}
|
|
166
175
|
debugMedals && console.log(xmlHttp.responseText);
|
|
167
176
|
return xmlHttp.responseText && JSON.parse(xmlHttp.responseText);
|
|
168
177
|
}
|
package/plugins/postProcess.js
CHANGED
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
* LittleJS Post Processing Plugin
|
|
3
3
|
* - Supports shadertoy style post processing shaders
|
|
4
4
|
* - call initPostProcess to set it up
|
|
5
|
+
* @namespace PostProcessPlugin
|
|
5
6
|
*/
|
|
6
7
|
|
|
7
8
|
'use strict';
|
|
@@ -9,12 +10,25 @@
|
|
|
9
10
|
///////////////////////////////////////////////////////////////////////////////
|
|
10
11
|
// post processing - can be enabled to pass other canvases through a final shader
|
|
11
12
|
|
|
12
|
-
|
|
13
|
+
/** Shader for post processing
|
|
14
|
+
* @type {WebGLProgram}
|
|
15
|
+
* @memberof PostProcessPlugin */
|
|
16
|
+
let glPostShader;
|
|
17
|
+
|
|
18
|
+
/** Texture for post processing
|
|
19
|
+
* @type {WebGLTexture}
|
|
20
|
+
* @memberof PostProcessPlugin */
|
|
21
|
+
let glPostTexture;
|
|
22
|
+
|
|
23
|
+
/** Should overlay canvas be included in post processing
|
|
24
|
+
* @type {boolean}
|
|
25
|
+
* @memberof PostProcessPlugin */
|
|
26
|
+
let glPostIncludeOverlay;
|
|
13
27
|
|
|
14
28
|
/** Set up a post processing shader
|
|
15
|
-
* @param {
|
|
16
|
-
* @param {
|
|
17
|
-
* @memberof
|
|
29
|
+
* @param {string} shaderCode
|
|
30
|
+
* @param {boolean} [includeOverlay]
|
|
31
|
+
* @memberof PostProcessPlugin */
|
|
18
32
|
function initPostProcess(shaderCode, includeOverlay=false)
|
|
19
33
|
{
|
|
20
34
|
ASSERT(!glPostShader, 'can only have 1 post effects shader');
|