littlejsengine 1.5.2 → 1.6.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 (72) hide show
  1. package/README.md +155 -33
  2. package/{engine/index.d.ts → build/littlejs.d.ts} +14 -6
  3. package/{engine/engine.all.module.js → build/littlejs.esm.js} +110 -99
  4. package/build/littlejs.esm.min.js +1 -0
  5. package/{engine/engine.all.js → build/littlejs.js} +102 -97
  6. package/build/littlejs.min.js +1 -0
  7. package/{engine/engine.all.release.js → build/littlejs.release.js} +95 -95
  8. package/examples/breakout/game.js +5 -0
  9. package/examples/breakout/gameObjects.js +41 -48
  10. package/examples/breakout/index.html +5 -4
  11. package/examples/breakoutTutorial/README.md +514 -0
  12. package/examples/breakoutTutorial/game.js +181 -0
  13. package/examples/breakoutTutorial/images/1.png +0 -0
  14. package/examples/breakoutTutorial/images/10.png +0 -0
  15. package/examples/breakoutTutorial/images/11.png +0 -0
  16. package/examples/breakoutTutorial/images/2.png +0 -0
  17. package/examples/breakoutTutorial/images/3.png +0 -0
  18. package/examples/breakoutTutorial/images/4.png +0 -0
  19. package/examples/breakoutTutorial/images/5.png +0 -0
  20. package/examples/breakoutTutorial/images/6.png +0 -0
  21. package/examples/breakoutTutorial/images/7.png +0 -0
  22. package/examples/breakoutTutorial/images/8.png +0 -0
  23. package/examples/breakoutTutorial/images/9.png +0 -0
  24. package/examples/breakoutTutorial/index.html +10 -0
  25. package/examples/electron/build.bat +52 -0
  26. package/{electron → examples/electron}/electron.js +18 -21
  27. package/{game.js → examples/electron/game.js} +1 -1
  28. package/examples/electron/index.html +2 -0
  29. package/examples/electron/package.json +20 -0
  30. package/examples/empty/game.js +11 -1
  31. package/examples/empty/index.html +2 -2
  32. package/examples/module/game.js +1 -1
  33. package/examples/module/index.html +3 -2
  34. package/examples/particles/index.html +3 -2
  35. package/examples/platformer/gameLevel.js +1 -1
  36. package/examples/platformer/gamePlayer.js +1 -1
  37. package/examples/platformer/index.html +8 -7
  38. package/examples/puzzle/index.html +4 -3
  39. package/{build.bat → examples/starter/build.bat} +17 -17
  40. package/examples/starter/game.js +111 -0
  41. package/examples/starter/index.html +27 -0
  42. package/examples/starter/tiles.png +0 -0
  43. package/examples/stress/index.html +3 -2
  44. package/examples/typescript/game.js +89 -89
  45. package/examples/typescript/game.ts +11 -11
  46. package/examples/typescript/index.html +3 -2
  47. package/package.json +4 -4
  48. package/{engine → src}/engine.js +1 -2
  49. package/{engine → src}/engineAudio.js +11 -11
  50. package/src/engineBuild.bat +132 -0
  51. package/{engine → src}/engineDebug.js +8 -2
  52. package/{engine → src}/engineDraw.js +19 -15
  53. package/{engine → src}/engineExport.js +8 -2
  54. package/{engine → src}/engineInput.js +54 -58
  55. package/{engine → src}/engineMedals.js +1 -1
  56. package/{engine → src}/engineObject.js +4 -4
  57. package/{engine → src}/engineRelease.js +1 -0
  58. package/{engine → src}/engineUtilities.js +4 -4
  59. package/electron/electronBuild.bat +0 -32
  60. package/electron/electronSetup.bat +0 -2
  61. package/electron/package.json +0 -21
  62. package/engine/engine.all.min.js +0 -1
  63. package/engine/engine.all.module.min.js +0 -1
  64. package/engine/engineBuild.bat +0 -127
  65. package/index.html +0 -26
  66. /package/{tiles.png → examples/electron/tiles.png} +0 -0
  67. /package/{favicon.png → examples/favicon.png} +0 -0
  68. /package/{engine → src}/engineFont.png +0 -0
  69. /package/{engine → src}/engineParticles.js +0 -0
  70. /package/{engine → src}/engineSettings.js +0 -0
  71. /package/{engine → src}/engineTileLayer.js +0 -0
  72. /package/{engine → src}/engineWebGL.js +0 -0
