littlejsengine 1.6.6 → 1.6.92

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 (57) hide show
  1. package/README.md +51 -35
  2. package/build/littlejs.d.ts +71 -80
  3. package/build/littlejs.esm.js +162 -139
  4. package/build/littlejs.esm.min.js +1 -1
  5. package/build/littlejs.js +159 -129
  6. package/build/littlejs.min.js +1 -1
  7. package/build/littlejs.release.js +1942 -1907
  8. package/examples/breakout/game.js +5 -1
  9. package/examples/breakout/index.html +5 -5
  10. package/examples/breakoutTutorial/README.md +6 -6
  11. package/examples/breakoutTutorial/game.js +3 -0
  12. package/examples/breakoutTutorial/index.html +3 -3
  13. package/examples/electron/build.js +105 -0
  14. package/examples/electron/game.js +4 -2
  15. package/examples/electron/index.html +13 -2
  16. package/examples/electron/package.json +5 -3
  17. package/examples/empty/game.js +3 -1
  18. package/examples/empty/index.html +1 -1
  19. package/examples/js13k/build.bat +2 -0
  20. package/examples/js13k/build.js +110 -0
  21. package/examples/js13k/game.js +109 -0
  22. package/examples/js13k/index.html +18 -0
  23. package/examples/js13k/tiles.png +0 -0
  24. package/examples/module/game.js +9 -3
  25. package/examples/module/index.html +2 -2
  26. package/examples/particles/index.html +7 -13
  27. package/examples/platformer/game.js +5 -2
  28. package/examples/platformer/gameEffects.js +1 -2
  29. package/examples/platformer/gamePlayer.js +2 -2
  30. package/examples/platformer/index.html +8 -8
  31. package/examples/puzzle/game.js +5 -3
  32. package/examples/puzzle/index.html +4 -4
  33. package/examples/starter/build.bat +2 -78
  34. package/examples/starter/build.js +109 -0
  35. package/examples/starter/game.js +4 -1
  36. package/examples/starter/index.html +15 -18
  37. package/examples/stress/index.html +2 -4
  38. package/examples/typescript/build.bat +2 -14
  39. package/examples/typescript/build.js +31 -0
  40. package/examples/typescript/game.js +94 -89
  41. package/examples/typescript/game.ts +9 -3
  42. package/examples/typescript/index.html +2 -2
  43. package/package.json +2 -2
  44. package/src/engine.js +3 -3
  45. package/src/engineAudio.js +2 -2
  46. package/src/engineBuild.bat +2 -132
  47. package/src/engineBuild.js +143 -0
  48. package/src/engineDebug.js +4 -10
  49. package/src/engineDraw.js +12 -4
  50. package/src/engineExport.js +1 -8
  51. package/src/engineInput.js +1 -1
  52. package/src/engineObject.js +13 -11
  53. package/src/engineParticles.js +6 -6
  54. package/src/engineRelease.js +0 -1
  55. package/src/engineTileLayer.js +31 -18
  56. package/src/engineUtilities.js +74 -61
  57. package/examples/electron/build.bat +0 -52
@@ -1,4 +1,4 @@
1
- <html><head>
1
+ <!DOCTYPE html><head>
2
2
  <title>Little TypeScript Demo</title>
3
3
  <meta name=viewport content=width=device-width,height=device-height,initial-scale=1,maximum-scale=1>
4
4
  <meta name=apple-mobile-web-app-capable content=yes>
@@ -7,4 +7,4 @@
7
7
  </head><body>
8
8
 
9
9
  <!-- Add your game scripts here -->
10
- <script src=game.js?166 type=module></script>
10
+ <script src=game.js?1691 type=module></script>
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "littlejsengine",
3
- "version": "1.6.6",
3
+ "version": "1.6.92",
4
4
  "description": "LittleJS - Tiny and Fast HTML5 Game Engine",
5
5
  "main": "build/littlejs.esm.js",
6
6
  "repository": {
@@ -23,7 +23,7 @@
23
23
  },
24
24
  "homepage": "https://github.com/KilledByAPixel/LittleJS",
