littlejsengine 1.11.2 → 1.11.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.
Files changed (56) hide show
  1. package/.vscode/launch.json +14 -0
  2. package/README.md +14 -20
  3. package/dist/littlejs.d.ts +41 -30
  4. package/dist/littlejs.esm.js +145 -141
  5. package/dist/littlejs.esm.min.js +1 -1
  6. package/dist/littlejs.js +141 -140
  7. package/dist/littlejs.min.js +1 -1
  8. package/dist/littlejs.release.js +138 -133
  9. package/examples/box2d/gameObjects.js +4 -4
  10. package/examples/box2d/scenes.js +2 -2
  11. package/examples/breakout/gameObjects.js +2 -2
  12. package/examples/breakoutTutorial/game.js +1 -1
  13. package/examples/index.html +1 -7
  14. package/examples/logo.png +0 -0
  15. package/examples/module/game.js +1 -1
  16. package/examples/platformer/game.js +2 -2
  17. package/examples/platformer/gameCharacter.js +5 -5
  18. package/examples/platformer/gameEffects.js +4 -4
  19. package/examples/platformer/gameObjects.js +2 -2
  20. package/examples/puzzle/game.js +2 -2
  21. package/examples/starter/game.js +10 -44
  22. package/examples/starter/tiles.png +0 -0
  23. package/jsconfig.json +1 -0
  24. package/package.json +1 -1
  25. package/plugins/box2d.js +10 -10
  26. package/plugins/newgrounds.js +1 -1
  27. package/src/engine.js +5 -3
  28. package/src/engineAudio.js +4 -4
  29. package/src/engineDebug.js +3 -7
  30. package/src/engineDraw.js +50 -25
  31. package/src/engineExport.js +4 -1
  32. package/src/engineInput.js +1 -1
  33. package/src/engineObject.js +8 -8
  34. package/src/engineParticles.js +6 -6
  35. package/src/engineSettings.js +5 -5
  36. package/src/engineTileLayer.js +2 -2
  37. package/src/engineUtilities.js +5 -5
  38. package/src/engineWebGL.js +52 -74
  39. package/examples/electron/build.js +0 -107
  40. package/examples/electron/electron.js +0 -43
  41. package/examples/electron/game.js +0 -131
  42. package/examples/electron/index.html +0 -13
  43. package/examples/electron/package.json +0 -22
  44. package/examples/electron/tiles.png +0 -0
  45. package/examples/js13k/build.bat +0 -2
  46. package/examples/js13k/build.js +0 -131
  47. package/examples/js13k/game.js +0 -118
  48. package/examples/js13k/index.html +0 -21
  49. package/examples/js13k/tiles.png +0 -0
  50. package/examples/typescript/build.bat +0 -5
  51. package/examples/typescript/build.js +0 -33
  52. package/examples/typescript/game.js +0 -102
  53. package/examples/typescript/game.ts +0 -134
  54. package/examples/typescript/index.html +0 -10
  55. package/examples/typescript/tiles.png +0 -0
  56. package/examples/typescript/tsconfig.json +0 -8
@@ -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
@@ -1,2 +0,0 @@
1
- rem LittleJS Build Script
2
- call node build.js
@@ -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
- };
@@ -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>
Binary file
@@ -1,5 +0,0 @@
1
- rem LittleJS Build Script
2
- call node build.js
3
-
4
- @echo off
5
- if %ERRORLEVEL% neq 0 ( pause )
@@ -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!`);
@@ -1,102 +0,0 @@
1
- /*
2
- Little JS TypeScript Demo
3
- - A simple starter project
4
- - Shows how to use LittleJS with TypeScript
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(48);
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, emiteCone
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']);