@@ -1,89 +1,89 @@
1
- /*
2
- LittleJS Hello World Starter Game
3
- */
4
- 'use strict';
5
- // import module
6
- import * as LittleJS from '../../engine/engine.all.module.js';
7
- const { Vector2, Color, Timer, vec2 } = LittleJS;
8
- // sound effects
9
- const sound_click = new LittleJS.Sound([1, .5]);
10
- // medals
11
- const medal_example = new LittleJS.Medal(0, 'Example Medal', 'Welcome to LittleJS!');
12
- LittleJS.medalsInit('Hello World');
13
- // game variables
14
- let particleEmiter;
15
- ///////////////////////////////////////////////////////////////////////////////
16
- function gameInit() {
17
- // create tile collision and visible tile layer
18
- LittleJS.initTileCollision(vec2(32, 16));
19
- const pos = vec2();
20
- const tileLayer = new LittleJS.TileLayer(pos, LittleJS.tileCollisionSize);
21
- // get level data from the tiles image
22
- const imageLevelDataRow = 1;
23
- const mainContext = LittleJS.mainContext;
24
- mainContext.drawImage(LittleJS.tileImage, 0, 0);
25
- for (pos.x = LittleJS.tileCollisionSize.x; pos.x--;)
26
- for (pos.y = LittleJS.tileCollisionSize.y; pos.y--;) {
27
- const imageData = mainContext.getImageData(pos.x, 16 * (imageLevelDataRow + 1) - pos.y - 1, 1, 1).data;
28
- if (imageData[0]) {
29
- const tileIndex = 1;
30
- const direction = LittleJS.randInt(4);
31
- const mirror = LittleJS.randInt(2) ? true : false;
32
- const color = LittleJS.randColor();
33
- const data = new LittleJS.TileLayerData(tileIndex, direction, mirror, color);
34
- tileLayer.setData(pos, data);
35
- LittleJS.setTileCollisionData(pos, 1);
36
- }
37
- }
38
- tileLayer.redraw();
39
- // move camera to center of collision
40
- LittleJS.setCameraPos(LittleJS.tileCollisionSize.scale(.5));
41
- // enable gravity
42
- LittleJS.setGravity(-.01);
43
- // create particle emitter
44
- const center = LittleJS.tileCollisionSize.scale(.5).add(vec2(0, 9));
45
- particleEmiter = new LittleJS.ParticleEmitter(center, 0, // emitPos, emitAngle
46
- 1, 0, 500, Math.PI, // emitSize, emitTime, emitRate, emiteCone
47
- 0, vec2(16), // tileIndex, tileSize
48
- new Color(1, 1, 1), new Color(0, 0, 0), // colorStartA, colorStartB
49
- new Color(1, 1, 1, 0), new Color(0, 0, 0, 0), // colorEndA, colorEndB
50
- 2, .2, .2, .1, .05, // time, sizeStart, sizeEnd, speed, angleSpeed
51
- .99, 1, 1, Math.PI, // damping, angleDamping, gravityScale, cone
52
- .05, .5, true, true // fadeRate, randomness, collide, additive
53
- );
54
- particleEmiter.elasticity = .3; // bounce when it collides
55
- particleEmiter.trailScale = 2; // stretch in direction of motion
56
- }
57
- ///////////////////////////////////////////////////////////////////////////////
58
- function gameUpdate() {
59
- if (LittleJS.mouseWasPressed(0)) {
60
- // play sound when mouse is pressed
61
- sound_click.play(LittleJS.mousePos);
62
- // change particle color and set to fade out
63
- particleEmiter.colorStartA = new Color;
64
- particleEmiter.colorStartB = LittleJS.randColor();
65
- particleEmiter.colorEndA = particleEmiter.colorStartA.scale(1, 0);
66
- particleEmiter.colorEndB = particleEmiter.colorStartB.scale(1, 0);
67
- // unlock medals
68
- medal_example.unlock();
69
- }
70
- // move particles to mouse location if on screen
71
- if (LittleJS.mousePosScreen.x)
72
- particleEmiter.pos = LittleJS.mousePos;
73
- }
74
- ///////////////////////////////////////////////////////////////////////////////
75
- function gameUpdatePost() {
76
- }
77
- ///////////////////////////////////////////////////////////////////////////////
78
- function gameRender() {
79
- // draw a grey square in the background without using webgl
80
- LittleJS.drawRect(LittleJS.cameraPos, LittleJS.tileCollisionSize.add(vec2(5)), new Color(.2, .2, .2), 0, false);
81
- }
82
- ///////////////////////////////////////////////////////////////////////////////
83
- function gameRenderPost() {
84
- // draw to overlay canvas for hud rendering
85
- LittleJS.drawTextScreen('LittleJS with TypeScript', vec2(LittleJS.mainCanvasSize.x / 2, 80), 80);
86
- }
87
- ///////////////////////////////////////////////////////////////////////////////
88
- // Startup LittleJS Engine
89
- LittleJS.engineInit(gameInit, gameUpdate, gameUpdatePost, gameRender, gameRenderPost, 'tiles.png');
1
+ /*
2
+ LittleJS Hello World Starter Game
3
+ */
4
+ 'use strict';
5
+ // import module
6
+ import * as LittleJS from '../../build/littlejs.esm.js';
7
+ const { Color, vec2 } = LittleJS;
8
+ // sound effects
9
+ const sound_click = new LittleJS.Sound([1, .5]);
10
+ // medals
11
+ const medal_example = new LittleJS.Medal(0, 'Example Medal', 'Welcome to LittleJS!');
12
+ LittleJS.medalsInit('Hello World');
13
+ // game variables
14
+ let particleEmitter;
15
+ ///////////////////////////////////////////////////////////////////////////////
16
+ function gameInit() {
17
+ // create tile collision and visible tile layer
18
+ LittleJS.initTileCollision(vec2(32, 16));
19
+ const pos = vec2();
20
+ const tileLayer = new LittleJS.TileLayer(pos, LittleJS.tileCollisionSize);
21
+ // get level data from the tiles image
22
+ const imageLevelDataRow = 1;
23
+ const mainContext = LittleJS.mainContext;
24
+ mainContext.drawImage(LittleJS.tileImage, 0, 0);
25
+ for (pos.x = LittleJS.tileCollisionSize.x; pos.x--;)
26
+ for (pos.y = LittleJS.tileCollisionSize.y; pos.y--;) {
27
+ const imageData = mainContext.getImageData(pos.x, 16 * (imageLevelDataRow + 1) - pos.y - 1, 1, 1).data;
28
+ if (imageData[0]) {
29
+ const tileIndex = 1;
30
+ const direction = LittleJS.randInt(4);
31
+ const mirror = LittleJS.randInt(2) ? true : false;
32
+ const color = LittleJS.randColor();
33
+ const data = new LittleJS.TileLayerData(tileIndex, direction, mirror, color);
34
+ tileLayer.setData(pos, data);
35
+ LittleJS.setTileCollisionData(pos, 1);
36
+ }
37
+ }
38
+ tileLayer.redraw();
39
+ // move camera to center of collision
40
+ LittleJS.setCameraPos(LittleJS.tileCollisionSize.scale(.5));
41
+ // enable gravity
42
+ LittleJS.setGravity(-.01);
43
+ // create particle emitter
44
+ const center = LittleJS.tileCollisionSize.scale(.5).add(vec2(0, 9));
45
+ particleEmitter = new LittleJS.ParticleEmitter(center, 0, // emitPos, emitAngle
46
+ 1, 0, 500, Math.PI, // emitSize, emitTime, emitRate, emiteCone
47
+ 0, vec2(16), // tileIndex, tileSize
48
+ new Color(1, 1, 1), new Color(0, 0, 0), // colorStartA, colorStartB
49
+ new Color(1, 1, 1, 0), new Color(0, 0, 0, 0), // colorEndA, colorEndB
50
+ 2, .2, .2, .1, .05, // time, sizeStart, sizeEnd, speed, angleSpeed
51
+ .99, 1, 1, Math.PI, // damping, angleDamping, gravityScale, cone
52
+ .05, .5, true, true // fadeRate, randomness, collide, additive
53
+ );
54
+ particleEmitter.elasticity = .3; // bounce when it collides
55
+ particleEmitter.trailScale = 2; // stretch in direction of motion
56
+ }
57
+ ///////////////////////////////////////////////////////////////////////////////
58
+ function gameUpdate() {
59
+ if (LittleJS.mouseWasPressed(0)) {
60
+ // play sound when mouse is pressed
61
+ sound_click.play(LittleJS.mousePos);
62
+ // change particle color and set to fade out
63
+ particleEmitter.colorStartA = new Color;
64
+ particleEmitter.colorStartB = LittleJS.randColor();
65
+ particleEmitter.colorEndA = particleEmitter.colorStartA.scale(1, 0);
66
+ particleEmitter.colorEndB = particleEmitter.colorStartB.scale(1, 0);
67
+ // unlock medals
68
+ medal_example.unlock();
69
+ }
70
+ // move particles to mouse location if on screen
71
+ if (LittleJS.mousePosScreen.x)
72
+ particleEmitter.pos = LittleJS.mousePos;
73
+ }
74
+ ///////////////////////////////////////////////////////////////////////////////
75
+ function gameUpdatePost() {
76
+ }
77
+ ///////////////////////////////////////////////////////////////////////////////
78
+ function gameRender() {
79
+ // draw a grey square in the background without using webgl
80
+ LittleJS.drawRect(LittleJS.cameraPos, LittleJS.tileCollisionSize.add(vec2(5)), new Color(.2, .2, .2), 0, false);
81
+ }
82
+ ///////////////////////////////////////////////////////////////////////////////
83
+ function gameRenderPost() {
84
+ // draw to overlay canvas for hud rendering
85
+ LittleJS.drawTextScreen('LittleJS with TypeScript', vec2(LittleJS.mainCanvasSize.x / 2, 80), 80);
86
+ }
87
+ ///////////////////////////////////////////////////////////////////////////////
88
+ // Startup LittleJS Engine
89
+ LittleJS.engineInit(gameInit, gameUpdate, gameUpdatePost, gameRender, gameRenderPost, 'tiles.png');
@@ -5,8 +5,8 @@
5
5
  'use strict';
