littlejsengine 1.4.9 → 1.5.0

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.
package/engine/index.d.ts CHANGED
@@ -1,1700 +1,1615 @@
1
- /** Draw textured tile centered in world space, with color applied if using WebGL
2
- * @param {Vector2} pos - Center of the tile in world space
3
- * @param {Vector2} [size=new Vector2(1,1)] - Size of the tile in world space
4
- * @param {Number} [tileIndex=-1] - Tile index to use, negative is untextured
5
- * @param {Vector2} [tileSize=tileSizeDefault] - Tile size in source pixels
6
- * @param {Color} [color=new Color(1,1,1)] - Color to modulate with
7
- * @param {Number} [angle=0] - Angle to rotate by
8
- * @param {Boolean} [mirror=0] - If true image is flipped along the Y axis
9
- * @param {Color} [additiveColor=new Color(0,0,0,0)] - Additive color to be applied
10
- * @param {Boolean} [useWebGL=glEnable] - Use accelerated WebGL rendering
11
- * @memberof Draw */
12
- declare function drawTile(pos: Vector2, size?: Vector2, tileIndex?: number, tileSize?: Vector2, color?: Color, angle?: number, mirror?: boolean, additiveColor?: Color, useWebGL?: boolean): void;
13
- /** Draw colored rect centered on pos
14
- * @param {Vector2} pos
15
- * @param {Vector2} [size=new Vector2(1,1)]
16
- * @param {Color} [color=new Color(1,1,1)]
17
- * @param {Number} [angle=0]
18
- * @param {Boolean} [useWebGL=glEnable]
19
- * @memberof Draw */
20
- declare function drawRect(pos: Vector2, size?: Vector2, color?: Color, angle?: number, useWebGL?: boolean): void;
21
- /** Draw textured tile centered on pos in screen space
22
- * @param {Vector2} pos - Center of the tile
23
- * @param {Vector2} [size=new Vector2(1,1)] - Size of the tile
24
- * @param {Number} [tileIndex=-1] - Tile index to use, negative is untextured
25
- * @param {Vector2} [tileSize=tileSizeDefault] - Tile size in source pixels
26
- * @param {Color} [color=new Color]
27
- * @param {Number} [angle=0]
28
- * @param {Boolean} [mirror=0]
29
- * @param {Color} [additiveColor=new Color(0,0,0,0)]
30
- * @param {Boolean} [useWebGL=glEnable]
31
- * @memberof Draw */
32
- declare function drawTileScreenSpace(pos: Vector2, size?: Vector2, tileIndex?: number, tileSize?: Vector2, color?: Color, angle?: number, mirror?: boolean, additiveColor?: Color, useWebGL?: boolean): void;
33
- /** Draw colored rectangle in screen space
34
- * @param {Vector2} pos
35
- * @param {Vector2} [size=new Vector2(1,1)]
36
- * @param {Color} [color=new Color(1,1,1)]
37
- * @param {Number} [angle=0]
38
- * @param {Boolean} [useWebGL=glEnable]
39
- * @memberof Draw */
40
- declare function drawRectScreenSpace(pos: Vector2, size?: Vector2, color?: Color, angle?: number, useWebGL?: boolean): void;
41
- /** Draw colored line between two points
42
- * @param {Vector2} posA
43
- * @param {Vector2} posB
44
- * @param {Number} [thickness=.1]
45
- * @param {Color} [color=new Color(1,1,1)]
46
- * @param {Boolean} [useWebGL=glEnable]
47
- * @memberof Draw */
48
- declare function drawLine(posA: Vector2, posB: Vector2, thickness?: number, color?: Color, useWebGL?: boolean): void;
49
- /** Draw directly to a 2d canvas context in world space
50
- * @param {Vector2} pos
51
- * @param {Vector2} size
52
- * @param {Number} angle
53
- * @param {Boolean} mirror
54
- * @param {Function} drawFunction
55
- * @param {CanvasRenderingContext2D} [context=mainContext]
56
- * @memberof Draw */
57
- declare function drawCanvas2D(pos: Vector2, size: Vector2, angle: number, mirror: boolean, drawFunction: Function, context?: CanvasRenderingContext2D): void;
58
- /** Enable normal or additive blend mode
59
- * @param {Boolean} [additive=0]
60
- * @param {Boolean} [useWebGL=glEnable]
61
- * @memberof Draw */
62
- declare function setBlendMode(additive?: boolean, useWebGL?: boolean): void;
63
- /** Draw text on overlay canvas in screen space
64
- * Automatically splits new lines into rows
65
- * @param {String} text
66
- * @param {Vector2} pos
67
- * @param {Number} [size=1]
68
- * @param {Color} [color=new Color(1,1,1)]
69
- * @param {Number} [lineWidth=0]
70
- * @param {Color} [lineColor=new Color(0,0,0)]
71
- * @param {String} [textAlign='center']
72
- * @memberof Draw */
73
- declare function drawTextScreen(text: string, pos: Vector2, size?: number, color?: Color, lineWidth?: number, lineColor?: Color, textAlign?: string, font?: string, context?: CanvasRenderingContext2D): void;
74
- /** Draw text on overlay canvas in world space
75
- * Automatically splits new lines into rows
76
- * @param {String} text
77
- * @param {Vector2} pos
78
- * @param {Number} [size=1]
79
- * @param {Color} [color=new Color(1,1,1)]
80
- * @param {Number} [lineWidth=0]
81
- * @param {Color} [lineColor=new Color(0,0,0)]
82
- * @param {String} [textAlign='center']
83
- * @memberof Draw */
84
- declare function drawText(text: string, pos: Vector2, size?: number, color?: Color, lineWidth?: number, lineColor?: Color, textAlign?: string, font: any): void;
85
- /** Toggle fullsceen mode
86
- * @memberof Draw */
87
- declare function toggleFullscreen(): void;
88
- declare function inputUpdate(): void;
89
- declare function inputUpdatePost(): void;
90
- declare function gamepadsUpdate(): void;
91
- declare function touchGamepadCreate(): void;
92
- declare function touchGamepadRender(): void;
93
- /** Play an mp3 or wav audio from a local file or url
94
- * @param {String} url - Location of sound file to play
95
- * @param {Number} [volume=1] - How much to scale volume by
96
- * @param {Boolean} [loop=1] - True if the music should loop when it reaches the end
97
- * @return {HTMLAudioElement} - The audio element for this sound
98
- * @memberof Audio */
99
- declare function playAudioFile(url: string, volume?: number, loop?: boolean): HTMLAudioElement;
100
- /** Speak text with passed in settings
101
- * @param {String} text - The text to speak
102
- * @param {String} [language] - The language/accent to use (examples: en, it, ru, ja, zh)
103
- * @param {Number} [volume=1] - How much to scale volume by
104
- * @param {Number} [rate=1] - How quickly to speak
105
- * @param {Number} [pitch=1] - How much to change the pitch by
106
- * @return {SpeechSynthesisUtterance} - The utterance that was spoken
107
- * @memberof Audio */
108
- declare function speak(text: string, language?: string, volume?: number, rate?: number, pitch?: number): SpeechSynthesisUtterance;
109
- /** Play cached audio samples with given settings
110
- * @param {Array} sampleChannels - Array of arrays of samples to play (for stereo playback)
111
- * @param {Number} [volume=1] - How much to scale volume by
112
- * @param {Number} [rate=1] - The playback rate to use
113
- * @param {Number} [pan=0] - How much to apply stereo panning
114
- * @param {Boolean} [loop=0] - True if the sound should loop when it reaches the end
115
- * @return {AudioBufferSourceNode} - The audio node of the sound played
116
- * @memberof Audio */
117
- declare function playSamples(sampleChannels: any[], volume?: number, rate?: number, pan?: number, loop?: boolean): AudioBufferSourceNode;
118
- /** Generate samples for a ZzFX sound
119
- * @memberof Audio */
120
- declare function zzfxG(volume?: number, randomness?: number, frequency?: number, attack?: number, sustain?: number, release?: number, shape?: number, shapeCurve?: number, slide?: number, deltaSlide?: number, pitchJump?: number, pitchJumpTime?: number, repeatTime?: number, noise?: number, modulation?: number, bitCrush?: number, delay?: number, sustainVolume?: number, decay?: number, tremolo?: number): number[];
121
- /** Generate samples for a ZzFM song with given parameters
122
- * @param {Array} instruments - Array of ZzFX sound paramaters
123
- * @param {Array} patterns - Array of pattern data
124
- * @param {Array} sequence - Array of pattern indexes
125
- * @param {Number} [BPM=125] - Playback speed of the song in BPM
126
- * @returns {Array} - Left and right channel sample data
127
- * @memberof Audio */
128
- declare function zzfxM(instruments: any[], patterns: any[], sequence: any[], BPM?: number): any[];
129
- /** Clear and initialize tile collision
130
- * @param {Vector2} size
131
- * @memberof TileCollision */
132
- declare function initTileCollision(size: Vector2): void;
133
- /** Check if collision with another object should occur
134
- * @param {Vector2} pos
135
- * @param {Vector2} [size=new Vector2(1,1)]
136
- * @param {EngineObject} [object]
137
- * @return {Boolean}
138
- * @memberof TileCollision */
139
- declare function tileCollisionTest(pos: Vector2, size?: Vector2, object?: EngineObject): boolean;
140
- /** Return the center of tile if any that is hit (this does not return the exact hit point)
141
- * @param {Vector2} posStart
142
- * @param {Vector2} posEnd
143
- * @param {EngineObject} [object]
144
- * @return {Vector2}
145
- * @memberof TileCollision */
146
- declare function tileCollisionRaycast(posStart: Vector2, posEnd: Vector2, object?: EngineObject): Vector2;
147
- /** Initialize medals with a save name used for storage
148
- * <br> - Call this after creating all medals
149
- * <br> - Checks if medals are unlocked
150
- * @param {String} saveName
151
- * @memberof Medals */
152
- declare function medalsInit(saveName: string): void;
153
- declare function medalsRender(): void;
154
- /** This can used to enable Newgrounds functionality
155
- * @param {Number} app_id - The newgrounds App ID
156
- * @param {String} [cipher] - The encryption Key (AES-128/Base64)
157
- * @memberof Medals */
158
- declare function newgroundsInit(app_id: number, cipher?: string): void;
159
- declare function glInit(): void;
160
- /** Set the WebGl blend mode, normally you should call setBlendMode instead
161
- * @param {Boolean} [additive=0]
162
- * @memberof WebGL */
163
- declare function glSetBlendMode(additive?: boolean): void;
164
- /** Set the WebGl texture, not normally necessary unless multiple tile sheets are used
165
- * <br> - This may also flush the gl buffer resulting in more draw calls and worse performance
166
- * @param {WebGLTexture} [texture=glTileTexture]
167
- * @memberof WebGL */
168
- declare function glSetTexture(texture?: WebGLTexture): void;
169
- /** Compile WebGL shader of the given type, will throw errors if in debug mode
170
- * @param {String} source
171
- * @param type
172
- * @return {WebGLShader}
173
- * @memberof WebGL */
174
- declare function glCompileShader(source: string, type: any): WebGLShader;
175
- /** Create WebGL program with given shaders
176
- * @param {WebGLShader} vsSource
177
- * @param {WebGLShader} fsSource
178
- * @return {WebGLProgram}
179
- * @memberof WebGL */
180
- declare function glCreateProgram(vsSource: WebGLShader, fsSource: WebGLShader): WebGLProgram;
181
- /** Create WebGL texture from an image and set the texture settings
182
- * @param {Image} image
183
- * @return {WebGLTexture}
184
- * @memberof WebGL */
185
- declare function glCreateTexture(image: new (width?: number, height?: number) => HTMLImageElement): WebGLTexture;
186
- declare function glPreRender(): void;
187
- /** Draw all sprites and clear out the buffer, called automatically by the system whenever necessary
188
- * @memberof WebGL */
189
- declare function glFlush(): void;
190
- /** Draw any sprites still in the buffer, copy to main canvas and clear
191
- * @param {CanvasRenderingContext2D} context
192
- * @param {Boolean} [forceDraw=0]
193
- * @memberof WebGL */
194
- declare function glCopyToContext(context: CanvasRenderingContext2D, forceDraw?: boolean): void;
195
- /** Add a sprite to the gl draw list, used by all gl draw functions
196
- * @param x
197
- * @param y
198
- * @param sizeX
199
- * @param sizeY
200
- * @param angle
201
- * @param uv0X
202
- * @param uv0Y
203
- * @param uv1X
204
- * @param uv1Y
205
- * @param rgba
206
- * @param [rgbaAdditive=0]
207
- * @memberof WebGL */
208
- declare function glDraw(x: any, y: any, sizeX: any, sizeY: any, angle: any, uv0X: any, uv0Y: any, uv1X: any, uv1Y: any, rgba: any, rgbaAdditive?: number): void;
209
- /** Set up a post processing shader
210
- * @param {String} shaderCode
211
- * @memberof WebGL */
212
- declare function glInitPostProcess(shaderCode: string): void;
213
- declare function glRenderPostProcess(): void;
214
- /** Set if game is paused
215
- * @param {Boolean} paused
216
- */
217
- declare function setPaused(_paused: any): void;
218
- /** Start up LittleJS engine with your callback functions
219
- * @param {Function} gameInit - Called once after the engine starts up, setup the game
220
- * @param {Function} gameUpdate - Called every frame at 60 frames per second, handle input and update the game state
221
- * @param {Function} gameUpdatePost - Called after physics and objects are updated, setup camera and prepare for render
222
- * @param {Function} gameRender - Called before objects are rendered, draw any background effects that appear behind objects
223
- * @param {Function} gameRenderPost - Called after objects are rendered, draw effects or hud that appear above all objects
224
- * @param {String} [tileImageSource] - Tile image to use, everything starts when the image is finished loading
225
- */
226
- declare function engineInit(gameInit: Function, gameUpdate: Function, gameUpdatePost: Function, gameRender: Function, gameRenderPost: Function, tileImageSource?: string): void;
227
- declare function enginePreRender(): void;
228
- /** Update each engine object, remove destroyed objects, and update time */
229
- declare function engineObjectsUpdate(): void;
230
- /** Destroy and remove all objects */
231
- declare function engineObjectsDestroy(): void;
232
- /** Triggers a callback for each object within a given area
233
- * @param {Vector2} [pos] - Center of test area
234
- * @param {Number} [size] - Radius of circle if float, rectangle size if Vector2
235
- * @param {Function} [callbackFunction] - Calls this function on every object that passes the test
236
- * @param {Array} [objects=engineObjects] - List of objects to check */
237
- declare function engineObjectsCallback(pos?: Vector2, size?: number, callbackFunction?: Function, objects?: any[]): void;
238
- /** True if debug is enabled
239
- * @default
240
- * @memberof Debug */
241
- declare const debug: 1;
242
- /** True if asserts are enaled
243
- * @default
244
- * @memberof Debug */
245
- declare const enableAsserts: 1;
246
- /** Size to render debug points by default
247
- * @default
248
- * @memberof Debug */
249
- declare const debugPointSize: 0.5;
250
- /** True if watermark with FPS should be down, false in release builds
251
- * @default
252
- * @memberof Debug */
253
- declare let showWatermark: number;
254
- /** True if god mode is enabled, handle this however you want
255
- * @default
256
- * @memberof Debug */
257
- declare let godMode: number;
258
- declare let debugPrimitives: any[];
259
- declare let debugOverlay: number;
260
- declare let debugPhysics: number;
261
- declare let debugRaycast: number;
262
- declare let debugParticles: number;
263
- declare let debugGamepads: number;
264
- declare let debugMedals: number;
265
- declare let debugTakeScreenshot: any;
266
- declare let downloadLink: any;
267
- declare function ASSERT(...assert: any[]): void;
268
- /** Draw a debug rectangle in world space
269
- * @param {Vector2} pos
270
- * @param {Vector2} [size=new Vector2()]
271
- * @param {String} [color='#fff']
272
- * @param {Number} [time=0]
273
- * @param {Number} [angle=0]
274
- * @param {Boolean} [fill=0]
275
- * @memberof Debug */
276
- declare function debugRect(pos: Vector2, size?: Vector2, color?: string, time?: number, angle?: number, fill?: boolean): void;
277
- /** Draw a debug circle in world space
278
- * @param {Vector2} pos
279
- * @param {Number} [radius=0]
280
- * @param {String} [color='#fff']
281
- * @param {Number} [time=0]
282
- * @param {Boolean} [fill=0]
283
- * @memberof Debug */
284
- declare function debugCircle(pos: Vector2, radius?: number, color?: string, time?: number, fill?: boolean): void;
285
- /** Draw a debug point in world space
286
- * @param {Vector2} pos
287
- * @param {String} [color='#fff']
288
- * @param {Number} [time=0]
289
- * @param {Number} [angle=0]
290
- * @memberof Debug */
291
- declare function debugPoint(pos: Vector2, color?: string, time?: number, angle?: number): void;
292
- /** Draw a debug line in world space
293
- * @param {Vector2} posA
294
- * @param {Vector2} posB
295
- * @param {String} [color='#fff']
296
- * @param {Number} [thickness=.1]
297
- * @param {Number} [time=0]
298
- * @memberof Debug */
299
- declare function debugLine(posA: Vector2, posB: Vector2, color?: string, thickness?: number, time?: number): void;
300
- /** Draw a debug axis aligned bounding box in world space
301
- * @param {Vector2} posA
302
- * @param {Vector2} sizeA
303
- * @param {Vector2} posB
304
- * @param {Vector2} sizeB
305
- * @param {String} [color='#fff']
306
- * @memberof Debug */
307
- declare function debugAABB(pA: any, sA: any, pB: any, sB: any, color?: string): void;
308
- /** Draw a debug axis aligned bounding box in world space
309
- * @param {String} text
310
- * @param {Vector2} pos
311
- * @param {Number} [size=1]
312
- * @param {String} [color='#fff']
313
- * @param {Number} [time=0]
314
- * @param {Number} [angle=0]
315
- * @param {String} [font='monospace']
316
- * @memberof Debug */
317
- declare function debugText(text: string, pos: Vector2, size?: number, color?: string, time?: number, angle?: number, font?: string): void;
318
- /** Clear all debug primitives in the list
319
- * @memberof Debug */
320
- declare function debugClear(): any[];
321
- /** Save a canvas to disk
322
- * @param {HTMLCanvasElement} canvas
323
- * @param {String} [filename]
324
- * @memberof Debug */
325
- declare function debugSaveCanvas(canvas: HTMLCanvasElement, filename?: string): void;
326
- declare function debugInit(): void;
327
- declare function debugUpdate(): void;
328
- declare function debugRender(): void;
329
- /** A shortcut to get Math.PI
330
- * @const
331
- * @memberof Utilities */
332
- declare const PI: number;
333
- /** Returns absoulte value of value passed in
334
- * @param {Number} value
335
- * @return {Number}
336
- * @memberof Utilities */
337
- declare function abs(a: any): number;
338
- /** Returns lowest of two values passed in
339
- * @param {Number} valueA
340
- * @param {Number} valueB
341
- * @return {Number}
342
- * @memberof Utilities */
343
- declare function min(a: any, b: any): number;
344
- /** Returns highest of two values passed in
345
- * @param {Number} valueA
346
- * @param {Number} valueB
347
- * @return {Number}
348
- * @memberof Utilities */
349
- declare function max(a: any, b: any): number;
350
- /** Returns the sign of value passed in (also returns 1 if 0)
351
- * @param {Number} value
352
- * @return {Number}
353
- * @memberof Utilities */
354
- declare function sign(a: any): number;
355
- /** Returns first parm modulo the second param, but adjusted so negative numbers work as expected
356
- * @param {Number} dividend
357
- * @param {Number} [divisor=1]
358
- * @return {Number}
359
- * @memberof Utilities */
360
- declare function mod(a: any, b?: number): number;
361
- /** Clamps the value beween max and min
362
- * @param {Number} value
363
- * @param {Number} [min=0]
364
- * @param {Number} [max=1]
365
- * @return {Number}
366
- * @memberof Utilities */
367
- declare function clamp(v: any, min?: number, max?: number): number;
368
- /** Returns what percentage the value is between max and min
369
- * @param {Number} value
370
- * @param {Number} [min=0]
371
- * @param {Number} [max=1]
372
- * @return {Number}
373
- * @memberof Utilities */
374
- declare function percent(v: any, min?: number, max?: number): number;
375
- /** Linearly interpolates the percent value between max and min
376
- * @param {Number} percent
377
- * @param {Number} [min=0]
378
- * @param {Number} [max=1]
379
- * @return {Number}
380
- * @memberof Utilities */
381
- declare function lerp(p: any, min?: number, max?: number): number;
382
- /** Applies smoothstep function to the percentage value
383
- * @param {Number} value
384
- * @return {Number}
385
- * @memberof Utilities */
386
- declare function smoothStep(p: any): number;
387
- /** Returns the nearest power of two not less then the value
388
- * @param {Number} value
389
- * @return {Number}
390
- * @memberof Utilities */
391
- declare function nearestPowerOfTwo(v: any): number;
392
- /** Returns true if two axis aligned bounding boxes are overlapping
393
- * @param {Vector2} pointA - Center of box A
394
- * @param {Vector2} sizeA - Size of box A
395
- * @param {Vector2} pointB - Center of box B
396
- * @param {Vector2} [sizeB] - Size of box B
397
- * @return {Boolean} - True if overlapping
398
- * @memberof Utilities */
399
- declare function isOverlapping(pA: any, sA: any, pB: any, sB: any): boolean;
400
- /** Returns an oscillating wave between 0 and amplitude with frequency of 1 Hz by default
401
- * @param {Number} [frequency=1] - Frequency of the wave in Hz
402
- * @param {Number} [amplitude=1] - Amplitude (max height) of the wave
403
- * @param {Number} [t=time] - Value to use for time of the wave
404
- * @return {Number} - Value waving between 0 and amplitude
405
- * @memberof Utilities */
406
- declare function wave(frequency?: number, amplitude?: number, t?: number): number;
407
- /** Formats seconds to mm:ss style for display purposes
408
- * @param {Number} t - time in seconds
409
- * @return {String}
410
- * @memberof Utilities */
411
- declare function formatTime(t: number): string;
412
- /** Random global functions
413
- * @namespace Random */
414
- /** Returns a random value between the two values passed in
415
- * @param {Number} [valueA=1]
416
- * @param {Number} [valueB=0]
417
- * @return {Number}
418
- * @memberof Random */
419
- declare function rand(a?: number, b?: number): number;
420
- /** Returns a floored random value the two values passed in
421
- * @param {Number} [valueA=1]
422
- * @param {Number} [valueB=0]
423
- * @return {Number}
424
- * @memberof Random */
425
- declare function randInt(a?: number, b?: number): number;
426
- /** Randomly returns either -1 or 1
427
- * @return {Number}
428
- * @memberof Random */
429
- declare function randSign(): number;
430
- /** Returns a random Vector2 within a circular shape
431
- * @param {Number} [radius=1]
432
- * @param {Number} [minRadius=0]
433
- * @return {Vector2}
434
- * @memberof Random */
435
- declare function randInCircle(radius?: number, minRadius?: number): Vector2;
436
- /** Returns a random Vector2 with the passed in length
437
- * @param {Number} [length=1]
438
- * @return {Vector2}
439
- * @memberof Random */
440
- declare function randVector(length?: number): Vector2;
441
- /** Returns a random color between the two passed in colors, combine components if linear
442
- * @param {Color} [colorA=new Color(1,1,1,1)]
443
- * @param {Color} [colorB=new Color(0,0,0,1)]
444
- * @param {Boolean} [linear]
445
- * @return {Color}
446
- * @memberof Random */
447
- declare function randColor(cA?: Color, cB?: Color, linear?: boolean): Color;
448
- /** Seed used by the randSeeded function
449
- * @memberof Random */
450
- declare let randSeed: number;
451
- /** Set seed used by the randSeeded function, should not be 0
452
- * @param {Number} seed
453
- * @memberof Random */
454
- declare function setRandSeed(seed: number): number;
455
- /** Returns a seeded random value between the two values passed in using randSeed
456
- * @param {Number} [valueA=1]
457
- * @param {Number} [valueB=0]
458
- * @return {Number}
459
- * @memberof Random */
460
- declare function randSeeded(a?: number, b?: number): number;
461
- /**
462
- * Create a 2d vector, can take another Vector2 to copy, 2 scalars, or 1 scalar
463
- * @param {Number} [x=0]
464
- * @param {Number} [y=0]
465
- * @return {Vector2}
466
- * @example
467
- * let a = vec2(0, 1); // vector with coordinates (0, 1)
468
- * let b = vec2(a); // copy a into b
469
- * a = vec2(5); // set a to (5, 5)
470
- * b = vec2(); // set b to (0, 0)
471
- * @memberof Utilities
472
- */
473
- declare function vec2(x?: number, y?: number): Vector2;
474
- /**
475
- * Check if object is a valid Vector2
476
- * @param {Vector2} vector
477
- * @return {Boolean}
478
- * @memberof Utilities
479
- */
480
- declare function isVector2(v: any): boolean;
481
- /**
482
- * 2D Vector object with vector math library
483
- * <br> - Functions do not change this so they can be chained together
484
- * @example
485
- * let a = new Vector2(2, 3); // vector with coordinates (2, 3)
486
- * let b = new Vector2; // vector with coordinates (0, 0)
487
- * let c = vec2(4, 2); // use the vec2 function to make a Vector2
488
- * let d = a.add(b).scale(5); // operators can be chained
489
- */
490
- declare class Vector2 {
491
- /** Create a 2D vector with the x and y passed in, can also be created with vec2()
492
- * @param {Number} [x=0] - X axis location
493
- * @param {Number} [y=0] - Y axis location */
494
- constructor(x?: number, y?: number);
495
- /** @property {Number} - X axis location */
496
- x: number;
497
- /** @property {Number} - Y axis location */
498
- y: number;
499
- /** Returns a new vector that is a copy of this
500
- * @return {Vector2} */
501
- copy(): Vector2;
502
- /** Returns a copy of this vector plus the vector passed in
503
- * @param {Vector2} vector
504
- * @return {Vector2} */
505
- add(v: any): Vector2;
506
- /** Returns a copy of this vector minus the vector passed in
507
- * @param {Vector2} vector
508
- * @return {Vector2} */
509
- subtract(v: any): Vector2;
510
- /** Returns a copy of this vector times the vector passed in
511
- * @param {Vector2} vector
512
- * @return {Vector2} */
513
- multiply(v: any): Vector2;
514
- /** Returns a copy of this vector divided by the vector passed in
515
- * @param {Vector2} vector
516
- * @return {Vector2} */
517
- divide(v: any): Vector2;
518
- /** Returns a copy of this vector scaled by the vector passed in
519
- * @param {Number} scale
520
- * @return {Vector2} */
521
- scale(s: any): Vector2;
522
- /** Returns the length of this vector
523
- * @return {Number} */
524
- length(): number;
525
- /** Returns the length of this vector squared
526
- * @return {Number} */
527
- lengthSquared(): number;
528
- /** Returns the distance from this vector to vector passed in
529
- * @param {Vector2} vector
530
- * @return {Number} */
531
- distance(v: any): number;
532
- /** Returns the distance squared from this vector to vector passed in
533
- * @param {Vector2} vector
534
- * @return {Number} */
535
- distanceSquared(v: any): number;
536
- /** Returns a new vector in same direction as this one with the length passed in
537
- * @param {Number} [length=1]
538
- * @return {Vector2} */
539
- normalize(length?: number): Vector2;
540
- /** Returns a new vector clamped to length passed in
541
- * @param {Number} [length=1]
542
- * @return {Vector2} */
543
- clampLength(length?: number): Vector2;
544
- /** Returns the dot product of this and the vector passed in
545
- * @param {Vector2} vector
546
- * @return {Number} */
547
- dot(v: any): number;
548
- /** Returns the cross product of this and the vector passed in
549
- * @param {Vector2} vector
550
- * @return {Number} */
551
- cross(v: any): number;
552
- /** Returns the angle of this vector, up is angle 0
553
- * @return {Number} */
554
- angle(): number;
555
- /** Sets this vector with angle and length passed in
556
- * @param {Number} [angle=0]
557
- * @param {Number} [length=1] */
558
- setAngle(a?: number, length?: number): Vector2;
559
- /** Returns copy of this vector rotated by the angle passed in
560
- * @param {Number} angle
561
- * @return {Vector2} */
562
- rotate(a: any): Vector2;
563
- /** Returns the integer direction of this vector, corrosponding to multiples of 90 degree rotation (0-3)
564
- * @return {Number} */
565
- direction(): number;
566
- /** Returns a copy of this vector that has been inverted
567
- * @return {Vector2} */
568
- invert(): Vector2;
569
- /** Returns a copy of this vector with each axis floored
570
- * @return {Vector2} */
571
- floor(): Vector2;
572
- /** Returns the area this vector covers as a rectangle
573
- * @return {Number} */
574
- area(): number;
575
- /** Returns a new vector that is p percent between this and the vector passed in
576
- * @param {Vector2} vector
577
- * @param {Number} percent
578
- * @return {Vector2} */
579
- lerp(v: any, p: any): Vector2;
580
- /** Returns true if this vector is within the bounds of an array size passed in
581
- * @param {Vector2} arraySize
582
- * @return {Boolean} */
583
- arrayCheck(arraySize: Vector2): boolean;
584
- /** Returns this vector expressed as a string
585
- * @param {float} digits - precision to display
586
- * @return {String} */
587
- toString(digits?: float): string;
588
- }
589
- /**
590
- * Create a color object with RGBA values
591
- * @param {Number} [r=1]
592
- * @param {Number} [g=1]
593
- * @param {Number} [b=1]
594
- * @param {Number} [a=1]
595
- * @return {Color}
596
- * @memberof Utilities
597
- */
598
- declare function colorRGBA(r?: number, g?: number, b?: number, a?: number): Color;
599
- /**
600
- * Create a color object with HSLA values
601
- * @param {Number} [h=0]
602
- * @param {Number} [s=0]
603
- * @param {Number} [l=1]
604
- * @param {Number} [a=1]
605
- * @return {Color}
606
- * @memberof Utilities
607
- */
608
- declare function colorHSLA(h?: number, s?: number, l?: number, a?: number): Color;
609
- /**
610
- * Color object (red, green, blue, alpha) with some helpful functions
611
- * @example
612
- * let a = new Color; // white
613
- * let b = new Color(1, 0, 0); // red
614
- * let c = new Color(0, 0, 0, 0); // transparent black
615
- */
616
- declare class Color {
617
- /** Create a color with the components passed in, white by default
618
- * @param {Number} [red=1]
619
- * @param {Number} [green=1]
620
- * @param {Number} [blue=1]
621
- * @param {Number} [alpha=1] */
622
- constructor(r?: number, g?: number, b?: number, a?: number);
623
- /** @property {Number} - Red */
624
- r: number;
625
- /** @property {Number} - Green */
626
- g: number;
627
- /** @property {Number} - Blue */
628
- b: number;
629
- /** @property {Number} - Alpha */
630
- a: number;
631
- /** Returns a new color that is a copy of this
632
- * @return {Color} */
633
- copy(): Color;
634
- /** Returns a copy of this color plus the color passed in
635
- * @param {Color} color
636
- * @return {Color} */
637
- add(c: any): Color;
638
- /** Returns a copy of this color minus the color passed in
639
- * @param {Color} color
640
- * @return {Color} */
641
- subtract(c: any): Color;
642
- /** Returns a copy of this color times the color passed in
643
- * @param {Color} color
644
- * @return {Color} */
645
- multiply(c: any): Color;
646
- /** Returns a copy of this color divided by the color passed in
647
- * @param {Color} color
648
- * @return {Color} */
649
- divide(c: any): Color;
650
- /** Returns a copy of this color scaled by the value passed in, alpha can be scaled separately
651
- * @param {Number} scale
652
- * @param {Number} [alphaScale=scale]
653
- * @return {Color} */
654
- scale(s: any, a?: any): Color;
655
- /** Returns a copy of this color clamped to the valid range between 0 and 1
656
- * @return {Color} */
657
- clamp(): Color;
658
- /** Returns a new color that is p percent between this and the color passed in
659
- * @param {Color} color
660
- * @param {Number} percent
661
- * @return {Color} */
662
- lerp(c: any, p: any): Color;
663
- /** Sets this color given a hue, saturation, lightness, and alpha
664
- * @param {Number} [hue=0]
665
- * @param {Number} [saturation=0]
666
- * @param {Number} [lightness=1]
667
- * @param {Number} [alpha=1]
668
- * @return {Color} */
669
- setHSLA(h?: number, s?: number, l?: number, a?: number): Color;
670
- /** Returns this color expressed in hsla format
671
- * @return {Array} */
672
- getHSLA(): any[];
673
- /** Returns a new color that has each component randomly adjusted
674
- * @param {Number} [amount=.05]
675
- * @param {Number} [alphaAmount=0]
676
- * @return {Color} */
677
- mutate(amount?: number, alphaAmount?: number): Color;
678
- /** Returns this color expressed as a hex color code
679
- * @param {Boolean} [useAlpha=1] - if alpha should be included in result
680
- * @return {String} */
681
- toString(useAlpha?: boolean): string;
682
- /** Set this color from a hex code
683
- * @param {String} hex - html hex code
684
- * @return {Color} */
685
- setHex(hex: string): Color;
686
- /** Returns this color expressed as 32 bit RGBA value
687
- * @return {Number} */
688
- rgbaInt(): number;
689
- }
690
- /**
691
- * Timer object tracks how long has passed since it was set
692
- * @example
693
- * let a = new Timer; // creates a timer that is not set
694
- * a.set(3); // sets the timer to 3 seconds
695
- *
696
- * let b = new Timer(1); // creates a timer with 1 second left
697
- * b.unset(); // unsets the timer
698
- */
699
- declare class Timer {
700
- /** Create a timer object set time passed in
701
- * @param {Number} [timeLeft] - How much time left before the timer elapses in seconds */
702
- constructor(timeLeft?: number);
703
- time: number;
704
- setTime: number;
705
- /** Set the timer with seconds passed in
706
- * @param {Number} [timeLeft=0] - How much time left before the timer is elapsed in seconds */
707
- set(timeLeft?: number): void;
708
- /** Unset the timer */
709
- unset(): void;
710
- /** Returns true if set
711
- * @return {Boolean} */
712
- isSet(): boolean;
713
- /** Returns true if set and has not elapsed
714
- * @return {Boolean} */
715
- active(): boolean;
716
- /** Returns true if set and elapsed
717
- * @return {Boolean} */
718
- elapsed(): boolean;
719
- /** Get how long since elapsed, returns 0 if not set (returns negative if currently active)
720
- * @return {Number} */
721
- get(): number;
722
- /** Get percentage elapsed based on time it was set to, returns 0 if not set
723
- * @return {Number} */
724
- getPercent(): number;
725
- /** Returns this timer expressed as a string
726
- * @return {String} */
727
- toString(): string;
728
- /** Get how long since elapsed, returns 0 if not set (returns negative if currently active)
729
- * @return {Number} */
730
- valueOf(): number;
731
- }
732
- /** Position of camera in world space
733
- * @type {Vector2}
734
- * @default
735
- * @memberof Settings */
736
- declare let cameraPos: Vector2;
737
- /** Scale of camera in world space
738
- * @default
739
- * @memberof Settings */
740
- declare let cameraScale: number;
741
- /** The max size of the canvas, centered if window is larger
742
- * @type {Vector2}
743
- * @default
744
- * @memberof Settings */
745
- declare let canvasMaxSize: Vector2;
746
- /** Fixed size of the canvas, if enabled canvas size never changes
747
- * - you may also need to set mainCanvasSize if using screen space coords in startup
748
- * @type {Vector2}
749
- * @default
750
- * @memberof Settings */
751
- declare let canvasFixedSize: Vector2;
752
- /** Disables anti aliasing for pixel art if true
753
- * @default
754
- * @memberof Settings */
755
- declare let cavasPixelated: number;
756
- /** Default font used for text rendering
757
- * @default
758
- * @memberof Settings */
759
- declare let fontDefault: string;
760
- /** Enable webgl rendering, webgl can be disabled and removed from build (with some features disabled)
761
- * @default
762
- * @memberof Settings */
763
- declare let glEnable: number;
764
- /** Fixes slow rendering in some browsers by not compositing the WebGL canvas
765
- * @default
766
- * @memberof Settings */
767
- declare let glOverlay: number;
768
- /** Default size of tiles in pixels
769
- * @type {Vector2}
770
- * @default
771
- * @memberof Settings */
772
- declare let tileSizeDefault: Vector2;
773
- /** Prevent tile bleeding from neighbors in pixels
774
- * @default
775
- * @memberof Settings */
776
- declare let tileFixBleedScale: number;
777
- /** Default size of objects
778
- * @type {Vector2}
779
- * @default
780
- * @memberof Settings */
781
- declare let objectDefaultSize: Vector2;
782
- /** Enable physics solver for collisions between objects
783
- * @default
784
- * @memberof Settings */
785
- declare let enablePhysicsSolver: number;
786
- /** Default object mass for collison calcuations (how heavy objects are)
787
- * @default
788
- * @memberof Settings */
789
- declare let objectDefaultMass: number;
790
- /** How much to slow velocity by each frame (0-1)
791
- * @default
792
- * @memberof Settings */
793
- declare let objectDefaultDamping: number;
794
- /** How much to slow angular velocity each frame (0-1)
795
- * @default
796
- * @memberof Settings */
797
- declare let objectDefaultAngleDamping: number;
798
- /** How much to bounce when a collision occurs (0-1)
799
- * @default
800
- * @memberof Settings */
801
- declare let objectDefaultElasticity: number;
802
- /** How much to slow when touching (0-1)
803
- * @default
804
- * @memberof Settings */
805
- declare let objectDefaultFriction: number;
806
- /** Clamp max speed to avoid fast objects missing collisions
807
- * @default
808
- * @memberof Settings */
809
- declare let objectMaxSpeed: number;
810
- /** How much gravity to apply to objects along the Y axis, negative is down
811
- * @default
812
- * @memberof Settings */
813
- declare let gravity: number;
814
- /** Scales emit rate of particles, useful for low graphics mode (0 disables particle emitters)
815
- * @default
816
- * @memberof Settings */
817
- declare let particleEmitRateScale: number;
818
- /** Should gamepads be allowed
819
- * @default
820
- * @memberof Settings */
821
- declare let gamepadsEnable: number;
822
- /** If true, the dpad input is also routed to the left analog stick (for better accessability)
823
- * @default
824
- * @memberof Settings */
825
- declare let gamepadDirectionEmulateStick: number;
826
- /** If true the WASD keys are also routed to the direction keys (for better accessability)
827
- * @default
828
- * @memberof Settings */
829
- declare let inputWASDEmulateDirection: number;
830
- /** True if touch gamepad should appear on mobile devices
831
- * <br> - Supports left analog stick, 4 face buttons and start button (button 9)
832
- * <br> - Must be set by end of gameInit to be activated
833
- * @default
834
- * @memberof Settings */
835
- declare let touchGamepadEnable: number;
836
- /** True if touch gamepad should be analog stick or false to use if 8 way dpad
837
- * @default
838
- * @memberof Settings */
839
- declare let touchGamepadAnalog: number;
840
- /** Size of virutal gamepad for touch devices in pixels
841
- * @default
842
- * @memberof Settings */
843
- declare let touchGamepadSize: number;
844
- /** Transparency of touch gamepad overlay
845
- * @default
846
- * @memberof Settings */
847
- declare let touchGamepadAlpha: number;
848
- /** Allow vibration hardware if it exists
849
- * @default
850
- * @memberof Settings */
851
- declare let vibrateEnable: number;
852
- /** All audio code can be disabled and removed from build
853
- * @default
854
- * @memberof Settings */
855
- declare let soundEnable: number;
856
- /** Volume scale to apply to all sound, music and speech
857
- * @default
858
- * @memberof Settings */
859
- declare let soundVolume: number;
860
- /** Default range where sound no longer plays
861
- * @default
862
- * @memberof Settings */
863
- declare let soundDefaultRange: number;
864
- /** Default range percent to start tapering off sound (0-1)
865
- * @default
866
- * @memberof Settings */
867
- declare let soundDefaultTaper: number;
868
- /** How long to show medals for in seconds
869
- * @default
870
- * @memberof Settings */
871
- declare let medalDisplayTime: number;
872
- /** How quickly to slide on/off medals in seconds
873
- * @default
874
- * @memberof Settings */
875
- declare let medalDisplaySlideTime: number;
876
- /** Size of medal display
877
- * @default
878
- * @memberof Settings */
879
- declare let medalDisplaySize: Vector2;
880
- /** Size of icon in medal display
881
- * @default
882
- * @memberof Settings */
883
- declare let medalDisplayIconSize: number;
884
- /** Set to stop medals from being unlockable (like if cheats are enabled)
885
- * @default
886
- * @memberof Settings */
887
- declare let medalsPreventUnlock: any;
888
- /**
889
- * LittleJS Object Base Object Class
890
- * <br> - Base object class used by the engine
891
- * <br> - Automatically adds self to object list
892
- * <br> - Will be updated and rendered each frame
893
- * <br> - Renders as a sprite from a tilesheet by default
894
- * <br> - Can have color and addtive color applied
895
- * <br> - 2d Physics and collision system
896
- * <br> - Sorted by renderOrder
897
- * <br> - Objects can have children attached
898
- * <br> - Parents are updated before children, and set child transform
899
- * <br> - Call destroy() to get rid of objects
900
- * <br>
901
- * <br>The physics system used by objects is simple and fast with some caveats...
902
- * <br> - Collision uses the axis aligned size, the object's rotation angle is only for rendering
903
- * <br> - Objects are guaranteed to not intersect tile collision from physics
904
- * <br> - If an object starts or is moved inside tile collision, it will not collide with that tile
905
- * <br> - Collision for objects can be set to be solid to block other objects
906
- * <br> - Objects may get pushed into overlapping other solid objects, if so they will push away
907
- * <br> - Solid objects are more performance intensive and should be used sparingly
908
- * @example
909
- * // create an engine object, normally you would first extend the class with your own
910
- * const pos = vec2(2,3);
911
- * const object = new EngineObject(pos);
912
- */
913
- declare class EngineObject {
914
- /** Create an engine object and adds it to the list of objects
915
- * @param {Vector2} [position=new Vector2()] - World space position of the object
916
- * @param {Vector2} [size=objectDefaultSize] - World space size of the object
917
- * @param {Number} [tileIndex=-1] - Tile to use to render object (-1 is untextured)
918
- * @param {Vector2} [tileSize=tileSizeDefault] - Size of tile in source pixels
919
- * @param {Number} [angle=0] - Angle the object is rotated by
920
- * @param {Color} [color] - Color to apply to tile when rendered
921
- * @param {Number} [renderOrder=0] - Objects sorted by renderOrder before being rendered
922
- */
923
- constructor(pos?: Vector2, size?: Vector2, tileIndex?: number, tileSize?: Vector2, angle?: number, color?: Color, renderOrder?: number);
924
- /** @property {Vector2} - World space position of the object */
925
- pos: Vector2;
926
- /** @property {Vector2} - World space width and height of the object */
927
- size: Vector2;
928
- /** @property {Number} - Tile to use to render object (-1 is untextured) */
929
- tileIndex: number;
930
- /** @property {Vector2} - Size of tile in source pixels */
931
- tileSize: Vector2;
932
- /** @property {Number} - Angle to rotate the object */
933
- angle: number;
934
- /** @property {Color} - Color to apply when rendered */
935
- color: Color;
936
- /** @property {Number} [mass=objectDefaultMass] - How heavy the object is, static if 0 */
937
- mass: number;
938
- /** @property {Number} [damping=objectDefaultDamping] - How much to slow down velocity each frame (0-1) */
939
- damping: number;
940
- /** @property {Number} [angleDamping=objectDefaultAngleDamping] - How much to slow down rotation each frame (0-1) */
941
- angleDamping: number;
942
- /** @property {Number} [elasticity=objectDefaultElasticity] - How bouncy the object is when colliding (0-1) */
943
- elasticity: number;
944
- /** @property {Number} [friction=objectDefaultFriction] - How much friction to apply when sliding (0-1) */
945
- friction: number;
946
- /** @property {Number} [gravityScale=1] - How much to scale gravity by for this object */
947
- gravityScale: number;
948
- /** @property {Number} [renderOrder=0] - Objects are sorted by render order */
949
- renderOrder: number;
950
- /** @property {Vector2} [velocity=new Vector2()] - Velocity of the object */
951
- velocity: Vector2;
952
- /** @property {Number} [angleVelocity=0] - Angular velocity of the object */
953
- angleVelocity: number;
954
- spawnTime: number;
955
- children: any[];
956
- collideTiles: number;
957
- /** Update the object transform and physics, called automatically by engine once each frame */
958
- update(): void;
959
- groundObject: any;
960
- /** Render the object, draws a tile by default, automatically called each frame, sorted by renderOrder */
961
- render(): void;
962
- /** Destroy this object, destroy it's children, detach it's parent, and mark it for removal */
963
- destroy(): void;
964
- destroyed: number;
965
- /** Called to check if a tile collision should be resolved
966
- * @param {Number} tileData - the value of the tile at the position
967
- * @param {Vector2} pos - tile where the collision occured
968
- * @return {Boolean} - true if the collision should be resolved */
969
- collideWithTile(tileData: number, pos: Vector2): boolean;
970
- /** Called to check if a tile raycast hit
971
- * @param {Number} tileData - the value of the tile at the position
972
- * @param {Vector2} pos - tile where the raycast is
973
- * @return {Boolean} - true if the raycast should hit */
974
- collideWithTileRaycast(tileData: number, pos: Vector2): boolean;
975
- /** Called to check if a object collision should be resolved
976
- * @param {EngineObject} object - the object to test against
977
- * @return {Boolean} - true if the collision should be resolved
978
- */
979
- collideWithObject(o: any): boolean;
980
- /** How long since the object was created
981
- * @return {Number} */
982
- getAliveTime(): number;
983
- /** Apply acceleration to this object (adjust velocity, not affected by mass)
984
- * @param {Vector2} acceleration */
985
- applyAcceleration(a: any): void;
986
- /** Apply force to this object (adjust velocity, affected by mass)
987
- * @param {Vector2} force */
988
- applyForce(force: Vector2): void;
989
- /** Get the direction of the mirror
990
- * @return {Number} -1 if this.mirror is true, or 1 if not mirrored */
991
- getMirrorSign(): number;
992
- /** Attaches a child to this with a given local transform
993
- * @param {EngineObject} child
994
- * @param {Vector2} [localPos=new Vector2]
995
- * @param {Number} [localAngle=0] */
996
- addChild(child: EngineObject, localPos?: Vector2, localAngle?: number): void;
997
- /** Removes a child from this one
998
- * @param {EngineObject} child */
999
- removeChild(child: EngineObject): void;
1000
- /** Set how this object collides
1001
- * @param {boolean} [collideSolidObjects=1] - Does it collide with solid objects
1002
- * @param {boolean} [isSolid=1] - Does it collide with and block other objects (expensive in large numbers)
1003
- * @param {boolean} [collideTiles=1] - Does it collide with the tile collision */
1004
- setCollision(collideSolidObjects?: boolean, isSolid?: boolean, collideTiles?: boolean): void;
1005
- collideSolidObjects: boolean;
1006
- isSolid: boolean;
1007
- toString(): string;
1008
- }
1009
- /** The primary 2D canvas visible to the user
1010
- * @type {HTMLCanvasElement}
1011
- * @memberof Draw */
1012
- declare let mainCanvas: HTMLCanvasElement;
1013
- /** 2d context for mainCanvas
1014
- * @type {CanvasRenderingContext2D}
1015
- * @memberof Draw */
1016
- declare let mainContext: CanvasRenderingContext2D;
1017
- /** A canvas that appears on top of everything the same size as mainCanvas
1018
- * @type {HTMLCanvasElement}
1019
- * @memberof Draw */
1020
- declare let overlayCanvas: HTMLCanvasElement;
1021
- /** 2d context for overlayCanvas
1022
- * @type {CanvasRenderingContext2D}
1023
- * @memberof Draw */
1024
- declare let overlayContext: CanvasRenderingContext2D;
1025
- /** The size of the main canvas (and other secondary canvases)
1026
- * @type {Vector2}
1027
- * @memberof Draw */
1028
- declare let mainCanvasSize: Vector2;
1029
- /** Tile sheet for batch rendering system
1030
- * @type {Image}
1031
- * @memberof Draw */
1032
- declare const tileImage: new (width?: number, height?: number) => HTMLImageElement;
1033
- declare let tileImageSize: any;
1034
- declare let tileImageFixBleed: any;
1035
- declare let drawCount: any;
1036
- /** Convert from screen to world space coordinates
1037
- * - if calling outside of render, you may need to manually set mainCanvasSize
1038
- * @param {Vector2} screenPos
1039
- * @return {Vector2}
1040
- * @memberof Draw */
1041
- declare function screenToWorld(screenPos: Vector2): Vector2;
1042
- /** Convert from world to screen space coordinates
1043
- * - if calling outside of render, you may need to manually set mainCanvasSize
1044
- * @param {Vector2} worldPos
1045
- * @return {Vector2}
1046
- * @memberof Draw */
1047
- declare function worldToScreen(worldPos: Vector2): Vector2;
1048
- /**
1049
- * Font Image Object - Draw text on a 2D canvas by using characters in an image
1050
- * <br> - 96 characters (from space to tilde) are stored in an image
1051
- * <br> - Uses a default 8x8 font if none is supplied
1052
- * <br> - You can also use fonts from the main tile sheet
1053
- * @example
1054
- * // use built in font
1055
- * const font = new ImageFont;
1056
- *
1057
- * // draw text
1058
- * font.drawTextScreen("LittleJS\nHello World!", vec2(200, 50));
1059
- */
1060
- declare let engineFontImage: any;
1061
- declare class FontImage {
1062
- /** Create an image font
1063
- * @param {HTMLImageElement} [image] - Image for the font, if undefined default font is used
1064
- * @param {Vector2} [tileSize=vec2(8)] - Size of the font source tiles
1065
- * @param {Vector2} [paddingSize=vec2(0,1)] - How much extra space to add between characters
1066
- * @param {Number} [startTileIndex=0] - Tile index in image where font starts
1067
- * @param {CanvasRenderingContext2D} [context=overlayContext] - context to draw to
1
+ declare module "engine.all.module" {
2
+ /**
3
+ * LittleJS Module Export
4
+ * <br> - Export engine as a module with extra functions where necessary
1068
5
  */
1069
- constructor(image?: HTMLImageElement, tileSize?: Vector2, paddingSize?: Vector2, startTileIndex?: number, context?: CanvasRenderingContext2D);
1070
- image: any;
1071
- tileSize: Vector2;
1072
- paddingSize: Vector2;
1073
- startTileIndex: number;
1074
- context: CanvasRenderingContext2D;
1075
- /** Draw text in screen space using the image font
1076
- * @param {String} text
6
+ export function setCameraPos(v: any): any;
7
+ export function setCameraScale(v: any): any;
8
+ export function setCanvasMaxSize(v: any): any;
9
+ export function setCanvasFixedSize(v: any): any;
10
+ export function setCavasPixelated(v: any): any;
11
+ export function setFontDefault(v: any): any;
12
+ export function setGlEnable(v: any): any;
13
+ export function setGlOverlay(v: any): any;
14
+ export function setTileSizeDefault(v: any): any;
15
+ export function setTileFixBleedScale(v: any): any;
16
+ export function setObjectDefaultSize(v: any): any;
17
+ export function setEnablePhysicsSolver(v: any): any;
18
+ export function setObjectDefaultMass(v: any): any;
19
+ export function setObjectDefaultDamping(v: any): any;
20
+ export function setObjectDefaultAngleDamping(v: any): any;
21
+ export function setObjectDefaultElasticity(v: any): any;
22
+ export function setObjectDefaultFriction(v: any): any;
23
+ export function setObjectMaxSpeed(v: any): any;
24
+ export function setGravity(v: any): any;
25
+ export function setParticleEmitRateScale(v: any): any;
26
+ export function setGamepadsEnable(v: any): any;
27
+ export function setGamepadDirectionEmulateStick(v: any): any;
28
+ export function setInputWASDEmulateDirection(v: any): any;
29
+ export function setTouchGamepadEnable(v: any): any;
30
+ export function setTouchGamepadAnalog(v: any): any;
31
+ export function setTouchGamepadSize(v: any): any;
32
+ export function setTouchGamepadAlpha(v: any): any;
33
+ export function setVibrateEnable(v: any): any;
34
+ export function setSoundEnable(v: any): any;
35
+ export function setSoundVolume(v: any): any;
36
+ export function setSoundDefaultRange(v: any): any;
37
+ export function setSoundDefaultTaper(v: any): any;
38
+ export function setMedalDisplayTime(v: any): any;
39
+ export function setMedalDisplaySlideTime(v: any): any;
40
+ export function setMedalDisplaySize(v: any): any;
41
+ export function setMedalDisplayIconSize(v: any): any;
42
+ export function setMedalsPreventUnlock(v: any): any;
43
+ /** The max size of the canvas, centered if window is larger
44
+ * @type {Vector2}
45
+ * @default
46
+ * @memberof Settings */
47
+ export let canvasMaxSize: Vector2;
48
+ /** Fixed size of the canvas, if enabled canvas size never changes
49
+ * - you may also need to set mainCanvasSize if using screen space coords in startup
50
+ * @type {Vector2}
51
+ * @default
52
+ * @memberof Settings */
53
+ export let canvasFixedSize: Vector2;
54
+ /** Disables anti aliasing for pixel art if true
55
+ * @default
56
+ * @memberof Settings */
57
+ export let cavasPixelated: number;
58
+ /** Default font used for text rendering
59
+ * @default
60
+ * @memberof Settings */
61
+ export let fontDefault: string;
62
+ /** Default size of tiles in pixels
63
+ * @type {Vector2}
64
+ * @default
65
+ * @memberof Settings */
66
+ export let tileSizeDefault: Vector2;
67
+ /** Prevent tile bleeding from neighbors in pixels
68
+ * @default
69
+ * @memberof Settings */
70
+ export let tileFixBleedScale: number;
71
+ /** Default size of objects
72
+ * @type {Vector2}
73
+ * @default
74
+ * @memberof Settings */
75
+ export let objectDefaultSize: Vector2;
76
+ /** Enable physics solver for collisions between objects
77
+ * @default
78
+ * @memberof Settings */
79
+ export let enablePhysicsSolver: number;
80
+ /** Default object mass for collison calcuations (how heavy objects are)
81
+ * @default
82
+ * @memberof Settings */
83
+ export let objectDefaultMass: number;
84
+ /** How much to slow velocity by each frame (0-1)
85
+ * @default
86
+ * @memberof Settings */
87
+ export let objectDefaultDamping: number;
88
+ /** How much to slow angular velocity each frame (0-1)
89
+ * @default
90
+ * @memberof Settings */
91
+ export let objectDefaultAngleDamping: number;
92
+ /** How much to bounce when a collision occurs (0-1)
93
+ * @default
94
+ * @memberof Settings */
95
+ export let objectDefaultElasticity: number;
96
+ /** How much to slow when touching (0-1)
97
+ * @default
98
+ * @memberof Settings */
99
+ export let objectDefaultFriction: number;
100
+ /** Clamp max speed to avoid fast objects missing collisions
101
+ * @default
102
+ * @memberof Settings */
103
+ export let objectMaxSpeed: number;
104
+ /** How much gravity to apply to objects along the Y axis, negative is down
105
+ * @default
106
+ * @memberof Settings */
107
+ export let gravity: number;
108
+ /** Scales emit rate of particles, useful for low graphics mode (0 disables particle emitters)
109
+ * @default
110
+ * @memberof Settings */
111
+ export let particleEmitRateScale: number;
112
+ /** Position of camera in world space
113
+ * @type {Vector2}
114
+ * @default
115
+ * @memberof Settings */
116
+ export let cameraPos: Vector2;
117
+ /** Scale of camera in world space
118
+ * @default
119
+ * @memberof Settings */
120
+ export let cameraScale: number;
121
+ /** Enable webgl rendering, webgl can be disabled and removed from build (with some features disabled)
122
+ * @default
123
+ * @memberof Settings */
124
+ export let glEnable: number;
125
+ /** Fixes slow rendering in some browsers by not compositing the WebGL canvas
126
+ * @default
127
+ * @memberof Settings */
128
+ export let glOverlay: number;
129
+ /** Should gamepads be allowed
130
+ * @default
131
+ * @memberof Settings */
132
+ export let gamepadsEnable: number;
133
+ /** If true, the dpad input is also routed to the left analog stick (for better accessability)
134
+ * @default
135
+ * @memberof Settings */
136
+ export let gamepadDirectionEmulateStick: number;
137
+ /** If true the WASD keys are also routed to the direction keys (for better accessability)
138
+ * @default
139
+ * @memberof Settings */
140
+ export let inputWASDEmulateDirection: number;
141
+ /** True if touch gamepad should appear on mobile devices
142
+ * <br> - Supports left analog stick, 4 face buttons and start button (button 9)
143
+ * <br> - Must be set by end of gameInit to be activated
144
+ * @default
145
+ * @memberof Settings */
146
+ export let touchGamepadEnable: number;
147
+ /** True if touch gamepad should be analog stick or false to use if 8 way dpad
148
+ * @default
149
+ * @memberof Settings */
150
+ export let touchGamepadAnalog: number;
151
+ /** Size of virutal gamepad for touch devices in pixels
152
+ * @default
153
+ * @memberof Settings */
154
+ export let touchGamepadSize: number;
155
+ /** Transparency of touch gamepad overlay
156
+ * @default
157
+ * @memberof Settings */
158
+ export let touchGamepadAlpha: number;
159
+ /** Allow vibration hardware if it exists
160
+ * @default
161
+ * @memberof Settings */
162
+ export let vibrateEnable: number;
163
+ /** All audio code can be disabled and removed from build
164
+ * @default
165
+ * @memberof Settings */
166
+ export let soundEnable: number;
167
+ /** Volume scale to apply to all sound, music and speech
168
+ * @default
169
+ * @memberof Settings */
170
+ export let soundVolume: number;
171
+ /** Default range where sound no longer plays
172
+ * @default
173
+ * @memberof Settings */
174
+ export let soundDefaultRange: number;
175
+ /** Default range percent to start tapering off sound (0-1)
176
+ * @default
177
+ * @memberof Settings */
178
+ export let soundDefaultTaper: number;
179
+ /** How long to show medals for in seconds
180
+ * @default
181
+ * @memberof Settings */
182
+ export let medalDisplayTime: number;
183
+ /** How quickly to slide on/off medals in seconds
184
+ * @default
185
+ * @memberof Settings */
186
+ export let medalDisplaySlideTime: number;
187
+ /** Size of medal display
188
+ * @default
189
+ * @memberof Settings */
190
+ export let medalDisplaySize: Vector2;
191
+ /** Size of icon in medal display
192
+ * @default
193
+ * @memberof Settings */
194
+ export let medalDisplayIconSize: number;
195
+ /** True if debug is enabled
196
+ * @default
197
+ * @memberof Debug */
198
+ export const debug: 1;
199
+ /** True if watermark with FPS should be down, false in release builds
200
+ * @default
201
+ * @memberof Debug */
202
+ export let showWatermark: number;
203
+ /** True if god mode is enabled, handle this however you want
204
+ * @default
205
+ * @memberof Debug */
206
+ export let godMode: number;
207
+ /** Draw a debug rectangle in world space
1077
208
  * @param {Vector2} pos
1078
- * @param {Number} [scale=4]
1079
- * @param {Boolean} [center]
1080
- */
1081
- drawTextScreen(text: string, pos: Vector2, scale?: number, center?: boolean): void;
1082
- /** Draw text in world space using the image font
209
+ * @param {Vector2} [size=new Vector2()]
210
+ * @param {String} [color='#fff']
211
+ * @param {Number} [time=0]
212
+ * @param {Number} [angle=0]
213
+ * @param {Boolean} [fill=false]
214
+ * @memberof Debug */
215
+ export function debugRect(pos: Vector2, size?: Vector2, color?: string, time?: number, angle?: number, fill?: boolean): void;
216
+ /** Draw a debug circle in world space
217
+ * @param {Vector2} pos
218
+ * @param {Number} [radius=0]
219
+ * @param {String} [color='#fff']
220
+ * @param {Number} [time=0]
221
+ * @param {Boolean} [fill=false]
222
+ * @memberof Debug */
223
+ export function debugCircle(pos: Vector2, radius?: number, color?: string, time?: number, fill?: boolean): void;
224
+ /** Draw a debug point in world space
225
+ * @param {Vector2} pos
226
+ * @param {String} [color='#fff']
227
+ * @param {Number} [time=0]
228
+ * @param {Number} [angle=0]
229
+ * @memberof Debug */
230
+ export function debugPoint(pos: Vector2, color?: string, time?: number, angle?: number): void;
231
+ /** Draw a debug line in world space
232
+ * @param {Vector2} posA
233
+ * @param {Vector2} posB
234
+ * @param {String} [color='#fff']
235
+ * @param {Number} [thickness=.1]
236
+ * @param {Number} [time=0]
237
+ * @memberof Debug */
238
+ export function debugLine(posA: Vector2, posB: Vector2, color?: string, thickness?: number, time?: number): void;
239
+ /** Draw a debug axis aligned bounding box in world space
240
+ * @param {Vector2} posA
241
+ * @param {Vector2} sizeA
242
+ * @param {Vector2} posB
243
+ * @param {Vector2} sizeB
244
+ * @param {String} [color='#fff']
245
+ * @memberof Debug */
246
+ export function debugAABB(pA: any, sA: any, pB: any, sB: any, color?: string): void;
247
+ /** Draw a debug axis aligned bounding box in world space
1083
248
  * @param {String} text
1084
249
  * @param {Vector2} pos
1085
- * @param {Number} [scale=.25]
1086
- * @param {Boolean} [center]
250
+ * @param {Number} [size=1]
251
+ * @param {String} [color='#fff']
252
+ * @param {Number} [time=0]
253
+ * @param {Number} [angle=0]
254
+ * @param {String} [font='monospace']
255
+ * @memberof Debug */
256
+ export function debugText(text: string, pos: Vector2, size?: number, color?: string, time?: number, angle?: number, font?: string): void;
257
+ /** Clear all debug primitives in the list
258
+ * @memberof Debug */
259
+ export function debugClear(): any[];
260
+ /** Save a canvas to disk
261
+ * @param {HTMLCanvasElement} canvas
262
+ * @param {String} [filename]
263
+ * @memberof Debug */
264
+ export function debugSaveCanvas(canvas: HTMLCanvasElement, filename?: string): void;
265
+ /** A shortcut to get Math.PI
266
+ * @const
267
+ * @memberof Utilities */
268
+ export const PI: number;
269
+ /** Returns absoulte value of value passed in
270
+ * @param {Number} value
271
+ * @return {Number}
272
+ * @memberof Utilities */
273
+ export function abs(a: any): number;
274
+ /** Returns lowest of two values passed in
275
+ * @param {Number} valueA
276
+ * @param {Number} valueB
277
+ * @return {Number}
278
+ * @memberof Utilities */
279
+ export function min(a: any, b: any): number;
280
+ /** Returns highest of two values passed in
281
+ * @param {Number} valueA
282
+ * @param {Number} valueB
283
+ * @return {Number}
284
+ * @memberof Utilities */
285
+ export function max(a: any, b: any): number;
286
+ /** Returns the sign of value passed in (also returns 1 if 0)
287
+ * @param {Number} value
288
+ * @return {Number}
289
+ * @memberof Utilities */
290
+ export function sign(a: any): number;
291
+ /** Returns first parm modulo the second param, but adjusted so negative numbers work as expected
292
+ * @param {Number} dividend
293
+ * @param {Number} [divisor=1]
294
+ * @return {Number}
295
+ * @memberof Utilities */
296
+ export function mod(a: any, b?: number): number;
297
+ /** Clamps the value beween max and min
298
+ * @param {Number} value
299
+ * @param {Number} [min=0]
300
+ * @param {Number} [max=1]
301
+ * @return {Number}
302
+ * @memberof Utilities */
303
+ export function clamp(v: any, min?: number, max?: number): number;
304
+ /** Returns what percentage the value is between max and min
305
+ * @param {Number} value
306
+ * @param {Number} [min=0]
307
+ * @param {Number} [max=1]
308
+ * @return {Number}
309
+ * @memberof Utilities */
310
+ export function percent(v: any, min?: number, max?: number): number;
311
+ /** Linearly interpolates the percent value between max and min
312
+ * @param {Number} percent
313
+ * @param {Number} [min=0]
314
+ * @param {Number} [max=1]
315
+ * @return {Number}
316
+ * @memberof Utilities */
317
+ export function lerp(p: any, min?: number, max?: number): number;
318
+ /** Applies smoothstep function to the percentage value
319
+ * @param {Number} value
320
+ * @return {Number}
321
+ * @memberof Utilities */
322
+ export function smoothStep(p: any): number;
323
+ /** Returns the nearest power of two not less then the value
324
+ * @param {Number} value
325
+ * @return {Number}
326
+ * @memberof Utilities */
327
+ export function nearestPowerOfTwo(v: any): number;
328
+ /** Returns true if two axis aligned bounding boxes are overlapping
329
+ * @param {Vector2} pointA - Center of box A
330
+ * @param {Vector2} sizeA - Size of box A
331
+ * @param {Vector2} pointB - Center of box B
332
+ * @param {Vector2} [sizeB] - Size of box B
333
+ * @return {Boolean} - True if overlapping
334
+ * @memberof Utilities */
335
+ export function isOverlapping(pA: any, sA: any, pB: any, sB: any): boolean;
336
+ /** Returns an oscillating wave between 0 and amplitude with frequency of 1 Hz by default
337
+ * @param {Number} [frequency=1] - Frequency of the wave in Hz
338
+ * @param {Number} [amplitude=1] - Amplitude (max height) of the wave
339
+ * @param {Number} [t=time] - Value to use for time of the wave
340
+ * @return {Number} - Value waving between 0 and amplitude
341
+ * @memberof Utilities */
342
+ export function wave(frequency?: number, amplitude?: number, t?: number): number;
343
+ /** Formats seconds to mm:ss style for display purposes
344
+ * @param {Number} t - time in seconds
345
+ * @return {String}
346
+ * @memberof Utilities */
347
+ export function formatTime(t: number): string;
348
+ /** Random global functions
349
+ * @namespace Random */
350
+ /** Returns a random value between the two values passed in
351
+ * @param {Number} [valueA=1]
352
+ * @param {Number} [valueB=0]
353
+ * @return {Number}
354
+ * @memberof Random */
355
+ export function rand(a?: number, b?: number): number;
356
+ /** Returns a floored random value the two values passed in
357
+ * @param {Number} [valueA=1]
358
+ * @param {Number} [valueB=0]
359
+ * @return {Number}
360
+ * @memberof Random */
361
+ export function randInt(a?: number, b?: number): number;
362
+ /** Randomly returns either -1 or 1
363
+ * @return {Number}
364
+ * @memberof Random */
365
+ export function randSign(): number;
366
+ /** Returns a random Vector2 within a circular shape
367
+ * @param {Number} [radius=1]
368
+ * @param {Number} [minRadius=0]
369
+ * @return {Vector2}
370
+ * @memberof Random */
371
+ export function randInCircle(radius?: number, minRadius?: number): Vector2;
372
+ /** Returns a random Vector2 with the passed in length
373
+ * @param {Number} [length=1]
374
+ * @return {Vector2}
375
+ * @memberof Random */
376
+ export function randVector(length?: number): Vector2;
377
+ /** Returns a random color between the two passed in colors, combine components if linear
378
+ * @param {Color} [colorA=new Color(1,1,1,1)]
379
+ * @param {Color} [colorB=new Color(0,0,0,1)]
380
+ * @param {Boolean} [linear]
381
+ * @return {Color}
382
+ * @memberof Random */
383
+ export function randColor(cA?: Color, cB?: Color, linear?: boolean): Color;
384
+ /** Seed used by the randSeeded function
385
+ * @memberof Random */
386
+ export let randSeed: number;
387
+ /** Set seed used by the randSeeded function, should not be 0
388
+ * @param {Number} seed
389
+ * @memberof Random */
390
+ export function setRandSeed(seed: number): number;
391
+ /** Returns a seeded random value between the two values passed in using randSeed
392
+ * @param {Number} [valueA=1]
393
+ * @param {Number} [valueB=0]
394
+ * @return {Number}
395
+ * @memberof Random */
396
+ export function randSeeded(a?: number, b?: number): number;
397
+ /**
398
+ * 2D Vector object with vector math library
399
+ * <br> - Functions do not change this so they can be chained together
400
+ * @example
401
+ * let a = new Vector2(2, 3); // vector with coordinates (2, 3)
402
+ * let b = new Vector2; // vector with coordinates (0, 0)
403
+ * let c = vec2(4, 2); // use the vec2 function to make a Vector2
404
+ * let d = a.add(b).scale(5); // operators can be chained
1087
405
  */
1088
- drawText(text: string, pos: Vector2, scale?: number, center?: boolean): void;
1089
- }
1090
- /** Returns true if fullscreen mode is active
1091
- * @return {Boolean}
1092
- * @memberof Draw */
1093
- declare function isFullscreen(): boolean;
1094
- /** Returns true if device key is down
1095
- * @param {Number} key
1096
- * @param {Number} [device=0]
1097
- * @return {Boolean}
1098
- * @memberof Input */
1099
- declare function keyIsDown(key: number, device?: number): boolean;
1100
- /** Returns true if device key was pressed this frame
1101
- * @param {Number} key
1102
- * @param {Number} [device=0]
1103
- * @return {Boolean}
1104
- * @memberof Input */
1105
- declare function keyWasPressed(key: number, device?: number): boolean;
1106
- /** Returns true if device key was released this frame
1107
- * @param {Number} key
1108
- * @param {Number} [device=0]
1109
- * @return {Boolean}
1110
- * @memberof Input */
1111
- declare function keyWasReleased(key: number, device?: number): boolean;
1112
- /** Clears all input
1113
- * @memberof Input */
1114
- declare function clearInput(): any[][];
1115
- /** Returns true if device key is down
1116
- * @param {Number} key
1117
- * @param {Number} [device=0]
1118
- * @return {Boolean}
1119
- * @memberof Input */
1120
- declare function mouseIsDown(key: number, device?: number): boolean;
1121
- /** Returns true if device key was pressed this frame
1122
- * @param {Number} key
1123
- * @param {Number} [device=0]
1124
- * @return {Boolean}
1125
- * @memberof Input */
1126
- declare function mouseWasPressed(key: number, device?: number): boolean;
1127
- /** Returns true if device key was released this frame
1128
- * @param {Number} key
1129
- * @param {Number} [device=0]
1130
- * @return {Boolean}
1131
- * @memberof Input */
1132
- declare function mouseWasReleased(key: number, device?: number): boolean;
1133
- /** Mouse pos in world space
1134
- * @type {Vector2}
1135
- * @memberof Input */
1136
- declare let mousePos: Vector2;
1137
- /** Mouse pos in screen space
1138
- * @type {Vector2}
1139
- * @memberof Input */
1140
- declare let mousePosScreen: Vector2;
1141
- /** Mouse wheel delta this frame
1142
- * @memberof Input */
1143
- declare let mouseWheel: number;
1144
- /** Returns true if user is using gamepad (has more recently pressed a gamepad button)
1145
- * @memberof Input */
1146
- declare let isUsingGamepad: number;
1147
- /** Prevents input continuing to the default browser handling (false by default)
1148
- * @memberof Input */
1149
- declare let preventDefaultInput: number;
1150
- /** Returns true if gamepad button is down
1151
- * @param {Number} button
1152
- * @param {Number} [gamepad=0]
1153
- * @return {Boolean}
1154
- * @memberof Input */
1155
- declare function gamepadIsDown(button: number, gamepad?: number): boolean;
1156
- /** Returns true if gamepad button was pressed
1157
- * @param {Number} button
1158
- * @param {Number} [gamepad=0]
1159
- * @return {Boolean}
1160
- * @memberof Input */
1161
- declare function gamepadWasPressed(button: number, gamepad?: number): boolean;
1162
- /** Returns true if gamepad button was released
1163
- * @param {Number} button
1164
- * @param {Number} [gamepad=0]
1165
- * @return {Boolean}
1166
- * @memberof Input */
1167
- declare function gamepadWasReleased(button: number, gamepad?: number): boolean;
1168
- /** Returns gamepad stick value
1169
- * @param {Number} stick
1170
- * @param {Number} [gamepad=0]
1171
- * @return {Vector2}
1172
- * @memberof Input */
1173
- declare function gamepadStick(stick: number, gamepad?: number): Vector2;
1174
- declare let inputData: any[][];
1175
- declare function remapKeyCode(c: any): any;
1176
- declare function mouseToScreen(mousePos: any): Vector2;
1177
- declare const stickData: any[];
1178
- /** Pulse the vibration hardware if it exists
1179
- * @param {Number} [pattern=100] - a single value in miliseconds or vibration interval array
1180
- * @memberof Input */
1181
- declare function vibrate(pattern?: number): boolean;
1182
- /** Cancel any ongoing vibration
1183
- * @memberof Input */
1184
- declare function vibrateStop(): boolean;
1185
- /** True if a touch device has been detected
1186
- * @const {boolean}
1187
- * @memberof Input */
1188
- declare const isTouchDevice: boolean;
1189
- declare let touchGamepadTimer: Timer;
1190
- declare let touchGamepadButtons: any;
1191
- declare let touchGamepadStick: any;
1192
- /**
1193
- * Sound Object - Stores a zzfx sound for later use and can be played positionally
1194
- * <br>
1195
- * <br><b><a href=https://killedbyapixel.github.io/ZzFX/>Create sounds using the ZzFX Sound Designer.</a></b>
1196
- * @example
1197
- * // create a sound
1198
- * const sound_example = new Sound([.5,.5]);
1199
- *
1200
- * // play the sound
1201
- * sound_example.play();
1202
- */
1203
- declare class Sound {
1204
- /** Create a sound object and cache the zzfx samples for later use
1205
- * @param {Array} zzfxSound - Array of zzfx parameters, ex. [.5,.5]
1206
- * @param {Number} [range=soundDefaultRange] - World space max range of sound, will not play if camera is farther away
1207
- * @param {Number} [taper=soundDefaultTaper] - At what percentage of range should it start tapering off
406
+ export class Vector2 {
407
+ /** Create a 2D vector with the x and y passed in, can also be created with vec2()
408
+ * @param {Number} [x=0] - X axis location
409
+ * @param {Number} [y=0] - Y axis location */
410
+ constructor(x?: number, y?: number);
411
+ /** @property {Number} - X axis location */
412
+ x: number;
413
+ /** @property {Number} - Y axis location */
414
+ y: number;
415
+ /** Returns a new vector that is a copy of this
416
+ * @return {Vector2} */
417
+ copy(): Vector2;
418
+ /** Returns a copy of this vector plus the vector passed in
419
+ * @param {Vector2} vector
420
+ * @return {Vector2} */
421
+ add(v: any): Vector2;
422
+ /** Returns a copy of this vector minus the vector passed in
423
+ * @param {Vector2} vector
424
+ * @return {Vector2} */
425
+ subtract(v: any): Vector2;
426
+ /** Returns a copy of this vector times the vector passed in
427
+ * @param {Vector2} vector
428
+ * @return {Vector2} */
429
+ multiply(v: any): Vector2;
430
+ /** Returns a copy of this vector divided by the vector passed in
431
+ * @param {Vector2} vector
432
+ * @return {Vector2} */
433
+ divide(v: any): Vector2;
434
+ /** Returns a copy of this vector scaled by the vector passed in
435
+ * @param {Number} scale
436
+ * @return {Vector2} */
437
+ scale(s: any): Vector2;
438
+ /** Returns the length of this vector
439
+ * @return {Number} */
440
+ length(): number;
441
+ /** Returns the length of this vector squared
442
+ * @return {Number} */
443
+ lengthSquared(): number;
444
+ /** Returns the distance from this vector to vector passed in
445
+ * @param {Vector2} vector
446
+ * @return {Number} */
447
+ distance(v: any): number;
448
+ /** Returns the distance squared from this vector to vector passed in
449
+ * @param {Vector2} vector
450
+ * @return {Number} */
451
+ distanceSquared(v: any): number;
452
+ /** Returns a new vector in same direction as this one with the length passed in
453
+ * @param {Number} [length=1]
454
+ * @return {Vector2} */
455
+ normalize(length?: number): Vector2;
456
+ /** Returns a new vector clamped to length passed in
457
+ * @param {Number} [length=1]
458
+ * @return {Vector2} */
459
+ clampLength(length?: number): Vector2;
460
+ /** Returns the dot product of this and the vector passed in
461
+ * @param {Vector2} vector
462
+ * @return {Number} */
463
+ dot(v: any): number;
464
+ /** Returns the cross product of this and the vector passed in
465
+ * @param {Vector2} vector
466
+ * @return {Number} */
467
+ cross(v: any): number;
468
+ /** Returns the angle of this vector, up is angle 0
469
+ * @return {Number} */
470
+ angle(): number;
471
+ /** Sets this vector with angle and length passed in
472
+ * @param {Number} [angle=0]
473
+ * @param {Number} [length=1] */
474
+ setAngle(a?: number, length?: number): Vector2;
475
+ /** Returns copy of this vector rotated by the angle passed in
476
+ * @param {Number} angle
477
+ * @return {Vector2} */
478
+ rotate(a: any): Vector2;
479
+ /** Returns the integer direction of this vector, corrosponding to multiples of 90 degree rotation (0-3)
480
+ * @return {Number} */
481
+ direction(): number;
482
+ /** Returns a copy of this vector that has been inverted
483
+ * @return {Vector2} */
484
+ invert(): Vector2;
485
+ /** Returns a copy of this vector with each axis floored
486
+ * @return {Vector2} */
487
+ floor(): Vector2;
488
+ /** Returns the area this vector covers as a rectangle
489
+ * @return {Number} */
490
+ area(): number;
491
+ /** Returns a new vector that is p percent between this and the vector passed in
492
+ * @param {Vector2} vector
493
+ * @param {Number} percent
494
+ * @return {Vector2} */
495
+ lerp(v: any, p: any): Vector2;
496
+ /** Returns true if this vector is within the bounds of an array size passed in
497
+ * @param {Vector2} arraySize
498
+ * @return {Boolean} */
499
+ arrayCheck(arraySize: Vector2): boolean;
500
+ /** Returns this vector expressed as a string
501
+ * @param {float} digits - precision to display
502
+ * @return {String} */
503
+ toString(digits?: float): string;
504
+ }
505
+ /**
506
+ * Color object (red, green, blue, alpha) with some helpful functions
507
+ * @example
508
+ * let a = new Color; // white
509
+ * let b = new Color(1, 0, 0); // red
510
+ * let c = new Color(0, 0, 0, 0); // transparent black
1208
511
  */
