littlejsengine 1.11.9 → 1.11.13

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 (44) hide show
  1. package/README.md +3 -3
  2. package/dist/littlejs.d.ts +485 -492
  3. package/dist/littlejs.esm.js +548 -529
  4. package/dist/littlejs.esm.min.js +1 -1
  5. package/dist/littlejs.js +546 -525
  6. package/dist/littlejs.min.js +1 -1
  7. package/dist/littlejs.release.js +502 -484
  8. package/examples/htmlMenu/game.js +11 -1
  9. package/examples/htmlMenu/index.html +1 -10
  10. package/examples/module/game.js +2 -2
  11. package/examples/shorts/base.html +1 -1
  12. package/examples/starter/build/index.html +2 -0
  13. package/examples/starter/build/index.js +1 -0
  14. package/examples/starter/build/tiles.png +0 -0
  15. package/examples/starter/build.js +13 -3
  16. package/examples/starter/game.js +8 -1
  17. package/examples/starter/game.zip +0 -0
  18. package/examples/typescript/build/dist/littlejs.esm.js +4834 -0
  19. package/examples/typescript/build/examples/typescript/build.js +24 -0
  20. package/examples/typescript/build/examples/typescript/game.js +102 -0
  21. package/examples/typescript/build.bat +5 -0
  22. package/examples/typescript/build.js +33 -0
  23. package/examples/typescript/game.js +102 -0
  24. package/examples/typescript/game.ts +134 -0
  25. package/examples/typescript/index.html +10 -0
  26. package/examples/typescript/tiles.png +0 -0
  27. package/examples/typescript/tsconfig.json +8 -0
  28. package/package.json +1 -1
  29. package/plugins/newgrounds.js +44 -35
  30. package/plugins/postProcess.js +18 -4
  31. package/plugins/uiSystem.js +196 -30
  32. package/src/engine.js +21 -20
  33. package/src/engineAudio.js +59 -59
  34. package/src/engineDebug.js +44 -41
  35. package/src/engineDraw.js +58 -58
  36. package/src/engineExport.js +2 -4
  37. package/src/engineInput.js +40 -35
  38. package/src/engineMedals.js +21 -11
  39. package/src/engineObject.js +42 -35
  40. package/src/engineParticles.js +10 -10
  41. package/src/engineSettings.js +77 -82
  42. package/src/engineTileLayer.js +21 -21
  43. package/src/engineUtilities.js +150 -150
  44. package/src/engineWebGL.js +3 -3