6
6
 
7
7
  // import module
8
- import * as LittleJS from '../../engine/engine.all.module.js';
9
- const {Vector2, Color, Timer, vec2} = LittleJS;
8
+ import * as LittleJS from '../../build/littlejs.esm.js';
9
+ const {Color, vec2} = LittleJS;
10
10
 
11
11
  // sound effects
12
12
  const sound_click = new LittleJS.Sound([1,.5]);
@@ -16,7 +16,7 @@ const medal_example = new LittleJS.Medal(0, 'Example Medal', 'Welcome to LittleJ
16
16
  LittleJS.medalsInit('Hello World');
17
17
 
18
18
  // game variables
19
- let particleEmiter;
19
+ let particleEmitter: LittleJS.ParticleEmitter;
20
20
 
21
21
  ///////////////////////////////////////////////////////////////////////////////
22
22
  function gameInit()
@@ -55,7 +55,7 @@ function gameInit()
55
55
 
56
56
  // create particle emitter
57
57
  const center = LittleJS.tileCollisionSize.scale(.5).add(vec2(0,9));
58
- particleEmiter = new LittleJS.ParticleEmitter(
58
+ particleEmitter = new LittleJS.ParticleEmitter(
59
59
  center, 0, // emitPos, emitAngle
60
60
  1, 0, 500, Math.PI, // emitSize, emitTime, emitRate, emiteCone
61
61
  0, vec2(16), // tileIndex, tileSize
@@ -65,8 +65,8 @@ function gameInit()
65
65
  .99, 1, 1, Math.PI, // damping, angleDamping, gravityScale, cone
66
66
  .05, .5, true, true // fadeRate, randomness, collide, additive
67
67
  );
68
- particleEmiter.elasticity = .3; // bounce when it collides
69
- particleEmiter.trailScale = 2; // stretch in direction of motion
68
+ particleEmitter.elasticity = .3; // bounce when it collides
69
+ particleEmitter.trailScale = 2; // stretch in direction of motion
70
70
  }
71
71
 
72
72
  ///////////////////////////////////////////////////////////////////////////////
@@ -78,10 +78,10 @@ function gameUpdate()
78
78
  sound_click.play(LittleJS.mousePos);
79
79
 
80
80
  // change particle color and set to fade out
81
- particleEmiter.colorStartA = new Color;
82
- particleEmiter.colorStartB = LittleJS.randColor();
83
- particleEmiter.colorEndA = particleEmiter.colorStartA.scale(1,0);
84
- particleEmiter.colorEndB = particleEmiter.colorStartB.scale(1,0);
81
+ particleEmitter.colorStartA = new Color;
82
+ particleEmitter.colorStartB = LittleJS.randColor();
83
+ particleEmitter.colorEndA = particleEmitter.colorStartA.scale(1,0);
84
+ particleEmitter.colorEndB = particleEmitter.colorStartB.scale(1,0);
85
85
 
86
86
  // unlock medals
87
87
  medal_example.unlock();
@@ -89,7 +89,7 @@ function gameUpdate()
89
89
 
90
90
  // move particles to mouse location if on screen
91
91
  if (LittleJS.mousePosScreen.x)
92
- particleEmiter.pos = LittleJS.mousePos;
92
+ particleEmitter.pos = LittleJS.mousePos;
93
93
  }