1209
- constructor(zzfxSound: any[], range?: number, taper?: number);
1210
- /** @property {Number} - World space max range of sound, will not play if camera is farther away */
1211
- range: number;
1212
- /** @property {Number} - At what percentage of range should it start tapering off */
1213
- taper: number;
1214
- randomness: any;
1215
- cachedSamples: number[];
1216
- /** Play the sound
1217
- * @param {Vector2} [pos] - World space position to play the sound, sound is not attenuated if null
1218
- * @param {Number} [volume=1] - How much to scale volume by (in addition to range fade)
1219
- * @param {Number} [pitch=1] - How much to scale pitch by (also adjusted by this.randomness)
1220
- * @param {Number} [randomnessScale=1] - How much to scale randomness
1221
- * @return {AudioBufferSourceNode} - The audio, can be used to stop sound later
512
+ export class Color {
513
+ /** Create a color with the components passed in, white by default
514
+ * @param {Number} [red=1]
515
+ * @param {Number} [green=1]
516
+ * @param {Number} [blue=1]
517
+ * @param {Number} [alpha=1] */
518
+ constructor(r?: number, g?: number, b?: number, a?: number);
519
+ /** @property {Number} - Red */
520
+ r: number;
521
+ /** @property {Number} - Green */
522
+ g: number;
523
+ /** @property {Number} - Blue */
524
+ b: number;
525
+ /** @property {Number} - Alpha */
526
+ a: number;
527
+ /** Returns a new color that is a copy of this
528
+ * @return {Color} */
529
+ copy(): Color;
530
+ /** Returns a copy of this color plus the color passed in
531
+ * @param {Color} color
532
+ * @return {Color} */
533
+ add(c: any): Color;
534
+ /** Returns a copy of this color minus the color passed in
535
+ * @param {Color} color
536
+ * @return {Color} */
537
+ subtract(c: any): Color;
538
+ /** Returns a copy of this color times the color passed in
539
+ * @param {Color} color
540
+ * @return {Color} */
541
+ multiply(c: any): Color;
542
+ /** Returns a copy of this color divided by the color passed in
543
+ * @param {Color} color
544
+ * @return {Color} */
545
+ divide(c: any): Color;
546
+ /** Returns a copy of this color scaled by the value passed in, alpha can be scaled separately
547
+ * @param {Number} scale
548
+ * @param {Number} [alphaScale=scale]
549
+ * @return {Color} */
550
+ scale(s: any, a?: any): Color;
551
+ /** Returns a copy of this color clamped to the valid range between 0 and 1
552
+ * @return {Color} */
553
+ clamp(): Color;
554
+ /** Returns a new color that is p percent between this and the color passed in
555
+ * @param {Color} color
556
+ * @param {Number} percent
557
+ * @return {Color} */
558
+ lerp(c: any, p: any): Color;
559
+ /** Sets this color given a hue, saturation, lightness, and alpha
560
+ * @param {Number} [hue=0]
561
+ * @param {Number} [saturation=0]
562
+ * @param {Number} [lightness=1]
563
+ * @param {Number} [alpha=1]
564
+ * @return {Color} */
565
+ setHSLA(h?: number, s?: number, l?: number, a?: number): Color;
566
+ /** Returns this color expressed in hsla format
567
+ * @return {Array} */
568
+ getHSLA(): any[];
569
+ /** Returns a new color that has each component randomly adjusted
570
+ * @param {Number} [amount=.05]
571
+ * @param {Number} [alphaAmount=0]
572
+ * @return {Color} */
573
+ mutate(amount?: number, alphaAmount?: number): Color;
574
+ /** Returns this color expressed as a hex color code
575
+ * @param {Boolean} [useAlpha=1] - if alpha should be included in result
576
+ * @return {String} */
577
+ toString(useAlpha?: boolean): string;
578
+ /** Set this color from a hex code
579
+ * @param {String} hex - html hex code
580
+ * @return {Color} */
581
+ setHex(hex: string): Color;
582
+ /** Returns this color expressed as 32 bit RGBA value
583
+ * @return {Number} */
584
+ rgbaInt(): number;
585
+ }
586
+ /**
587
+ * Timer object tracks how long has passed since it was set
588
+ * @example
589
+ * let a = new Timer; // creates a timer that is not set
590
+ * a.set(3); // sets the timer to 3 seconds
591
+ *
592
+ * let b = new Timer(1); // creates a timer with 1 second left
593
+ * b.unset(); // unsets the timer
1222
594
  */