25
25
  "scripts": {
26
- "build": "cd src && engineBuild.bat"
26
+ "build": "node src/engineBuild.js"
27
27
  },
28
28
  "devDependencies": {
29
29
  "google-closure-compiler": "~20230502.0.0",
package/src/engine.js CHANGED
@@ -30,7 +30,7 @@ const engineName = 'LittleJS';
30
30
  * @type {String}
31
31
  * @default
32
32
  * @memberof Engine */
33
- const engineVersion = '1.6.6';
33
+ const engineVersion = '1.6.92';
34
34
 
35
35
  /** Frames per second to update objects
36
36
  * @type {Number}
@@ -120,7 +120,7 @@ function engineInit(gameInit, gameUpdate, gameUpdatePost, gameRender, gameRender
120
120
  // set canvas style
121
121
  const styleCanvas = 'position:absolute;' +
122
122
  'top:50%;left:50%;transform:translate(-50%,-50%);' + // center the canvas
123
- (canvasPixelated?'image-rendering:pixelated':''); // set pixelated rendering
123
+ (canvasPixelated?'image-rendering:pixelated':''); // set pixelated rendering
124
124
  (glCanvas||mainCanvas).style = mainCanvas.style = overlayCanvas.style = styleCanvas;
125
125
 
126
126
  gameInit();
@@ -128,7 +128,7 @@ function engineInit(gameInit, gameUpdate, gameUpdatePost, gameRender, gameRender
128
128
  };
129
129
 
130
130
  // frame time tracking
131
- let frameTimeLastMS = 0, frameTimeBufferMS, averageFPS;
131
+ let frameTimeLastMS = 0, frameTimeBufferMS = 0, averageFPS;
132
132
 
133
133
  // main update loop
134
134
  function engineUpdate(frameTimeMS=0)
@@ -438,7 +438,7 @@ function zzfxM(instruments, patterns, sequence, BPM = 125)
438
438
  patternChannel = patterns[patternIndex][channelIndex] || [0, 0, 0];
439
439
 
440
440
  // check if there are more channels
441
- hasMore |= !!patterns[patternIndex][channelIndex];
441
+ hasMore ||= !!patterns[patternIndex][channelIndex];
442
442
 
443
443
  // get next offset, use the length of first channel
444
444
  nextSampleOffset = outSampleOffset + (patterns[patternIndex][0].length - 2 - !notFirstBeat) * beatLength;
@@ -451,7 +451,7 @@ function zzfxM(instruments, patterns, sequence, BPM = 125)
451
451
 
452
452
  // stop if end, different instrument or new note
453
453
  stop = i == patternChannel.length + isSequenceEnd - 1 && isSequenceEnd ||
454
- instrument != (patternChannel[0] || 0) | note | 0;
454
+ instrument != (patternChannel[0] || 0) || note;
455
455
 
456
456
  // fill buffer with samples for previous beat, most cpu intensive part
457
457
  for (j = 0; j < beatLength && notFirstBeat;
@@ -1,132 +1,2 @@
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
1
+ rem LittleJS Build Script
2
+ call npm run build
@@ -0,0 +1,143 @@
1
+ #!/usr/bin/env node
2
+
3
+ /**
4
+ * LittleJS Build System
5
+ * - Combine input files
6
+ * - Run custom build steps
7
+ * - Check for errors
8
+ * - Output to build folder
9
+ * @namespace Build
10
+ */
11
+
12
+ const ENGINE_NAME = 'littlejs';
13
+ const BUILD_FOLDER = 'build';
14
+ const SOURCE_FOLDER = 'src';
15
+ const engineSourceFiles =
16
+ [
17
+ `${SOURCE_FOLDER}/engineUtilities.js`,
18
+ `${SOURCE_FOLDER}/engineSettings.js`,
19
+ `${SOURCE_FOLDER}/engineObject.js`,
20
+ `${SOURCE_FOLDER}/engineDraw.js`,
21
+ `${SOURCE_FOLDER}/engineInput.js`,
22
+ `${SOURCE_FOLDER}/engineAudio.js`,
23
+ `${SOURCE_FOLDER}/engineTileLayer.js`,
24
+ `${SOURCE_FOLDER}/engineParticles.js`,
25
+ `${SOURCE_FOLDER}/engineMedals.js`,
26
+ `${SOURCE_FOLDER}/engineWebGL.js`,
27
+ `${SOURCE_FOLDER}/engine.js`,
28
+ ];
29
+
30
+ console.log('Choo Choo... Building LittleJS Engine!');
31
+ const startTime = Date.now();
32
+ const fs = require('node:fs');
33
+ const child_process = require('node:child_process');
34
+
35
+ try
36
+ {
37
+ // Setup build folder
38
+ fs.rmSync(BUILD_FOLDER, { recursive: true, force: true });
39
+ fs.mkdirSync(BUILD_FOLDER);
40
+ }
41
+ catch (e) { handleError(e, 'Failed to create build folder!'); }
42
+
43
+ Build
44
+ (
45
+ 'Build Engine -- all',
46
+ `${BUILD_FOLDER}/${ENGINE_NAME}.js`,
47
+ [`${SOURCE_FOLDER}/engineDebug.js`].concat(engineSourceFiles)
48
+ );
49
+
50
+ Build
51
+ (
52
+ 'Build Engine -- release',
53
+ `${BUILD_FOLDER}/${ENGINE_NAME}.release.js`,
54
+ [`${SOURCE_FOLDER}/engineRelease.js`].concat(engineSourceFiles)
55
+ );
56
+
57
+ Build
58
+ (
59
+ 'Build Engine -- minified',
60
+ `${BUILD_FOLDER}/${ENGINE_NAME}.min.js`,
61
+ [`${BUILD_FOLDER}/${ENGINE_NAME}.release.js`],
62
+ [closureCompilerStep, uglifyBuildStep]
63
+ );
64
+
65
+ Build
66
+ (
67
+ 'Build Engine -- ESM',
68
+ `${BUILD_FOLDER}/${ENGINE_NAME}.esm.js`,
69
+ [`${BUILD_FOLDER}/${ENGINE_NAME}.js`, `${SOURCE_FOLDER}/engineExport.js`],
70
+ [typeScriptBuildStep]
71
+ );
72
+
73
+ Build
74
+ (
75
+ 'Build Engine -- ESM minified release',
76
+ `${BUILD_FOLDER}/${ENGINE_NAME}.esm.min.js`,
77
+ [`${BUILD_FOLDER}/${ENGINE_NAME}.min.js`, `${SOURCE_FOLDER}/engineExport.js`],
78
+ [uglifyBuildStep]
79
+ );
80
+
81
+ console.log(`Engine built in ${((Date.now() - startTime)/1e3).toFixed(2)} seconds!`);
82
+
83
+ ///////////////////////////////////////////////////////////////////////////////
84
+
85
+ // A single build with its own source files, build steps, and output file
86
+ // - each build step is a callback that accepts a single filename
87
+ function Build(message, outputFile, files=[], buildSteps=[])
88
+ {
89
+ console.log(message);
90
+
91
+ // copy files into a buffer
92
+ let buffer = '';
93
+ for (const file of files)
94
+ buffer += fs.readFileSync(file) + '\n';
95
+
96
+ // output file
97
+ fs.writeFileSync(outputFile, buffer, {flag: 'w+'});
98
+
99
+ // execute build steps in order
100
+ for (const buildStep of buildSteps)
101
+ buildStep(outputFile);
102
+ }
103
+
104
+ // Process with Closure Compiler to minify and check for errors
105
+ function closureCompilerStep(filename)
106
+ {
107
+ const filenameTemp = filename + '.tmp';
108
+ fs.copyFileSync(filename, filenameTemp);
109
+ try
110
+ {
111
+ child_process.execSync(`npx google-closure-compiler --js=${filenameTemp} --js_output_file=${filename} --language_out=ECMASCRIPT_2021 --warning_level=VERBOSE --jscomp_off=*`);
112
+ fs.rmSync(filenameTemp);
113
+ }
114
+ catch (e) { handleError(e, 'Failed to run Closure Compiler step!'); }
115
+ };
116
+
117
+ // Process with Uglify to minify
118
+ function uglifyBuildStep(filename)
119
+ {
120
+ try
121
+ {
122
+ child_process.execSync(`npx uglifyjs ${filename} -o ${filename}`);
123
+ }
124
+ catch (e) { handleError(e,'Failed to run Uglify minification step!'); }
125
+ };
126
+
127
+ // Build TypeScript definitions
128
+ function typeScriptBuildStep(filename)
129
+ {
130
+ try
131
+ {
132
+ child_process.execSync(`npx tsc ${filename} --declaration --allowJs --emitDeclarationOnly --outFile ${BUILD_FOLDER}/${ENGINE_NAME}.d.ts`);
133
+ }
134
+ catch (e) { handleError(e, 'Failed to run TypeScript build step!'); }
135
+ };
136
+
137
+ // display the error and exit
138
+ function handleError(e,message)
139
+ {
140
+ console.error(e);
141
+ console.error(message);
142
+ process.exit(1);
143
+ }
@@ -34,12 +34,6 @@ const debugPointSize = .5;
34
34
  * @memberof Debug */
35
35
  let showWatermark = 1;
36
36
 
37
- /** True if god mode is enabled, handle this however you want
38
- * @type {Boolean}
39
- * @default
40
- * @memberof Debug */
41
- let godMode = 0;
42
-
43
37
  /** Key code used to toggle debug mode, Esc by default
44
38
  * @type {Boolean}
45
39
  * @default
@@ -180,7 +174,7 @@ function debugUpdate()
180
174
  if (keyWasPressed(51)) // 3
181
175
  debugGamepads = !debugGamepads;
182
176
  if (keyWasPressed(52)) // 4
183
- godMode = !godMode;
177
+ debugRaycast = !debugRaycast;
184
178
  if (keyWasPressed(53)) // 5
185
179
  debugTakeScreenshot = 1;
186
180
  //if (keyWasPressed(54)) // 6
@@ -359,8 +353,8 @@ function debugRender()
359
353
  overlayContext.fillText('2: Debug Particles', x, y += h);
360
354
  overlayContext.fillStyle = debugGamepads ? '#f00' : '#fff';
361
355
  overlayContext.fillText('3: Debug Gamepads', x, y += h);
362
- overlayContext.fillStyle = godMode ? '#f00' : '#fff';
363
- overlayContext.fillText('4: God Mode', x, y += h);
356
+ overlayContext.fillStyle = debugRaycast ? '#f00' : '#fff';
357
+ overlayContext.fillText('4: Debug Raycasts', x, y += h);
364
358
  overlayContext.fillStyle = '#fff';
365
359
  overlayContext.fillText('5: Save Screenshot', x, y += h);
366
360
 
@@ -385,7 +379,7 @@ function debugRender()
385
379
  {
386
380
  overlayContext.fillText(debugPhysics ? 'Debug Physics' : '', x, y += h);
387
381
  overlayContext.fillText(debugParticles ? 'Debug Particles' : '', x, y += h);
388
- overlayContext.fillText(godMode ? 'God Mode' : '', x, y += h);
382
+ overlayContext.fillText(debugRaycast ? 'Debug Raycasts' : '', x, y += h);
389
383
  overlayContext.fillText(debugGamepads ? 'Debug Gamepads' : '', x, y += h);
390
384
  }
391
385
 
package/src/engineDraw.js CHANGED
@@ -63,7 +63,11 @@ let tileImageSize, tileImageFixBleed, drawCount;
63
63
  function screenToWorld(screenPos)
64
64
  {
65
65
  ASSERT(mainCanvasSize.x && mainCanvasSize.y, 'mainCanvasSize is invalid');
66
- return screenPos.add(vec2(.5)).subtract(mainCanvasSize.scale(.5)).multiply(vec2(1/cameraScale,-1/cameraScale)).add(cameraPos);
66
+ return screenPos
67
+ .add(vec2(.5))
68
+ .subtract(mainCanvasSize.scale(.5))
69
+ .multiply(vec2(1/cameraScale,-1/cameraScale))
70
+ .add(cameraPos);
67
71
  }
68
72
 
69
73
  /** Convert from world to screen space coordinates
@@ -74,7 +78,11 @@ function screenToWorld(screenPos)
74
78
  function worldToScreen(worldPos)
75
79
  {
76
80
  ASSERT(mainCanvasSize.x && mainCanvasSize.y, 'mainCanvasSize is invalid');
77
- return worldPos.subtract(cameraPos).multiply(vec2(cameraScale,-cameraScale)).add(mainCanvasSize.scale(.5)).subtract(vec2(.5));
81
+ return worldPos
82
+ .subtract(cameraPos)
83
+ .multiply(vec2(cameraScale,-cameraScale))
84
+ .add(mainCanvasSize.scale(.5))
85
+ .subtract(vec2(.5));
78
86
  }
79
87
 
80
88
  /** Draw textured tile centered in world space, with color applied if using WebGL
@@ -88,8 +96,8 @@ function worldToScreen(worldPos)
88
96
  * @param {Color} [additiveColor=Color(0,0,0,0)] - Additive color to be applied
89
97
  * @param {Boolean} [useWebGL=glEnable] - Use accelerated WebGL rendering
90
98
  * @memberof Draw */
91
- function drawTile(pos, size=vec2(1), tileIndex=-1, tileSize=tileSizeDefault, color=new Color, angle=0, mirror,
92
- additiveColor=new Color(0,0,0,0), useWebGL=glEnable)
99
+ function drawTile(pos, size=vec2(1), tileIndex=-1, tileSize=tileSizeDefault, color=new Color,
100
+ angle=0, mirror, additiveColor=new Color(0,0,0,0), useWebGL=glEnable)
93
101
  {
94
102
  showWatermark && ++drawCount;
95
103
  if (glEnable && useWebGL)
@@ -181,18 +181,13 @@ function setMedalDisplayIconSize(size) { medalDisplayIconSize = size; }
181
181
  /** Set to stop medals from being unlockable
182
182
  * @param {Boolean} preventUnlock
183
183
  * @memberof Settings */
184
- function setMedalsPreventUnlock(prevent) { medalsPreventUnlock = prevent; }
184
+ function setMedalsPreventUnlock(preventUnlock) { medalsPreventUnlock = preventUnlock; }
185
185
 
186
186
  /** Set if watermark with FPS should be shown
187
187
  * @param {Boolean} show
188
188
  * @memberof Debug */
189
189
  function setShowWatermark(show) { showWatermark = show; }
190
190
 
191
- /** Set if god mode is enabled
192
- * @param {Boolean} enable
193
- * @memberof Debug */
194
- function setGodMode(enable) { godMode = enable; }
195
-
196
191
  /** Set key code used to toggle debug mode, Esc by default
197
192
  * @param {Number} key
198
193
  * @memberof Debug */
@@ -237,7 +232,6 @@ export {
237
232
  setMedalDisplayIconSize,
238
233
  setMedalsPreventUnlock,
239
234
  setShowWatermark,
240
- setGodMode,
241
235
  setDebugKey,
242
236
 
243
237
  // Settings
@@ -280,7 +274,6 @@ export {
280
274
  // Globals
281
275
  debug,
282
276
  showWatermark,
283
- godMode,
284
277
 
285
278
  // Debug
286
279
  ASSERT,
@@ -431,7 +431,7 @@ function touchGamepadRender()
431
431
  const rightCenter = vec2(mainCanvasSize.x-touchGamepadSize, mainCanvasSize.y-touchGamepadSize);
432
432
  for (let i=4; i--;)
433
433
  {
434
- const pos = rightCenter.add((new Vector2).setAngle(i*PI/2, touchGamepadSize/2));
434
+ const pos = rightCenter.add(vec2().setAngle(i*PI/2, touchGamepadSize/2));
435
435
  overlayContext.fillStyle = touchGamepadButtons[i] ? '#fff' : '#000';
436
436
  overlayContext.beginPath();
437
437
  overlayContext.arc(pos.x, pos.y, touchGamepadSize/4, 0,9);
@@ -78,7 +78,7 @@ class EngineObject
78
78
  /** @property {Number} [renderOrder=0] - Objects are sorted by render order */
79
79
  this.renderOrder = renderOrder;
80
80
  /** @property {Vector2} [velocity=Vector2()] - Velocity of the object */
81
- this.velocity = new Vector2();
81
+ this.velocity = vec2();
82
82
  /** @property {Number} [angleVelocity=0] - Angular velocity of the object */
83
83
  this.angleVelocity = 0;
84
84
 
@@ -138,15 +138,17 @@ class EngineObject
138
138
  for (const o of engineObjectsCollide)
139
139
  {
140
140
  // non solid objects don't collide with eachother
141
- if (!this.isSolid & !o.isSolid || o.destroyed || o.parent || o == this)
141
+ if (!this.isSolid && !o.isSolid || o.destroyed || o.parent || o == this)
142
142
  continue;
143
143
 
144
144
  // check collision
145
145
  if (!isOverlapping(this.pos, this.size, o.pos, o.size))
146
146
  continue;
147
147
 
148
- // pass collision to objects
149
- if (!this.collideWithObject(o) | !o.collideWithObject(this))
148
+ // notify objects of collision and check if should be resolved
149
+ const collide1 = this.collideWithObject(o);
150
+ const collide2 = o.collideWithObject(this);
151
+ if (!collide1 || !collide2)
150
152
  continue;
151
153
 
152
154
  if (isOverlapping(oldPos, this.size, o.pos, o.size))
@@ -171,7 +173,7 @@ class EngineObject
171
173
  const isBlockedY = abs(oldPos.x - o.pos.x)*2 < sizeBoth.x;
172
174
  const elasticity = max(this.elasticity, o.elasticity);
173
175
 
174
- if (smallStepUp | isBlockedY | !isBlockedX) // resolve y collision
176
+ if (smallStepUp || isBlockedY || !isBlockedX) // resolve y collision
175
177
  {
176
178
  // push outside object collision
177
179
  this.pos.y = o.pos.y + (sizeBoth.y/2 + epsilon) * sign(oldPos.y - o.pos.y);
@@ -200,7 +202,7 @@ class EngineObject
200
202
  o.velocity.y = lerp(elasticity, inelastic, elastic1);
201
203
  }
202
204
  }
203
- if (!smallStepUp & isBlockedX) // resolve x collision
205
+ if (!smallStepUp && isBlockedX) // resolve x collision
204
206
  {
205
207
  // push outside collision
206
208
  this.pos.x = o.pos.x + (sizeBoth.x/2 + epsilon) * sign(oldPos.x - o.pos.x);
@@ -235,9 +237,9 @@ class EngineObject
235
237
  if (!tileCollisionTest(oldPos, this.size, this))
236
238
  {
237
239
  // test which side we bounced off (or both if a corner)
238
- const isBlockedY = tileCollisionTest(new Vector2(oldPos.x, this.pos.y), this.size, this);
239
- const isBlockedX = tileCollisionTest(new Vector2(this.pos.x, oldPos.y), this.size, this);
240
- if (isBlockedY | !isBlockedX)
240
+ const isBlockedY = tileCollisionTest(vec2(oldPos.x, this.pos.y), this.size, this);
241
+ const isBlockedX = tileCollisionTest(vec2(this.pos.x, oldPos.y), this.size, this);
242
+ if (isBlockedY || !isBlockedX)
241
243
  {
242
244
  // set if landed on ground
243
245
  this.groundObject = wasMovingDown;
@@ -300,7 +302,7 @@ class EngineObject
300
302
  * @param {EngineObject} object - the object to test against
301
303
  * @return {Boolean} - true if the collision should be resolved
302
304
  */
303
- collideWithObject(o) { return 1; }
305
+ collideWithObject(object) { return 1; }
304
306
 
305
307
  /** How long since the object was created
306
308
  * @return {Number} */
@@ -308,7 +310,7 @@ class EngineObject
308
310
 
309
311
  /** Apply acceleration to this object (adjust velocity, not affected by mass)
310
312
  * @param {Vector2} acceleration */
311
- applyAcceleration(a) { if (this.mass) this.velocity = this.velocity.add(a); }
313
+ applyAcceleration(acceleration) { if (this.mass) this.velocity = this.velocity.add(acceleration); }
312
314
 
313
315
  /** Apply force to this object (adjust velocity, affected by mass)
314
316
  * @param {Vector2} force */
@@ -85,7 +85,7 @@ class ParticleEmitter extends EngineObject
85
85
  localSpace
86
86
  )
87
87
  {
88
- super(pos, new Vector2, tileIndex, tileSize, angle, undefined, renderOrder);
88
+ super(pos, vec2(), tileIndex, tileSize, angle, undefined, renderOrder);
89
89
 
90
90
  // emitter settings
91
91
  /** @property {Number} - World space size of the emitter (float for circle diameter, vec2 for rect) */
@@ -152,7 +152,7 @@ class ParticleEmitter extends EngineObject
152
152
  this.parent && super.update();
153
153
 
154
154
  // update emitter
155
- if (!this.emitTime | this.getAliveTime() <= this.emitTime)
155
+ if (!this.emitTime || this.getAliveTime() <= this.emitTime)
156
156
  {
157
157
  // emit particles
158
158
  if (this.emitRate * particleEmitRateScale)
@@ -174,7 +174,7 @@ class ParticleEmitter extends EngineObject
174
174
  {
175
175
  // spawn a particle
176
176
  let pos = this.emitSize.x != undefined ? // check if vec2 was used for size
177
- (new Vector2(rand(-.5,.5), rand(-.5,.5)))
177
+ vec2(rand(-.5,.5), rand(-.5,.5))
178
178
  .multiply(this.emitSize).rotate(this.angle) // box emitter
179
179
  : randInCircle(this.emitSize/2); // circle emitter
180
180
  let angle = rand(this.particleConeAngle, -this.particleConeAngle);
@@ -204,7 +204,7 @@ class ParticleEmitter extends EngineObject
204
204
  // build particle settings
205
205
  particle.colorStart = colorStart;
206
206
  particle.colorEndDelta = colorEnd.subtract(colorStart);
207
- particle.velocity = (new Vector2).setAngle(velocityAngle, speed);
207
+ particle.velocity = vec2().setAngle(velocityAngle, speed);
208
208
  particle.angleVelocity = angleSpeed;
209
209
  particle.lifeTime = particleTime;
210
210
  particle.sizeStart = sizeStart;
@@ -249,7 +249,7 @@ class Particle extends EngineObject
249
249
  * @param {Number} [angle=0] - Angle to rotate the particle
250
250
  */
251
251
  constructor(pos, tileIndex, tileSize, angle)
252
- { super(pos, new Vector2, tileIndex, tileSize, angle); }
252
+ { super(pos, vec2(), tileIndex, tileSize, angle); }
253
253
 
254
254
  /** Render the particle, automatically called each frame, sorted by renderOrder */
255
255
  render()
@@ -257,7 +257,7 @@ class Particle extends EngineObject
257
257
  // modulate size and color
258
258
  const p = min((time - this.spawnTime) / this.lifeTime, 1);
259
259
  const radius = this.sizeStart + p * this.sizeEndDelta;
260
- const size = new Vector2(radius, radius);
260
+ const size = vec2(radius);
261
261
  const fadeRate = this.fadeRate/2;
262
262
  const color = new Color(
263
263
  this.colorStart.r + p * this.colorEndDelta.r,
@@ -8,7 +8,6 @@
8
8
  'use strict';
9
9
 
10
10
  let showWatermark = 0;
11
- let godMode = 0;
12
11
  let debugKeyCode = 0;
13
12
  const debug = 0;
14
13
  const debugOverlay = 0;