94
94
 
95
95
  ///////////////////////////////////////////////////////////////////////////////
@@ -1,9 +1,10 @@
1
1
  <html><head>
2
+ <title>Little TypeScript Demo</title>
2
3
  <meta name=viewport content=width=device-width,height=device-height,initial-scale=1,maximum-scale=1>
3
4
  <meta name=apple-mobile-web-app-capable content=yes>
4
5
  <meta name=mobile-web-app-capable content=yes>
5
- <link rel=icon type=image/png href=../../favicon.png>
6
+ <link rel=icon type=image/png href=../favicon.png>
6
7
  </head><body>
7
8
 
8
9
  <!-- Add your game scripts here -->
9
- <script src=game.js?125 type=module></script>
10
+ <script src=game.js?126 type=module></script>
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "littlejsengine",
3
- "version": "1.5.2",
3
+ "version": "1.6.4",
4
4
  "description": "LittleJS - Tiny and Fast HTML5 Game Engine",
5
5
  "main": "engine/engine.all.module.js",
6
6
  "repository": {
@@ -23,13 +23,13 @@
23
23
  },
24
24
  "homepage": "https://github.com/KilledByAPixel/LittleJS",
25
25
  "scripts": {
26
- "build": "build.bat"
26
+ "build": "cd src && engineBuild.bat"
27
27
  },
