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.
Files changed (172) hide show
  1. package/COPYRIGHT.txt +38 -0
  2. package/FAQ.md +633 -0
  3. package/LICENSE +5 -27
  4. package/README.md +19 -1
  5. package/dist/littlejs.d.ts +550 -57
  6. package/dist/littlejs.esm.js +2208 -492
  7. package/dist/littlejs.esm.min.js +1 -1
  8. package/dist/littlejs.js +2165 -480
  9. package/dist/littlejs.min.js +1 -1
  10. package/dist/littlejs.release.js +2166 -481
  11. package/package.json +8 -1
  12. package/plugins/box2d.js +36 -9
  13. package/{src/engineMedals.js → plugins/medalSystem.js} +248 -196
  14. package/plugins/pathFinder.js +758 -0
  15. package/plugins/pluginExport.js +26 -0
  16. package/plugins/tween.js +509 -0
  17. package/plugins/tweenSystem.js +509 -0
  18. package/plugins/uiSystem.js +151 -12
  19. package/src/engine.js +9 -145
  20. package/src/engineAudio.js +8 -5
  21. package/src/engineBuild.mjs +4 -1
  22. package/src/engineDebug.js +1 -1
  23. package/src/engineDraw.js +154 -5
  24. package/src/engineExport.js +17 -12
  25. package/src/engineInput.js +27 -1
  26. package/src/engineLogo.js +146 -0
  27. package/src/engineMath.js +10 -3
  28. package/src/engineObject.js +11 -5
  29. package/src/engineParticles.js +6 -3
  30. package/src/engineRelease.js +1 -1
  31. package/src/engineSettings.js +17 -47
  32. package/src/engineUtilities.js +7 -2
  33. package/src/engineWebGL.js +31 -8
  34. package/src/jsconfig.json +3 -1
  35. package/.claude/settings.local.json +0 -7
  36. package/.github/workflows/test.yml +0 -17
  37. package/AI.md +0 -172
  38. package/CLAUDE.md +0 -1
  39. package/examples/box2d/game.js +0 -192
  40. package/examples/box2d/gameObjects.js +0 -564
  41. package/examples/box2d/index.html +0 -9
  42. package/examples/box2d/scenes.js +0 -194
  43. package/examples/box2d/tiles.png +0 -0
  44. package/examples/breakout/game.js +0 -175
  45. package/examples/breakout/gameObjects.js +0 -147
  46. package/examples/breakout/index.html +0 -8
  47. package/examples/breakout/tiles.png +0 -0
  48. package/examples/breakoutTutorial/README.md +0 -521
  49. package/examples/breakoutTutorial/game.js +0 -191
  50. package/examples/breakoutTutorial/images/1.png +0 -0
  51. package/examples/breakoutTutorial/images/10.png +0 -0
  52. package/examples/breakoutTutorial/images/11.png +0 -0
  53. package/examples/breakoutTutorial/images/2.png +0 -0
  54. package/examples/breakoutTutorial/images/3.png +0 -0
  55. package/examples/breakoutTutorial/images/4.png +0 -0
  56. package/examples/breakoutTutorial/images/5.png +0 -0
  57. package/examples/breakoutTutorial/images/6.png +0 -0
  58. package/examples/breakoutTutorial/images/7.png +0 -0
  59. package/examples/breakoutTutorial/images/8.png +0 -0
  60. package/examples/breakoutTutorial/images/9.png +0 -0
  61. package/examples/breakoutTutorial/index.html +0 -8
  62. package/examples/electron/build.mjs +0 -127
  63. package/examples/electron/electron.js +0 -35
  64. package/examples/electron/game.js +0 -54
  65. package/examples/electron/index.html +0 -13
  66. package/examples/electron/package.json +0 -5
  67. package/examples/electron/tiles.png +0 -0
  68. package/examples/empty/game.js +0 -51
  69. package/examples/empty/index.html +0 -5
  70. package/examples/empty/tiles.png +0 -0
  71. package/examples/favicon.png +0 -0
  72. package/examples/games.jpg +0 -0
  73. package/examples/htmlMenu/game.js +0 -82
  74. package/examples/htmlMenu/index.html +0 -45
  75. package/examples/htmlMenu/tiles.png +0 -0
  76. package/examples/index.html +0 -800
  77. package/examples/logo.png +0 -0
  78. package/examples/logo2.png +0 -0
  79. package/examples/module/build.mjs +0 -124
  80. package/examples/module/game.js +0 -132
  81. package/examples/module/index.html +0 -10
  82. package/examples/module/tiles.png +0 -0
  83. package/examples/particles/index.html +0 -426
  84. package/examples/particles/tiles.png +0 -0
  85. package/examples/platformer/data/gameLevelData.tmx +0 -143
  86. package/examples/platformer/data/gameLevelData.tsx +0 -4
  87. package/examples/platformer/game.js +0 -147
  88. package/examples/platformer/gameCharacter.js +0 -309
  89. package/examples/platformer/gameEffects.js +0 -278
  90. package/examples/platformer/gameLevel.js +0 -205
  91. package/examples/platformer/gameLevelData.json +0 -171
  92. package/examples/platformer/gameObjects.js +0 -378
  93. package/examples/platformer/gamePlayer.js +0 -35
  94. package/examples/platformer/index.html +0 -9
  95. package/examples/platformer/tiles.png +0 -0
  96. package/examples/platformer/tilesLevel.png +0 -0
  97. package/examples/puzzle/game.js +0 -331
  98. package/examples/puzzle/index.html +0 -8
  99. package/examples/puzzle/tiles.png +0 -0
  100. package/examples/screenshot.jpg +0 -0
  101. package/examples/shorts/animation.js +0 -18
  102. package/examples/shorts/base.html +0 -54
  103. package/examples/shorts/blending.js +0 -14
  104. package/examples/shorts/box2d.js +0 -51
  105. package/examples/shorts/box2dCar.js +0 -59
  106. package/examples/shorts/box2dPool.js +0 -107
  107. package/examples/shorts/box2dTileLayer.js +0 -48
  108. package/examples/shorts/cameraDrag.js +0 -22
  109. package/examples/shorts/clock.js +0 -21
  110. package/examples/shorts/colors.js +0 -25
  111. package/examples/shorts/debugDraw.js +0 -37
  112. package/examples/shorts/empty.js +0 -30
  113. package/examples/shorts/flappyGame.js +0 -55
  114. package/examples/shorts/fontImage.js +0 -17
  115. package/examples/shorts/fps.js +0 -90
  116. package/examples/shorts/helloWorld.js +0 -11
  117. package/examples/shorts/hillGlideGame.js +0 -63
  118. package/examples/shorts/input.js +0 -64
  119. package/examples/shorts/landerGame.js +0 -57
  120. package/examples/shorts/maze.js +0 -48
  121. package/examples/shorts/medals.js +0 -51
  122. package/examples/shorts/music.js +0 -78
  123. package/examples/shorts/musicPlayer.js +0 -137
  124. package/examples/shorts/nineSlice.js +0 -40
  125. package/examples/shorts/parallax.js +0 -72
  126. package/examples/shorts/particles.js +0 -28
  127. package/examples/shorts/piano.js +0 -44
  128. package/examples/shorts/platformer.js +0 -45
  129. package/examples/shorts/pongGame.js +0 -41
  130. package/examples/shorts/postProcess.js +0 -62
  131. package/examples/shorts/sequencer.js +0 -124
  132. package/examples/shorts/shader.js +0 -29
  133. package/examples/shorts/shapes.js +0 -21
  134. package/examples/shorts/slidingPuzzle.js +0 -52
  135. package/examples/shorts/song.mp3 +0 -0
  136. package/examples/shorts/sound.js +0 -36
  137. package/examples/shorts/spaceGame.js +0 -58
  138. package/examples/shorts/spriteAtlas.js +0 -31
  139. package/examples/shorts/starfield.js +0 -15
  140. package/examples/shorts/texture.js +0 -16
  141. package/examples/shorts/tileLayer.js +0 -48
  142. package/examples/shorts/tileRaycast.js +0 -39
  143. package/examples/shorts/tiles.png +0 -0
  144. package/examples/shorts/tiltedView.js +0 -63
  145. package/examples/shorts/timers.js +0 -53
  146. package/examples/shorts/topDown.js +0 -38
  147. package/examples/shorts/uiSystem.js +0 -61
  148. package/examples/shorts/video.webm +0 -0
  149. package/examples/shorts/videoPlayer.js +0 -34
  150. package/examples/starter/build.bat +0 -7
  151. package/examples/starter/build.mjs +0 -126
  152. package/examples/starter/game.js +0 -137
  153. package/examples/starter/index.html +0 -35
  154. package/examples/starter/tiles.png +0 -0
  155. package/examples/stress/index.html +0 -173
  156. package/examples/style.css +0 -150
  157. package/examples/typescript/build.mjs +0 -60
  158. package/examples/typescript/game.js +0 -100
  159. package/examples/typescript/game.ts +0 -132
  160. package/examples/typescript/index.html +0 -10
  161. package/examples/typescript/tiles.png +0 -0
  162. package/examples/typescript/tsconfig.json +0 -17
  163. package/examples/uiSystem/game.js +0 -139
  164. package/examples/uiSystem/index.html +0 -10
  165. package/examples/uiSystem/tiles.png +0 -0
  166. package/jsconfig.json +0 -12
  167. package/plugins/desktop.ini +0 -2
  168. package/reference.md +0 -447
  169. package/test/math.test.mjs +0 -774
  170. package/test/setup.mjs +0 -22
  171. package/test/smoke.test.mjs +0 -258
  172. package/test/util.test.mjs +0 -80