1223
- play(pos?: Vector2, volume?: number, pitch?: number, randomnessScale?: number): AudioBufferSourceNode;
1224
- /** Play the sound as a note with a semitone offset
1225
- * @param {Number} semitoneOffset - How many semitones to offset pitch
1226
- * @param {Vector2} [pos] - World space position to play the sound, sound is not attenuated if null
1227
- * @param {Number} [volume=1] - How much to scale volume by (in addition to range fade)
1228
- * @return {AudioBufferSourceNode} - The audio, can be used to stop sound later
595
+ export class Timer {
596
+ /** Create a timer object set time passed in
597
+ * @param {Number} [timeLeft] - How much time left before the timer elapses in seconds */
598
+ constructor(timeLeft?: number);
599
+ time: number;
600
+ setTime: number;
601
+ /** Set the timer with seconds passed in
602
+ * @param {Number} [timeLeft=0] - How much time left before the timer is elapsed in seconds */
603
+ set(timeLeft?: number): void;
604
+ /** Unset the timer */
605
+ unset(): void;
606
+ /** Returns true if set
607
+ * @return {Boolean} */
608
+ isSet(): boolean;
609
+ /** Returns true if set and has not elapsed
610
+ * @return {Boolean} */
611
+ active(): boolean;
612
+ /** Returns true if set and elapsed
613
+ * @return {Boolean} */
614
+ elapsed(): boolean;
615
+ /** Get how long since elapsed, returns 0 if not set (returns negative if currently active)
616
+ * @return {Number} */
617
+ get(): number;
618
+ /** Get percentage elapsed based on time it was set to, returns 0 if not set
619
+ * @return {Number} */
620
+ getPercent(): number;
621
+ /** Returns this timer expressed as a string
622
+ * @return {String} */
623
+ toString(): string;
624
+ /** Get how long since elapsed, returns 0 if not set (returns negative if currently active)
625
+ * @return {Number} */
626
+ valueOf(): number;
627
+ }
628
+ /**
629
+ * Create a 2d vector, can take another Vector2 to copy, 2 scalars, or 1 scalar
630
+ * @param {Number} [x=0]
631
+ * @param {Number} [y=0]
632
+ * @return {Vector2}
633
+ * @example
634
+ * let a = vec2(0, 1); // vector with coordinates (0, 1)
635
+ * let b = vec2(a); // copy a into b
636
+ * a = vec2(5); // set a to (5, 5)
637
+ * b = vec2(); // set b to (0, 0)
638
+ * @memberof Utilities
1229
639
  */