28
28
  "devDependencies": {
29
- "ect-bin": "~1.4.1",
30
29
  "google-closure-compiler": "~20230502.0.0",
31
30
  "roadroller": "~2.1.0",
31
+ "uglify-js": "~3.17.4",
32
32
  "typescript": "~5.1.6",
33
- "uglify-js": "~3.17.4"
33
+ "ect-bin": "~1.4.1"
34
34
  }
35
35
  }
@@ -34,7 +34,7 @@ const engineName = 'LittleJS';
34
34
  * @type {String}
35
35
  * @default
36
36
  * @memberof Engine */
37
- const engineVersion = '1.5.2';
37
+ const engineVersion = '1.6.4';
38
38
 
39
39
  /** Frames per second to update objects
40
40
  * @type {Number}
@@ -125,7 +125,6 @@ function engineInit(gameInit, gameUpdate, gameUpdatePost, gameRender, gameRender
125
125
  (glCanvas||mainCanvas).style = mainCanvas.style = overlayCanvas.style = styleCanvas;
126
126
 
127
127
  gameInit();
128
- touchGamepadCreate();
129
128
  engineUpdate();
130
129
  };
131
130
 
@@ -270,7 +270,7 @@ function playSamples(sampleChannels, volume=1, rate=1, pan=0, loop=0)
270
270
  }
271
271
 
272
272
  ///////////////////////////////////////////////////////////////////////////////
273
- // ZzFXMicro - Zuper Zmall Zound Zynth - v1.1.8 by Frank Force
273
+ // ZzFXMicro - Zuper Zmall Zound Zynth - v1.2.0 by Frank Force
274
274
 
275
275
  /** Generate and play a ZzFX sound
276
276
  * <br>
@@ -296,11 +296,11 @@ function zzfxG
296
296
  bitCrush = 0, delay = 0, sustainVolume = 1, decay = 0, tremolo = 0
297
297
  )
298
298
  {
299
- // init parameters
299
+ // locals
300
300
  let PI2 = PI*2, startSlide = slide *= 500 * PI2 / zzfxR / zzfxR, b=[],
301
301
  startFrequency = frequency *= (1 + randomness*rand(-1,1)) * PI2 / zzfxR,
302
- t=0, tm=0, i=0, j=1, r=0, c=0, s=0, f, length;
303
-
302
+ t=0, tm=0, i=0, j=1, r=0, c=0, s=0, f, length
303
+
304
304
  // scale by sample rate
305
305
  attack = attack * zzfxR + 9; // minimum attack to prevent pop
306
306
  decay *= zzfxR;
@@ -350,18 +350,18 @@ function zzfxG
350
350
  Math.cos(modulation*tm++); // modulation
351
351
  t += f - f*noise*(1 - (Math.sin(i)+1)*1e9%2); // noise
352
352
 
353
- if (j && ++j > pitchJumpTime) // pitch jump
353
+ if (j && ++j > pitchJumpTime) // pitch jump
354
354
  {
355
- frequency += pitchJump; // apply pitch jump
356
- startFrequency += pitchJump; // also apply to start
357
- j = 0; // reset pitch jump time
355
+ frequency += pitchJump; // apply pitch jump
356
+ startFrequency += pitchJump; // also apply to start
357
+ j = 0; // reset pitch jump time
358
358
  }
359
359
 
360
360
  if (repeatTime && !(++r % repeatTime)) // repeat
361
361
  {
362
- frequency = startFrequency; // reset frequency
363
- slide = startSlide; // reset slide
364
- j = j || 1; // reset pitch jump time
362
+ frequency = startFrequency; // reset frequency
363
+ slide = startSlide; // reset slide
364
+ j ||= 1; // reset pitch jump time
365
365
  }
366
366
  }
367
367
 
@@ -0,0 +1,132 @@
1
+ rem Simple build script for LittleJS Engine by Frank Force
2
+ rem Minfies and combines index.html and index.js and zips the result
3
+ rem Run npm install first to install required dependencies
4
+
5
+ rem --- BUILD ENGINE DEBUG ---
6
+
7
+ set BUILD_FOLDER=build
8
+ set ENGINE_NAME=littlejs
9
+
10
+ pushd ..
11
+
12
+ rem remove old files
13
+ rmdir /s /q %BUILD_FOLDER%
14
+ mkdir %BUILD_FOLDER%
15
+ pushd %BUILD_FOLDER%
16
+
17
+ rem --- BUILD ENGINE ALL ---
18
+
19
+ set OUTPUT_FILENAME=%ENGINE_NAME%.js
20
+
21
+ rem combine code
22
+ type ..\src\engineDebug.js >> %OUTPUT_FILENAME%
23
+ echo.>> %OUTPUT_FILENAME%
24
+ type ..\src\engineUtilities.js >> %OUTPUT_FILENAME%
25
+ echo.>> %OUTPUT_FILENAME%
26
+ type ..\src\engineSettings.js >> %OUTPUT_FILENAME%
27
+ echo.>> %OUTPUT_FILENAME%
28
+ type ..\src\engineObject.js >> %OUTPUT_FILENAME%
29
+ echo.>> %OUTPUT_FILENAME%
30
+ type ..\src\engineDraw.js >> %OUTPUT_FILENAME%
31
+ echo.>> %OUTPUT_FILENAME%
32
+ type ..\src\engineInput.js >> %OUTPUT_FILENAME%
33
+ echo.>> %OUTPUT_FILENAME%
34
+ type ..\src\engineAudio.js >> %OUTPUT_FILENAME%
35
+ echo.>> %OUTPUT_FILENAME%
36
+ type ..\src\engineTileLayer.js >> %OUTPUT_FILENAME%
37
+ echo.>> %OUTPUT_FILENAME%
38
+ type ..\src\engineParticles.js >> %OUTPUT_FILENAME%
39
+ echo.>> %OUTPUT_FILENAME%
40
+ type ..\src\engineMedals.js >> %OUTPUT_FILENAME%
41
+ echo.>> %OUTPUT_FILENAME%
42
+ type ..\src\engineWebGL.js >> %OUTPUT_FILENAME%
43
+ echo.>> %OUTPUT_FILENAME%
44
+ type ..\src\engine.js >> %OUTPUT_FILENAME%
45
+ echo.>> %OUTPUT_FILENAME%
46
+
47
+ rem --- BUILD ENGINE RELEASE ---
48
+
49
+ set OUTPUT_FILENAME=%ENGINE_NAME%.release.js
50
+
51
+ rem combine code
52
+ type ..\src\engineRelease.js >> %OUTPUT_FILENAME%
53
+ echo.>> %OUTPUT_FILENAME%
54
+ type ..\src\engineUtilities.js >> %OUTPUT_FILENAME%
55
+ echo.>> %OUTPUT_FILENAME%
56
+ type ..\src\engineSettings.js >> %OUTPUT_FILENAME%
57
+ echo.>> %OUTPUT_FILENAME%
58
+ type ..\src\engine.js >> %OUTPUT_FILENAME%
59
+ echo.>> %OUTPUT_FILENAME%
60
+ type ..\src\engineObject.js >> %OUTPUT_FILENAME%
61
+ echo.>> %OUTPUT_FILENAME%
62
+ type ..\src\engineDraw.js >> %OUTPUT_FILENAME%
63
+ echo.>> %OUTPUT_FILENAME%
64
+ type ..\src\engineInput.js >> %OUTPUT_FILENAME%
65
+ echo.>> %OUTPUT_FILENAME%
66
+ type ..\src\engineAudio.js >> %OUTPUT_FILENAME%
67
+ echo.>> %OUTPUT_FILENAME%
68
+ type ..\src\engineTileLayer.js >> %OUTPUT_FILENAME%
69
+ echo.>> %OUTPUT_FILENAME%
70
+ type ..\src\engineParticles.js >> %OUTPUT_FILENAME%
71
+ echo.>> %OUTPUT_FILENAME%
72
+ type ..\src\engineMedals.js >> %OUTPUT_FILENAME%
73
+ echo.>> %OUTPUT_FILENAME%
74
+ type ..\src\engineWebGL.js >> %OUTPUT_FILENAME%
75
+ echo.>> %OUTPUT_FILENAME%
76
+
77
+ rem --- BUILD ENGINE MINIFIED ---
78
+
79
+ set OUTPUT_FILENAME=%ENGINE_NAME%.min.js
80
+
81
+ rem start with release build
82
+ copy %ENGINE_NAME%.release.js %OUTPUT_FILENAME%
83
+
84
+ rem check code with closure
85
+ move %OUTPUT_FILENAME% %OUTPUT_FILENAME%.temp
86
+ call npx google-closure-compiler --js=%OUTPUT_FILENAME%.temp --js_output_file=%OUTPUT_FILENAME% --language_out=ECMASCRIPT_2021 --warning_level=VERBOSE --jscomp_off=*
87
+ del %OUTPUT_FILENAME%.temp
88
+ if %ERRORLEVEL% NEQ 0 (
89
+ pause
90
+ exit /b %ERRORLEVEL%
91
+ )
92
+
93
+ rem lightly minify with uglify
94
+ call npx uglifyjs -o %OUTPUT_FILENAME% -- %OUTPUT_FILENAME%
95
+ if %ERRORLEVEL% NEQ 0 (
96
+ pause
97
+ exit /b %ERRORLEVEL%
98
+ )
99
+
100
+ rem --- BUILD ENGINE ESM MODULE ---
101
+
102
+ set OUTPUT_FILENAME=%ENGINE_NAME%.esm.js
103
+ type %ENGINE_NAME%.js >> %OUTPUT_FILENAME%
104
+ echo.>> %OUTPUT_FILENAME%
105
+ type ..\src\engineExport.js >> %OUTPUT_FILENAME%
106
+ echo.>> %OUTPUT_FILENAME%
107
+
108
+ rem --- BUILD ENGINE ESM MODULE RELEASE ---
109
+
110
+ set OUTPUT_FILENAME=%ENGINE_NAME%.esm.min.js
111
+ type %ENGINE_NAME%.min.js >> %OUTPUT_FILENAME%
112
+ echo.>> %OUTPUT_FILENAME%
113
+ type ..\src\engineExport.js >> %OUTPUT_FILENAME%
114
+ echo.>> %OUTPUT_FILENAME%
115
+
116
+ rem lightly minify with uglify
117
+ call npx uglifyjs -o %OUTPUT_FILENAME% -- %OUTPUT_FILENAME%
118
+ if %ERRORLEVEL% NEQ 0 (
119
+ pause
120
+ exit /b %ERRORLEVEL%
121
+ )
122
+
123
+ rem --- BUILD TYPESCRIPT DEFINITIONS ---
124
+
125
+ call npx tsc %ENGINE_NAME%.esm.js --declaration --allowJs --emitDeclarationOnly --outFile %ENGINE_NAME%.d.ts
126
+ if %ERRORLEVEL% NEQ 0 (
127
+ pause
128
+ exit /b %ERRORLEVEL%
129
+ )
130
+
131
+ popd
132
+ popd
@@ -45,6 +45,12 @@ let showWatermark = 1;
45
45
  * @memberof Debug */
