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/engine.all.js +179 -97
- package/engine/engine.all.min.js +1 -1
- package/engine/engine.all.module.js +362 -173
- package/engine/engine.all.module.min.js +1 -1
- package/engine/engine.all.release.js +173 -96
- package/engine/engine.js +47 -16
- package/engine/engineAudio.js +1 -1
- package/engine/engineDebug.js +6 -1
- package/engine/engineDraw.js +24 -26
- package/engine/engineExport.js +183 -76
- package/engine/engineInput.js +6 -1
- package/engine/engineMedals.js +1 -0
- package/engine/engineObject.js +6 -6
- package/engine/engineParticles.js +5 -5
- package/engine/engineSettings.js +46 -20
- package/engine/engineTileLayer.js +13 -12
- package/engine/engineUtilities.js +13 -7
- package/engine/engineWebGL.js +11 -2
- package/engine/index.d.ts +1788 -1615
- package/examples/breakout/game.js +3 -1
- package/examples/breakout/index.html +3 -3
- package/examples/module/index.html +1 -1
- package/examples/particles/index.html +1 -1
- package/examples/platformer/game.js +2 -0
- package/examples/platformer/gameObjects.js +3 -3
- package/examples/platformer/index.html +6 -6
- package/examples/puzzle/index.html +2 -2
- package/examples/stress/index.html +4 -4
- package/examples/typescript/game.js +89 -89
- package/examples/typescript/index.html +1 -1
- package/index.html +13 -13
- package/package.json +6 -6
package/engine/engine.js
CHANGED
|
@@ -17,43 +17,71 @@
|
|
|
17
17
|
- Call engineInit() to start it up!
|
|
18
18
|
*/
|
|
19
19
|
|
|
20
|
+
/**
|
|
21
|
+
* LittleJS Engine Globals
|
|
22
|
+
* @namespace Engine
|
|
23
|
+
*/
|
|
24
|
+
|
|
20
25
|
'use strict';
|
|
21
26
|
|
|
22
|
-
/** Name of engine
|
|
27
|
+
/** Name of engine
|
|
28
|
+
* @type {String}
|
|
29
|
+
* @default
|
|
30
|
+
* @memberof Engine */
|
|
23
31
|
const engineName = 'LittleJS';
|
|
24
32
|
|
|
25
|
-
/** Version of engine
|
|
26
|
-
|
|
33
|
+
/** Version of engine
|
|
34
|
+
* @type {String}
|
|
35
|
+
* @default
|
|
36
|
+
* @memberof Engine */
|
|
37
|
+
const engineVersion = '1.5.1';
|
|
27
38
|
|
|
28
39
|
/** Frames per second to update objects
|
|
29
|
-
* @
|
|
40
|
+
* @type {Number}
|
|
41
|
+
* @default
|
|
42
|
+
* @memberof Engine */
|
|
30
43
|
const frameRate = 60;
|
|
31
44
|
|
|
32
45
|
/** How many seconds each frame lasts, engine uses a fixed time step
|
|
33
|
-
* @
|
|
46
|
+
* @type {Number}
|
|
47
|
+
* @default 1/60
|
|
48
|
+
* @memberof Engine */
|
|
34
49
|
const timeDelta = 1/frameRate;
|
|
35
50
|
|
|
36
|
-
/** Array containing all engine objects
|
|
51
|
+
/** Array containing all engine objects
|
|
52
|
+
* @type {Array}
|
|
53
|
+
* @memberof Engine */
|
|
37
54
|
let engineObjects = [];
|
|
38
55
|
|
|
39
|
-
/** Array containing only objects that are set to collide with other objects this frame (for optimization)
|
|
56
|
+
/** Array containing only objects that are set to collide with other objects this frame (for optimization)
|
|
57
|
+
* @type {Array}
|
|
58
|
+
* @memberof Engine */
|
|
40
59
|
let engineObjectsCollide = [];
|
|
41
60
|
|
|
42
|
-
/** Current update frame, used to calculate time
|
|
61
|
+
/** Current update frame, used to calculate time
|
|
62
|
+
* @type {Number}
|
|
63
|
+
* @memberof Engine */
|
|
43
64
|
let frame = 0;
|
|
44
65
|
|
|
45
|
-
/** Current engine time since start in seconds, derived from frame
|
|
66
|
+
/** Current engine time since start in seconds, derived from frame
|
|
67
|
+
* @type {Number}
|
|
68
|
+
* @memberof Engine */
|
|
46
69
|
let time = 0;
|
|
47
70
|
|
|
48
|
-
/** Actual clock time since start in seconds (not affected by pause or frame rate clamping)
|
|
71
|
+
/** Actual clock time since start in seconds (not affected by pause or frame rate clamping)
|
|
72
|
+
* @type {Number}
|
|
73
|
+
* @memberof Engine */
|
|
49
74
|
let timeReal = 0;
|
|
50
75
|
|
|
51
|
-
/** Is the game paused? Causes time and objects to not be updated
|
|
76
|
+
/** Is the game paused? Causes time and objects to not be updated
|
|
77
|
+
* @type {Boolean}
|
|
78
|
+
* @default 0
|
|
79
|
+
* @memberof Engine */
|
|
52
80
|
let paused = 0;
|
|
53
81
|
|
|
54
82
|
/** Set if game is paused
|
|
55
83
|
* @param {Boolean} paused
|
|
56
|
-
*/
|
|
84
|
+
* @memberof Engine */
|
|
57
85
|
function setPaused(_paused) { paused = _paused; }
|
|
58
86
|
|
|
59
87
|
///////////////////////////////////////////////////////////////////////////////
|
|
@@ -65,7 +93,7 @@ function setPaused(_paused) { paused = _paused; }
|
|
|
65
93
|
* @param {Function} gameRender - Called before objects are rendered, draw any background effects that appear behind objects
|
|
66
94
|
* @param {Function} gameRenderPost - Called after objects are rendered, draw effects or hud that appear above all objects
|
|
67
95
|
* @param {String} [tileImageSource] - Tile image to use, everything starts when the image is finished loading
|
|
68
|
-
*/
|
|
96
|
+
* @memberof Engine */
|
|
69
97
|
function engineInit(gameInit, gameUpdate, gameUpdatePost, gameRender, gameRenderPost, tileImageSource)
|
|
70
98
|
{
|
|
71
99
|
// init engine when tiles load or fail to load
|
|
@@ -229,7 +257,8 @@ function enginePreRender()
|
|
|
229
257
|
glEnable && glPreRender();
|
|
230
258
|
}
|
|
231
259
|
|
|
232
|
-
/** Update each engine object, remove destroyed objects, and update time
|
|
260
|
+
/** Update each engine object, remove destroyed objects, and update time
|
|
261
|
+
* @memberof Engine */
|
|
233
262
|
function engineObjectsUpdate()
|
|
234
263
|
{
|
|
235
264
|
// get list of solid objects for physics optimzation
|
|
@@ -255,7 +284,8 @@ function engineObjectsUpdate()
|
|
|
255
284
|
time = ++frame / frameRate;
|
|
256
285
|
}
|
|
257
286
|
|
|
258
|
-
/** Destroy and remove all objects
|
|
287
|
+
/** Destroy and remove all objects
|
|
288
|
+
* @memberof Engine */
|
|
259
289
|
function engineObjectsDestroy()
|
|
260
290
|
{
|
|
261
291
|
for (const o of engineObjects)
|
|
@@ -267,7 +297,8 @@ function engineObjectsDestroy()
|
|
|
267
297
|
* @param {Vector2} [pos] - Center of test area
|
|
268
298
|
* @param {Number} [size] - Radius of circle if float, rectangle size if Vector2
|
|
269
299
|
* @param {Function} [callbackFunction] - Calls this function on every object that passes the test
|
|
270
|
-
* @param {Array} [objects=engineObjects] - List of objects to check
|
|
300
|
+
* @param {Array} [objects=engineObjects] - List of objects to check
|
|
301
|
+
* @memberof Engine */
|
|
271
302
|
function engineObjectsCallback(pos, size, callbackFunction, objects=engineObjects)
|
|
272
303
|
{
|
|
273
304
|
if (!pos) // all objects
|
package/engine/engineAudio.js
CHANGED
package/engine/engineDebug.js
CHANGED
|
@@ -16,26 +16,31 @@
|
|
|
16
16
|
'use strict';
|
|
17
17
|
|
|
18
18
|
/** True if debug is enabled
|
|
19
|
+
* @type {Boolean}
|
|
19
20
|
* @default
|
|
20
21
|
* @memberof Debug */
|
|
21
22
|
const debug = 1;
|
|
22
23
|
|
|
23
24
|
/** True if asserts are enaled
|
|
25
|
+
* @type {Boolean}
|
|
24
26
|
* @default
|
|
25
27
|
* @memberof Debug */
|
|
26
28
|
const enableAsserts = 1;
|
|
27
29
|
|
|
28
30
|
/** Size to render debug points by default
|
|
31
|
+
* @type {Number}
|
|
29
32
|
* @default
|
|
30
33
|
* @memberof Debug */
|
|
31
34
|
const debugPointSize = .5;
|
|
32
35
|
|
|
33
36
|
/** True if watermark with FPS should be down, false in release builds
|
|
37
|
+
* @type {Boolean}
|
|
34
38
|
* @default
|
|
35
39
|
* @memberof Debug */
|
|
36
40
|
let showWatermark = 1;
|
|
37
41
|
|
|
38
42
|
/** True if god mode is enabled, handle this however you want
|
|
43
|
+
* @type {Boolean}
|
|
39
44
|
* @default
|
|
40
45
|
* @memberof Debug */
|
|
41
46
|
let godMode = 0;
|
|
@@ -55,7 +60,7 @@ const ASSERT = enableAsserts ? (...assert)=> console.assert(...assert) : ()=>{};
|
|
|
55
60
|
|
|
56
61
|
/** Draw a debug rectangle in world space
|
|
57
62
|
* @param {Vector2} pos
|
|
58
|
-
* @param {Vector2} [size=
|
|
63
|
+
* @param {Vector2} [size=Vector2()]
|
|
59
64
|
* @param {String} [color='#fff']
|
|
60
65
|
* @param {Number} [time=0]
|
|
61
66
|
* @param {Number} [angle=0]
|
package/engine/engineDraw.js
CHANGED
|
@@ -78,15 +78,15 @@ const worldToScreen = (worldPos)=>
|
|
|
78
78
|
}
|
|
79
79
|
|
|
80
80
|
/** Draw textured tile centered in world space, with color applied if using WebGL
|
|
81
|
-
* @param {Vector2} pos
|
|
82
|
-
* @param {Vector2} [size=
|
|
83
|
-
* @param {Number} [tileIndex=-1]
|
|
84
|
-
* @param {Vector2} [tileSize=tileSizeDefault]
|
|
85
|
-
* @param {Color} [color=
|
|
86
|
-
* @param {Number} [angle=0]
|
|
87
|
-
* @param {Boolean} [mirror=0]
|
|
88
|
-
* @param {Color} [additiveColor=
|
|
89
|
-
* @param {Boolean} [useWebGL=glEnable]
|
|
81
|
+
* @param {Vector2} pos - Center of the tile in world space
|
|
82
|
+
* @param {Vector2} [size=Vector2(1,1)] - Size of the tile in world space
|
|
83
|
+
* @param {Number} [tileIndex=-1] - Tile index to use, negative is untextured
|
|
84
|
+
* @param {Vector2} [tileSize=tileSizeDefault] - Tile size in source pixels
|
|
85
|
+
* @param {Color} [color=Color()] - Color to modulate with
|
|
86
|
+
* @param {Number} [angle=0] - Angle to rotate by
|
|
87
|
+
* @param {Boolean} [mirror=0] - If true image is flipped along the Y axis
|
|
88
|
+
* @param {Color} [additiveColor=Color(0,0,0,0)] - Additive color to be applied
|
|
89
|
+
* @param {Boolean} [useWebGL=glEnable] - Use accelerated WebGL rendering
|
|
90
90
|
* @memberof Draw */
|
|
91
91
|
function drawTile(pos, size=vec2(1), tileIndex=-1, tileSize=tileSizeDefault, color=new Color, angle=0, mirror,
|
|
92
92
|
additiveColor=new Color(0,0,0,0), useWebGL=glEnable)
|
|
@@ -141,8 +141,8 @@ function drawTile(pos, size=vec2(1), tileIndex=-1, tileSize=tileSizeDefault, col
|
|
|
141
141
|
|
|
142
142
|
/** Draw colored rect centered on pos
|
|
143
143
|
* @param {Vector2} pos
|
|
144
|
-
* @param {Vector2} [size=
|
|
145
|
-
* @param {Color} [color=
|
|
144
|
+
* @param {Vector2} [size=Vector2(1,1)]
|
|
145
|
+
* @param {Color} [color=Color()]
|
|
146
146
|
* @param {Number} [angle=0]
|
|
147
147
|
* @param {Boolean} [useWebGL=glEnable]
|
|
148
148
|
* @memberof Draw */
|
|
@@ -153,13 +153,13 @@ function drawRect(pos, size, color, angle, useWebGL)
|
|
|
153
153
|
|
|
154
154
|
/** Draw textured tile centered on pos in screen space
|
|
155
155
|
* @param {Vector2} pos - Center of the tile
|
|
156
|
-
* @param {Vector2} [size=
|
|
156
|
+
* @param {Vector2} [size=Vector2(1,1)] - Size of the tile
|
|
157
157
|
* @param {Number} [tileIndex=-1] - Tile index to use, negative is untextured
|
|
158
158
|
* @param {Vector2} [tileSize=tileSizeDefault] - Tile size in source pixels
|
|
159
|
-
* @param {Color} [color=
|
|
159
|
+
* @param {Color} [color=Color()]
|
|
160
160
|
* @param {Number} [angle=0]
|
|
161
161
|
* @param {Boolean} [mirror=0]
|
|
162
|
-
* @param {Color} [additiveColor=
|
|
162
|
+
* @param {Color} [additiveColor=Color(0,0,0,0)]
|
|
163
163
|
* @param {Boolean} [useWebGL=glEnable]
|
|
164
164
|
* @memberof Draw */
|
|
165
165
|
function drawTileScreenSpace(pos, size=vec2(1), tileIndex, tileSize, color, angle, mirror, additiveColor, useWebGL)
|
|
@@ -169,8 +169,8 @@ function drawTileScreenSpace(pos, size=vec2(1), tileIndex, tileSize, color, angl
|
|
|
169
169
|
|
|
170
170
|
/** Draw colored rectangle in screen space
|
|
171
171
|
* @param {Vector2} pos
|
|
172
|
-
* @param {Vector2} [size=
|
|
173
|
-
* @param {Color} [color=
|
|
172
|
+
* @param {Vector2} [size=Vector2(1,1)]
|
|
173
|
+
* @param {Color} [color=Color()]
|
|
174
174
|
* @param {Number} [angle=0]
|
|
175
175
|
* @param {Boolean} [useWebGL=glEnable]
|
|
176
176
|
* @memberof Draw */
|
|
@@ -183,7 +183,7 @@ function drawRectScreenSpace(pos, size, color, angle, useWebGL)
|
|
|
183
183
|
* @param {Vector2} posA
|
|
184
184
|
* @param {Vector2} posB
|
|
185
185
|
* @param {Number} [thickness=.1]
|
|
186
|
-
* @param {Color} [color=
|
|
186
|
+
* @param {Color} [color=Color()]
|
|
187
187
|
* @param {Boolean} [useWebGL=glEnable]
|
|
188
188
|
* @memberof Draw */
|
|
189
189
|
function drawLine(posA, posB, thickness=.1, color, useWebGL)
|
|
@@ -231,9 +231,9 @@ function setBlendMode(additive, useWebGL=glEnable)
|
|
|
231
231
|
* @param {String} text
|
|
232
232
|
* @param {Vector2} pos
|
|
233
233
|
* @param {Number} [size=1]
|
|
234
|
-
* @param {Color} [color=
|
|
234
|
+
* @param {Color} [color=Color()]
|
|
235
235
|
* @param {Number} [lineWidth=0]
|
|
236
|
-
* @param {Color} [lineColor=
|
|
236
|
+
* @param {Color} [lineColor=Color(0,0,0)]
|
|
237
237
|
* @param {String} [textAlign='center']
|
|
238
238
|
* @memberof Draw */
|
|
239
239
|
function drawTextScreen(text, pos, size=1, color=new Color, lineWidth=0, lineColor=new Color(0,0,0), textAlign='center', font=fontDefault, context=overlayContext)
|
|
@@ -260,18 +260,20 @@ function drawTextScreen(text, pos, size=1, color=new Color, lineWidth=0, lineCol
|
|
|
260
260
|
* @param {String} text
|
|
261
261
|
* @param {Vector2} pos
|
|
262
262
|
* @param {Number} [size=1]
|
|
263
|
-
* @param {Color} [color=
|
|
263
|
+
* @param {Color} [color=Color()]
|
|
264
264
|
* @param {Number} [lineWidth=0]
|
|
265
|
-
* @param {Color} [lineColor=
|
|
265
|
+
* @param {Color} [lineColor=Color(0,0,0)]
|
|
266
266
|
* @param {String} [textAlign='center']
|
|
267
267
|
* @memberof Draw */
|
|
268
|
-
function drawText(text, pos, size=1, color, lineWidth, lineColor, textAlign, font)
|
|
268
|
+
function drawText(text, pos, size=1, color, lineWidth=0, lineColor, textAlign, font)
|
|
269
269
|
{
|
|
270
270
|
drawTextScreen(text, worldToScreen(pos), size*cameraScale, color, lineWidth*cameraScale, lineColor, textAlign, font, mainContext);
|
|
271
271
|
}
|
|
272
272
|
|
|
273
273
|
///////////////////////////////////////////////////////////////////////////////
|
|
274
274
|
|
|
275
|
+
let engineFontImage;
|
|
276
|
+
|
|
275
277
|
/**
|
|
276
278
|
* Font Image Object - Draw text on a 2D canvas by using characters in an image
|
|
277
279
|
* <br> - 96 characters (from space to tilde) are stored in an image
|
|
@@ -284,10 +286,6 @@ function drawText(text, pos, size=1, color, lineWidth, lineColor, textAlign, fon
|
|
|
284
286
|
* // draw text
|
|
285
287
|
* font.drawTextScreen("LittleJS\nHello World!", vec2(200, 50));
|
|
286
288
|
*/
|
|
287
|
-
|
|
288
|
-
// default font image created by engine
|
|
289
|
-
let engineFontImage;
|
|
290
|
-
|
|
291
289
|
class FontImage
|
|
292
290
|
{
|
|
293
291
|
/** Create an image font
|
package/engine/engineExport.js
CHANGED
|
@@ -4,43 +4,187 @@
|
|
|
4
4
|
*/
|
|
5
5
|
|
|
6
6
|
// Setters for all variables that devs will need to modify
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
const
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
const
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
const
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
const
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
const
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
const
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
const
|
|
43
|
-
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
/** Set position of camera in world space
|
|
10
|
+
* @param {Vector2} pos
|
|
11
|
+
* @memberof Settings */
|
|
12
|
+
const setCameraPos = (pos)=> cameraPos = pos;
|
|
13
|
+
|
|
14
|
+
/** Set scale of camera in world space
|
|
15
|
+
* @param {Number} scale
|
|
16
|
+
* @memberof Settings */
|
|
17
|
+
const setCameraScale = (scale)=> cameraScale = scale;
|
|
18
|
+
|
|
19
|
+
/** Set max size of the canvas
|
|
20
|
+
* @param {Vector2} size
|
|
21
|
+
* @memberof Settings */
|
|
22
|
+
const setCanvasMaxSize = (size)=> canvasMaxSize = size;
|
|
23
|
+
|
|
24
|
+
/** Set fixed size of the canvas
|
|
25
|
+
* @param {Vector2} size
|
|
26
|
+
* @memberof Settings */
|
|
27
|
+
const setCanvasFixedSize = (size)=> canvasFixedSize = size;
|
|
28
|
+
|
|
29
|
+
/** Disables anti aliasing for pixel art if true
|
|
30
|
+
* @param {Boolean} pixelated
|
|
31
|
+
* @memberof Settings */
|
|
32
|
+
const setCavasPixelated = (pixelated)=> cavasPixelated = pixelated;
|
|
33
|
+
|
|
34
|
+
/** Set default font used for text rendering
|
|
35
|
+
* @param {String} font
|
|
36
|
+
* @memberof Settings */
|
|
37
|
+
const setFontDefault = (font)=> fontDefault = font;
|
|
38
|
+
|
|
39
|
+
/** Set if webgl rendering is enabled
|
|
40
|
+
* @param {Boolean} enable
|
|
41
|
+
* @memberof Settings */
|
|
42
|
+
const setGlEnable = (enable)=> glEnable = enable;
|
|
43
|
+
|
|
44
|
+
/** Set to not composite the WebGL canvas
|
|
45
|
+
* @param {Boolean} overlay
|
|
46
|
+
* @memberof Settings */
|
|
47
|
+
const setGlOverlay = (overlay)=> glOverlay = overlay;
|
|
48
|
+
|
|
49
|
+
/** Set default size of tiles in pixels
|
|
50
|
+
* @param {Vector2} size
|
|
51
|
+
* @memberof Settings */
|
|
52
|
+
const setTileSizeDefault = (size)=> tileSizeDefault = size;
|
|
53
|
+
|
|
54
|
+
/** Set to prevent tile bleeding from neighbors in pixels
|
|
55
|
+
* @param {Number} scale
|
|
56
|
+
* @memberof Settings */
|
|
57
|
+
const setTileFixBleedScale = (scale)=> tileFixBleedScale = scale;
|
|
58
|
+
|
|
59
|
+
/** Set if collisions between objects are enabled
|
|
60
|
+
* @param {Boolean} enable
|
|
61
|
+
* @memberof Settings */
|
|
62
|
+
const setEnablePhysicsSolver = (enable)=> enablePhysicsSolver = enable;
|
|
63
|
+
|
|
64
|
+
/** Set default object mass for collison calcuations
|
|
65
|
+
* @param {Number} mass
|
|
66
|
+
* @memberof Settings */
|
|
67
|
+
const setObjectDefaultMass = (mass)=> objectDefaultMass = mass;
|
|
68
|
+
|
|
69
|
+
/** Set how much to slow velocity by each frame
|
|
70
|
+
* @param {Number} damping
|
|
71
|
+
* @memberof Settings */
|
|
72
|
+
const setObjectDefaultDamping = (damp)=> objectDefaultDamping = damp;
|
|
73
|
+
|
|
74
|
+
/** Set how much to slow angular velocity each frame
|
|
75
|
+
* @param {Number} damping
|
|
76
|
+
* @memberof Settings */
|
|
77
|
+
const setObjectDefaultAngleDamping = (damp)=> objectDefaultAngleDamping = damp;
|
|
78
|
+
|
|
79
|
+
/** Set how much to bounce when a collision occur
|
|
80
|
+
* @param {Number} elasticity
|
|
81
|
+
* @memberof Settings */
|
|
82
|
+
const setObjectDefaultElasticity = (elasticity)=> objectDefaultElasticity = elasticity;
|
|
83
|
+
|
|
84
|
+
/** Set how much to slow when touching
|
|
85
|
+
* @param {Number} friction
|
|
86
|
+
* @memberof Settings */
|
|
87
|
+
const setObjectDefaultFriction = (friction)=> objectDefaultFriction = friction;
|
|
88
|
+
|
|
89
|
+
/** Set max speed to avoid fast objects missing collisions
|
|
90
|
+
* @param {Number} speed
|
|
91
|
+
* @memberof Settings */
|
|
92
|
+
const setObjectMaxSpeed = (speed)=> objectMaxSpeed = speed;
|
|
93
|
+
|
|
94
|
+
/** Set how much gravity to apply to objects along the Y axis
|
|
95
|
+
* @param {Number} gravity
|
|
96
|
+
* @memberof Settings */
|
|
97
|
+
const setGravity = (g)=> gravity = g;
|
|
98
|
+
|
|
99
|
+
/** Set to scales emit rate of particles
|
|
100
|
+
* @param {Number} scale
|
|
101
|
+
* @memberof Settings */
|
|
102
|
+
const setParticleEmitRateScale = (scale)=> particleEmitRateScale = scale;
|
|
103
|
+
|
|
104
|
+
/** Set if gamepads are enabled
|
|
105
|
+
* @param {Boolean} enable
|
|
106
|
+
* @memberof Settings */
|
|
107
|
+
const setGamepadsEnable = (enable)=> gamepadsEnable = enable;
|
|
108
|
+
|
|
109
|
+
/** Set if the dpad input is also routed to the left analog stick
|
|
110
|
+
* @param {Boolean} enable
|
|
111
|
+
* @memberof Settings */
|
|
112
|
+
const setGamepadDirectionEmulateStick = (enable)=> gamepadDirectionEmulateStick = enable;
|
|
113
|
+
|
|
114
|
+
/** Set if true the WASD keys are also routed to the direction keys
|
|
115
|
+
* @param {Boolean} enable
|
|
116
|
+
* @memberof Settings */
|
|
117
|
+
const setInputWASDEmulateDirection = (enable)=> inputWASDEmulateDirection = enable;
|
|
118
|
+
|
|
119
|
+
/** Set if touch gamepad should appear on mobile devices
|
|
120
|
+
* @param {Boolean} enable
|
|
121
|
+
* @memberof Settings */
|
|
122
|
+
const setTouchGamepadEnable = (enable)=> touchGamepadEnable = enable;
|
|
123
|
+
|
|
124
|
+
/** Set if touch gamepad should be analog stick or 8 way dpad
|
|
125
|
+
* @param {Boolean} analog
|
|
126
|
+
* @memberof Settings */
|
|
127
|
+
const setTouchGamepadAnalog = (analog)=> touchGamepadAnalog = analog;
|
|
128
|
+
|
|
129
|
+
/** Set size of virutal gamepad for touch devices in pixels
|
|
130
|
+
* @param {Number} size
|
|
131
|
+
* @memberof Settings */
|
|
132
|
+
const setTouchGamepadSize = (size)=> touchGamepadSize = size;
|
|
133
|
+
|
|
134
|
+
/** Set transparency of touch gamepad overlay
|
|
135
|
+
* @param {Number} alpha
|
|
136
|
+
* @memberof Settings */
|
|
137
|
+
const setTouchGamepadAlpha = (alpha)=> touchGamepadAlpha = alpha;
|
|
138
|
+
|
|
139
|
+
/** Set to allow vibration hardware if it exists
|
|
140
|
+
* @param {Boolean} enable
|
|
141
|
+
* @memberof Settings */
|
|
142
|
+
const setVibrateEnable = (enable)=> vibrateEnable = enable;
|
|
143
|
+
|
|
144
|
+
/** Set to disable all audio code
|
|
145
|
+
* @param {Boolean} enable
|
|
146
|
+
* @memberof Settings */
|
|
147
|
+
const setSoundEnable = (enable)=> soundEnable = enable;
|
|
148
|
+
|
|
149
|
+
/** Set volume scale to apply to all sound, music and speech
|
|
150
|
+
* @param {Number} volume
|
|
151
|
+
* @memberof Settings */
|
|
152
|
+
const setSoundVolume = (volume)=> soundVolume = volume;
|
|
153
|
+
|
|
154
|
+
/** Set default range where sound no longer plays
|
|
155
|
+
* @param {Number} range
|
|
156
|
+
* @memberof Settings */
|
|
157
|
+
const setSoundDefaultRange = (range)=> soundDefaultRange = range;
|
|
158
|
+
|
|
159
|
+
/** Set default range percent to start tapering off sound
|
|
160
|
+
* @param {Number} taper
|
|
161
|
+
* @memberof Settings */
|
|
162
|
+
const setSoundDefaultTaper = (taper)=> soundDefaultTaper = taper;
|
|
163
|
+
|
|
164
|
+
/** Set how long to show medals for in seconds
|
|
165
|
+
* @param {Number} time
|
|
166
|
+
* @memberof Settings */
|
|
167
|
+
const setMedalDisplayTime = (time)=> medalDisplayTime = time;
|
|
168
|
+
|
|
169
|
+
/** Set how quickly to slide on/off medals in seconds
|
|
170
|
+
* @param {Number} time
|
|
171
|
+
* @memberof Settings */
|
|
172
|
+
const setMedalDisplaySlideTime = (time)=> medalDisplaySlideTime = time;
|
|
173
|
+
|
|
174
|
+
/** Set size of medal display
|
|
175
|
+
* @param {Vector2} size
|
|
176
|
+
* @memberof Settings */
|
|
177
|
+
const setMedalDisplaySize = (size)=> medalDisplaySize = size;
|
|
178
|
+
|
|
179
|
+
/** Set size of icon in medal display
|
|
180
|
+
* @param {Number} size
|
|
181
|
+
* @memberof Settings */
|
|
182
|
+
const setMedalDisplayIconSize = (size)=> medalDisplayIconSize = size;
|
|
183
|
+
|
|
184
|
+
/** Set to stop medals from being unlockable
|
|
185
|
+
* @param {Boolean} preventUnlock
|
|
186
|
+
* @memberof Settings */
|
|
187
|
+
const setMedalsPreventUnlock = (prevent)=> medalsPreventUnlock = prevent;
|
|
44
188
|
|
|
45
189
|
export {
|
|
46
190
|
// Setters for global variables
|
|
@@ -54,7 +198,6 @@ export {
|
|
|
54
198
|
setGlOverlay,
|
|
55
199
|
setTileSizeDefault,
|
|
56
200
|
setTileFixBleedScale,
|
|
57
|
-
setObjectDefaultSize,
|
|
58
201
|
setEnablePhysicsSolver,
|
|
59
202
|
setObjectDefaultMass,
|
|
60
203
|
setObjectDefaultDamping,
|
|
@@ -89,7 +232,6 @@ export {
|
|
|
89
232
|
fontDefault,
|
|
90
233
|
tileSizeDefault,
|
|
91
234
|
tileFixBleedScale,
|
|
92
|
-
objectDefaultSize,
|
|
93
235
|
enablePhysicsSolver,
|
|
94
236
|
objectDefaultMass,
|
|
95
237
|
objectDefaultDamping,
|
|
@@ -124,17 +266,9 @@ export {
|
|
|
124
266
|
debug,
|
|
125
267
|
showWatermark,
|
|
126
268
|
godMode,
|
|
269
|
+
|
|
127
270
|
// Debug
|
|
128
|
-
|
|
129
|
-
//debugOverlay,
|
|
130
|
-
//debugPhysics,
|
|
131
|
-
//debugRaycast,
|
|
132
|
-
//debugParticles,
|
|
133
|
-
//debugGamepads,
|
|
134
|
-
//debugMedals,
|
|
135
|
-
//debugTakeScreenshot,
|
|
136
|
-
//downloadLink,
|
|
137
|
-
//ASSERT,
|
|
271
|
+
ASSERT,
|
|
138
272
|
debugRect,
|
|
139
273
|
debugCircle,
|
|
140
274
|
debugPoint,
|
|
@@ -143,9 +277,6 @@ export {
|
|
|
143
277
|
debugText,
|
|
144
278
|
debugClear,
|
|
145
279
|
debugSaveCanvas,
|
|
146
|
-
//debugInit,
|
|
147
|
-
//debugUpdate,
|
|
148
|
-
//debugRender,
|
|
149
280
|
|
|
150
281
|
// Utilities
|
|
151
282
|
PI,
|
|
@@ -225,18 +356,6 @@ export {
|
|
|
225
356
|
gamepadWasPressed,
|
|
226
357
|
gamepadWasReleased,
|
|
227
358
|
gamepadStick,
|
|
228
|
-
//inputData,
|
|
229
|
-
//inputUpdate,
|
|
230
|
-
//inputUpdatePost,
|
|
231
|
-
// onkeydown,
|
|
232
|
-
// onkeyup,
|
|
233
|
-
//remapKeyCode,
|
|
234
|
-
// onmousedown,
|
|
235
|
-
// onmouseup,
|
|
236
|
-
// onmousemove,
|
|
237
|
-
// onwheel,
|
|
238
|
-
// oncontextmenu,
|
|
239
|
-
//stickData,
|
|
240
359
|
mouseToScreen,
|
|
241
360
|
gamepadsUpdate,
|
|
242
361
|
vibrate,
|
|
@@ -253,9 +372,6 @@ export {
|
|
|
253
372
|
audioContext,
|
|
254
373
|
playSamples,
|
|
255
374
|
zzfx,
|
|
256
|
-
//zzfxR,
|
|
257
|
-
//zzfxG,
|
|
258
|
-
//zzfxM,
|
|
259
375
|
|
|
260
376
|
// Tiles
|
|
261
377
|
tileCollision,
|
|
@@ -278,25 +394,17 @@ export {
|
|
|
278
394
|
medalsInit,
|
|
279
395
|
newgroundsInit,
|
|
280
396
|
Medal,
|
|
281
|
-
//medalsRender,
|
|
282
397
|
Newgrounds,
|
|
283
|
-
//CryptoJS,
|
|
284
398
|
|
|
285
399
|
// WebGL
|
|
286
400
|
glCanvas,
|
|
287
401
|
glContext,
|
|
288
|
-
//glInit,
|
|
289
402
|
glSetBlendMode,
|
|
290
403
|
glSetTexture,
|
|
291
404
|
glCompileShader,
|
|
292
405
|
glCreateProgram,
|
|
293
406
|
glCreateTexture,
|
|
294
|
-
//glPreRender,
|
|
295
|
-
//glFlush,
|
|
296
|
-
//glCopyToContext,
|
|
297
|
-
//glDraw,
|
|
298
407
|
glInitPostProcess,
|
|
299
|
-
//glRenderPostProcess,
|
|
300
408
|
|
|
301
409
|
// Engine
|
|
302
410
|
engineName,
|
|
@@ -304,7 +412,6 @@ export {
|
|
|
304
412
|
frameRate,
|
|
305
413
|
timeDelta,
|
|
306
414
|
engineObjects,
|
|
307
|
-
//engineObjectsCollide,
|
|
308
415
|
frame,
|
|
309
416
|
time,
|
|
310
417
|
timeReal,
|
package/engine/engineInput.js
CHANGED
|
@@ -35,18 +35,21 @@ const keyWasReleased = (key, device=0)=> inputData[device] && inputData[device][
|
|
|
35
35
|
const clearInput = ()=> inputData = [[]];
|
|
36
36
|
|
|
37
37
|
/** Returns true if mouse button is down
|
|
38
|
+
* @function
|
|
38
39
|
* @param {Number} button
|
|
39
40
|
* @return {Boolean}
|
|
40
41
|
* @memberof Input */
|
|
41
42
|
const mouseIsDown = keyIsDown;
|
|
42
43
|
|
|
43
44
|
/** Returns true if mouse button was pressed
|
|
45
|
+
* @function
|
|
44
46
|
* @param {Number} button
|
|
45
47
|
* @return {Boolean}
|
|
46
48
|
* @memberof Input */
|
|
47
49
|
const mouseWasPressed = keyWasPressed;
|
|
48
50
|
|
|
49
51
|
/** Returns true if mouse button was released
|
|
52
|
+
* @function
|
|
50
53
|
* @param {Number} button
|
|
51
54
|
* @return {Boolean}
|
|
52
55
|
* @memberof Input */
|
|
@@ -63,14 +66,17 @@ let mousePos = vec2();
|
|
|
63
66
|
let mousePosScreen = vec2();
|
|
64
67
|
|
|
65
68
|
/** Mouse wheel delta this frame
|
|
69
|
+
* @type {Number}
|
|
66
70
|
* @memberof Input */
|
|
67
71
|
let mouseWheel = 0;
|
|
68
72
|
|
|
69
73
|
/** Returns true if user is using gamepad (has more recently pressed a gamepad button)
|
|
74
|
+
* @type {Boolean}
|
|
70
75
|
* @memberof Input */
|
|
71
76
|
let isUsingGamepad = 0;
|
|
72
77
|
|
|
73
78
|
/** Prevents input continuing to the default browser handling (false by default)
|
|
79
|
+
* @type {Boolean}
|
|
74
80
|
* @memberof Input */
|
|
75
81
|
let preventDefaultInput = 0;
|
|
76
82
|
|
|
@@ -246,7 +252,6 @@ const vibrateStop = ()=> vibrate(0);
|
|
|
246
252
|
// Touch input
|
|
247
253
|
|
|
248
254
|
/** True if a touch device has been detected
|
|
249
|
-
* @const {Boolean}
|
|
250
255
|
* @memberof Input */
|
|
251
256
|
const isTouchDevice = window.ontouchstart !== undefined;
|
|
252
257
|
|