1230
- playNote(semitoneOffset: number, pos?: Vector2, volume?: number): AudioBufferSourceNode;
1231
- }
1232
- /**
1233
- * Music Object - Stores a zzfx music track for later use
1234
- * <br>
1235
- * <br><b><a href=https://keithclark.github.io/ZzFXM/>Create music with the ZzFXM tracker.</a></b>
1236
- * @example
1237
- * // create some music
1238
- * const music_example = new Music(
1239
- * [
1240
- * [ // instruments
1241
- * [,0,400] // simple note
1242
- * ],
1243
- * [ // patterns
1244
- * [ // pattern 1
1245
- * [ // channel 0
1246
- * 0, -1, // instrument 0, left speaker
1247
- * 1, 0, 9, 1 // channel notes
1248
- * ],
1249
- * [ // channel 1
1250
- * 0, 1, // instrument 1, right speaker
1251
- * 0, 12, 17, -1 // channel notes
1252
- * ]
1253
- * ],
1254
- * ],
1255
- * [0, 0, 0, 0], // sequence, play pattern 0 four times
1256
- * 90 // BPM
1257
- * ]);
1258
- *
1259
- * // play the music
1260
- * music_example.play();
1261
- */
1262
- declare class Music {
1263
- /** Create a music object and cache the zzfx music samples for later use
1264
- * @param {Array} zzfxMusic - Array of zzfx music parameters
640
+ export function vec2(x?: number, y?: number): Vector2;
641
+ /**
642
+ * Create a color object with RGBA values
643
+ * @param {Number} [r=1]
644
+ * @param {Number} [g=1]
645
+ * @param {Number} [b=1]
646
+ * @param {Number} [a=1]
647
+ * @return {Color}
648
+ * @memberof Utilities
1265
649
  */
1266
- constructor(zzfxMusic: any[]);
1267
- cachedSamples: any[];
1268
- /** Play the music
1269
- * @param {Number} [volume=1] - How much to scale volume by
1270
- * @param {Boolean} [loop=1] - True if the music should loop when it reaches the end
1271
- * @return {AudioBufferSourceNode} - The audio node, can be used to stop sound later
650
+ export function colorRGBA(r?: number, g?: number, b?: number, a?: number): Color;
651
+ /**
652
+ * Create a color object with HSLA values
653
+ * @param {Number} [h=0]
654
+ * @param {Number} [s=0]
655
+ * @param {Number} [l=1]
656
+ * @param {Number} [a=1]
657
+ * @return {Color}
658
+ * @memberof Utilities
1272
659
  */
1273
- play(volume?: number, loop?: boolean): AudioBufferSourceNode;
1274
- }
1275
- /** Stop all queued speech
1276
- * @memberof Audio */
1277
- declare function speakStop(): void;
1278
- /** Get frequency of a note on a musical scale
1279
- * @param {Number} semitoneOffset - How many semitones away from the root note
1280
- * @param {Number} [rootNoteFrequency=220] - Frequency at semitone offset 0
1281
- * @return {Number} - The frequency of the note
1282
- * @memberof Audio */
1283
- declare function getNoteFrequency(semitoneOffset: number, rootFrequency?: number): number;
1284
- /** Audio context used by the engine
1285
- * @memberof Audio */
1286
- declare let audioContext: any;
1287
- /** Generate and play a ZzFX sound
1288
- * <br>
1289
- * <br><b><a href=https://killedbyapixel.github.io/ZzFX/>Create sounds using the ZzFX Sound Designer.</a></b>
1290
- * @param {Array} zzfxSound - Array of ZzFX parameters, ex. [.5,.5]
1291
- * @return {Array} - Array of audio samples
1292
- * @memberof Audio */
1293
- declare function zzfx(...zzfxSound: any[]): any[];
1294
- /** Sample rate used for all ZzFX sounds
1295
- * @default 44100
1296
- * @memberof Audio */
1297
- declare const zzfxR: 44100;
1298
- /** The tile collision layer array, use setTileCollisionData and getTileCollisionData to access
1299
- * @memberof TileCollision */
1300
- declare let tileCollision: any[];
1301
- /** Size of the tile collision layer
1302
- * @type {Vector2}
1303
- * @memberof TileCollision */
1304
- declare let tileCollisionSize: Vector2;
1305
- /** Set tile collision data
1306
- * @param {Vector2} pos
1307
- * @param {Number} [data=0]
1308
- * @memberof TileCollision */
1309
- declare function setTileCollisionData(pos: Vector2, data?: number): number;
1310
- /** Get tile collision data
1311
- * @param {Vector2} pos
1312
- * @return {Number}
1313
- * @memberof TileCollision */
1314
- declare function getTileCollisionData(pos: Vector2): number;
1315
- /**
1316
- * Tile layer data object stores info about how to render a tile
1317
- * @example
1318
- * // create tile layer data with tile index 0 and random orientation and color
1319
- * const tileIndex = 0;
1320
- * const direction = randInt(4)
1321
- * const mirror = randInt(2);
1322
- * const color = randColor();
1323
- * const data = new TileLayerData(tileIndex, direction, mirror, color);
1324
- */
1325
- declare class TileLayerData {
1326
- /** Create a tile layer data object, one for each tile in a TileLayer
1327
- * @param {Number} [tile] - The tile to use, untextured if undefined
1328
- * @param {Number} [direction=0] - Integer direction of tile, in 90 degree increments
1329
- * @param {Boolean} [mirror=0] - If the tile should be mirrored along the x axis
1330
- * @param {Color} [color=new Color(1,1,1)] - Color of the tile */
1331
- constructor(tile?: number, direction?: number, mirror?: boolean, color?: Color);
1332
- /** @property {Number} - The tile to use, untextured if undefined */
1333
- tile: number;
1334
- /** @property {Number} - Integer direction of tile, in 90 degree increments */
1335
- direction: number;
1336
- /** @property {Boolean} - If the tile should be mirrored along the x axis */
1337
- mirror: boolean;
1338
- /** @property {Color} - Color of the tile */
1339
- color: Color;
1340
- /** Set this tile to clear, it will not be rendered */
1341
- clear(): void;
1342
- }
1343
- /**
1344
- * Tile layer object - cached rendering system for tile layers
1345
- * <br> - Each Tile layer is rendered to an off screen canvas
1346
- * <br> - To allow dynamic modifications, layers are rendered using canvas 2d
1347
- * <br> - Some devices like mobile phones are limited to 4k texture resolution
1348
- * <br> - So with 16x16 tiles this limits layers to 256x256 on mobile devices
1349
- * @extends EngineObject
1350
- * @example
1351
- * // create tile collision and visible tile layer
1352
- * initTileCollision(vec2(200,100));
1353
- * const tileLayer = new TileLayer();
1354
- */
1355
- declare class TileLayer extends EngineObject {
1356
- /** Create a tile layer object
1357
- * @param {Vector2} [position=new Vector2()] - World space position
1358
- * @param {Vector2} [size=tileCollisionSize] - World space size
1359
- * @param {Vector2} [tileSize=tileSizeDefault] - Size of tiles in source pixels
1360
- * @param {Vector2} [scale=new Vector2(1,1)] - How much to scale this layer when rendered
1361
- * @param {Number} [renderOrder=0] - Objects sorted by renderOrder before being rendered
1362
- */
1363
- constructor(pos: any, size?: Vector2, tileSize?: Vector2, scale?: Vector2, renderOrder?: number);
1364
- /** @property {HTMLCanvasElement} - The canvas used by this tile layer */
1365
- canvas: HTMLCanvasElement;
1366
- /** @property {CanvasRenderingContext2D} - The 2D canvas context used by this tile layer */
1367
- context: CanvasRenderingContext2D;
1368
- /** @property {Vector2} - How much to scale this layer when rendered */
1369
- scale: Vector2;
1370
- data: TileLayerData[];
1371
- /** Set data at a given position in the array
1372
- * @param {Vector2} position - Local position in array
1373
- * @param {TileLayerData} data - Data to set
1374
- * @param {Boolean} [redraw=0] - Force the tile to redraw if true */
1375
- setData(layerPos: any, data: TileLayerData, redraw?: boolean): void;
1376
- /** Get data at a given position in the array
1377
- * @param {Vector2} layerPos - Local position in array
1378
- * @return {TileLayerData} */
1379
- getData(layerPos: Vector2): TileLayerData;
1380
- /** Draw all the tile data to an offscreen canvas
1381
- * - This may be slow in some browsers
1382
- */
1383
- redraw(): void;
1384
- /** Call to start the redraw process
1385
- * @param {Boolean} [clear=0] - Should it clear the canvas before drawing */
1386
- redrawStart(clear?: boolean): void;
1387
- savedRenderSettings: (number | HTMLCanvasElement | CanvasRenderingContext2D | Vector2)[];
1388
- /** Call to end the redraw process */
1389
- redrawEnd(): void;
1390
- /** Draw the tile at a given position
1391
- * @param {Vector2} layerPos */
1392
- drawTileData(layerPos: Vector2): void;
1393
- /** Draw all the tiles in this layer */
1394
- drawAllTileData(): void;
1395
- /** Draw directly to the 2D canvas in world space (bipass webgl)
1396
- * @param {Vector2} pos
1397
- * @param {Vector2} size
1398
- * @param {Number} [angle=0]
1399
- * @param {Boolean} [mirror=0]
1400
- * @param {Function} drawFunction */
1401
- drawCanvas2D(pos: Vector2, size: Vector2, angle?: number, mirror?: boolean, drawFunction: Function): void;
1402
- /** Draw a tile directly onto the layer canvas
660
+ export function colorHSLA(h?: number, s?: number, l?: number, a?: number): Color;
661
+ /**
662
+ * LittleJS Object Base Object Class
663
+ * <br> - Base object class used by the engine
664
+ * <br> - Automatically adds self to object list
665
+ * <br> - Will be updated and rendered each frame
666
+ * <br> - Renders as a sprite from a tilesheet by default
667
+ * <br> - Can have color and addtive color applied
668
+ * <br> - 2d Physics and collision system
669
+ * <br> - Sorted by renderOrder
670
+ * <br> - Objects can have children attached
671
+ * <br> - Parents are updated before children, and set child transform
672
+ * <br> - Call destroy() to get rid of objects
673
+ * <br>
674
+ * <br>The physics system used by objects is simple and fast with some caveats...
675
+ * <br> - Collision uses the axis aligned size, the object's rotation angle is only for rendering
676
+ * <br> - Objects are guaranteed to not intersect tile collision from physics
677
+ * <br> - If an object starts or is moved inside tile collision, it will not collide with that tile
678
+ * <br> - Collision for objects can be set to be solid to block other objects
679
+ * <br> - Objects may get pushed into overlapping other solid objects, if so they will push away
680
+ * <br> - Solid objects are more performance intensive and should be used sparingly
681
+ * @example
682
+ * // create an engine object, normally you would first extend the class with your own
683
+ * const pos = vec2(2,3);
684
+ * const object = new EngineObject(pos);
685
+ */
686
+ export class EngineObject {
687
+ /** Create an engine object and adds it to the list of objects
688
+ * @param {Vector2} [position=new Vector2()] - World space position of the object
689
+ * @param {Vector2} [size=objectDefaultSize] - World space size of the object
690
+ * @param {Number} [tileIndex=-1] - Tile to use to render object (-1 is untextured)
691
+ * @param {Vector2} [tileSize=tileSizeDefault] - Size of tile in source pixels
692
+ * @param {Number} [angle=0] - Angle the object is rotated by
693
+ * @param {Color} [color] - Color to apply to tile when rendered
694
+ * @param {Number} [renderOrder=0] - Objects sorted by renderOrder before being rendered
695
+ */
696
+ constructor(pos?: Vector2, size?: Vector2, tileIndex?: number, tileSize?: Vector2, angle?: number, color?: Color, renderOrder?: number);
697
+ /** @property {Vector2} - World space position of the object */
698
+ pos: Vector2;
699
+ /** @property {Vector2} - World space width and height of the object */
700
+ size: Vector2;
701
+ /** @property {Number} - Tile to use to render object (-1 is untextured) */
702
+ tileIndex: number;
703
+ /** @property {Vector2} - Size of tile in source pixels */
704
+ tileSize: Vector2;
705
+ /** @property {Number} - Angle to rotate the object */
706
+ angle: number;
707
+ /** @property {Color} - Color to apply when rendered */
708
+ color: Color;
709
+ /** @property {Number} [mass=objectDefaultMass] - How heavy the object is, static if 0 */
710
+ mass: number;
711
+ /** @property {Number} [damping=objectDefaultDamping] - How much to slow down velocity each frame (0-1) */
712
+ damping: number;
713
+ /** @property {Number} [angleDamping=objectDefaultAngleDamping] - How much to slow down rotation each frame (0-1) */
714
+ angleDamping: number;
715
+ /** @property {Number} [elasticity=objectDefaultElasticity] - How bouncy the object is when colliding (0-1) */
716
+ elasticity: number;
717
+ /** @property {Number} [friction=objectDefaultFriction] - How much friction to apply when sliding (0-1) */
718
+ friction: number;
719
+ /** @property {Number} [gravityScale=1] - How much to scale gravity by for this object */
720
+ gravityScale: number;
721
+ /** @property {Number} [renderOrder=0] - Objects are sorted by render order */
722
+ renderOrder: number;
723
+ /** @property {Vector2} [velocity=new Vector2()] - Velocity of the object */
724
+ velocity: Vector2;
725
+ /** @property {Number} [angleVelocity=0] - Angular velocity of the object */
726
+ angleVelocity: number;
727
+ spawnTime: number;
728
+ children: any[];
729
+ collideTiles: number;
730
+ /** Update the object transform and physics, called automatically by engine once each frame */
731
+ update(): void;
732
+ groundObject: any;
733
+ /** Render the object, draws a tile by default, automatically called each frame, sorted by renderOrder */
734
+ render(): void;
735
+ /** Destroy this object, destroy it's children, detach it's parent, and mark it for removal */
736
+ destroy(): void;
737
+ destroyed: number;
738
+ /** Called to check if a tile collision should be resolved
739
+ * @param {Number} tileData - the value of the tile at the position
740
+ * @param {Vector2} pos - tile where the collision occured
741
+ * @return {Boolean} - true if the collision should be resolved */
742
+ collideWithTile(tileData: number, pos: Vector2): boolean;
743
+ /** Called to check if a tile raycast hit
744
+ * @param {Number} tileData - the value of the tile at the position
745
+ * @param {Vector2} pos - tile where the raycast is
746
+ * @return {Boolean} - true if the raycast should hit */
747
+ collideWithTileRaycast(tileData: number, pos: Vector2): boolean;
748
+ /** Called to check if a object collision should be resolved
749
+ * @param {EngineObject} object - the object to test against
750
+ * @return {Boolean} - true if the collision should be resolved
751
+ */
752
+ collideWithObject(o: any): boolean;
753
+ /** How long since the object was created
754
+ * @return {Number} */
755
+ getAliveTime(): number;
756
+ /** Apply acceleration to this object (adjust velocity, not affected by mass)
757
+ * @param {Vector2} acceleration */
758
+ applyAcceleration(a: any): void;
759
+ /** Apply force to this object (adjust velocity, affected by mass)
760
+ * @param {Vector2} force */
761
+ applyForce(force: Vector2): void;
762
+ /** Get the direction of the mirror
763
+ * @return {Number} -1 if this.mirror is true, or 1 if not mirrored */
764
+ getMirrorSign(): number;
765
+ /** Attaches a child to this with a given local transform
766
+ * @param {EngineObject} child
767
+ * @param {Vector2} [localPos=new Vector2]
768
+ * @param {Number} [localAngle=0] */
769
+ addChild(child: EngineObject, localPos?: Vector2, localAngle?: number): void;
770
+ /** Removes a child from this one
771
+ * @param {EngineObject} child */
772
+ removeChild(child: EngineObject): void;
773
+ /** Set how this object collides
774
+ * @param {Boolean} [collideSolidObjects=1] - Does it collide with solid objects
775
+ * @param {Boolean} [isSolid=1] - Does it collide with and block other objects (expensive in large numbers)
776
+ * @param {Boolean} [collideTiles=1] - Does it collide with the tile collision */
777
+ setCollision(collideSolidObjects?: boolean, isSolid?: boolean, collideTiles?: boolean): void;
778
+ collideSolidObjects: boolean;
779
+ isSolid: boolean;
780
+ /** Returns string containg info about this object for debugging
781
+ * @return {String} */
782
+ toString(): string;
783
+ }
784
+ /** Tile sheet for batch rendering system
785
+ * @type {CanvasImageSource}
786
+ * @memberof Draw */
787
+ export const tileImage: CanvasImageSource;
788
+ /** The primary 2D canvas visible to the user
789
+ * @type {HTMLCanvasElement}
790
+ * @memberof Draw */
791
+ export let mainCanvas: HTMLCanvasElement;
792
+ /** 2d context for mainCanvas
793
+ * @type {CanvasRenderingContext2D}
794
+ * @memberof Draw */
795
+ export let mainContext: CanvasRenderingContext2D;
796
+ /** A canvas that appears on top of everything the same size as mainCanvas
797
+ * @type {HTMLCanvasElement}
798
+ * @memberof Draw */
799
+ export let overlayCanvas: HTMLCanvasElement;
800
+ /** 2d context for overlayCanvas
801
+ * @type {CanvasRenderingContext2D}
802
+ * @memberof Draw */
803
+ export let overlayContext: CanvasRenderingContext2D;
804
+ /** The size of the main canvas (and other secondary canvases)
805
+ * @type {Vector2}
806
+ * @memberof Draw */
807
+ export let mainCanvasSize: Vector2;
808
+ /** Convert from screen to world space coordinates
809
+ * - if calling outside of render, you may need to manually set mainCanvasSize
810
+ * @param {Vector2} screenPos
811
+ * @return {Vector2}
812
+ * @memberof Draw */
813
+ export function screenToWorld(screenPos: Vector2): Vector2;
814
+ /** Convert from world to screen space coordinates
815
+ * - if calling outside of render, you may need to manually set mainCanvasSize
816
+ * @param {Vector2} worldPos
817
+ * @return {Vector2}
818
+ * @memberof Draw */
819
+ export function worldToScreen(worldPos: Vector2): Vector2;
820
+ /** Draw textured tile centered in world space, with color applied if using WebGL
821
+ * @param {Vector2} pos - Center of the tile in world space
822
+ * @param {Vector2} [size=new Vector2(1,1)] - Size of the tile in world space
823
+ * @param {Number} [tileIndex=-1] - Tile index to use, negative is untextured
824
+ * @param {Vector2} [tileSize=tileSizeDefault] - Tile size in source pixels
825
+ * @param {Color} [color=new Color(1,1,1)] - Color to modulate with
826
+ * @param {Number} [angle=0] - Angle to rotate by
827
+ * @param {Boolean} [mirror=0] - If true image is flipped along the Y axis
828
+ * @param {Color} [additiveColor=new Color(0,0,0,0)] - Additive color to be applied
829
+ * @param {Boolean} [useWebGL=glEnable] - Use accelerated WebGL rendering
830
+ * @memberof Draw */
831
+ export function drawTile(pos: Vector2, size?: Vector2, tileIndex?: number, tileSize?: Vector2, color?: Color, angle?: number, mirror?: boolean, additiveColor?: Color, useWebGL?: boolean): void;
832
+ /** Draw colored rect centered on pos
1403
833
  * @param {Vector2} pos
1404
834
  * @param {Vector2} [size=new Vector2(1,1)]
1405
- * @param {Number} [tileIndex=-1]
1406
- * @param {Vector2} [tileSize=tileSizeDefault]
1407
835
  * @param {Color} [color=new Color(1,1,1)]
1408
836
  * @param {Number} [angle=0]
1409
- * @param {Boolean} [mirror=0] */
1410
- drawTile(pos: Vector2, size?: Vector2, tileIndex?: number, tileSize?: Vector2, color?: Color, angle?: number, mirror?: boolean): void;
1411
- /** Draw a rectangle directly onto the layer canvas
837
+ * @param {Boolean} [useWebGL=glEnable]
838
+ * @memberof Draw */
839
+ export function drawRect(pos: Vector2, size?: Vector2, color?: Color, angle?: number, useWebGL?: boolean): void;
840
+ /** Draw textured tile centered on pos in screen space
841
+ * @param {Vector2} pos - Center of the tile
842
+ * @param {Vector2} [size=new Vector2(1,1)] - Size of the tile
843
+ * @param {Number} [tileIndex=-1] - Tile index to use, negative is untextured
844
+ * @param {Vector2} [tileSize=tileSizeDefault] - Tile size in source pixels
845
+ * @param {Color} [color=new Color]
846
+ * @param {Number} [angle=0]
847
+ * @param {Boolean} [mirror=0]
848
+ * @param {Color} [additiveColor=new Color(0,0,0,0)]
849
+ * @param {Boolean} [useWebGL=glEnable]
850
+ * @memberof Draw */
851
+ export function drawTileScreenSpace(pos: Vector2, size?: Vector2, tileIndex?: number, tileSize?: Vector2, color?: Color, angle?: number, mirror?: boolean, additiveColor?: Color, useWebGL?: boolean): void;
852
+ /** Draw colored rectangle in screen space
1412
853
  * @param {Vector2} pos
1413
854
  * @param {Vector2} [size=new Vector2(1,1)]
1414
855
  * @param {Color} [color=new Color(1,1,1)]
1415
- * @param {Number} [angle=0] */
1416
- drawRect(pos: Vector2, size?: Vector2, color?: Color, angle?: number): void;
1417
- }
1418
- /**
1419
- * Particle Emitter - Spawns particles with the given settings
1420
- * @extends EngineObject
1421
- * @example
1422
- * // create a particle emitter
1423
- * let pos = vec2(2,3);
1424
- * let particleEmiter = new ParticleEmitter
1425
- * (
1426
- * pos, 0, 1, 0, 500, PI, // pos, angle, emitSize, emitTime, emitRate, emiteCone
1427
- * 0, vec2(16), // tileIndex, tileSize
1428
- * new Color(1,1,1), new Color(0,0,0), // colorStartA, colorStartB
1429
- * new Color(1,1,1,0), new Color(0,0,0,0), // colorEndA, colorEndB
1430
- * 2, .2, .2, .1, .05, // particleTime, sizeStart, sizeEnd, particleSpeed, particleAngleSpeed
1431
- * .99, 1, 1, PI, .05, // damping, angleDamping, gravityScale, particleCone, fadeRate,
1432
- * .5, 1 // randomness, collide, additive, randomColorLinear, renderOrder
1433
- * );
1434
- */
1435
- declare class ParticleEmitter extends EngineObject {
1436
- /** Create a particle system with the given settings
1437
- * @param {Vector2} position - World space position of the emitter
1438
- * @param {Number} [angle=0] - Angle to emit the particles
1439
- * @param {Number} [emitSize=0] - World space size of the emitter (float for circle diameter, vec2 for rect)
1440
- * @param {Number} [emitTime=0] - How long to stay alive (0 is forever)
1441
- * @param {Number} [emitRate=100] - How many particles per second to spawn, does not emit if 0
1442
- * @param {Number} [emitConeAngle=PI] - Local angle to apply velocity to particles from emitter
1443
- * @param {Number} [tileIndex=-1] - Index into tile sheet, if <0 no texture is applied
1444
- * @param {Number} [tileSize=tileSizeDefault] - Tile size for particles
1445
- * @param {Color} [colorStartA=new Color(1,1,1)] - Color at start of life 1, randomized between start colors
1446
- * @param {Color} [colorStartB=new Color(1,1,1)] - Color at start of life 2, randomized between start colors
1447
- * @param {Color} [colorEndA=new Color(1,1,1,0)] - Color at end of life 1, randomized between end colors
1448
- * @param {Color} [colorEndB=new Color(1,1,1,0)] - Color at end of life 2, randomized between end colors
1449
- * @param {Number} [particleTime=.5] - How long particles live
1450
- * @param {Number} [sizeStart=.1] - How big are particles at start
1451
- * @param {Number} [sizeEnd=1] - How big are particles at end
1452
- * @param {Number} [speed=.1] - How fast are particles when spawned
1453
- * @param {Number} [angleSpeed=.05] - How fast are particles rotating
1454
- * @param {Number} [damping=1] - How much to dampen particle speed
1455
- * @param {Number} [angleDamping=1] - How much to dampen particle angular speed
1456
- * @param {Number} [gravityScale=0] - How much does gravity effect particles
1457
- * @param {Number} [particleConeAngle=PI] - Cone for start particle angle
1458
- * @param {Number} [fadeRate=.1] - How quick to fade in particles at start/end in percent of life
1459
- * @param {Number} [randomness=.2] - Apply extra randomness percent
1460
- * @param {Boolean} [collideTiles=0] - Do particles collide against tiles
1461
- * @param {Boolean} [additive=0] - Should particles use addtive blend
1462
- * @param {Boolean} [randomColorLinear=1] - Should color be randomized linearly or across each component
1463
- * @param {Number} [renderOrder=0] - Render order for particles (additive is above other stuff by default)
1464
- * @param {Boolean} [localSpace=0] - Should it be in local space of emitter (world space is default)
856
+ * @param {Number} [angle=0]
857
+ * @param {Boolean} [useWebGL=glEnable]
858
+ * @memberof Draw */
859
+ export function drawRectScreenSpace(pos: Vector2, size?: Vector2, color?: Color, angle?: number, useWebGL?: boolean): void;
860
+ /** Draw colored line between two points
861
+ * @param {Vector2} posA
862
+ * @param {Vector2} posB
863
+ * @param {Number} [thickness=.1]
864
+ * @param {Color} [color=new Color(1,1,1)]
865
+ * @param {Boolean} [useWebGL=glEnable]
866
+ * @memberof Draw */
867
+ export function drawLine(posA: Vector2, posB: Vector2, thickness?: number, color?: Color, useWebGL?: boolean): void;
868
+ /** Draw directly to a 2d canvas context in world space
869
+ * @param {Vector2} pos
870
+ * @param {Vector2} size
871
+ * @param {Number} angle
872
+ * @param {Boolean} mirror
873
+ * @param {Function} drawFunction
874
+ * @param {CanvasRenderingContext2D} [context=mainContext]
875
+ * @memberof Draw */
876
+ export function drawCanvas2D(pos: Vector2, size: Vector2, angle: number, mirror: boolean, drawFunction: Function, context?: CanvasRenderingContext2D): void;
877
+ /** Enable normal or additive blend mode
878
+ * @param {Boolean} [additive=0]
879
+ * @param {Boolean} [useWebGL=glEnable]
880
+ * @memberof Draw */
881
+ export function setBlendMode(additive?: boolean, useWebGL?: boolean): void;
882
+ /** Draw text on overlay canvas in screen space
883
+ * Automatically splits new lines into rows
884
+ * @param {String} text
885
+ * @param {Vector2} pos
886
+ * @param {Number} [size=1]
887
+ * @param {Color} [color=new Color(1,1,1)]
888
+ * @param {Number} [lineWidth=0]
889
+ * @param {Color} [lineColor=new Color(0,0,0)]
890
+ * @param {String} [textAlign='center']
891
+ * @memberof Draw */
892
+ export function drawTextScreen(text: string, pos: Vector2, size?: number, color?: Color, lineWidth?: number, lineColor?: Color, textAlign?: string, font?: string, context?: CanvasRenderingContext2D): void;
893
+ /** Draw text on overlay canvas in world space
894
+ * Automatically splits new lines into rows
895
+ * @param {String} text
896
+ * @param {Vector2} pos
897
+ * @param {Number} [size=1]
898
+ * @param {Color} [color=new Color(1,1,1)]
899
+ * @param {Number} [lineWidth=0]
900
+ * @param {Color} [lineColor=new Color(0,0,0)]
901
+ * @param {String} [textAlign='center']
902
+ * @memberof Draw */
903
+ export function drawText(text: string, pos: Vector2, size?: number, color?: Color, lineWidth?: number, lineColor?: Color, textAlign?: string, font: any): void;
904
+ /**
905
+ * Font Image Object - Draw text on a 2D canvas by using characters in an image
906
+ * <br> - 96 characters (from space to tilde) are stored in an image
907
+ * <br> - Uses a default 8x8 font if none is supplied
908
+ * <br> - You can also use fonts from the main tile sheet
909
+ * @example
910
+ * // use built in font
911
+ * const font = new ImageFont;
912
+ *
913
+ * // draw text
914
+ * font.drawTextScreen("LittleJS\nHello World!", vec2(200, 50));
1465
915
  */
1466
- constructor(pos: any, angle?: number, emitSize?: number, emitTime?: number, emitRate?: number, emitConeAngle?: number, tileIndex?: number, tileSize?: number, colorStartA?: Color, colorStartB?: Color, colorEndA?: Color, colorEndB?: Color, particleTime?: number, sizeStart?: number, sizeEnd?: number, speed?: number, angleSpeed?: number, damping?: number, angleDamping?: number, gravityScale?: number, particleConeAngle?: number, fadeRate?: number, randomness?: number, collideTiles?: boolean, additive?: boolean, randomColorLinear?: boolean, renderOrder?: number, localSpace?: boolean);
1467
- /** @property {Number} - World space size of the emitter (float for circle diameter, vec2 for rect) */
1468
- emitSize: number;
1469
- /** @property {Number} - How long to stay alive (0 is forever) */
1470
- emitTime: number;
1471
- /** @property {Number} - How many particles per second to spawn, does not emit if 0 */
1472
- emitRate: number;
1473
- /** @property {Number} - Local angle to apply velocity to particles from emitter */
1474
- emitConeAngle: number;
1475
- /** @property {Color} - Color at start of life 1, randomized between start colors */
1476
- colorStartA: Color;
1477
- /** @property {Color} - Color at start of life 2, randomized between start colors */
1478
- colorStartB: Color;
1479
- /** @property {Color} - Color at end of life 1, randomized between end colors */
1480
- colorEndA: Color;
1481
- /** @property {Color} - Color at end of life 2, randomized between end colors */
1482
- colorEndB: Color;
1483
- /** @property {Boolean} - Should color be randomized linearly or across each component */
1484
- randomColorLinear: boolean;
1485
- /** @property {Number} - How long particles live */
1486
- particleTime: number;
1487
- /** @property {Number} - How big are particles at start */
1488
- sizeStart: number;
1489
- /** @property {Number} - How big are particles at end */
1490
- sizeEnd: number;
1491
- /** @property {Number} - How fast are particles when spawned */
1492
- speed: number;
1493
- /** @property {Number} - How fast are particles rotating */
1494
- angleSpeed: number;
1495
- /** @property {Number} - Cone for start particle angle */
1496
- particleConeAngle: number;
1497
- /** @property {Number} - How quick to fade in particles at start/end in percent of life */
1498
- fadeRate: number;
1499
- /** @property {Number} - Apply extra randomness percent */
1500
- randomness: number;
1501
- /** @property {Number} - Do particles collide against tiles */
1502
- collideTiles: boolean;
1503
- /** @property {Number} - Should particles use addtive blend */
1504
- additive: boolean;
1505
- /** @property {Boolean} - Should it be in local space of emitter */
1506
- localSpace: boolean;
1507
- /** @property {Number} - If set the partile is drawn as a trail, stretched in the drection of velocity */
1508
- trailScale: number;
1509
- emitTimeBuffer: number;
1510
- /** Spawn one particle
1511
- * @return {Particle} */
1512
- emitParticle(): Particle;
1513
- }
1514
- /**
1515
- * Particle Object - Created automatically by Particle Emitters
1516
- * @extends EngineObject
1517
- */
1518
- declare class Particle extends EngineObject {
916
+ export let engineFontImage: any;
917
+ export class FontImage {
918
+ /** Create an image font
919
+ * @param {HTMLImageElement} [image] - Image for the font, if undefined default font is used
920
+ * @param {Vector2} [tileSize=vec2(8)] - Size of the font source tiles
921
+ * @param {Vector2} [paddingSize=vec2(0,1)] - How much extra space to add between characters
922
+ * @param {Number} [startTileIndex=0] - Tile index in image where font starts
923
+ * @param {CanvasRenderingContext2D} [context=overlayContext] - context to draw to
924
+ */
925
+ constructor(image?: HTMLImageElement, tileSize?: Vector2, paddingSize?: Vector2, startTileIndex?: number, context?: CanvasRenderingContext2D);
926
+ image: any;
927
+ tileSize: Vector2;
928
+ paddingSize: Vector2;
929
+ startTileIndex: number;
930
+ context: CanvasRenderingContext2D;
931
+ /** Draw text in screen space using the image font
932
+ * @param {String} text
933
+ * @param {Vector2} pos
934
+ * @param {Number} [scale=4]
935
+ * @param {Boolean} [center]
936
+ */
937
+ drawTextScreen(text: string, pos: Vector2, scale?: number, center?: boolean): void;
938
+ /** Draw text in world space using the image font
939
+ * @param {String} text
940
+ * @param {Vector2} pos
941
+ * @param {Number} [scale=.25]
942
+ * @param {Boolean} [center]
943
+ */
944
+ drawText(text: string, pos: Vector2, scale?: number, center?: boolean): void;
945
+ }
946
+ /** Returns true if fullscreen mode is active
947
+ * @return {Boolean}
948
+ * @memberof Draw */
949
+ export function isFullscreen(): boolean;
950
+ /** Toggle fullsceen mode
951
+ * @memberof Draw */
952
+ export function toggleFullscreen(): void;
953
+ /** Returns true if device key is down
954
+ * @param {Number} key
955
+ * @param {Number} [device=0]
956
+ * @return {Boolean}
957
+ * @memberof Input */
958
+ export function keyIsDown(key: number, device?: number): boolean;
959
+ /** Returns true if device key was pressed this frame
960
+ * @param {Number} key
961
+ * @param {Number} [device=0]
962
+ * @return {Boolean}
963
+ * @memberof Input */
964
+ export function keyWasPressed(key: number, device?: number): boolean;
965
+ /** Returns true if device key was released this frame
966
+ * @param {Number} key
967
+ * @param {Number} [device=0]
968
+ * @return {Boolean}
969
+ * @memberof Input */
970
+ export function keyWasReleased(key: number, device?: number): boolean;
971
+ /** Clears all input
972
+ * @memberof Input */
973
+ export function clearInput(): any[][];
974
+ /** Returns true if device key is down
975
+ * @param {Number} key
976
+ * @param {Number} [device=0]
977
+ * @return {Boolean}
978
+ * @memberof Input */
979
+ export function mouseIsDown(key: number, device?: number): boolean;
980
+ /** Returns true if device key was pressed this frame
981
+ * @param {Number} key
982
+ * @param {Number} [device=0]
983
+ * @return {Boolean}
984
+ * @memberof Input */
985
+ export function mouseWasPressed(key: number, device?: number): boolean;
986
+ /** Returns true if device key was released this frame
987
+ * @param {Number} key
988
+ * @param {Number} [device=0]
989
+ * @return {Boolean}
990
+ * @memberof Input */
991
+ export function mouseWasReleased(key: number, device?: number): boolean;
992
+ /** Mouse pos in world space
993
+ * @type {Vector2}
994
+ * @memberof Input */
995
+ export let mousePos: Vector2;
996
+ /** Mouse pos in screen space
997
+ * @type {Vector2}
998
+ * @memberof Input */
999
+ export let mousePosScreen: Vector2;
1000
+ /** Mouse wheel delta this frame
1001
+ * @memberof Input */
1002
+ export let mouseWheel: number;
1003
+ /** Returns true if user is using gamepad (has more recently pressed a gamepad button)
1004
+ * @memberof Input */
1005
+ export let isUsingGamepad: number;
1006
+ /** Prevents input continuing to the default browser handling (false by default)
1007
+ * @memberof Input */
1008
+ export let preventDefaultInput: number;
1009
+ /** Returns true if gamepad button is down
1010
+ * @param {Number} button
1011
+ * @param {Number} [gamepad=0]
1012
+ * @return {Boolean}
1013
+ * @memberof Input */
1014
+ export function gamepadIsDown(button: number, gamepad?: number): boolean;
1015
+ /** Returns true if gamepad button was pressed
1016
+ * @param {Number} button
1017
+ * @param {Number} [gamepad=0]
1018
+ * @return {Boolean}
1019
+ * @memberof Input */
1020
+ export function gamepadWasPressed(button: number, gamepad?: number): boolean;
1021
+ /** Returns true if gamepad button was released
1022
+ * @param {Number} button
1023
+ * @param {Number} [gamepad=0]
1024
+ * @return {Boolean}
1025
+ * @memberof Input */
1026
+ export function gamepadWasReleased(button: number, gamepad?: number): boolean;
1027
+ /** Returns gamepad stick value
1028
+ * @param {Number} stick
1029
+ * @param {Number} [gamepad=0]
1030
+ * @return {Vector2}
1031
+ * @memberof Input */
1032
+ export function gamepadStick(stick: number, gamepad?: number): Vector2;
1033
+ export function mouseToScreen(mousePos: any): Vector2;
1034
+ export function gamepadsUpdate(): void;
1035
+ /** Pulse the vibration hardware if it exists
1036
+ * @param {Number} [pattern=100] - a single value in miliseconds or vibration interval array
1037
+ * @memberof Input */
1038
+ export function vibrate(pattern?: number): boolean;
1039
+ /** Cancel any ongoing vibration
1040
+ * @memberof Input */
1041
+ export function vibrateStop(): boolean;
1042
+ /** True if a touch device has been detected
1043
+ * @const {Boolean}
1044
+ * @memberof Input */
1045
+ export const isTouchDevice: boolean;
1519
1046
  /**
1520
- * Create a particle with the given settings
1521
- * @param {Vector2} position - World space position of the particle
1522
- * @param {Number} [tileIndex=-1] - Tile to use to render, untextured if -1
1523
- * @param {Vector2} [tileSize=tileSizeDefault] - Size of tile in source pixels
1524
- * @param {Number} [angle=0] - Angle to rotate the particle
1047
+ * Sound Object - Stores a zzfx sound for later use and can be played positionally
1048
+ * <br>
1049
+ * <br><b><a href=https://killedbyapixel.github.io/ZzFX/>Create sounds using the ZzFX Sound Designer.</a></b>
1050
+ * @example
1051
+ * // create a sound
1052
+ * const sound_example = new Sound([.5,.5]);
1053
+ *
1054
+ * // play the sound
1055
+ * sound_example.play();
1525
1056
  */
1526
- constructor(pos: any, tileIndex?: number, tileSize?: Vector2, angle?: number);
1527
- }
1528
- /** List of all medals
1529
- * @memberof Medals */
1530
- declare const medals: any[];
1531
- declare let medalsDisplayQueue: any[];
1532
- declare let medalsSaveName: any;
1533
- declare let medalsDisplayTimeLast: any;
1534
- /**
1535
- * Medal Object - Tracks an unlockable medal
1536
- * @example
1537
- * // create a medal
1538
- * const medal_example = new Medal(0, 'Example Medal', 'More info about the medal goes here.', '🎖️');
1539
- *
1540
- * // initialize medals
1541
- * medalsInit('Example Game');
1542
- *
1543
- * // unlock the medal
1544
- * medal_example.unlock();
1545
- */
1546
- declare class Medal {
1547
- /** Create an medal object and adds it to the list of medals
1548
- * @param {Number} id - The unique identifier of the medal
1549
- * @param {String} name - Name of the medal
1550
- * @param {String} [description] - Description of the medal
1551
- * @param {String} [icon='🏆'] - Icon for the medal
1552
- * @param {String} [src] - Image location for the medal
1057
+ export class Sound {
1058
+ /** Create a sound object and cache the zzfx samples for later use
1059
+ * @param {Array} zzfxSound - Array of zzfx parameters, ex. [.5,.5]
1060
+ * @param {Number} [range=soundDefaultRange] - World space max range of sound, will not play if camera is farther away
1061
+ * @param {Number} [taper=soundDefaultTaper] - At what percentage of range should it start tapering off
1062
+ */
1063
+ constructor(zzfxSound: any[], range?: number, taper?: number);
1064
+ /** @property {Number} - World space max range of sound, will not play if camera is farther away */
1065
+ range: number;
1066
+ /** @property {Number} - At what percentage of range should it start tapering off */
1067
+ taper: number;
1068
+ randomness: any;
1069
+ cachedSamples: number[];
1070
+ /** Play the sound
1071
+ * @param {Vector2} [pos] - World space position to play the sound, sound is not attenuated if null
1072
+ * @param {Number} [volume=1] - How much to scale volume by (in addition to range fade)
1073
+ * @param {Number} [pitch=1] - How much to scale pitch by (also adjusted by this.randomness)
1074
+ * @param {Number} [randomnessScale=1] - How much to scale randomness
1075
+ * @return {AudioBufferSourceNode} - The audio, can be used to stop sound later
1076
+ */
1077
+ play(pos?: Vector2, volume?: number, pitch?: number, randomnessScale?: number): AudioBufferSourceNode;
1078
+ /** Play the sound as a note with a semitone offset
1079
+ * @param {Number} semitoneOffset - How many semitones to offset pitch
1080
+ * @param {Vector2} [pos] - World space position to play the sound, sound is not attenuated if null
1081
+ * @param {Number} [volume=1] - How much to scale volume by (in addition to range fade)
1082
+ * @return {AudioBufferSourceNode} - The audio, can be used to stop sound later
1083
+ */
1084
+ playNote(semitoneOffset: number, pos?: Vector2, volume?: number): AudioBufferSourceNode;
1085
+ }
1086
+ /**
1087
+ * Music Object - Stores a zzfx music track for later use
1088
+ * <br>
1089
+ * <br><b><a href=https://keithclark.github.io/ZzFXM/>Create music with the ZzFXM tracker.</a></b>
1090
+ * @example
1091
+ * // create some music
1092
+ * const music_example = new Music(
1093
+ * [
1094
+ * [ // instruments
1095
+ * [,0,400] // simple note
1096
+ * ],
1097
+ * [ // patterns
1098
+ * [ // pattern 1
1099
+ * [ // channel 0
1100
+ * 0, -1, // instrument 0, left speaker
1101
+ * 1, 0, 9, 1 // channel notes
1102
+ * ],
1103
+ * [ // channel 1
1104
+ * 0, 1, // instrument 1, right speaker
1105
+ * 0, 12, 17, -1 // channel notes
1106
+ * ]
1107
+ * ],
1108
+ * ],
1109
+ * [0, 0, 0, 0], // sequence, play pattern 0 four times
1110
+ * 90 // BPM
1111
+ * ]);
1112
+ *
1113
+ * // play the music
1114
+ * music_example.play();
1115
+ */
1116
+ export class Music {
1117
+ /** Create a music object and cache the zzfx music samples for later use
1118
+ * @param {Array} zzfxMusic - Array of zzfx music parameters
1119
+ */
1120
+ constructor(zzfxMusic: any[]);
1121
+ cachedSamples: any[];
1122
+ /** Play the music
1123
+ * @param {Number} [volume=1] - How much to scale volume by
1124
+ * @param {Boolean} [loop=1] - True if the music should loop when it reaches the end
1125
+ * @return {AudioBufferSourceNode} - The audio node, can be used to stop sound later
1126
+ */
1127
+ play(volume?: number, loop?: boolean): AudioBufferSourceNode;
1128
+ source: number | AudioBufferSourceNode;
1129
+ /** Stop the music */
1130
+ stop(): void;
1131
+ /** Check if music is playing
1132
+ * @return {Boolean}
1133
+ */
1134
+ isPlaying(): boolean;
1135
+ }
1136
+ /** Play an mp3 or wav audio from a local file or url
1137
+ * @param {String} url - Location of sound file to play
1138
+ * @param {Number} [volume=1] - How much to scale volume by
1139
+ * @param {Boolean} [loop=1] - True if the music should loop when it reaches the end
1140
+ * @return {HTMLAudioElement} - The audio element for this sound
1141
+ * @memberof Audio */
1142
+ export function playAudioFile(url: string, volume?: number, loop?: boolean): HTMLAudioElement;
1143
+ /** Speak text with passed in settings
1144
+ * @param {String} text - The text to speak
1145
+ * @param {String} [language] - The language/accent to use (examples: en, it, ru, ja, zh)
1146
+ * @param {Number} [volume=1] - How much to scale volume by
1147
+ * @param {Number} [rate=1] - How quickly to speak
1148
+ * @param {Number} [pitch=1] - How much to change the pitch by
1149
+ * @return {SpeechSynthesisUtterance} - The utterance that was spoken
1150
+ * @memberof Audio */
1151
+ export function speak(text: string, language?: string, volume?: number, rate?: number, pitch?: number): SpeechSynthesisUtterance;
1152
+ /** Stop all queued speech
1153
+ * @memberof Audio */
1154
+ export function speakStop(): void;
1155
+ /** Get frequency of a note on a musical scale
1156
+ * @param {Number} semitoneOffset - How many semitones away from the root note
1157
+ * @param {Number} [rootNoteFrequency=220] - Frequency at semitone offset 0
1158
+ * @return {Number} - The frequency of the note
1159
+ * @memberof Audio */
1160
+ export function getNoteFrequency(semitoneOffset: number, rootFrequency?: number): number;
1161
+ /** Audio context used by the engine
1162
+ * @memberof Audio */
1163
+ export let audioContext: any;
1164
+ /** Play cached audio samples with given settings
1165
+ * @param {Array} sampleChannels - Array of arrays of samples to play (for stereo playback)
1166
+ * @param {Number} [volume=1] - How much to scale volume by
1167
+ * @param {Number} [rate=1] - The playback rate to use
1168
+ * @param {Number} [pan=0] - How much to apply stereo panning
1169
+ * @param {Boolean} [loop=0] - True if the sound should loop when it reaches the end
1170
+ * @return {AudioBufferSourceNode} - The audio node of the sound played
1171
+ * @memberof Audio */
1172
+ export function playSamples(sampleChannels: any[], volume?: number, rate?: number, pan?: number, loop?: boolean): AudioBufferSourceNode;
1173
+ /** Generate and play a ZzFX sound
1174
+ * <br>
1175
+ * <br><b><a href=https://killedbyapixel.github.io/ZzFX/>Create sounds using the ZzFX Sound Designer.</a></b>
1176
+ * @param {Array} zzfxSound - Array of ZzFX parameters, ex. [.5,.5]
1177
+ * @return {Array} - Array of audio samples
1178
+ * @memberof Audio */
1179
+ export function zzfx(...zzfxSound: any[]): any[];
1180
+ /** The tile collision layer array, use setTileCollisionData and getTileCollisionData to access
1181
+ * @memberof TileCollision */
1182
+ export let tileCollision: any[];
1183
+ /** Size of the tile collision layer
1184
+ * @type {Vector2}
1185
+ * @memberof TileCollision */
1186
+ export let tileCollisionSize: Vector2;
1187
+ /** Clear and initialize tile collision
1188
+ * @param {Vector2} size
1189
+ * @memberof TileCollision */
1190
+ export function initTileCollision(size: Vector2): void;
1191
+ /** Set tile collision data
1192
+ * @param {Vector2} pos
1193
+ * @param {Number} [data=0]
1194
+ * @memberof TileCollision */
1195
+ export function setTileCollisionData(pos: Vector2, data?: number): number;
1196
+ /** Get tile collision data
1197
+ * @param {Vector2} pos
1198
+ * @return {Number}
1199
+ * @memberof TileCollision */
1200
+ export function getTileCollisionData(pos: Vector2): number;
1201
+ /** Check if collision with another object should occur
1202
+ * @param {Vector2} pos
1203
+ * @param {Vector2} [size=new Vector2(1,1)]
1204
+ * @param {EngineObject} [object]
1205
+ * @return {Boolean}
1206
+ * @memberof TileCollision */
1207
+ export function tileCollisionTest(pos: Vector2, size?: Vector2, object?: EngineObject): boolean;
1208
+ /** Return the center of tile if any that is hit (this does not return the exact hit point)
1209
+ * @param {Vector2} posStart
1210
+ * @param {Vector2} posEnd
1211
+ * @param {EngineObject} [object]
1212
+ * @return {Vector2}
1213
+ * @memberof TileCollision */
1214
+ export function tileCollisionRaycast(posStart: Vector2, posEnd: Vector2, object?: EngineObject): Vector2;
1215
+ /**
1216
+ * Tile layer data object stores info about how to render a tile
1217
+ * @example
1218
+ * // create tile layer data with tile index 0 and random orientation and color
1219
+ * const tileIndex = 0;
1220
+ * const direction = randInt(4)
1221
+ * const mirror = randInt(2);
1222
+ * const color = randColor();
1223
+ * const data = new TileLayerData(tileIndex, direction, mirror, color);
1224
+ */
1225
+ export class TileLayerData {
1226
+ /** Create a tile layer data object, one for each tile in a TileLayer
1227
+ * @param {Number} [tile] - The tile to use, untextured if undefined
1228
+ * @param {Number} [direction=0] - Integer direction of tile, in 90 degree increments
1229
+ * @param {Boolean} [mirror=0] - If the tile should be mirrored along the x axis
1230
+ * @param {Color} [color=new Color(1,1,1)] - Color of the tile */
1231
+ constructor(tile?: number, direction?: number, mirror?: boolean, color?: Color);
1232
+ /** @property {Number} - The tile to use, untextured if undefined */
1233
+ tile: number;
1234
+ /** @property {Number} - Integer direction of tile, in 90 degree increments */
1235
+ direction: number;
1236
+ /** @property {Boolean} - If the tile should be mirrored along the x axis */
1237
+ mirror: boolean;
1238
+ /** @property {Color} - Color of the tile */
1239
+ color: Color;
1240
+ /** Set this tile to clear, it will not be rendered */
1241
+ clear(): void;
1242
+ }
1243
+ /**
1244
+ * Tile layer object - cached rendering system for tile layers
1245
+ * <br> - Each Tile layer is rendered to an off screen canvas
1246
+ * <br> - To allow dynamic modifications, layers are rendered using canvas 2d
1247
+ * <br> - Some devices like mobile phones are limited to 4k texture resolution
1248
+ * <br> - So with 16x16 tiles this limits layers to 256x256 on mobile devices
1249
+ * @extends EngineObject
1250
+ * @example
1251
+ * // create tile collision and visible tile layer
1252
+ * initTileCollision(vec2(200,100));
1253
+ * const tileLayer = new TileLayer();
1553
1254
  */
