littlejsengine 1.11.9 → 1.11.10
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/README.md +3 -3
- package/dist/littlejs.d.ts +482 -479
- package/dist/littlejs.esm.js +512 -501
- package/dist/littlejs.esm.min.js +1 -1
- package/dist/littlejs.js +510 -499
- package/dist/littlejs.min.js +1 -1
- package/dist/littlejs.release.js +466 -458
- package/examples/module/game.js +2 -2
- package/examples/shorts/base.html +1 -1
- package/examples/starter/game.js +8 -1
- package/examples/typescript/build/dist/littlejs.esm.js +4834 -0
- package/examples/typescript/build/examples/typescript/build.js +24 -0
- package/examples/typescript/build/examples/typescript/game.js +102 -0
- package/examples/typescript/build.bat +5 -0
- package/examples/typescript/build.js +33 -0
- package/examples/typescript/game.js +102 -0
- package/examples/typescript/game.ts +134 -0
- package/examples/typescript/index.html +10 -0
- package/examples/typescript/tiles.png +0 -0
- package/examples/typescript/tsconfig.json +8 -0
- package/package.json +1 -1
- package/plugins/newgrounds.js +38 -34
- package/plugins/postProcess.js +18 -4
- package/plugins/uiSystem.js +196 -30
- package/src/engine.js +21 -20
- package/src/engineAudio.js +59 -59
- package/src/engineDebug.js +44 -41
- package/src/engineDraw.js +58 -58
- package/src/engineExport.js +2 -2
- package/src/engineInput.js +30 -30
- package/src/engineMedals.js +1 -1
- package/src/engineObject.js +39 -34
- package/src/engineParticles.js +10 -10
- package/src/engineSettings.js +74 -72
- package/src/engineTileLayer.js +21 -21
- package/src/engineUtilities.js +150 -150
- package/src/engineWebGL.js +3 -3
package/src/engineDraw.js
CHANGED
|
@@ -61,10 +61,10 @@ let drawCount;
|
|
|
61
61
|
* Create a tile info object using a grid based system
|
|
62
62
|
* - This can take vecs or floats for easier use and conversion
|
|
63
63
|
* - If an index is passed in, the tile size and index will determine the position
|
|
64
|
-
* @param {
|
|
65
|
-
* @param {
|
|
66
|
-
* @param {
|
|
67
|
-
* @param {
|
|
64
|
+
* @param {Vector2|number} [pos=0] - Index of tile in sheet
|
|
65
|
+
* @param {Vector2|number} [size=tileSizeDefault] - Size of tile in pixels
|
|
66
|
+
* @param {number} [textureIndex] - Texture index to use
|
|
67
|
+
* @param {number} [padding] - How many pixels padding around tiles
|
|
68
68
|
* @return {TileInfo}
|
|
69
69
|
* @example
|
|
70
70
|
* tile(2) // a tile at index 2 using the default tile size of 16
|
|
@@ -108,8 +108,8 @@ class TileInfo
|
|
|
108
108
|
/** Create a tile info object
|
|
109
109
|
* @param {Vector2} [pos=(0,0)] - Top left corner of tile in pixels
|
|
110
110
|
* @param {Vector2} [size=tileSizeDefault] - Size of tile in pixels
|
|
111
|
-
* @param {
|
|
112
|
-
* @param {
|
|
111
|
+
* @param {number} [textureIndex] - Texture index to use
|
|
112
|
+
* @param {number} [padding] - How many pixels padding around tiles
|
|
113
113
|
*/
|
|
114
114
|
constructor(pos=vec2(), size=tileSizeDefault, textureIndex=0, padding=0)
|
|
115
115
|
{
|
|
@@ -117,9 +117,9 @@ class TileInfo
|
|
|
117
117
|
this.pos = pos.copy();
|
|
118
118
|
/** @property {Vector2} - Size of tile in pixels */
|
|
119
119
|
this.size = size.copy();
|
|
120
|
-
/** @property {
|
|
120
|
+
/** @property {number} - Texture index to use */
|
|
121
121
|
this.textureIndex = textureIndex;
|
|
122
|
-
/** @property {
|
|
122
|
+
/** @property {number} - How many pixels padding around tiles */
|
|
123
123
|
this.padding = padding;
|
|
124
124
|
}
|
|
125
125
|
|
|
@@ -131,7 +131,7 @@ class TileInfo
|
|
|
131
131
|
{ return new TileInfo(this.pos.add(offset), this.size, this.textureIndex); }
|
|
132
132
|
|
|
133
133
|
/** Returns a copy of this tile offset by a number of animation frames
|
|
134
|
-
* @param {
|
|
134
|
+
* @param {number} frame - Offset to apply in animation frames
|
|
135
135
|
* @return {TileInfo}
|
|
136
136
|
*/
|
|
137
137
|
frame(frame)
|
|
@@ -203,11 +203,11 @@ function getCameraSize() { return mainCanvasSize.scale(1/cameraScale); }
|
|
|
203
203
|
* @param {Vector2} [size=(1,1)] - Size of the tile in world space
|
|
204
204
|
* @param {TileInfo}[tileInfo] - Tile info to use, untextured if undefined
|
|
205
205
|
* @param {Color} [color=(1,1,1,1)] - Color to modulate with
|
|
206
|
-
* @param {
|
|
207
|
-
* @param {
|
|
206
|
+
* @param {number} [angle] - Angle to rotate by
|
|
207
|
+
* @param {boolean} [mirror] - If true image is flipped along the Y axis
|
|
208
208
|
* @param {Color} [additiveColor=(0,0,0,0)] - Additive color to be applied
|
|
209
|
-
* @param {
|
|
210
|
-
* @param {
|
|
209
|
+
* @param {boolean} [useWebGL=glEnable] - Use accelerated WebGL rendering
|
|
210
|
+
* @param {boolean} [screenSpace=false] - If true the pos and size are in screen space
|
|
211
211
|
* @param {CanvasRenderingContext2D|OffscreenCanvasRenderingContext2D} [context] - Canvas 2D context to draw to
|
|
212
212
|
* @memberof Draw */
|
|
213
213
|
function drawTile(pos, size=vec2(1), tileInfo, color=new Color,
|
|
@@ -282,9 +282,9 @@ function drawTile(pos, size=vec2(1), tileInfo, color=new Color,
|
|
|
282
282
|
* @param {Vector2} pos
|
|
283
283
|
* @param {Vector2} [size=(1,1)]
|
|
284
284
|
* @param {Color} [color=(1,1,1,1)]
|
|
285
|
-
* @param {
|
|
286
|
-
* @param {
|
|
287
|
-
* @param {
|
|
285
|
+
* @param {number} [angle]
|
|
286
|
+
* @param {boolean} [useWebGL=glEnable]
|
|
287
|
+
* @param {boolean} [screenSpace=false]
|
|
288
288
|
* @param {CanvasRenderingContext2D|OffscreenCanvasRenderingContext2D} [context]
|
|
289
289
|
* @memberof Draw */
|
|
290
290
|
function drawRect(pos, size, color, angle, useWebGL, screenSpace, context)
|
|
@@ -295,10 +295,10 @@ function drawRect(pos, size, color, angle, useWebGL, screenSpace, context)
|
|
|
295
295
|
/** Draw colored line between two points
|
|
296
296
|
* @param {Vector2} posA
|
|
297
297
|
* @param {Vector2} posB
|
|
298
|
-
* @param {
|
|
298
|
+
* @param {number} [thickness]
|
|
299
299
|
* @param {Color} [color=(1,1,1,1)]
|
|
300
|
-
* @param {
|
|
301
|
-
* @param {
|
|
300
|
+
* @param {boolean} [useWebGL=glEnable]
|
|
301
|
+
* @param {boolean} [screenSpace=false]
|
|
302
302
|
* @param {CanvasRenderingContext2D|OffscreenCanvasRenderingContext2D} [context]
|
|
303
303
|
* @memberof Draw */
|
|
304
304
|
function drawLine(posA, posB, thickness=.1, color, useWebGL, screenSpace, context)
|
|
@@ -309,11 +309,11 @@ function drawLine(posA, posB, thickness=.1, color, useWebGL, screenSpace, contex
|
|
|
309
309
|
}
|
|
310
310
|
|
|
311
311
|
/** Draw colored polygon using passed in points
|
|
312
|
-
* @param {Array} points - Array of Vector2 points
|
|
312
|
+
* @param {Array<Vector2>} points - Array of Vector2 points
|
|
313
313
|
* @param {Color} [color=(1,1,1,1)]
|
|
314
|
-
* @param {
|
|
314
|
+
* @param {number} [lineWidth=0]
|
|
315
315
|
* @param {Color} [lineColor=(0,0,0,1)]
|
|
316
|
-
* @param {
|
|
316
|
+
* @param {boolean} [screenSpace=false]
|
|
317
317
|
* @param {CanvasRenderingContext2D} [context=mainContext]
|
|
318
318
|
* @memberof Draw */
|
|
319
319
|
function drawPoly(points, color=new Color, lineWidth=0, lineColor=new Color(0,0,0), screenSpace, context=mainContext)
|
|
@@ -335,13 +335,13 @@ function drawPoly(points, color=new Color, lineWidth=0, lineColor=new Color(0,0,
|
|
|
335
335
|
|
|
336
336
|
/** Draw colored ellipse using passed in point
|
|
337
337
|
* @param {Vector2} pos
|
|
338
|
-
* @param {
|
|
339
|
-
* @param {
|
|
340
|
-
* @param {
|
|
338
|
+
* @param {number} [width=1]
|
|
339
|
+
* @param {number} [height=1]
|
|
340
|
+
* @param {number} [angle=0]
|
|
341
341
|
* @param {Color} [color=(1,1,1,1)]
|
|
342
|
-
* @param {
|
|
342
|
+
* @param {number} [lineWidth=0]
|
|
343
343
|
* @param {Color} [lineColor=(0,0,0,1)]
|
|
344
|
-
* @param {
|
|
344
|
+
* @param {boolean} [screenSpace=false]
|
|
345
345
|
* @param {CanvasRenderingContext2D} [context=mainContext]
|
|
346
346
|
* @memberof Draw */
|
|
347
347
|
function drawEllipse(pos, width=1, height=1, angle=0, color=new Color, lineWidth=0, lineColor=new Color(0,0,0), screenSpace, context=mainContext)
|
|
@@ -368,11 +368,11 @@ function drawEllipse(pos, width=1, height=1, angle=0, color=new Color, lineWidth
|
|
|
368
368
|
|
|
369
369
|
/** Draw colored circle using passed in point
|
|
370
370
|
* @param {Vector2} pos
|
|
371
|
-
* @param {
|
|
371
|
+
* @param {number} [radius=1]
|
|
372
372
|
* @param {Color} [color=(1,1,1,1)]
|
|
373
|
-
* @param {
|
|
373
|
+
* @param {number} [lineWidth=0]
|
|
374
374
|
* @param {Color} [lineColor=(0,0,0,1)]
|
|
375
|
-
* @param {
|
|
375
|
+
* @param {boolean} [screenSpace=false]
|
|
376
376
|
* @param {CanvasRenderingContext2D} [context=mainContext]
|
|
377
377
|
* @memberof Draw */
|
|
378
378
|
function drawCircle(pos, radius=1, color=new Color, lineWidth=0, lineColor=new Color(0,0,0), screenSpace, context=mainContext)
|
|
@@ -381,10 +381,10 @@ function drawCircle(pos, radius=1, color=new Color, lineWidth=0, lineColor=new C
|
|
|
381
381
|
/** Draw directly to a 2d canvas context in world space
|
|
382
382
|
* @param {Vector2} pos
|
|
383
383
|
* @param {Vector2} size
|
|
384
|
-
* @param {
|
|
385
|
-
* @param {
|
|
384
|
+
* @param {number} angle
|
|
385
|
+
* @param {boolean} mirror
|
|
386
386
|
* @param {Function} drawFunction
|
|
387
|
-
* @param {
|
|
387
|
+
* @param {boolean} [screenSpace=false]
|
|
388
388
|
* @param {CanvasRenderingContext2D|OffscreenCanvasRenderingContext2D} [context=mainContext]
|
|
389
389
|
* @memberof Draw */
|
|
390
390
|
function drawCanvas2D(pos, size, angle, mirror, drawFunction, screenSpace, context=mainContext)
|
|
@@ -405,15 +405,15 @@ function drawCanvas2D(pos, size, angle, mirror, drawFunction, screenSpace, conte
|
|
|
405
405
|
|
|
406
406
|
/** Draw text on main canvas in world space
|
|
407
407
|
* Automatically splits new lines into rows
|
|
408
|
-
* @param {
|
|
408
|
+
* @param {string} text
|
|
409
409
|
* @param {Vector2} pos
|
|
410
|
-
* @param {
|
|
410
|
+
* @param {number} [size]
|
|
411
411
|
* @param {Color} [color=(1,1,1,1)]
|
|
412
|
-
* @param {
|
|
412
|
+
* @param {number} [lineWidth]
|
|
413
413
|
* @param {Color} [lineColor=(0,0,0,1)]
|
|
414
414
|
* @param {CanvasTextAlign} [textAlign='center']
|
|
415
|
-
* @param {
|
|
416
|
-
* @param {
|
|
415
|
+
* @param {string} [font=fontDefault]
|
|
416
|
+
* @param {number} [maxWidth]
|
|
417
417
|
* @param {CanvasRenderingContext2D|OffscreenCanvasRenderingContext2D} [context=mainContext]
|
|
418
418
|
* @memberof Draw */
|
|
419
419
|
function drawText(text, pos, size=1, color, lineWidth=0, lineColor, textAlign, font, maxWidth, context=mainContext)
|
|
@@ -423,15 +423,15 @@ function drawText(text, pos, size=1, color, lineWidth=0, lineColor, textAlign, f
|
|
|
423
423
|
|
|
424
424
|
/** Draw text on overlay canvas in world space
|
|
425
425
|
* Automatically splits new lines into rows
|
|
426
|
-
* @param {
|
|
426
|
+
* @param {string} text
|
|
427
427
|
* @param {Vector2} pos
|
|
428
|
-
* @param {
|
|
428
|
+
* @param {number} [size]
|
|
429
429
|
* @param {Color} [color=(1,1,1,1)]
|
|
430
|
-
* @param {
|
|
430
|
+
* @param {number} [lineWidth]
|
|
431
431
|
* @param {Color} [lineColor=(0,0,0,1)]
|
|
432
432
|
* @param {CanvasTextAlign} [textAlign='center']
|
|
433
|
-
* @param {
|
|
434
|
-
* @param {
|
|
433
|
+
* @param {string} [font=fontDefault]
|
|
434
|
+
* @param {number} [maxWidth]
|
|
435
435
|
* @memberof Draw */
|
|
436
436
|
function drawTextOverlay(text, pos, size=1, color, lineWidth=0, lineColor, textAlign, font, maxWidth)
|
|
437
437
|
{
|
|
@@ -440,15 +440,15 @@ function drawTextOverlay(text, pos, size=1, color, lineWidth=0, lineColor, textA
|
|
|
440
440
|
|
|
441
441
|
/** Draw text on overlay canvas in screen space
|
|
442
442
|
* Automatically splits new lines into rows
|
|
443
|
-
* @param {
|
|
443
|
+
* @param {string} text
|
|
444
444
|
* @param {Vector2} pos
|
|
445
|
-
* @param {
|
|
445
|
+
* @param {number} [size]
|
|
446
446
|
* @param {Color} [color=(1,1,1,1)]
|
|
447
|
-
* @param {
|
|
447
|
+
* @param {number} [lineWidth]
|
|
448
448
|
* @param {Color} [lineColor=(0,0,0,1)]
|
|
449
449
|
* @param {CanvasTextAlign} [textAlign]
|
|
450
|
-
* @param {
|
|
451
|
-
* @param {
|
|
450
|
+
* @param {string} [font=fontDefault]
|
|
451
|
+
* @param {number} [maxWidth]
|
|
452
452
|
* @param {CanvasRenderingContext2D|OffscreenCanvasRenderingContext2D} [context=overlayContext]
|
|
453
453
|
* @memberof Draw */
|
|
454
454
|
function drawTextScreen(text, pos, size=1, color=new Color, lineWidth=0, lineColor=new Color(0,0,0), textAlign='center', font=fontDefault, maxWidth=undefined, context=overlayContext)
|
|
@@ -474,8 +474,8 @@ function drawTextScreen(text, pos, size=1, color=new Color, lineWidth=0, lineCol
|
|
|
474
474
|
}
|
|
475
475
|
|
|
476
476
|
/** Enable normal or additive blend mode
|
|
477
|
-
* @param {
|
|
478
|
-
* @param {
|
|
477
|
+
* @param {boolean} [additive]
|
|
478
|
+
* @param {boolean} [useWebGL=glEnable]
|
|
479
479
|
* @param {CanvasRenderingContext2D|OffscreenCanvasRenderingContext2D} [context=mainContext]
|
|
480
480
|
* @memberof Draw */
|
|
481
481
|
function setBlendMode(additive, useWebGL=glEnable, context)
|
|
@@ -542,10 +542,10 @@ class FontImage
|
|
|
542
542
|
}
|
|
543
543
|
|
|
544
544
|
/** Draw text in world space using the image font
|
|
545
|
-
* @param {
|
|
545
|
+
* @param {string} text
|
|
546
546
|
* @param {Vector2} pos
|
|
547
|
-
* @param {
|
|
548
|
-
* @param {
|
|
547
|
+
* @param {number} [scale=.25]
|
|
548
|
+
* @param {boolean} [center]
|
|
549
549
|
*/
|
|
550
550
|
drawText(text, pos, scale=1, center)
|
|
551
551
|
{
|
|
@@ -553,10 +553,10 @@ class FontImage
|
|
|
553
553
|
}
|
|
554
554
|
|
|
555
555
|
/** Draw text in screen space using the image font
|
|
556
|
-
* @param {
|
|
556
|
+
* @param {string} text
|
|
557
557
|
* @param {Vector2} pos
|
|
558
|
-
* @param {
|
|
559
|
-
* @param {
|
|
558
|
+
* @param {number} [scale]
|
|
559
|
+
* @param {boolean} [center]
|
|
560
560
|
*/
|
|
561
561
|
drawTextScreen(text, pos, scale=4, center)
|
|
562
562
|
{
|
|
@@ -594,7 +594,7 @@ class FontImage
|
|
|
594
594
|
// Display functions
|
|
595
595
|
|
|
596
596
|
/** Returns true if fullscreen mode is active
|
|
597
|
-
* @return {
|
|
597
|
+
* @return {boolean}
|
|
598
598
|
* @memberof Draw */
|
|
599
599
|
function isFullscreen() { return !!document.fullscreenElement; }
|
|
600
600
|
|
|
@@ -613,7 +613,7 @@ function toggleFullscreen()
|
|
|
613
613
|
}
|
|
614
614
|
|
|
615
615
|
/** Set the cursor style
|
|
616
|
-
* @param {
|
|
616
|
+
* @param {string} cursorStyle - CSS cursor style (auto, none, crosshair, etc)
|
|
617
617
|
* @memberof Draw */
|
|
618
618
|
function setCursor(cursorStyle = 'auto')
|
|
619
619
|
{
|
package/src/engineExport.js
CHANGED
package/src/engineInput.js
CHANGED
|
@@ -11,9 +11,9 @@
|
|
|
11
11
|
'use strict';
|
|
12
12
|
|
|
13
13
|
/** Returns true if device key is down
|
|
14
|
-
* @param {
|
|
15
|
-
* @param {
|
|
16
|
-
* @return {
|
|
14
|
+
* @param {string|number} key
|
|
15
|
+
* @param {number} [device]
|
|
16
|
+
* @return {boolean}
|
|
17
17
|
* @memberof Input */
|
|
18
18
|
function keyIsDown(key, device=0)
|
|
19
19
|
{
|
|
@@ -22,9 +22,9 @@ function keyIsDown(key, device=0)
|
|
|
22
22
|
}
|
|
23
23
|
|
|
24
24
|
/** Returns true if device key was pressed this frame
|
|
25
|
-
* @param {
|
|
26
|
-
* @param {
|
|
27
|
-
* @return {
|
|
25
|
+
* @param {string|number} key
|
|
26
|
+
* @param {number} [device]
|
|
27
|
+
* @return {boolean}
|
|
28
28
|
* @memberof Input */
|
|
29
29
|
function keyWasPressed(key, device=0)
|
|
30
30
|
{
|
|
@@ -33,9 +33,9 @@ function keyWasPressed(key, device=0)
|
|
|
33
33
|
}
|
|
34
34
|
|
|
35
35
|
/** Returns true if device key was released this frame
|
|
36
|
-
* @param {
|
|
37
|
-
* @param {
|
|
38
|
-
* @return {
|
|
36
|
+
* @param {string|number} key
|
|
37
|
+
* @param {number} [device]
|
|
38
|
+
* @return {boolean}
|
|
39
39
|
* @memberof Input */
|
|
40
40
|
function keyWasReleased(key, device=0)
|
|
41
41
|
{
|
|
@@ -58,22 +58,22 @@ function clearInput() { inputData = [[]]; touchGamepadButtons = []; }
|
|
|
58
58
|
|
|
59
59
|
/** Returns true if mouse button is down
|
|
60
60
|
* @function
|
|
61
|
-
* @param {
|
|
62
|
-
* @return {
|
|
61
|
+
* @param {number} button
|
|
62
|
+
* @return {boolean}
|
|
63
63
|
* @memberof Input */
|
|
64
64
|
const mouseIsDown = keyIsDown;
|
|
65
65
|
|
|
66
66
|
/** Returns true if mouse button was pressed
|
|
67
67
|
* @function
|
|
68
|
-
* @param {
|
|
69
|
-
* @return {
|
|
68
|
+
* @param {number} button
|
|
69
|
+
* @return {boolean}
|
|
70
70
|
* @memberof Input */
|
|
71
71
|
const mouseWasPressed = keyWasPressed;
|
|
72
72
|
|
|
73
73
|
/** Returns true if mouse button was released
|
|
74
74
|
* @function
|
|
75
|
-
* @param {
|
|
76
|
-
* @return {
|
|
75
|
+
* @param {number} button
|
|
76
|
+
* @return {boolean}
|
|
77
77
|
* @memberof Input */
|
|
78
78
|
const mouseWasReleased = keyWasReleased;
|
|
79
79
|
|
|
@@ -88,47 +88,47 @@ let mousePos = vec2();
|
|
|
88
88
|
let mousePosScreen = vec2();
|
|
89
89
|
|
|
90
90
|
/** Mouse wheel delta this frame
|
|
91
|
-
* @type {
|
|
91
|
+
* @type {number}
|
|
92
92
|
* @memberof Input */
|
|
93
93
|
let mouseWheel = 0;
|
|
94
94
|
|
|
95
95
|
/** Returns true if user is using gamepad (has more recently pressed a gamepad button)
|
|
96
|
-
* @type {
|
|
96
|
+
* @type {boolean}
|
|
97
97
|
* @memberof Input */
|
|
98
98
|
let isUsingGamepad = false;
|
|
99
99
|
|
|
100
100
|
/** Prevents input continuing to the default browser handling (false by default)
|
|
101
|
-
* @type {
|
|
101
|
+
* @type {boolean}
|
|
102
102
|
* @memberof Input */
|
|
103
103
|
let preventDefaultInput = false;
|
|
104
104
|
|
|
105
105
|
/** Returns true if gamepad button is down
|
|
106
|
-
* @param {
|
|
107
|
-
* @param {
|
|
108
|
-
* @return {
|
|
106
|
+
* @param {number} button
|
|
107
|
+
* @param {number} [gamepad]
|
|
108
|
+
* @return {boolean}
|
|
109
109
|
* @memberof Input */
|
|
110
110
|
function gamepadIsDown(button, gamepad=0)
|
|
111
111
|
{ return keyIsDown(button, gamepad+1); }
|
|
112
112
|
|
|
113
113
|
/** Returns true if gamepad button was pressed
|
|
114
|
-
* @param {
|
|
115
|
-
* @param {
|
|
116
|
-
* @return {
|
|
114
|
+
* @param {number} button
|
|
115
|
+
* @param {number} [gamepad]
|
|
116
|
+
* @return {boolean}
|
|
117
117
|
* @memberof Input */
|
|
118
118
|
function gamepadWasPressed(button, gamepad=0)
|
|
119
119
|
{ return keyWasPressed(button, gamepad+1); }
|
|
120
120
|
|
|
121
121
|
/** Returns true if gamepad button was released
|
|
122
|
-
* @param {
|
|
123
|
-
* @param {
|
|
124
|
-
* @return {
|
|
122
|
+
* @param {number} button
|
|
123
|
+
* @param {number} [gamepad]
|
|
124
|
+
* @return {boolean}
|
|
125
125
|
* @memberof Input */
|
|
126
126
|
function gamepadWasReleased(button, gamepad=0)
|
|
127
127
|
{ return keyWasReleased(button, gamepad+1); }
|
|
128
128
|
|
|
129
129
|
/** Returns gamepad stick value
|
|
130
|
-
* @param {
|
|
131
|
-
* @param {
|
|
130
|
+
* @param {number} stick
|
|
131
|
+
* @param {number} [gamepad]
|
|
132
132
|
* @return {Vector2}
|
|
133
133
|
* @memberof Input */
|
|
134
134
|
function gamepadStick(stick, gamepad=0)
|
|
@@ -331,7 +331,7 @@ function gamepadsUpdate()
|
|
|
331
331
|
///////////////////////////////////////////////////////////////////////////////
|
|
332
332
|
|
|
333
333
|
/** Pulse the vibration hardware if it exists
|
|
334
|
-
* @param {
|
|
334
|
+
* @param {number|Array} [pattern] - single value in ms or vibration interval array
|
|
335
335
|
* @memberof Input */
|
|
336
336
|
function vibrate(pattern=100)
|
|
337
337
|
{ vibrateEnable && !headlessMode && navigator && navigator.vibrate && navigator.vibrate(pattern); }
|
package/src/engineMedals.js
CHANGED
|
@@ -104,7 +104,7 @@ class Medal
|
|
|
104
104
|
/** @property {String} - Icon for the medal */
|
|
105
105
|
this.icon = icon;
|
|
106
106
|
|
|
107
|
-
/** @property {
|
|
107
|
+
/** @property {boolean} - Is the medal unlocked? */
|
|
108
108
|
this.unlocked = false;
|
|
109
109
|
|
|
110
110
|
// load the source image if provided
|
package/src/engineObject.js
CHANGED
|
@@ -35,9 +35,9 @@ class EngineObject
|
|
|
35
35
|
* @param {Vector2} [pos=(0,0)] - World space position of the object
|
|
36
36
|
* @param {Vector2} [size=(1,1)] - World space size of the object
|
|
37
37
|
* @param {TileInfo} [tileInfo] - Tile info to render object (undefined is untextured)
|
|
38
|
-
* @param {
|
|
38
|
+
* @param {number} [angle] - Angle the object is rotated by
|
|
39
39
|
* @param {Color} [color=(1,1,1,1)] - Color to apply to tile when rendered
|
|
40
|
-
* @param {
|
|
40
|
+
* @param {number} [renderOrder] - Objects sorted by renderOrder before being rendered
|
|
41
41
|
*/
|
|
42
42
|
constructor(pos=vec2(), size=vec2(1), tileInfo, angle=0, color=new Color, renderOrder=0)
|
|
43
43
|
{
|
|
@@ -53,57 +53,59 @@ class EngineObject
|
|
|
53
53
|
this.drawSize = undefined;
|
|
54
54
|
/** @property {TileInfo} - Tile info to render object (undefined is untextured) */
|
|
55
55
|
this.tileInfo = tileInfo;
|
|
56
|
-
/** @property {
|
|
56
|
+
/** @property {number} - Angle to rotate the object */
|
|
57
57
|
this.angle = angle;
|
|
58
58
|
/** @property {Color} - Color to apply when rendered */
|
|
59
59
|
this.color = color;
|
|
60
60
|
/** @property {Color} - Additive color to apply when rendered */
|
|
61
61
|
this.additiveColor = undefined;
|
|
62
|
-
/** @property {
|
|
62
|
+
/** @property {boolean} - Should it flip along y axis when rendered */
|
|
63
63
|
this.mirror = false;
|
|
64
64
|
|
|
65
65
|
// physical properties
|
|
66
|
-
/** @property {
|
|
66
|
+
/** @property {number} [mass=objectDefaultMass] - How heavy the object is, static if 0 */
|
|
67
67
|
this.mass = objectDefaultMass;
|
|
68
|
-
/** @property {
|
|
68
|
+
/** @property {number} [damping=objectDefaultDamping] - How much to slow down velocity each frame (0-1) */
|
|
69
69
|
this.damping = objectDefaultDamping;
|
|
70
|
-
/** @property {
|
|
70
|
+
/** @property {number} [angleDamping=objectDefaultAngleDamping] - How much to slow down rotation each frame (0-1) */
|
|
71
71
|
this.angleDamping = objectDefaultAngleDamping;
|
|
72
|
-
/** @property {
|
|
72
|
+
/** @property {number} [elasticity=objectDefaultElasticity] - How bouncy the object is when colliding (0-1) */
|
|
73
73
|
this.elasticity = objectDefaultElasticity;
|
|
74
|
-
/** @property {
|
|
74
|
+
/** @property {number} [friction=objectDefaultFriction] - How much friction to apply when sliding (0-1) */
|
|
75
75
|
this.friction = objectDefaultFriction;
|
|
76
|
-
/** @property {
|
|
76
|
+
/** @property {number} - How much to scale gravity by for this object */
|
|
77
77
|
this.gravityScale = 1;
|
|
78
|
-
/** @property {
|
|
78
|
+
/** @property {number} - Objects are sorted by render order */
|
|
79
79
|
this.renderOrder = renderOrder;
|
|
80
80
|
/** @property {Vector2} - Velocity of the object */
|
|
81
81
|
this.velocity = vec2();
|
|
82
|
-
/** @property {
|
|
82
|
+
/** @property {number} - Angular velocity of the object */
|
|
83
83
|
this.angleVelocity = 0;
|
|
84
|
-
/** @property {
|
|
84
|
+
/** @property {number} - Track when object was created */
|
|
85
85
|
this.spawnTime = time;
|
|
86
|
-
/** @property {Array} - List of children of this object */
|
|
86
|
+
/** @property {Array<EngineObject>} - List of children of this object */
|
|
87
87
|
this.children = [];
|
|
88
|
-
/** @property {
|
|
88
|
+
/** @property {boolean} - Limit object speed using linear or circular math */
|
|
89
89
|
this.clampSpeedLinear = true;
|
|
90
|
+
/** @property {EngineObject} - Object we are standing on, if any */
|
|
91
|
+
this.groundObject = undefined;
|
|
90
92
|
|
|
91
93
|
// parent child system
|
|
92
94
|
/** @property {EngineObject} - Parent of object if in local space */
|
|
93
95
|
this.parent = undefined;
|
|
94
96
|
/** @property {Vector2} - Local position if child */
|
|
95
97
|
this.localPos = vec2();
|
|
96
|
-
/** @property {
|
|
98
|
+
/** @property {number} - Local angle if child */
|
|
97
99
|
this.localAngle = 0;
|
|
98
100
|
|
|
99
101
|
// collision flags
|
|
100
|
-
/** @property {
|
|
102
|
+
/** @property {boolean} - Object collides with the tile collision */
|
|
101
103
|
this.collideTiles = false;
|
|
102
|
-
/** @property {
|
|
104
|
+
/** @property {boolean} - Object collides with solid objects */
|
|
103
105
|
this.collideSolidObjects = false;
|
|
104
|
-
/** @property {
|
|
106
|
+
/** @property {boolean} - Object collides with and blocks other objects */
|
|
105
107
|
this.isSolid = false;
|
|
106
|
-
/** @property {
|
|
108
|
+
/** @property {boolean} - Object collides with raycasts */
|
|
107
109
|
this.collideRaycast = false;
|
|
108
110
|
|
|
109
111
|
// add to list of objects
|
|
@@ -173,7 +175,7 @@ class EngineObject
|
|
|
173
175
|
// apply friction in local space of ground object
|
|
174
176
|
const groundSpeed = this.groundObject.velocity ? this.groundObject.velocity.x : 0;
|
|
175
177
|
this.velocity.x = groundSpeed + (this.velocity.x - groundSpeed) * this.friction;
|
|
176
|
-
this.groundObject =
|
|
178
|
+
this.groundObject = undefined;
|
|
177
179
|
//debugOverlay && debugPhysics && debugPoint(this.pos.subtract(vec2(0,this.size.y/2)), '#0f0');
|
|
178
180
|
}
|
|
179
181
|
|
|
@@ -290,18 +292,21 @@ class EngineObject
|
|
|
290
292
|
// bounce velocity
|
|
291
293
|
this.velocity.y *= -this.elasticity;
|
|
292
294
|
|
|
293
|
-
|
|
294
|
-
if (this.groundObject = wasMovingDown)
|
|
295
|
+
if (wasMovingDown)
|
|
295
296
|
{
|
|
296
297
|
// adjust position to slightly above nearest tile boundary
|
|
297
298
|
// this prevents gap between object and ground
|
|
298
299
|
const epsilon = .0001;
|
|
299
300
|
this.pos.y = (oldPos.y-this.size.y/2|0)+this.size.y/2+epsilon;
|
|
301
|
+
|
|
302
|
+
// set ground object to self for tile collision
|
|
303
|
+
this.groundObject = this;
|
|
300
304
|
}
|
|
301
305
|
else
|
|
302
306
|
{
|
|
303
307
|
// move to previous position
|
|
304
308
|
this.pos.y = oldPos.y;
|
|
309
|
+
this.groundObject = undefined;
|
|
305
310
|
}
|
|
306
311
|
}
|
|
307
312
|
if (isBlockedX)
|
|
@@ -353,19 +358,19 @@ class EngineObject
|
|
|
353
358
|
worldToLocalVector(vec) { return vec.rotate(-this.angle); }
|
|
354
359
|
|
|
355
360
|
/** Called to check if a tile collision should be resolved
|
|
356
|
-
* @param {
|
|
361
|
+
* @param {number} tileData - the value of the tile at the position
|
|
357
362
|
* @param {Vector2} pos - tile where the collision occurred
|
|
358
|
-
* @return {
|
|
363
|
+
* @return {boolean} - true if the collision should be resolved */
|
|
359
364
|
collideWithTile(tileData, pos) { return tileData > 0; }
|
|
360
365
|
|
|
361
366
|
/** Called to check if a object collision should be resolved
|
|
362
367
|
* @param {EngineObject} object - the object to test against
|
|
363
|
-
* @return {
|
|
368
|
+
* @return {boolean} - true if the collision should be resolved
|
|
364
369
|
*/
|
|
365
370
|
collideWithObject(object) { return true; }
|
|
366
371
|
|
|
367
372
|
/** How long since the object was created
|
|
368
|
-
* @return {
|
|
373
|
+
* @return {number} */
|
|
369
374
|
getAliveTime() { return time - this.spawnTime; }
|
|
370
375
|
|
|
371
376
|
/** Apply acceleration to this object (adjust velocity, not affected by mass)
|
|
@@ -377,13 +382,13 @@ class EngineObject
|
|
|
377
382
|
applyForce(force) { this.applyAcceleration(force.scale(1/this.mass)); }
|
|
378
383
|
|
|
379
384
|
/** Get the direction of the mirror
|
|
380
|
-
* @return {
|
|
385
|
+
* @return {number} -1 if this.mirror is true, or 1 if not mirrored */
|
|
381
386
|
getMirrorSign() { return this.mirror ? -1 : 1; }
|
|
382
387
|
|
|
383
388
|
/** Attaches a child to this with a given local transform
|
|
384
389
|
* @param {EngineObject} child
|
|
385
390
|
* @param {Vector2} [localPos=(0,0)]
|
|
386
|
-
* @param {
|
|
391
|
+
* @param {number} [localAngle] */
|
|
387
392
|
addChild(child, localPos=vec2(), localAngle=0)
|
|
388
393
|
{
|
|
389
394
|
ASSERT(!child.parent && !this.children.includes(child));
|
|
@@ -403,10 +408,10 @@ class EngineObject
|
|
|
403
408
|
}
|
|
404
409
|
|
|
405
410
|
/** Set how this object collides
|
|
406
|
-
* @param {
|
|
407
|
-
* @param {
|
|
408
|
-
* @param {
|
|
409
|
-
* @param {
|
|
411
|
+
* @param {boolean} [collideSolidObjects] - Does it collide with solid objects?
|
|
412
|
+
* @param {boolean} [isSolid] - Does it collide with and block other objects? (expensive in large numbers)
|
|
413
|
+
* @param {boolean} [collideTiles] - Does it collide with the tile collision?
|
|
414
|
+
* @param {boolean} [collideRaycast] - Does it collide with raycasts? */
|
|
410
415
|
setCollision(collideSolidObjects=true, isSolid=true, collideTiles=true, collideRaycast=true)
|
|
411
416
|
{
|
|
412
417
|
ASSERT(collideSolidObjects || !isSolid, 'solid objects must be set to collide');
|
|
@@ -418,7 +423,7 @@ class EngineObject
|
|
|
418
423
|
}
|
|
419
424
|
|
|
420
425
|
/** Returns string containing info about this object for debugging
|
|
421
|
-
* @return {
|
|
426
|
+
* @return {string} */
|
|
422
427
|
toString()
|
|
423
428
|
{
|
|
424
429
|
if (debug)
|