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