1554
- constructor(id: number, name: string, description?: string, icon?: string, src?: string);
1555
- id: number;
1556
- name: string;
1557
- description: string;
1558
- icon: string;
1559
- image: HTMLImageElement;
1560
- /** Unlocks a medal if not already unlocked */
1561
- unlock(): void;
1562
- unlocked: number;
1563
- /** Render a medal
1564
- * @param {Number} [hidePercent=0] - How much to slide the medal off screen
1255
+ export class TileLayer extends EngineObject {
1256
+ /** Create a tile layer object
1257
+ * @param {Vector2} [position=new Vector2()] - World space position
1258
+ * @param {Vector2} [size=tileCollisionSize] - World space size
1259
+ * @param {Vector2} [tileSize=tileSizeDefault] - Size of tiles in source pixels
1260
+ * @param {Vector2} [scale=new Vector2(1,1)] - How much to scale this layer when rendered
1261
+ * @param {Number} [renderOrder=0] - Objects sorted by renderOrder before being rendered
1262
+ */
1263
+ constructor(pos: any, size?: Vector2, tileSize?: Vector2, scale?: Vector2, renderOrder?: number);
1264
+ /** @property {HTMLCanvasElement} - The canvas used by this tile layer */
1265
+ canvas: HTMLCanvasElement;
1266
+ /** @property {CanvasRenderingContext2D} - The 2D canvas context used by this tile layer */
1267
+ context: CanvasRenderingContext2D;
1268
+ /** @property {Vector2} - How much to scale this layer when rendered */
1269
+ scale: Vector2;
1270
+ data: TileLayerData[];
1271
+ /** Set data at a given position in the array
1272
+ * @param {Vector2} position - Local position in array
1273
+ * @param {TileLayerData} data - Data to set
1274
+ * @param {Boolean} [redraw=0] - Force the tile to redraw if true */
1275
+ setData(layerPos: any, data: TileLayerData, redraw?: boolean): void;
1276
+ /** Get data at a given position in the array
1277
+ * @param {Vector2} layerPos - Local position in array
1278
+ * @return {TileLayerData} */
1279
+ getData(layerPos: Vector2): TileLayerData;
1280
+ /** Draw all the tile data to an offscreen canvas
1281
+ * - This may be slow in some browsers
1282
+ */
1283
+ redraw(): void;
1284
+ /** Call to start the redraw process
1285
+ * @param {Boolean} [clear=0] - Should it clear the canvas before drawing */
1286
+ redrawStart(clear?: boolean): void;
1287
+ savedRenderSettings: (number | HTMLCanvasElement | CanvasRenderingContext2D | Vector2)[];
1288
+ /** Call to end the redraw process */
1289
+ redrawEnd(): void;
1290
+ /** Draw the tile at a given position
1291
+ * @param {Vector2} layerPos */
1292
+ drawTileData(layerPos: Vector2): void;
1293
+ /** Draw all the tiles in this layer */
1294
+ drawAllTileData(): void;
1295
+ /** Draw directly to the 2D canvas in world space (bipass webgl)
1296
+ * @param {Vector2} pos
1297
+ * @param {Vector2} size
1298
+ * @param {Number} [angle=0]
1299
+ * @param {Boolean} [mirror=0]
1300
+ * @param {Function} drawFunction */
1301
+ drawCanvas2D(pos: Vector2, size: Vector2, angle?: number, mirror?: boolean, drawFunction: Function): void;
1302
+ /** Draw a tile directly onto the layer canvas
1303
+ * @param {Vector2} pos
1304
+ * @param {Vector2} [size=new Vector2(1,1)]
1305
+ * @param {Number} [tileIndex=-1]
1306
+ * @param {Vector2} [tileSize=tileSizeDefault]
1307
+ * @param {Color} [color=new Color(1,1,1)]
1308
+ * @param {Number} [angle=0]
1309
+ * @param {Boolean} [mirror=0] */
1310
+ drawTile(pos: Vector2, size?: Vector2, tileIndex?: number, tileSize?: Vector2, color?: Color, angle?: number, mirror?: boolean): void;
1311
+ /** Draw a rectangle directly onto the layer canvas
1312
+ * @param {Vector2} pos
1313
+ * @param {Vector2} [size=new Vector2(1,1)]
1314
+ * @param {Color} [color=new Color(1,1,1)]
1315
+ * @param {Number} [angle=0] */
1316
+ drawRect(pos: Vector2, size?: Vector2, color?: Color, angle?: number): void;
1317
+ }
1318
+ /**
1319
+ * Particle Emitter - Spawns particles with the given settings
1320
+ * @extends EngineObject
1321
+ * @example
1322
+ * // create a particle emitter
1323
+ * let pos = vec2(2,3);
1324
+ * let particleEmiter = new ParticleEmitter
1325
+ * (
1326
+ * pos, 0, 1, 0, 500, PI, // pos, angle, emitSize, emitTime, emitRate, emiteCone
1327
+ * 0, vec2(16), // tileIndex, tileSize
1328
+ * new Color(1,1,1), new Color(0,0,0), // colorStartA, colorStartB
1329
+ * new Color(1,1,1,0), new Color(0,0,0,0), // colorEndA, colorEndB
1330
+ * 2, .2, .2, .1, .05, // particleTime, sizeStart, sizeEnd, particleSpeed, particleAngleSpeed
1331
+ * .99, 1, 1, PI, .05, // damping, angleDamping, gravityScale, particleCone, fadeRate,
1332
+ * .5, 1 // randomness, collide, additive, randomColorLinear, renderOrder
1333
+ * );
1565
1334
  */
