littlejsengine 1.4.91 → 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.
Files changed (41) hide show
  1. package/README.md +1 -0
  2. package/build.bat +4 -6
  3. package/engine/engine.all.js +202 -105
  4. package/engine/engine.all.min.js +1 -1
  5. package/engine/engine.all.module.js +385 -181
  6. package/engine/engine.all.module.min.js +1 -1
  7. package/engine/engine.all.release.js +192 -100
  8. package/engine/engine.js +47 -16
  9. package/engine/engineAudio.js +14 -1
  10. package/engine/engineBuild.bat +8 -8
  11. package/engine/engineDebug.js +10 -5
  12. package/engine/engineDraw.js +25 -27
  13. package/engine/engineExport.js +183 -76
  14. package/engine/engineInput.js +6 -1
  15. package/engine/engineMedals.js +1 -0
  16. package/engine/engineObject.js +11 -9
  17. package/engine/engineParticles.js +5 -5
  18. package/engine/engineSettings.js +46 -20
  19. package/engine/engineTileLayer.js +13 -12
  20. package/engine/engineUtilities.js +13 -7
  21. package/engine/engineWebGL.js +11 -2
  22. package/engine/index.d.ts +1788 -1700
  23. package/examples/breakout/game.js +3 -1
  24. package/examples/breakout/index.html +4 -4
  25. package/examples/empty/index.html +1 -4
  26. package/examples/module/game.js +1 -4
  27. package/examples/module/index.html +2 -2
  28. package/examples/particles/index.html +2 -2
  29. package/examples/platformer/game.js +2 -0
  30. package/examples/platformer/gameObjects.js +3 -3
  31. package/examples/platformer/index.html +7 -7
  32. package/examples/puzzle/index.html +3 -3
  33. package/examples/stress/index.html +5 -5
  34. package/examples/typescript/build.bat +14 -0
  35. package/examples/typescript/game.js +89 -0
  36. package/examples/typescript/game.ts +117 -0
  37. package/examples/typescript/index.html +9 -0
  38. package/examples/typescript/tiles.png +0 -0
  39. package/examples/typescript/tsconfig.json +8 -0
  40. package/index.html +14 -14
  41. package/package.json +6 -6
@@ -4,43 +4,187 @@
4
4
  */
5
5
 
6
6
  // Setters for all variables that devs will need to modify
7
- const setCameraPos = (v)=> cameraPos = v;
8
- const setCameraScale = (v)=> cameraScale = v;
9
- const setCanvasMaxSize = (v)=> canvasMaxSize = v;
10
- const setCanvasFixedSize = (v)=> canvasFixedSize = v;
11
- const setCavasPixelated = (v)=> cavasPixelated = v;
12
- const setFontDefault = (v)=> fontDefault = v;
13
- const setGlEnable = (v)=> glEnable = v;
14
- const setGlOverlay = (v)=> glOverlay = v;
15
- const setTileSizeDefault = (v)=> tileSizeDefault = v;
16
- const setTileFixBleedScale = (v)=> tileFixBleedScale = v;
17
- const setObjectDefaultSize = (v)=> objectDefaultSize = v;
18
- const setEnablePhysicsSolver = (v)=> enablePhysicsSolver = v;
19
- const setObjectDefaultMass = (v)=> objectDefaultMass = v;
20
- const setObjectDefaultDamping = (v)=> objectDefaultDamping = v;
21
- const setObjectDefaultAngleDamping = (v)=> objectDefaultAngleDamping = v;
22
- const setObjectDefaultElasticity = (v)=> objectDefaultElasticity = v;
23
- const setObjectDefaultFriction = (v)=> objectDefaultFriction = v;
24
- const setObjectMaxSpeed = (v)=> objectMaxSpeed = v;
25
- const setGravity = (v)=> gravity = v;
26
- const setParticleEmitRateScale = (v)=> particleEmitRateScale = v;
27
- const setGamepadsEnable = (v)=> gamepadsEnable = v;
28
- const setGamepadDirectionEmulateStick = (v)=> gamepadDirectionEmulateStick = v;
29
- const setInputWASDEmulateDirection = (v)=> inputWASDEmulateDirection = v;
30
- const setTouchGamepadEnable = (v)=> touchGamepadEnable = v;
31
- const setTouchGamepadAnalog = (v)=> touchGamepadAnalog = v;
32
- const setTouchGamepadSize = (v)=> touchGamepadSize = v;
33
- const setTouchGamepadAlpha = (v)=> touchGamepadAlpha = v;
34
- const setVibrateEnable = (v)=> vibrateEnable = v;
35
- const setSoundEnable = (v)=> soundEnable = v;
36
- const setSoundVolume = (v)=> soundVolume = v;
37
- const setSoundDefaultRange = (v)=> soundDefaultRange = v;
38
- const setSoundDefaultTaper = (v)=> soundDefaultTaper = v;
39
- const setMedalDisplayTime = (v)=> medalDisplayTime = v;
40
- const setMedalDisplaySlideTime = (v)=> medalDisplaySlideTime = v;
41
- const setMedalDisplaySize = (v)=> medalDisplaySize = v;
42
- const setMedalDisplayIconSize = (v)=> medalDisplayIconSize = v;
43
- const setMedalsPreventUnlock = (v)=> medalsPreventUnlock = v;
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
- //debugPrimitives,
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,
@@ -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
 
@@ -9,6 +9,7 @@
9
9
  'use strict';
10
10
 
11
11
  /** List of all medals
12
+ * @type {Array}
12
13
  * @memberof Medals */