46
46
  let godMode = 0;
47
47
 
48
+ /** Key code used to toggle debug mode, Esc by default
49
+ * @type {Boolean}
50
+ * @default
51
+ * @memberof Debug */
52
+ let debugKey = 27;
53
+
48
54
  // Engine internal variables not exposed to documentation
49
55
  let debugPrimitives = [], debugOverlay = 0, debugPhysics = 0, debugRaycast = 0,
50
56
  debugParticles = 0, debugGamepads = 0, debugMedals = 0, debugTakeScreenshot, downloadLink;
@@ -166,7 +172,7 @@ const debugUpdate = ()=>
166
172
  if (!debug)
167
173
  return;
168
174
 
169
- if (keyWasPressed(192)) // ~
175
+ if (keyWasPressed(debugKey)) // Esc
170
176
  debugOverlay = !debugOverlay;
171
177
  if (debugOverlay)
172
178
  {
@@ -351,7 +357,7 @@ const debugRender = ()=>
351
357
  overlayContext.fillText('Time: ' + formatTime(time), x, y += h);
352
358
  overlayContext.fillText('---------', x, y += h);
353
359
  overlayContext.fillStyle = '#f00';
354
- overlayContext.fillText('~: Debug Overlay', x, y += h);
360
+ overlayContext.fillText('ESC: Debug Overlay', x, y += h);
355
361
  overlayContext.fillStyle = debugPhysics ? '#f00' : '#fff';
356
362
  overlayContext.fillText('1: Debug Physics', x, y += h);
357
363
  overlayContext.fillStyle = debugParticles ? '#f00' : '#fff';
@@ -226,6 +226,23 @@ function setBlendMode(additive, useWebGL=glEnable)
226
226
  mainContext.globalCompositeOperation = additive ? 'lighter' : 'source-over';
227
227
  }
