litecanvas 0.39.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,657 @@
1
+ /**
2
+ * The litecanvas constructor
3
+ */
4
+ export default function litecanvas(
5
+ settings?: LitecanvasOptions,
6
+ ): LitecanvasInstance
7
+
8
+ declare global {
9
+ function litecanvas(settings?: LitecanvasOptions): LitecanvasInstance
10
+
11
+ /** The game screen width */
12
+ var WIDTH: number
13
+ /** The game screen height */
14
+ var HEIGHT: number
15
+ /** The game canvas HTML element */
16
+ var CANVAS: HTMLCanvasElement
17
+ /** `true` when the game screen is touched/clicked */
18
+ var TAPPED: boolean
19
+ /** `true` while the screen is being touched/clicked (holding) */
20
+ var TAPPING: boolean
21
+ /** the tap/click X position */
22
+ var TAPX: number
23
+ /** the tap/click Y position */
24
+ var TAPY: number
25
+ /** the amount of time (in seconds) since the game started */
26
+ var ELAPSED: number
27
+ /** the FPS meter */
28
+ var FPS: number
29
+ /** the fixed delta time */
30
+ var DT: number
31
+ /** the center X of the game screen */
32
+ var CENTERX: number
33
+ /** the center Y of the game screen */
34
+ var CENTERY: number
35
+
36
+ /** MATH API */
37
+ /**
38
+ * The value of the mathematical constant PI (π).
39
+ * Approximately 3.14159
40
+ */
41
+ var PI: number
42
+ /**
43
+ * Twice the value of the mathematical constant PI (π).
44
+ * Approximately 6.28318
45
+ *
46
+ * Note: TWO_PI radians equals 360°, PI radians equals 180°,
47
+ * HALF_PI radians equals 90°, and HALF_PI/2 radians equals 45°.
48
+ */
49
+ var TWO_PI: number
50
+ /**
51
+ * Half the value of the mathematical constant PI (π).
52
+ * Approximately 1.57079
53
+ */
54
+ var HALF_PI: number
55
+ /**
56
+ * Calculates a linear (interpolation) value over t%.
57
+ *
58
+ * @param {number} start
59
+ * @param {number} end
60
+ * @param {number} t The progress in percentage, where 0 = 0% and 1 = 100%.
61
+ * @returns {number} The unterpolated value
62
+ * @tutorial https://gamedev.net/tutorials/programming/general-and-gameplay-programming/a-brief-introduction-to-lerp-r4954/
63
+ */
64
+ function lerp(start: number, end: number, t: number): number
65
+ /**
66
+ * Convert degrees to radians
67
+ *
68
+ * @param {number} degs
69
+ * @returns {number} the value in radians
70
+ */
71
+ function deg2rad(degs: number): number
72
+ /**
73
+ * Convert radians to degrees
74
+ *
75
+ * @param {number} rads
76
+ * @returns {number} the value in degrees
77
+ */
78
+ function rad2deg(rads: number): number
79
+ /**
80
+ * Constrains a number between `min` and `max`.
81
+ *
82
+ * @param {number} value
83
+ * @param {number} min
84
+ * @param {number} max
85
+ * @returns {number}
86
+ */
87
+ function clamp(value: number, min: number, max: number): number
88
+ /**
89
+ * Wraps a number between `min` (inclusive) and `max` (exclusive).
90
+ *
91
+ * @param {number} value
92
+ * @param {number} min
93
+ * @param {number} max
94
+ * @returns {number}
95
+ */
96
+ function wrap(value: number, min: number, max: number): number
97
+ /**
98
+ * Re-maps a number from one range to another.
99
+ *
100
+ * @param {number} value the value to be remapped.
101
+ * @param {number} min1 lower bound of the value's current range.
102
+ * @param {number} max1 upper bound of the value's current range.
103
+ * @param {number} min2 lower bound of the value's target range.
104
+ * @param {number} max2 upper bound of the value's target range.
105
+ * @param {boolean} [withinBounds=false] constrain the value to the newly mapped range
106
+ * @returns {number} the remapped number
107
+ */
108
+ function map(
109
+ value: number,
110
+ min1: number,
111
+ max1: number,
112
+ min2: number,
113
+ max2: number,
114
+ withinBounds?: boolean,
115
+ ): number
116
+ /**
117
+ * Maps a number from one range to a value between 0 and 1.
118
+ *
119
+ * @param {number} value
120
+ * @param {number} min
121
+ * @param {number} max
122
+ * @returns {number} the normalized number.
123
+ */
124
+ function norm(value: number, min: number, max: number): number
125
+ /**
126
+ * Returns the fractional part of a number
127
+ *
128
+ * @param {number} value The number
129
+ * @returns {number}
130
+ */
131
+ function fract(value: number): number
132
+ /**
133
+ * Returns the sine of a number in radians
134
+ */
135
+ function sin(n: number): number
136
+ /**
137
+ * Returns the cosine of a number in radians
138
+ */
139
+ function cos(n: number): number
140
+ /**
141
+ * Returns the angle in the plane (in radians) between the positive x-axis and the ray from (0, 0) to the point (x, y)
142
+ */
143
+ function atan2(y: number, x: number): number
144
+ /**
145
+ * Returns the square root of the sum of squares of its arguments.
146
+ */
147
+ function hypot(...ns: number[]): number
148
+ /**
149
+ * Returns the tangent of a number in radians.
150
+ */
151
+ function tan(n: number): number
152
+ /**
153
+ * Returns the absolute value of a number.
154
+ */
155
+ function abs(n: number): number
156
+ /**
157
+ * Always rounds up and returns the smallest integer greater than or equal to a given number.
158
+ */
159
+ function ceil(n: number): number
160
+ /**
161
+ * Returns the value of a number rounded to the nearest integer.
162
+ */
163
+ function round(n: number): number
164
+ /**
165
+ * Always rounds down and returns the largest integer less than or equal to a given number.
166
+ */
167
+ function floor(n: number): number
168
+ /**
169
+ * Returns the integer part of a number by removing any fractional digits.
170
+ */
171
+ function trunc(n: number): number
172
+ /**
173
+ * Returns the smallest of the numbers given as input parameters, or `Infinity` if there are no parameters.
174
+ */
175
+ function min(...ns: number[]): number
176
+ /**
177
+ * Returns the largest of the numbers given as input parameters, or `-Infinity` if there are no parameters.
178
+ */
179
+ function max(...ns: number[]): number
180
+ /**
181
+ * Returns the value of a base raised to a power.
182
+ */
183
+ function pow(base: number, exponent: number): number
184
+ /**
185
+ * Returns the square root of a number.
186
+ */
187
+ function sqrt(n: number): number
188
+ /**
189
+ * Returns 1 or -1, indicating the sign of the number passed as argument.
190
+ * If the input is 0 or -0, it will be returned as-is.
191
+ */
192
+ function sign(n: number): number
193
+ /**
194
+ * Returns the Euler's number raised to the power of a number.
195
+ */
196
+ function exp(exponent: number): number
197
+
198
+ /** RNG API */
199
+ /**
200
+ * Generates a pseudorandom float between min (inclusive) and max (exclusive)
201
+ *
202
+ * @param {number} [min=0.0]
203
+ * @param {number} [max=1.0]
204
+ * @returns {number} the random number
205
+ */
206
+ function rand(min?: number, max?: number): number
207
+ /**
208
+ * Generates a pseudorandom integer between min (inclusive) and max (inclusive)
209
+ *
210
+ * @param {number} [min=0]
211
+ * @param {number} [max=1]
212
+ * @returns {number} the random number
213
+ */
214
+ function randi(min?: number, max?: number): number
215
+
216
+ /** BASIC GRAPHICS API */
217
+ /**
218
+ * Clear the game screen
219
+ *
220
+ * @param {number|null} color The background color (from 0 to 7) or null
221
+ */
222
+ function cls(color: number | null): void
223
+ /**
224
+ * Clear the game screen
225
+ * alias of `cls()`
226
+ *
227
+ * @param {number|null} color The background color (from 0 to 7) or null
228
+ */
229
+ function clear(color: number | null): void
230
+ /**
231
+ * Draw a rectangle outline
232
+ *
233
+ * @param {number} x
234
+ * @param {number} y
235
+ * @param {number} width
236
+ * @param {number} height
237
+ * @param {number} [color=0] the color index (generally from 0 to 7)
238
+ * @param {number|number[]} [radii] A number or list specifying the radii used to draw a rounded-borders rectangle
239
+ */
240
+ function rect(
241
+ x: number,
242
+ y: number,
243
+ width: number,
244
+ height: number,
245
+ color?: number,
246
+ radii?: number | number[],
247
+ ): void
248
+ /**
249
+ * Draw a color-filled rectangle
250
+ *
251
+ * @param {number} x
252
+ * @param {number} y
253
+ * @param {number} width
254
+ * @param {number} height
255
+ * @param {number} [color=0] the color index (generally from 0 to 7)
256
+ * @param {number|number[]} [radii] A number or list specifying the radii used to draw a rounded-borders rectangle
257
+ */
258
+ function rectfill(
259
+ x: number,
260
+ y: number,
261
+ width: number,
262
+ height: number,
263
+ color?: number,
264
+ radii?: number | number[],
265
+ ): void
266
+ /**
267
+ * Draw a circle outline
268
+ *
269
+ * @param {number} x
270
+ * @param {number} y
271
+ * @param {number} radius
272
+ * @param {number} [color=0] the color index (generally from 0 to 7)
273
+ */
274
+ function circ(x: number, y: number, radius: number, color?: number): void
275
+ /**
276
+ * Draw a color-filled circle
277
+ *
278
+ * @param {number} x
279
+ * @param {number} y
280
+ * @param {number} radius
281
+ * @param {number} [color=0] the color index (generally from 0 to 7)
282
+ */
283
+ function circfill(
284
+ x: number,
285
+ y: number,
286
+ radius: number,
287
+ color?: number,
288
+ ): void
289
+ /**
290
+ * Draw a line
291
+ *
292
+ * @param {number} x1
293
+ * @param {number} y1
294
+ * @param {number} x2
295
+ * @param {number} y2
296
+ * @param {number} [color=0] the color index (generally from 0 to 7)
297
+ */
298
+ function line(
299
+ x1: number,
300
+ y1: number,
301
+ x2: number,
302
+ y2: number,
303
+ color?: number,
304
+ ): void
305
+ /**
306
+ * Sets the thickness of lines
307
+ *
308
+ * @param {number} value
309
+ * @see https://developer.mozilla.org/en-US/docs/Web/API/CanvasRenderingContext2D/lineWidth
310
+ */
311
+ function linewidth(value: number): void
312
+ /**
313
+ * Sets the line dash pattern used when drawing lines
314
+ *
315
+ * @param {number|number[]} segments the line dash pattern
316
+ * @param {number} [offset=0] the line dash offset, or "phase".
317
+ * @see https://developer.mozilla.org/en-US/docs/Web/API/CanvasRenderingContext2D/setLineDash
318
+ * @see https://developer.mozilla.org/en-US/docs/Web/API/CanvasRenderingContext2D/lineDashOffset
319
+ */
320
+ function linedash(segments: number | number[], offset?: number): void
321
+ /**
322
+ * Determines the shape used to draw the end points of lines
323
+ * Possible values are: "butt", "round" or "square"
324
+ *
325
+ * @param {string} value
326
+ * @see https://developer.mozilla.org/en-US/docs/Web/API/CanvasRenderingContext2D/lineCap
327
+ */
328
+ function linecap(value: string): void
329
+ /**
330
+ * Determines the shape used to join two line segments where they meet
331
+ * Possible values are: "round", "bevel", and "miter"
332
+ *
333
+ * @param {string} value
334
+ * @see https://developer.mozilla.org/en-US/docs/Web/API/CanvasRenderingContext2D/lineJoin
335
+ */
336
+ function linejoin(value: string): void
337
+ /** TEXT RENDERING API */
338
+ /**
339
+ * Draw text
340
+ *
341
+ * @param {number} x
342
+ * @param {number} y
343
+ * @param {string} text the text message
344
+ * @param {number} [color=3] the color index (generally from 0 to 7)
345
+ */
346
+ function text(x: number, y: number, text: string, color?: number): void
347
+ /**
348
+ * Draw text
349
+ * alias of `text()`
350
+ *
351
+ * @param {number} x
352
+ * @param {number} y
353
+ * @param {string} text the text message
354
+ * @param {number} [color=3] the color index (generally from 0 to 7)
355
+ */
356
+ function print(x: number, y: number, text: string, color?: number): void
357
+ /**
358
+ * Set the font family
359
+ *
360
+ * @param {string} fontFamily
361
+ */
362
+ function textfont(fontFamily: string): void
363
+ /**
364
+ * Set the font size
365
+ *
366
+ * @param {string} size
367
+ */
368
+ function textsize(size: string): void
369
+ /**
370
+ * Sets whether a font should be styled with a normal, italic, or bold.
371
+ *
372
+ * @param {string} style
373
+ */
374
+ function textstyle(style: string): void
375
+ /**
376
+ * Sets the alignment used when drawing texts
377
+ *
378
+ * @param {string} align the horizontal alignment. Possible values: "left", "right", "center", "start" or "end"
379
+ * @param {string} baseline the vertical alignment. Possible values: "top", "bottom", "middle", "hanging" or "ideographic"
380
+ * @see https://developer.mozilla.org/en-US/docs/Web/API/CanvasRenderingContext2D/textBaseline
381
+ * @see https://developer.mozilla.org/en-US/docs/Web/API/CanvasRenderingContext2D/textAlign
382
+ */
383
+ function textalign(align: string, baseline: string): void
384
+ /**
385
+ * Returns a TextMetrics object that contains information about the measured text (such as its width, for example)
386
+ *
387
+ * @param {string} text
388
+ * @param {number} [size]
389
+ * @returns {TextMetrics}
390
+ * @see https://developer.mozilla.org/en-US/docs/Web/API/TextMetrics
391
+ */
392
+ function textmetrics(text: string, size?: number): TextMetrics
393
+ /** IMAGE GRAPHICS API */
394
+ /**
395
+ * Draw an image
396
+ *
397
+ * @param {number} x
398
+ * @param {number} y
399
+ * @param {OffscreenCanvas|HTMLImageElement|HTMLCanvasElement} image
400
+ */
401
+ function image(
402
+ x: number,
403
+ y: number,
404
+ image: OffscreenCanvas | HTMLImageElement | HTMLCanvasElement,
405
+ ): void
406
+ /**
407
+ * Creates a offscreen canvas to draw on it
408
+ *
409
+ * @param {number} width
410
+ * @param {number} height
411
+ * @param {string[] | drawCallback} draw
412
+ * @param {{scale?:number}} [options]
413
+ * @returns {OffscreenCanvas}
414
+ * @see https://developer.mozilla.org/en-US/docs/Web/API/OffscreenCanvas
415
+ */
416
+ function paint(
417
+ width: number,
418
+ height: number,
419
+ draw: string[] | drawCallback,
420
+ options?: {
421
+ scale?: number
422
+ },
423
+ ): OffscreenCanvas
424
+ /** ADVANCED GRAPHICS API */
425
+ /**
426
+ * Get the canvas context
427
+ *
428
+ * @returns {CanvasRenderingContext2D}
429
+ */
430
+ function ctx(): CanvasRenderingContext2D
431
+ /**
432
+ * saves the current drawing style settings and transformations
433
+ * @see https://developer.mozilla.org/en-US/docs/Web/API/CanvasRenderingContext2D/save
434
+ */
435
+ function push(): void
436
+ /**
437
+ * restores the drawing style settings and transformations
438
+ * @see https://developer.mozilla.org/en-US/docs/Web/API/CanvasRenderingContext2D/restore
439
+ */
440
+ function pop(): void
441
+ /**
442
+ * Adds a translation transformation to the current matrix
443
+ *
444
+ * @param {number} x
445
+ * @param {number} y
446
+ */
447
+ function translate(x: number, y: number): void
448
+ /**
449
+ * Adds a scaling transformation to the canvas units horizontally and/or vertically.
450
+ *
451
+ * @param {number} x
452
+ * @param {number} [y]
453
+ */
454
+ function scale(x: number, y?: number): void
455
+ /**
456
+ * Adds a rotation to the transformation matrix
457
+ *
458
+ * @param {number} radians
459
+ */
460
+ function rotate(radians: number): void
461
+ /**
462
+ * Adds a transformation that skews to the transformation matrix
463
+ *
464
+ * @param {number} a
465
+ * @param {number} b
466
+ * @param {number} c
467
+ * @param {number} d
468
+ * @param {number} e
469
+ * @param {number} f
470
+ * @param {boolean} [resetFirst=true] `false` to use _ctx.transform(); by default use _ctx.setTransform()
471
+ * @see https://developer.mozilla.org/en-US/docs/Web/API/CanvasRenderingContext2D/setTransform
472
+ */
473
+ function transform(
474
+ a: number,
475
+ b: number,
476
+ c: number,
477
+ d: number,
478
+ e: number,
479
+ f: number,
480
+ resetFirst?: boolean,
481
+ ): void
482
+ /**
483
+ * Sets the alpha (transparency) value to apply when drawing new shapes and images
484
+ *
485
+ * @param {number} alpha float from 0 to 1 (e.g: 0.5 = 50% transparent)
486
+ * @see https://developer.mozilla.org/en-US/docs/Web/API/CanvasRenderingContext2D/globalAlpha
487
+ */
488
+ function alpha(alpha: number): void
489
+ /**
490
+ * Returns a newly instantiated Path2D object, optionally with another
491
+ * path as an argument (creates a copy), or optionally with a string
492
+ * consisting of SVG path data.
493
+ *
494
+ * @param {Path2D|string} [arg]
495
+ * @returns Path2D
496
+ * @see https://developer.mozilla.org/en-US/docs/Web/API/Path2D/Path2D
497
+ */
498
+ function path(arg?: Path2D | string): Path2D
499
+ /**
500
+ * Fills the current or given path with a given color.
501
+ *
502
+ * @param {number} color
503
+ * @param {Path2D} [path]
504
+ */
505
+ function fill(color: number, path?: Path2D): void
506
+ /**
507
+ * Outlines the current or given path with a given color.
508
+ *
509
+ * @param {number} color
510
+ * @param {Path2D} [path]
511
+ */
512
+ function stroke(color: number, path?: Path2D): void
513
+ /**
514
+ * Create a retangular clipping region.
515
+ *
516
+ * Note: Clip paths cannot be reverted directly. You must save your
517
+ * canvas state using push() before calling cliprect(), and restore it
518
+ * once you have finished drawing in the clipped area using pop().
519
+ *
520
+ * @param {number} x
521
+ * @param {number} y
522
+ * @param {number} width
523
+ * @param {number} height
524
+ * @see https://developer.mozilla.org/en-US/docs/Web/API/CanvasRenderingContext2D/clip
525
+ */
526
+ function cliprect(x: number, y: number, width: number, height: number): void
527
+ /**
528
+ * Create a circular clipping region.
529
+ *
530
+ * Note: Clip paths cannot be reverted directly. You must save your
531
+ * canvas state using push() before calling clipcirc(), and restore it
532
+ * once you have finished drawing in the clipped area using pop().
533
+ *
534
+ * @param {number} x
535
+ * @param {number} y
536
+ * @param {number} radius
537
+ * @see https://developer.mozilla.org/en-US/docs/Web/API/CanvasRenderingContext2D/clip
538
+ */
539
+ function clipcirc(x: number, y: number, radius: number): void
540
+ /**
541
+ * Sets the type of compositing operation to apply when drawing new shapes.
542
+ * Default value = 'source-over'.
543
+ *
544
+ * @param {string} value
545
+ * @see https://developer.mozilla.org/en-US/docs/Web/API/CanvasRenderingContext2D/globalCompositeOperation
546
+ */
547
+ function blendmode(value: string): void
548
+ /**
549
+ * Provides filter effects such as blurring and grayscaling.
550
+ * It is similar to the CSS filter property and accepts the same values.
551
+ *
552
+ * @param {string} effect
553
+ * @see https://developer.mozilla.org/en-US/docs/Web/API/CanvasRenderingContext2D/filter
554
+ */
555
+ function filter(effect: string): void
556
+ /** SOUND API */
557
+ /**
558
+ * Play a defined sound or a ZzFX array of params
559
+ *
560
+ * @param {number|number[]} [sound=0] the sound index (from 0 to 7) or a ZzFX array of params
561
+ * @param {number} [volume=1]
562
+ * @param {number} [pitch=0]
563
+ * @param {number} [randomness=0]
564
+ * @returns {AudioBufferSourceNode}
565
+ * @see https://github.com/KilledByAPixel/ZzFX
566
+ */
567
+ function sfx(
568
+ sound?: number | number[],
569
+ volume?: number,
570
+ pitch?: number,
571
+ randomness?: number,
572
+ ): AudioBufferSourceNode
573
+ /** UTILS API */
574
+ /**
575
+ * Check a collision between two rectangles
576
+ *
577
+ * @param {number} x1 first rectangle position X
578
+ * @param {number} y1 first rectangle position Y
579
+ * @param {number} w1 first rectangle width
580
+ * @param {number} h1 first rectangle height
581
+ * @param {number} x2 second rectangle position X
582
+ * @param {number} y2 second rectangle position Y
583
+ * @param {number} w2 second rectangle width
584
+ * @param {number} h2 second rectangle height
585
+ * @returns {boolean}
586
+ */
587
+ function colrect(
588
+ x1: number,
589
+ y1: number,
590
+ w1: number,
591
+ h1: number,
592
+ x2: number,
593
+ y2: number,
594
+ w2: number,
595
+ h2: number,
596
+ ): boolean
597
+ /**
598
+ * Check a collision between two circles
599
+ *
600
+ * @param {number} x1 first circle position X
601
+ * @param {number} y1 first circle position Y
602
+ * @param {number} r1 first circle position radius
603
+ * @param {number} x2 second circle position X
604
+ * @param {number} y2 second circle position Y
605
+ * @param {number} r2 second circle position radius
606
+ * @returns {boolean}
607
+ */
608
+ function colcirc(
609
+ x1: number,
610
+ y1: number,
611
+ r1: number,
612
+ x2: number,
613
+ y2: number,
614
+ r2: number,
615
+ ): boolean
616
+ /** PLUGINS API */
617
+ /**
618
+ * Prepares a plugin to be loaded
619
+ *
620
+ * @param {pluginCallback} callback
621
+ */
622
+ function use(callback: pluginCallback): void
623
+ /**
624
+ * Add a game loop event listener
625
+ *
626
+ * @param {string} event should be "init", "update", "draw" or "resized"
627
+ * @param {function} callback the function that is called when the event occurs
628
+ * @param {boolean} [highPriority=false] determines whether the callback will be called before or after the others
629
+ * @returns {function?} a function to remove the listener or `undefined` if passed a invalid event
630
+ */
631
+ function listen(
632
+ event: string,
633
+ callback: Function,
634
+ highPriority?: boolean,
635
+ ): Function | null
636
+ /**
637
+ * Get the color value
638
+ *
639
+ * @param {number} index The color number
640
+ * @returns {string} the color value
641
+ */
642
+ function getcolor(index: number): string
643
+ /**
644
+ * Create or update a instance variable
645
+ *
646
+ * @param {string} key
647
+ * @param {any} value
648
+ */
649
+ function setvar(key: string, value: any): void
650
+ /**
651
+ * Resizes the game canvas and emit the "resized" event
652
+ *
653
+ * @param {number} width
654
+ * @param {number} height
655
+ */
656
+ function resize(width: number, height: number): void
657
+ }