@@ -1,60 +0,0 @@
1
- /**
2
- * LittleJS TypeScript Example 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
- const PROGRAM_NAME = 'game';
14
- const BUILD_FOLDER = join(__dirname, 'build');
15
-
16
- // Define TypeScript source files
17
- const tsSourceFiles = [
18
- 'game.ts',
19
- // add your TypeScript files here
20
- ];
21
-
22
- // Corresponding JS output files
23
- const jsSourceFiles = tsSourceFiles.map(file => file.replace('.ts', '.js'));
24
-
25
- console.log(`Building TypeScript for ${PROGRAM_NAME}...`);
26
- const startTime = Date.now();
27
-
28
- console.log(`Removing old build folder...`);
29
- fs.rmSync(BUILD_FOLDER, { recursive: true, force: true });
30
-
31
- console.log(`Compiling TypeScript...`);
32
-
33
- // Use tsconfig.json for compilation settings
34
- try
35
- {
36
- const result = execSync(`npx -p typescript tsc`, {cwd: __dirname, encoding: 'utf8', stdio: 'pipe'});
37
- console.log(result);
38
- } catch (error)
39
- {
40
- console.error('TypeScript compilation errors:');
41
- if (error.stdout) console.log(error.stdout);
42
- if (error.stderr) console.error(error.stderr);
43
- console.error('TypeScript compilation failed!');
44
- process.exit(1);
45
- }
46
-
47
- console.log(`Copying js files back to root...`);
48
- for (const file of jsSourceFiles)
49
- {
50
- // TypeScript outputs to build/examples/typescript/ because of relative paths
51
- const buildFile = join(BUILD_FOLDER, 'examples', 'typescript', file);
52
- const targetFile = join(__dirname, file);
53
- console.log(`Copying ${file}...`);
54
- if (fs.existsSync(buildFile))
55
- fs.copyFileSync(buildFile, targetFile);
56
- else
57
- console.error(`✗ Build file not found: ${buildFile}`);
58
- }
59
-
60
- console.log(`TypeScript built in ${((Date.now() - startTime)/1e3).toFixed(2)} seconds!`);
@@ -1,100 +0,0 @@
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 LittleJS module
8
- import * as LJS from '../../dist/littlejs.esm.js';
9
- const { tile, vec2, hsl } = LJS;
10
- // show the LittleJS splash screen
11
- LJS.setShowSplashScreen(true);
12
- // fix texture bleeding by shrinking tile slightly
13
- LJS.setTileDefaultBleed(.5);
14
- // sound effects
15
- const sound_click = new LJS.Sound([1, .5]);
16
- // medals
17
- const medal_example = new LJS.Medal(0, 'Example Medal', 'Welcome to LittleJS!');
18
- LJS.medalsInit('Hello World');
19
- // game variables
20
- let particleEmitter;
21
- ///////////////////////////////////////////////////////////////////////////////
22
- function gameInit() {
23
- // create tile collision and visible tile layer
24
- const pos = vec2();
25
- const tileLayer = new LJS.TileCollisionLayer(pos, vec2(32, 16));
26
- // get level data from the tiles image
27
- const mainContext = LJS.mainContext;
28
- const tileImage = LJS.textureInfos[0].image;
29
- mainContext.drawImage(tileImage, 0, 0);
30
- const imageData = mainContext.getImageData(0, 0, tileImage.width, tileImage.height).data;
31
- for (pos.x = tileLayer.size.x; pos.x--;)
32
- for (pos.y = tileLayer.size.y; pos.y--;) {
33
- // check if this pixel is set
34
- const i = pos.x + tileImage.width * (15 + tileLayer.size.y - pos.y);
35
- if (!imageData[4 * i])
36
- continue;
37
- // set tile data
38
- const tileIndex = 1;
39
- const direction = LJS.randInt(4);
40
- const mirror = !LJS.randInt(2);
41
- const color = LJS.randColor();
42
- const data = new LJS.TileLayerData(tileIndex, direction, mirror, color);
43
- tileLayer.setData(pos, data);
44
- tileLayer.setCollisionData(pos);
45
- }
46
- // draw tile layer with new data
47
- tileLayer.redraw();
48
- // move camera to center of collision
49
- LJS.setCameraPos(tileLayer.size.scale(.5));
50
- LJS.setCameraScale(32);
51
- // enable gravity
52
- LJS.setGravity(vec2(0, -.01));
53
- // create particle emitter
54
- particleEmitter = new LJS.ParticleEmitter(vec2(16, 9), 0, // emitPos, emitAngle
55
- 0, 0, 500, 3.14, // emitSize, emitTime, rate, cone
56
- tile(0, 16), // tileIndex, tileSize
57
- hsl(1, 1, 1), hsl(0, 0, 0), // colorStartA, colorStartB
58
- hsl(0, 0, 0, 0), hsl(0, 0, 0, 0), // colorEndA, colorEndB
59
- 1, .2, .2, .1, .05, // time, sizeStart, sizeEnd, speed, angleSpeed
60
- .99, 1, 1, 3.14, // damping, angleDamping, gravityScale, cone
61
- .05, .5, true, true // fadeRate, randomness, collide, additive
62
- );
63
- particleEmitter.restitution = .3; // bounce when it collides
64
- particleEmitter.trailScale = 2; // stretch stretch as it moves
65
- particleEmitter.velocityInheritance = .3; // inherit emitter velocity
66
- }
67
- ///////////////////////////////////////////////////////////////////////////////
68
- function gameUpdate() {
69
- if (LJS.mouseWasPressed(0)) {
70
- // play sound when mouse is pressed
71
- sound_click.play(LJS.mousePos);
72
- // change particle color and set to fade out
73
- particleEmitter.colorStartA = LJS.randColor();
74
- particleEmitter.colorStartB = LJS.randColor();
75
- particleEmitter.colorEndA = particleEmitter.colorStartA.scale(1, 0);
76
- particleEmitter.colorEndB = particleEmitter.colorStartB.scale(1, 0);
77
- // unlock medals
78
- medal_example.unlock();
79
- }
80
- // move particles to mouse location if on screen
81
- if (LJS.mousePosScreen.x)
82
- particleEmitter.pos = LJS.mousePos;
83
- }
84
- ///////////////////////////////////////////////////////////////////////////////
85
- function gameUpdatePost() {
86
- }
87
- ///////////////////////////////////////////////////////////////////////////////
88
- function gameRender() {
89
- // draw a grey square in the background
90
- LJS.drawRect(vec2(16, 8), vec2(20, 14), hsl(0, 0, .6));
91
- // draw the logo as a tile
92
- LJS.drawTile(vec2(21, 5), vec2(4.5), tile(3, 128));
93
- }
94
- ///////////////////////////////////////////////////////////////////////////////
95
- function gameRenderPost() {
96
- LJS.drawTextScreen('LittleJS with TypeScript', vec2(LJS.mainCanvasSize.x / 2, 80), 80);
97
- }
98
- ///////////////////////////////////////////////////////////////////////////////
99
- // Startup LittleJS Engine
100
- LJS.engineInit(gameInit, gameUpdate, gameUpdatePost, gameRender, gameRenderPost, ['tiles.png']);
@@ -1,132 +0,0 @@
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 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 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 TypeScript', 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 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
@@ -1,17 +0,0 @@
1
- {
2
- "compilerOptions": {
3
- "allowJs": true,
4
- "module": "es2020",
5
- "target": "es2020",
6
- "outDir": "build",
7
- "moduleResolution": "bundler",
8
- "skipLibCheck": true
9
- },
10
- "include": [
11
- "*.ts"
12
- ],
13
- "exclude": [
14
- "node_modules",
15
- "build"
16
- ]
17
- }
@@ -1,139 +0,0 @@
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
- // import LittleJS module
10
- import * as LJS from '../../dist/littlejs.esm.js';
11
- const {vec2, hsl, tile} = LJS;
12
-
13
- // UI system
14
- let uiRoot, uiMenu;
15
- const getMenuVisible =()=> uiMenu.visible;
16
- const setMenuVisible =(visible)=> uiMenu.visible = visible;
17
-
18
- // use a fixed size canvas
19
- LJS.setCanvasFixedSize(vec2(1920, 1080)); // 1080p
20
- LJS.setCanvasPixelated(false);
21
-
22
- function createUI()
23
- {
24
- LJS.uiSystem.defaultSoundPress = new LJS.Sound([.5,0,220]);
25
- LJS.uiSystem.defaultSoundClick = new LJS.Sound([.5,0,440]);
26
- LJS.uiSystem.defaultCornerRadius = 8;
27
- LJS.uiSystem.defaultGradientColor = LJS.WHITE;
28
- LJS.uiSystem.defaultShadowColor = LJS.BLACK;
29
-
30
- // setup root to attach all ui elements to
31
- uiRoot = new LJS.UIObject;
32
- const uiInfo = new LJS.UIText(vec2(0,90), vec2(1e3, 70),
33
- 'LittleJS UI System Example\nM = Toggle menu');
34
- uiInfo.textColor = LJS.WHITE;
35
- uiInfo.textLineWidth = 8;
36
- uiRoot.addChild(uiInfo);
37
-
38
- // setup example menu
39
- uiMenu = new LJS.UIObject(vec2(0,500));
40
- uiRoot.addChild(uiMenu);
41
- const uiBackground = new LJS.UIObject(vec2(), vec2(450,580));
42
- uiBackground.lineWidth = 8;
43
- uiMenu.addChild(uiBackground);
44
-
45
- // example large text
46
- const textTitle = new LJS.UIText(vec2(0,-220), vec2(400, 120), 'Test Title');
47
- uiMenu.addChild(textTitle);
48
- textTitle.textColor = LJS.RED;
49
- textTitle.textLineColor = LJS.BLUE;
50
- textTitle.textLineWidth = 4;
51
-
52
- // example multiline text
53
- const textTest = new LJS.UIText(vec2(-60,-120), vec2(300, 60), 'Test Text\nSecond text line.')
54
- uiMenu.addChild(textTest);
55
-
56
- // example tile image
57
- const tileTest = new LJS.UITile(vec2(150,-130), vec2(110), tile(3,128))
58
- uiMenu.addChild(tileTest);
59
-
60
- // setup navigation index for gamepad and keyboard navigation
61
- let navigationIndex = 0;
62
-
63
- // example checkbox
64
- const checkbox = new LJS.UICheckbox(vec2(-140,-20), vec2(50));
65
- uiMenu.addChild(checkbox);
66
- checkbox.onChange = ()=> button1.disabled = checkbox.checked;
67
- checkbox.navigationIndex = ++navigationIndex;
68
- checkbox.text = 'Test Checkbox';
69
-
70
- // example slider
71
- const slider = new LJS.UISlider(vec2(0,60), vec2(350, 50));
72
- uiMenu.addChild(slider);
73
- slider.onChange = ()=> slider.text = slider.value.toFixed(2)
74
- slider.onChange();
75
- slider.navigationIndex = ++navigationIndex;
76
-
77
- // example button
78
- const button1 = new LJS.UIButton(vec2(0,140), vec2(350, 50), 'Test Button');
79
- uiMenu.addChild(button1);
80
- button1.onClick = ()=> uiBackground.color = hsl(LJS.rand(),1,.7);
81
- button1.navigationIndex = ++navigationIndex;
82
-
83
- // exit button
84
- const button2 = new LJS.UIButton(vec2(0,220), vec2(350, 50), 'Exit Menu');
85
- uiMenu.addChild(button2);
86
- button2.onClick = ()=> LJS.uiSystem.showConfirmDialog('Exit menu?',
87
- ()=> setMenuVisible(false));
88
- button2.navigationIndex = ++navigationIndex;
89
- button2.navigationAutoSelect = true;
90
- }
91
-
92
- ///////////////////////////////////////////////////////////////////////////////
93
- function gameInit()
94
- {
95
- new LJS.UISystemPlugin;
96
- createUI();
97
- LJS.setCanvasClearColor(hsl(0,0,.2));
98
- }
99
-
100
- ///////////////////////////////////////////////////////////////////////////////
101
- function gameUpdate()
102
- {
103
- }
104
-
105
- ///////////////////////////////////////////////////////////////////////////////
106
- function gameUpdatePost()
107
- {
108
- if (LJS.keyWasPressed('KeyM') && !LJS.uiSystem.confirmDialog)
109
- {
110
- // toggle menu visibility
111
- setMenuVisible(!getMenuVisible());
112
- }
113
-
114
- // center ui
115
- uiRoot.pos.x = LJS.mainCanvasSize.x/2;
116
-
117
- // pause when menu is visible
118
- LJS.setPaused(getMenuVisible())
119
- }
120
-
121
- ///////////////////////////////////////////////////////////////////////////////
122
- function gameRender()
123
- {
124
- // test game rendering
125
- for (let i=0; i<1e3; ++i)
126
- {
127
- const pos = vec2(30*LJS.sin(i+LJS.time/9),20*LJS.sin(i*i+LJS.time/9));
128
- LJS.drawTile(pos, vec2(2), tile(3,128), hsl(i/9,1,.4), LJS.time+i, !(i%2), hsl(i/9,1,.1,0));
129
- }
130
- }
131
-
132
- ///////////////////////////////////////////////////////////////////////////////
133
- function gameRenderPost()
134
- {
135
- }
136
-
137
- ///////////////////////////////////////////////////////////////////////////////
138
- // Startup LittleJS Engine
139
- LJS.engineInit(gameInit, gameUpdate, gameUpdatePost, gameRender, gameRenderPost, ['tiles.png']);
@@ -1,10 +0,0 @@
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
- <!-- Add your game scripts here -->
10
- <script src=game.js type=module></script>
Binary file
package/jsconfig.json DELETED
@@ -1,12 +0,0 @@
1
- {
2
- "compilerOptions": {
3
- },
4
- "include": [
5
- "./src/*.js",
6
- "./plugins/*.js",
7
- "./examples/**/*.js",
8
- "./shortExamples/**/*.js",
9
- ],
10
- "exclude": [
11
- ]
12
- }
@@ -1,2 +0,0 @@
1
- [LocalizedFileNames]
2
- tweens (1).js=@tweens (1).js,0