1566
- render(hidePercent?: number): void;
1567
- /** Render the icon for a medal
1568
- * @param {Number} x - Screen space X position
1569
- * @param {Number} y - Screen space Y position
1570
- * @param {Number} [size=medalDisplayIconSize] - Screen space size
1335
+ export class ParticleEmitter extends EngineObject {
1336
+ /** Create a particle system with the given settings
1337
+ * @param {Vector2} position - World space position of the emitter
1338
+ * @param {Number} [angle=0] - Angle to emit the particles
1339
+ * @param {Number} [emitSize=0] - World space size of the emitter (float for circle diameter, vec2 for rect)
1340
+ * @param {Number} [emitTime=0] - How long to stay alive (0 is forever)
1341
+ * @param {Number} [emitRate=100] - How many particles per second to spawn, does not emit if 0
1342
+ * @param {Number} [emitConeAngle=PI] - Local angle to apply velocity to particles from emitter
1343
+ * @param {Number} [tileIndex=-1] - Index into tile sheet, if <0 no texture is applied
1344
+ * @param {Vector2} [tileSize=tileSizeDefault] - Tile size for particles
1345
+ * @param {Color} [colorStartA=new Color(1,1,1)] - Color at start of life 1, randomized between start colors
1346
+ * @param {Color} [colorStartB=new Color(1,1,1)] - Color at start of life 2, randomized between start colors
1347
+ * @param {Color} [colorEndA=new Color(1,1,1,0)] - Color at end of life 1, randomized between end colors
1348
+ * @param {Color} [colorEndB=new Color(1,1,1,0)] - Color at end of life 2, randomized between end colors
1349
+ * @param {Number} [particleTime=.5] - How long particles live
1350
+ * @param {Number} [sizeStart=.1] - How big are particles at start
1351
+ * @param {Number} [sizeEnd=1] - How big are particles at end
1352
+ * @param {Number} [speed=.1] - How fast are particles when spawned
1353
+ * @param {Number} [angleSpeed=.05] - How fast are particles rotating
1354
+ * @param {Number} [damping=1] - How much to dampen particle speed
1355
+ * @param {Number} [angleDamping=1] - How much to dampen particle angular speed
1356
+ * @param {Number} [gravityScale=0] - How much does gravity effect particles
1357
+ * @param {Number} [particleConeAngle=PI] - Cone for start particle angle
1358
+ * @param {Number} [fadeRate=.1] - How quick to fade in particles at start/end in percent of life
1359
+ * @param {Number} [randomness=.2] - Apply extra randomness percent
1360
+ * @param {Boolean} [collideTiles=0] - Do particles collide against tiles
1361
+ * @param {Boolean} [additive=0] - Should particles use addtive blend
1362
+ * @param {Boolean} [randomColorLinear=1] - Should color be randomized linearly or across each component
1363
+ * @param {Number} [renderOrder=0] - Render order for particles (additive is above other stuff by default)
1364
+ * @param {Boolean} [localSpace=0] - Should it be in local space of emitter (world space is default)
1365
+ */
1366
+ constructor(pos: any, angle?: number, emitSize?: number, emitTime?: number, emitRate?: number, emitConeAngle?: number, tileIndex?: number, tileSize?: Vector2, colorStartA?: Color, colorStartB?: Color, colorEndA?: Color, colorEndB?: Color, particleTime?: number, sizeStart?: number, sizeEnd?: number, speed?: number, angleSpeed?: number, damping?: number, angleDamping?: number, gravityScale?: number, particleConeAngle?: number, fadeRate?: number, randomness?: number, collideTiles?: boolean, additive?: boolean, randomColorLinear?: boolean, renderOrder?: number, localSpace?: boolean);
1367
+ /** @property {Number} - World space size of the emitter (float for circle diameter, vec2 for rect) */
1368
+ emitSize: number;
1369
+ /** @property {Number} - How long to stay alive (0 is forever) */
1370
+ emitTime: number;
1371
+ /** @property {Number} - How many particles per second to spawn, does not emit if 0 */
1372
+ emitRate: number;
1373
+ /** @property {Number} - Local angle to apply velocity to particles from emitter */
1374
+ emitConeAngle: number;
1375
+ /** @property {Color} - Color at start of life 1, randomized between start colors */
1376
+ colorStartA: Color;
1377
+ /** @property {Color} - Color at start of life 2, randomized between start colors */
1378
+ colorStartB: Color;
1379
+ /** @property {Color} - Color at end of life 1, randomized between end colors */
1380
+ colorEndA: Color;
1381
+ /** @property {Color} - Color at end of life 2, randomized between end colors */
1382
+ colorEndB: Color;
1383
+ /** @property {Boolean} - Should color be randomized linearly or across each component */
1384
+ randomColorLinear: boolean;
1385
+ /** @property {Number} - How long particles live */
1386
+ particleTime: number;
1387
+ /** @property {Number} - How big are particles at start */
1388
+ sizeStart: number;
1389
+ /** @property {Number} - How big are particles at end */
1390
+ sizeEnd: number;
1391
+ /** @property {Number} - How fast are particles when spawned */
1392
+ speed: number;
1393
+ /** @property {Number} - How fast are particles rotating */
1394
+ angleSpeed: number;
1395
+ /** @property {Number} - Cone for start particle angle */
1396
+ particleConeAngle: number;
1397
+ /** @property {Number} - How quick to fade in particles at start/end in percent of life */
1398
+ fadeRate: number;
1399
+ /** @property {Number} - Apply extra randomness percent */
1400
+ randomness: number;
1401
+ /** @property {Number} - Do particles collide against tiles */
1402
+ collideTiles: boolean;
1403
+ /** @property {Number} - Should particles use addtive blend */
1404
+ additive: boolean;
1405
+ /** @property {Boolean} - Should it be in local space of emitter */
1406
+ localSpace: boolean;
1407
+ /** @property {Number} - If set the partile is drawn as a trail, stretched in the drection of velocity */
1408
+ trailScale: number;
1409
+ emitTimeBuffer: number;
1410
+ /** Spawn one particle
1411
+ * @return {Particle} */
1412
+ emitParticle(): Particle;
1413
+ }
1414
+ /**
1415
+ * Particle Object - Created automatically by Particle Emitters
1416
+ * @extends EngineObject
1571
1417
  */
