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/engineDraw.js
CHANGED
|
@@ -57,14 +57,14 @@ const worldToScreen = (worldPos)=>
|
|
|
57
57
|
* @param {Vector2} pos - Center of the tile in world space
|
|
58
58
|
* @param {Vector2} [size=new Vector2(1,1)] - Size of the tile in world space, width and height
|
|
59
59
|
* @param {Number} [tileIndex=-1] - Tile index to use, negative is untextured
|
|
60
|
-
* @param {Vector2} [tileSize=
|
|
60
|
+
* @param {Vector2} [tileSize=tileSizeDefault] - Tile size in source pixels
|
|
61
61
|
* @param {Color} [color=new Color(1,1,1)] - Color to modulate with
|
|
62
62
|
* @param {Number} [angle=0] - Angle to rotate by
|
|
63
63
|
* @param {Boolean} [mirror=0] - If true image is flipped along the Y axis
|
|
64
64
|
* @param {Color} [additiveColor=new Color(0,0,0,0)] - Additive color to be applied
|
|
65
65
|
* @param {Boolean} [useWebGL=glEnable] - Use accelerated WebGL rendering
|
|
66
66
|
* @memberof Draw */
|
|
67
|
-
function drawTile(pos, size=vec2(1), tileIndex=-1, tileSize=
|
|
67
|
+
function drawTile(pos, size=vec2(1), tileIndex=-1, tileSize=tileSizeDefault, color=new Color, angle=0, mirror,
|
|
68
68
|
additiveColor=new Color(0,0,0,0), useWebGL=glEnable)
|
|
69
69
|
{
|
|
70
70
|
showWatermark && ++drawCount;
|
|
@@ -128,14 +128,14 @@ function drawTile(pos, size=vec2(1), tileIndex=-1, tileSize=defaultTileSize, col
|
|
|
128
128
|
* @memberof Draw */
|
|
129
129
|
function drawRect(pos, size, color, angle, useWebGL)
|
|
130
130
|
{
|
|
131
|
-
drawTile(pos, size, -1,
|
|
131
|
+
drawTile(pos, size, -1, tileSizeDefault, color, angle, 0, 0, useWebGL);
|
|
132
132
|
}
|
|
133
133
|
|
|
134
134
|
/** Draw textured tile centered on pos in screen space
|
|
135
135
|
* @param {Vector2} pos - Center of the tile
|
|
136
136
|
* @param {Vector2} [size=new Vector2(1,1)] - Size of the tile
|
|
137
137
|
* @param {Number} [tileIndex=-1] - Tile index to use, negative is untextured
|
|
138
|
-
* @param {Vector2} [tileSize=
|
|
138
|
+
* @param {Vector2} [tileSize=tileSizeDefault] - Tile size in source pixels
|
|
139
139
|
* @param {Color} [color=new Color]
|
|
140
140
|
* @param {Number} [angle=0]
|
|
141
141
|
* @param {Boolean} [mirror=0]
|
|
@@ -156,7 +156,7 @@ function drawTileScreenSpace(pos, size=vec2(1), tileIndex, tileSize, color, angl
|
|
|
156
156
|
* @memberof Draw */
|
|
157
157
|
function drawRectScreenSpace(pos, size, color, angle, useWebGL)
|
|
158
158
|
{
|
|
159
|
-
drawTileSrceenSpace(pos, size, -1,
|
|
159
|
+
drawTileSrceenSpace(pos, size, -1, tileSizeDefault, color, angle, 0, 0, useWebGL);
|
|
160
160
|
}
|
|
161
161
|
|
|
162
162
|
/** Draw colored line between two points
|
|
@@ -203,7 +203,7 @@ function drawCanvas2D(pos, size, angle, mirror, drawFunction, context = mainCont
|
|
|
203
203
|
* @param {Color} [lineColor=new Color(0,0,0)]
|
|
204
204
|
* @param {String} [textAlign='center']
|
|
205
205
|
* @memberof Draw */
|
|
206
|
-
function drawText(text, pos, size=1, color=new Color, lineWidth=0, lineColor=new Color(0,0,0), textAlign='center', font=
|
|
206
|
+
function drawText(text, pos, size=1, color=new Color, lineWidth=0, lineColor=new Color(0,0,0), textAlign='center', font=fontDefault)
|
|
207
207
|
{
|
|
208
208
|
pos = worldToScreen(pos);
|
|
209
209
|
overlayContext.font = size*cameraScale + 'px '+ font;
|
package/engine/engineInput.js
CHANGED
|
@@ -67,7 +67,7 @@ let mouseWheel = 0;
|
|
|
67
67
|
|
|
68
68
|
/** Returns true if user is using gamepad (has more recently pressed a gamepad button)
|
|
69
69
|
* @memberof Input */
|
|
70
|
-
let
|
|
70
|
+
let isUsingGamepad = 0;
|
|
71
71
|
|
|
72
72
|
/** Returns true if gamepad button is down
|
|
73
73
|
* @param {Number} button
|
|
@@ -129,7 +129,7 @@ function inputUpdatePost()
|
|
|
129
129
|
onkeydown = e=>
|
|
130
130
|
{
|
|
131
131
|
if (debug && e.target != document.body) return;
|
|
132
|
-
e.repeat || (inputData[
|
|
132
|
+
e.repeat || (inputData[isUsingGamepad = 0][remapKeyCode(e.keyCode)] = 3);
|
|
133
133
|
debug || e.preventDefault();
|
|
134
134
|
}
|
|
135
135
|
onkeyup = e=>
|
|
@@ -137,12 +137,12 @@ onkeyup = e=>
|
|
|
137
137
|
if (debug && e.target != document.body) return;
|
|
138
138
|
inputData[0][remapKeyCode(e.keyCode)] = 4;
|
|
139
139
|
}
|
|
140
|
-
const remapKeyCode = c=>
|
|
140
|
+
const remapKeyCode = c=> inputWASDEmulateDirection ? c==87?38 : c==83?40 : c==65?37 : c==68?39 : c : c;
|
|
141
141
|
|
|
142
142
|
///////////////////////////////////////////////////////////////////////////////
|
|
143
143
|
// Mouse event handlers
|
|
144
144
|
|
|
145
|
-
onmousedown = e=> {inputData[
|
|
145
|
+
onmousedown = e=> {inputData[isUsingGamepad = 0][e.button] = 3; onmousemove(e); e.button && e.preventDefault();}
|
|
146
146
|
onmouseup = e=> inputData[0][e.button] = inputData[0][e.button] & 2 | 4;
|
|
147
147
|
onmousemove = e=>
|
|
148
148
|
{
|
|
@@ -190,10 +190,10 @@ function gamepadsUpdate()
|
|
|
190
190
|
{
|
|
191
191
|
const button = gamepad.buttons[j];
|
|
192
192
|
data[j] = button.pressed ? 1 + 2*!gamepadIsDown(j,i) : 4*gamepadIsDown(j,i);
|
|
193
|
-
|
|
193
|
+
isUsingGamepad |= !i && button.pressed;
|
|
194
194
|
}
|
|
195
195
|
|
|
196
|
-
if (
|
|
196
|
+
if (gamepadDirectionEmulateStick)
|
|
197
197
|
{
|
|
198
198
|
// copy dpad to left analog stick when pressed
|
|
199
199
|
const dpad = vec2(gamepadIsDown(15,i) - gamepadIsDown(14,i), gamepadIsDown(12,i) - gamepadIsDown(13,i));
|
|
@@ -210,7 +210,7 @@ function gamepadsUpdate()
|
|
|
210
210
|
/** True if a touch device has been detected
|
|
211
211
|
* @const {boolean}
|
|
212
212
|
* @memberof Input */
|
|
213
|
-
const isTouchDevice =
|
|
213
|
+
const isTouchDevice = inputTouchEnable && window.ontouchstart !== undefined;
|
|
214
214
|
if (isTouchDevice)
|
|
215
215
|
{
|
|
216
216
|
// handle all touch events the same way
|
package/engine/engineMedals.js
CHANGED
|
@@ -113,9 +113,9 @@ class Medal
|
|
|
113
113
|
|
|
114
114
|
// draw the text
|
|
115
115
|
context.textAlign = 'left';
|
|
116
|
-
context.font = '3em '+
|
|
116
|
+
context.font = '3em '+ fontDefault;
|
|
117
117
|
context.fillText(this.name, x+medalDisplayIconSize+25, y+35);
|
|
118
|
-
context.font = '1.5em '+
|
|
118
|
+
context.font = '1.5em '+ fontDefault;
|
|
119
119
|
context.restore(context.fillText(this.description, x+medalDisplayIconSize+25, y+70));
|
|
120
120
|
}
|
|
121
121
|
|
|
@@ -130,7 +130,7 @@ class Medal
|
|
|
130
130
|
const context = overlayContext;
|
|
131
131
|
context.textAlign = 'center';
|
|
132
132
|
context.textBaseline = 'middle';
|
|
133
|
-
context.font = size*.6 + 'px '+
|
|
133
|
+
context.font = size*.6 + 'px '+ fontDefault;
|
|
134
134
|
context.fillStyle = '#000';
|
|
135
135
|
if (this.image)
|
|
136
136
|
context.drawImage(this.image, x-size/2, y-size/2, size, size);
|
package/engine/engineObject.js
CHANGED
|
@@ -25,14 +25,14 @@ class EngineObject
|
|
|
25
25
|
{
|
|
26
26
|
/** Create an engine object and adds it to the list of objects
|
|
27
27
|
* @param {Vector2} [position=new Vector2(0,0)] - World space position of the object
|
|
28
|
-
* @param {Vector2} [size=
|
|
28
|
+
* @param {Vector2} [size=objectDefaultSize] - World space size of the object
|
|
29
29
|
* @param {Number} [tileIndex=-1] - Tile to use to render object, untextured if -1
|
|
30
|
-
* @param {Vector2} [tileSize=
|
|
30
|
+
* @param {Vector2} [tileSize=tileSizeDefault] - Size of tile in source pixels
|
|
31
31
|
* @param {Number} [angle=0] - Angle to rotate the object
|
|
32
32
|
* @param {Color} [color] - Color to apply to tile when rendered
|
|
33
33
|
* @param {Number} [renderOrder=0] - Objects sorted by renderOrder before being rendered
|
|
34
34
|
*/
|
|
35
|
-
constructor(pos=vec2(), size=
|
|
35
|
+
constructor(pos=vec2(), size=objectDefaultSize, tileIndex=-1, tileSize=tileSizeDefault, angle=0, color, renderOrder=0)
|
|
36
36
|
{
|
|
37
37
|
// set passed in params
|
|
38
38
|
ASSERT(pos && pos.x != undefined && size.x != undefined); // ensure pos and size are vec2s
|
|
@@ -55,16 +55,16 @@ class EngineObject
|
|
|
55
55
|
this.additiveColor;
|
|
56
56
|
|
|
57
57
|
// set object defaults
|
|
58
|
-
/** @property {Number} [mass=
|
|
59
|
-
this.mass =
|
|
60
|
-
/** @property {Number} [damping=
|
|
61
|
-
this.damping =
|
|
62
|
-
/** @property {Number} [angleDamping=
|
|
63
|
-
this.angleDamping =
|
|
64
|
-
/** @property {Number} [elasticity=
|
|
65
|
-
this.elasticity =
|
|
66
|
-
/** @property {Number} [friction=
|
|
67
|
-
this.friction =
|
|
58
|
+
/** @property {Number} [mass=objectDefaultMass] - How heavy the object is */
|
|
59
|
+
this.mass = objectDefaultMass;
|
|
60
|
+
/** @property {Number} [damping=objectDefaultDamping] - How much to slow down velocity each frame (0-1) */
|
|
61
|
+
this.damping = objectDefaultDamping;
|
|
62
|
+
/** @property {Number} [angleDamping=objectDefaultAngleDamping] - How much to slow down rotation each frame (0-1) */
|
|
63
|
+
this.angleDamping = objectDefaultAngleDamping;
|
|
64
|
+
/** @property {Number} [elasticity=objectDefaultElasticity] - How bouncy the object is when colliding (0-1) */
|
|
65
|
+
this.elasticity = objectDefaultElasticity;
|
|
66
|
+
/** @property {Number} [friction=objectDefaultFriction] - How much friction to apply when sliding (0-1) */
|
|
67
|
+
this.friction = objectDefaultFriction;
|
|
68
68
|
/** @property {Number} [gravityScale=1] - How much to scale gravity by for this object */
|
|
69
69
|
this.gravityScale = 1;
|
|
70
70
|
/** @property {Number} [renderOrder=0] - Objects are sorted by render order */
|
|
@@ -93,8 +93,8 @@ class EngineObject
|
|
|
93
93
|
}
|
|
94
94
|
|
|
95
95
|
// limit max speed to prevent missing collisions
|
|
96
|
-
this.velocity.x = clamp(this.velocity.x,
|
|
97
|
-
this.velocity.y = clamp(this.velocity.y,
|
|
96
|
+
this.velocity.x = clamp(this.velocity.x, objectMaxSpeed, -objectMaxSpeed);
|
|
97
|
+
this.velocity.y = clamp(this.velocity.y, objectMaxSpeed, -objectMaxSpeed);
|
|
98
98
|
|
|
99
99
|
// apply physics
|
|
100
100
|
const oldPos = this.pos.copy();
|
|
@@ -33,7 +33,7 @@ class ParticleEmitter extends EngineObject
|
|
|
33
33
|
* @param {Number} [emitRate=100] - How many particles per second to spawn, does not emit if 0
|
|
34
34
|
* @param {Number} [emitConeAngle=PI] - Local angle to apply velocity to particles from emitter
|
|
35
35
|
* @param {Number} [tileIndex=-1] - Index into tile sheet, if <0 no texture is applied
|
|
36
|
-
* @param {Number} [tileSize=
|
|
36
|
+
* @param {Number} [tileSize=tileSizeDefault] - Tile size for particles
|
|
37
37
|
* @param {Color} [colorStartA=new Color(1,1,1)] - Color at start of life 1, randomized between start colors
|
|
38
38
|
* @param {Color} [colorStartB=new Color(1,1,1)] - Color at start of life 2, randomized between start colors
|
|
39
39
|
* @param {Color} [colorEndA=new Color(1,1,1,0)] - Color at end of life 1, randomized between end colors
|
|
@@ -62,7 +62,7 @@ class ParticleEmitter extends EngineObject
|
|
|
62
62
|
emitRate = 100,
|
|
63
63
|
emitConeAngle = PI,
|
|
64
64
|
tileIndex = -1,
|
|
65
|
-
tileSize =
|
|
65
|
+
tileSize = tileSizeDefault,
|
|
66
66
|
colorStartA = new Color,
|
|
67
67
|
colorStartB = new Color,
|
|
68
68
|
colorEndA = new Color(1,1,1,0),
|
|
@@ -233,7 +233,7 @@ class Particle extends EngineObject
|
|
|
233
233
|
* Create a particle with the given settings
|
|
234
234
|
* @param {Vector2} position - World space position of the particle
|
|
235
235
|
* @param {Number} [tileIndex=-1] - Tile to use to render, untextured if -1
|
|
236
|
-
* @param {Vector2} [tileSize=
|
|
236
|
+
* @param {Vector2} [tileSize=tileSizeDefault] - Size of tile in source pixels
|
|
237
237
|
* @param {Number} [angle=0] - Angle to rotate the particle
|
|
238
238
|
*/
|
|
239
239
|
constructor(pos, tileIndex, tileSize, angle) { super(pos, new Vector2, tileIndex, tileSize, angle); }
|
package/engine/engineSettings.js
CHANGED
|
@@ -8,35 +8,27 @@
|
|
|
8
8
|
///////////////////////////////////////////////////////////////////////////////
|
|
9
9
|
// Display settings
|
|
10
10
|
|
|
11
|
-
/** The max
|
|
12
|
-
* @
|
|
13
|
-
* @memberof Settings */
|
|
14
|
-
const maxWidth = 1920;
|
|
15
|
-
|
|
16
|
-
/** The max height of the canvas, centered if window is larger
|
|
17
|
-
* @default
|
|
18
|
-
* @memberof Settings */
|
|
19
|
-
const maxHeight = 1200; // up to 1080p and 16:10
|
|
20
|
-
|
|
21
|
-
/** Fixed witdh, if enabled cavnvas size never changes
|
|
11
|
+
/** The max size of the canvas, centered if window is larger
|
|
12
|
+
* @type {Vector2}
|
|
22
13
|
* @default
|
|
23
14
|
* @memberof Settings */
|
|
24
|
-
|
|
15
|
+
const maxSize = vec2(1920, 1200);
|
|
25
16
|
|
|
26
|
-
/** Fixed
|
|
17
|
+
/** Fixed size of the canvas, if enabled cavnvas size never changes
|
|
18
|
+
* @type {Vector2}
|
|
27
19
|
* @default
|
|
28
20
|
* @memberof Settings */
|
|
29
|
-
let
|
|
21
|
+
let fixedSize = vec2();
|
|
30
22
|
|
|
31
|
-
/**
|
|
23
|
+
/** Default font used for text rendering
|
|
32
24
|
* @default
|
|
33
25
|
* @memberof Settings */
|
|
34
|
-
let
|
|
26
|
+
let fontDefault = 'arial';
|
|
35
27
|
|
|
36
|
-
/**
|
|
28
|
+
/** Use crisp pixels for pixel art if true
|
|
37
29
|
* @default
|
|
38
30
|
* @memberof Settings */
|
|
39
|
-
let
|
|
31
|
+
let pixelated = 1;
|
|
40
32
|
|
|
41
33
|
///////////////////////////////////////////////////////////////////////////////
|
|
42
34
|
// Tile sheet settings
|
|
@@ -45,18 +37,13 @@ let defaultFont = 'arial';
|
|
|
45
37
|
* @type {Vector2}
|
|
46
38
|
* @default
|
|
47
39
|
* @memberof Settings */
|
|
48
|
-
const
|
|
40
|
+
const tileSizeDefault = vec2(16);
|
|
49
41
|
|
|
50
42
|
/** Prevent tile bleeding from neighbors in pixels
|
|
51
43
|
* @default
|
|
52
44
|
* @memberof Settings */
|
|
53
45
|
const tileBleedShrinkFix = .3;
|
|
54
46
|
|
|
55
|
-
/** Use crisp pixels for pixel art if true
|
|
56
|
-
* @default
|
|
57
|
-
* @memberof Settings */
|
|
58
|
-
let pixelated = 1;
|
|
59
|
-
|
|
60
47
|
///////////////////////////////////////////////////////////////////////////////
|
|
61
48
|
// Object settings
|
|
62
49
|
|
|
@@ -64,37 +51,37 @@ let pixelated = 1;
|
|
|
64
51
|
* @type {Vector2}
|
|
65
52
|
* @default
|
|
66
53
|
* @memberof Settings */
|
|
67
|
-
const
|
|
54
|
+
const objectDefaultSize = vec2(1);
|
|
68
55
|
|
|
69
56
|
/** Default object mass for collison calcuations (how heavy objects are)
|
|
70
57
|
* @default
|
|
71
58
|
* @memberof Settings */
|
|
72
|
-
const
|
|
59
|
+
const objectDefaultMass = 1;
|
|
73
60
|
|
|
74
61
|
/** How much to slow velocity by each frame (0-1)
|
|
75
62
|
* @default
|
|
76
63
|
* @memberof Settings */
|
|
77
|
-
const
|
|
64
|
+
const objectDefaultDamping = .99;
|
|
78
65
|
|
|
79
66
|
/** How much to slow angular velocity each frame (0-1)
|
|
80
67
|
* @default
|
|
81
68
|
* @memberof Settings */
|
|
82
|
-
const
|
|
69
|
+
const objectDefaultAngleDamping = .99;
|
|
83
70
|
|
|
84
71
|
/** How much to bounce when a collision occurs (0-1)
|
|
85
72
|
* @default
|
|
86
73
|
* @memberof Settings */
|
|
87
|
-
const
|
|
74
|
+
const objectDefaultElasticity = 0;
|
|
88
75
|
|
|
89
76
|
/** How much to slow when touching (0-1)
|
|
90
77
|
* @default
|
|
91
78
|
* @memberof Settings */
|
|
92
|
-
const
|
|
79
|
+
const objectDefaultFriction = .8;
|
|
93
80
|
|
|
94
81
|
/** Clamp max speed to avoid fast objects missing collisions
|
|
95
82
|
* @default
|
|
96
83
|
* @memberof Settings */
|
|
97
|
-
const
|
|
84
|
+
const objectMaxSpeed = 1;
|
|
98
85
|
|
|
99
86
|
/** How much gravity to apply to objects along the Y axis, negative is down
|
|
100
87
|
* @default
|
|
@@ -113,7 +100,7 @@ let cameraPos = vec2();
|
|
|
113
100
|
/** Scale of camera in world space
|
|
114
101
|
* @default
|
|
115
102
|
* @memberof Settings */
|
|
116
|
-
let cameraScale = max(
|
|
103
|
+
let cameraScale = max(tileSizeDefault.x, tileSizeDefault.y);
|
|
117
104
|
|
|
118
105
|
///////////////////////////////////////////////////////////////////////////////
|
|
119
106
|
// WebGL settings
|
|
@@ -136,43 +123,43 @@ let glOverlay = 1;
|
|
|
136
123
|
* @memberof Settings */
|
|
137
124
|
const gamepadsEnable = 1;
|
|
138
125
|
|
|
139
|
-
/** If true
|
|
126
|
+
/** If true, the dpad input is also routed to the left analog stick (for better accessability)
|
|
140
127
|
* @default
|
|
141
128
|
* @memberof Settings */
|
|
142
|
-
const
|
|
129
|
+
const gamepadDirectionEmulateStick = 1;
|
|
143
130
|
|
|
144
|
-
/** If true
|
|
131
|
+
/** If true touch input is routed to mouse functions
|
|
145
132
|
* @default
|
|
146
133
|
* @memberof Settings */
|
|
147
|
-
const
|
|
134
|
+
const inputTouchEnable = 1;
|
|
148
135
|
|
|
149
136
|
/** If true the WASD keys are also routed to the direction keys (for better accessability)
|
|
150
137
|
* @default
|
|
151
138
|
* @memberof Settings */
|
|
152
|
-
const
|
|
139
|
+
const inputWASDEmulateDirection = 1;
|
|
153
140
|
|
|
154
141
|
///////////////////////////////////////////////////////////////////////////////
|
|
155
142
|
// Audio settings
|
|
156
143
|
|
|
157
|
-
/**
|
|
144
|
+
/** Volume scale to apply to all sound, music and speech
|
|
158
145
|
* @default
|
|
159
146
|
* @memberof Settings */
|
|
160
|
-
|
|
147
|
+
let soundVolume = .5;
|
|
161
148
|
|
|
162
|
-
/**
|
|
149
|
+
/** All audio code can be disabled and removed from build
|
|
163
150
|
* @default
|
|
164
151
|
* @memberof Settings */
|
|
165
|
-
|
|
152
|
+
const soundEnable = 1;
|
|
166
153
|
|
|
167
154
|
/** Default range where sound no longer plays
|
|
168
155
|
* @default
|
|
169
156
|
* @memberof Settings */
|
|
170
|
-
const
|
|
157
|
+
const soundDefaultRange = 30;
|
|
171
158
|
|
|
172
159
|
/** Default range percent to start tapering off sound (0-1)
|
|
173
160
|
* @default
|
|
174
161
|
* @memberof Settings */
|
|
175
|
-
const
|
|
162
|
+
const soundDefaultTaper = .7;
|
|
176
163
|
|
|
177
164
|
///////////////////////////////////////////////////////////////////////////////
|
|
178
165
|
// Medals settings
|
|
@@ -156,12 +156,12 @@ class TileLayer extends EngineObject
|
|
|
156
156
|
{
|
|
157
157
|
/** Create a tile layer object
|
|
158
158
|
* @param {Vector2} [position=new Vector2(0,0)] - World space position
|
|
159
|
-
* @param {Vector2} [size=
|
|
160
|
-
* @param {Vector2} [tileSize=
|
|
159
|
+
* @param {Vector2} [size=objectDefaultSize] - World space size
|
|
160
|
+
* @param {Vector2} [tileSize=tileSizeDefault] - Size of tiles in source pixels
|
|
161
161
|
* @param {Vector2} [scale=new Vector2(1,1)] - How much to scale this layer when rendered
|
|
162
162
|
* @param {Number} [renderOrder=0] - Objects sorted by renderOrder before being rendered
|
|
163
163
|
*/
|
|
164
|
-
constructor(pos, size=tileCollisionSize, tileSize=
|
|
164
|
+
constructor(pos, size=tileCollisionSize, tileSize=tileSizeDefault, scale=vec2(1), renderOrder=0)
|
|
165
165
|
{
|
|
166
166
|
super(pos, size, -1, tileSize, 0, undefined, renderOrder);
|
|
167
167
|
|
|
@@ -320,11 +320,11 @@ class TileLayer extends EngineObject
|
|
|
320
320
|
* @param {Vector2} pos
|
|
321
321
|
* @param {Vector2} [size=new Vector2(1,1)]
|
|
322
322
|
* @param {Number} [tileIndex=-1]
|
|
323
|
-
* @param {Vector2} [tileSize=
|
|
323
|
+
* @param {Vector2} [tileSize=tileSizeDefault]
|
|
324
324
|
* @param {Color} [color=new Color(1,1,1)]
|
|
325
325
|
* @param {Number} [angle=0]
|
|
326
326
|
* @param {Boolean} [mirror=0] */
|
|
327
|
-
drawTile(pos, size=vec2(1), tileIndex=-1, tileSize=
|
|
327
|
+
drawTile(pos, size=vec2(1), tileIndex=-1, tileSize=tileSizeDefault, color=new Color, angle=0, mirror)
|
|
328
328
|
{
|
|
329
329
|
this.drawCanvas2D(pos, size, angle, mirror, (context)=>
|
|
330
330
|
{
|
|
@@ -333,10 +333,10 @@ class Vector2
|
|
|
333
333
|
class Color
|
|
334
334
|
{
|
|
335
335
|
/** Create a color with the components passed in, white by default
|
|
336
|
-
* @param {Number} [
|
|
337
|
-
* @param {Number} [
|
|
338
|
-
* @param {Number} [
|
|
339
|
-
* @param {Number} [
|
|
336
|
+
* @param {Number} [red=1]
|
|
337
|
+
* @param {Number} [green=1]
|
|
338
|
+
* @param {Number} [blue=1]
|
|
339
|
+
* @param {Number} [alpha=1] */
|
|
340
340
|
constructor(r=1, g=1, b=1, a=1)
|
|
341
341
|
{
|
|
342
342
|
/** @property {Number} - Red */
|
|
@@ -14,7 +14,7 @@ const sound_bounce = new Sound([,,1e3,,.03,.02,1,2,,,940,.03,,,,,.2,.6,,.06]
|
|
|
14
14
|
///////////////////////////////////////////////////////////////////////////////
|
|
15
15
|
function gameInit()
|
|
16
16
|
{
|
|
17
|
-
|
|
17
|
+
fixedSize = vec2(1280, 720); // 720p
|
|
18
18
|
levelSize = vec2(72, 40);
|
|
19
19
|
cameraPos = levelSize.scale(.5);
|
|
20
20
|
paddle = new Paddle(vec2(levelSize.x/2-12,2));
|
|
@@ -3,6 +3,6 @@
|
|
|
3
3
|
<link rel=icon type=image/png href=../../favicon.png>
|
|
4
4
|
</head><body>
|
|
5
5
|
|
|
6
|
-
<script src=../../engine/engine.all.min.js?
|
|
7
|
-
<script src=game.js?
|
|
8
|
-
<script src=gameObjects.js?
|
|
6
|
+
<script src=../../engine/engine.all.min.js?60></script>
|
|
7
|
+
<script src=game.js?60></script>
|
|
8
|
+
<script src=gameObjects.js?60></script>
|
|
@@ -66,7 +66,7 @@ class Crate extends GameObject
|
|
|
66
66
|
{
|
|
67
67
|
constructor(pos, typeOverride)
|
|
68
68
|
{
|
|
69
|
-
super(pos,
|
|
69
|
+
super(pos, objectDefaultSize, 2, vec2(16), (randInt(4))*PI/2);
|
|
70
70
|
|
|
71
71
|
this.color = (new Color).setHSLA(rand(),1,.8);
|
|
72
72
|
this.health = 5;
|
|
@@ -296,7 +296,7 @@ class Player extends Character
|
|
|
296
296
|
this.pressingThrow = mouseIsDown(2) || keyIsDown(67) || gamepadIsDown(1);
|
|
297
297
|
|
|
298
298
|
// movement control
|
|
299
|
-
this.moveInput =
|
|
299
|
+
this.moveInput = isUsingGamepad ? gamepadStick(0) :
|
|
300
300
|
vec2(keyIsDown(39) - keyIsDown(37), keyIsDown(38) - keyIsDown(40));
|
|
301
301
|
|
|
302
302
|
super.update();
|
|
@@ -3,9 +3,9 @@
|
|
|
3
3
|
<link rel=icon type=image/png href=../../favicon.png>
|
|
4
4
|
</head><body>
|
|
5
5
|
|
|
6
|
-
<script src=../../engine/engine.all.min.js?
|
|
7
|
-
<script src=gameObjects.js?
|
|
8
|
-
<script src=gamePlayer.js?
|
|
9
|
-
<script src=gameEffects.js?
|
|
10
|
-
<script src=gameLevel.js?
|
|
11
|
-
<script src=game.js?
|
|
6
|
+
<script src=../../engine/engine.all.min.js?60></script>
|
|
7
|
+
<script src=gameObjects.js?60></script>
|
|
8
|
+
<script src=gamePlayer.js?60></script>
|
|
9
|
+
<script src=gameEffects.js?60></script>
|
|
10
|
+
<script src=gameLevel.js?60></script>
|
|
11
|
+
<script src=game.js?60></script>
|
package/examples/puzzle/game.js
CHANGED
|
@@ -42,7 +42,7 @@ const setTile = (pos, data) => level[pos.x + pos.y * levelSize.x] = data;
|
|
|
42
42
|
function gameInit()
|
|
43
43
|
{
|
|
44
44
|
// setup canvas
|
|
45
|
-
|
|
45
|
+
fixedSize = vec2(1920, 1080); // 1080p
|
|
46
46
|
mainCanvas.style.background = backgroundColor.rgba();
|
|
47
47
|
|
|
48
48
|
// load high score
|
package/index.html
CHANGED
|
@@ -4,21 +4,21 @@
|
|
|
4
4
|
</head><body>
|
|
5
5
|
|
|
6
6
|
<!-- LittleJS engine scripts -->
|
|
7
|
-
<script src=engine/engineDebug.js?
|
|
8
|
-
<script src=engine/engineUtilities.js?
|
|
9
|
-
<script src=engine/engineSettings.js?
|
|
10
|
-
<script src=engine/engineObject.js?
|
|
11
|
-
<script src=engine/engineDraw.js?
|
|
12
|
-
<script src=engine/engineInput.js?
|
|
13
|
-
<script src=engine/engineAudio.js?
|
|
14
|
-
<script src=engine/engineTileLayer.js?
|
|
15
|
-
<script src=engine/engineParticles.js?
|
|
16
|
-
<script src=engine/engineMedals.js?
|
|
17
|
-
<script src=engine/engineWebGL.js?
|
|
18
|
-
<script src=engine/engine.js?
|
|
7
|
+
<script src=engine/engineDebug.js?60></script>
|
|
8
|
+
<script src=engine/engineUtilities.js?60></script>
|
|
9
|
+
<script src=engine/engineSettings.js?60></script>
|
|
10
|
+
<script src=engine/engineObject.js?60></script>
|
|
11
|
+
<script src=engine/engineDraw.js?60></script>
|
|
12
|
+
<script src=engine/engineInput.js?60></script>
|
|
13
|
+
<script src=engine/engineAudio.js?60></script>
|
|
14
|
+
<script src=engine/engineTileLayer.js?60></script>
|
|
15
|
+
<script src=engine/engineParticles.js?60></script>
|
|
16
|
+
<script src=engine/engineMedals.js?60></script>
|
|
17
|
+
<script src=engine/engineWebGL.js?60></script>
|
|
18
|
+
<script src=engine/engine.js?60></script>
|
|
19
19
|
|
|
20
20
|
<!-- You can also include all engine scripts like this... -->
|
|
21
21
|
<!-- <script src=engine/engine.all.js></script> -->
|
|
22
22
|
|
|
23
23
|
<!-- Add your game scripts here -->
|
|
24
|
-
<script src=game.js?
|
|
24
|
+
<script src=game.js?60></script>
|