littlejsengine 1.9.0 → 1.9.1

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/index.d.ts ADDED
@@ -0,0 +1,2094 @@
1
+ declare module "littlejsengine" {
2
+ /**
3
+ * LittleJS - The Tiny JavaScript Game Engine That Can!
4
+ * MIT License - Copyright 2021 Frank Force
5
+ *
6
+ * Engine Features
7
+ * - Object oriented system with base class engine object
8
+ * - Base class object handles update, physics, collision, rendering, etc
9
+ * - Engine helper classes and functions like Vector2, Color, and Timer
10
+ * - Super fast rendering system for tile sheets
11
+ * - Sound effects audio with zzfx and music with zzfxm
12
+ * - Input processing system with gamepad and touchscreen support
13
+ * - Tile layer rendering and collision system
14
+ * - Particle effect system
15
+ * - Medal system tracks and displays achievements
16
+ * - Debug tools and debug rendering system
17
+ * - Post processing effects
18
+ * - Call engineInit() to start it up!
19
+ * @namespace Engine
20
+ */
21
+ /** Name of engine
22
+ * @type {String}
23
+ * @default
24
+ * @memberof Engine */
25
+ export const engineName: string;
26
+ /** Version of engine
27
+ * @type {String}
28
+ * @default
29
+ * @memberof Engine */
30
+ export const engineVersion: string;
31
+ /** Frames per second to update objects
32
+ * @type {Number}
33
+ * @default
34
+ * @memberof Engine */
35
+ export const frameRate: number;
36
+ /** How many seconds each frame lasts, engine uses a fixed time step
37
+ * @type {Number}
38
+ * @default 1/60
39
+ * @memberof Engine */
40
+ export const timeDelta: number;
41
+ /** Array containing all engine objects
42
+ * @type {Array}
43
+ * @memberof Engine */
44
+ export let engineObjects: any[];
45
+ /** Current update frame, used to calculate time
46
+ * @type {Number}
47
+ * @memberof Engine */
48
+ export let frame: number;
49
+ /** Current engine time since start in seconds, derived from frame
50
+ * @type {Number}
51
+ * @memberof Engine */
52
+ export let time: number;
53
+ /** Actual clock time since start in seconds (not affected by pause or frame rate clamping)
54
+ * @type {Number}
55
+ * @memberof Engine */
56
+ export let timeReal: number;
57
+ /** Is the game paused? Causes time and objects to not be updated
58
+ * @type {Boolean}
59
+ * @default false
60
+ * @memberof Engine */
61
+ export let paused: boolean;
62
+ /** Set if game is paused
63
+ * @param {Boolean} isPaused
64
+ * @memberof Engine */
65
+ export function setPaused(isPaused: boolean): void;
66
+ /** Start up LittleJS engine with your callback functions
67
+ * @param {Function} gameInit - Called once after the engine starts up, setup the game
68
+ * @param {Function} gameUpdate - Called every frame at 60 frames per second, handle input and update the game state
69
+ * @param {Function} gameUpdatePost - Called after physics and objects are updated, setup camera and prepare for render
70
+ * @param {Function} gameRender - Called before objects are rendered, draw any background effects that appear behind objects
71
+ * @param {Function} gameRenderPost - Called after objects are rendered, draw effects or hud that appear above all objects
72
+ * @param {Array} [imageSources=['tiles.png']] - Image to load
73
+ * @memberof Engine */
74
+ export function engineInit(gameInit: Function, gameUpdate: Function, gameUpdatePost: Function, gameRender: Function, gameRenderPost: Function, imageSources?: any[]): void;
75
+ /** Update each engine object, remove destroyed objects, and update time
76
+ * @memberof Engine */
77
+ export function engineObjectsUpdate(): void;
78
+ /** Destroy and remove all objects
79
+ * @memberof Engine */
80
+ export function engineObjectsDestroy(): void;
81
+ /** Triggers a callback for each object within a given area
82
+ * @param {Vector2} [pos] - Center of test area
83
+ * @param {Number|Vector2} [size] - Radius of circle if float, rectangle size if Vector2
84
+ * @param {Function} [callbackFunction] - Calls this function on every object that passes the test
85
+ * @param {Array} [objects=engineObjects] - List of objects to check
86
+ * @memberof Engine */
87
+ export function engineObjectsCallback(pos?: Vector2, size?: number | Vector2, callbackFunction?: Function, objects?: any[]): void;
88
+ /**
89
+ * LittleJS Debug System
90
+ * - Press Esc to show debug overlay with mouse pick
91
+ * - Number keys toggle debug functions
92
+ * - +/- apply time scale
93
+ * - Debug primitive rendering
94
+ * - Save a 2d canvas as a png image
95
+ * @namespace Debug
96
+ */
97
+ /** True if debug is enabled
98
+ * @type {Boolean}
99
+ * @default
100
+ * @memberof Debug */
101
+ export const debug: boolean;
102
+ /** True if the debug overlay is active, always false in release builds
103
+ * @type {Boolean}
104
+ * @default
105
+ * @memberof Debug */
106
+ export let debugOverlay: boolean;
107
+ /** True if watermark with FPS should be shown, false in release builds
108
+ * @type {Boolean}
109
+ * @default
110
+ * @memberof Debug */
111
+ export let showWatermark: boolean;
112
+ /** Asserts if the experssion is false, does not do anything in release builds
113
+ * @param {Boolean} assert
114
+ * @param {Object} output
115
+ * @memberof Debug */
116
+ export function ASSERT(assert: boolean, output: any): void;
117
+ /** Draw a debug rectangle in world space
118
+ * @param {Vector2} pos
119
+ * @param {Vector2} [size=Vector2()]
120
+ * @param {String} [color]
121
+ * @param {Number} [time]
122
+ * @param {Number} [angle]
123
+ * @param {Boolean} [fill]
124
+ * @memberof Debug */
125
+ export function debugRect(pos: Vector2, size?: Vector2, color?: string, time?: number, angle?: number, fill?: boolean): void;
126
+ /** Draw a debug circle in world space
127
+ * @param {Vector2} pos
128
+ * @param {Number} [radius]
129
+ * @param {String} [color]
130
+ * @param {Number} [time]
131
+ * @param {Boolean} [fill]
132
+ * @memberof Debug */
133
+ export function debugCircle(pos: Vector2, radius?: number, color?: string, time?: number, fill?: boolean): void;
134
+ /** Draw a debug point in world space
135
+ * @param {Vector2} pos
136
+ * @param {String} [color]
137
+ * @param {Number} [time]
138
+ * @param {Number} [angle]
139
+ * @memberof Debug */
140
+ export function debugPoint(pos: Vector2, color?: string, time?: number, angle?: number): void;
141
+ /** Draw a debug line in world space
142
+ * @param {Vector2} posA
143
+ * @param {Vector2} posB
144
+ * @param {String} [color]
145
+ * @param {Number} [thickness]
146
+ * @param {Number} [time]
147
+ * @memberof Debug */
148
+ export function debugLine(posA: Vector2, posB: Vector2, color?: string, thickness?: number, time?: number): void;
149
+ /** Draw a debug axis aligned bounding box in world space
150
+ * @param {Vector2} pA - position A
151
+ * @param {Vector2} sA - size A
152
+ * @param {Vector2} pB - position B
153
+ * @param {Vector2} sB - size B
154
+ * @param {String} [color]
155
+ * @memberof Debug */
156
+ export function debugAABB(pA: Vector2, sA: Vector2, pB: Vector2, sB: Vector2, color?: string): void;
157
+ /** Draw a debug axis aligned bounding box in world space
158
+ * @param {String} text
159
+ * @param {Vector2} pos
160
+ * @param {Number} [size]
161
+ * @param {String} [color]
162
+ * @param {Number} [time]
163
+ * @param {Number} [angle]
164
+ * @param {String} [font]
165
+ * @memberof Debug */
166
+ export function debugText(text: string, pos: Vector2, size?: number, color?: string, time?: number, angle?: number, font?: string): void;
167
+ /** Clear all debug primitives in the list
168
+ * @memberof Debug */
169
+ export function debugClear(): void;
170
+ /** Save a canvas to disk
171
+ * @param {HTMLCanvasElement} canvas
172
+ * @param {String} [filename]
173
+ * @param {String} [type]
174
+ * @memberof Debug */
175
+ export function debugSaveCanvas(canvas: HTMLCanvasElement, filename?: string, type?: string): void;
176
+ /**
177
+ * LittleJS Engine Settings
178
+ * - All settings for the engine are here
179
+ * @namespace Settings
180
+ */
181
+ /** Position of camera in world space
182
+ * @type {Vector2}
183
+ * @default Vector2()
184
+ * @memberof Settings */
185
+ export let cameraPos: Vector2;
186
+ /** Scale of camera in world space
187
+ * @type {Number}
188
+ * @default
189
+ * @memberof Settings */
190
+ export let cameraScale: number;
191
+ /** The max size of the canvas, centered if window is larger
192
+ * @type {Vector2}
193
+ * @default Vector2(1920,1200)
194
+ * @memberof Settings */
195
+ export let canvasMaxSize: Vector2;
196
+ /** Fixed size of the canvas, if enabled canvas size never changes
197
+ * - you may also need to set mainCanvasSize if using screen space coords in startup
198
+ * @type {Vector2}
199
+ * @default Vector2()
200
+ * @memberof Settings */
201
+ export let canvasFixedSize: Vector2;
202
+ /** Disables filtering for crisper pixel art if true
203
+ * @type {Boolean}
204
+ * @default
205
+ * @memberof Settings */
206
+ export let canvasPixelated: boolean;
207
+ /** Default font used for text rendering
208
+ * @type {String}
209
+ * @default
210
+ * @memberof Settings */
211
+ export let fontDefault: string;
212
+ /** Enable to show the LittleJS splash screen be shown on startup
213
+ * @type {Boolean}
214
+ * @default
215
+ * @memberof Settings */
216
+ export let showSplashScreen: boolean;
217
+ /** Default size of tiles in pixels
218
+ * @type {Vector2}
219
+ * @default Vector2(16,16)
220
+ * @memberof Settings */
221
+ export let tileSizeDefault: Vector2;
222
+ /** How many pixels smaller to draw tiles to prevent bleeding from neighbors
223
+ * @type {Number}
224
+ * @default
225
+ * @memberof Settings */
226
+ export let tileFixBleedScale: number;
227
+ /** Enable physics solver for collisions between objects
228
+ * @type {Boolean}
229
+ * @default
230
+ * @memberof Settings */
231
+ export let enablePhysicsSolver: boolean;
232
+ /** Default object mass for collison calcuations (how heavy objects are)
233
+ * @type {Number}
234
+ * @default
235
+ * @memberof Settings */
236
+ export let objectDefaultMass: number;
237
+ /** How much to slow velocity by each frame (0-1)
238
+ * @type {Number}
239
+ * @default
240
+ * @memberof Settings */
241
+ export let objectDefaultDamping: number;
242
+ /** How much to slow angular velocity each frame (0-1)
243
+ * @type {Number}
244
+ * @default
245
+ * @memberof Settings */
246
+ export let objectDefaultAngleDamping: number;
247
+ /** How much to bounce when a collision occurs (0-1)
248
+ * @type {Number}
249
+ * @default
250
+ * @memberof Settings */
251
+ export let objectDefaultElasticity: number;
252
+ /** How much to slow when touching (0-1)
253
+ * @type {Number}
254
+ * @default
255
+ * @memberof Settings */
256
+ export let objectDefaultFriction: number;
257
+ /** Clamp max speed to avoid fast objects missing collisions
258
+ * @type {Number}
259
+ * @default
260
+ * @memberof Settings */
261
+ export let objectMaxSpeed: number;
262
+ /** How much gravity to apply to objects along the Y axis, negative is down
263
+ * @type {Number}
264
+ * @default
265
+ * @memberof Settings */
266
+ export let gravity: number;
267
+ /** Scales emit rate of particles, useful for low graphics mode (0 disables particle emitters)
268
+ * @type {Number}
269
+ * @default
270
+ * @memberof Settings */
271
+ export let particleEmitRateScale: number;
272
+ /** Enable webgl rendering, webgl can be disabled and removed from build (with some features disabled)
273
+ * @type {Boolean}
274
+ * @default
275
+ * @memberof Settings */
276
+ export let glEnable: boolean;
277
+ /** Fixes slow rendering in some browsers by not compositing the WebGL canvas
278
+ * @type {Boolean}
279
+ * @default
280
+ * @memberof Settings */
281
+ export let glOverlay: boolean;
282
+ /** Should gamepads be allowed
283
+ * @type {Boolean}
284
+ * @default
285
+ * @memberof Settings */
286
+ export let gamepadsEnable: boolean;
287
+ /** If true, the dpad input is also routed to the left analog stick (for better accessability)
288
+ * @type {Boolean}
289
+ * @default
290
+ * @memberof Settings */
291
+ export let gamepadDirectionEmulateStick: boolean;
292
+ /** If true the WASD keys are also routed to the direction keys (for better accessability)
293
+ * @type {Boolean}
294
+ * @default
295
+ * @memberof Settings */
296
+ export let inputWASDEmulateDirection: boolean;
297
+ /** True if touch gamepad should appear on mobile devices
298
+ * - Supports left analog stick, 4 face buttons and start button (button 9)
299
+ * - Must be set by end of gameInit to be activated
300
+ * @type {Boolean}
301
+ * @default
302
+ * @memberof Settings */
303
+ export let touchGamepadEnable: boolean;
304
+ /** True if touch gamepad should be analog stick or false to use if 8 way dpad
305
+ * @type {Boolean}
306
+ * @default
307
+ * @memberof Settings */
308
+ export let touchGamepadAnalog: boolean;
309
+ /** Size of virutal gamepad for touch devices in pixels
310
+ * @type {Number}
311
+ * @default
312
+ * @memberof Settings */
313
+ export let touchGamepadSize: number;
314
+ /** Transparency of touch gamepad overlay
315
+ * @type {Number}
316
+ * @default
317
+ * @memberof Settings */
318
+ export let touchGamepadAlpha: number;
319
+ /** Allow vibration hardware if it exists
320
+ * @type {Boolean}
321
+ * @default
322
+ * @memberof Settings */
323
+ export let vibrateEnable: boolean;
324
+ /** All audio code can be disabled and removed from build
325
+ * @type {Boolean}
326
+ * @default
327
+ * @memberof Settings */
328
+ export let soundEnable: boolean;
329
+ /** Volume scale to apply to all sound, music and speech
330
+ * @type {Number}
331
+ * @default
332
+ * @memberof Settings */
333
+ export let soundVolume: number;
334
+ /** Default range where sound no longer plays
335
+ * @type {Number}
336
+ * @default
337
+ * @memberof Settings */
338
+ export let soundDefaultRange: number;
339
+ /** Default range percent to start tapering off sound (0-1)
340
+ * @type {Number}
341
+ * @default
342
+ * @memberof Settings */
343
+ export let soundDefaultTaper: number;
344
+ /** How long to show medals for in seconds
345
+ * @type {Number}
346
+ * @default
347
+ * @memberof Settings */
348
+ export let medalDisplayTime: number;
349
+ /** How quickly to slide on/off medals in seconds
350
+ * @type {Number}
351
+ * @default
352
+ * @memberof Settings */
353
+ export let medalDisplaySlideTime: number;
354
+ /** Size of medal display
355
+ * @type {Vector2}
356
+ * @default Vector2(640,80)
357
+ * @memberof Settings */
358
+ export let medalDisplaySize: Vector2;
359
+ /** Size of icon in medal display
360
+ * @type {Number}
361
+ * @default
362
+ * @memberof Settings */
363
+ export let medalDisplayIconSize: number;
364
+ /** Set position of camera in world space
365
+ * @param {Vector2} pos
366
+ * @memberof Settings */
367
+ export function setCameraPos(pos: Vector2): void;
368
+ /** Set scale of camera in world space
369
+ * @param {Number} scale
370
+ * @memberof Settings */
371
+ export function setCameraScale(scale: number): void;
372
+ /** Set max size of the canvas
373
+ * @param {Vector2} size
374
+ * @memberof Settings */
375
+ export function setCanvasMaxSize(size: Vector2): void;
376
+ /** Set fixed size of the canvas
377
+ * @param {Vector2} size
378
+ * @memberof Settings */
379
+ export function setCanvasFixedSize(size: Vector2): void;
380
+ /** Disables anti aliasing for pixel art if true
381
+ * @param {Boolean} pixelated
382
+ * @memberof Settings */
383
+ export function setCanvasPixelated(pixelated: boolean): void;
384
+ /** Set default font used for text rendering
385
+ * @param {String} font
386
+ * @memberof Settings */
387
+ export function setFontDefault(font: string): void;
388
+ /** Set if the LittleJS splash screen be shown on startup
389
+ * @param {Boolean} show
390
+ * @memberof Settings */
391
+ export function setShowSplashScreen(show: boolean): void;
392
+ /** Set if webgl rendering is enabled
393
+ * @param {Boolean} enable
394
+ * @memberof Settings */
395
+ export function setGlEnable(enable: boolean): void;
396
+ /** Set to not composite the WebGL canvas
397
+ * @param {Boolean} overlay
398
+ * @memberof Settings */
399
+ export function setGlOverlay(overlay: boolean): void;
400
+ /** Set default size of tiles in pixels
401
+ * @param {Vector2} size
402
+ * @memberof Settings */
403
+ export function setTileSizeDefault(size: Vector2): void;
404
+ /** Set to prevent tile bleeding from neighbors in pixels
405
+ * @param {Number} scale
406
+ * @memberof Settings */
407
+ export function setTileFixBleedScale(scale: number): void;
408
+ /** Set if collisions between objects are enabled
409
+ * @param {Boolean} enable
410
+ * @memberof Settings */
411
+ export function setEnablePhysicsSolver(enable: boolean): void;
412
+ /** Set default object mass for collison calcuations
413
+ * @param {Number} mass
414
+ * @memberof Settings */
415
+ export function setObjectDefaultMass(mass: number): void;
416
+ /** Set how much to slow velocity by each frame
417
+ * @param {Number} damp
418
+ * @memberof Settings */
419
+ export function setObjectDefaultDamping(damp: number): void;
420
+ /** Set how much to slow angular velocity each frame
421
+ * @param {Number} damp
422
+ * @memberof Settings */
423
+ export function setObjectDefaultAngleDamping(damp: number): void;
424
+ /** Set how much to bounce when a collision occur
425
+ * @param {Number} elasticity
426
+ * @memberof Settings */
427
+ export function setObjectDefaultElasticity(elasticity: number): void;
428
+ /** Set how much to slow when touching
429
+ * @param {Number} friction
430
+ * @memberof Settings */
431
+ export function setObjectDefaultFriction(friction: number): void;
432
+ /** Set max speed to avoid fast objects missing collisions
433
+ * @param {Number} speed
434
+ * @memberof Settings */
435
+ export function setObjectMaxSpeed(speed: number): void;
436
+ /** Set how much gravity to apply to objects along the Y axis
437
+ * @param {Number} newGravity
438
+ * @memberof Settings */
439
+ export function setGravity(newGravity: number): void;
440
+ /** Set to scales emit rate of particles
441
+ * @param {Number} scale
442
+ * @memberof Settings */
443
+ export function setParticleEmitRateScale(scale: number): void;
444
+ /** Set if gamepads are enabled
445
+ * @param {Boolean} enable
446
+ * @memberof Settings */
447
+ export function setGamepadsEnable(enable: boolean): void;
448
+ /** Set if the dpad input is also routed to the left analog stick
449
+ * @param {Boolean} enable
450
+ * @memberof Settings */
451
+ export function setGamepadDirectionEmulateStick(enable: boolean): void;
452
+ /** Set if true the WASD keys are also routed to the direction keys
453
+ * @param {Boolean} enable
454
+ * @memberof Settings */
455
+ export function setInputWASDEmulateDirection(enable: boolean): void;
456
+ /** Set if touch gamepad should appear on mobile devices
457
+ * @param {Boolean} enable
458
+ * @memberof Settings */
459
+ export function setTouchGamepadEnable(enable: boolean): void;
460
+ /** Set if touch gamepad should be analog stick or 8 way dpad
461
+ * @param {Boolean} analog
462
+ * @memberof Settings */
463
+ export function setTouchGamepadAnalog(analog: boolean): void;
464
+ /** Set size of virutal gamepad for touch devices in pixels
465
+ * @param {Number} size
466
+ * @memberof Settings */
467
+ export function setTouchGamepadSize(size: number): void;
468
+ /** Set transparency of touch gamepad overlay
469
+ * @param {Number} alpha
470
+ * @memberof Settings */
471
+ export function setTouchGamepadAlpha(alpha: number): void;
472
+ /** Set to allow vibration hardware if it exists
473
+ * @param {Boolean} enable
474
+ * @memberof Settings */
475
+ export function setVibrateEnable(enable: boolean): void;
476
+ /** Set to disable all audio code
477
+ * @param {Boolean} enable
478
+ * @memberof Settings */
479
+ export function setSoundEnable(enable: boolean): void;
480
+ /** Set volume scale to apply to all sound, music and speech
481
+ * @param {Number} volume
482
+ * @memberof Settings */
483
+ export function setSoundVolume(volume: number): void;
484
+ /** Set default range where sound no longer plays
485
+ * @param {Number} range
486
+ * @memberof Settings */
487
+ export function setSoundDefaultRange(range: number): void;
488
+ /** Set default range percent to start tapering off sound
489
+ * @param {Number} taper
490
+ * @memberof Settings */
491
+ export function setSoundDefaultTaper(taper: number): void;
492
+ /** Set how long to show medals for in seconds
493
+ * @param {Number} time
494
+ * @memberof Settings */
495
+ export function setMedalDisplayTime(time: number): void;
496
+ /** Set how quickly to slide on/off medals in seconds
497
+ * @param {Number} time
498
+ * @memberof Settings */
499
+ export function setMedalDisplaySlideTime(time: number): void;
500
+ /** Set size of medal display
501
+ * @param {Vector2} size
502
+ * @memberof Settings */
503
+ export function setMedalDisplaySize(size: Vector2): void;
504
+ /** Set size of icon in medal display
505
+ * @param {Number} size
506
+ * @memberof Settings */
507
+ export function setMedalDisplayIconSize(size: number): void;
508
+ /** Set to stop medals from being unlockable
509
+ * @param {Boolean} preventUnlock
510
+ * @memberof Settings */
511
+ export function setMedalsPreventUnlock(preventUnlock: boolean): void;
512
+ /** Set if watermark with FPS should be shown
513
+ * @param {Boolean} show
514
+ * @memberof Debug */
515
+ export function setShowWatermark(show: boolean): void;
516
+ /** Set key code used to toggle debug mode, Esc by default
517
+ * @param {String} key
518
+ * @memberof Debug */
519
+ export function setDebugKey(key: string): void;
520
+ /**
521
+ * LittleJS Utility Classes and Functions
522
+ * - General purpose math library
523
+ * - Vector2 - fast, simple, easy 2D vector class
524
+ * - Color - holds a rgba color with some math functions
525
+ * - Timer - tracks time automatically
526
+ * - RandomGenerator - seeded random number generator
527
+ * @namespace Utilities
528
+ */
529
+ /** A shortcut to get Math.PI
530
+ * @type {Number}
531
+ * @default Math.PI
532
+ * @memberof Utilities */
533
+ export const PI: number;
534
+ /** Returns absoulte value of value passed in
535
+ * @param {Number} value
536
+ * @return {Number}
537
+ * @memberof Utilities */
538
+ export function abs(value: number): number;
539
+ /** Returns lowest of two values passed in
540
+ * @param {Number} valueA
541
+ * @param {Number} valueB
542
+ * @return {Number}
543
+ * @memberof Utilities */
544
+ export function min(valueA: number, valueB: number): number;
545
+ /** Returns highest of two values passed in
546
+ * @param {Number} valueA
547
+ * @param {Number} valueB
548
+ * @return {Number}
549
+ * @memberof Utilities */
550
+ export function max(valueA: number, valueB: number): number;
551
+ /** Returns the sign of value passed in (also returns 1 if 0)
552
+ * @param {Number} value
553
+ * @return {Number}
554
+ * @memberof Utilities */
555
+ export function sign(value: number): number;
556
+ /** Returns first parm modulo the second param, but adjusted so negative numbers work as expected
557
+ * @param {Number} dividend
558
+ * @param {Number} [divisor]
559
+ * @return {Number}
560
+ * @memberof Utilities */
561
+ export function mod(dividend: number, divisor?: number): number;
562
+ /** Clamps the value beween max and min
563
+ * @param {Number} value
564
+ * @param {Number} [min]
565
+ * @param {Number} [max]
566
+ * @return {Number}
567
+ * @memberof Utilities */
568
+ export function clamp(value: number, min?: number, max?: number): number;
569
+ /** Returns what percentage the value is between valueA and valueB
570
+ * @param {Number} value
571
+ * @param {Number} valueA
572
+ * @param {Number} valueB
573
+ * @return {Number}
574
+ * @memberof Utilities */
575
+ export function percent(value: number, valueA: number, valueB: number): number;
576
+ /** Returns signed wrapped distance between the two values passed in
577
+ * @param {Number} valueA
578
+ * @param {Number} valueB
579
+ * @param {Number} [wrapSize]
580
+ * @returns {Number}
581
+ * @memberof Utilities */
582
+ export function distanceWrap(valueA: number, valueB: number, wrapSize?: number): number;
583
+ /** Linearly interpolates between values passed in with wrappping
584
+ * @param {Number} percent
585
+ * @param {Number} valueA
586
+ * @param {Number} valueB
587
+ * @param {Number} [wrapSize]
588
+ * @returns {Number}
589
+ * @memberof Utilities */
590
+ export function lerpWrap(percent: number, valueA: number, valueB: number, wrapSize?: number): number;
591
+ /** Returns signed wrapped distance between the two angles passed in
592
+ * @param {Number} angleA
593
+ * @param {Number} angleB
594
+ * @returns {Number}
595
+ * @memberof Utilities */
596
+ export function distanceAngle(angleA: number, angleB: number): number;
597
+ /** Linearly interpolates between the angles passed in with wrappping
598
+ * @param {Number} percent
599
+ * @param {Number} angleA
600
+ * @param {Number} angleB
601
+ * @returns {Number}
602
+ * @memberof Utilities */
603
+ export function lerpAngle(percent: number, angleA: number, angleB: number): number;
604
+ /** Linearly interpolates between values passed in using percent
605
+ * @param {Number} percent
606
+ * @param {Number} valueA
607
+ * @param {Number} valueB
608
+ * @return {Number}
609
+ * @memberof Utilities */
610
+ export function lerp(percent: number, valueA: number, valueB: number): number;
611
+ /** Applies smoothstep function to the percentage value
612
+ * @param {Number} percent
613
+ * @return {Number}
614
+ * @memberof Utilities */
615
+ export function smoothStep(percent: number): number;
616
+ /** Returns the nearest power of two not less then the value
617
+ * @param {Number} value
618
+ * @return {Number}
619
+ * @memberof Utilities */
620
+ export function nearestPowerOfTwo(value: number): number;
621
+ /** Returns true if two axis aligned bounding boxes are overlapping
622
+ * @param {Vector2} pointA - Center of box A
623
+ * @param {Vector2} sizeA - Size of box A
624
+ * @param {Vector2} pointB - Center of box B
625
+ * @param {Vector2} sizeB - Size of box B
626
+ * @return {Boolean} - True if overlapping
627
+ * @memberof Utilities */
628
+ export function isOverlapping(pointA: Vector2, sizeA: Vector2, pointB: Vector2, sizeB: Vector2): boolean;
629
+ /** Returns an oscillating wave between 0 and amplitude with frequency of 1 Hz by default
630
+ * @param {Number} [frequency] - Frequency of the wave in Hz
631
+ * @param {Number} [amplitude] - Amplitude (max height) of the wave
632
+ * @param {Number} [t=time] - Value to use for time of the wave
633
+ * @return {Number} - Value waving between 0 and amplitude
634
+ * @memberof Utilities */
635
+ export function wave(frequency?: number, amplitude?: number, t?: number): number;
636
+ /** Formats seconds to mm:ss style for display purposes
637
+ * @param {Number} t - time in seconds
638
+ * @return {String}
639
+ * @memberof Utilities */
640
+ export function formatTime(t: number): string;
641
+ /** Random global functions
642
+ * @namespace Random */
643
+ /** Returns a random value between the two values passed in
644
+ * @param {Number} [valueA]
645
+ * @param {Number} [valueB]
646
+ * @return {Number}
647
+ * @memberof Random */
648
+ export function rand(valueA?: number, valueB?: number): number;
649
+ /** Returns a floored random value the two values passed in
650
+ * @param {Number} valueA
651
+ * @param {Number} [valueB]
652
+ * @return {Number}
653
+ * @memberof Random */
654
+ export function randInt(valueA: number, valueB?: number): number;
655
+ /** Randomly returns either -1 or 1
656
+ * @return {Number}
657
+ * @memberof Random */
658
+ export function randSign(): number;
659
+ /** Returns a random Vector2 within a circular shape
660
+ * @param {Number} [radius]
661
+ * @param {Number} [minRadius]
662
+ * @return {Vector2}
663
+ * @memberof Random */
664
+ export function randInCircle(radius?: number, minRadius?: number): Vector2;
665
+ /** Returns a random Vector2 with the passed in length
666
+ * @param {Number} [length]
667
+ * @return {Vector2}
668
+ * @memberof Random */
669
+ export function randVector(length?: number): Vector2;
670
+ /** Returns a random color between the two passed in colors, combine components if linear
671
+ * @param {Color} [colorA=Color()]
672
+ * @param {Color} [colorB=Color(0,0,0,1)]
673
+ * @param {Boolean} [linear]
674
+ * @return {Color}
675
+ * @memberof Random */
676
+ export function randColor(colorA?: Color, colorB?: Color, linear?: boolean): Color;
677
+ /**
678
+ * Seeded random number generator
679
+ * - Can be used to create a deterministic random number sequence
680
+ * @example
681
+ * let r = new RandomGenerator(123); // random number generator with seed 123
682
+ * let a = r.float(); // random value between 0 and 1
683
+ * let b = r.int(10); // random integer between 0 and 9
684
+ * r.seed = 123; // reset the seed
685
+ * let c = r.float(); // the same value as a
686
+ */
687
+ export class RandomGenerator {
688
+ /** Create a random number generator with the seed passed in
689
+ * @param {Number} seed - Starting seed */
690
+ constructor(seed: number);
691
+ /** @property {Number} - random seed */
692
+ seed: number;
693
+ /** Returns a seeded random value between the two values passed in
694
+ * @param {Number} [valueA]
695
+ * @param {Number} [valueB]
696
+ * @return {Number} */
697
+ float(valueA?: number, valueB?: number): number;
698
+ /** Returns a floored seeded random value the two values passed in
699
+ * @param {Number} valueA
700
+ * @param {Number} [valueB]
701
+ * @return {Number} */
702
+ int(valueA: number, valueB?: number): number;
703
+ /** Randomly returns either -1 or 1 deterministically
704
+ * @return {Number} */
705
+ sign(): number;
706
+ }
707
+ /**
708
+ * 2D Vector object with vector math library
709
+ * - Functions do not change this so they can be chained together
710
+ * @example
711
+ * let a = new Vector2(2, 3); // vector with coordinates (2, 3)
712
+ * let b = new Vector2; // vector with coordinates (0, 0)
713
+ * let c = vec2(4, 2); // use the vec2 function to make a Vector2
714
+ * let d = a.add(b).scale(5); // operators can be chained
715
+ */
716
+ export class Vector2 {
717
+ /** Create a 2D vector with the x and y passed in, can also be created with vec2()
718
+ * @param {Number} [x] - X axis location
719
+ * @param {Number} [y] - Y axis location */
720
+ constructor(x?: number, y?: number);
721
+ /** @property {Number} - X axis location */
722
+ x: number;
723
+ /** @property {Number} - Y axis location */
724
+ y: number;
725
+ /** Returns a new vector that is a copy of this
726
+ * @return {Vector2} */
727
+ copy(): Vector2;
728
+ /** Returns a copy of this vector plus the vector passed in
729
+ * @param {Vector2} v - other vector
730
+ * @return {Vector2} */
731
+ add(v: Vector2): Vector2;
732
+ /** Returns a copy of this vector minus the vector passed in
733
+ * @param {Vector2} v - other vector
734
+ * @return {Vector2} */
735
+ subtract(v: Vector2): Vector2;
736
+ /** Returns a copy of this vector times the vector passed in
737
+ * @param {Vector2} v - other vector
738
+ * @return {Vector2} */
739
+ multiply(v: Vector2): Vector2;
740
+ /** Returns a copy of this vector divided by the vector passed in
741
+ * @param {Vector2} v - other vector
742
+ * @return {Vector2} */
743
+ divide(v: Vector2): Vector2;
744
+ /** Returns a copy of this vector scaled by the vector passed in
745
+ * @param {Number} s - scale
746
+ * @return {Vector2} */
747
+ scale(s: number): Vector2;
748
+ /** Returns the length of this vector
749
+ * @return {Number} */
750
+ length(): number;
751
+ /** Returns the length of this vector squared
752
+ * @return {Number} */
753
+ lengthSquared(): number;
754
+ /** Returns the distance from this vector to vector passed in
755
+ * @param {Vector2} v - other vector
756
+ * @return {Number} */
757
+ distance(v: Vector2): number;
758
+ /** Returns the distance squared from this vector to vector passed in
759
+ * @param {Vector2} v - other vector
760
+ * @return {Number} */
761
+ distanceSquared(v: Vector2): number;
762
+ /** Returns a new vector in same direction as this one with the length passed in
763
+ * @param {Number} [length]
764
+ * @return {Vector2} */
765
+ normalize(length?: number): Vector2;
766
+ /** Returns a new vector clamped to length passed in
767
+ * @param {Number} [length]
768
+ * @return {Vector2} */
769
+ clampLength(length?: number): Vector2;
770
+ /** Returns the dot product of this and the vector passed in
771
+ * @param {Vector2} v - other vector
772
+ * @return {Number} */
773
+ dot(v: Vector2): number;
774
+ /** Returns the cross product of this and the vector passed in
775
+ * @param {Vector2} v - other vector
776
+ * @return {Number} */
777
+ cross(v: Vector2): number;
778
+ /** Returns the angle of this vector, up is angle 0
779
+ * @return {Number} */
780
+ angle(): number;
781
+ /** Sets this vector with angle and length passed in
782
+ * @param {Number} [angle]
783
+ * @param {Number} [length]
784
+ * @return {Vector2} */
785
+ setAngle(angle?: number, length?: number): Vector2;
786
+ /** Returns copy of this vector rotated by the angle passed in
787
+ * @param {Number} angle
788
+ * @return {Vector2} */
789
+ rotate(angle: number): Vector2;
790
+ /** Returns the integer direction of this vector, corrosponding to multiples of 90 degree rotation (0-3)
791
+ * @return {Number} */
792
+ direction(): number;
793
+ /** Returns a copy of this vector that has been inverted
794
+ * @return {Vector2} */
795
+ invert(): Vector2;
796
+ /** Returns a copy of this vector with each axis floored
797
+ * @return {Vector2} */
798
+ floor(): Vector2;
799
+ /** Returns the area this vector covers as a rectangle
800
+ * @return {Number} */
801
+ area(): number;
802
+ /** Returns a new vector that is p percent between this and the vector passed in
803
+ * @param {Vector2} v - other vector
804
+ * @param {Number} percent
805
+ * @return {Vector2} */
806
+ lerp(v: Vector2, percent: number): Vector2;
807
+ /** Returns true if this vector is within the bounds of an array size passed in
808
+ * @param {Vector2} arraySize
809
+ * @return {Boolean} */
810
+ arrayCheck(arraySize: Vector2): boolean;
811
+ /** Returns this vector expressed as a string
812
+ * @param {Number} digits - precision to display
813
+ * @return {String} */
814
+ toString(digits?: number): string;
815
+ }
816
+ /**
817
+ * Color object (red, green, blue, alpha) with some helpful functions
818
+ * @example
819
+ * let a = new Color; // white
820
+ * let b = new Color(1, 0, 0); // red
821
+ * let c = new Color(0, 0, 0, 0); // transparent black
822
+ * let d = RGB(0, 0, 1); // blue using rgb color
823
+ * let e = HSL(.3, 1, .5); // green using hsl color
824
+ */
825
+ export class Color {
826
+ /** Create a color with the rgba components passed in, white by default
827
+ * @param {Number} [r] - red
828
+ * @param {Number} [g] - green
829
+ * @param {Number} [b] - blue
830
+ * @param {Number} [a] - alpha*/
831
+ constructor(r?: number, g?: number, b?: number, a?: number);
832
+ /** @property {Number} - Red */
833
+ r: number;
834
+ /** @property {Number} - Green */
835
+ g: number;
836
+ /** @property {Number} - Blue */
837
+ b: number;
838
+ /** @property {Number} - Alpha */
839
+ a: number;
840
+ /** Returns a new color that is a copy of this
841
+ * @return {Color} */
842
+ copy(): Color;
843
+ /** Returns a copy of this color plus the color passed in
844
+ * @param {Color} c - other color
845
+ * @return {Color} */
846
+ add(c: Color): Color;
847
+ /** Returns a copy of this color minus the color passed in
848
+ * @param {Color} c - other color
849
+ * @return {Color} */
850
+ subtract(c: Color): Color;
851
+ /** Returns a copy of this color times the color passed in
852
+ * @param {Color} c - other color
853
+ * @return {Color} */
854
+ multiply(c: Color): Color;
855
+ /** Returns a copy of this color divided by the color passed in
856
+ * @param {Color} c - other color
857
+ * @return {Color} */
858
+ divide(c: Color): Color;
859
+ /** Returns a copy of this color scaled by the value passed in, alpha can be scaled separately
860
+ * @param {Number} scale
861
+ * @param {Number} [alphaScale=scale]
862
+ * @return {Color} */
863
+ scale(scale: number, alphaScale?: number): Color;
864
+ /** Returns a copy of this color clamped to the valid range between 0 and 1
865
+ * @return {Color} */
866
+ clamp(): Color;
867
+ /** Returns a new color that is p percent between this and the color passed in
868
+ * @param {Color} c - other color
869
+ * @param {Number} percent
870
+ * @return {Color} */
871
+ lerp(c: Color, percent: number): Color;
872
+ /** Sets this color given a hue, saturation, lightness, and alpha
873
+ * @param {Number} [h] - hue
874
+ * @param {Number} [s] - saturation
875
+ * @param {Number} [l] - lightness
876
+ * @param {Number} [a] - alpha
877
+ * @return {Color} */
878
+ setHSLA(h?: number, s?: number, l?: number, a?: number): Color;
879
+ /** Returns this color expressed in hsla format
880
+ * @return {Array} */
881
+ getHSLA(): any[];
882
+ /** Returns a new color that has each component randomly adjusted
883
+ * @param {Number} [amount]
884
+ * @param {Number} [alphaAmount]
885
+ * @return {Color} */
886
+ mutate(amount?: number, alphaAmount?: number): Color;
887
+ /** Returns this color expressed as a hex color code
888
+ * @param {Boolean} [useAlpha] - if alpha should be included in result
889
+ * @return {String} */
890
+ toString(useAlpha?: boolean): string;
891
+ /** Set this color from a hex code
892
+ * @param {String} hex - html hex code
893
+ * @return {Color} */
894
+ setHex(hex: string): Color;
895
+ /** Returns this color expressed as 32 bit RGBA value
896
+ * @return {Number} */
897
+ rgbaInt(): number;
898
+ }
899
+ /**
900
+ * Timer object tracks how long has passed since it was set
901
+ * @example
902
+ * let a = new Timer; // creates a timer that is not set
903
+ * a.set(3); // sets the timer to 3 seconds
904
+ *
905
+ * let b = new Timer(1); // creates a timer with 1 second left
906
+ * b.unset(); // unsets the timer
907
+ */
908
+ export class Timer {
909
+ /** Create a timer object set time passed in
910
+ * @param {Number} [timeLeft] - How much time left before the timer elapses in seconds */
911
+ constructor(timeLeft?: number);
912
+ time: number;
913
+ setTime: number;
914
+ /** Set the timer with seconds passed in
915
+ * @param {Number} [timeLeft] - How much time left before the timer is elapsed in seconds */
916
+ set(timeLeft?: number): void;
917
+ /** Unset the timer */
918
+ unset(): void;
919
+ /** Returns true if set
920
+ * @return {Boolean} */
921
+ isSet(): boolean;
922
+ /** Returns true if set and has not elapsed
923
+ * @return {Boolean} */
924
+ active(): boolean;
925
+ /** Returns true if set and elapsed
926
+ * @return {Boolean} */
927
+ elapsed(): boolean;
928
+ /** Get how long since elapsed, returns 0 if not set (returns negative if currently active)
929
+ * @return {Number} */
930
+ get(): number;
931
+ /** Get percentage elapsed based on time it was set to, returns 0 if not set
932
+ * @return {Number} */
933
+ getPercent(): number;
934
+ /** Returns this timer expressed as a string
935
+ * @return {String} */
936
+ toString(): string;
937
+ /** Get how long since elapsed, returns 0 if not set (returns negative if currently active)
938
+ * @return {Number} */
939
+ valueOf(): number;
940
+ }
941
+ /**
942
+ * Create a 2d vector, can take another Vector2 to copy, 2 scalars, or 1 scalar
943
+ * @param {(Number|Vector2)} [x]
944
+ * @param {Number} [y]
945
+ * @return {Vector2}
946
+ * @example
947
+ * let a = vec2(0, 1); // vector with coordinates (0, 1)
948
+ * let b = vec2(a); // copy a into b
949
+ * a = vec2(5); // set a to (5, 5)
950
+ * b = vec2(); // set b to (0, 0)
951
+ * @memberof Utilities
952
+ */
953
+ export function vec2(x?: (number | Vector2), y?: number): Vector2;
954
+ /**
955
+ * Create a color object with RGBA values
956
+ * @param {Number} [r=1] - red
957
+ * @param {Number} [g=1] - green
958
+ * @param {Number} [b=1] - blue
959
+ * @param {Number} [a=1] - alpha
960
+ * @return {Color}
961
+ * @memberof Utilities
962
+ */
963
+ export function rgb(r?: number, g?: number, b?: number, a?: number): Color;
964
+ /**
965
+ * Create a color object with HSLA values
966
+ * @param {Number} [h=0] - hue
967
+ * @param {Number} [s=0] - saturation
968
+ * @param {Number} [l=1] - lightness
969
+ * @param {Number} [a=1] - alpha
970
+ * @return {Color}
971
+ * @memberof Utilities
972
+ */
973
+ export function hsl(h?: number, s?: number, l?: number, a?: number): Color;
974
+ /** Array containing texture info for batch rendering system
975
+ * @type {Array}
976
+ * @memberof Draw */
977
+ export let textureInfos: any[];
978
+ /**
979
+ * Create a tile info object
980
+ * - This can take vecs or floats for easier use and conversion
981
+ * - If an index is passed in, the tile size and index will determine the position
982
+ * @param {(Number|Vector2)} [pos=(0,0)] - Top left corner of tile in pixels or index
983
+ * @param {(Number|Vector2)} [size=tileSizeDefault] - Size of tile in pixels
984
+ * @param {Number} [textureIndex] - Texture index to use
985
+ * @return {TileInfo}
986
+ * @example
987
+ * tile(2) // a tile at index 2 using the default tile size of 16
988
+ * tile(5, 8) // a tile at index 5 using a tile size of 8
989
+ * tile(1, 16, 3) // a tile at index 1 of size 16 on texture 3
990
+ * tile(vec2(4,8), vec2(30,10)) // a tile at pixel location (4,8) with a size of (30,10)
991
+ * @memberof Draw
992
+ */
993
+ export function tile(pos?: (number | Vector2), size?: (number | Vector2), textureIndex?: number): TileInfo;
994
+ /**
995
+ * Tile Info - Stores info about how to draw a tile
996
+ */
997
+ export class TileInfo {
998
+ /** Create a tile info object
999
+ * @param {Vector2} [pos=(0,0)] - Top left corner of tile in pixels
1000
+ * @param {Vector2} [size=tileSizeDefault] - Size of tile in pixels
1001
+ * @param {Number} [textureIndex] - Texture index to use
1002
+ */
1003
+ constructor(pos?: Vector2, size?: Vector2, textureIndex?: number);
1004
+ /** @property {Vector2} - Top left corner of tile in pixels */
1005
+ pos: Vector2;
1006
+ /** @property {Vector2} - Size of tile in pixels */
1007
+ size: Vector2;
1008
+ /** @property {Number} - Texture index to use */
1009
+ textureIndex: number;
1010
+ /** Returns an offset copy of this tile, useful for animation
1011
+ * @param {Vector2} offset - Offset to apply in pixels
1012
+ * @return {TileInfo}
1013
+ */
1014
+ offset(offset: Vector2): TileInfo;
1015
+ /** Returns the texture info for this tile
1016
+ * @return {TextureInfo}
1017
+ */
1018
+ getTextureInfo(): TextureInfo;
1019
+ }
1020
+ /** Texture Info - Stores info about each texture */
1021
+ export class TextureInfo {
1022
+ /**
1023
+ * Create a TextureInfo, called automatically by the engine
1024
+ * @param {HTMLImageElement} image
1025
+ */
1026
+ constructor(image: HTMLImageElement);
1027
+ /** @property {HTMLImageElement} - image source */
1028
+ image: HTMLImageElement;
1029
+ /** @property {Vector2} - size of the image */
1030
+ size: Vector2;
1031
+ /** @property {WebGLTexture} - webgl texture */
1032
+ glTexture: WebGLTexture;
1033
+ /** @property {Vector2} - size to adjust tile to fix bleeding */
1034
+ fixBleedSize: Vector2;
1035
+ }
1036
+ /**
1037
+ * LittleJS Drawing System
1038
+ * - Hybrid system with both Canvas2D and WebGL available
1039
+ * - Super fast tile sheet rendering with WebGL
1040
+ * - Can apply rotation, mirror, color and additive color
1041
+ * - Font rendering system with built in engine font
1042
+ * - Many useful utility functions
1043
+ *
1044
+ * LittleJS uses a hybrid rendering solution with the best of both Canvas2D and WebGL.
1045
+ * There are 3 canvas/contexts available to draw to...
1046
+ * mainCanvas - 2D background canvas, non WebGL stuff like tile layers are drawn here.
1047
+ * glCanvas - Used by the accelerated WebGL batch rendering system.
1048
+ * overlayCanvas - Another 2D canvas that appears on top of the other 2 canvases.
1049
+ *
1050
+ * The WebGL rendering system is very fast with some caveats...
1051
+ * - Switching blend modes (additive) or textures causes another draw call which is expensive in excess
1052
+ * - Group additive rendering together using renderOrder to mitigate this issue
1053
+ *
1054
+ * The LittleJS rendering solution is intentionally simple, feel free to adjust it for your needs!
1055
+ * @namespace Draw
1056
+ */
1057
+ /** The primary 2D canvas visible to the user
1058
+ * @type {HTMLCanvasElement}
1059
+ * @memberof Draw */
1060
+ export let mainCanvas: HTMLCanvasElement;
1061
+ /** 2d context for mainCanvas
1062
+ * @type {CanvasRenderingContext2D}
1063
+ * @memberof Draw */
1064
+ export let mainContext: CanvasRenderingContext2D;
1065
+ /** A canvas that appears on top of everything the same size as mainCanvas
1066
+ * @type {HTMLCanvasElement}
1067
+ * @memberof Draw */
1068
+ export let overlayCanvas: HTMLCanvasElement;
1069
+ /** 2d context for overlayCanvas
1070
+ * @type {CanvasRenderingContext2D}
1071
+ * @memberof Draw */
1072
+ export let overlayContext: CanvasRenderingContext2D;
1073
+ /** The size of the main canvas (and other secondary canvases)
1074
+ * @type {Vector2}
1075
+ * @memberof Draw */
1076
+ export let mainCanvasSize: Vector2;
1077
+ /** Convert from screen to world space coordinates
1078
+ * @param {Vector2} screenPos
1079
+ * @return {Vector2}
1080
+ * @memberof Draw */
1081
+ export function screenToWorld(screenPos: Vector2): Vector2;
1082
+ /** Convert from world to screen space coordinates
1083
+ * @param {Vector2} worldPos
1084
+ * @return {Vector2}
1085
+ * @memberof Draw */
1086
+ export function worldToScreen(worldPos: Vector2): Vector2;
1087
+ /** Draw textured tile centered in world space, with color applied if using WebGL
1088
+ * @param {Vector2} pos - Center of the tile in world space
1089
+ * @param {Vector2} [size=(1,1)] - Size of the tile in world space
1090
+ * @param {TileInfo}[tileInfo] - Tile info to use, untextured if undefined
1091
+ * @param {Color} [color=(1,1,1,1)] - Color to modulate with
1092
+ * @param {Number} [angle] - Angle to rotate by
1093
+ * @param {Boolean} [mirror] - If true image is flipped along the Y axis
1094
+ * @param {Color} [additiveColor=(0,0,0,0)] - Additive color to be applied
1095
+ * @param {Boolean} [useWebGL=glEnable] - Use accelerated WebGL rendering
1096
+ * @param {Boolean} [screenSpace=false] - If true the pos and size are in screen space
1097
+ * @param {CanvasRenderingContext2D} [context] - Canvas 2D context to draw to
1098
+ * @memberof Draw */
1099
+ export function drawTile(pos: Vector2, size?: Vector2, tileInfo?: TileInfo, color?: Color, angle?: number, mirror?: boolean, additiveColor?: Color, useWebGL?: boolean, screenSpace?: boolean, context?: CanvasRenderingContext2D): void;
1100
+ /** Draw colored rect centered on pos
1101
+ * @param {Vector2} pos
1102
+ * @param {Vector2} [size=(1,1)]
1103
+ * @param {Color} [color=(1,1,1,1)]
1104
+ * @param {Number} [angle]
1105
+ * @param {Boolean} [useWebGL=glEnable]
1106
+ * @param {Boolean} [screenSpace=false]
1107
+ * @param {CanvasRenderingContext2D} [context]
1108
+ * @memberof Draw */
1109
+ export function drawRect(pos: Vector2, size?: Vector2, color?: Color, angle?: number, useWebGL?: boolean, screenSpace?: boolean, context?: CanvasRenderingContext2D): void;
1110
+ /** Draw colored line between two points
1111
+ * @param {Vector2} posA
1112
+ * @param {Vector2} posB
1113
+ * @param {Number} [thickness]
1114
+ * @param {Color} [color=(1,1,1,1)]
1115
+ * @param {Boolean} [useWebGL=glEnable]
1116
+ * @param {Boolean} [screenSpace=false]
1117
+ * @param {CanvasRenderingContext2D} [context]
1118
+ * @memberof Draw */
1119
+ export function drawLine(posA: Vector2, posB: Vector2, thickness?: number, color?: Color, useWebGL?: boolean, screenSpace?: boolean, context?: CanvasRenderingContext2D): void;
1120
+ /** Draw directly to a 2d canvas context in world space
1121
+ * @param {Vector2} pos
1122
+ * @param {Vector2} size
1123
+ * @param {Number} angle
1124
+ * @param {Boolean} mirror
1125
+ * @param {Function} drawFunction
1126
+ * @param {Boolean} [screenSpace=false]
1127
+ * @param {CanvasRenderingContext2D} [context=mainContext]
1128
+ * @memberof Draw */
1129
+ export function drawCanvas2D(pos: Vector2, size: Vector2, angle: number, mirror: boolean, drawFunction: Function, screenSpace?: boolean, context?: CanvasRenderingContext2D): void;
1130
+ /** Enable normal or additive blend mode
1131
+ * @param {Boolean} [additive]
1132
+ * @param {Boolean} [useWebGL=glEnable]
1133
+ * @param {CanvasRenderingContext2D} [context=mainContext]
1134
+ * @memberof Draw */
1135
+ export function setBlendMode(additive?: boolean, useWebGL?: boolean, context?: CanvasRenderingContext2D): void;
1136
+ /** Draw text on overlay canvas in screen space
1137
+ * Automatically splits new lines into rows
1138
+ * @param {String} text
1139
+ * @param {Vector2} pos
1140
+ * @param {Number} [size]
1141
+ * @param {Color} [color=(1,1,1,1)]
1142
+ * @param {Number} [lineWidth]
1143
+ * @param {Color} [lineColor=(0,0,0,1)]
1144
+ * @param {CanvasTextAlign} [textAlign]
1145
+ * @param {String} [font=fontDefault]
1146
+ * @param {CanvasRenderingContext2D} [context=overlayContext]
1147
+ * @memberof Draw */
1148
+ export function drawTextScreen(text: string, pos: Vector2, size?: number, color?: Color, lineWidth?: number, lineColor?: Color, textAlign?: CanvasTextAlign, font?: string, context?: CanvasRenderingContext2D): void;
1149
+ /** Draw text on overlay canvas in world space
1150
+ * Automatically splits new lines into rows
1151
+ * @param {String} text
1152
+ * @param {Vector2} pos
1153
+ * @param {Number} [size]
1154
+ * @param {Color} [color=(1,1,1,1)]
1155
+ * @param {Number} [lineWidth]
1156
+ * @param {Color} [lineColor=(0,0,0,1)]
1157
+ * @param {CanvasTextAlign} [textAlign='center']
1158
+ * @param {String} [font=fontDefault]
1159
+ * @param {CanvasRenderingContext2D} [context=overlayContext]
1160
+ * @memberof Draw */
1161
+ export function drawText(text: string, pos: Vector2, size?: number, color?: Color, lineWidth?: number, lineColor?: Color, textAlign?: CanvasTextAlign, font?: string, context?: CanvasRenderingContext2D): void;
1162
+ export let engineFontImage: any;
1163
+ /**
1164
+ * Font Image Object - Draw text on a 2D canvas by using characters in an image
1165
+ * - 96 characters (from space to tilde) are stored in an image
1166
+ * - Uses a default 8x8 font if none is supplied
1167
+ * - You can also use fonts from the main tile sheet
1168
+ * @example
1169
+ * // use built in font
1170
+ * const font = new ImageFont;
1171
+ *
1172
+ * // draw text
1173
+ * font.drawTextScreen("LittleJS\nHello World!", vec2(200, 50));
1174
+ */
1175
+ export class FontImage {
1176
+ /** Create an image font
1177
+ * @param {HTMLImageElement} [image] - Image for the font, if undefined default font is used
1178
+ * @param {Vector2} [tileSize=(8,8)] - Size of the font source tiles
1179
+ * @param {Vector2} [paddingSize=(0,1)] - How much extra space to add between characters
1180
+ * @param {CanvasRenderingContext2D} [context=overlayContext] - context to draw to
1181
+ */
1182
+ constructor(image?: HTMLImageElement, tileSize?: Vector2, paddingSize?: Vector2, context?: CanvasRenderingContext2D);
1183
+ image: any;
1184
+ tileSize: Vector2;
1185
+ paddingSize: Vector2;
1186
+ context: CanvasRenderingContext2D;
1187
+ /** Draw text in world space using the image font
1188
+ * @param {String} text
1189
+ * @param {Vector2} pos
1190
+ * @param {Number} [scale=.25]
1191
+ * @param {Boolean} [center]
1192
+ */
1193
+ drawText(text: string, pos: Vector2, scale?: number, center?: boolean): void;
1194
+ /** Draw text in screen space using the image font
1195
+ * @param {String} text
1196
+ * @param {Vector2} pos
1197
+ * @param {Number} [scale]
1198
+ * @param {Boolean} [center]
1199
+ */
1200
+ drawTextScreen(text: string, pos: Vector2, scale?: number, center?: boolean): void;
1201
+ }
1202
+ /** Returns true if fullscreen mode is active
1203
+ * @return {Boolean}
1204
+ * @memberof Draw */
1205
+ export function isFullscreen(): boolean;
1206
+ /** Toggle fullsceen mode
1207
+ * @memberof Draw */
1208
+ export function toggleFullscreen(): void;
1209
+ /**
1210
+ * LittleJS WebGL Interface
1211
+ * - All webgl used by the engine is wrapped up here
1212
+ * - For normal stuff you won't need to see or call anything in this file
1213
+ * - For advanced stuff there are helper functions to create shaders, textures, etc
1214
+ * - Can be disabled with glEnable to revert to 2D canvas rendering
1215
+ * - Batches sprite rendering on GPU for incredibly fast performance
1216
+ * - Sprite transform math is done in the shader where possible
1217
+ * - Supports shadertoy style post processing shaders
1218
+ * @namespace WebGL
1219
+ */
1220
+ /** The WebGL canvas which appears above the main canvas and below the overlay canvas
1221
+ * @type {HTMLCanvasElement}
1222
+ * @memberof WebGL */
1223
+ export let glCanvas: HTMLCanvasElement;
1224
+ /** 2d context for glCanvas
1225
+ * @type {WebGL2RenderingContext}
1226
+ * @memberof WebGL */
1227
+ export let glContext: WebGL2RenderingContext;
1228
+ /** Set the WebGl texture, called automatically if using multiple textures
1229
+ * - This may also flush the gl buffer resulting in more draw calls and worse performance
1230
+ * @param {WebGLTexture} texture
1231
+ * @memberof WebGL */
1232
+ export function glSetTexture(texture: WebGLTexture): void;
1233
+ /** Compile WebGL shader of the given type, will throw errors if in debug mode
1234
+ * @param {String} source
1235
+ * @param {Number} type
1236
+ * @return {WebGLShader}
1237
+ * @memberof WebGL */
1238
+ export function glCompileShader(source: string, type: number): WebGLShader;
1239
+ /** Create WebGL program with given shaders
1240
+ * @param {String} vsSource
1241
+ * @param {String} fsSource
1242
+ * @return {WebGLProgram}
1243
+ * @memberof WebGL */
1244
+ export function glCreateProgram(vsSource: string, fsSource: string): WebGLProgram;
1245
+ /** Create WebGL texture from an image and init the texture settings
1246
+ * @param {HTMLImageElement} image
1247
+ * @return {WebGLTexture}
1248
+ * @memberof WebGL */
1249
+ export function glCreateTexture(image: HTMLImageElement): WebGLTexture;
1250
+ /** Set up a post processing shader
1251
+ * @param {String} shaderCode
1252
+ * @param {Boolean} includeOverlay
1253
+ * @memberof WebGL */
1254
+ export function glInitPostProcess(shaderCode: string, includeOverlay?: boolean): void;
1255
+ /**
1256
+ * LittleJS Input System
1257
+ * - Tracks keyboard down, pressed, and released
1258
+ * - Tracks mouse buttons, position, and wheel
1259
+ * - Tracks multiple analog gamepads
1260
+ * - Virtual gamepad for touch devices
1261
+ * @namespace Input
1262
+ */
1263
+ /** Returns true if device key is down
1264
+ * @param {String|Number} key
1265
+ * @param {Number} [device]
1266
+ * @return {Boolean}
1267
+ * @memberof Input */
1268
+ export function keyIsDown(key: string | number, device?: number): boolean;
1269
+ /** Returns true if device key was pressed this frame
1270
+ * @param {String|Number} key
1271
+ * @param {Number} [device]
1272
+ * @return {Boolean}
1273
+ * @memberof Input */
1274
+ export function keyWasPressed(key: string | number, device?: number): boolean;
1275
+ /** Returns true if device key was released this frame
1276
+ * @param {String|Number} key
1277
+ * @param {Number} [device]
1278
+ * @return {Boolean}
1279
+ * @memberof Input */
1280
+ export function keyWasReleased(key: string | number, device?: number): boolean;
1281
+ /** Clears all input
1282
+ * @memberof Input */
1283
+ export function clearInput(): void;
1284
+ /**
1285
+ * LittleJS Input System
1286
+ * - Tracks keyboard down, pressed, and released
1287
+ * - Tracks mouse buttons, position, and wheel
1288
+ * - Tracks multiple analog gamepads
1289
+ * - Virtual gamepad for touch devices
1290
+ * @namespace Input
1291
+ */
1292
+ /** Returns true if device key is down
1293
+ * @param {String|Number} key
1294
+ * @param {Number} [device]
1295
+ * @return {Boolean}
1296
+ * @memberof Input */
1297
+ export function mouseIsDown(key: string | number, device?: number): boolean;
1298
+ /** Returns true if device key was pressed this frame
1299
+ * @param {String|Number} key
1300
+ * @param {Number} [device]
1301
+ * @return {Boolean}
1302
+ * @memberof Input */
1303
+ export function mouseWasPressed(key: string | number, device?: number): boolean;
1304
+ /** Returns true if device key was released this frame
1305
+ * @param {String|Number} key
1306
+ * @param {Number} [device]
1307
+ * @return {Boolean}
1308
+ * @memberof Input */
1309
+ export function mouseWasReleased(key: string | number, device?: number): boolean;
1310
+ /** Mouse pos in world space
1311
+ * @type {Vector2}
1312
+ * @memberof Input */
1313
+ export let mousePos: Vector2;
1314
+ /** Mouse pos in screen space
1315
+ * @type {Vector2}
1316
+ * @memberof Input */
1317
+ export let mousePosScreen: Vector2;
1318
+ /** Mouse wheel delta this frame
1319
+ * @type {Number}
1320
+ * @memberof Input */
1321
+ export let mouseWheel: number;
1322
+ /** Returns true if user is using gamepad (has more recently pressed a gamepad button)
1323
+ * @type {Boolean}
1324
+ * @memberof Input */
1325
+ export let isUsingGamepad: boolean;
1326
+ /** Prevents input continuing to the default browser handling (false by default)
1327
+ * @type {Boolean}
1328
+ * @memberof Input */
1329
+ export let preventDefaultInput: boolean;
1330
+ /** Returns true if gamepad button is down
1331
+ * @param {Number} button
1332
+ * @param {Number} [gamepad]
1333
+ * @return {Boolean}
1334
+ * @memberof Input */
1335
+ export function gamepadIsDown(button: number, gamepad?: number): boolean;
1336
+ /** Returns true if gamepad button was pressed
1337
+ * @param {Number} button
1338
+ * @param {Number} [gamepad]
1339
+ * @return {Boolean}
1340
+ * @memberof Input */
1341
+ export function gamepadWasPressed(button: number, gamepad?: number): boolean;
1342
+ /** Returns true if gamepad button was released
1343
+ * @param {Number} button
1344
+ * @param {Number} [gamepad]
1345
+ * @return {Boolean}
1346
+ * @memberof Input */
1347
+ export function gamepadWasReleased(button: number, gamepad?: number): boolean;
1348
+ /** Returns gamepad stick value
1349
+ * @param {Number} stick
1350
+ * @param {Number} [gamepad]
1351
+ * @return {Vector2}
1352
+ * @memberof Input */
1353
+ export function gamepadStick(stick: number, gamepad?: number): Vector2;
1354
+ export function mouseToScreen(mousePos: any): Vector2;
1355
+ export function gamepadsUpdate(): void;
1356
+ /** Pulse the vibration hardware if it exists
1357
+ * @param {Number|Array} [pattern] - single value in ms or vibration interval array
1358
+ * @memberof Input */
1359
+ export function vibrate(pattern?: number | any[]): void;
1360
+ /** Cancel any ongoing vibration
1361
+ * @memberof Input */
1362
+ export function vibrateStop(): void;
1363
+ /** True if a touch device has been detected
1364
+ * @memberof Input */
1365
+ export const isTouchDevice: boolean;
1366
+ /**
1367
+ * LittleJS Audio System
1368
+ * - <a href=https://killedbyapixel.github.io/ZzFX/>ZzFX Sound Effects</a> - ZzFX Sound Effect Generator
1369
+ * - <a href=https://keithclark.github.io/ZzFXM/>ZzFXM Music</a> - ZzFXM Music System
1370
+ * - Caches sounds and music for fast playback
1371
+ * - Can attenuate and apply stereo panning to sounds
1372
+ * - Ability to play mp3, ogg, and wave files
1373
+ * - Speech synthesis functions
1374
+ * @namespace Audio
1375
+ */
1376
+ /**
1377
+ * Sound Object - Stores a zzfx sound for later use and can be played positionally
1378
+ *
1379
+ * <a href=https://killedbyapixel.github.io/ZzFX/>Create sounds using the ZzFX Sound Designer.</a>
1380
+ * @example
1381
+ * // create a sound
1382
+ * const sound_example = new Sound([.5,.5]);
1383
+ *
1384
+ * // play the sound
1385
+ * sound_example.play();
1386
+ */
1387
+ export class Sound {
1388
+ /** Create a sound object and cache the zzfx samples for later use
1389
+ * @param {Array} zzfxSound - Array of zzfx parameters, ex. [.5,.5]
1390
+ * @param {Number} [range=soundDefaultRange] - World space max range of sound, will not play if camera is farther away
1391
+ * @param {Number} [taper=soundDefaultTaper] - At what percentage of range should it start tapering off
1392
+ */
1393
+ constructor(zzfxSound: any[], range?: number, taper?: number);
1394
+ /** @property {Number} - World space max range of sound, will not play if camera is farther away */
1395
+ range: number;
1396
+ /** @property {Number} - At what percentage of range should it start tapering off */
1397
+ taper: number;
1398
+ /** @property {Number} - How much to randomize frequency each time sound plays */
1399
+ randomness: any;
1400
+ sampleChannels: any[][];
1401
+ sampleRate: number;
1402
+ /** Play the sound
1403
+ * @param {Vector2} [pos] - World space position to play the sound, sound is not attenuated if null
1404
+ * @param {Number} [volume] - How much to scale volume by (in addition to range fade)
1405
+ * @param {Number} [pitch] - How much to scale pitch by (also adjusted by this.randomness)
1406
+ * @param {Number} [randomnessScale] - How much to scale randomness
1407
+ * @param {Boolean} [loop] - Should the sound loop
1408
+ * @return {AudioBufferSourceNode} - The audio source node
1409
+ */
1410
+ play(pos?: Vector2, volume?: number, pitch?: number, randomnessScale?: number, loop?: boolean): AudioBufferSourceNode;
1411
+ source: AudioBufferSourceNode;
1412
+ /** Stop the last instance of this sound that was played */
1413
+ stop(): void;
1414
+ /** Get source of most recent instance of this sound that was played
1415
+ * @return {AudioBufferSourceNode}
1416
+ */
1417
+ getSource(): AudioBufferSourceNode;
1418
+ /** Play the sound as a note with a semitone offset
1419
+ * @param {Number} semitoneOffset - How many semitones to offset pitch
1420
+ * @param {Vector2} [pos] - World space position to play the sound, sound is not attenuated if null
1421
+ * @param {Number} [volume=1] - How much to scale volume by (in addition to range fade)
1422
+ * @return {AudioBufferSourceNode} - The audio source node
1423
+ */
1424
+ playNote(semitoneOffset: number, pos?: Vector2, volume?: number): AudioBufferSourceNode;
1425
+ /** Get how long this sound is in seconds
1426
+ * @return {Number} - How long the sound is in seconds (undefined if loading)
1427
+ */
1428
+ getDuration(): number;
1429
+ /** Check if sound is loading, for sounds fetched from a url
1430
+ * @return {Boolean} - True if sound is loading and not ready to play
1431
+ */
1432
+ isLoading(): boolean;
1433
+ }
1434
+ /**
1435
+ * Sound Wave Object - Stores a wave sound for later use and can be played positionally
1436
+ * - this can be used to play wave, mp3, and ogg files
1437
+ * @example
1438
+ * // create a sound
1439
+ * const sound_example = new SoundWave('sound.mp3');
1440
+ *
1441
+ * // play the sound
1442
+ * sound_example.play();
1443
+ */
1444
+ export class SoundWave extends Sound {
1445
+ /** Create a sound object and cache the wave file for later use
1446
+ * @param {String} filename - Filename of audio file to load
1447
+ * @param {Number} [randomness] - How much to randomize frequency each time sound plays
1448
+ * @param {Number} [range=soundDefaultRange] - World space max range of sound, will not play if camera is farther away
1449
+ * @param {Number} [taper=soundDefaultTaper] - At what percentage of range should it start tapering off
1450
+ */
1451
+ constructor(filename: string, randomness?: number, range?: number, taper?: number);
1452
+ randomness: number;
1453
+ }
1454
+ /**
1455
+ * Music Object - Stores a zzfx music track for later use
1456
+ *
1457
+ * <a href=https://keithclark.github.io/ZzFXM/>Create music with the ZzFXM tracker.</a>
1458
+ * @example
1459
+ * // create some music
1460
+ * const music_example = new Music(
1461
+ * [
1462
+ * [ // instruments
1463
+ * [,0,400] // simple note
1464
+ * ],
1465
+ * [ // patterns
1466
+ * [ // pattern 1
1467
+ * [ // channel 0
1468
+ * 0, -1, // instrument 0, left speaker
1469
+ * 1, 0, 9, 1 // channel notes
1470
+ * ],
1471
+ * [ // channel 1
1472
+ * 0, 1, // instrument 1, right speaker
1473
+ * 0, 12, 17, -1 // channel notes
1474
+ * ]
1475
+ * ],
1476
+ * ],
1477
+ * [0, 0, 0, 0], // sequence, play pattern 0 four times
1478
+ * 90 // BPM
1479
+ * ]);
1480
+ *
1481
+ * // play the music
1482
+ * music_example.play();
1483
+ */
1484
+ export class Music extends Sound {
1485
+ /** Create a music object and cache the zzfx music samples for later use
1486
+ * @param {[Array, Array, Array, Number]} zzfxMusic - Array of zzfx music parameters
1487
+ */
1488
+ constructor(zzfxMusic: [any[], any[], any[], number]);
1489
+ sampleChannels: any[];
1490
+ /** Play the music
1491
+ * @param {Number} [volume=1] - How much to scale volume by
1492
+ * @param {Boolean} [loop=1] - True if the music should loop
1493
+ * @return {AudioBufferSourceNode} - The audio source node
1494
+ */
1495
+ playMusic(volume?: number, loop?: boolean): AudioBufferSourceNode;
1496
+ }
1497
+ /** Play an mp3, ogg, or wav audio from a local file or url
1498
+ * @param {String} url - Location of sound file to play
1499
+ * @param {Number} [volume] - How much to scale volume by
1500
+ * @param {Boolean} [loop] - True if the music should loop
1501
+ * @return {HTMLAudioElement} - The audio element for this sound
1502
+ * @memberof Audio */
1503
+ export function playAudioFile(url: string, volume?: number, loop?: boolean): HTMLAudioElement;
1504
+ /** Speak text with passed in settings
1505
+ * @param {String} text - The text to speak
1506
+ * @param {String} [language] - The language/accent to use (examples: en, it, ru, ja, zh)
1507
+ * @param {Number} [volume] - How much to scale volume by
1508
+ * @param {Number} [rate] - How quickly to speak
1509
+ * @param {Number} [pitch] - How much to change the pitch by
1510
+ * @return {SpeechSynthesisUtterance} - The utterance that was spoken
1511
+ * @memberof Audio */
1512
+ export function speak(text: string, language?: string, volume?: number, rate?: number, pitch?: number): SpeechSynthesisUtterance;
1513
+ /** Stop all queued speech
1514
+ * @memberof Audio */
1515
+ export function speakStop(): void;
1516
+ /** Get frequency of a note on a musical scale
1517
+ * @param {Number} semitoneOffset - How many semitones away from the root note
1518
+ * @param {Number} [rootFrequency=220] - Frequency at semitone offset 0
1519
+ * @return {Number} - The frequency of the note
1520
+ * @memberof Audio */
1521
+ export function getNoteFrequency(semitoneOffset: number, rootFrequency?: number): number;
1522
+ /** Audio context used by the engine
1523
+ * @memberof Audio */
1524
+ export let audioContext: any;
1525
+ /** Play cached audio samples with given settings
1526
+ * @param {Array} sampleChannels - Array of arrays of samples to play (for stereo playback)
1527
+ * @param {Number} [volume] - How much to scale volume by
1528
+ * @param {Number} [rate] - The playback rate to use
1529
+ * @param {Number} [pan] - How much to apply stereo panning
1530
+ * @param {Boolean} [loop] - True if the sound should loop when it reaches the end
1531
+ * @param {Number} [sampleRate=44100] - Sample rate for the sound
1532
+ * @return {AudioBufferSourceNode} - The audio node of the sound played
1533
+ * @memberof Audio */
1534
+ export function playSamples(sampleChannels: any[], volume?: number, rate?: number, pan?: number, loop?: boolean, sampleRate?: number): AudioBufferSourceNode;
1535
+ /** Generate and play a ZzFX sound
1536
+ *
1537
+ * <a href=https://killedbyapixel.github.io/ZzFX/>Create sounds using the ZzFX Sound Designer.</a>
1538
+ * @param {Array} zzfxSound - Array of ZzFX parameters, ex. [.5,.5]
1539
+ * @return {AudioBufferSourceNode} - The audio node of the sound played
1540
+ * @memberof Audio */
1541
+ export function zzfx(...zzfxSound: any[]): AudioBufferSourceNode;
1542
+ /**
1543
+ * LittleJS Object System
1544
+ */
1545
+ /**
1546
+ * LittleJS Object Base Object Class
1547
+ * - Top level object class used by the engine
1548
+ * - Automatically adds self to object list
1549
+ * - Will be updated and rendered each frame
1550
+ * - Renders as a sprite from a tilesheet by default
1551
+ * - Can have color and addtive color applied
1552
+ * - 2D Physics and collision system
1553
+ * - Sorted by renderOrder
1554
+ * - Objects can have children attached
1555
+ * - Parents are updated before children, and set child transform
1556
+ * - Call destroy() to get rid of objects
1557
+ *
1558
+ * The physics system used by objects is simple and fast with some caveats...
1559
+ * - Collision uses the axis aligned size, the object's rotation angle is only for rendering
1560
+ * - Objects are guaranteed to not intersect tile collision from physics
1561
+ * - If an object starts or is moved inside tile collision, it will not collide with that tile
1562
+ * - Collision for objects can be set to be solid to block other objects
1563
+ * - Objects may get pushed into overlapping other solid objects, if so they will push away
1564
+ * - Solid objects are more performance intensive and should be used sparingly
1565
+ * @example
1566
+ * // create an engine object, normally you would first extend the class with your own
1567
+ * const pos = vec2(2,3);
1568
+ * const object = new EngineObject(pos);
1569
+ */
1570
+ export class EngineObject {
1571
+ /** Create an engine object and adds it to the list of objects
1572
+ * @param {Vector2} [pos=(0,0)] - World space position of the object
1573
+ * @param {Vector2} [size=(1,1)] - World space size of the object
1574
+ * @param {TileInfo} [tileInfo] - Tile info to render object (undefined is untextured)
1575
+ * @param {Number} [angle] - Angle the object is rotated by
1576
+ * @param {Color} [color=(1,1,1,1)] - Color to apply to tile when rendered
1577
+ * @param {Number} [renderOrder] - Objects sorted by renderOrder before being rendered
1578
+ */
1579
+ constructor(pos?: Vector2, size?: Vector2, tileInfo?: TileInfo, angle?: number, color?: Color, renderOrder?: number);
1580
+ /** @property {Vector2} - World space position of the object */
1581
+ pos: Vector2;
1582
+ /** @property {Vector2} - World space width and height of the object */
1583
+ size: Vector2;
1584
+ /** @property {Vector2} - Size of object used for drawing, uses size if not set */
1585
+ drawSize: any;
1586
+ /** @property {TileInfo} - Tile info to render object (undefined is untextured) */
1587
+ tileInfo: TileInfo;
1588
+ /** @property {Number} - Angle to rotate the object */
1589
+ angle: number;
1590
+ /** @property {Color} - Color to apply when rendered */
1591
+ color: Color;
1592
+ /** @property {Color} - Additive color to apply when rendered */
1593
+ additiveColor: any;
1594
+ /** @property {Boolean} - Should it flip along y axis when rendered */
1595
+ mirror: boolean;
1596
+ /** @property {Number} [mass=objectDefaultMass] - How heavy the object is, static if 0 */
1597
+ mass: number;
1598
+ /** @property {Number} [damping=objectDefaultDamping] - How much to slow down velocity each frame (0-1) */
1599
+ damping: number;
1600
+ /** @property {Number} [angleDamping=objectDefaultAngleDamping] - How much to slow down rotation each frame (0-1) */
1601
+ angleDamping: number;
1602
+ /** @property {Number} [elasticity=objectDefaultElasticity] - How bouncy the object is when colliding (0-1) */
1603
+ elasticity: number;
1604
+ /** @property {Number} [friction=objectDefaultFriction] - How much friction to apply when sliding (0-1) */
1605
+ friction: number;
1606
+ /** @property {Number} - How much to scale gravity by for this object */
1607
+ gravityScale: number;
1608
+ /** @property {Number} - Objects are sorted by render order */
1609
+ renderOrder: number;
1610
+ /** @property {Vector2} - Velocity of the object */
1611
+ velocity: Vector2;
1612
+ /** @property {Number} - Angular velocity of the object */
1613
+ angleVelocity: number;
1614
+ /** @property {Number} - Track when object was created */
1615
+ spawnTime: number;
1616
+ /** @property {Array} - List of children of this object */
1617
+ children: any[];
1618
+ /** @property {EngineObject} - Parent of object if in local space */
1619
+ parent: any;
1620
+ /** @property {Vector2} - Local position if child */
1621
+ localPos: Vector2;
1622
+ /** @property {Number} - Local angle if child */
1623
+ localAngle: number;
1624
+ /** @property {Boolean} - Object collides with the tile collision */
1625
+ collideTiles: boolean;
1626
+ /** @property {Boolean} - Object collides with solid objects */
1627
+ collideSolidObjects: boolean;
1628
+ /** @property {Boolean} - Object collides with and blocks other objects */
1629
+ isSolid: boolean;
1630
+ /** Update the object transform and physics, called automatically by engine once each frame */
1631
+ update(): void;
1632
+ groundObject: any;
1633
+ /** Render the object, draws a tile by default, automatically called each frame, sorted by renderOrder */
1634
+ render(): void;
1635
+ /** Destroy this object, destroy it's children, detach it's parent, and mark it for removal */
1636
+ destroy(): void;
1637
+ destroyed: number;
1638
+ /** Called to check if a tile collision should be resolved
1639
+ * @param {Number} tileData - the value of the tile at the position
1640
+ * @param {Vector2} pos - tile where the collision occured
1641
+ * @return {Boolean} - true if the collision should be resolved */
1642
+ collideWithTile(tileData: number, pos: Vector2): boolean;
1643
+ /** Called to check if a tile raycast hit
1644
+ * @param {Number} tileData - the value of the tile at the position
1645
+ * @param {Vector2} pos - tile where the raycast is
1646
+ * @return {Boolean} - true if the raycast should hit */
1647
+ collideWithTileRaycast(tileData: number, pos: Vector2): boolean;
1648
+ /** Called to check if a object collision should be resolved
1649
+ * @param {EngineObject} object - the object to test against
1650
+ * @return {Boolean} - true if the collision should be resolved
1651
+ */
1652
+ collideWithObject(object: EngineObject): boolean;
1653
+ /** How long since the object was created
1654
+ * @return {Number} */
1655
+ getAliveTime(): number;
1656
+ /** Apply acceleration to this object (adjust velocity, not affected by mass)
1657
+ * @param {Vector2} acceleration */
1658
+ applyAcceleration(acceleration: Vector2): void;
1659
+ /** Apply force to this object (adjust velocity, affected by mass)
1660
+ * @param {Vector2} force */
1661
+ applyForce(force: Vector2): void;
1662
+ /** Get the direction of the mirror
1663
+ * @return {Number} -1 if this.mirror is true, or 1 if not mirrored */
1664
+ getMirrorSign(): number;
1665
+ /** Attaches a child to this with a given local transform
1666
+ * @param {EngineObject} child
1667
+ * @param {Vector2} [localPos=(0,0)]
1668
+ * @param {Number} [localAngle] */
1669
+ addChild(child: EngineObject, localPos?: Vector2, localAngle?: number): void;
1670
+ /** Removes a child from this one
1671
+ * @param {EngineObject} child */
1672
+ removeChild(child: EngineObject): void;
1673
+ /** Set how this object collides
1674
+ * @param {Boolean} [collideSolidObjects] - Does it collide with solid objects
1675
+ * @param {Boolean} [isSolid] - Does it collide with and block other objects (expensive in large numbers)
1676
+ * @param {Boolean} [collideTiles] - Does it collide with the tile collision */
1677
+ setCollision(collideSolidObjects?: boolean, isSolid?: boolean, collideTiles?: boolean): void;
1678
+ /** Returns string containg info about this object for debugging
1679
+ * @return {String} */
1680
+ toString(): string;
1681
+ }
1682
+ /**
1683
+ * LittleJS Tile Layer System
1684
+ * - Caches arrays of tiles to off screen canvas for fast rendering
1685
+ * - Unlimted numbers of layers, allocates canvases as needed
1686
+ * - Interfaces with EngineObject for collision
1687
+ * - Collision layer is separate from visible layers
1688
+ * - It is recommended to have a visible layer that matches the collision
1689
+ * - Tile layers can be drawn to using their context with canvas2d
1690
+ * - Drawn directly to the main canvas without using WebGL
1691
+ * @namespace TileCollision
1692
+ */
1693
+ /** The tile collision layer array, use setTileCollisionData and getTileCollisionData to access
1694
+ * @type {Array}
1695
+ * @memberof TileCollision */
1696
+ export let tileCollision: any[];
1697
+ /** Size of the tile collision layer
1698
+ * @type {Vector2}
1699
+ * @memberof TileCollision */
1700
+ export let tileCollisionSize: Vector2;
1701
+ /** Clear and initialize tile collision
1702
+ * @param {Vector2} size
1703
+ * @memberof TileCollision */
1704
+ export function initTileCollision(size: Vector2): void;
1705
+ /** Set tile collision data
1706
+ * @param {Vector2} pos
1707
+ * @param {Number} [data]
1708
+ * @memberof TileCollision */
1709
+ export function setTileCollisionData(pos: Vector2, data?: number): void;
1710
+ /** Get tile collision data
1711
+ * @param {Vector2} pos
1712
+ * @return {Number}
1713
+ * @memberof TileCollision */
1714
+ export function getTileCollisionData(pos: Vector2): number;
1715
+ /** Check if collision with another object should occur
1716
+ * @param {Vector2} pos
1717
+ * @param {Vector2} [size=(1,1)]
1718
+ * @param {EngineObject} [object]
1719
+ * @return {Boolean}
1720
+ * @memberof TileCollision */
1721
+ export function tileCollisionTest(pos: Vector2, size?: Vector2, object?: EngineObject): boolean;
1722
+ /** Return the center of tile if any that is hit (does not return the exact intersection)
1723
+ * @param {Vector2} posStart
1724
+ * @param {Vector2} posEnd
1725
+ * @param {EngineObject} [object]
1726
+ * @return {Vector2}
1727
+ * @memberof TileCollision */
1728
+ export function tileCollisionRaycast(posStart: Vector2, posEnd: Vector2, object?: EngineObject): Vector2;
1729
+ /**
1730
+ * Tile layer data object stores info about how to render a tile
1731
+ * @example
1732
+ * // create tile layer data with tile index 0 and random orientation and color
1733
+ * const tileIndex = 0;
1734
+ * const direction = randInt(4)
1735
+ * const mirror = randInt(2);
1736
+ * const color = randColor();
1737
+ * const data = new TileLayerData(tileIndex, direction, mirror, color);
1738
+ */
1739
+ export class TileLayerData {
1740
+ /** Create a tile layer data object, one for each tile in a TileLayer
1741
+ * @param {Number} [tile] - The tile to use, untextured if undefined
1742
+ * @param {Number} [direction] - Integer direction of tile, in 90 degree increments
1743
+ * @param {Boolean} [mirror] - If the tile should be mirrored along the x axis
1744
+ * @param {Color} [color] - Color of the tile */
1745
+ constructor(tile?: number, direction?: number, mirror?: boolean, color?: Color);
1746
+ /** @property {Number} - The tile to use, untextured if undefined */
1747
+ tile: number;
1748
+ /** @property {Number} - Integer direction of tile, in 90 degree increments */
1749
+ direction: number;
1750
+ /** @property {Boolean} - If the tile should be mirrored along the x axis */
1751
+ mirror: boolean;
1752
+ /** @property {Color} - Color of the tile */
1753
+ color: Color;
1754
+ /** Set this tile to clear, it will not be rendered */
1755
+ clear(): void;
1756
+ }
1757
+ /**
1758
+ * Tile Layer - cached rendering system for tile layers
1759
+ * - Each Tile layer is rendered to an off screen canvas
1760
+ * - To allow dynamic modifications, layers are rendered using canvas 2d
1761
+ * - Some devices like mobile phones are limited to 4k texture resolution
1762
+ * - So with 16x16 tiles this limits layers to 256x256 on mobile devices
1763
+ * @extends EngineObject
1764
+ * @example
1765
+ * // create tile collision and visible tile layer
1766
+ * initTileCollision(vec2(200,100));
1767
+ * const tileLayer = new TileLayer();
1768
+ */
1769
+ export class TileLayer extends EngineObject {
1770
+ /** Create a tile layer object
1771
+ * @param {Vector2} [position=(0,0)] - World space position
1772
+ * @param {Vector2} [size=tileCollisionSize] - World space size
1773
+ * @param {TileInfo} [tileInfo] - Tile info for layer
1774
+ * @param {Vector2} [scale=(1,1)] - How much to scale this layer when rendered
1775
+ * @param {Number} [renderOrder] - Objects are sorted by renderOrder
1776
+ */
1777
+ constructor(position?: Vector2, size?: Vector2, tileInfo?: TileInfo, scale?: Vector2, renderOrder?: number);
1778
+ /** @property {HTMLCanvasElement} - The canvas used by this tile layer */
1779
+ canvas: HTMLCanvasElement;
1780
+ /** @property {CanvasRenderingContext2D} - The 2D canvas context used by this tile layer */
1781
+ context: CanvasRenderingContext2D;
1782
+ /** @property {Vector2} - How much to scale this layer when rendered */
1783
+ scale: Vector2;
1784
+ /** @property {Boolean} - If true this layer will render to overlay canvas and appear above all objects */
1785
+ isOverlay: boolean;
1786
+ data: TileLayerData[];
1787
+ /** Set data at a given position in the array
1788
+ * @param {Vector2} layerPos - Local position in array
1789
+ * @param {TileLayerData} data - Data to set
1790
+ * @param {Boolean} [redraw] - Force the tile to redraw if true */
1791
+ setData(layerPos: Vector2, data: TileLayerData, redraw?: boolean): void;
1792
+ /** Get data at a given position in the array
1793
+ * @param {Vector2} layerPos - Local position in array
1794
+ * @return {TileLayerData} */
1795
+ getData(layerPos: Vector2): TileLayerData;
1796
+ /** Draw all the tile data to an offscreen canvas
1797
+ * - This may be slow in some browsers but only needs to be done once */
1798
+ redraw(): void;
1799
+ /** Call to start the redraw process
1800
+ * - This can be used to manually update small parts of the level
1801
+ * @param {Boolean} [clear] - Should it clear the canvas before drawing */
1802
+ redrawStart(clear?: boolean): void;
1803
+ /** @type {[HTMLCanvasElement, CanvasRenderingContext2D, Vector2, Vector2, number]} */
1804
+ savedRenderSettings: [HTMLCanvasElement, CanvasRenderingContext2D, Vector2, Vector2, number];
1805
+ /** Call to end the redraw process */
1806
+ redrawEnd(): void;
1807
+ /** Draw the tile at a given position in the tile grid
1808
+ * This can be used to clear out tiles when they are destroyed
1809
+ * Tiles can also be redrawn if isinde a redrawStart/End block
1810
+ * @param {Vector2} layerPos
1811
+ * @param {Boolean} [clear] - should the old tile be cleared out
1812
+ */
1813
+ drawTileData(layerPos: Vector2, clear?: boolean): void;
1814
+ /** Draw directly to the 2D canvas in world space (bipass webgl)
1815
+ * @param {Vector2} pos
1816
+ * @param {Vector2} size
1817
+ * @param {Number} angle
1818
+ * @param {Boolean} mirror
1819
+ * @param {Function} drawFunction */
1820
+ drawCanvas2D(pos: Vector2, size: Vector2, angle: number, mirror: boolean, drawFunction: Function): void;
1821
+ /** Draw a tile directly onto the layer canvas in world space
1822
+ * @param {Vector2} pos
1823
+ * @param {Vector2} [size=(1,1)]
1824
+ * @param {TileInfo} [tileInfo]
1825
+ * @param {Color} [color=(1,1,1,1)]
1826
+ * @param {Number} [angle=0]
1827
+ * @param {Boolean} [mirror=0] */
1828
+ drawTile(pos: Vector2, size?: Vector2, tileInfo?: TileInfo, color?: Color, angle?: number, mirror?: boolean): void;
1829
+ /** Draw a rectangle directly onto the layer canvas in world space
1830
+ * @param {Vector2} pos
1831
+ * @param {Vector2} [size=(1,1)]
1832
+ * @param {Color} [color=(1,1,1,1)]
1833
+ * @param {Number} [angle=0] */
1834
+ drawRect(pos: Vector2, size?: Vector2, color?: Color, angle?: number): void;
1835
+ }
1836
+ /**
1837
+ * LittleJS Particle System
1838
+ */
1839
+ /**
1840
+ * Particle Emitter - Spawns particles with the given settings
1841
+ * @extends EngineObject
1842
+ * @example
1843
+ * // create a particle emitter
1844
+ * let pos = vec2(2,3);
1845
+ * let particleEmiter = new ParticleEmitter
1846
+ * (
1847
+ * pos, 0, 1, 0, 500, PI, // pos, angle, emitSize, emitTime, emitRate, emiteCone
1848
+ * tile(0, 16), // tileInfo
1849
+ * new Color(1,1,1), new Color(0,0,0), // colorStartA, colorStartB
1850
+ * new Color(1,1,1,0), new Color(0,0,0,0), // colorEndA, colorEndB
1851
+ * 2, .2, .2, .1, .05, // particleTime, sizeStart, sizeEnd, particleSpeed, particleAngleSpeed
1852
+ * .99, 1, 1, PI, .05, // damping, angleDamping, gravityScale, particleCone, fadeRate,
1853
+ * .5, 1 // randomness, collide, additive, randomColorLinear, renderOrder
1854
+ * );
1855
+ */
1856
+ export class ParticleEmitter extends EngineObject {
1857
+ /** Create a particle system with the given settings
1858
+ * @param {Vector2} position - World space position of the emitter
1859
+ * @param {Number} [angle] - Angle to emit the particles
1860
+ * @param {Number|Vector2} [emitSize] - World space size of the emitter (float for circle diameter, vec2 for rect)
1861
+ * @param {Number} [emitTime] - How long to stay alive (0 is forever)
1862
+ * @param {Number} [emitRate] - How many particles per second to spawn, does not emit if 0
1863
+ * @param {Number} [emitConeAngle=PI] - Local angle to apply velocity to particles from emitter
1864
+ * @param {TileInfo} [tileInfo] - Tile info to render particles (undefined is untextured)
1865
+ * @param {Color} [colorStartA=(1,1,1,1)] - Color at start of life 1, randomized between start colors
1866
+ * @param {Color} [colorStartB=(1,1,1,1)] - Color at start of life 2, randomized between start colors
1867
+ * @param {Color} [colorEndA=(1,1,1,0)] - Color at end of life 1, randomized between end colors
1868
+ * @param {Color} [colorEndB=(1,1,1,0)] - Color at end of life 2, randomized between end colors
1869
+ * @param {Number} [particleTime] - How long particles live
1870
+ * @param {Number} [sizeStart] - How big are particles at start
1871
+ * @param {Number} [sizeEnd] - How big are particles at end
1872
+ * @param {Number} [speed] - How fast are particles when spawned
1873
+ * @param {Number} [angleSpeed] - How fast are particles rotating
1874
+ * @param {Number} [damping] - How much to dampen particle speed
1875
+ * @param {Number} [angleDamping] - How much to dampen particle angular speed
1876
+ * @param {Number} [gravityScale] - How much gravity effect particles
1877
+ * @param {Number} [particleConeAngle] - Cone for start particle angle
1878
+ * @param {Number} [fadeRate] - How quick to fade particles at start/end in percent of life
1879
+ * @param {Number} [randomness] - Apply extra randomness percent
1880
+ * @param {Boolean} [collideTiles] - Do particles collide against tiles
1881
+ * @param {Boolean} [additive] - Should particles use addtive blend
1882
+ * @param {Boolean} [randomColorLinear] - Should color be randomized linearly or across each component
1883
+ * @param {Number} [renderOrder] - Render order for particles (additive is above other stuff by default)
1884
+ * @param {Boolean} [localSpace] - Should it be in local space of emitter (world space is default)
1885
+ */
1886
+ constructor(position: Vector2, angle?: number, emitSize?: number | Vector2, emitTime?: number, emitRate?: number, emitConeAngle?: number, tileInfo?: TileInfo, 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);
1887
+ /** @property {Number|Vector2} - World space size of the emitter (float for circle diameter, vec2 for rect) */
1888
+ emitSize: number | Vector2;
1889
+ /** @property {Number} - How long to stay alive (0 is forever) */
1890
+ emitTime: number;
1891
+ /** @property {Number} - How many particles per second to spawn, does not emit if 0 */
1892
+ emitRate: number;
1893
+ /** @property {Number} - Local angle to apply velocity to particles from emitter */
1894
+ emitConeAngle: number;
1895
+ /** @property {Color} - Color at start of life 1, randomized between start colors */
1896
+ colorStartA: Color;
1897
+ /** @property {Color} - Color at start of life 2, randomized between start colors */
1898
+ colorStartB: Color;
1899
+ /** @property {Color} - Color at end of life 1, randomized between end colors */
1900
+ colorEndA: Color;
1901
+ /** @property {Color} - Color at end of life 2, randomized between end colors */
1902
+ colorEndB: Color;
1903
+ /** @property {Boolean} - Should color be randomized linearly or across each component */
1904
+ randomColorLinear: boolean;
1905
+ /** @property {Number} - How long particles live */
1906
+ particleTime: number;
1907
+ /** @property {Number} - How big are particles at start */
1908
+ sizeStart: number;
1909
+ /** @property {Number} - How big are particles at end */
1910
+ sizeEnd: number;
1911
+ /** @property {Number} - How fast are particles when spawned */
1912
+ speed: number;
1913
+ /** @property {Number} - How fast are particles rotating */
1914
+ angleSpeed: number;
1915
+ /** @property {Number} - Cone for start particle angle */
1916
+ particleConeAngle: number;
1917
+ /** @property {Number} - How quick to fade in particles at start/end in percent of life */
1918
+ fadeRate: number;
1919
+ /** @property {Number} - Apply extra randomness percent */
1920
+ randomness: number;
1921
+ /** @property {Boolean} - Should particles use addtive blend */
1922
+ additive: boolean;
1923
+ /** @property {Boolean} - Should it be in local space of emitter */
1924
+ localSpace: boolean;
1925
+ /** @property {Number} - If non zero the partile is drawn as a trail, stretched in the drection of velocity */
1926
+ trailScale: number;
1927
+ /** @property {Function} - Callback when particle is destroyed */
1928
+ particleDestroyCallback: any;
1929
+ /** @property {Function} - Callback when particle is created */
1930
+ particleCreateCallback: any;
1931
+ /** @property {Number} - Track particle emit time */
1932
+ emitTimeBuffer: number;
1933
+ /** Spawn one particle
1934
+ * @return {Particle} */
1935
+ emitParticle(): Particle;
1936
+ }
1937
+ /**
1938
+ * Particle Object - Created automatically by Particle Emitters
1939
+ * @extends EngineObject
1940
+ */
1941
+ export class Particle extends EngineObject {
1942
+ /**
1943
+ * Create a particle with the given shis.colorStart = undefined;ettings
1944
+ * @param {Vector2} position - World space position of the particle
1945
+ * @param {TileInfo} [tileInfo] - Tile info to render particles
1946
+ * @param {Number} [angle] - Angle to rotate the particle
1947
+ * @param {Color} [colorStart] - Color at start of life
1948
+ * @param {Color} [colorEnd] - Color at end of life
1949
+ * @param {Number} [lifeTime] - How long to live for
1950
+ * @param {Number} [sizeStart] - Angle to rotate the particle
1951
+ * @param {Number} [sizeEnd] - Angle to rotate the particle
1952
+ * @param {Number} [fadeRate] - Angle to rotate the particle
1953
+ * @param {Boolean} [additive] - Angle to rotate the particle
1954
+ * @param {Number} [trailScale] - If a trail, how long to make it
1955
+ * @param {ParticleEmitter} [localSpaceEmitter] - Parent emitter if local space
1956
+ * @param {Function} [destroyCallback] - Called when particle dies
1957
+ */
1958
+ constructor(position: Vector2, tileInfo?: TileInfo, angle?: number, colorStart?: Color, colorEnd?: Color, lifeTime?: number, sizeStart?: number, sizeEnd?: number, fadeRate?: number, additive?: boolean, trailScale?: number, localSpaceEmitter?: ParticleEmitter, destroyCallback?: Function);
1959
+ /** @property {Color} - Color at start of life */
1960
+ colorStart: Color;
1961
+ /** @property {Color} - Calculated change in color */
1962
+ colorEndDelta: Color;
1963
+ /** @property {Number} - How long to live for */
1964
+ lifeTime: number;
1965
+ /** @property {Number} - Size at start of life */
1966
+ sizeStart: number;
1967
+ /** @property {Number} - Calculated change in size */
1968
+ sizeEndDelta: number;
1969
+ /** @property {Number} - How quick to fade in/out */
1970
+ fadeRate: number;
1971
+ /** @property {Boolean} - Is it additive */
1972
+ additive: boolean;
1973
+ /** @property {Number} - If a trail, how long to make it */
1974
+ trailScale: number;
1975
+ /** @property {ParticleEmitter} - Parent emitter if local space */
1976
+ localSpaceEmitter: ParticleEmitter;
1977
+ /** @property {Function} - Called when particle dies */
1978
+ destroyCallback: Function;
1979
+ }
1980
+ /**
1981
+ * LittleJS Medal System
1982
+ * - Tracks and displays medals
1983
+ * - Saves medals to local storage
1984
+ * - Newgrounds integration
1985
+ * @namespace Medals
1986
+ */
1987
+ /** List of all medals
1988
+ * @type {Array}
1989
+ * @memberof Medals */
1990
+ export const medals: any[];
1991
+ /** Set to stop medals from being unlockable (like if cheats are enabled)
1992
+ * @type {Boolean}
1993
+ * @default
1994
+ * @memberof Settings */
1995
+ export let medalsPreventUnlock: boolean;
1996
+ /** Initialize medals with a save name used for storage
1997
+ * - Call this after creating all medals
1998
+ * - Checks if medals are unlocked
1999
+ * @param {String} saveName
2000
+ * @memberof Medals */
2001
+ export function medalsInit(saveName: string): void;
2002
+ /** This can used to enable Newgrounds functionality
2003
+ * @param {Number} app_id - The newgrounds App ID
2004
+ * @param {String} [cipher] - The encryption Key (AES-128/Base64)
2005
+ * @param {Object} [cryptoJS] - An instance of CryptoJS, if there is a cipher
2006
+ * @memberof Medals */
2007
+ export function newgroundsInit(app_id: number, cipher?: string, cryptoJS?: any): void;
2008
+ /**
2009
+ * Medal - Tracks an unlockable medal
2010
+ * @example
2011
+ * // create a medal
2012
+ * const medal_example = new Medal(0, 'Example Medal', 'More info about the medal goes here.', '🎖️');
2013
+ *
2014
+ * // initialize medals
2015
+ * medalsInit('Example Game');
2016
+ *
2017
+ * // unlock the medal
2018
+ * medal_example.unlock();
2019
+ */
2020
+ export class Medal {
2021
+ /** Create a medal object and adds it to the list of medals
2022
+ * @param {Number} id - The unique identifier of the medal
2023
+ * @param {String} name - Name of the medal
2024
+ * @param {String} [description] - Description of the medal
2025
+ * @param {String} [icon] - Icon for the medal
2026
+ * @param {String} [src] - Image location for the medal
2027
+ */
2028
+ constructor(id: number, name: string, description?: string, icon?: string, src?: string);
2029
+ id: number;
2030
+ name: string;
2031
+ description: string;
2032
+ icon: string;
2033
+ image: HTMLImageElement;
2034
+ /** Unlocks a medal if not already unlocked */
2035
+ unlock(): void;
2036
+ unlocked: number;
2037
+ /** Render a medal
2038
+ * @param {Number} [hidePercent] - How much to slide the medal off screen
2039
+ */
2040
+ render(hidePercent?: number): void;
2041
+ /** Render the icon for a medal
2042
+ * @param {Vector2} pos - Screen space position
2043
+ * @param {Number} [size=medalDisplayIconSize] - Screen space size
2044
+ */
2045
+ renderIcon(pos: Vector2, size?: number): void;
2046
+ storageKey(): string;
2047
+ }
2048
+ /**
2049
+ * Newgrounds API wrapper object
2050
+ * @example
2051
+ * // create a newgrounds object, replace the app id with your own
2052
+ * const app_id = '53123:1ZuSTQ9l';
2053
+ * newgrounds = new Newgrounds(app_id);
2054
+ */
2055
+ export class Newgrounds {
2056
+ /** Create a newgrounds object
2057
+ * @param {Number} app_id - The newgrounds App ID
2058
+ * @param {String} [cipher] - The encryption Key (AES-128/Base64)
2059
+ * @param {Object} [cryptoJS] - An instance of CryptoJS, if there is a cipher */
2060
+ constructor(app_id: number, cipher?: string, cryptoJS?: any);
2061
+ app_id: number;
2062
+ cipher: string;
2063
+ cryptoJS: any;
2064
+ host: string;
2065
+ session_id: string;
2066
+ medals: any;
2067
+ scoreboards: any;
2068
+ /** Send message to unlock a medal by id
2069
+ * @param {Number} id - The medal id */
2070
+ unlockMedal(id: number): any;
2071
+ /** Send message to post score
2072
+ * @param {Number} id - The scoreboard id
2073
+ * @param {Number} value - The score value */
2074
+ postScore(id: number, value: number): any;
2075
+ /** Get scores from a scoreboard
2076
+ * @param {Number} id - The scoreboard id
2077
+ * @param {String} [user] - A user's id or name
2078
+ * @param {Number} [social] - If true, only social scores will be loaded
2079
+ * @param {Number} [skip] - Number of scores to skip before start
2080
+ * @param {Number} [limit] - Number of scores to include in the list
2081
+ * @return {Object} - The response JSON object
2082
+ */
2083
+ getScores(id: number, user?: string, social?: number, skip?: number, limit?: number): any;
2084
+ /** Send message to log a view */
2085
+ logView(): any;
2086
+ /** Send a message to call a component of the Newgrounds API
2087
+ * @param {String} component - Name of the component
2088
+ * @param {Object} [parameters] - Parameters to use for call
2089
+ * @param {Boolean} [async] - If true, don't wait for response before continuing
2090
+ * @return {Object} - The response JSON object
2091
+ */
2092
+ call(component: string, parameters?: any, async?: boolean): any;
2093
+ }
2094
+ }