1572
- renderIcon(pos: any, size?: number): void;
1573
- storageKey(): string;
1574
- }
1575
- declare let newgrounds: any;
1576
- /**
1577
- * Newgrounds API wrapper object
1578
- * @example
1579
- * // create a newgrounds object, replace the app id and cipher with your own
1580
- * const app_id = '53123:1ZuSTQ9l';
1581
- * const cipher = 'enF0vGH@Mj/FRASKL23Q==';
1582
- * newgrounds = new Newgrounds(app_id, cipher);
1583
- */
1584
- declare class Newgrounds {
1585
- /** Create a newgrounds object
1418
+ export class Particle extends EngineObject {
1419
+ /**
1420
+ * Create a particle with the given settings
1421
+ * @param {Vector2} position - World space position of the particle
1422
+ * @param {Number} [tileIndex=-1] - Tile to use to render, untextured if -1
1423
+ * @param {Vector2} [tileSize=tileSizeDefault] - Size of tile in source pixels
1424
+ * @param {Number} [angle=0] - Angle to rotate the particle
1425
+ */
1426
+ constructor(pos: any, tileIndex?: number, tileSize?: Vector2, angle?: number);
1427
+ }
1428
+ /** List of all medals
1429
+ * @memberof Medals */
1430
+ export const medals: any[];
1431
+ /** Set to stop medals from being unlockable (like if cheats are enabled)
1432
+ * @default
1433
+ * @memberof Settings */
1434
+ export let medalsPreventUnlock: any;
1435
+ /** Initialize medals with a save name used for storage
1436
+ * <br> - Call this after creating all medals
1437
+ * <br> - Checks if medals are unlocked
1438
+ * @param {String} saveName
1439
+ * @memberof Medals */
1440
+ export function medalsInit(saveName: string): void;
1441
+ /** This can used to enable Newgrounds functionality
1586
1442
  * @param {Number} app_id - The newgrounds App ID
1587
- * @param {String} [cipher] - The encryption Key (AES-128/Base64) */
1588
- constructor(app_id: number, cipher?: string);
1589
- app_id: number;
1590
- cipher: string;
1591
- host: string;
1592
- cryptoJS: any;
1593
- session_id: string;
1594
- medals: any;
1595
- scoreboards: any;
1596
- /** Send message to unlock a medal by id
1597
- * @param {Number} id - The medal id */
1598
- unlockMedal(id: number): any;
1599
- /** Send message to post score
1600
- * @param {Number} id - The scoreboard id
1601
- * @param {Number} value - The score value */
1602
- postScore(id: number, value: number): any;
1603
- /** Get scores from a scoreboard
1604
- * @param {Number} id - The scoreboard id
1605
- * @param {String} [user=0] - A user's id or name
1606
- * @param {Number} [social=0] - If true, only social scores will be loaded
1607
- * @param {Number} [skip=0] - Number of scores to skip before start
1608
- * @param {Number} [limit=10] - Number of scores to include in the list
1609
- * @return {Object} - The response JSON object
1443
+ * @param {String} [cipher] - The encryption Key (AES-128/Base64)
1444
+ * @memberof Medals */
1445
+ export function newgroundsInit(app_id: number, cipher?: string): void;
1446
+ /**
1447
+ * Medal Object - Tracks an unlockable medal
1448
+ * @example
1449
+ * // create a medal
1450
+ * const medal_example = new Medal(0, 'Example Medal', 'More info about the medal goes here.', '🎖️');
1451
+ *
1452
+ * // initialize medals
1453
+ * medalsInit('Example Game');
1454
+ *
1455
+ * // unlock the medal
1456
+ * medal_example.unlock();
1457
+ */
1458
+ export class Medal {
1459
+ /** Create an medal object and adds it to the list of medals
1460
+ * @param {Number} id - The unique identifier of the medal
1461
+ * @param {String} name - Name of the medal
1462
+ * @param {String} [description] - Description of the medal
1463
+ * @param {String} [icon='🏆'] - Icon for the medal
1464
+ * @param {String} [src] - Image location for the medal
1465
+ */
1466
+ constructor(id: number, name: string, description?: string, icon?: string, src?: string);
1467
+ id: number;
1468
+ name: string;
1469
+ description: string;
1470
+ icon: string;
1471
+ image: HTMLImageElement;
1472
+ /** Unlocks a medal if not already unlocked */
1473
+ unlock(): void;
1474
+ unlocked: number;
1475
+ /** Render a medal
1476
+ * @param {Number} [hidePercent=0] - How much to slide the medal off screen
1477
+ */
1478
+ render(hidePercent?: number): void;
1479
+ /** Render the icon for a medal
1480
+ * @param {Number} x - Screen space X position
1481
+ * @param {Number} y - Screen space Y position
1482
+ * @param {Number} [size=medalDisplayIconSize] - Screen space size
1483
+ */
1484
+ renderIcon(pos: any, size?: number): void;
1485
+ storageKey(): string;
1486
+ }
1487
+ /**
1488
+ * Newgrounds API wrapper object
1489
+ * @example
1490
+ * // create a newgrounds object, replace the app id and cipher with your own
1491
+ * const app_id = '53123:1ZuSTQ9l';
1492
+ * const cipher = 'enF0vGH@Mj/FRASKL23Q==';
1493
+ * newgrounds = new Newgrounds(app_id, cipher);
1494
+ */
1495
+ export class Newgrounds {
1496
+ /** Create a newgrounds object
1497
+ * @param {Number} app_id - The newgrounds App ID
1498
+ * @param {String} [cipher] - The encryption Key (AES-128/Base64) */
1499
+ constructor(app_id: number, cipher?: string);
1500
+ app_id: number;
1501
+ cipher: string;
1502
+ host: string;
1503
+ cryptoJS: any;
1504
+ session_id: string;
1505
+ medals: any;
1506
+ scoreboards: any;
1507
+ /** Send message to unlock a medal by id
1508
+ * @param {Number} id - The medal id */
1509
+ unlockMedal(id: number): any;
1510
+ /** Send message to post score
1511
+ * @param {Number} id - The scoreboard id
1512
+ * @param {Number} value - The score value */
1513
+ postScore(id: number, value: number): any;
1514
+ /** Get scores from a scoreboard
1515
+ * @param {Number} id - The scoreboard id
1516
+ * @param {String} [user=0] - A user's id or name
1517
+ * @param {Number} [social=0] - If true, only social scores will be loaded
1518
+ * @param {Number} [skip=0] - Number of scores to skip before start
1519
+ * @param {Number} [limit=10] - Number of scores to include in the list
1520
+ * @return {Object} - The response JSON object
1521
+ */
1522
+ getScores(id: number, user?: string, social?: number, skip?: number, limit?: number): any;
1523
+ /** Send message to log a view */
1524
+ logView(): any;
1525
+ /** Send a message to call a component of the Newgrounds API
1526
+ * @param {String} component - Name of the component
1527
+ * @param {Object} [parameters=0] - Parameters to use for call
1528
+ * @param {Boolean} [async=0] - If true, don't wait for response before continuing (avoid stall)
1529
+ * @return {Object} - The response JSON object
1530
+ */
1531
+ call(component: string, parameters?: any, async?: boolean): any;
1532
+ CryptoJS(): any;
1533
+ }
1534
+ /** The WebGL canvas which appears above the main canvas and below the overlay canvas
1535
+ * @type {HTMLCanvasElement}
1536
+ * @memberof WebGL */
1537
+ export let glCanvas: HTMLCanvasElement;
1538
+ /** 2d context for glCanvas
1539
+ * @type {WebGLRenderingContext}
1540
+ * @memberof WebGL */
1541
+ export let glContext: WebGLRenderingContext;
1542
+ /** Set the WebGl blend mode, normally you should call setBlendMode instead
1543
+ * @param {Boolean} [additive=0]
1544
+ * @memberof WebGL */
1545
+ export function glSetBlendMode(additive?: boolean): void;
1546
+ /** Set the WebGl texture, not normally necessary unless multiple tile sheets are used
1547
+ * <br> - This may also flush the gl buffer resulting in more draw calls and worse performance
1548
+ * @param {WebGLTexture} [texture=glTileTexture]
1549
+ * @memberof WebGL */
1550
+ export function glSetTexture(texture?: WebGLTexture): void;
1551
+ /** Compile WebGL shader of the given type, will throw errors if in debug mode
1552
+ * @param {String} source
1553
+ * @param type
1554
+ * @return {WebGLShader}
1555
+ * @memberof WebGL */
1556
+ export function glCompileShader(source: string, type: any): WebGLShader;
1557
+ /** Create WebGL program with given shaders
1558
+ * @param {WebGLShader} vsSource
1559
+ * @param {WebGLShader} fsSource
1560
+ * @return {WebGLProgram}
1561
+ * @memberof WebGL */
1562
+ export function glCreateProgram(vsSource: WebGLShader, fsSource: WebGLShader): WebGLProgram;
1563
+ /** Create WebGL texture from an image and set the texture settings
1564
+ * @param {Image} image
1565
+ * @return {WebGLTexture}
1566
+ * @memberof WebGL */
1567
+ export function glCreateTexture(image: new (width?: number, height?: number) => HTMLImageElement): WebGLTexture;
1568
+ /** Set up a post processing shader
1569
+ * @param {String} shaderCode
1570
+ * @memberof WebGL */
1571
+ export function glInitPostProcess(shaderCode: string): void;
1572
+ /** Name of engine */
1573
+ export const engineName: "LittleJS";
1574
+ /** Version of engine */
1575
+ export const engineVersion: "1.5.0";
1576
+ /** Frames per second to update objects
1577
+ * @default */
1578
+ export const frameRate: 60;
1579
+ /** How many seconds each frame lasts, engine uses a fixed time step
1580
+ * @default 1/60 */
1581
+ export const timeDelta: number;
1582
+ /** Array containing all engine objects */
1583
+ export let engineObjects: any[];
1584
+ /** Current update frame, used to calculate time */
1585
+ export let frame: number;
1586
+ /** Current engine time since start in seconds, derived from frame */
1587
+ export let time: number;
1588
+ /** Actual clock time since start in seconds (not affected by pause or frame rate clamping) */
1589
+ export let timeReal: number;
1590
+ /** Is the game paused? Causes time and objects to not be updated */
1591
+ export let paused: number;
1592
+ /** Set if game is paused
1593
+ * @param {Boolean} paused
1610
1594
  */
