littlejsengine 1.11.17 → 1.12.4
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/dist/littlejs.d.ts +112 -43
- package/dist/littlejs.esm.js +586 -500
- package/dist/littlejs.esm.min.js +1 -1
- package/dist/littlejs.js +2993 -122
- package/dist/littlejs.min.js +1 -1
- package/dist/littlejs.release.js +2992 -119
- package/examples/box2d/game.js +70 -39
- package/examples/box2d/gameObjects.js +81 -77
- package/examples/box2d/index.html +2 -7
- package/examples/box2d/scenes.js +80 -90
- package/examples/breakout/game.js +63 -28
- package/examples/breakout/gameObjects.js +45 -47
- package/examples/breakout/index.html +1 -5
- package/examples/breakoutTutorial/game.js +36 -29
- package/examples/breakoutTutorial/index.html +1 -3
- package/examples/empty/game.js +5 -2
- package/examples/empty/index.html +1 -3
- package/examples/htmlMenu/game.js +24 -15
- package/examples/htmlMenu/index.html +5 -7
- package/examples/index.html +2 -3
- package/examples/module/game.js +32 -34
- package/examples/module/index.html +1 -1
- package/examples/particles/index.html +27 -22
- package/examples/platformer/game.js +71 -45
- package/examples/platformer/gameCharacter.js +42 -34
- package/examples/platformer/gameEffects.js +82 -75
- package/examples/platformer/gameLevel.js +67 -38
- package/examples/platformer/{gameLevelData.js → gameLevelData.json} +1 -11
- package/examples/platformer/gameObjects.js +70 -64
- package/examples/platformer/gamePlayer.js +12 -7
- package/examples/platformer/index.html +1 -9
- package/examples/puzzle/game.js +59 -40
- package/examples/puzzle/index.html +1 -3
- package/examples/shorts/base.html +2 -2
- package/examples/shorts/particles.js +1 -1
- package/examples/shorts/platformer.js +1 -1
- package/examples/shorts/tileLayer.js +5 -6
- package/examples/shorts/tiles.png +0 -0
- package/examples/starter/game.js +9 -12
- package/examples/starter/index.html +13 -13
- package/examples/stress/index.html +44 -44
- package/examples/typescript/build.js +17 -18
- package/examples/typescript/game.js +32 -34
- package/examples/typescript/game.ts +32 -34
- package/examples/typescript/index.html +1 -1
- package/examples/uiSystem/game.js +34 -31
- package/examples/uiSystem/index.html +1 -5
- package/package.json +1 -1
- package/plugins/box2d.js +6 -2
- package/plugins/pluginExport.js +1 -2
- package/reference.md +29 -27
- package/src/engine.js +1 -1
- package/src/engineBuild.js +13 -6
- package/src/engineDebug.js +1 -3
- package/src/engineExport.js +2 -6
- package/src/engineInput.js +3 -1
- package/src/engineObject.js +18 -14
- package/src/engineSettings.js +6 -6
- package/src/engineTileLayer.js +179 -96
- package/examples/typescript/build/dist/littlejs.esm.js +0 -4834
- package/examples/typescript/build/examples/typescript/build.js +0 -24
- package/examples/typescript/build/examples/typescript/game.js +0 -102
package/dist/littlejs.esm.js
CHANGED
|
@@ -334,11 +334,9 @@ function debugRender()
|
|
|
334
334
|
}
|
|
335
335
|
}
|
|
336
336
|
|
|
337
|
-
if (
|
|
337
|
+
if (tileCollisionLayers.length) // show floored tile pick if there is tile collision
|
|
338
338
|
drawRect(mousePos.floor().add(vec2(.5)), vec2(1), rgb(0,0,1,.5), 0, false);
|
|
339
339
|
mainContext = saveContext;
|
|
340
|
-
|
|
341
|
-
//glCopyToContext(mainContext = saveContext);
|
|
342
340
|
}
|
|
343
341
|
|
|
344
342
|
{
|
|
@@ -1530,7 +1528,7 @@ let canvasMaxSize = vec2(1920, 1080);
|
|
|
1530
1528
|
* @memberof Settings */
|
|
1531
1529
|
let canvasFixedSize = vec2();
|
|
1532
1530
|
|
|
1533
|
-
/** Use nearest neighbor scaling
|
|
1531
|
+
/** Use nearest neighbor canvas scaling for more pixelated look
|
|
1534
1532
|
* - Must be set before startup to take effect
|
|
1535
1533
|
* - If enabled sets css image-rendering:pixelated
|
|
1536
1534
|
* @type {boolean}
|
|
@@ -1640,11 +1638,11 @@ let objectDefaultFriction = .8;
|
|
|
1640
1638
|
* @memberof Settings */
|
|
1641
1639
|
let objectMaxSpeed = 1;
|
|
1642
1640
|
|
|
1643
|
-
/** How much gravity to apply to objects
|
|
1644
|
-
* @type {
|
|
1641
|
+
/** How much gravity to apply to objects, negative Y is down
|
|
1642
|
+
* @type {Vector2}
|
|
1645
1643
|
* @default
|
|
1646
1644
|
* @memberof Settings */
|
|
1647
|
-
let gravity =
|
|
1645
|
+
let gravity = vec2();
|
|
1648
1646
|
|
|
1649
1647
|
/** Scales emit rate of particles, useful for low graphics mode (0 disables particle emitters)
|
|
1650
1648
|
* @type {number}
|
|
@@ -1870,8 +1868,8 @@ function setObjectDefaultFriction(friction) { objectDefaultFriction = friction;
|
|
|
1870
1868
|
* @memberof Settings */
|
|
1871
1869
|
function setObjectMaxSpeed(speed) { objectMaxSpeed = speed; }
|
|
1872
1870
|
|
|
1873
|
-
/** Set how much gravity to apply to objects
|
|
1874
|
-
* @param {
|
|
1871
|
+
/** Set how much gravity to apply to objects
|
|
1872
|
+
* @param {Vector2} newGravity
|
|
1875
1873
|
* @memberof Settings */
|
|
1876
1874
|
function setGravity(newGravity) { gravity = newGravity; }
|
|
1877
1875
|
|
|
@@ -2139,7 +2137,10 @@ class EngineObject
|
|
|
2139
2137
|
this.velocity.x *= this.damping;
|
|
2140
2138
|
this.velocity.y *= this.damping;
|
|
2141
2139
|
if (this.mass) // don't apply gravity to static objects
|
|
2142
|
-
|
|
2140
|
+
{
|
|
2141
|
+
this.velocity.x += gravity.x * this.gravityScale;
|
|
2142
|
+
this.velocity.y += gravity.y * this.gravityScale;
|
|
2143
|
+
}
|
|
2143
2144
|
this.pos.x += this.velocity.x;
|
|
2144
2145
|
this.pos.y += this.velocity.y;
|
|
2145
2146
|
this.angle += this.angleVelocity *= this.angleDamping;
|
|
@@ -2154,9 +2155,9 @@ class EngineObject
|
|
|
2154
2155
|
if (this.groundObject)
|
|
2155
2156
|
{
|
|
2156
2157
|
// apply friction in local space of ground object
|
|
2157
|
-
const
|
|
2158
|
-
|
|
2159
|
-
this.velocity.x = groundSpeed + (this.velocity.x - groundSpeed) *
|
|
2158
|
+
const friction = max(this.friction, this.groundObject.friction);
|
|
2159
|
+
const groundSpeed = this.groundObject.velocity ? this.groundObject.velocity.x : 0;
|
|
2160
|
+
this.velocity.x = groundSpeed + (this.velocity.x - groundSpeed) * friction;
|
|
2160
2161
|
this.groundObject = undefined;
|
|
2161
2162
|
//debugOverlay && debugPhysics && debugPoint(this.pos.subtract(vec2(0,this.size.y/2)), '#0f0');
|
|
2162
2163
|
}
|
|
@@ -2198,7 +2199,7 @@ class EngineObject
|
|
|
2198
2199
|
|
|
2199
2200
|
// check for collision
|
|
2200
2201
|
const sizeBoth = this.size.add(o.size);
|
|
2201
|
-
const smallStepUp = (oldPos.y - o.pos.y)*2 > sizeBoth.y + gravity; // prefer to push up if small delta
|
|
2202
|
+
const smallStepUp = (oldPos.y - o.pos.y)*2 > sizeBoth.y + gravity.y; // prefer to push up if small delta
|
|
2202
2203
|
const isBlockedX = abs(oldPos.y - o.pos.y)*2 < sizeBoth.y;
|
|
2203
2204
|
const isBlockedY = abs(oldPos.x - o.pos.x)*2 < sizeBoth.x;
|
|
2204
2205
|
const elasticity = max(this.elasticity, o.elasticity);
|
|
@@ -2260,19 +2261,21 @@ class EngineObject
|
|
|
2260
2261
|
if (this.collideTiles)
|
|
2261
2262
|
{
|
|
2262
2263
|
// check collision against tiles
|
|
2263
|
-
|
|
2264
|
+
const hitLayer = tileCollisionTest(this.pos, this.size, this)
|
|
2265
|
+
if (hitLayer)
|
|
2264
2266
|
{
|
|
2265
2267
|
// if already was stuck in collision, don't do anything
|
|
2266
2268
|
// this should not happen unless something starts in collision
|
|
2267
2269
|
if (!tileCollisionTest(oldPos, this.size, this))
|
|
2268
2270
|
{
|
|
2269
2271
|
// test which side we bounced off (or both if a corner)
|
|
2270
|
-
const
|
|
2271
|
-
const
|
|
2272
|
-
if (
|
|
2272
|
+
const blockedLayerY = tileCollisionTest(vec2(oldPos.x, this.pos.y), this.size, this);
|
|
2273
|
+
const blockedLayerX = tileCollisionTest(vec2(this.pos.x, oldPos.y), this.size, this);
|
|
2274
|
+
if (blockedLayerY || !blockedLayerX)
|
|
2273
2275
|
{
|
|
2274
2276
|
// bounce velocity
|
|
2275
|
-
|
|
2277
|
+
const elasticity = max(this.elasticity, hitLayer.elasticity);
|
|
2278
|
+
this.velocity.y *= -elasticity;
|
|
2276
2279
|
|
|
2277
2280
|
if (wasMovingDown)
|
|
2278
2281
|
{
|
|
@@ -2281,9 +2284,8 @@ class EngineObject
|
|
|
2281
2284
|
const epsilon = .0001;
|
|
2282
2285
|
this.pos.y = (oldPos.y-this.size.y/2|0)+this.size.y/2+epsilon;
|
|
2283
2286
|
|
|
2284
|
-
// set ground object
|
|
2285
|
-
|
|
2286
|
-
this.groundObject = this;
|
|
2287
|
+
// set ground object for tile collision
|
|
2288
|
+
this.groundObject = hitLayer;
|
|
2287
2289
|
}
|
|
2288
2290
|
else
|
|
2289
2291
|
{
|
|
@@ -2292,7 +2294,7 @@ class EngineObject
|
|
|
2292
2294
|
this.groundObject = undefined;
|
|
2293
2295
|
}
|
|
2294
2296
|
}
|
|
2295
|
-
if (
|
|
2297
|
+
if (blockedLayerX)
|
|
2296
2298
|
{
|
|
2297
2299
|
// move to previous position and bounce
|
|
2298
2300
|
this.pos.x = oldPos.x;
|
|
@@ -3392,7 +3394,9 @@ function gamepadsUpdate()
|
|
|
3392
3394
|
const button = gamepad.buttons[j];
|
|
3393
3395
|
const wasDown = gamepadIsDown(j,i);
|
|
3394
3396
|
data[j] = button.pressed ? wasDown ? 1 : 3 : wasDown ? 4 : 0;
|
|
3395
|
-
|
|
3397
|
+
if (!button.value || button.value > .9) // must be a full press
|
|
3398
|
+
if (!i && button.pressed)
|
|
3399
|
+
isUsingGamepad = true;
|
|
3396
3400
|
}
|
|
3397
3401
|
|
|
3398
3402
|
if (gamepadDirectionEmulateStick)
|
|
@@ -4067,75 +4071,47 @@ function zzfxG
|
|
|
4067
4071
|
* LittleJS Tile Layer System
|
|
4068
4072
|
* - Caches arrays of tiles to off screen canvas for fast rendering
|
|
4069
4073
|
* - Unlimited numbers of layers, allocates canvases as needed
|
|
4070
|
-
* - Interfaces with EngineObject for collision
|
|
4071
|
-
* - Collision layer is separate from visible layers
|
|
4072
|
-
* - It is recommended to have a visible layer that matches the collision
|
|
4073
4074
|
* - Tile layers can be drawn to using their context with canvas2d
|
|
4074
4075
|
* - Drawn directly to the main canvas without using WebGL
|
|
4076
|
+
* - Tile layers can also have collision with EngineObjects
|
|
4075
4077
|
* @namespace TileCollision
|
|
4076
4078
|
*/
|
|
4077
4079
|
|
|
4078
4080
|
|
|
4079
4081
|
|
|
4080
|
-
|
|
4081
|
-
|
|
4082
|
-
* @memberof TileCollision */
|
|
4083
|
-
let tileCollision = [];
|
|
4084
|
-
|
|
4085
|
-
/** Size of the tile collision layer 2d grid
|
|
4086
|
-
* @type {Vector2}
|
|
4087
|
-
* @memberof TileCollision */
|
|
4088
|
-
let tileCollisionSize = vec2();
|
|
4089
|
-
|
|
4090
|
-
/** Clear and initialize tile collision
|
|
4091
|
-
* @param {Vector2} size - width and height of tile collision 2d grid
|
|
4092
|
-
* @memberof TileCollision */
|
|
4093
|
-
function initTileCollision(size)
|
|
4094
|
-
{
|
|
4095
|
-
tileCollisionSize = size;
|
|
4096
|
-
tileCollision = [];
|
|
4097
|
-
for (let i=tileCollision.length = tileCollisionSize.area(); i--;)
|
|
4098
|
-
tileCollision[i] = 0;
|
|
4099
|
-
}
|
|
4082
|
+
///////////////////////////////////////////////////////////////////////////////
|
|
4083
|
+
// Tile Layer System
|
|
4100
4084
|
|
|
4101
|
-
/**
|
|
4102
|
-
* @
|
|
4103
|
-
* @param {number} [data]
|
|
4085
|
+
/** Keep track of all tile layers with collision
|
|
4086
|
+
* @type {Array<TileCollisionLayer>}
|
|
4104
4087
|
* @memberof TileCollision */
|
|
4105
|
-
|
|
4106
|
-
{
|
|
4107
|
-
pos.arrayCheck(tileCollisionSize) && (tileCollision[(pos.y|0)*tileCollisionSize.x+pos.x|0] = data);
|
|
4108
|
-
}
|
|
4088
|
+
let tileCollisionLayers = [];
|
|
4109
4089
|
|
|
4110
4090
|
/** Get tile collision data for a given cell in the grid
|
|
4111
|
-
|
|
4112
|
-
|
|
4113
|
-
|
|
4091
|
+
* @param {Vector2} pos
|
|
4092
|
+
* @return {number}
|
|
4093
|
+
* @memberof TileCollision */
|
|
4114
4094
|
function getTileCollisionData(pos)
|
|
4115
4095
|
{
|
|
4116
|
-
|
|
4096
|
+
// check all tile collision layers
|
|
4097
|
+
for (const layer of tileCollisionLayers)
|
|
4098
|
+
if (pos.arrayCheck(layer.size))
|
|
4099
|
+
return layer.getCollisionData(pos);
|
|
4100
|
+
return 0;
|
|
4117
4101
|
}
|
|
4118
4102
|
|
|
4119
|
-
/** Check if
|
|
4103
|
+
/** Check if a tile layer collides with another object
|
|
4120
4104
|
* @param {Vector2} pos
|
|
4121
4105
|
* @param {Vector2} [size=(0,0)]
|
|
4122
4106
|
* @param {EngineObject} [object]
|
|
4123
|
-
* @return {
|
|
4107
|
+
* @return {TileCollisionLayer}
|
|
4124
4108
|
* @memberof TileCollision */
|
|
4125
4109
|
function tileCollisionTest(pos, size=vec2(), object)
|
|
4126
4110
|
{
|
|
4127
|
-
|
|
4128
|
-
|
|
4129
|
-
|
|
4130
|
-
|
|
4131
|
-
for (let y = minY; y < maxY; ++y)
|
|
4132
|
-
for (let x = minX; x < maxX; ++x)
|
|
4133
|
-
{
|
|
4134
|
-
const tileData = tileCollision[y*tileCollisionSize.x+x];
|
|
4135
|
-
if (tileData && (!object || object.collideWithTile(tileData, vec2(x, y))))
|
|
4136
|
-
return true;
|
|
4137
|
-
}
|
|
4138
|
-
return false;
|
|
4111
|
+
// check all tile collision layers
|
|
4112
|
+
for (const layer of tileCollisionLayers)
|
|
4113
|
+
if (layer.collisionTest(pos, size, object))
|
|
4114
|
+
return layer;
|
|
4139
4115
|
}
|
|
4140
4116
|
|
|
4141
4117
|
/** Return the center of first tile hit, undefined if nothing was hit.
|
|
@@ -4147,49 +4123,17 @@ function tileCollisionTest(pos, size=vec2(), object)
|
|
|
4147
4123
|
* @memberof TileCollision */
|
|
4148
4124
|
function tileCollisionRaycast(posStart, posEnd, object)
|
|
4149
4125
|
{
|
|
4150
|
-
//
|
|
4151
|
-
|
|
4152
|
-
|
|
4153
|
-
|
|
4154
|
-
|
|
4155
|
-
|
|
4156
|
-
const flooredPosStart = posStart.floor();
|
|
4157
|
-
|
|
4158
|
-
// setup iteration variables
|
|
4159
|
-
let pos = flooredPosStart;
|
|
4160
|
-
let xi = unit.x * (delta.x < 0 ? posStart.x - pos.x : pos.x - posStart.x + 1);
|
|
4161
|
-
let yi = unit.y * (delta.y < 0 ? posStart.y - pos.y : pos.y - posStart.y + 1);
|
|
4162
|
-
|
|
4163
|
-
while (true)
|
|
4164
|
-
{
|
|
4165
|
-
// check for tile collision
|
|
4166
|
-
const tileData = getTileCollisionData(pos);
|
|
4167
|
-
if (tileData && (!object || object.collideWithTile(tileData, pos)))
|
|
4168
|
-
{
|
|
4169
|
-
debugRaycast && debugLine(posStart, posEnd, '#f00', .02);
|
|
4170
|
-
debugRaycast && debugPoint(pos.add(vec2(.5)), '#ff0');
|
|
4171
|
-
return pos.add(vec2(.5));
|
|
4172
|
-
}
|
|
4173
|
-
|
|
4174
|
-
// check if past the end
|
|
4175
|
-
if (xi > totalLength && yi > totalLength)
|
|
4176
|
-
break;
|
|
4177
|
-
|
|
4178
|
-
// get coordinates of the next tile to check
|
|
4179
|
-
if (xi > yi)
|
|
4180
|
-
pos.y += sign(delta.y), yi += unit.y;
|
|
4181
|
-
else
|
|
4182
|
-
pos.x += sign(delta.x), xi += unit.x;
|
|
4126
|
+
// check all tile collision layers
|
|
4127
|
+
for (const layer of tileCollisionLayers)
|
|
4128
|
+
{
|
|
4129
|
+
const hitPos = layer.collisionRaycast(posStart, posEnd, object)
|
|
4130
|
+
if (hitPos)
|
|
4131
|
+
return hitPos;
|
|
4183
4132
|
}
|
|
4184
|
-
|
|
4185
|
-
debugRaycast && debugLine(posStart, posEnd, '#00f', .02);
|
|
4186
4133
|
}
|
|
4187
4134
|
|
|
4188
|
-
///////////////////////////////////////////////////////////////////////////////
|
|
4189
|
-
// Tile Layer Rendering System
|
|
4190
|
-
|
|
4191
4135
|
/**
|
|
4192
|
-
* Tile layer data object stores info about how to
|
|
4136
|
+
* Tile layer data object stores info about how to draw a tile
|
|
4193
4137
|
* @example
|
|
4194
4138
|
* // create tile layer data with tile index 0 and random orientation and color
|
|
4195
4139
|
* const tileIndex = 0;
|
|
@@ -4221,28 +4165,27 @@ class TileLayerData
|
|
|
4221
4165
|
clear() { this.tile = this.direction = 0; this.mirror = false; this.color = new Color; }
|
|
4222
4166
|
}
|
|
4223
4167
|
|
|
4168
|
+
///////////////////////////////////////////////////////////////////////////////
|
|
4224
4169
|
/**
|
|
4225
4170
|
* Tile Layer - cached rendering system for tile layers
|
|
4226
4171
|
* - Each Tile layer is rendered to an off screen canvas
|
|
4227
4172
|
* - To allow dynamic modifications, layers are rendered using canvas 2d
|
|
4228
4173
|
* - Some devices like mobile phones are limited to 4k texture resolution
|
|
4229
|
-
* -
|
|
4174
|
+
* - For with 16x16 tiles this limits layers to 256x256 on mobile devices
|
|
4230
4175
|
* @extends EngineObject
|
|
4231
4176
|
* @example
|
|
4232
|
-
*
|
|
4233
|
-
* initTileCollision(vec2(200,100));
|
|
4234
|
-
* const tileLayer = new TileLayer();
|
|
4177
|
+
* const tileLayer = new TileLayer(vec2(), vec2(200,100));
|
|
4235
4178
|
*/
|
|
4236
4179
|
class TileLayer extends EngineObject
|
|
4237
4180
|
{
|
|
4238
4181
|
/** Create a tile layer object
|
|
4239
|
-
* @param {Vector2} [position=(0,0)]
|
|
4240
|
-
* @param {Vector2} [size=
|
|
4241
|
-
* @param {TileInfo} [tileInfo]
|
|
4242
|
-
* @param {Vector2} [scale=(1,1)]
|
|
4243
|
-
* @param {number} [renderOrder]
|
|
4182
|
+
* @param {Vector2} [position=(0,0)] - World space position
|
|
4183
|
+
* @param {Vector2} [size=(1,1)] - World space size
|
|
4184
|
+
* @param {TileInfo} [tileInfo] - Tile info for layer
|
|
4185
|
+
* @param {Vector2} [scale=(1,1)] - How much to scale this layer when rendered
|
|
4186
|
+
* @param {number} [renderOrder] - Objects are sorted by renderOrder
|
|
4244
4187
|
*/
|
|
4245
|
-
constructor(position, size
|
|
4188
|
+
constructor(position, size, tileInfo=tile(), scale=vec2(1), renderOrder=0)
|
|
4246
4189
|
{
|
|
4247
4190
|
super(position, size, tileInfo, 0, undefined, renderOrder);
|
|
4248
4191
|
|
|
@@ -4254,6 +4197,10 @@ class TileLayer extends EngineObject
|
|
|
4254
4197
|
this.scale = scale;
|
|
4255
4198
|
/** @property {boolean} - If true this layer will render to overlay canvas and appear above all objects */
|
|
4256
4199
|
this.isOverlay = false;
|
|
4200
|
+
// set no friction by default, applied friction is max of both objects
|
|
4201
|
+
this.friction = 0;
|
|
4202
|
+
// set no elasticity by default, applied elasticity is max of both objects
|
|
4203
|
+
this.elasticity = 0;
|
|
4257
4204
|
|
|
4258
4205
|
// init tile data
|
|
4259
4206
|
this.data = [];
|
|
@@ -4450,6 +4397,146 @@ class TileLayer extends EngineObject
|
|
|
4450
4397
|
* @param {number} [angle=0] */
|
|
4451
4398
|
drawRect(pos, size, color, angle)
|
|
4452
4399
|
{ this.drawTile(pos, size, undefined, color, angle); }
|
|
4400
|
+
}
|
|
4401
|
+
|
|
4402
|
+
///////////////////////////////////////////////////////////////////////////////
|
|
4403
|
+
/**
|
|
4404
|
+
* Tile Collision Layer - a tile layer with collision
|
|
4405
|
+
* - adds collision data and functions to TileLayer
|
|
4406
|
+
* - there can be multiple tile collision layers
|
|
4407
|
+
* - tile collison layers should not overlap each other
|
|
4408
|
+
* @extends TileLayer
|
|
4409
|
+
*/
|
|
4410
|
+
class TileCollisionLayer extends TileLayer
|
|
4411
|
+
{
|
|
4412
|
+
/** Create a tile layer object
|
|
4413
|
+
* @param {Vector2} [position=(0,0)] - World space position
|
|
4414
|
+
* @param {Vector2} [size=(0,0)] - World space size
|
|
4415
|
+
* @param {TileInfo} [tileInfo] - Tile info for layer
|
|
4416
|
+
* @param {number} [renderOrder] - Objects are sorted by renderOrder
|
|
4417
|
+
*/
|
|
4418
|
+
constructor(position, size, tileInfo=tile(), renderOrder=0)
|
|
4419
|
+
{
|
|
4420
|
+
const scale = vec2(1); // collision layers are not scaled
|
|
4421
|
+
super(position, size.floor(), tileInfo, scale, renderOrder);
|
|
4422
|
+
|
|
4423
|
+
/** @property {Array<number>} - The tile collision grid */
|
|
4424
|
+
this.collisionData = [];
|
|
4425
|
+
this.initCollision(this.size);
|
|
4426
|
+
|
|
4427
|
+
// keep track of all collision layers
|
|
4428
|
+
tileCollisionLayers.push(this);
|
|
4429
|
+
}
|
|
4430
|
+
|
|
4431
|
+
/** Destroy this collision layer */
|
|
4432
|
+
destroy()
|
|
4433
|
+
{
|
|
4434
|
+
if (this.destroyed)
|
|
4435
|
+
return;
|
|
4436
|
+
|
|
4437
|
+
// remove from collision layers array and destroy
|
|
4438
|
+
const index = tileCollisionLayers.indexOf(this);
|
|
4439
|
+
ASSERT(index >= 0, 'tile collision layer not found in array');
|
|
4440
|
+
tileCollisionLayers.splice(index, 1);
|
|
4441
|
+
super.destroy();
|
|
4442
|
+
}
|
|
4443
|
+
|
|
4444
|
+
/** Clear and initialize tile collision to new size
|
|
4445
|
+
* @param {Vector2} size - width and height of tile collision 2d grid */
|
|
4446
|
+
initCollision(size)
|
|
4447
|
+
{
|
|
4448
|
+
this.size = size.floor();
|
|
4449
|
+
this.collisionData = [];
|
|
4450
|
+
this.collisionData.length = size.area();
|
|
4451
|
+
this.collisionData.fill(0);
|
|
4452
|
+
}
|
|
4453
|
+
|
|
4454
|
+
/** Set tile collision data for a given cell in the grid
|
|
4455
|
+
* @param {Vector2} pos
|
|
4456
|
+
* @param {number} [data] */
|
|
4457
|
+
setCollisionData(pos, data=1)
|
|
4458
|
+
{
|
|
4459
|
+
const i = (pos.y|0)*this.size.x + pos.x|0;
|
|
4460
|
+
pos.arrayCheck(this.size) && (this.collisionData[i] = data);
|
|
4461
|
+
}
|
|
4462
|
+
|
|
4463
|
+
/** Get tile collision data for a given cell in the grid
|
|
4464
|
+
* @param {Vector2} pos
|
|
4465
|
+
* @return {number} */
|
|
4466
|
+
getCollisionData(pos)
|
|
4467
|
+
{
|
|
4468
|
+
const i = (pos.y|0)*this.size.x + pos.x|0;
|
|
4469
|
+
return pos.arrayCheck(this.size) ? this.collisionData[i] : 0;
|
|
4470
|
+
}
|
|
4471
|
+
|
|
4472
|
+
/** Check if collision with another object should occur
|
|
4473
|
+
* @param {Vector2} pos
|
|
4474
|
+
* @param {Vector2} [size=(0,0)]
|
|
4475
|
+
* @param {EngineObject} [object]
|
|
4476
|
+
* @return {boolean} */
|
|
4477
|
+
collisionTest(pos, size=vec2(), object)
|
|
4478
|
+
{
|
|
4479
|
+
const minX = max(pos.x - size.x/2|0, 0);
|
|
4480
|
+
const minY = max(pos.y - size.y/2|0, 0);
|
|
4481
|
+
const maxX = min(pos.x + size.x/2, this.size.x);
|
|
4482
|
+
const maxY = min(pos.y + size.y/2, this.size.y);
|
|
4483
|
+
for (let y = minY; y < maxY; ++y)
|
|
4484
|
+
for (let x = minX; x < maxX; ++x)
|
|
4485
|
+
{
|
|
4486
|
+
// check if the object should collide with this tile
|
|
4487
|
+
const tileData = this.collisionData[y*this.size.x+x];
|
|
4488
|
+
if (tileData && (!object || object.collideWithTile(tileData, vec2(x, y))))
|
|
4489
|
+
return true;
|
|
4490
|
+
}
|
|
4491
|
+
return false;
|
|
4492
|
+
}
|
|
4493
|
+
|
|
4494
|
+
/** Return the center of first tile hit, undefined if nothing was hit.
|
|
4495
|
+
* This does not return the exact intersection, but the center of the tile hit.
|
|
4496
|
+
* @param {Vector2} posStart
|
|
4497
|
+
* @param {Vector2} posEnd
|
|
4498
|
+
* @param {EngineObject} [object]
|
|
4499
|
+
* @return {Vector2} */
|
|
4500
|
+
collisionRaycast(posStart, posEnd, object)
|
|
4501
|
+
{
|
|
4502
|
+
// test if a ray collides with tiles from start to end
|
|
4503
|
+
// todo: a way to get the exact hit point, it must still be inside the hit tile
|
|
4504
|
+
const delta = posEnd.subtract(posStart);
|
|
4505
|
+
const totalLength = delta.length();
|
|
4506
|
+
const normalizedDelta = delta.normalize();
|
|
4507
|
+
const unit = vec2(abs(1/normalizedDelta.x), abs(1/normalizedDelta.y));
|
|
4508
|
+
const flooredPosStart = posStart.floor();
|
|
4509
|
+
|
|
4510
|
+
// setup iteration variables
|
|
4511
|
+
let pos = flooredPosStart;
|
|
4512
|
+
let xi = unit.x * (delta.x < 0 ? posStart.x - pos.x : pos.x - posStart.x + 1);
|
|
4513
|
+
let yi = unit.y * (delta.y < 0 ? posStart.y - pos.y : pos.y - posStart.y + 1);
|
|
4514
|
+
|
|
4515
|
+
// use line drawing algorithm to test for collisions
|
|
4516
|
+
while (true)
|
|
4517
|
+
{
|
|
4518
|
+
// check for tile collision
|
|
4519
|
+
const tileData = this.getCollisionData(pos);
|
|
4520
|
+
if (tileData && (!object || object.collideWithTile(tileData, pos)))
|
|
4521
|
+
{
|
|
4522
|
+
debugRaycast && debugLine(posStart, posEnd, '#f00', .02);
|
|
4523
|
+
debugRaycast && debugPoint(pos.add(vec2(.5)), '#ff0');
|
|
4524
|
+
return pos.add(vec2(.5));
|
|
4525
|
+
}
|
|
4526
|
+
|
|
4527
|
+
// check if past the end
|
|
4528
|
+
if (xi > totalLength && yi > totalLength)
|
|
4529
|
+
break;
|
|
4530
|
+
|
|
4531
|
+
// get coordinates of next tile to check
|
|
4532
|
+
if (xi > yi)
|
|
4533
|
+
pos.y += sign(delta.y), yi += unit.y;
|
|
4534
|
+
else
|
|
4535
|
+
pos.x += sign(delta.x), xi += unit.x;
|
|
4536
|
+
}
|
|
4537
|
+
|
|
4538
|
+
debugRaycast && debugLine(posStart, posEnd, '#00f', .02);
|
|
4539
|
+
}
|
|
4453
4540
|
}
|
|
4454
4541
|
/**
|
|
4455
4542
|
* LittleJS Particle System
|
|
@@ -5326,7 +5413,7 @@ const engineName = 'LittleJS';
|
|
|
5326
5413
|
* @type {string}
|
|
5327
5414
|
* @default
|
|
5328
5415
|
* @memberof Engine */
|
|
5329
|
-
const engineVersion = '1.
|
|
5416
|
+
const engineVersion = '1.12.4';
|
|
5330
5417
|
|
|
5331
5418
|
/** Frames per second to update
|
|
5332
5419
|
* @type {number}
|
|
@@ -5920,383 +6007,80 @@ function drawEngineSplashScreen(t)
|
|
|
5920
6007
|
x.restore();
|
|
5921
6008
|
}
|
|
5922
6009
|
|
|
5923
|
-
|
|
6010
|
+
/**
|
|
6011
|
+
* LittleJS Newgrounds API
|
|
6012
|
+
* - NewgroundsMedal extends Medal with Newgrounds API functionality
|
|
6013
|
+
* - Call new NewgroundsPlugin() to setup Newgrounds
|
|
6014
|
+
* - Uses CryptoJS for encryption if optional cipher is provided
|
|
6015
|
+
* - Keeps connection alive and logs views
|
|
6016
|
+
* - Functions to interact with scoreboards
|
|
6017
|
+
* - Functions to unlock medals
|
|
6018
|
+
*/
|
|
6019
|
+
|
|
6020
|
+
|
|
6021
|
+
|
|
6022
|
+
/** Global Newgrounds object
|
|
6023
|
+
* @type {NewgroundsPlugin}
|
|
6024
|
+
* @memberof Medal */
|
|
6025
|
+
let newgrounds;
|
|
6026
|
+
|
|
6027
|
+
///////////////////////////////////////////////////////////////////////////////
|
|
5924
6028
|
/**
|
|
5925
|
-
*
|
|
6029
|
+
* Newgrounds medal auto unlocks in newgrounds API
|
|
6030
|
+
* @extends Medal
|
|
5926
6031
|
*/
|
|
6032
|
+
class NewgroundsMedal extends Medal
|
|
6033
|
+
{
|
|
6034
|
+
/** Create a newgrounds medal object and adds it to the list of medals
|
|
6035
|
+
* @param {Number} id - The unique identifier of the medal
|
|
6036
|
+
* @param {String} name - Name of the medal
|
|
6037
|
+
* @param {String} [description] - Description of the medal
|
|
6038
|
+
* @param {String} [icon] - Icon for the medal
|
|
6039
|
+
* @param {String} [src] - Image location for the medal
|
|
6040
|
+
*/
|
|
6041
|
+
constructor(id, name, description, icon, src)
|
|
6042
|
+
{ super(id, name, description, icon, src); }
|
|
5927
6043
|
|
|
5928
|
-
|
|
6044
|
+
/** Unlocks a medal if not already unlocked */
|
|
6045
|
+
unlock()
|
|
6046
|
+
{
|
|
6047
|
+
super.unlock();
|
|
6048
|
+
newgrounds && newgrounds.unlockMedal(this.id);
|
|
6049
|
+
}
|
|
6050
|
+
}
|
|
5929
6051
|
|
|
5930
|
-
|
|
6052
|
+
///////////////////////////////////////////////////////////////////////////////
|
|
6053
|
+
/**
|
|
6054
|
+
* Newgrounds API object
|
|
6055
|
+
*/
|
|
6056
|
+
class NewgroundsPlugin
|
|
5931
6057
|
{
|
|
5932
|
-
|
|
5933
|
-
|
|
5934
|
-
|
|
5935
|
-
|
|
5936
|
-
|
|
5937
|
-
|
|
5938
|
-
|
|
5939
|
-
|
|
5940
|
-
|
|
5941
|
-
|
|
5942
|
-
|
|
5943
|
-
|
|
5944
|
-
|
|
5945
|
-
engineObjectsDestroy,
|
|
5946
|
-
engineObjectsCollect,
|
|
5947
|
-
engineObjectsCallback,
|
|
5948
|
-
engineObjectsRaycast,
|
|
5949
|
-
engineAddPlugin,
|
|
6058
|
+
/** Create the global newgrounds object
|
|
6059
|
+
* @param {string} app_id - The newgrounds App ID
|
|
6060
|
+
* @param {string} [cipher] - The encryption Key (AES-128/Base64)
|
|
6061
|
+
* @param {Object} [cryptoJS] - An instance of CryptoJS, if there is a cipher
|
|
6062
|
+
* @example
|
|
6063
|
+
* // create the newgrounds object, replace the app id with your own
|
|
6064
|
+
* const app_id = 'your_app_id_here';
|
|
6065
|
+
* new NewgroundsPlugin(app_id);
|
|
6066
|
+
*/
|
|
6067
|
+
constructor(app_id, cipher, cryptoJS)
|
|
6068
|
+
{
|
|
6069
|
+
ASSERT(!newgrounds, 'there can only be one newgrounds object');
|
|
6070
|
+
ASSERT(!cipher || cryptoJS, 'must provide cryptojs if there is a cipher');
|
|
5950
6071
|
|
|
5951
|
-
|
|
5952
|
-
|
|
5953
|
-
|
|
5954
|
-
|
|
6072
|
+
newgrounds = this; // set global newgrounds object
|
|
6073
|
+
this.app_id = app_id;
|
|
6074
|
+
this.cipher = cipher;
|
|
6075
|
+
this.cryptoJS = cryptoJS;
|
|
6076
|
+
this.host = location ? location.hostname : '';
|
|
5955
6077
|
|
|
5956
|
-
|
|
5957
|
-
|
|
5958
|
-
|
|
5959
|
-
debugPoly,
|
|
5960
|
-
debugCircle,
|
|
5961
|
-
debugPoint,
|
|
5962
|
-
debugLine,
|
|
5963
|
-
debugOverlap,
|
|
5964
|
-
debugText,
|
|
5965
|
-
debugClear,
|
|
5966
|
-
debugScreenshot,
|
|
5967
|
-
debugSaveCanvas,
|
|
5968
|
-
debugSaveText,
|
|
5969
|
-
debugSaveDataURL,
|
|
5970
|
-
debugShowErrors,
|
|
5971
|
-
debugVideoCaptureIsActive,
|
|
5972
|
-
debugVideoCaptureStart,
|
|
5973
|
-
debugVideoCaptureStop,
|
|
6078
|
+
// get session id from url search params
|
|
6079
|
+
const url = new URL(location.href);
|
|
6080
|
+
this.session_id = url.searchParams.get('ngio_session_id');
|
|
5974
6081
|
|
|
5975
|
-
|
|
5976
|
-
|
|
5977
|
-
cameraScale,
|
|
5978
|
-
canvasMaxSize,
|
|
5979
|
-
canvasFixedSize,
|
|
5980
|
-
canvasPixelated,
|
|
5981
|
-
tilesPixelated,
|
|
5982
|
-
fontDefault,
|
|
5983
|
-
showSplashScreen,
|
|
5984
|
-
headlessMode,
|
|
5985
|
-
tileSizeDefault,
|
|
5986
|
-
tileFixBleedScale,
|
|
5987
|
-
enablePhysicsSolver,
|
|
5988
|
-
objectDefaultMass,
|
|
5989
|
-
objectDefaultDamping,
|
|
5990
|
-
objectDefaultAngleDamping,
|
|
5991
|
-
objectDefaultElasticity,
|
|
5992
|
-
objectDefaultFriction,
|
|
5993
|
-
objectMaxSpeed,
|
|
5994
|
-
gravity,
|
|
5995
|
-
particleEmitRateScale,
|
|
5996
|
-
glEnable,
|
|
5997
|
-
glOverlay,
|
|
5998
|
-
gamepadsEnable,
|
|
5999
|
-
gamepadDirectionEmulateStick,
|
|
6000
|
-
inputWASDEmulateDirection,
|
|
6001
|
-
touchGamepadEnable,
|
|
6002
|
-
touchGamepadAnalog,
|
|
6003
|
-
touchGamepadSize,
|
|
6004
|
-
touchGamepadAlpha,
|
|
6005
|
-
vibrateEnable,
|
|
6006
|
-
soundEnable,
|
|
6007
|
-
soundVolume,
|
|
6008
|
-
soundDefaultRange,
|
|
6009
|
-
soundDefaultTaper,
|
|
6010
|
-
medalDisplayTime,
|
|
6011
|
-
medalDisplaySlideTime,
|
|
6012
|
-
medalDisplaySize,
|
|
6013
|
-
|
|
6014
|
-
// Setters for globals
|
|
6015
|
-
setCameraPos,
|
|
6016
|
-
setCameraScale,
|
|
6017
|
-
setCanvasMaxSize,
|
|
6018
|
-
setCanvasFixedSize,
|
|
6019
|
-
setCanvasPixelated,
|
|
6020
|
-
setTilesPixelated,
|
|
6021
|
-
setFontDefault,
|
|
6022
|
-
setShowSplashScreen,
|
|
6023
|
-
setHeadlessMode,
|
|
6024
|
-
setGlEnable,
|
|
6025
|
-
setGlOverlay,
|
|
6026
|
-
setTileSizeDefault,
|
|
6027
|
-
setTileFixBleedScale,
|
|
6028
|
-
setEnablePhysicsSolver,
|
|
6029
|
-
setObjectDefaultMass,
|
|
6030
|
-
setObjectDefaultDamping,
|
|
6031
|
-
setObjectDefaultAngleDamping,
|
|
6032
|
-
setObjectDefaultElasticity,
|
|
6033
|
-
setObjectDefaultFriction,
|
|
6034
|
-
setObjectMaxSpeed,
|
|
6035
|
-
setGravity,
|
|
6036
|
-
setParticleEmitRateScale,
|
|
6037
|
-
setTouchInputEnable,
|
|
6038
|
-
setGamepadsEnable,
|
|
6039
|
-
setGamepadDirectionEmulateStick,
|
|
6040
|
-
setInputWASDEmulateDirection,
|
|
6041
|
-
setTouchGamepadEnable,
|
|
6042
|
-
setTouchGamepadAnalog,
|
|
6043
|
-
setTouchGamepadSize,
|
|
6044
|
-
setTouchGamepadAlpha,
|
|
6045
|
-
setVibrateEnable,
|
|
6046
|
-
setSoundEnable,
|
|
6047
|
-
setSoundVolume,
|
|
6048
|
-
setSoundDefaultRange,
|
|
6049
|
-
setSoundDefaultTaper,
|
|
6050
|
-
setMedalDisplayTime,
|
|
6051
|
-
setMedalDisplaySlideTime,
|
|
6052
|
-
setMedalDisplaySize,
|
|
6053
|
-
setMedalsPreventUnlock,
|
|
6054
|
-
setShowWatermark,
|
|
6055
|
-
setDebugKey,
|
|
6056
|
-
|
|
6057
|
-
// Utilities
|
|
6058
|
-
PI,
|
|
6059
|
-
abs,
|
|
6060
|
-
min,
|
|
6061
|
-
max,
|
|
6062
|
-
sign,
|
|
6063
|
-
mod,
|
|
6064
|
-
clamp,
|
|
6065
|
-
percent,
|
|
6066
|
-
distanceWrap,
|
|
6067
|
-
lerpWrap,
|
|
6068
|
-
distanceAngle,
|
|
6069
|
-
lerpAngle,
|
|
6070
|
-
lerp,
|
|
6071
|
-
smoothStep,
|
|
6072
|
-
nearestPowerOfTwo,
|
|
6073
|
-
isOverlapping,
|
|
6074
|
-
isIntersecting,
|
|
6075
|
-
wave,
|
|
6076
|
-
formatTime,
|
|
6077
|
-
|
|
6078
|
-
// Random
|
|
6079
|
-
rand,
|
|
6080
|
-
randInt,
|
|
6081
|
-
randSign,
|
|
6082
|
-
randInCircle,
|
|
6083
|
-
randVector,
|
|
6084
|
-
randColor,
|
|
6085
|
-
|
|
6086
|
-
// Utility Classes
|
|
6087
|
-
RandomGenerator,
|
|
6088
|
-
Vector2,
|
|
6089
|
-
Color,
|
|
6090
|
-
Timer,
|
|
6091
|
-
vec2,
|
|
6092
|
-
rgb,
|
|
6093
|
-
hsl,
|
|
6094
|
-
isColor,
|
|
6095
|
-
|
|
6096
|
-
// Default Colors
|
|
6097
|
-
WHITE,
|
|
6098
|
-
BLACK,
|
|
6099
|
-
GRAY,
|
|
6100
|
-
RED,
|
|
6101
|
-
ORANGE,
|
|
6102
|
-
YELLOW,
|
|
6103
|
-
GREEN,
|
|
6104
|
-
CYAN,
|
|
6105
|
-
BLUE,
|
|
6106
|
-
PURPLE,
|
|
6107
|
-
MAGENTA,
|
|
6108
|
-
|
|
6109
|
-
// Draw
|
|
6110
|
-
textureInfos,
|
|
6111
|
-
tile,
|
|
6112
|
-
TileInfo,
|
|
6113
|
-
TextureInfo,
|
|
6114
|
-
mainCanvas,
|
|
6115
|
-
mainContext,
|
|
6116
|
-
overlayCanvas,
|
|
6117
|
-
overlayContext,
|
|
6118
|
-
mainCanvasSize,
|
|
6119
|
-
screenToWorld,
|
|
6120
|
-
worldToScreen,
|
|
6121
|
-
drawTile,
|
|
6122
|
-
drawRect,
|
|
6123
|
-
drawLine,
|
|
6124
|
-
drawPoly,
|
|
6125
|
-
drawEllipse,
|
|
6126
|
-
drawCircle,
|
|
6127
|
-
drawCanvas2D,
|
|
6128
|
-
drawText,
|
|
6129
|
-
drawTextOverlay,
|
|
6130
|
-
drawTextScreen,
|
|
6131
|
-
setBlendMode,
|
|
6132
|
-
combineCanvases,
|
|
6133
|
-
engineFontImage,
|
|
6134
|
-
FontImage,
|
|
6135
|
-
isFullscreen,
|
|
6136
|
-
toggleFullscreen,
|
|
6137
|
-
setCursor,
|
|
6138
|
-
getCameraSize,
|
|
6139
|
-
|
|
6140
|
-
// WebGL
|
|
6141
|
-
glCanvas,
|
|
6142
|
-
glContext,
|
|
6143
|
-
glCompileShader,
|
|
6144
|
-
glCopyToContext,
|
|
6145
|
-
glCreateProgram,
|
|
6146
|
-
glCreateTexture,
|
|
6147
|
-
glSetTextureData,
|
|
6148
|
-
glDraw,
|
|
6149
|
-
glFlush,
|
|
6150
|
-
glSetTexture,
|
|
6151
|
-
glSetAntialias,
|
|
6152
|
-
glClearCanvas,
|
|
6153
|
-
glAntialias,
|
|
6154
|
-
glShader,
|
|
6155
|
-
glActiveTexture,
|
|
6156
|
-
glArrayBuffer,
|
|
6157
|
-
glGeometryBuffer,
|
|
6158
|
-
glPositionData,
|
|
6159
|
-
glColorData,
|
|
6160
|
-
glInstanceCount,
|
|
6161
|
-
glAdditive,
|
|
6162
|
-
glBatchAdditive,
|
|
6163
|
-
|
|
6164
|
-
// Input
|
|
6165
|
-
keyIsDown,
|
|
6166
|
-
keyWasPressed,
|
|
6167
|
-
keyWasReleased,
|
|
6168
|
-
keyDirection,
|
|
6169
|
-
clearInput,
|
|
6170
|
-
mouseIsDown,
|
|
6171
|
-
mouseWasPressed,
|
|
6172
|
-
mouseWasReleased,
|
|
6173
|
-
mousePos,
|
|
6174
|
-
mousePosScreen,
|
|
6175
|
-
mouseWheel,
|
|
6176
|
-
isUsingGamepad,
|
|
6177
|
-
inputPreventDefault,
|
|
6178
|
-
setInputPreventDefault,
|
|
6179
|
-
gamepadIsDown,
|
|
6180
|
-
gamepadWasPressed,
|
|
6181
|
-
gamepadWasReleased,
|
|
6182
|
-
gamepadStick,
|
|
6183
|
-
gamepadsUpdate,
|
|
6184
|
-
vibrate,
|
|
6185
|
-
vibrateStop,
|
|
6186
|
-
isTouchDevice,
|
|
6187
|
-
|
|
6188
|
-
// Audio
|
|
6189
|
-
Sound,
|
|
6190
|
-
SoundWave,
|
|
6191
|
-
playAudioFile,
|
|
6192
|
-
speak,
|
|
6193
|
-
speakStop,
|
|
6194
|
-
getNoteFrequency,
|
|
6195
|
-
playSamples,
|
|
6196
|
-
zzfx,
|
|
6197
|
-
zzfxG,
|
|
6198
|
-
zzfxR,
|
|
6199
|
-
audioContext,
|
|
6200
|
-
|
|
6201
|
-
// Base Object
|
|
6202
|
-
EngineObject,
|
|
6203
|
-
|
|
6204
|
-
// Tiles
|
|
6205
|
-
tileCollision,
|
|
6206
|
-
tileCollisionSize,
|
|
6207
|
-
initTileCollision,
|
|
6208
|
-
setTileCollisionData,
|
|
6209
|
-
getTileCollisionData,
|
|
6210
|
-
tileCollisionTest,
|
|
6211
|
-
tileCollisionRaycast,
|
|
6212
|
-
TileLayerData,
|
|
6213
|
-
TileLayer,
|
|
6214
|
-
|
|
6215
|
-
// Particles
|
|
6216
|
-
ParticleEmitter,
|
|
6217
|
-
Particle,
|
|
6218
|
-
|
|
6219
|
-
// Medals
|
|
6220
|
-
medals,
|
|
6221
|
-
medalsPreventUnlock,
|
|
6222
|
-
medalsInit,
|
|
6223
|
-
Medal,
|
|
6224
|
-
};
|
|
6225
|
-
|
|
6226
|
-
/**
|
|
6227
|
-
* LittleJS Newgrounds API
|
|
6228
|
-
* - NewgroundsMedal extends Medal with Newgrounds API functionality
|
|
6229
|
-
* - Call new NewgroundsPlugin() to setup Newgrounds
|
|
6230
|
-
* - Uses CryptoJS for encryption if optional cipher is provided
|
|
6231
|
-
* - Keeps connection alive and logs views
|
|
6232
|
-
* - Functions to interact with scoreboards
|
|
6233
|
-
* - Functions to unlock medals
|
|
6234
|
-
*/
|
|
6235
|
-
|
|
6236
|
-
'use strict';
|
|
6237
|
-
|
|
6238
|
-
/** Global Newgrounds object
|
|
6239
|
-
* @type {NewgroundsPlugin}
|
|
6240
|
-
* @memberof Medal */
|
|
6241
|
-
let newgrounds;
|
|
6242
|
-
|
|
6243
|
-
///////////////////////////////////////////////////////////////////////////////
|
|
6244
|
-
/**
|
|
6245
|
-
* Newgrounds medal auto unlocks in newgrounds API
|
|
6246
|
-
* @extends Medal
|
|
6247
|
-
*/
|
|
6248
|
-
class NewgroundsMedal extends Medal
|
|
6249
|
-
{
|
|
6250
|
-
/** Create a newgrounds medal object and adds it to the list of medals
|
|
6251
|
-
* @param {Number} id - The unique identifier of the medal
|
|
6252
|
-
* @param {String} name - Name of the medal
|
|
6253
|
-
* @param {String} [description] - Description of the medal
|
|
6254
|
-
* @param {String} [icon] - Icon for the medal
|
|
6255
|
-
* @param {String} [src] - Image location for the medal
|
|
6256
|
-
*/
|
|
6257
|
-
constructor(id, name, description, icon, src)
|
|
6258
|
-
{ super(id, name, description, icon, src); }
|
|
6259
|
-
|
|
6260
|
-
/** Unlocks a medal if not already unlocked */
|
|
6261
|
-
unlock()
|
|
6262
|
-
{
|
|
6263
|
-
super.unlock();
|
|
6264
|
-
newgrounds && newgrounds.unlockMedal(this.id);
|
|
6265
|
-
}
|
|
6266
|
-
}
|
|
6267
|
-
|
|
6268
|
-
///////////////////////////////////////////////////////////////////////////////
|
|
6269
|
-
/**
|
|
6270
|
-
* Newgrounds API object
|
|
6271
|
-
*/
|
|
6272
|
-
class NewgroundsPlugin
|
|
6273
|
-
{
|
|
6274
|
-
/** Create the global newgrounds object
|
|
6275
|
-
* @param {string} app_id - The newgrounds App ID
|
|
6276
|
-
* @param {string} [cipher] - The encryption Key (AES-128/Base64)
|
|
6277
|
-
* @param {Object} [cryptoJS] - An instance of CryptoJS, if there is a cipher
|
|
6278
|
-
* @example
|
|
6279
|
-
* // create the newgrounds object, replace the app id with your own
|
|
6280
|
-
* const app_id = 'your_app_id_here';
|
|
6281
|
-
* new NewgroundsPlugin(app_id);
|
|
6282
|
-
*/
|
|
6283
|
-
constructor(app_id, cipher, cryptoJS)
|
|
6284
|
-
{
|
|
6285
|
-
ASSERT(!newgrounds, 'there can only be one newgrounds object');
|
|
6286
|
-
ASSERT(!cipher || cryptoJS, 'must provide cryptojs if there is a cipher');
|
|
6287
|
-
|
|
6288
|
-
newgrounds = this; // set global newgrounds object
|
|
6289
|
-
this.app_id = app_id;
|
|
6290
|
-
this.cipher = cipher;
|
|
6291
|
-
this.cryptoJS = cryptoJS;
|
|
6292
|
-
this.host = location ? location.hostname : '';
|
|
6293
|
-
|
|
6294
|
-
// get session id from url search params
|
|
6295
|
-
const url = new URL(location.href);
|
|
6296
|
-
this.session_id = url.searchParams.get('ngio_session_id');
|
|
6297
|
-
|
|
6298
|
-
if (!this.session_id)
|
|
6299
|
-
return; // only use newgrounds when logged in
|
|
6082
|
+
if (!this.session_id)
|
|
6083
|
+
return; // only use newgrounds when logged in
|
|
6300
6084
|
|
|
6301
6085
|
// get medals
|
|
6302
6086
|
const medalsResult = this.call('Medal.getList');
|
|
@@ -6408,7 +6192,7 @@ class NewgroundsPlugin
|
|
|
6408
6192
|
* - can be enabled to pass other canvases through a final shader
|
|
6409
6193
|
*/
|
|
6410
6194
|
|
|
6411
|
-
|
|
6195
|
+
|
|
6412
6196
|
|
|
6413
6197
|
///////////////////////////////////////////////////////////////////////////////
|
|
6414
6198
|
|
|
@@ -6522,7 +6306,7 @@ class PostProcessPlugin
|
|
|
6522
6306
|
* LittleJS ZzFXM Plugin
|
|
6523
6307
|
*/
|
|
6524
6308
|
|
|
6525
|
-
|
|
6309
|
+
|
|
6526
6310
|
|
|
6527
6311
|
/**
|
|
6528
6312
|
* Music Object - Stores a zzfx music track for later use
|
|
@@ -6692,7 +6476,7 @@ function zzfxM(instruments, patterns, sequence, BPM = 125)
|
|
|
6692
6476
|
* - Images
|
|
6693
6477
|
*/
|
|
6694
6478
|
|
|
6695
|
-
|
|
6479
|
+
|
|
6696
6480
|
|
|
6697
6481
|
///////////////////////////////////////////////////////////////////////////////
|
|
6698
6482
|
|
|
@@ -7152,7 +6936,7 @@ class UIScrollbar extends UIObject
|
|
|
7152
6936
|
* - Debug physics drawing
|
|
7153
6937
|
*/
|
|
7154
6938
|
|
|
7155
|
-
|
|
6939
|
+
|
|
7156
6940
|
|
|
7157
6941
|
/** Global Box2d Plugin object
|
|
7158
6942
|
* @type {Box2dPlugin} */
|
|
@@ -7163,7 +6947,11 @@ let box2d;
|
|
|
7163
6947
|
* @default */
|
|
7164
6948
|
let box2dDebug = false;
|
|
7165
6949
|
|
|
7166
|
-
|
|
6950
|
+
/** Enable Box2D debug drawing
|
|
6951
|
+
* @param {boolean} enable */
|
|
6952
|
+
function box2dSetDebug(enable) { box2dDebug = enable; }
|
|
6953
|
+
|
|
6954
|
+
///////////////////////////////////////////////////////////////////////////////
|
|
7167
6955
|
/**
|
|
7168
6956
|
* Box2D Object - extend with your own custom physics objects
|
|
7169
6957
|
* - A LittleJS object with Box2D physics
|
|
@@ -8566,7 +8354,7 @@ class Box2dPlugin
|
|
|
8566
8354
|
* @param {number} [frames] */
|
|
8567
8355
|
step(frames=1)
|
|
8568
8356
|
{
|
|
8569
|
-
box2d.world.SetGravity(box2d.vec2dTo(
|
|
8357
|
+
box2d.world.SetGravity(box2d.vec2dTo(gravity));
|
|
8570
8358
|
for (let i=frames; i--;)
|
|
8571
8359
|
box2d.world.Step(timeDelta, this.velocityIterations, this.positionIterations);
|
|
8572
8360
|
}
|
|
@@ -8707,8 +8495,8 @@ class Box2dPlugin
|
|
|
8707
8495
|
aabb.set_upperBound(box2d.vec2dTo(pos));
|
|
8708
8496
|
|
|
8709
8497
|
let queryObject;
|
|
8710
|
-
debugRaycast && debugRect(pos, vec2(), queryObject ? '#f00' : '#00f', .02);
|
|
8711
8498
|
box2d.world.QueryAABB(queryCallback, aabb);
|
|
8499
|
+
debugRaycast && debugRect(pos, vec2(), queryObject ? '#f00' : '#00f', .02);
|
|
8712
8500
|
return queryObject;
|
|
8713
8501
|
}
|
|
8714
8502
|
|
|
@@ -9003,11 +8791,308 @@ function box2dEngineInit(gameInit, gameUpdate, gameUpdatePost, gameRender, gameR
|
|
|
9003
8791
|
}
|
|
9004
8792
|
}
|
|
9005
8793
|
|
|
8794
|
+
|
|
9006
8795
|
/**
|
|
9007
|
-
* LittleJS Module
|
|
8796
|
+
* LittleJS Module Export
|
|
9008
8797
|
*/
|
|
9009
8798
|
|
|
9010
|
-
|
|
8799
|
+
export
|
|
8800
|
+
{
|
|
8801
|
+
// Engine
|
|
8802
|
+
engineName,
|
|
8803
|
+
engineVersion,
|
|
8804
|
+
frameRate,
|
|
8805
|
+
timeDelta,
|
|
8806
|
+
engineObjects,
|
|
8807
|
+
frame,
|
|
8808
|
+
time,
|
|
8809
|
+
timeReal,
|
|
8810
|
+
paused,
|
|
8811
|
+
setPaused,
|
|
8812
|
+
engineInit,
|
|
8813
|
+
engineObjectsUpdate,
|
|
8814
|
+
engineObjectsDestroy,
|
|
8815
|
+
engineObjectsCollect,
|
|
8816
|
+
engineObjectsCallback,
|
|
8817
|
+
engineObjectsRaycast,
|
|
8818
|
+
engineAddPlugin,
|
|
8819
|
+
|
|
8820
|
+
// Globals
|
|
8821
|
+
debug,
|
|
8822
|
+
debugOverlay,
|
|
8823
|
+
showWatermark,
|
|
8824
|
+
|
|
8825
|
+
// Debug
|
|
8826
|
+
ASSERT,
|
|
8827
|
+
debugRect,
|
|
8828
|
+
debugPoly,
|
|
8829
|
+
debugCircle,
|
|
8830
|
+
debugPoint,
|
|
8831
|
+
debugLine,
|
|
8832
|
+
debugOverlap,
|
|
8833
|
+
debugText,
|
|
8834
|
+
debugClear,
|
|
8835
|
+
debugScreenshot,
|
|
8836
|
+
debugSaveCanvas,
|
|
8837
|
+
debugSaveText,
|
|
8838
|
+
debugSaveDataURL,
|
|
8839
|
+
debugShowErrors,
|
|
8840
|
+
debugVideoCaptureIsActive,
|
|
8841
|
+
debugVideoCaptureStart,
|
|
8842
|
+
debugVideoCaptureStop,
|
|
8843
|
+
|
|
8844
|
+
// Settings
|
|
8845
|
+
cameraPos,
|
|
8846
|
+
cameraScale,
|
|
8847
|
+
canvasMaxSize,
|
|
8848
|
+
canvasFixedSize,
|
|
8849
|
+
canvasPixelated,
|
|
8850
|
+
tilesPixelated,
|
|
8851
|
+
fontDefault,
|
|
8852
|
+
showSplashScreen,
|
|
8853
|
+
headlessMode,
|
|
8854
|
+
tileSizeDefault,
|
|
8855
|
+
tileFixBleedScale,
|
|
8856
|
+
enablePhysicsSolver,
|
|
8857
|
+
objectDefaultMass,
|
|
8858
|
+
objectDefaultDamping,
|
|
8859
|
+
objectDefaultAngleDamping,
|
|
8860
|
+
objectDefaultElasticity,
|
|
8861
|
+
objectDefaultFriction,
|
|
8862
|
+
objectMaxSpeed,
|
|
8863
|
+
gravity,
|
|
8864
|
+
particleEmitRateScale,
|
|
8865
|
+
glEnable,
|
|
8866
|
+
glOverlay,
|
|
8867
|
+
gamepadsEnable,
|
|
8868
|
+
gamepadDirectionEmulateStick,
|
|
8869
|
+
inputWASDEmulateDirection,
|
|
8870
|
+
touchGamepadEnable,
|
|
8871
|
+
touchGamepadAnalog,
|
|
8872
|
+
touchGamepadSize,
|
|
8873
|
+
touchGamepadAlpha,
|
|
8874
|
+
vibrateEnable,
|
|
8875
|
+
soundEnable,
|
|
8876
|
+
soundVolume,
|
|
8877
|
+
soundDefaultRange,
|
|
8878
|
+
soundDefaultTaper,
|
|
8879
|
+
medalDisplayTime,
|
|
8880
|
+
medalDisplaySlideTime,
|
|
8881
|
+
medalDisplaySize,
|
|
8882
|
+
|
|
8883
|
+
// Setters for globals
|
|
8884
|
+
setCameraPos,
|
|
8885
|
+
setCameraScale,
|
|
8886
|
+
setCanvasMaxSize,
|
|
8887
|
+
setCanvasFixedSize,
|
|
8888
|
+
setCanvasPixelated,
|
|
8889
|
+
setTilesPixelated,
|
|
8890
|
+
setFontDefault,
|
|
8891
|
+
setShowSplashScreen,
|
|
8892
|
+
setHeadlessMode,
|
|
8893
|
+
setGlEnable,
|
|
8894
|
+
setGlOverlay,
|
|
8895
|
+
setTileSizeDefault,
|
|
8896
|
+
setTileFixBleedScale,
|
|
8897
|
+
setEnablePhysicsSolver,
|
|
8898
|
+
setObjectDefaultMass,
|
|
8899
|
+
setObjectDefaultDamping,
|
|
8900
|
+
setObjectDefaultAngleDamping,
|
|
8901
|
+
setObjectDefaultElasticity,
|
|
8902
|
+
setObjectDefaultFriction,
|
|
8903
|
+
setObjectMaxSpeed,
|
|
8904
|
+
setGravity,
|
|
8905
|
+
setParticleEmitRateScale,
|
|
8906
|
+
setTouchInputEnable,
|
|
8907
|
+
setGamepadsEnable,
|
|
8908
|
+
setGamepadDirectionEmulateStick,
|
|
8909
|
+
setInputWASDEmulateDirection,
|
|
8910
|
+
setTouchGamepadEnable,
|
|
8911
|
+
setTouchGamepadAnalog,
|
|
8912
|
+
setTouchGamepadSize,
|
|
8913
|
+
setTouchGamepadAlpha,
|
|
8914
|
+
setVibrateEnable,
|
|
8915
|
+
setSoundEnable,
|
|
8916
|
+
setSoundVolume,
|
|
8917
|
+
setSoundDefaultRange,
|
|
8918
|
+
setSoundDefaultTaper,
|
|
8919
|
+
setMedalDisplayTime,
|
|
8920
|
+
setMedalDisplaySlideTime,
|
|
8921
|
+
setMedalDisplaySize,
|
|
8922
|
+
setMedalsPreventUnlock,
|
|
8923
|
+
setShowWatermark,
|
|
8924
|
+
setDebugKey,
|
|
8925
|
+
|
|
8926
|
+
// Utilities
|
|
8927
|
+
PI,
|
|
8928
|
+
abs,
|
|
8929
|
+
min,
|
|
8930
|
+
max,
|
|
8931
|
+
sign,
|
|
8932
|
+
mod,
|
|
8933
|
+
clamp,
|
|
8934
|
+
percent,
|
|
8935
|
+
distanceWrap,
|
|
8936
|
+
lerpWrap,
|
|
8937
|
+
distanceAngle,
|
|
8938
|
+
lerpAngle,
|
|
8939
|
+
lerp,
|
|
8940
|
+
smoothStep,
|
|
8941
|
+
nearestPowerOfTwo,
|
|
8942
|
+
isOverlapping,
|
|
8943
|
+
isIntersecting,
|
|
8944
|
+
wave,
|
|
8945
|
+
formatTime,
|
|
8946
|
+
|
|
8947
|
+
// Random
|
|
8948
|
+
rand,
|
|
8949
|
+
randInt,
|
|
8950
|
+
randSign,
|
|
8951
|
+
randInCircle,
|
|
8952
|
+
randVector,
|
|
8953
|
+
randColor,
|
|
8954
|
+
|
|
8955
|
+
// Utility Classes
|
|
8956
|
+
RandomGenerator,
|
|
8957
|
+
Vector2,
|
|
8958
|
+
Color,
|
|
8959
|
+
Timer,
|
|
8960
|
+
vec2,
|
|
8961
|
+
rgb,
|
|
8962
|
+
hsl,
|
|
8963
|
+
isColor,
|
|
8964
|
+
|
|
8965
|
+
// Default Colors
|
|
8966
|
+
WHITE,
|
|
8967
|
+
BLACK,
|
|
8968
|
+
GRAY,
|
|
8969
|
+
RED,
|
|
8970
|
+
ORANGE,
|
|
8971
|
+
YELLOW,
|
|
8972
|
+
GREEN,
|
|
8973
|
+
CYAN,
|
|
8974
|
+
BLUE,
|
|
8975
|
+
PURPLE,
|
|
8976
|
+
MAGENTA,
|
|
8977
|
+
|
|
8978
|
+
// Draw
|
|
8979
|
+
textureInfos,
|
|
8980
|
+
tile,
|
|
8981
|
+
TileInfo,
|
|
8982
|
+
TextureInfo,
|
|
8983
|
+
mainCanvas,
|
|
8984
|
+
mainContext,
|
|
8985
|
+
overlayCanvas,
|
|
8986
|
+
overlayContext,
|
|
8987
|
+
mainCanvasSize,
|
|
8988
|
+
screenToWorld,
|
|
8989
|
+
worldToScreen,
|
|
8990
|
+
drawTile,
|
|
8991
|
+
drawRect,
|
|
8992
|
+
drawLine,
|
|
8993
|
+
drawPoly,
|
|
8994
|
+
drawEllipse,
|
|
8995
|
+
drawCircle,
|
|
8996
|
+
drawCanvas2D,
|
|
8997
|
+
drawText,
|
|
8998
|
+
drawTextOverlay,
|
|
8999
|
+
drawTextScreen,
|
|
9000
|
+
setBlendMode,
|
|
9001
|
+
combineCanvases,
|
|
9002
|
+
engineFontImage,
|
|
9003
|
+
FontImage,
|
|
9004
|
+
isFullscreen,
|
|
9005
|
+
toggleFullscreen,
|
|
9006
|
+
setCursor,
|
|
9007
|
+
getCameraSize,
|
|
9008
|
+
|
|
9009
|
+
// WebGL
|
|
9010
|
+
glCanvas,
|
|
9011
|
+
glContext,
|
|
9012
|
+
glCompileShader,
|
|
9013
|
+
glCopyToContext,
|
|
9014
|
+
glCreateProgram,
|
|
9015
|
+
glCreateTexture,
|
|
9016
|
+
glSetTextureData,
|
|
9017
|
+
glDraw,
|
|
9018
|
+
glFlush,
|
|
9019
|
+
glSetTexture,
|
|
9020
|
+
glSetAntialias,
|
|
9021
|
+
glClearCanvas,
|
|
9022
|
+
glAntialias,
|
|
9023
|
+
glShader,
|
|
9024
|
+
glActiveTexture,
|
|
9025
|
+
glArrayBuffer,
|
|
9026
|
+
glGeometryBuffer,
|
|
9027
|
+
glPositionData,
|
|
9028
|
+
glColorData,
|
|
9029
|
+
glInstanceCount,
|
|
9030
|
+
glAdditive,
|
|
9031
|
+
glBatchAdditive,
|
|
9032
|
+
|
|
9033
|
+
// Input
|
|
9034
|
+
keyIsDown,
|
|
9035
|
+
keyWasPressed,
|
|
9036
|
+
keyWasReleased,
|
|
9037
|
+
keyDirection,
|
|
9038
|
+
clearInput,
|
|
9039
|
+
mouseIsDown,
|
|
9040
|
+
mouseWasPressed,
|
|
9041
|
+
mouseWasReleased,
|
|
9042
|
+
mousePos,
|
|
9043
|
+
mousePosScreen,
|
|
9044
|
+
mouseWheel,
|
|
9045
|
+
isUsingGamepad,
|
|
9046
|
+
inputPreventDefault,
|
|
9047
|
+
setInputPreventDefault,
|
|
9048
|
+
gamepadIsDown,
|
|
9049
|
+
gamepadWasPressed,
|
|
9050
|
+
gamepadWasReleased,
|
|
9051
|
+
gamepadStick,
|
|
9052
|
+
gamepadsUpdate,
|
|
9053
|
+
vibrate,
|
|
9054
|
+
vibrateStop,
|
|
9055
|
+
isTouchDevice,
|
|
9056
|
+
|
|
9057
|
+
// Audio
|
|
9058
|
+
Sound,
|
|
9059
|
+
SoundWave,
|
|
9060
|
+
playAudioFile,
|
|
9061
|
+
speak,
|
|
9062
|
+
speakStop,
|
|
9063
|
+
getNoteFrequency,
|
|
9064
|
+
playSamples,
|
|
9065
|
+
zzfx,
|
|
9066
|
+
zzfxG,
|
|
9067
|
+
zzfxR,
|
|
9068
|
+
audioContext,
|
|
9069
|
+
|
|
9070
|
+
// Base Object
|
|
9071
|
+
EngineObject,
|
|
9072
|
+
|
|
9073
|
+
// Tiles
|
|
9074
|
+
tileCollisionLayers,
|
|
9075
|
+
getTileCollisionData,
|
|
9076
|
+
tileCollisionTest,
|
|
9077
|
+
tileCollisionRaycast,
|
|
9078
|
+
TileLayerData,
|
|
9079
|
+
TileLayer,
|
|
9080
|
+
TileCollisionLayer,
|
|
9081
|
+
|
|
9082
|
+
// Particles
|
|
9083
|
+
ParticleEmitter,
|
|
9084
|
+
Particle,
|
|
9085
|
+
|
|
9086
|
+
// Medals
|
|
9087
|
+
medals,
|
|
9088
|
+
medalsPreventUnlock,
|
|
9089
|
+
medalsInit,
|
|
9090
|
+
Medal,
|
|
9091
|
+
};
|
|
9092
|
+
|
|
9093
|
+
/**
|
|
9094
|
+
* LittleJS Module Plugins Export
|
|
9095
|
+
*/
|
|
9011
9096
|
|
|
9012
9097
|
export
|
|
9013
9098
|
{
|
|
@@ -9036,6 +9121,7 @@ export
|
|
|
9036
9121
|
// Box2D Physics
|
|
9037
9122
|
box2d,
|
|
9038
9123
|
box2dDebug,
|
|
9124
|
+
box2dSetDebug,
|
|
9039
9125
|
box2dEngineInit,
|
|
9040
9126
|
Box2dPlugin,
|
|
9041
9127
|
Box2dObject,
|