13
14
  const medals = [];
14
15
 
@@ -32,15 +32,15 @@
32
32
  class EngineObject
33
33
  {
34
34
  /** Create an engine object and adds it to the list of objects
35
- * @param {Vector2} [position=new Vector2()] - World space position of the object
36
- * @param {Vector2} [size=objectDefaultSize] - World space size of the object
35
+ * @param {Vector2} [position=Vector2()] - World space position of the object
36
+ * @param {Vector2} [size=Vector2(1,1)] - World space size of the object
37
37
  * @param {Number} [tileIndex=-1] - Tile to use to render object (-1 is untextured)
38
38
  * @param {Vector2} [tileSize=tileSizeDefault] - Size of tile in source pixels
39
39
  * @param {Number} [angle=0] - Angle the object is rotated by
40
- * @param {Color} [color] - Color to apply to tile when rendered
40
+ * @param {Color} [color=Color()] - Color to apply to tile when rendered
41
41
  * @param {Number} [renderOrder=0] - Objects sorted by renderOrder before being rendered
42
42
  */
43
- constructor(pos=vec2(), size=objectDefaultSize, tileIndex=-1, tileSize=tileSizeDefault, angle=0, color, renderOrder=0)
43
+ constructor(pos=vec2(), size=vec2(1), tileIndex=-1, tileSize=tileSizeDefault, angle=0, color, renderOrder=0)
44
44
  {
45
45
  // set passed in params
46
46
  ASSERT(isVector2(pos) && isVector2(size)); // ensure pos and size are vec2s
@@ -77,7 +77,7 @@ class EngineObject
77
77
  this.gravityScale = 1;
78
78
  /** @property {Number} [renderOrder=0] - Objects are sorted by render order */
79
79
  this.renderOrder = renderOrder;
80
- /** @property {Vector2} [velocity=new Vector2()] - Velocity of the object */
80
+ /** @property {Vector2} [velocity=Vector2()] - Velocity of the object */
81
81
  this.velocity = new Vector2();
82
82
  /** @property {Number} [angleVelocity=0] - Angular velocity of the object */
83
83
  this.angleVelocity = 0;
@@ -320,7 +320,7 @@ class EngineObject
320
320
 
321
321
  /** Attaches a child to this with a given local transform
322
322
  * @param {EngineObject} child
323
- * @param {Vector2} [localPos=new Vector2]
323
+ * @param {Vector2} [localPos=Vector2()]
324
324
  * @param {Number} [localAngle=0] */
325
325
  addChild(child, localPos=vec2(), localAngle=0)
326
326
  {
@@ -341,9 +341,9 @@ class EngineObject
341
341
  }
342
342
 
343
343
  /** Set how this object collides
344
- * @param {boolean} [collideSolidObjects=1] - Does it collide with solid objects
345
- * @param {boolean} [isSolid=1] - Does it collide with and block other objects (expensive in large numbers)
346
- * @param {boolean} [collideTiles=1] - Does it collide with the tile collision */
344
+ * @param {Boolean} [collideSolidObjects=1] - Does it collide with solid objects
345
+ * @param {Boolean} [isSolid=1] - Does it collide with and block other objects (expensive in large numbers)
346
+ * @param {Boolean} [collideTiles=1] - Does it collide with the tile collision */
347
347
  setCollision(collideSolidObjects=1, isSolid=1, collideTiles=1)
348
348
  {
349
349
  ASSERT(collideSolidObjects || !isSolid); // solid objects must be set to collide
@@ -353,6 +353,8 @@ class EngineObject
353
353
  this.collideTiles = collideTiles;
354
354
  }
355
355
 
356
+ /** Returns string containg info about this object for debugging
357
+ * @return {String} */
356
358
  toString()
357
359
  {
358
360
  if (debug)
@@ -34,11 +34,11 @@ class ParticleEmitter extends EngineObject
34
34
  * @param {Number} [emitRate=100] - How many particles per second to spawn, does not emit if 0
35
35
  * @param {Number} [emitConeAngle=PI] - Local angle to apply velocity to particles from emitter
36
36
  * @param {Number} [tileIndex=-1] - Index into tile sheet, if <0 no texture is applied
37
- * @param {Number} [tileSize=tileSizeDefault] - Tile size for particles
38
- * @param {Color} [colorStartA=new Color(1,1,1)] - Color at start of life 1, randomized between start colors
39
- * @param {Color} [colorStartB=new Color(1,1,1)] - Color at start of life 2, randomized between start colors
40
- * @param {Color} [colorEndA=new Color(1,1,1,0)] - Color at end of life 1, randomized between end colors
41
- * @param {Color} [colorEndB=new Color(1,1,1,0)] - Color at end of life 2, randomized between end colors
37
+ * @param {Vector2} [tileSize=tileSizeDefault] - Tile size for particles
38
+ * @param {Color} [colorStartA=Color()] - Color at start of life 1, randomized between start colors
39
+ * @param {Color} [colorStartB=Color()] - Color at start of life 2, randomized between start colors
40
+ * @param {Color} [colorEndA=Color(1,1,1,0)] - Color at end of life 1, randomized between end colors
41
+ * @param {Color} [colorEndB=Color(1,1,1,0)] - Color at end of life 2, randomized between end colors
42
42
  * @param {Number} [particleTime=.5] - How long particles live
43
43
  * @param {Number} [sizeStart=.1] - How big are particles at start
44
44
  * @param {Number} [sizeEnd=1] - How big are particles at end