littlejsengine 1.1.6 → 1.1.8
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/docs/Audio.html +2268 -0
- package/docs/Color.html +2989 -0
- package/docs/Debug.html +2933 -0
- package/docs/Draw.html +4092 -0
- package/docs/EngineObject.html +4458 -0
- package/docs/Input.html +2482 -0
- package/docs/Medal.html +1007 -0
- package/docs/Medals.html +628 -0
- package/docs/Music.html +584 -0
- package/docs/Newgrounds.html +1399 -0
- package/docs/Particle.html +4535 -0
- package/docs/ParticleEmitter.html +7770 -0
- package/docs/Random.html +1774 -0
- package/docs/Settings.html +2679 -0
- package/docs/Sound.html +1249 -0
- package/docs/TileCollision.html +1409 -0
- package/docs/TileLayer.html +6948 -0
- package/docs/TileLayerData.html +1052 -0
- package/docs/Timer.html +1183 -0
- package/docs/Utilities.html +3281 -0
- package/docs/Vector2.html +4207 -0
- package/docs/WebGL.html +2327 -0
- package/docs/engine.js.html +429 -0
- package/docs/engineAudio.js.html +609 -0
- package/docs/engineDebug.js.html +725 -0
- package/docs/engineDraw.js.html +419 -0
- package/docs/engineInput.js.html +401 -0
- package/docs/engineMedals.js.html +461 -0
- package/docs/engineObject.js.html +518 -0
- package/docs/engineParticles.js.html +441 -0
- package/docs/engineSettings.js.html +349 -0
- package/docs/engineTileLayer.js.html +513 -0
- package/docs/engineUtilities.js.html +647 -0
- package/docs/engineWebGL.js.html +522 -0
- package/docs/fonts/MavenPro-Regular.ttf +0 -0
- package/docs/fonts/Montserrat-Regular.ttf +0 -0
- package/docs/fonts/Muli-Black.ttf +0 -0
- package/docs/fonts/OFL-hind.txt +93 -0
- package/docs/fonts/OFL-montserrat.txt +93 -0
- package/docs/global.html +1691 -0
- package/docs/index.css +6 -0
- package/docs/index.html +247 -0
- package/docs/scripts/fix-code-block.js +53 -0
- package/docs/scripts/fix-navbar.js +25 -0
- package/docs/scripts/linenumber.js +25 -0
- package/docs/scripts/misc.js +217 -0
- package/docs/scripts/resize.js +85 -0
- package/docs/scripts/search.js +83 -0
- package/docs/scripts/third-party/Apache-License-2.0.txt +202 -0
- package/docs/scripts/third-party/fuse.js +9 -0
- package/docs/scripts/third-party/lang-css.js +2 -0
- package/docs/scripts/third-party/prettify.js +28 -0
- package/docs/static/favicon.png +0 -0
- package/docs/static/index.css +4 -0
- package/docs/styles/clean-jsdoc-theme-base.css +393 -0
- package/docs/styles/clean-jsdoc-theme-dark.css +324 -0
- package/docs/styles/clean-jsdoc-theme-light.css +319 -0
- package/docs/styles/reset.css +346 -0
- package/docs/styles/third-party/ionicons.min.css +11 -0
- package/docs/styles/third-party/prettify-jsdoc.css +111 -0
- package/docs/styles/third-party/prettify-tomorrow.css +5 -0
- package/engine/engine.all.js +94 -110
- package/engine/engine.all.min.js +1 -1
- package/engine/engine.all.release.js +94 -110
- package/engine/engine.js +14 -17
- package/engine/engineAudio.js +7 -7
- package/engine/engineDraw.js +6 -6
- package/engine/engineInput.js +7 -7
- package/engine/engineMedals.js +3 -3
- package/engine/engineObject.js +15 -15
- package/engine/engineParticles.js +3 -3
- package/engine/engineSettings.js +30 -43
- package/engine/engineTileLayer.js +5 -5
- package/engine/engineUtilities.js +4 -4
- package/examples/breakout/game.js +1 -1
- package/examples/breakout/gameObjects.js +1 -1
- package/examples/breakout/index.html +3 -3
- package/examples/platformer/gameObjects.js +1 -1
- package/examples/platformer/gamePlayer.js +1 -1
- package/examples/platformer/index.html +6 -6
- package/examples/puzzle/game.js +1 -1
- package/examples/puzzle/index.html +2 -2
- package/examples/stress/index.html +1 -1
- package/index.html +13 -13
- package/package.json +1 -1
package/engine/engine.all.js
CHANGED
|
@@ -899,10 +899,10 @@ class Vector2
|
|
|
899
899
|
class Color
|
|
900
900
|
{
|
|
901
901
|
/** Create a color with the components passed in, white by default
|
|
902
|
-
* @param {Number} [
|
|
903
|
-
* @param {Number} [
|
|
904
|
-
* @param {Number} [
|
|
905
|
-
* @param {Number} [
|
|
902
|
+
* @param {Number} [red=1]
|
|
903
|
+
* @param {Number} [green=1]
|
|
904
|
+
* @param {Number} [blue=1]
|
|
905
|
+
* @param {Number} [alpha=1] */
|
|
906
906
|
constructor(r=1, g=1, b=1, a=1)
|
|
907
907
|
{
|
|
908
908
|
/** @property {Number} - Red */
|
|
@@ -1062,35 +1062,27 @@ class Timer
|
|
|
1062
1062
|
///////////////////////////////////////////////////////////////////////////////
|
|
1063
1063
|
// Display settings
|
|
1064
1064
|
|
|
1065
|
-
/** The max
|
|
1066
|
-
* @
|
|
1067
|
-
* @memberof Settings */
|
|
1068
|
-
const maxWidth = 1920;
|
|
1069
|
-
|
|
1070
|
-
/** The max height of the canvas, centered if window is larger
|
|
1071
|
-
* @default
|
|
1072
|
-
* @memberof Settings */
|
|
1073
|
-
const maxHeight = 1200; // up to 1080p and 16:10
|
|
1074
|
-
|
|
1075
|
-
/** Fixed witdh, if enabled cavnvas size never changes
|
|
1065
|
+
/** The max size of the canvas, centered if window is larger
|
|
1066
|
+
* @type {Vector2}
|
|
1076
1067
|
* @default
|
|
1077
1068
|
* @memberof Settings */
|
|
1078
|
-
|
|
1069
|
+
const maxSize = vec2(1920, 1200);
|
|
1079
1070
|
|
|
1080
|
-
/** Fixed
|
|
1071
|
+
/** Fixed size of the canvas, if enabled cavnvas size never changes
|
|
1072
|
+
* @type {Vector2}
|
|
1081
1073
|
* @default
|
|
1082
1074
|
* @memberof Settings */
|
|
1083
|
-
let
|
|
1075
|
+
let fixedSize = vec2();
|
|
1084
1076
|
|
|
1085
|
-
/**
|
|
1077
|
+
/** Default font used for text rendering
|
|
1086
1078
|
* @default
|
|
1087
1079
|
* @memberof Settings */
|
|
1088
|
-
let
|
|
1080
|
+
let fontDefault = 'arial';
|
|
1089
1081
|
|
|
1090
|
-
/**
|
|
1082
|
+
/** Use crisp pixels for pixel art if true
|
|
1091
1083
|
* @default
|
|
1092
1084
|
* @memberof Settings */
|
|
1093
|
-
let
|
|
1085
|
+
let pixelated = 1;
|
|
1094
1086
|
|
|
1095
1087
|
///////////////////////////////////////////////////////////////////////////////
|
|
1096
1088
|
// Tile sheet settings
|
|
@@ -1099,18 +1091,13 @@ let defaultFont = 'arial';
|
|
|
1099
1091
|
* @type {Vector2}
|
|
1100
1092
|
* @default
|
|
1101
1093
|
* @memberof Settings */
|
|
1102
|
-
const
|
|
1094
|
+
const tileSizeDefault = vec2(16);
|
|
1103
1095
|
|
|
1104
1096
|
/** Prevent tile bleeding from neighbors in pixels
|
|
1105
1097
|
* @default
|
|
1106
1098
|
* @memberof Settings */
|
|
1107
1099
|
const tileBleedShrinkFix = .3;
|
|
1108
1100
|
|
|
1109
|
-
/** Use crisp pixels for pixel art if true
|
|
1110
|
-
* @default
|
|
1111
|
-
* @memberof Settings */
|
|
1112
|
-
let pixelated = 1;
|
|
1113
|
-
|
|
1114
1101
|
///////////////////////////////////////////////////////////////////////////////
|
|
1115
1102
|
// Object settings
|
|
1116
1103
|
|
|
@@ -1118,37 +1105,37 @@ let pixelated = 1;
|
|
|
1118
1105
|
* @type {Vector2}
|
|
1119
1106
|
* @default
|
|
1120
1107
|
* @memberof Settings */
|
|
1121
|
-
const
|
|
1108
|
+
const objectDefaultSize = vec2(1);
|
|
1122
1109
|
|
|
1123
1110
|
/** Default object mass for collison calcuations (how heavy objects are)
|
|
1124
1111
|
* @default
|
|
1125
1112
|
* @memberof Settings */
|
|
1126
|
-
const
|
|
1113
|
+
const objectDefaultMass = 1;
|
|
1127
1114
|
|
|
1128
1115
|
/** How much to slow velocity by each frame (0-1)
|
|
1129
1116
|
* @default
|
|
1130
1117
|
* @memberof Settings */
|
|
1131
|
-
const
|
|
1118
|
+
const objectDefaultDamping = .99;
|
|
1132
1119
|
|
|
1133
1120
|
/** How much to slow angular velocity each frame (0-1)
|
|
1134
1121
|
* @default
|
|
1135
1122
|
* @memberof Settings */
|
|
1136
|
-
const
|
|
1123
|
+
const objectDefaultAngleDamping = .99;
|
|
1137
1124
|
|
|
1138
1125
|
/** How much to bounce when a collision occurs (0-1)
|
|
1139
1126
|
* @default
|
|
1140
1127
|
* @memberof Settings */
|
|
1141
|
-
const
|
|
1128
|
+
const objectDefaultElasticity = 0;
|
|
1142
1129
|
|
|
1143
1130
|
/** How much to slow when touching (0-1)
|
|
1144
1131
|
* @default
|
|
1145
1132
|
* @memberof Settings */
|
|
1146
|
-
const
|
|
1133
|
+
const objectDefaultFriction = .8;
|
|
1147
1134
|
|
|
1148
1135
|
/** Clamp max speed to avoid fast objects missing collisions
|
|
1149
1136
|
* @default
|
|
1150
1137
|
* @memberof Settings */
|
|
1151
|
-
const
|
|
1138
|
+
const objectMaxSpeed = 1;
|
|
1152
1139
|
|
|
1153
1140
|
/** How much gravity to apply to objects along the Y axis, negative is down
|
|
1154
1141
|
* @default
|
|
@@ -1167,7 +1154,7 @@ let cameraPos = vec2();
|
|
|
1167
1154
|
/** Scale of camera in world space
|
|
1168
1155
|
* @default
|
|
1169
1156
|
* @memberof Settings */
|
|
1170
|
-
let cameraScale = max(
|
|
1157
|
+
let cameraScale = max(tileSizeDefault.x, tileSizeDefault.y);
|
|
1171
1158
|
|
|
1172
1159
|
///////////////////////////////////////////////////////////////////////////////
|
|
1173
1160
|
// WebGL settings
|
|
@@ -1190,43 +1177,43 @@ let glOverlay = 1;
|
|
|
1190
1177
|
* @memberof Settings */
|
|
1191
1178
|
const gamepadsEnable = 1;
|
|
1192
1179
|
|
|
1193
|
-
/** If true
|
|
1180
|
+
/** If true, the dpad input is also routed to the left analog stick (for better accessability)
|
|
1194
1181
|
* @default
|
|
1195
1182
|
* @memberof Settings */
|
|
1196
|
-
const
|
|
1183
|
+
const gamepadDirectionEmulateStick = 1;
|
|
1197
1184
|
|
|
1198
|
-
/** If true
|
|
1185
|
+
/** If true touch input is routed to mouse functions
|
|
1199
1186
|
* @default
|
|
1200
1187
|
* @memberof Settings */
|
|
1201
|
-
const
|
|
1188
|
+
const inputTouchEnable = 1;
|
|
1202
1189
|
|
|
1203
1190
|
/** If true the WASD keys are also routed to the direction keys (for better accessability)
|
|
1204
1191
|
* @default
|
|
1205
1192
|
* @memberof Settings */
|
|
1206
|
-
const
|
|
1193
|
+
const inputWASDEmulateDirection = 1;
|
|
1207
1194
|
|
|
1208
1195
|
///////////////////////////////////////////////////////////////////////////////
|
|
1209
1196
|
// Audio settings
|
|
1210
1197
|
|
|
1211
|
-
/**
|
|
1198
|
+
/** Volume scale to apply to all sound, music and speech
|
|
1212
1199
|
* @default
|
|
1213
1200
|
* @memberof Settings */
|
|
1214
|
-
|
|
1201
|
+
let soundVolume = .5;
|
|
1215
1202
|
|
|
1216
|
-
/**
|
|
1203
|
+
/** All audio code can be disabled and removed from build
|
|
1217
1204
|
* @default
|
|
1218
1205
|
* @memberof Settings */
|
|
1219
|
-
|
|
1206
|
+
const soundEnable = 1;
|
|
1220
1207
|
|
|
1221
1208
|
/** Default range where sound no longer plays
|
|
1222
1209
|
* @default
|
|
1223
1210
|
* @memberof Settings */
|
|
1224
|
-
const
|
|
1211
|
+
const soundDefaultRange = 30;
|
|
1225
1212
|
|
|
1226
1213
|
/** Default range percent to start tapering off sound (0-1)
|
|
1227
1214
|
* @default
|
|
1228
1215
|
* @memberof Settings */
|
|
1229
|
-
const
|
|
1216
|
+
const soundDefaultTaper = .7;
|
|
1230
1217
|
|
|
1231
1218
|
///////////////////////////////////////////////////////////////////////////////
|
|
1232
1219
|
// Medals settings
|
|
@@ -1282,14 +1269,14 @@ class EngineObject
|
|
|
1282
1269
|
{
|
|
1283
1270
|
/** Create an engine object and adds it to the list of objects
|
|
1284
1271
|
* @param {Vector2} [position=new Vector2(0,0)] - World space position of the object
|
|
1285
|
-
* @param {Vector2} [size=
|
|
1272
|
+
* @param {Vector2} [size=objectDefaultSize] - World space size of the object
|
|
1286
1273
|
* @param {Number} [tileIndex=-1] - Tile to use to render object, untextured if -1
|
|
1287
|
-
* @param {Vector2} [tileSize=
|
|
1274
|
+
* @param {Vector2} [tileSize=tileSizeDefault] - Size of tile in source pixels
|
|
1288
1275
|
* @param {Number} [angle=0] - Angle to rotate the object
|
|
1289
1276
|
* @param {Color} [color] - Color to apply to tile when rendered
|
|
1290
1277
|
* @param {Number} [renderOrder=0] - Objects sorted by renderOrder before being rendered
|
|
1291
1278
|
*/
|
|
1292
|
-
constructor(pos=vec2(), size=
|
|
1279
|
+
constructor(pos=vec2(), size=objectDefaultSize, tileIndex=-1, tileSize=tileSizeDefault, angle=0, color, renderOrder=0)
|
|
1293
1280
|
{
|
|
1294
1281
|
// set passed in params
|
|
1295
1282
|
ASSERT(pos && pos.x != undefined && size.x != undefined); // ensure pos and size are vec2s
|
|
@@ -1312,16 +1299,16 @@ class EngineObject
|
|
|
1312
1299
|
this.additiveColor;
|
|
1313
1300
|
|
|
1314
1301
|
// set object defaults
|
|
1315
|
-
/** @property {Number} [mass=
|
|
1316
|
-
this.mass =
|
|
1317
|
-
/** @property {Number} [damping=
|
|
1318
|
-
this.damping =
|
|
1319
|
-
/** @property {Number} [angleDamping=
|
|
1320
|
-
this.angleDamping =
|
|
1321
|
-
/** @property {Number} [elasticity=
|
|
1322
|
-
this.elasticity =
|
|
1323
|
-
/** @property {Number} [friction=
|
|
1324
|
-
this.friction =
|
|
1302
|
+
/** @property {Number} [mass=objectDefaultMass] - How heavy the object is */
|
|
1303
|
+
this.mass = objectDefaultMass;
|
|
1304
|
+
/** @property {Number} [damping=objectDefaultDamping] - How much to slow down velocity each frame (0-1) */
|
|
1305
|
+
this.damping = objectDefaultDamping;
|
|
1306
|
+
/** @property {Number} [angleDamping=objectDefaultAngleDamping] - How much to slow down rotation each frame (0-1) */
|
|
1307
|
+
this.angleDamping = objectDefaultAngleDamping;
|
|
1308
|
+
/** @property {Number} [elasticity=objectDefaultElasticity] - How bouncy the object is when colliding (0-1) */
|
|
1309
|
+
this.elasticity = objectDefaultElasticity;
|
|
1310
|
+
/** @property {Number} [friction=objectDefaultFriction] - How much friction to apply when sliding (0-1) */
|
|
1311
|
+
this.friction = objectDefaultFriction;
|
|
1325
1312
|
/** @property {Number} [gravityScale=1] - How much to scale gravity by for this object */
|
|
1326
1313
|
this.gravityScale = 1;
|
|
1327
1314
|
/** @property {Number} [renderOrder=0] - Objects are sorted by render order */
|
|
@@ -1350,8 +1337,8 @@ class EngineObject
|
|
|
1350
1337
|
}
|
|
1351
1338
|
|
|
1352
1339
|
// limit max speed to prevent missing collisions
|
|
1353
|
-
this.velocity.x = clamp(this.velocity.x,
|
|
1354
|
-
this.velocity.y = clamp(this.velocity.y,
|
|
1340
|
+
this.velocity.x = clamp(this.velocity.x, objectMaxSpeed, -objectMaxSpeed);
|
|
1341
|
+
this.velocity.y = clamp(this.velocity.y, objectMaxSpeed, -objectMaxSpeed);
|
|
1355
1342
|
|
|
1356
1343
|
// apply physics
|
|
1357
1344
|
const oldPos = this.pos.copy();
|
|
@@ -1673,14 +1660,14 @@ const worldToScreen = (worldPos)=>
|
|
|
1673
1660
|
* @param {Vector2} pos - Center of the tile in world space
|
|
1674
1661
|
* @param {Vector2} [size=new Vector2(1,1)] - Size of the tile in world space, width and height
|
|
1675
1662
|
* @param {Number} [tileIndex=-1] - Tile index to use, negative is untextured
|
|
1676
|
-
* @param {Vector2} [tileSize=
|
|
1663
|
+
* @param {Vector2} [tileSize=tileSizeDefault] - Tile size in source pixels
|
|
1677
1664
|
* @param {Color} [color=new Color(1,1,1)] - Color to modulate with
|
|
1678
1665
|
* @param {Number} [angle=0] - Angle to rotate by
|
|
1679
1666
|
* @param {Boolean} [mirror=0] - If true image is flipped along the Y axis
|
|
1680
1667
|
* @param {Color} [additiveColor=new Color(0,0,0,0)] - Additive color to be applied
|
|
1681
1668
|
* @param {Boolean} [useWebGL=glEnable] - Use accelerated WebGL rendering
|
|
1682
1669
|
* @memberof Draw */
|
|
1683
|
-
function drawTile(pos, size=vec2(1), tileIndex=-1, tileSize=
|
|
1670
|
+
function drawTile(pos, size=vec2(1), tileIndex=-1, tileSize=tileSizeDefault, color=new Color, angle=0, mirror,
|
|
1684
1671
|
additiveColor=new Color(0,0,0,0), useWebGL=glEnable)
|
|
1685
1672
|
{
|
|
1686
1673
|
showWatermark && ++drawCount;
|
|
@@ -1744,14 +1731,14 @@ function drawTile(pos, size=vec2(1), tileIndex=-1, tileSize=defaultTileSize, col
|
|
|
1744
1731
|
* @memberof Draw */
|
|
1745
1732
|
function drawRect(pos, size, color, angle, useWebGL)
|
|
1746
1733
|
{
|
|
1747
|
-
drawTile(pos, size, -1,
|
|
1734
|
+
drawTile(pos, size, -1, tileSizeDefault, color, angle, 0, 0, useWebGL);
|
|
1748
1735
|
}
|
|
1749
1736
|
|
|
1750
1737
|
/** Draw textured tile centered on pos in screen space
|
|
1751
1738
|
* @param {Vector2} pos - Center of the tile
|
|
1752
1739
|
* @param {Vector2} [size=new Vector2(1,1)] - Size of the tile
|
|
1753
1740
|
* @param {Number} [tileIndex=-1] - Tile index to use, negative is untextured
|
|
1754
|
-
* @param {Vector2} [tileSize=
|
|
1741
|
+
* @param {Vector2} [tileSize=tileSizeDefault] - Tile size in source pixels
|
|
1755
1742
|
* @param {Color} [color=new Color]
|
|
1756
1743
|
* @param {Number} [angle=0]
|
|
1757
1744
|
* @param {Boolean} [mirror=0]
|
|
@@ -1772,7 +1759,7 @@ function drawTileScreenSpace(pos, size=vec2(1), tileIndex, tileSize, color, angl
|
|
|
1772
1759
|
* @memberof Draw */
|
|
1773
1760
|
function drawRectScreenSpace(pos, size, color, angle, useWebGL)
|
|
1774
1761
|
{
|
|
1775
|
-
drawTileSrceenSpace(pos, size, -1,
|
|
1762
|
+
drawTileSrceenSpace(pos, size, -1, tileSizeDefault, color, angle, 0, 0, useWebGL);
|
|
1776
1763
|
}
|
|
1777
1764
|
|
|
1778
1765
|
/** Draw colored line between two points
|
|
@@ -1819,7 +1806,7 @@ function drawCanvas2D(pos, size, angle, mirror, drawFunction, context = mainCont
|
|
|
1819
1806
|
* @param {Color} [lineColor=new Color(0,0,0)]
|
|
1820
1807
|
* @param {String} [textAlign='center']
|
|
1821
1808
|
* @memberof Draw */
|
|
1822
|
-
function drawText(text, pos, size=1, color=new Color, lineWidth=0, lineColor=new Color(0,0,0), textAlign='center', font=
|
|
1809
|
+
function drawText(text, pos, size=1, color=new Color, lineWidth=0, lineColor=new Color(0,0,0), textAlign='center', font=fontDefault)
|
|
1823
1810
|
{
|
|
1824
1811
|
pos = worldToScreen(pos);
|
|
1825
1812
|
overlayContext.font = size*cameraScale + 'px '+ font;
|
|
@@ -1943,7 +1930,7 @@ let mouseWheel = 0;
|
|
|
1943
1930
|
|
|
1944
1931
|
/** Returns true if user is using gamepad (has more recently pressed a gamepad button)
|
|
1945
1932
|
* @memberof Input */
|
|
1946
|
-
let
|
|
1933
|
+
let isUsingGamepad = 0;
|
|
1947
1934
|
|
|
1948
1935
|
/** Returns true if gamepad button is down
|
|
1949
1936
|
* @param {Number} button
|
|
@@ -2005,7 +1992,7 @@ function inputUpdatePost()
|
|
|
2005
1992
|
onkeydown = e=>
|
|
2006
1993
|
{
|
|
2007
1994
|
if (debug && e.target != document.body) return;
|
|
2008
|
-
e.repeat || (inputData[
|
|
1995
|
+
e.repeat || (inputData[isUsingGamepad = 0][remapKeyCode(e.keyCode)] = 3);
|
|
2009
1996
|
debug || e.preventDefault();
|
|
2010
1997
|
}
|
|
2011
1998
|
onkeyup = e=>
|
|
@@ -2013,12 +2000,12 @@ onkeyup = e=>
|
|
|
2013
2000
|
if (debug && e.target != document.body) return;
|
|
2014
2001
|
inputData[0][remapKeyCode(e.keyCode)] = 4;
|
|
2015
2002
|
}
|
|
2016
|
-
const remapKeyCode = c=>
|
|
2003
|
+
const remapKeyCode = c=> inputWASDEmulateDirection ? c==87?38 : c==83?40 : c==65?37 : c==68?39 : c : c;
|
|
2017
2004
|
|
|
2018
2005
|
///////////////////////////////////////////////////////////////////////////////
|
|
2019
2006
|
// Mouse event handlers
|
|
2020
2007
|
|
|
2021
|
-
onmousedown = e=> {inputData[
|
|
2008
|
+
onmousedown = e=> {inputData[isUsingGamepad = 0][e.button] = 3; onmousemove(e); e.button && e.preventDefault();}
|
|
2022
2009
|
onmouseup = e=> inputData[0][e.button] = inputData[0][e.button] & 2 | 4;
|
|
2023
2010
|
onmousemove = e=>
|
|
2024
2011
|
{
|
|
@@ -2066,10 +2053,10 @@ function gamepadsUpdate()
|
|
|
2066
2053
|
{
|
|
2067
2054
|
const button = gamepad.buttons[j];
|
|
2068
2055
|
data[j] = button.pressed ? 1 + 2*!gamepadIsDown(j,i) : 4*gamepadIsDown(j,i);
|
|
2069
|
-
|
|
2056
|
+
isUsingGamepad |= !i && button.pressed;
|
|
2070
2057
|
}
|
|
2071
2058
|
|
|
2072
|
-
if (
|
|
2059
|
+
if (gamepadDirectionEmulateStick)
|
|
2073
2060
|
{
|
|
2074
2061
|
// copy dpad to left analog stick when pressed
|
|
2075
2062
|
const dpad = vec2(gamepadIsDown(15,i) - gamepadIsDown(14,i), gamepadIsDown(12,i) - gamepadIsDown(13,i));
|
|
@@ -2086,7 +2073,7 @@ function gamepadsUpdate()
|
|
|
2086
2073
|
/** True if a touch device has been detected
|
|
2087
2074
|
* @const {boolean}
|
|
2088
2075
|
* @memberof Input */
|
|
2089
|
-
const isTouchDevice =
|
|
2076
|
+
const isTouchDevice = inputTouchEnable && window.ontouchstart !== undefined;
|
|
2090
2077
|
if (isTouchDevice)
|
|
2091
2078
|
{
|
|
2092
2079
|
// handle all touch events the same way
|
|
@@ -2141,10 +2128,10 @@ class Sound
|
|
|
2141
2128
|
{
|
|
2142
2129
|
/** Create a sound object and cache the zzfx samples for later use
|
|
2143
2130
|
* @param {Array} zzfxSound - Array of zzfx parameters, ex. [.5,.5]
|
|
2144
|
-
* @param {Number} [range=
|
|
2145
|
-
* @param {Number} [taper=
|
|
2131
|
+
* @param {Number} [range=soundDefaultRange] - World space max range of sound, will not play if camera is farther away
|
|
2132
|
+
* @param {Number} [taper=soundDefaultTaper] - At what percentage of range should it start tapering off
|
|
2146
2133
|
*/
|
|
2147
|
-
constructor(zzfxSound, range=
|
|
2134
|
+
constructor(zzfxSound, range=soundDefaultRange, taper=soundDefaultTaper)
|
|
2148
2135
|
{
|
|
2149
2136
|
if (!soundEnable) return;
|
|
2150
2137
|
|
|
@@ -2275,7 +2262,7 @@ function playAudioFile(url, volume=1, loop=1)
|
|
|
2275
2262
|
if (!soundEnable) return;
|
|
2276
2263
|
|
|
2277
2264
|
const audio = new Audio(url);
|
|
2278
|
-
audio.volume =
|
|
2265
|
+
audio.volume = soundVolume * volume;
|
|
2279
2266
|
audio.loop = loop;
|
|
2280
2267
|
audio.play();
|
|
2281
2268
|
return audio;
|
|
@@ -2300,7 +2287,7 @@ function speak(text, language='', volume=1, rate=1, pitch=1)
|
|
|
2300
2287
|
// build utterance and speak
|
|
2301
2288
|
const utterance = new SpeechSynthesisUtterance(text);
|
|
2302
2289
|
utterance.lang = language;
|
|
2303
|
-
utterance.volume = 2*volume*
|
|
2290
|
+
utterance.volume = 2*volume*soundVolume;
|
|
2304
2291
|
utterance.rate = rate;
|
|
2305
2292
|
utterance.pitch = pitch;
|
|
2306
2293
|
speechSynthesis.speak(utterance);
|
|
@@ -2353,7 +2340,7 @@ function playSamples(sampleChannels, volume=1, rate=1, pan=0, loop=0)
|
|
|
2353
2340
|
// create pan and gain nodes
|
|
2354
2341
|
source
|
|
2355
2342
|
.connect(new StereoPannerNode(audioContext, {'pan':clamp(pan, 1, -1)}))
|
|
2356
|
-
.connect(new GainNode(audioContext, {'gain':
|
|
2343
|
+
.connect(new GainNode(audioContext, {'gain':soundVolume*volume}))
|
|
2357
2344
|
.connect(audioContext.destination);
|
|
2358
2345
|
|
|
2359
2346
|
// play and return sound
|
|
@@ -2421,7 +2408,7 @@ function zzfxG
|
|
|
2421
2408
|
1 - tremolo + tremolo*Math.sin(PI2*i/repeatTime) // tremolo
|
|
2422
2409
|
: 1) *
|
|
2423
2410
|
sign(s)*(abs(s)**shapeCurve) * // curve 0=square, 2=pointy
|
|
2424
|
-
volume *
|
|
2411
|
+
volume * soundVolume * ( // envelope
|
|
2425
2412
|
i < attack ? i/attack : // attack
|
|
2426
2413
|
i < attack + decay ? // decay
|
|
2427
2414
|
1-((i-attack)/decay)*(1-sustainVolume) : // decay falloff
|
|
@@ -2724,12 +2711,12 @@ class TileLayer extends EngineObject
|
|
|
2724
2711
|
{
|
|
2725
2712
|
/** Create a tile layer object
|
|
2726
2713
|
* @param {Vector2} [position=new Vector2(0,0)] - World space position
|
|
2727
|
-
* @param {Vector2} [size=
|
|
2728
|
-
* @param {Vector2} [tileSize=
|
|
2714
|
+
* @param {Vector2} [size=objectDefaultSize] - World space size
|
|
2715
|
+
* @param {Vector2} [tileSize=tileSizeDefault] - Size of tiles in source pixels
|
|
2729
2716
|
* @param {Vector2} [scale=new Vector2(1,1)] - How much to scale this layer when rendered
|
|
2730
2717
|
* @param {Number} [renderOrder=0] - Objects sorted by renderOrder before being rendered
|
|
2731
2718
|
*/
|
|
2732
|
-
constructor(pos, size=tileCollisionSize, tileSize=
|
|
2719
|
+
constructor(pos, size=tileCollisionSize, tileSize=tileSizeDefault, scale=vec2(1), renderOrder=0)
|
|
2733
2720
|
{
|
|
2734
2721
|
super(pos, size, -1, tileSize, 0, undefined, renderOrder);
|
|
2735
2722
|
|
|
@@ -2888,11 +2875,11 @@ class TileLayer extends EngineObject
|
|
|
2888
2875
|
* @param {Vector2} pos
|
|
2889
2876
|
* @param {Vector2} [size=new Vector2(1,1)]
|
|
2890
2877
|
* @param {Number} [tileIndex=-1]
|
|
2891
|
-
* @param {Vector2} [tileSize=
|
|
2878
|
+
* @param {Vector2} [tileSize=tileSizeDefault]
|
|
2892
2879
|
* @param {Color} [color=new Color(1,1,1)]
|
|
2893
2880
|
* @param {Number} [angle=0]
|
|
2894
2881
|
* @param {Boolean} [mirror=0] */
|
|
2895
|
-
drawTile(pos, size=vec2(1), tileIndex=-1, tileSize=
|
|
2882
|
+
drawTile(pos, size=vec2(1), tileIndex=-1, tileSize=tileSizeDefault, color=new Color, angle=0, mirror)
|
|
2896
2883
|
{
|
|
2897
2884
|
this.drawCanvas2D(pos, size, angle, mirror, (context)=>
|
|
2898
2885
|
{
|
|
@@ -2955,7 +2942,7 @@ class ParticleEmitter extends EngineObject
|
|
|
2955
2942
|
* @param {Number} [emitRate=100] - How many particles per second to spawn, does not emit if 0
|
|
2956
2943
|
* @param {Number} [emitConeAngle=PI] - Local angle to apply velocity to particles from emitter
|
|
2957
2944
|
* @param {Number} [tileIndex=-1] - Index into tile sheet, if <0 no texture is applied
|
|
2958
|
-
* @param {Number} [tileSize=
|
|
2945
|
+
* @param {Number} [tileSize=tileSizeDefault] - Tile size for particles
|
|
2959
2946
|
* @param {Color} [colorStartA=new Color(1,1,1)] - Color at start of life 1, randomized between start colors
|
|
2960
2947
|
* @param {Color} [colorStartB=new Color(1,1,1)] - Color at start of life 2, randomized between start colors
|
|
2961
2948
|
* @param {Color} [colorEndA=new Color(1,1,1,0)] - Color at end of life 1, randomized between end colors
|
|
@@ -2984,7 +2971,7 @@ class ParticleEmitter extends EngineObject
|
|
|
2984
2971
|
emitRate = 100,
|
|
2985
2972
|
emitConeAngle = PI,
|
|
2986
2973
|
tileIndex = -1,
|
|
2987
|
-
tileSize =
|
|
2974
|
+
tileSize = tileSizeDefault,
|
|
2988
2975
|
colorStartA = new Color,
|
|
2989
2976
|
colorStartB = new Color,
|
|
2990
2977
|
colorEndA = new Color(1,1,1,0),
|
|
@@ -3155,7 +3142,7 @@ class Particle extends EngineObject
|
|
|
3155
3142
|
* Create a particle with the given settings
|
|
3156
3143
|
* @param {Vector2} position - World space position of the particle
|
|
3157
3144
|
* @param {Number} [tileIndex=-1] - Tile to use to render, untextured if -1
|
|
3158
|
-
* @param {Vector2} [tileSize=
|
|
3145
|
+
* @param {Vector2} [tileSize=tileSizeDefault] - Size of tile in source pixels
|
|
3159
3146
|
* @param {Number} [angle=0] - Angle to rotate the particle
|
|
3160
3147
|
*/
|
|
3161
3148
|
constructor(pos, tileIndex, tileSize, angle) { super(pos, new Vector2, tileIndex, tileSize, angle); }
|
|
@@ -3317,9 +3304,9 @@ class Medal
|
|
|
3317
3304
|
|
|
3318
3305
|
// draw the text
|
|
3319
3306
|
context.textAlign = 'left';
|
|
3320
|
-
context.font = '3em '+
|
|
3307
|
+
context.font = '3em '+ fontDefault;
|
|
3321
3308
|
context.fillText(this.name, x+medalDisplayIconSize+25, y+35);
|
|
3322
|
-
context.font = '1.5em '+
|
|
3309
|
+
context.font = '1.5em '+ fontDefault;
|
|
3323
3310
|
context.restore(context.fillText(this.description, x+medalDisplayIconSize+25, y+70));
|
|
3324
3311
|
}
|
|
3325
3312
|
|
|
@@ -3334,7 +3321,7 @@ class Medal
|
|
|
3334
3321
|
const context = overlayContext;
|
|
3335
3322
|
context.textAlign = 'center';
|
|
3336
3323
|
context.textBaseline = 'middle';
|
|
3337
|
-
context.font = size*.6 + 'px '+
|
|
3324
|
+
context.font = size*.6 + 'px '+ fontDefault;
|
|
3338
3325
|
context.fillStyle = '#000';
|
|
3339
3326
|
if (this.image)
|
|
3340
3327
|
context.drawImage(this.image, x-size/2, y-size/2, size, size);
|
|
@@ -3891,7 +3878,7 @@ gl_VERTEX_BYTE_STRIDE = 4 + (4 * 2) * 3 + (4) * 2; // float + vec2 * 3 + (char *
|
|
|
3891
3878
|
const engineName = 'LittleJS';
|
|
3892
3879
|
|
|
3893
3880
|
/** Version of engine */
|
|
3894
|
-
const engineVersion = '1.1.
|
|
3881
|
+
const engineVersion = '1.1.8';
|
|
3895
3882
|
|
|
3896
3883
|
/** Frames per second to update objects
|
|
3897
3884
|
* @default */
|
|
@@ -4016,31 +4003,28 @@ function engineInit(gameInit, gameUpdate, gameUpdatePost, gameRender, gameRender
|
|
|
4016
4003
|
frameTimeBufferMS += deltaSmooth;
|
|
4017
4004
|
}
|
|
4018
4005
|
|
|
4019
|
-
if (
|
|
4006
|
+
if (fixedSize.x)
|
|
4020
4007
|
{
|
|
4021
4008
|
// clear set fixed size
|
|
4022
|
-
mainCanvas.width =
|
|
4023
|
-
mainCanvas.height =
|
|
4009
|
+
mainCanvas.width = fixedSize.x;
|
|
4010
|
+
mainCanvas.height = fixedSize.y;
|
|
4024
4011
|
|
|
4025
|
-
if
|
|
4012
|
+
// fit to window by adding space on top or bottom if necessary
|
|
4013
|
+
const aspect = innerWidth / innerHeight;
|
|
4014
|
+
const fixedAspect = mainCanvas.width / mainCanvas.height;
|
|
4015
|
+
mainCanvas.style.width = overlayCanvas.style.width = aspect < fixedAspect ? '100%' : '';
|
|
4016
|
+
mainCanvas.style.height = overlayCanvas.style.height = aspect < fixedAspect ? '' : '100%';
|
|
4017
|
+
if (glCanvas)
|
|
4026
4018
|
{
|
|
4027
|
-
|
|
4028
|
-
|
|
4029
|
-
const fixedAspect = fixedWidth / fixedHeight;
|
|
4030
|
-
mainCanvas.style.width = overlayCanvas.style.width = aspect < fixedAspect ? '100%' : '';
|
|
4031
|
-
mainCanvas.style.height = overlayCanvas.style.height = aspect < fixedAspect ? '' : '100%';
|
|
4032
|
-
if (glCanvas)
|
|
4033
|
-
{
|
|
4034
|
-
glCanvas.style.width = mainCanvas.style.width;
|
|
4035
|
-
glCanvas.style.height = mainCanvas.style.height;
|
|
4036
|
-
}
|
|
4019
|
+
glCanvas.style.width = mainCanvas.style.width;
|
|
4020
|
+
glCanvas.style.height = mainCanvas.style.height;
|
|
4037
4021
|
}
|
|
4038
4022
|
}
|
|
4039
4023
|
else
|
|
4040
4024
|
{
|
|
4041
4025
|
// clear and set size to same as window
|
|
4042
|
-
mainCanvas.width = min(innerWidth,
|
|
4043
|
-
mainCanvas.height = min(innerHeight,
|
|
4026
|
+
mainCanvas.width = min(innerWidth, maxSize.x);
|
|
4027
|
+
mainCanvas.height = min(innerHeight, maxSize.y);
|
|
4044
4028
|
}
|
|
4045
4029
|
|
|
4046
4030
|
// save canvas size and clear overlay canvas
|