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,191 +0,0 @@
1
- /*
2
- Little JS Breakout Tutorial
3
- - Shows how to make a simple breakout game
4
- - Includes sound and particles
5
- - Control with mouse or touch
6
- */
7
-
8
- 'use strict';
9
-
10
- // import LittleJS module
11
- import * as LJS from '../../dist/littlejs.esm.js';
12
- const {vec2, rgb} = LJS;
13
-
14
- ///////////////////////////////////////////////////////////////////////////////
15
-
16
- // globals
17
- const levelSize = vec2(38, 20); // size of play area
18
- let score = 0; // start score at 0
19
- let ball; // keep track of ball object
20
- let paddle; // keep track of player paddle
21
-
22
- // sound effects
23
- const sound_bounce = new LJS.Sound([,,1e3,,.03,.02,1,2,,,940,.03,,,,,.2,.6,,.06], 0);
24
- const sound_break = new LJS.Sound([,,90,,.01,.03,4,,,,,,,9,50,.2,,.2,.01], 0);
25
- const sound_start = new LJS.Sound([,0,500,,.04,.3,1,2,,,570,.02,.02,,,,.04]);
26
-
27
- ///////////////////////////////////////////////////////////////////////////////
28
-
29
- class Paddle extends LJS.EngineObject
30
- {
31
- constructor()
32
- {
33
- super(vec2(0,1), vec2(6,.5)); // set object position and size
34
- this.setCollision(); // make object collide
35
- this.mass = 0; // make object have static physics
36
- }
37
-
38
- update()
39
- {
40
- this.pos.x = LJS.mousePos.x; // move paddle to mouse
41
-
42
- // clamp paddle to level size
43
- this.pos.x = LJS.clamp(this.pos.x, this.size.x/2, levelSize.x - this.size.x/2);
44
- }
45
- }
46
-
47
- class Ball extends LJS.EngineObject
48
- {
49
- constructor(pos)
50
- {
51
- super(pos, vec2(.5)); // set object position and size
52
-
53
- this.velocity = vec2(-.1, -.1); // give ball some movement
54
- this.setCollision(); // make object collide
55
- this.restitution = 1; // make object bounce
56
- }
57
- collideWithObject(o)
58
- {
59
- // prevent colliding with paddle if moving upwards
60
- if (o == paddle && this.velocity.y > 0)
61
- return false;
62
-
63
- // speed up
64
- const speed = LJS.min(1.04*this.velocity.length(), .5);
65
- this.velocity = this.velocity.normalize(speed);
66
-
67
- // play bounce sound with pitch scaled by speed
68
- sound_bounce.play(this.pos, 1, speed);
69
-
70
- if (o == paddle)
71
- {
72
- // control bounce angle when ball collides with paddle
73
- const deltaX = o.pos.x - this.pos.x;
74
- this.velocity = this.velocity.rotate(.3 * deltaX);
75
-
76
- // make sure ball is moving upwards with a minimum speed
77
- this.velocity.y = LJS.max(-this.velocity.y, .2);
78
-
79
- // prevent default collision code
80
- return false;
81
- }
82
-
83
- return true; // allow object to collide
84
- }
85
- }
86
-
87
- class Wall extends LJS.EngineObject
88
- {
89
- constructor(pos, size)
90
- {
91
- super(pos, size); // set object position and size
92
-
93
- this.setCollision(); // make object collide
94
- this.mass = 0; // make object have static physics
95
- this.color = rgb(0,0,0,0); // make object invisible
96
- }
97
- }
98
-
99
- class Brick extends LJS.EngineObject
100
- {
101
- constructor(pos, size)
102
- {
103
- super(pos, size);
104
-
105
- this.setCollision(); // make object collide
106
- this.mass = 0; // make object have static physics
107
- this.color = LJS.randColor(); // give brick a random color
108
- }
109
-
110
- collideWithObject(o)
111
- {
112
- this.destroy(); // destroy block when hit
113
- sound_break.play(this.pos); // play brick break sound
114
- ++score; // award a point for each brick broke
115
-
116
- // create explosion effect
117
- const color = this.color;
118
- new LJS.ParticleEmitter(
119
- this.pos, 0, // pos, angle
120
- this.size, .1, 200, 3.14,// emitSize, emitTime, rate, cone
121
- undefined, // tileInfo
122
- color, color, // colorStartA, colorStartB
123
- color.scale(1,0), color.scale(1,0), // colorEndA, colorEndB
124
- .2, .5, 1, .1, .1, // time, sizeStart, sizeEnd, speed, angleSpeed
125
- .99, .95, .4, 3.14, // damp, angleDamp, gravity, cone
126
- .1, .5, false, true // fade, randomness, collide, additive
127
- );
128
-
129
- return true; // allow object to collide
130
- }
131
- }
132
-
133
- ///////////////////////////////////////////////////////////////////////////////
134
- function gameInit()
135
- {
136
- // setup camera and canvas
137
- LJS.setCameraPos(levelSize.scale(.5)); // center camera in level
138
- LJS.setCanvasFixedSize(vec2(1280, 720)); // use a 720p fixed size canvas
139
-
140
- // create bricks
141
- for (let x=2; x<=levelSize.x-2; x+=2)
142
- for (let y=12; y<=levelSize.y-2; y+=1)
143
- new Brick(vec2(x,y), vec2(2,1)); // create a brick
144
-
145
- // create player paddle
146
- paddle = new Paddle;
147
-
148
- // create walls
149
- new Wall(vec2(-.5,levelSize.y/2), vec2(1,100)) // top
150
- new Wall(vec2(levelSize.x+.5,levelSize.y/2), vec2(1,100)) // left
151
- new Wall(vec2(levelSize.x/2,levelSize.y+.5), vec2(100,1)) // right
152
- }
153
-
154
- ///////////////////////////////////////////////////////////////////////////////
155
- function gameUpdate()
156
- {
157
- if (ball && ball.pos.y < -1) // if ball is below level
158
- {
159
- // destroy old ball
160
- ball.destroy();
161
- ball = 0;
162
- }
163
- if (!ball && LJS.mouseWasPressed(0))
164
- {
165
- // spawn new ball if there is no ball and left mouse pressed
166
- ball = new Ball(LJS.cameraPos); // create a ball
167
- sound_start.play(); // play start sound
168
- }
169
- }
170
-
171
- ///////////////////////////////////////////////////////////////////////////////
172
- function gameUpdatePost()
173
- {
174
- }
175
-
176
- ///////////////////////////////////////////////////////////////////////////////
177
- function gameRender()
178
- {
179
- LJS.drawRect(LJS.cameraPos, vec2(100), rgb(.5,.5,.5)); // draw background
180
- LJS.drawRect(LJS.cameraPos, levelSize, rgb(.1,.1,.1)); // draw level boundary
181
- }
182
-
183
- ///////////////////////////////////////////////////////////////////////////////
184
- function gameRenderPost()
185
- {
186
- LJS.drawTextScreen('Score ' + score, vec2(LJS.mainCanvasSize.x/2, 70), 50); // show score
187
- }
188
-
189
- ///////////////////////////////////////////////////////////////////////////////
190
- // Startup LittleJS Engine
191
- LJS.engineInit(gameInit, gameUpdate, gameUpdatePost, gameRender, gameRenderPost);
@@ -1,8 +0,0 @@
1
- <!DOCTYPE html><head>
2
- <title>LittleJS Breakout Tutorial</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
- <script src=game.js type=module></script>
@@ -1,127 +0,0 @@
1
- /**
2
- * LittleJS Build System
3
- */
4
-
5
- 'use strict';
6
-
7
- import { fileURLToPath } from 'node:url';
8
- import { dirname, join } from 'node:path';
9
- import fs from 'node:fs';
10
- import { execSync } from 'node:child_process';
11
-
12
- const __dirname = dirname(fileURLToPath(import.meta.url));
13
-
14
- const PROGRAM_TITLE = 'Little JS Electron Project';
15
- const PROGRAM_NAME = 'game';
16
- const BUILD_FOLDER = join(__dirname, 'build');
17
- const USE_ROADROLLER = false; // enable for extra compression
18
- const sourceFiles =
19
- [
20
- join(__dirname, '../../dist/littlejs.release.js'),
21
- join(__dirname, 'game.js'),
22
- // add your game's files here
23
- ];
24
- const dataFiles =
25
- [
26
- 'tiles.png',
27
- // add your game's data files here
28
- ];
29
-
30
- console.log(`Building ${PROGRAM_NAME}...`);
31
- const startTime = Date.now();
32
-
33
- // rebuild engine
34
- //execSync(`npm run build`, { stdio: 'inherit' });
35
-
36
- // remove old files and setup build folder
37
- fs.rmSync(BUILD_FOLDER, { recursive: true, force: true });
38
- fs.rmSync(join(__dirname, `${PROGRAM_NAME}.zip`), { force: true });
39
- fs.mkdirSync(BUILD_FOLDER);
40
-
41
- // copy data files
42
- for (const file of dataFiles)
43
- fs.copyFileSync(join(__dirname, file), join(BUILD_FOLDER, file));
44
-
45
- Build
46
- (
47
- join(BUILD_FOLDER, 'index.js'),
48
- sourceFiles,
49
- USE_ROADROLLER ?
50
- [closureCompilerStep, uglifyBuildStep, roadrollerBuildStep, htmlBuildStep, electronBuildStep] :
51
- [closureCompilerStep, uglifyBuildStep, htmlBuildStep, electronBuildStep]
52
- );
53
-
54
- console.log('');
55
- console.log(`Build Completed in ${((Date.now() - startTime)/1e3).toFixed(2)} seconds!`);
56
-
57
- ///////////////////////////////////////////////////////////////////////////////
58
-
59
- // A single build with its own source files, build steps, and output file
60
- // - each build step is a callback that accepts a single filename
61
- function Build(outputFile, files=[], buildSteps=[])
62
- {
63
- // copy files into a buffer
64
- let buffer = '';
65
- for (const file of files)
66
- buffer += fs.readFileSync(file) + '\n';
67
-
68
- // output file
69
- fs.writeFileSync(outputFile, buffer, {flag: 'w+'});
70
-
71
- // execute build steps in order
72
- for (const buildStep of buildSteps)
73
- buildStep(outputFile);
74
- }
75
-
76
- function closureCompilerStep(filename)
77
- {
78
- console.log('Running closure compiler...');
79
-
80
- // use closer compiler to minify the code
81
- const filenameTemp = filename + '.tmp';
82
- fs.copyFileSync(filename, filenameTemp);
83
- execSync(`npx google-closure-compiler --js=${filenameTemp} --js_output_file=${filename} --compilation_level=ADVANCED --warning_level=VERBOSE --jscomp_off=* --assume_function_wrapper`, {stdio: 'inherit'});
84
- fs.rmSync(filenameTemp);
85
- }
86
-
87
- function uglifyBuildStep(filename)
88
- {
89
- console.log('Running uglify...');
90
- execSync(`npx uglifyjs ${filename} -c -m -o ${filename}`, {stdio: 'inherit'});
91
- }
92
-
93
- function roadrollerBuildStep(filename)
94
- {
95
- console.log('Running roadroller...');
96
- execSync(`npx roadroller ${filename} -o ${filename}`, {stdio: 'inherit'});
97
- }
98
-
99
- function htmlBuildStep(filename)
100
- {
101
- console.log('Building html...');
102
-
103
- // create html file
104
- let buffer = '';
105
- buffer += '<!DOCTYPE html>';
106
- buffer += '<head>';
107
- buffer += `<title>${PROGRAM_TITLE}</title>`;
108
- buffer += '<meta charset=utf-8>';
109
- buffer += '</head>';
110
- buffer += '<body>';
111
- buffer += `<script src='index.js'></script>`;
112
-
113
- // output html file
114
- fs.writeFileSync(join(BUILD_FOLDER, 'index.html'), buffer, {flag: 'w+'});
115
- }
116
-
117
- function electronBuildStep(filename)
118
- {
119
- console.log('Building executable with electron...');
120
-
121
- // copy elecron files to build folder
122
- fs.copyFileSync(join(__dirname, 'electron.js'), join(BUILD_FOLDER, 'electron.js'));
123
- fs.copyFileSync(join(__dirname, 'package.json'), join(BUILD_FOLDER, 'package.json'));
124
-
125
- // run electron packager
126
- execSync(`npx electron-packager "${BUILD_FOLDER}" --overwrite --out="${__dirname}"`, {stdio: 'inherit'});
127
- }
@@ -1,35 +0,0 @@
1
- const { app, BrowserWindow } = require('electron');
2
-
3
- function createWindow()
4
- {
5
- // create the browser window
6
- const mainWindow = new BrowserWindow({width: 800, height: 600});
7
-
8
- // hide the toolbar menu
9
- mainWindow.setMenu(null);
10
-
11
- // load the index.html of the app
12
- mainWindow.loadFile('index.html');
13
-
14
- // go fullscreen
15
- //mainWindow.setFullScreen(true);
16
-
17
- // open the dev tools debugging
18
- //mainWindow.webContents.openDevTools()
19
- }
20
-
21
- // wait until the app is ready and create the window
22
- app.whenReady().then(createWindow);
23
-
24
- // quit when all windows are closed (except macOS convention)
25
- app.on('window-all-closed', ()=>
26
- {
27
- if (process.platform != 'darwin')
28
- app.quit();
29
- });
30
-
31
- app.on('activate', ()=>
32
- {
33
- if (BrowserWindow.getAllWindows().length == 0)
34
- createWindow();
35
- });
@@ -1,54 +0,0 @@
1
- /*
2
- Little JS Starter Project
3
- - A simple starter project for LittleJS
4
- - Demos all the main engine features
5
- - Builds to a zip file
6
- */
7
-
8
- 'use strict';
9
-
10
- // show the LittleJS splash screen
11
- setShowSplashScreen(true);
12
-
13
- // sound effects
14
- const sound_click = new Sound([1,.5]);
15
-
16
- ///////////////////////////////////////////////////////////////////////////////
17
- function gameInit()
18
- {
19
- setCanvasClearColor(GRAY);
20
- }
21
-
22
- ///////////////////////////////////////////////////////////////////////////////
23
- function gameUpdate()
24
- {
25
- if (mouseWasPressed(0))
26
- {
27
- // play sound when mouse is pressed
28
- sound_click.play(mousePos);
29
- }
30
- }
31
-
32
- ///////////////////////////////////////////////////////////////////////////////
33
- function gameUpdatePost()
34
- {
35
- }
36
-
37
- ///////////////////////////////////////////////////////////////////////////////
38
- function gameRender()
39
- {
40
- // draw the logo as a tile
41
- drawTile(vec2(sin(time)*4, 0), vec2(10), tile(3,128));
42
- }
43
-
44
- ///////////////////////////////////////////////////////////////////////////////
45
- function gameRenderPost()
46
- {
47
- drawTextScreen('LittleJS\nElectron Demo',
48
- vec2(mainCanvasSize.x/2, 100), 80, // position, size
49
- hsl(0,0,1), 6, hsl(0,0,0)); // color, outline size and color
50
- }
51
-
52
- ///////////////////////////////////////////////////////////////////////////////
53
- // Startup LittleJS Engine
54
- engineInit(gameInit, gameUpdate, gameUpdatePost, gameRender, gameRenderPost, ['tiles.png']);
@@ -1,13 +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
- <!-- LittleJS Engine -->
10
- <script src=../../dist/littlejs.js></script>
11
-
12
- <!-- Add your game scripts here -->
13
- <script src=game.js></script>
@@ -1,5 +0,0 @@
1
- {
2
- "name": "littlejsgame",
3
- "version": "1.0.0",
4
- "main": "electron.js"
5
- }
Binary file
@@ -1,51 +0,0 @@
1
- /*
2
- Little JS Hello World Demo
3
- - Just prints 'Hello World!'
4
- - A good starting point for new projects
5
- */
6
-
7
- 'use strict';
8
-
9
- // import LittleJS module
10
- import * as LJS from '../../dist/littlejs.esm.js';
11
- const {vec2, rgb} = LJS;
12
-
13
- ///////////////////////////////////////////////////////////////////////////////
14
- function gameInit()
15
- {
16
- // called once after the engine starts up
17
- // setup the game
18
- }
19
-
20
- ///////////////////////////////////////////////////////////////////////////////
21
- function gameUpdate()
22
- {
23
- // called every frame at 60 frames per second
24
- // handle input and update the game state
25
- }
26
-
27
- ///////////////////////////////////////////////////////////////////////////////
28
- function gameUpdatePost()
29
- {
30
- // called after physics and objects are updated
31
- // setup camera and prepare for render
32
- }
33
-
34
- ///////////////////////////////////////////////////////////////////////////////
35
- function gameRender()
36
- {
37
- // called before objects are rendered
38
- // draw any background effects that appear behind objects
39
- }
40
-
41
- ///////////////////////////////////////////////////////////////////////////////
42
- function gameRenderPost()
43
- {
44
- // called after objects are rendered
45
- // draw effects or hud that appear above all objects
46
- LJS.drawTextScreen('Hello World!', LJS.mainCanvasSize.scale(.5), 80);
47
- }
48
-
49
- ///////////////////////////////////////////////////////////////////////////////
50
- // Startup LittleJS Engine
51
- LJS.engineInit(gameInit, gameUpdate, gameUpdatePost, gameRender, gameRenderPost, ['tiles.png']);
@@ -1,5 +0,0 @@
1
- <!DOCTYPE html><head>
2
- <title>LittleJS Hello World Demo</title>
3
- <meta charset=utf-8>
4
- </head><body>
5
- <script src=game.js type=module></script>
Binary file
Binary file
Binary file
@@ -1,82 +0,0 @@
1
- /*
2
- Little JS HTML Menu Example Project
3
- - Setup a simple html menu system
4
- - Menu can be opened and closed
5
- - Pauses game when menu is visible
6
- - Shows several input types
7
- */
8
-
9
- 'use strict';
10
-
11
- // import LittleJS module
12
- import * as LJS from '../../dist/littlejs.esm.js';
13
- const {vec2, hsl, tile} = LJS;
14
-
15
- // sound effects
16
- const sound_click = new LJS.Sound([1,.5]);
17
-
18
- ///////////////////////////////////////////////////////////////////////////////
19
-
20
- // html menu system
21
- const getMenuVisible = ()=> menu.style.visibility != 'hidden';
22
- function setMenuVisible(visible)
23
- {
24
- menu.style.visibility = visible ? 'visible' : 'hidden';
25
- LJS.setInputPreventDefault(!visible); // don't prevent default when menu is visible
26
- }
27
-
28
- ///////////////////////////////////////////////////////////////////////////////
29
- function gameInit()
30
- {
31
- button_test.onclick = function() { alert('Button was clicked!'); }
32
- button_exitMenu.onclick = function() { setMenuVisible(false); }
33
- input_test.onchange = function() { alert('New text: ' + this.value); }
34
- input_rangeTest.onchange = function() { alert('New value: ' + this.value); }
35
- LJS.setCanvasClearColor(hsl(0,0,.2));
36
-
37
- // show menu for demo
38
- setMenuVisible(true);
39
- }
40
-
41
- ///////////////////////////////////////////////////////////////////////////////
42
- function gameUpdate()
43
- {
44
- // play sound when mouse is pressed
45
- if (LJS.mouseWasPressed(0))
46
- sound_click.play(LJS.mousePos);
47
- }
48
-
49
- ///////////////////////////////////////////////////////////////////////////////
50
- function gameUpdatePost()
51
- {
52
- // open menu visibility
53
- if (LJS.keyWasPressed('KeyM'))
54
- setMenuVisible(true);
55
-
56
- // pause game when menu is visible
57
- LJS.setPaused(getMenuVisible());
58
- }
59
-
60
- ///////////////////////////////////////////////////////////////////////////////
61
- function gameRender()
62
- {
63
- // test game rendering
64
- for (let i=0; i<1e3; ++i)
65
- {
66
- const time = LJS.time;
67
- const pos = vec2(30*LJS.sin(i+time/9),20*LJS.sin(i*i+time/9));
68
- LJS.drawTile(pos, vec2(2), tile(3,128), hsl(i/9,1,.4), time+i, !(i%2), hsl(i/9,1,.1,0));
69
- }
70
- }
71
-
72
- ///////////////////////////////////////////////////////////////////////////////
73
- function gameRenderPost()
74
- {
75
- LJS.drawTextScreen('LittleJS HTML Menu Example\nM = Open menu',
76
- vec2(LJS.mainCanvasSize.x/2, 70), 60, // position, size
77
- hsl(0,0,1), 6, hsl(0,0,0)); // color, outline size and color
78
- }
79
-
80
- ///////////////////////////////////////////////////////////////////////////////
81
- // Startup LittleJS Engine
82
- LJS.engineInit(gameInit, gameUpdate, gameUpdatePost, gameRender, gameRenderPost, ['tiles.png']);