@@ -48,20 +48,20 @@ class Sound
48
48
  {
49
49
  /** Create a sound object and cache the zzfx samples for later use
50
50
  * @param {Array} zzfxSound - Array of zzfx parameters, ex. [.5,.5]
51
- * @param {Number} [range=soundDefaultRange] - World space max range of sound, will not play if camera is farther away
52
- * @param {Number} [taper=soundDefaultTaper] - At what percentage of range should it start tapering
51
+ * @param {number} [range=soundDefaultRange] - World space max range of sound, will not play if camera is farther away
52
+ * @param {number} [taper=soundDefaultTaper] - At what percentage of range should it start tapering
53
53
  */
54
54
  constructor(zzfxSound, range=soundDefaultRange, taper=soundDefaultTaper)
55
55
  {
56
56
  if (!soundEnable || headlessMode) return;
57
57
 
58
- /** @property {Number} - World space max range of sound, will not play if camera is farther away */
58
+ /** @property {number} - World space max range of sound, will not play if camera is farther away */
59
59
  this.range = range;
60
60
 
61
- /** @property {Number} - At what percentage of range should it start tapering off */
61
+ /** @property {number} - At what percentage of range should it start tapering off */
62
62
  this.taper = taper;
63
63
 
64
- /** @property {Number} - How much to randomize frequency each time sound plays */
64
+ /** @property {number} - How much to randomize frequency each time sound plays */
65
65
  this.randomness = 0;
66
66
 
67
67
  if (zzfxSound)
@@ -77,10 +77,10 @@ class Sound
77
77
 
78
78
  /** Play the sound
79
79
  * @param {Vector2} [pos] - World space position to play the sound, sound is not attenuated if null
80
- * @param {Number} [volume] - How much to scale volume by (in addition to range fade)
81
- * @param {Number} [pitch] - How much to scale pitch by (also adjusted by this.randomness)
82
- * @param {Number} [randomnessScale] - How much to scale randomness
83
- * @param {Boolean} [loop] - Should the sound loop
80
+ * @param {number} [volume] - How much to scale volume by (in addition to range fade)
81
+ * @param {number} [pitch] - How much to scale pitch by (also adjusted by this.randomness)
82
+ * @param {number} [randomnessScale] - How much to scale randomness
83
+ * @param {boolean} [loop] - Should the sound loop
84
84
  * @return {AudioBufferSourceNode} - The audio source node
85
85
  */
86
86
  play(pos, volume=1, pitch=1, randomnessScale=1, loop=false)
@@ -115,7 +115,7 @@ class Sound
115
115
  }
116
116
 
117
117
  /** Set the sound volume of the most recently played instance of this sound
118
- * @param {Number} [volume] - How much to scale volume by
118
+ * @param {number} [volume] - How much to scale volume by
119
119
  */
120
120
  setVolume(volume=1)
121
121
  {
@@ -137,22 +137,22 @@ class Sound
137
137
  getSource() { return this.source; }
138
138
 
139
139
  /** Play the sound as a note with a semitone offset
140
- * @param {Number} semitoneOffset - How many semitones to offset pitch
140
+ * @param {number} semitoneOffset - How many semitones to offset pitch
141
141
  * @param {Vector2} [pos] - World space position to play the sound, sound is not attenuated if null
142
- * @param {Number} [volume=1] - How much to scale volume by (in addition to range fade)
142
+ * @param {number} [volume=1] - How much to scale volume by (in addition to range fade)
143
143
  * @return {AudioBufferSourceNode} - The audio source node
144
144
  */
145
145
  playNote(semitoneOffset, pos, volume)
146
146
  { return this.play(pos, volume, 2**(semitoneOffset/12), 0); }
147
147
 
148
148
  /** Get how long this sound is in seconds
149
- * @return {Number} - How long the sound is in seconds (undefined if loading)
149
+ * @return {number} - How long the sound is in seconds (undefined if loading)
150
150
  */
151
151
  getDuration()
152
152
  { return this.sampleChannels && this.sampleChannels[0].length / this.sampleRate; }
153
153
 
154
154
  /** Check if sound is loading, for sounds fetched from a url
155
- * @return {Boolean} - True if sound is loading and not ready to play
155
+ * @return {boolean} - True if sound is loading and not ready to play
156
156
  */
157
157
  isLoading() { return !this.sampleChannels; }
158
158
  }
@@ -170,10 +170,10 @@ class Sound
170
170
  class SoundWave extends Sound
171
171
  {
172
172
  /** Create a sound object and cache the wave file for later use
173
- * @param {String} filename - Filename of audio file to load
174
- * @param {Number} [randomness] - How much to randomize frequency each time sound plays
175
- * @param {Number} [range=soundDefaultRange] - World space max range of sound, will not play if camera is farther away
176
- * @param {Number} [taper=soundDefaultTaper] - At what percentage of range should it start tapering off
173
+ * @param {string} filename - Filename of audio file to load
174
+ * @param {number} [randomness] - How much to randomize frequency each time sound plays
175
+ * @param {number} [range=soundDefaultRange] - World space max range of sound, will not play if camera is farther away
176
+ * @param {number} [taper=soundDefaultTaper] - At what percentage of range should it start tapering off
177
177
  * @param {Function} [onloadCallback] - callback function to call when sound is loaded
178
178
  */
179
179
  constructor(filename, randomness=0, range, taper, onloadCallback)
@@ -196,9 +196,9 @@ class SoundWave extends Sound
196
196
  }
197
197
 
198
198
  /** Play an mp3, ogg, or wav audio from a local file or url
199
- * @param {String} filename - Location of sound file to play
200
- * @param {Number} [volume] - How much to scale volume by
201
- * @param {Boolean} [loop] - True if the music should loop
199
+ * @param {string} filename - Location of sound file to play
200
+ * @param {number} [volume] - How much to scale volume by
201
+ * @param {boolean} [loop] - True if the music should loop
202
202
  * @return {SoundWave} - The sound object for this file
203
203
  * @memberof Audio */
204
204
  function playAudioFile(filename, volume=1, loop=false)
@@ -241,7 +241,7 @@ function playAudioFile(filename, volume=1, loop=false)
241
241
  class Music extends Sound
242
242
  {
243
243
  /** Create a music object and cache the zzfx music samples for later use
244
- * @param {[Array, Array, Array, Number]} zzfxMusic - Array of zzfx music parameters
244
+ * @param {[Array, Array, Array, number]} zzfxMusic - Array of zzfx music parameters
245
245
  */
246
246
  constructor(zzfxMusic)
247
247
  {
@@ -254,8 +254,8 @@ class Music extends Sound
254
254
  }
255
255
 
256
256
  /** Play the music
257
- * @param {Number} [volume=1] - How much to scale volume by
258
- * @param {Boolean} [loop] - True if the music should loop
257
+ * @param {number} [volume=1] - How much to scale volume by
258
+ * @param {boolean} [loop] - True if the music should loop
259
259
  * @return {AudioBufferSourceNode} - The audio source node
260
260
  */
261
261
  playMusic(volume, loop=false)
@@ -263,11 +263,11 @@ class Music extends Sound
263
263
  }
264
264
 
265
265
  /** Speak text with passed in settings
266
- * @param {String} text - The text to speak
267
- * @param {String} [language] - The language/accent to use (examples: en, it, ru, ja, zh)
268
- * @param {Number} [volume] - How much to scale volume by
269
- * @param {Number} [rate] - How quickly to speak
270
- * @param {Number} [pitch] - How much to change the pitch by
266
+ * @param {string} text - The text to speak
267
+ * @param {string} [language] - The language/accent to use (examples: en, it, ru, ja, zh)
268
+ * @param {number} [volume] - How much to scale volume by
269
+ * @param {number} [rate] - How quickly to speak
270
+ * @param {number} [pitch] - How much to change the pitch by
271
271
  * @return {SpeechSynthesisUtterance} - The utterance that was spoken
272
272
  * @memberof Audio */
273
273
  function speak(text, language='', volume=1, rate=1, pitch=1)
@@ -294,9 +294,9 @@ function speak(text, language='', volume=1, rate=1, pitch=1)
294
294
  function speakStop() {speechSynthesis && speechSynthesis.cancel();}
295
295
 
296
296
  /** Get frequency of a note on a musical scale
297
- * @param {Number} semitoneOffset - How many semitones away from the root note
298
- * @param {Number} [rootFrequency=220] - Frequency at semitone offset 0
299
- * @return {Number} - The frequency of the note
297
+ * @param {number} semitoneOffset - How many semitones away from the root note
298
+ * @param {number} [rootFrequency=220] - Frequency at semitone offset 0
299
+ * @return {number} - The frequency of the note
300
300
  * @memberof Audio */
301
301
  function getNoteFrequency(semitoneOffset, rootFrequency=220)
302
302
  { return rootFrequency * 2**(semitoneOffset/12); }
@@ -305,11 +305,11 @@ function getNoteFrequency(semitoneOffset, rootFrequency=220)
305
305
 
306
306
  /** Play cached audio samples with given settings
307
307
  * @param {Array} sampleChannels - Array of arrays of samples to play (for stereo playback)
308
- * @param {Number} [volume] - How much to scale volume by
309
- * @param {Number} [rate] - The playback rate to use
310
- * @param {Number} [pan] - How much to apply stereo panning
311
- * @param {Boolean} [loop] - True if the sound should loop when it reaches the end
312
- * @param {Number} [sampleRate=44100] - Sample rate for the sound
308
+ * @param {number} [volume] - How much to scale volume by
309
+ * @param {number} [rate] - The playback rate to use
310
+ * @param {number} [pan] - How much to apply stereo panning
311
+ * @param {boolean} [loop] - True if the sound should loop when it reaches the end
312
+ * @param {number} [sampleRate=44100] - Sample rate for the sound
313
313
  * @param {GainNode} [gainNode] - Optional gain node for volume control while playing
314
314
  * @return {AudioBufferSourceNode} - The audio node of the sound played
315
315
  * @memberof Audio */
@@ -368,27 +368,27 @@ function zzfx(...zzfxSound) { return playSamples([zzfxG(...zzfxSound)]); }
368
368
  const zzfxR = 44100;
369
369
 
370
370
  /** Generate samples for a ZzFX sound
371
- * @param {Number} [volume] - Volume scale (percent)
372
- * @param {Number} [randomness] - How much to randomize frequency (percent Hz)
373
- * @param {Number} [frequency] - Frequency of sound (Hz)
374
- * @param {Number} [attack] - Attack time, how fast sound starts (seconds)
375
- * @param {Number} [sustain] - Sustain time, how long sound holds (seconds)
376
- * @param {Number} [release] - Release time, how fast sound fades out (seconds)
377
- * @param {Number} [shape] - Shape of the sound wave
378
- * @param {Number} [shapeCurve] - Squareness of wave (0=square, 1=normal, 2=pointy)
379
- * @param {Number} [slide] - How much to slide frequency (kHz/s)
380
- * @param {Number} [deltaSlide] - How much to change slide (kHz/s/s)
381
- * @param {Number} [pitchJump] - Frequency of pitch jump (Hz)
382
- * @param {Number} [pitchJumpTime] - Time of pitch jump (seconds)
383
- * @param {Number} [repeatTime] - Resets some parameters periodically (seconds)
384
- * @param {Number} [noise] - How much random noise to add (percent)
385
- * @param {Number} [modulation] - Frequency of modulation wave, negative flips phase (Hz)
386
- * @param {Number} [bitCrush] - Resamples at a lower frequency in (samples*100)
387
- * @param {Number} [delay] - Overlap sound with itself for reverb and flanger effects (seconds)
388
- * @param {Number} [sustainVolume] - Volume level for sustain (percent)
389
- * @param {Number} [decay] - Decay time, how long to reach sustain after attack (seconds)
390
- * @param {Number} [tremolo] - Trembling effect, rate controlled by repeat time (percent)
391
- * @param {Number} [filter] - Filter cutoff frequency, positive for HPF, negative for LPF (Hz)
371
+ * @param {number} [volume] - Volume scale (percent)
372
+ * @param {number} [randomness] - How much to randomize frequency (percent Hz)
373
+ * @param {number} [frequency] - Frequency of sound (Hz)
374
+ * @param {number} [attack] - Attack time, how fast sound starts (seconds)
375
+ * @param {number} [sustain] - Sustain time, how long sound holds (seconds)
376
+ * @param {number} [release] - Release time, how fast sound fades out (seconds)
377
+ * @param {number} [shape] - Shape of the sound wave
378
+ * @param {number} [shapeCurve] - Squareness of wave (0=square, 1=normal, 2=pointy)
379
+ * @param {number} [slide] - How much to slide frequency (kHz/s)
380
+ * @param {number} [deltaSlide] - How much to change slide (kHz/s/s)
381
+ * @param {number} [pitchJump] - Frequency of pitch jump (Hz)
382
+ * @param {number} [pitchJumpTime] - Time of pitch jump (seconds)
383
+ * @param {number} [repeatTime] - Resets some parameters periodically (seconds)
384
+ * @param {number} [noise] - How much random noise to add (percent)
385
+ * @param {number} [modulation] - Frequency of modulation wave, negative flips phase (Hz)
386
+ * @param {number} [bitCrush] - Resamples at a lower frequency in (samples*100)
387
+ * @param {number} [delay] - Overlap sound with itself for reverb and flanger effects (seconds)
388
+ * @param {number} [sustainVolume] - Volume level for sustain (percent)
389
+ * @param {number} [decay] - Decay time, how long to reach sustain after attack (seconds)
390
+ * @param {number} [tremolo] - Trembling effect, rate controlled by repeat time (percent)
391
+ * @param {number} [filter] - Filter cutoff frequency, positive for HPF, negative for LPF (Hz)
392
392
  * @return {Array} - Array of audio samples
393
393
  * @memberof Audio
394
394
  */
@@ -494,7 +494,7 @@ function zzfxG
494
494
  * @param {Array} instruments - Array of ZzFX sound parameters
495
495
  * @param {Array} patterns - Array of pattern data
496
496
  * @param {Array} sequence - Array of pattern indexes
497
- * @param {Number} [BPM] - Playback speed of the song in BPM
497
+ * @param {number} [BPM] - Playback speed of the song in BPM
498
498
  * @return {Array} - Left and right channel sample data
499
499
  * @memberof Audio */
500
500
  function zzfxM(instruments, patterns, sequence, BPM = 125)
@@ -11,37 +11,37 @@
11
11
  'use strict';
12
12
 
13
13
  /** True if debug is enabled
14
- * @type {Boolean}
14
+ * @type {boolean}
15
15
  * @default
16
16
  * @memberof Debug */
17
17
  const debug = true;
18
18
 
19
19
  /** True if asserts are enabled
20
- * @type {Boolean}
20
+ * @type {boolean}
21
21
  * @default
22
22
  * @memberof Debug */
23
23
  const enableAsserts = true;
24
24
 
25
25
  /** Size to render debug points by default
26
- * @type {Number}
26
+ * @type {number}
27
27
  * @default
28
28
  * @memberof Debug */
29
29
  const debugPointSize = .5;
30
30
 
31
31
  /** True if watermark with FPS should be shown, false in release builds
32
- * @type {Boolean}
32
+ * @type {boolean}
33
33
  * @default
34
34
  * @memberof Debug */
35
35
  let showWatermark = true;
36
36
 
37
37
  /** Key code used to toggle debug mode, Esc by default
38
- * @type {String}
38
+ * @type {string}
39
39
  * @default
40
40
  * @memberof Debug */
41
41
  let debugKey = 'Escape';
42
42
 
43
43
  /** True if the debug overlay is active, always false in release builds
44
- * @type {Boolean}
44
+ * @type {boolean}
45
45
  * @default
46
46
  * @memberof Debug */
47
47
  let debugOverlay = false;
@@ -53,7 +53,7 @@ let debugPrimitives = [], debugPhysics = false, debugRaycast = false, debugParti
53
53
  // Debug helper functions
54
54
 
55
55
  /** Asserts if the expression is false, does not do anything in release builds
56
- * @param {Boolean} assert
56
+ * @param {boolean} assert
57
57
  * @param {Object} [output]
58
58
  * @memberof Debug */
59
59
  function ASSERT(assert, output)
@@ -65,10 +65,10 @@ function ASSERT(assert, output)
65
65
  /** Draw a debug rectangle in world space
66
66
  * @param {Vector2} pos
67
67
  * @param {Vector2} [size=Vector2()]
68
- * @param {String} [color]
69
- * @param {Number} [time]
70
- * @param {Number} [angle]
71
- * @param {Boolean} [fill]
68
+ * @param {string} [color]
69
+ * @param {number} [time]
70
+ * @param {number} [angle]
71
+ * @param {boolean} [fill]
72
72
  * @memberof Debug */
73
73
  function debugRect(pos, size=vec2(), color='#fff', time=0, angle=0, fill=false)
74
74
  {
@@ -78,11 +78,11 @@ function debugRect(pos, size=vec2(), color='#fff', time=0, angle=0, fill=false)
78
78
 
79
79
  /** Draw a debug poly in world space
80
80
  * @param {Vector2} pos
81
- * @param {Array} points
82
- * @param {String} [color]
83
- * @param {Number} [time]
84
- * @param {Number} [angle]
85
- * @param {Boolean} [fill]
81
+ * @param {Array<Vector2>} points
82
+ * @param {string} [color]
83
+ * @param {number} [time]
84
+ * @param {number} [angle]
85
+ * @param {boolean} [fill]
86
86
  * @memberof Debug */
87
87
  function debugPoly(pos, points, color='#fff', time=0, angle=0, fill=false)
88
88
  {
@@ -92,10 +92,10 @@ function debugPoly(pos, points, color='#fff', time=0, angle=0, fill=false)
92
92
 
93
93
  /** Draw a debug circle in world space
94
94
  * @param {Vector2} pos
95
- * @param {Number} [radius]
96
- * @param {String} [color]
97
- * @param {Number} [time]
98
- * @param {Boolean} [fill]
95
+ * @param {number} [radius]
96
+ * @param {string} [color]
97
+ * @param {number} [time]
98
+ * @param {boolean} [fill]
99
99
  * @memberof Debug */
100
100
  function debugCircle(pos, radius=0, color='#fff', time=0, fill=false)
101
101
  {
@@ -105,9 +105,9 @@ function debugCircle(pos, radius=0, color='#fff', time=0, fill=false)
105
105
 
106
106
  /** Draw a debug point in world space
107
107
  * @param {Vector2} pos
108
- * @param {String} [color]
109
- * @param {Number} [time]
110
- * @param {Number} [angle]
108
+ * @param {string} [color]
109
+ * @param {number} [time]
110
+ * @param {number} [angle]
111
111
  * @memberof Debug */
112
112
  function debugPoint(pos, color, time, angle)
113
113
  {
@@ -118,9 +118,9 @@ function debugPoint(pos, color, time, angle)
118
118
  /** Draw a debug line in world space
119
119
  * @param {Vector2} posA
120
120
  * @param {Vector2} posB
121
- * @param {String} [color]
122
- * @param {Number} [thickness]
123
- * @param {Number} [time]
121
+ * @param {string} [color]
122
+ * @param {number} [thickness]
123
+ * @param {number} [time]
124
124
  * @memberof Debug */
125
125
  function debugLine(posA, posB, color, thickness=.1, time)
126
126
  {
@@ -134,7 +134,7 @@ function debugLine(posA, posB, color, thickness=.1, time)
134
134
  * @param {Vector2} sA - size A
135
135
  * @param {Vector2} pB - position B
136
136
  * @param {Vector2} sB - size B
137
- * @param {String} [color]
137
+ * @param {string} [color]
138
138
  * @memberof Debug */
139
139
  function debugOverlap(pA, sA, pB, sB, color)
140
140
  {
@@ -144,13 +144,13 @@ function debugOverlap(pA, sA, pB, sB, color)
144
144
  }
145
145
 
146
146
  /** Draw a debug axis aligned bounding box in world space
147
- * @param {String} text
147
+ * @param {string} text
148
148
  * @param {Vector2} pos
149
- * @param {Number} [size]
150
- * @param {String} [color]
151
- * @param {Number} [time]
152
- * @param {Number} [angle]
153
- * @param {String} [font]
149
+ * @param {number} [size]
150
+ * @param {string} [color]
151
+ * @param {number} [time]
152
+ * @param {number} [angle]
153
+ * @param {string} [font]
154
154
  * @memberof Debug */
155
155
  function debugText(text, pos, size=1, color='#fff', time=0, angle=0, font='monospace')
156
156
  {
@@ -168,23 +168,23 @@ function debugScreenshot() { debugTakeScreenshot = 1; }
168
168
 
169
169
  /** Save a canvas to disk
170
170
  * @param {HTMLCanvasElement} canvas
171
- * @param {String} [filename]
172
- * @param {String} [type]
171
+ * @param {string} [filename]
172
+ * @param {string} [type]
173
173
  * @memberof Debug */
174
174
  function debugSaveCanvas(canvas, filename='screenshot', type='image/png')
175
175
  { debugSaveDataURL(canvas.toDataURL(type), filename); }
176
176
 
177
177
  /** Save a text file to disk
178
- * @param {String} text
179
- * @param {String} [filename]
180
- * @param {String} [type]
178
+ * @param {string} text
179
+ * @param {string} [filename]
180
+ * @param {string} [type]
181
181
  * @memberof Debug */
182
182
  function debugSaveText(text, filename='text', type='text/plain')
183
183
  { debugSaveDataURL(URL.createObjectURL(new Blob([text], {'type':type})), filename); }
184
184
 
185
185
  /** Save a data url to disk
186
- * @param {String} dataURL
187
- * @param {String} filename
186
+ * @param {string} dataURL
187
+ * @param {string} filename
188
188
  * @memberof Debug */
189
189
  function debugSaveDataURL(dataURL, filename)
190
190
  {
@@ -304,9 +304,12 @@ function debugRender()
304
304
  let bestDistance = Infinity;
305
305
  for (const o of engineObjects)
306
306
  {
307
- if (o.canvas || o.destroyed)
307
+ if (o.destroyed)
308
308
  continue;
309
309
 
310
+ if (o instanceof TileLayer)
311
+ continue; // prevent tile layers from being picked
312
+
310
313
  o.renderDebugInfo();
311
314
  if (!o.size.x || !o.size.y)
312
315
  continue;