228
228
 
229
+ /** Draw text on overlay canvas in world space
230
+ * Automatically splits new lines into rows
231
+ * @param {String} text
232
+ * @param {Vector2} pos
233
+ * @param {Number} [size=1]
234
+ * @param {Color} [color=Color()]
235
+ * @param {Number} [lineWidth=0]
236
+ * @param {Color} [lineColor=Color(0,0,0)]
237
+ * @param {String} [textAlign='center']
238
+ * @param {String} [font=fontDefault]
239
+ * @param {CanvasRenderingContext2D} [context=overlayContext]
240
+ * @memberof Draw */
241
+ function drawText(text, pos, size=1, color, lineWidth=0, lineColor, textAlign, font, context)
242
+ {
243
+ drawTextScreen(text, worldToScreen(pos), size*cameraScale, color, lineWidth*cameraScale, lineColor, textAlign, font, context);
244
+ }
245
+
229
246
  /** Draw text on overlay canvas in screen space
230
247
  * Automatically splits new lines into rows
231
248
  * @param {String} text
@@ -235,6 +252,8 @@ function setBlendMode(additive, useWebGL=glEnable)
235
252
  * @param {Number} [lineWidth=0]
236
253
  * @param {Color} [lineColor=Color(0,0,0)]
237
254
  * @param {String} [textAlign='center']
255
+ * @param {String} [font=fontDefault]
256
+ * @param {CanvasRenderingContext2D} [context=overlayContext]
238
257
  * @memberof Draw */
