-
Notifications
You must be signed in to change notification settings - Fork 185
/
littlejs.d.ts
2115 lines (2115 loc) · 98 KB
/
littlejs.d.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
declare module "littlejsengine" {
/**
* LittleJS - The Tiny Fast JavaScript Game Engine
* MIT License - Copyright 2021 Frank Force
*
* Engine Features
* - Object oriented system with base class engine object
* - Base class object handles update, physics, collision, rendering, etc
* - Engine helper classes and functions like Vector2, Color, and Timer
* - Super fast rendering system for tile sheets
* - Sound effects audio with zzfx and music with zzfxm
* - Input processing system with gamepad and touchscreen support
* - Tile layer rendering and collision system
* - Particle effect system
* - Medal system tracks and displays achievements
* - Debug tools and debug rendering system
* - Post processing effects
* - Call engineInit() to start it up!
* @namespace Engine
*/
/** Name of engine
* @type {String}
* @default
* @memberof Engine */
export const engineName: string;
/** Version of engine
* @type {String}
* @default
* @memberof Engine */
export const engineVersion: string;
/** Frames per second to update
* @type {Number}
* @default
* @memberof Engine */
export const frameRate: number;
/** How many seconds each frame lasts, engine uses a fixed time step
* @type {Number}
* @default 1/60
* @memberof Engine */
export const timeDelta: number;
/** Array containing all engine objects
* @type {Array}
* @memberof Engine */
export let engineObjects: any[];
/** Current update frame, used to calculate time
* @type {Number}
* @memberof Engine */
export let frame: number;
/** Current engine time since start in seconds
* @type {Number}
* @memberof Engine */
export let time: number;
/** Actual clock time since start in seconds (not affected by pause or frame rate clamping)
* @type {Number}
* @memberof Engine */
export let timeReal: number;
/** Is the game paused? Causes time and objects to not be updated
* @type {Boolean}
* @default false
* @memberof Engine */
export let paused: boolean;
/** Set if game is paused
* @param {Boolean} isPaused
* @memberof Engine */
export function setPaused(isPaused: boolean): void;
/** Startup LittleJS engine with your callback functions
* @param {Function} gameInit - Called once after the engine starts up, setup the game
* @param {Function} gameUpdate - Called every frame at 60 frames per second, handle input and update the game state
* @param {Function} gameUpdatePost - Called after physics and objects are updated, setup camera and prepare for render
* @param {Function} gameRender - Called before objects are rendered, draw any background effects that appear behind objects
* @param {Function} gameRenderPost - Called after objects are rendered, draw effects or hud that appear above all objects
* @param {Array} [imageSources=['tiles.png']] - Image to load
* @memberof Engine */
export function engineInit(gameInit: Function, gameUpdate: Function, gameUpdatePost: Function, gameRender: Function, gameRenderPost: Function, imageSources?: any[]): void;
/** Update each engine object, remove destroyed objects, and update time
* @memberof Engine */
export function engineObjectsUpdate(): void;
/** Destroy and remove all objects
* @memberof Engine */
export function engineObjectsDestroy(): void;
/** Triggers a callback for each object within a given area
* @param {Vector2} [pos] - Center of test area, or undefined for all objects
* @param {Number|Vector2} [size] - Radius of circle if float, rectangle size if Vector2
* @param {Function} [callbackFunction] - Calls this function on every object that passes the test
* @param {Array} [objects=engineObjects] - List of objects to check
* @memberof Engine */
export function engineObjectsCallback(pos?: Vector2, size?: number | Vector2, callbackFunction?: Function, objects?: any[]): void;
/**
* LittleJS Debug System
* - Press Esc to show debug overlay with mouse pick
* - Number keys toggle debug functions
* - +/- apply time scale
* - Debug primitive rendering
* - Save a 2d canvas as a png image
* @namespace Debug
*/
/** True if debug is enabled
* @type {Boolean}
* @default
* @memberof Debug */
export const debug: boolean;
/** True if the debug overlay is active, always false in release builds
* @type {Boolean}
* @default
* @memberof Debug */
export let debugOverlay: boolean;
/** True if watermark with FPS should be shown, false in release builds
* @type {Boolean}
* @default
* @memberof Debug */
export let showWatermark: boolean;
/** Asserts if the expression is false, does not do anything in release builds
* @param {Boolean} assert
* @param {Object} [output]
* @memberof Debug */
export function ASSERT(assert: boolean, output?: any): void;
/** Draw a debug rectangle in world space
* @param {Vector2} pos
* @param {Vector2} [size=Vector2()]
* @param {String} [color]
* @param {Number} [time]
* @param {Number} [angle]
* @param {Boolean} [fill]
* @memberof Debug */
export function debugRect(pos: Vector2, size?: Vector2, color?: string, time?: number, angle?: number, fill?: boolean): void;
/** Draw a debug poly in world space
* @param {Vector2} pos
* @param {Array} points
* @param {String} [color]
* @param {Number} [time]
* @param {Number} [angle]
* @param {Boolean} [fill]
* @memberof Debug */
export function debugPoly(pos: Vector2, points: any[], color?: string, time?: number, angle?: number, fill?: boolean): void;
/** Draw a debug circle in world space
* @param {Vector2} pos
* @param {Number} [radius]
* @param {String} [color]
* @param {Number} [time]
* @param {Boolean} [fill]
* @memberof Debug */
export function debugCircle(pos: Vector2, radius?: number, color?: string, time?: number, fill?: boolean): void;
/** Draw a debug point in world space
* @param {Vector2} pos
* @param {String} [color]
* @param {Number} [time]
* @param {Number} [angle]
* @memberof Debug */
export function debugPoint(pos: Vector2, color?: string, time?: number, angle?: number): void;
/** Draw a debug line in world space
* @param {Vector2} posA
* @param {Vector2} posB
* @param {String} [color]
* @param {Number} [thickness]
* @param {Number} [time]
* @memberof Debug */
export function debugLine(posA: Vector2, posB: Vector2, color?: string, thickness?: number, time?: number): void;
/** Draw a debug combined axis aligned bounding box in world space
* @param {Vector2} pA - position A
* @param {Vector2} sA - size A
* @param {Vector2} pB - position B
* @param {Vector2} sB - size B
* @param {String} [color]
* @memberof Debug */
export function debugOverlap(pA: Vector2, sA: Vector2, pB: Vector2, sB: Vector2, color?: string): void;
/** Draw a debug axis aligned bounding box in world space
* @param {String} text
* @param {Vector2} pos
* @param {Number} [size]
* @param {String} [color]
* @param {Number} [time]
* @param {Number} [angle]
* @param {String} [font]
* @memberof Debug */
export function debugText(text: string, pos: Vector2, size?: number, color?: string, time?: number, angle?: number, font?: string): void;
/** Clear all debug primitives in the list
* @memberof Debug */
export function debugClear(): void;
/** Save a canvas to disk
* @param {HTMLCanvasElement} canvas
* @param {String} [filename]
* @param {String} [type]
* @memberof Debug */
export function debugSaveCanvas(canvas: HTMLCanvasElement, filename?: string, type?: string): void;
/** Save a text file to disk
* @param {String} text
* @param {String} [filename]
* @param {String} [type]
* @memberof Debug */
export function debugSaveText(text: string, filename?: string, type?: string): void;
/** Save a data url to disk
* @param {String} dataURL
* @param {String} filename
* @memberof Debug */
export function debugSaveDataURL(dataURL: string, filename: string): void;
/**
* LittleJS Engine Settings
* - All settings for the engine are here
* @namespace Settings
*/
/** Position of camera in world space
* @type {Vector2}
* @default Vector2()
* @memberof Settings */
export let cameraPos: Vector2;
/** Scale of camera in world space
* @type {Number}
* @default
* @memberof Settings */
export let cameraScale: number;
/** The max size of the canvas, centered if window is larger
* @type {Vector2}
* @default Vector2(1920,1080)
* @memberof Settings */
export let canvasMaxSize: Vector2;
/** Fixed size of the canvas, if enabled canvas size never changes
* - you may also need to set mainCanvasSize if using screen space coords in startup
* @type {Vector2}
* @default Vector2()
* @memberof Settings */
export let canvasFixedSize: Vector2;
/** Disables filtering for crisper pixel art if true
* @type {Boolean}
* @default
* @memberof Settings */
export let canvasPixelated: boolean;
/** Default font used for text rendering
* @type {String}
* @default
* @memberof Settings */
export let fontDefault: string;
/** Enable to show the LittleJS splash screen be shown on startup
* @type {Boolean}
* @default
* @memberof Settings */
export let showSplashScreen: boolean;
/** Disables all rendering, audio, and input for servers
* @type {Boolean}
* @default
* @memberof Settings */
export let headlessMode: boolean;
/** Default size of tiles in pixels
* @type {Vector2}
* @default Vector2(16,16)
* @memberof Settings */
export let tileSizeDefault: Vector2;
/** How many pixels smaller to draw tiles to prevent bleeding from neighbors
* @type {Number}
* @default
* @memberof Settings */
export let tileFixBleedScale: number;
/** Enable physics solver for collisions between objects
* @type {Boolean}
* @default
* @memberof Settings */
export let enablePhysicsSolver: boolean;
/** Default object mass for collision calcuations (how heavy objects are)
* @type {Number}
* @default
* @memberof Settings */
export let objectDefaultMass: number;
/** How much to slow velocity by each frame (0-1)
* @type {Number}
* @default
* @memberof Settings */
export let objectDefaultDamping: number;
/** How much to slow angular velocity each frame (0-1)
* @type {Number}
* @default
* @memberof Settings */
export let objectDefaultAngleDamping: number;
/** How much to bounce when a collision occurs (0-1)
* @type {Number}
* @default
* @memberof Settings */
export let objectDefaultElasticity: number;
/** How much to slow when touching (0-1)
* @type {Number}
* @default
* @memberof Settings */
export let objectDefaultFriction: number;
/** Clamp max speed to avoid fast objects missing collisions
* @type {Number}
* @default
* @memberof Settings */
export let objectMaxSpeed: number;
/** How much gravity to apply to objects along the Y axis, negative is down
* @type {Number}
* @default
* @memberof Settings */
export let gravity: number;
/** Scales emit rate of particles, useful for low graphics mode (0 disables particle emitters)
* @type {Number}
* @default
* @memberof Settings */
export let particleEmitRateScale: number;
/** Enable webgl rendering, webgl can be disabled and removed from build (with some features disabled)
* @type {Boolean}
* @default
* @memberof Settings */
export let glEnable: boolean;
/** Fixes slow rendering in some browsers by not compositing the WebGL canvas
* @type {Boolean}
* @default
* @memberof Settings */
export let glOverlay: boolean;
/** Should gamepads be allowed
* @type {Boolean}
* @default
* @memberof Settings */
export let gamepadsEnable: boolean;
/** If true, the dpad input is also routed to the left analog stick (for better accessability)
* @type {Boolean}
* @default
* @memberof Settings */
export let gamepadDirectionEmulateStick: boolean;
/** If true the WASD keys are also routed to the direction keys (for better accessability)
* @type {Boolean}
* @default
* @memberof Settings */
export let inputWASDEmulateDirection: boolean;
/** True if touch gamepad should appear on mobile devices
* - Supports left analog stick, 4 face buttons and start button (button 9)
* - Must be set by end of gameInit to be activated
* @type {Boolean}
* @default
* @memberof Settings */
export let touchGamepadEnable: boolean;
/** True if touch gamepad should be analog stick or false to use if 8 way dpad
* @type {Boolean}
* @default
* @memberof Settings */
export let touchGamepadAnalog: boolean;
/** Size of virtual gamepad for touch devices in pixels
* @type {Number}
* @default
* @memberof Settings */
export let touchGamepadSize: number;
/** Transparency of touch gamepad overlay
* @type {Number}
* @default
* @memberof Settings */
export let touchGamepadAlpha: number;
/** Allow vibration hardware if it exists
* @type {Boolean}
* @default
* @memberof Settings */
export let vibrateEnable: boolean;
/** All audio code can be disabled and removed from build
* @type {Boolean}
* @default
* @memberof Settings */
export let soundEnable: boolean;
/** Volume scale to apply to all sound, music and speech
* @type {Number}
* @default
* @memberof Settings */
export let soundVolume: number;
/** Default range where sound no longer plays
* @type {Number}
* @default
* @memberof Settings */
export let soundDefaultRange: number;
/** Default range percent to start tapering off sound (0-1)
* @type {Number}
* @default
* @memberof Settings */
export let soundDefaultTaper: number;
/** How long to show medals for in seconds
* @type {Number}
* @default
* @memberof Settings */
export let medalDisplayTime: number;
/** How quickly to slide on/off medals in seconds
* @type {Number}
* @default
* @memberof Settings */
export let medalDisplaySlideTime: number;
/** Size of medal display
* @type {Vector2}
* @default Vector2(640,80)
* @memberof Settings */
export let medalDisplaySize: Vector2;
/** Size of icon in medal display
* @type {Number}
* @default
* @memberof Settings */
export let medalDisplayIconSize: number;
/** Set position of camera in world space
* @param {Vector2} pos
* @memberof Settings */
export function setCameraPos(pos: Vector2): void;
/** Set scale of camera in world space
* @param {Number} scale
* @memberof Settings */
export function setCameraScale(scale: number): void;
/** Set max size of the canvas
* @param {Vector2} size
* @memberof Settings */
export function setCanvasMaxSize(size: Vector2): void;
/** Set fixed size of the canvas
* @param {Vector2} size
* @memberof Settings */
export function setCanvasFixedSize(size: Vector2): void;
/** Disables anti aliasing for pixel art if true
* @param {Boolean} pixelated
* @memberof Settings */
export function setCanvasPixelated(pixelated: boolean): void;
/** Set default font used for text rendering
* @param {String} font
* @memberof Settings */
export function setFontDefault(font: string): void;
/** Set if the LittleJS splash screen be shown on startup
* @param {Boolean} show
* @memberof Settings */
export function setShowSplashScreen(show: boolean): void;
/** Set to disalbe rendering, audio, and input for servers
* @param {Boolean} headless
* @memberof Settings */
export function setHeadlessMode(headless: boolean): void;
/** Set if webgl rendering is enabled
* @param {Boolean} enable
* @memberof Settings */
export function setGlEnable(enable: boolean): void;
/** Set to not composite the WebGL canvas
* @param {Boolean} overlay
* @memberof Settings */
export function setGlOverlay(overlay: boolean): void;
/** Set default size of tiles in pixels
* @param {Vector2} size
* @memberof Settings */
export function setTileSizeDefault(size: Vector2): void;
/** Set to prevent tile bleeding from neighbors in pixels
* @param {Number} scale
* @memberof Settings */
export function setTileFixBleedScale(scale: number): void;
/** Set if collisions between objects are enabled
* @param {Boolean} enable
* @memberof Settings */
export function setEnablePhysicsSolver(enable: boolean): void;
/** Set default object mass for collison calcuations
* @param {Number} mass
* @memberof Settings */
export function setObjectDefaultMass(mass: number): void;
/** Set how much to slow velocity by each frame
* @param {Number} damp
* @memberof Settings */
export function setObjectDefaultDamping(damp: number): void;
/** Set how much to slow angular velocity each frame
* @param {Number} damp
* @memberof Settings */
export function setObjectDefaultAngleDamping(damp: number): void;
/** Set how much to bounce when a collision occur
* @param {Number} elasticity
* @memberof Settings */
export function setObjectDefaultElasticity(elasticity: number): void;
/** Set how much to slow when touching
* @param {Number} friction
* @memberof Settings */
export function setObjectDefaultFriction(friction: number): void;
/** Set max speed to avoid fast objects missing collisions
* @param {Number} speed
* @memberof Settings */
export function setObjectMaxSpeed(speed: number): void;
/** Set how much gravity to apply to objects along the Y axis
* @param {Number} newGravity
* @memberof Settings */
export function setGravity(newGravity: number): void;
/** Set to scales emit rate of particles
* @param {Number} scale
* @memberof Settings */
export function setParticleEmitRateScale(scale: number): void;
/** Set if gamepads are enabled
* @param {Boolean} enable
* @memberof Settings */
export function setGamepadsEnable(enable: boolean): void;
/** Set if the dpad input is also routed to the left analog stick
* @param {Boolean} enable
* @memberof Settings */
export function setGamepadDirectionEmulateStick(enable: boolean): void;
/** Set if true the WASD keys are also routed to the direction keys
* @param {Boolean} enable
* @memberof Settings */
export function setInputWASDEmulateDirection(enable: boolean): void;
/** Set if touch gamepad should appear on mobile devices
* @param {Boolean} enable
* @memberof Settings */
export function setTouchGamepadEnable(enable: boolean): void;
/** Set if touch gamepad should be analog stick or 8 way dpad
* @param {Boolean} analog
* @memberof Settings */
export function setTouchGamepadAnalog(analog: boolean): void;
/** Set size of virutal gamepad for touch devices in pixels
* @param {Number} size
* @memberof Settings */
export function setTouchGamepadSize(size: number): void;
/** Set transparency of touch gamepad overlay
* @param {Number} alpha
* @memberof Settings */
export function setTouchGamepadAlpha(alpha: number): void;
/** Set to allow vibration hardware if it exists
* @param {Boolean} enable
* @memberof Settings */
export function setVibrateEnable(enable: boolean): void;
/** Set to disable all audio code
* @param {Boolean} enable
* @memberof Settings */
export function setSoundEnable(enable: boolean): void;
/** Set volume scale to apply to all sound, music and speech
* @param {Number} volume
* @memberof Settings */
export function setSoundVolume(volume: number): void;
/** Set default range where sound no longer plays
* @param {Number} range
* @memberof Settings */
export function setSoundDefaultRange(range: number): void;
/** Set default range percent to start tapering off sound
* @param {Number} taper
* @memberof Settings */
export function setSoundDefaultTaper(taper: number): void;
/** Set how long to show medals for in seconds
* @param {Number} time
* @memberof Settings */
export function setMedalDisplayTime(time: number): void;
/** Set how quickly to slide on/off medals in seconds
* @param {Number} time
* @memberof Settings */
export function setMedalDisplaySlideTime(time: number): void;
/** Set size of medal display
* @param {Vector2} size
* @memberof Settings */
export function setMedalDisplaySize(size: Vector2): void;
/** Set size of icon in medal display
* @param {Number} size
* @memberof Settings */
export function setMedalDisplayIconSize(size: number): void;
/** Set to stop medals from being unlockable
* @param {Boolean} preventUnlock
* @memberof Settings */
export function setMedalsPreventUnlock(preventUnlock: boolean): void;
/** Set if watermark with FPS should be shown
* @param {Boolean} show
* @memberof Debug */
export function setShowWatermark(show: boolean): void;
/** Set key code used to toggle debug mode, Esc by default
* @param {String} key
* @memberof Debug */
export function setDebugKey(key: string): void;
/**
* LittleJS Utility Classes and Functions
* - General purpose math library
* - Vector2 - fast, simple, easy 2D vector class
* - Color - holds a rgba color with some math functions
* - Timer - tracks time automatically
* - RandomGenerator - seeded random number generator
* @namespace Utilities
*/
/** A shortcut to get Math.PI
* @type {Number}
* @default Math.PI
* @memberof Utilities */
export const PI: number;
/** Returns absoulte value of value passed in
* @param {Number} value
* @return {Number}
* @memberof Utilities */
export function abs(value: number): number;
/** Returns lowest of two values passed in
* @param {Number} valueA
* @param {Number} valueB
* @return {Number}
* @memberof Utilities */
export function min(valueA: number, valueB: number): number;
/** Returns highest of two values passed in
* @param {Number} valueA
* @param {Number} valueB
* @return {Number}
* @memberof Utilities */
export function max(valueA: number, valueB: number): number;
/** Returns the sign of value passed in
* @param {Number} value
* @return {Number}
* @memberof Utilities */
export function sign(value: number): number;
/** Returns first parm modulo the second param, but adjusted so negative numbers work as expected
* @param {Number} dividend
* @param {Number} [divisor]
* @return {Number}
* @memberof Utilities */
export function mod(dividend: number, divisor?: number): number;
/** Clamps the value beween max and min
* @param {Number} value
* @param {Number} [min]
* @param {Number} [max]
* @return {Number}
* @memberof Utilities */
export function clamp(value: number, min?: number, max?: number): number;
/** Returns what percentage the value is between valueA and valueB
* @param {Number} value
* @param {Number} valueA
* @param {Number} valueB
* @return {Number}
* @memberof Utilities */
export function percent(value: number, valueA: number, valueB: number): number;
/** Returns signed wrapped distance between the two values passed in
* @param {Number} valueA
* @param {Number} valueB
* @param {Number} [wrapSize]
* @returns {Number}
* @memberof Utilities */
export function distanceWrap(valueA: number, valueB: number, wrapSize?: number): number;
/** Linearly interpolates between values passed in with wrapping
* @param {Number} percent
* @param {Number} valueA
* @param {Number} valueB
* @param {Number} [wrapSize]
* @returns {Number}
* @memberof Utilities */
export function lerpWrap(percent: number, valueA: number, valueB: number, wrapSize?: number): number;
/** Returns signed wrapped distance between the two angles passed in
* @param {Number} angleA
* @param {Number} angleB
* @returns {Number}
* @memberof Utilities */
export function distanceAngle(angleA: number, angleB: number): number;
/** Linearly interpolates between the angles passed in with wrapping
* @param {Number} percent
* @param {Number} angleA
* @param {Number} angleB
* @returns {Number}
* @memberof Utilities */
export function lerpAngle(percent: number, angleA: number, angleB: number): number;
/** Linearly interpolates between values passed in using percent
* @param {Number} percent
* @param {Number} valueA
* @param {Number} valueB
* @return {Number}
* @memberof Utilities */
export function lerp(percent: number, valueA: number, valueB: number): number;
/** Applies smoothstep function to the percentage value
* @param {Number} percent
* @return {Number}
* @memberof Utilities */
export function smoothStep(percent: number): number;
/** Returns the nearest power of two not less then the value
* @param {Number} value
* @return {Number}
* @memberof Utilities */
export function nearestPowerOfTwo(value: number): number;
/** Returns true if two axis aligned bounding boxes are overlapping
* @param {Vector2} posA - Center of box A
* @param {Vector2} sizeA - Size of box A
* @param {Vector2} posB - Center of box B
* @param {Vector2} [sizeB=(0,0)] - Size of box B, a point if undefined
* @return {Boolean} - True if overlapping
* @memberof Utilities */
export function isOverlapping(posA: Vector2, sizeA: Vector2, posB: Vector2, sizeB?: Vector2): boolean;
/** Returns an oscillating wave between 0 and amplitude with frequency of 1 Hz by default
* @param {Number} [frequency] - Frequency of the wave in Hz
* @param {Number} [amplitude] - Amplitude (max height) of the wave
* @param {Number} [t=time] - Value to use for time of the wave
* @return {Number} - Value waving between 0 and amplitude
* @memberof Utilities */
export function wave(frequency?: number, amplitude?: number, t?: number): number;
/** Formats seconds to mm:ss style for display purposes
* @param {Number} t - time in seconds
* @return {String}
* @memberof Utilities */
export function formatTime(t: number): string;
/** Random global functions
* @namespace Random */
/** Returns a random value between the two values passed in
* @param {Number} [valueA]
* @param {Number} [valueB]
* @return {Number}
* @memberof Random */
export function rand(valueA?: number, valueB?: number): number;
/** Returns a floored random value the two values passed in
* @param {Number} valueA
* @param {Number} [valueB]
* @return {Number}
* @memberof Random */
export function randInt(valueA: number, valueB?: number): number;
/** Randomly returns either -1 or 1
* @return {Number}
* @memberof Random */
export function randSign(): number;
/** Returns a random Vector2 within a circular shape
* @param {Number} [radius]
* @param {Number} [minRadius]
* @return {Vector2}
* @memberof Random */
export function randInCircle(radius?: number, minRadius?: number): Vector2;
/** Returns a random Vector2 with the passed in length
* @param {Number} [length]
* @return {Vector2}
* @memberof Random */
export function randVector(length?: number): Vector2;
/** Returns a random color between the two passed in colors, combine components if linear
* @param {Color} [colorA=(1,1,1,1)]
* @param {Color} [colorB=(0,0,0,1)]
* @param {Boolean} [linear]
* @return {Color}
* @memberof Random */
export function randColor(colorA?: Color, colorB?: Color, linear?: boolean): Color;
/**
* Seeded random number generator
* - Can be used to create a deterministic random number sequence
* @example
* let r = new RandomGenerator(123); // random number generator with seed 123
* let a = r.float(); // random value between 0 and 1
* let b = r.int(10); // random integer between 0 and 9
* r.seed = 123; // reset the seed
* let c = r.float(); // the same value as a
*/
export class RandomGenerator {
/** Create a random number generator with the seed passed in
* @param {Number} seed - Starting seed */
constructor(seed: number);
/** @property {Number} - random seed */
seed: number;
/** Returns a seeded random value between the two values passed in
* @param {Number} [valueA]
* @param {Number} [valueB]
* @return {Number} */
float(valueA?: number, valueB?: number): number;
/** Returns a floored seeded random value the two values passed in
* @param {Number} valueA
* @param {Number} [valueB]
* @return {Number} */
int(valueA: number, valueB?: number): number;
/** Randomly returns either -1 or 1 deterministically
* @return {Number} */
sign(): number;
}
/**
* 2D Vector object with vector math library
* - Functions do not change this so they can be chained together
* @example
* let a = new Vector2(2, 3); // vector with coordinates (2, 3)
* let b = new Vector2; // vector with coordinates (0, 0)
* let c = vec2(4, 2); // use the vec2 function to make a Vector2
* let d = a.add(b).scale(5); // operators can be chained
*/
export class Vector2 {
/** Create a 2D vector with the x and y passed in, can also be created with vec2()
* @param {Number} [x] - X axis location
* @param {Number} [y] - Y axis location */
constructor(x?: number, y?: number);
/** @property {Number} - X axis location */
x: number;
/** @property {Number} - Y axis location */
y: number;
/** Sets values of this vector and returns self
* @param {Number} [x] - X axis location
* @param {Number} [y] - Y axis location
* @return {Vector2} */
set(x?: number, y?: number): Vector2;
/** Returns a new vector that is a copy of this
* @return {Vector2} */
copy(): Vector2;
/** Returns a copy of this vector plus the vector passed in
* @param {Vector2} v - other vector
* @return {Vector2} */
add(v: Vector2): Vector2;
/** Returns a copy of this vector minus the vector passed in
* @param {Vector2} v - other vector
* @return {Vector2} */
subtract(v: Vector2): Vector2;
/** Returns a copy of this vector times the vector passed in
* @param {Vector2} v - other vector
* @return {Vector2} */
multiply(v: Vector2): Vector2;
/** Returns a copy of this vector divided by the vector passed in
* @param {Vector2} v - other vector
* @return {Vector2} */
divide(v: Vector2): Vector2;
/** Returns a copy of this vector scaled by the vector passed in
* @param {Number} s - scale
* @return {Vector2} */
scale(s: number): Vector2;
/** Returns the length of this vector
* @return {Number} */
length(): number;
/** Returns the length of this vector squared
* @return {Number} */
lengthSquared(): number;
/** Returns the distance from this vector to vector passed in
* @param {Vector2} v - other vector
* @return {Number} */
distance(v: Vector2): number;
/** Returns the distance squared from this vector to vector passed in
* @param {Vector2} v - other vector
* @return {Number} */
distanceSquared(v: Vector2): number;
/** Returns a new vector in same direction as this one with the length passed in
* @param {Number} [length]
* @return {Vector2} */
normalize(length?: number): Vector2;
/** Returns a new vector clamped to length passed in
* @param {Number} [length]
* @return {Vector2} */
clampLength(length?: number): Vector2;
/** Returns the dot product of this and the vector passed in
* @param {Vector2} v - other vector
* @return {Number} */
dot(v: Vector2): number;
/** Returns the cross product of this and the vector passed in
* @param {Vector2} v - other vector
* @return {Number} */
cross(v: Vector2): number;
/** Returns the angle of this vector, up is angle 0
* @return {Number} */
angle(): number;
/** Sets this vector with angle and length passed in
* @param {Number} [angle]
* @param {Number} [length]
* @return {Vector2} */
setAngle(angle?: number, length?: number): Vector2;
/** Returns copy of this vector rotated by the angle passed in
* @param {Number} angle
* @return {Vector2} */
rotate(angle: number): Vector2;
/** Set the integer direction of this vector, corrosponding to multiples of 90 degree rotation (0-3)
* @param {Number} [direction]
* @param {Number} [length] */
setDirection(direction?: number, length?: number): Vector2;
/** Returns the integer direction of this vector, corrosponding to multiples of 90 degree rotation (0-3)
* @return {Number} */
direction(): number;
/** Returns a copy of this vector that has been inverted
* @return {Vector2} */
invert(): Vector2;
/** Returns a copy of this vector with each axis floored
* @return {Vector2} */
floor(): Vector2;
/** Returns the area this vector covers as a rectangle
* @return {Number} */
area(): number;
/** Returns a new vector that is p percent between this and the vector passed in
* @param {Vector2} v - other vector
* @param {Number} percent
* @return {Vector2} */
lerp(v: Vector2, percent: number): Vector2;
/** Returns true if this vector is within the bounds of an array size passed in
* @param {Vector2} arraySize
* @return {Boolean} */
arrayCheck(arraySize: Vector2): boolean;
/** Returns this vector expressed as a string
* @param {Number} digits - precision to display
* @return {String} */
toString(digits?: number): string;
}
/**
* Color object (red, green, blue, alpha) with some helpful functions
* @example
* let a = new Color; // white
* let b = new Color(1, 0, 0); // red
* let c = new Color(0, 0, 0, 0); // transparent black
* let d = rgb(0, 0, 1); // blue using rgb color
* let e = hsl(.3, 1, .5); // green using hsl color
*/
export class Color {
/** Create a color with the rgba components passed in, white by default
* @param {Number} [r] - red
* @param {Number} [g] - green
* @param {Number} [b] - blue
* @param {Number} [a] - alpha*/
constructor(r?: number, g?: number, b?: number, a?: number);
/** @property {Number} - Red */
r: number;
/** @property {Number} - Green */
g: number;
/** @property {Number} - Blue */
b: number;
/** @property {Number} - Alpha */
a: number;
/** Sets values of this color and returns self
* @param {Number} [r] - red
* @param {Number} [g] - green
* @param {Number} [b] - blue
* @param {Number} [a] - alpha
* @return {Color} */
set(r?: number, g?: number, b?: number, a?: number): Color;
/** Returns a new color that is a copy of this
* @return {Color} */
copy(): Color;
/** Returns a copy of this color plus the color passed in
* @param {Color} c - other color
* @return {Color} */
add(c: Color): Color;
/** Returns a copy of this color minus the color passed in
* @param {Color} c - other color
* @return {Color} */
subtract(c: Color): Color;
/** Returns a copy of this color times the color passed in
* @param {Color} c - other color
* @return {Color} */
multiply(c: Color): Color;
/** Returns a copy of this color divided by the color passed in
* @param {Color} c - other color
* @return {Color} */
divide(c: Color): Color;
/** Returns a copy of this color scaled by the value passed in, alpha can be scaled separately
* @param {Number} scale
* @param {Number} [alphaScale=scale]
* @return {Color} */
scale(scale: number, alphaScale?: number): Color;
/** Returns a copy of this color clamped to the valid range between 0 and 1
* @return {Color} */
clamp(): Color;
/** Returns a new color that is p percent between this and the color passed in
* @param {Color} c - other color
* @param {Number} percent
* @return {Color} */
lerp(c: Color, percent: number): Color;
/** Sets this color given a hue, saturation, lightness, and alpha
* @param {Number} [h] - hue
* @param {Number} [s] - saturation
* @param {Number} [l] - lightness
* @param {Number} [a] - alpha
* @return {Color} */
setHSLA(h?: number, s?: number, l?: number, a?: number): Color;
/** Returns this color expressed in hsla format
* @return {Array} */
HSLA(): any[];
/** Returns a new color that has each component randomly adjusted
* @param {Number} [amount]
* @param {Number} [alphaAmount]
* @return {Color} */
mutate(amount?: number, alphaAmount?: number): Color;
/** Returns this color expressed as a hex color code
* @param {Boolean} [useAlpha] - if alpha should be included in result
* @return {String} */
toString(useAlpha?: boolean): string;
/** Set this color from a hex code
* @param {String} hex - html hex code
* @return {Color} */
setHex(hex: string): Color;
/** Returns this color expressed as 32 bit RGBA value
* @return {Number} */
rgbaInt(): number;
}
/**
* Timer object tracks how long has passed since it was set
* @example
* let a = new Timer; // creates a timer that is not set
* a.set(3); // sets the timer to 3 seconds
*
* let b = new Timer(1); // creates a timer with 1 second left
* b.unset(); // unsets the timer
*/
export class Timer {
/** Create a timer object set time passed in
* @param {Number} [timeLeft] - How much time left before the timer elapses in seconds */
constructor(timeLeft?: number);
time: number;
setTime: number;
/** Set the timer with seconds passed in
* @param {Number} [timeLeft] - How much time left before the timer is elapsed in seconds */
set(timeLeft?: number): void;
/** Unset the timer */
unset(): void;
/** Returns true if set
* @return {Boolean} */
isSet(): boolean;
/** Returns true if set and has not elapsed
* @return {Boolean} */
active(): boolean;
/** Returns true if set and elapsed
* @return {Boolean} */
elapsed(): boolean;
/** Get how long since elapsed, returns 0 if not set (returns negative if currently active)
* @return {Number} */
get(): number;
/** Get percentage elapsed based on time it was set to, returns 0 if not set
* @return {Number} */
getPercent(): number;
/** Returns this timer expressed as a string
* @return {String} */
toString(): string;
/** Get how long since elapsed, returns 0 if not set (returns negative if currently active)
* @return {Number} */
valueOf(): number;
}
/**
* Create a 2d vector, can take another Vector2 to copy, 2 scalars, or 1 scalar
* @param {(Number|Vector2)} [x]
* @param {Number} [y]
* @return {Vector2}
* @example
* let a = vec2(0, 1); // vector with coordinates (0, 1)
* let b = vec2(a); // copy a into b
* a = vec2(5); // set a to (5, 5)
* b = vec2(); // set b to (0, 0)
* @memberof Utilities
*/
export function vec2(x?: (number | Vector2), y?: number): Vector2;
/**
* Create a color object with RGBA values, white by default