1611
- getScores(id: number, user?: string, social?: number, skip?: number, limit?: number): any;
1612
- /** Send message to log a view */
1613
- logView(): any;
1614
- /** Send a message to call a component of the Newgrounds API
1615
- * @param {String} component - Name of the component
1616
- * @param {Object} [parameters=0] - Parameters to use for call
1617
- * @param {Boolean} [async=0] - If true, don't wait for response before continuing (avoid stall)
1618
- * @return {Object} - The response JSON object
1595
+ export function setPaused(_paused: any): void;
1596
+ /** Start up LittleJS engine with your callback functions
1597
+ * @param {Function} gameInit - Called once after the engine starts up, setup the game
1598
+ * @param {Function} gameUpdate - Called every frame at 60 frames per second, handle input and update the game state
1599
+ * @param {Function} gameUpdatePost - Called after physics and objects are updated, setup camera and prepare for render
1600
+ * @param {Function} gameRender - Called before objects are rendered, draw any background effects that appear behind objects
1601
+ * @param {Function} gameRenderPost - Called after objects are rendered, draw effects or hud that appear above all objects
1602
+ * @param {String} [tileImageSource] - Tile image to use, everything starts when the image is finished loading
1619
1603
  */
1620
- call(component: string, parameters?: any, async?: boolean): any;
1621
- CryptoJS(): any;
1604
+ export function engineInit(gameInit: Function, gameUpdate: Function, gameUpdatePost: Function, gameRender: Function, gameRenderPost: Function, tileImageSource?: string): void;
1605
+ /** Update each engine object, remove destroyed objects, and update time */
1606
+ export function engineObjectsUpdate(): void;
1607
+ /** Destroy and remove all objects */
1608
+ export function engineObjectsDestroy(): void;
1609
+ /** Triggers a callback for each object within a given area
1610
+ * @param {Vector2} [pos] - Center of test area
1611
+ * @param {Number} [size] - Radius of circle if float, rectangle size if Vector2
1612
+ * @param {Function} [callbackFunction] - Calls this function on every object that passes the test
1613
+ * @param {Array} [objects=engineObjects] - List of objects to check */
1614
+ export function engineObjectsCallback(pos?: Vector2, size?: number, callbackFunction?: Function, objects?: any[]): void;
1622
1615
  }
1623
- /** The WebGL canvas which appears above the main canvas and below the overlay canvas
1624
- * @type {HTMLCanvasElement}
1625
- * @memberof WebGL */
1626
- declare let glCanvas: HTMLCanvasElement;
1627
- /** 2d context for glCanvas
1628
- * @type {WebGLRenderingContext}
1629
- * @memberof WebGL */
1630
- declare let glContext: WebGLRenderingContext;
1631
- /** Main tile sheet texture automatically loaded by engine
1632
- * @type {WebGLTexture}
1633
- * @memberof WebGL */
1634
- declare let glTileTexture: WebGLTexture;
1635
- declare let glActiveTexture: any;
1636
- declare let glShader: any;
1637
- declare let glArrayBuffer: any;
1638
- declare let glPositionData: any;
1639
- declare let glColorData: any;
1640
- declare let glBatchCount: any;
1641
- declare let glBatchAdditive: any;
1642
- declare let glAdditive: any;
1643
- declare let glPostShader: any;
1644
- declare let glPostArrayBuffer: any;
1645
- declare let glPostTexture: any;
1646
- declare const gl_ONE: 1;
1647
- declare const gl_TRIANGLES: 4;
1648
- declare const gl_SRC_ALPHA: 770;
1649
- declare const gl_ONE_MINUS_SRC_ALPHA: 771;
1650
- declare const gl_BLEND: 3042;
1651
- declare const gl_TEXTURE_2D: 3553;
1652
- declare const gl_UNSIGNED_BYTE: 5121;
1653
- declare const gl_BYTE: 5120;
1654
- declare const gl_FLOAT: 5126;
1655
- declare const gl_RGBA: 6408;
1656
- declare const gl_NEAREST: 9728;
1657
- declare const gl_LINEAR: 9729;
1658
- declare const gl_TEXTURE_MAG_FILTER: 10240;
1659
- declare const gl_TEXTURE_MIN_FILTER: 10241;
1660
- declare const gl_TEXTURE_WRAP_S: 10242;
1661
- declare const gl_TEXTURE_WRAP_T: 10243;
1662
- declare const gl_COLOR_BUFFER_BIT: 16384;
1663
- declare const gl_CLAMP_TO_EDGE: 33071;
1664
- declare const gl_TEXTURE0: 33984;
1665
- declare const gl_TEXTURE1: 33985;
1666
- declare const gl_ARRAY_BUFFER: 34962;
1667
- declare const gl_STATIC_DRAW: 35044;
1668
- declare const gl_DYNAMIC_DRAW: 35048;
1669
- declare const gl_FRAGMENT_SHADER: 35632;
1670
- declare const gl_VERTEX_SHADER: 35633;
1671
- declare const gl_COMPILE_STATUS: 35713;
1672
- declare const gl_LINK_STATUS: 35714;
1673
- declare const gl_UNPACK_FLIP_Y_WEBGL: 37440;
1674
- declare const gl_VERTICES_PER_QUAD: 6;
1675
- declare const gl_INDICIES_PER_VERT: 6;
1676
- declare const gl_MAX_BATCH: number;
1677
- declare const gl_VERTEX_BYTE_STRIDE: number;
1678
- declare const gl_VERTEX_BUFFER_SIZE: number;
1679
- /** Name of engine */
1680
- declare const engineName: "LittleJS";
1681
- /** Version of engine */
1682
- declare const engineVersion: "1.4.9";
1683
- /** Frames per second to update objects
1684
- * @default */
1685
- declare const frameRate: 60;
1686
- /** How many seconds each frame lasts, engine uses a fixed time step
1687
- * @default 1/60 */
1688
- declare const timeDelta: number;
1689
- /** Array containing all engine objects */
1690
- declare let engineObjects: any[];
1691
- /** Array containing only objects that are set to collide with other objects this frame (for optimization) */
1692
- declare let engineObjectsCollide: any[];
1693
- /** Current update frame, used to calculate time */
1694
- declare let frame: number;
1695
- /** Current engine time since start in seconds, derived from frame */
1696
- declare let time: number;
1697
- /** Actual clock time since start in seconds (not affected by pause or frame rate clamping) */
1698
- declare let timeReal: number;
1699
- /** Is the game paused? Causes time and objects to not be updated */
1700
- declare let paused: number;