239
258
  function drawTextScreen(text, pos, size=1, color=new Color, lineWidth=0, lineColor=new Color(0,0,0), textAlign='center', font=fontDefault, context=overlayContext)
240
259
  {
@@ -255,21 +274,6 @@ function drawTextScreen(text, pos, size=1, color=new Color, lineWidth=0, lineCol
255
274
  });
256
275
  }
257
276
 
258
- /** Draw text on overlay canvas in world space
259
- * Automatically splits new lines into rows
260
- * @param {String} text
261
- * @param {Vector2} pos
262
- * @param {Number} [size=1]
263
- * @param {Color} [color=Color()]
264
- * @param {Number} [lineWidth=0]
265
- * @param {Color} [lineColor=Color(0,0,0)]
266
- * @param {String} [textAlign='center']
267
- * @memberof Draw */
268
- function drawText(text, pos, size=1, color, lineWidth=0, lineColor, textAlign, font)
269
- {
270
- drawTextScreen(text, worldToScreen(pos), size*cameraScale, color, lineWidth*cameraScale, lineColor, textAlign, font, mainContext);
271
- }
272
-
273
277
  ///////////////////////////////////////////////////////////////////////////////
274
278
 
275
279
  let engineFontImage;
@@ -196,6 +196,11 @@ const setShowWatermark = (show)=> showWatermark = show;
196
196
  * @memberof Debug */
197
197
  const setGodMode = (enable)=> godMode = enable;
198
198
 
199
+ /** Set key code used to toggle debug mode, Esc by default
200
+ * @param {Number} key
201
+ * @memberof Debug */
202
+ const setDebugKey = (key)=> debugKey = key;
203
+
199
204
  export {
200
205
  // Setters for global variables
201
206
  setCameraPos,
@@ -236,6 +241,7 @@ export {
236
241
  setMedalsPreventUnlock,
237
242
  setShowWatermark,
238
243
  setGodMode,
244
+ setDebugKey,
239
245
 
240
246
  // Settings
241
247
  canvasMaxSize,
@@ -322,8 +328,8 @@ export {
322
328
  Color,
323
329
  Timer,
324
330
  vec2,
325
- colorRGBA,
326
- colorHSLA,
331
+ rgb,
332
+ hsl,
327
333
 
328
334
  // Base
329
335
  EngineObject,