littlejsengine 1.4.7 → 1.4.9
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/build.bat +7 -3
- package/engine/engine.all.js +291 -323
- package/engine/engine.all.min.js +1 -1
- package/engine/engine.all.module.js +307 -352
- package/engine/engine.all.module.min.js +1 -0
- package/engine/engine.all.release.js +291 -323
- package/engine/engine.js +21 -30
- package/engine/engineAudio.js +8 -15
- package/engine/engineBuild.bat +10 -3
- package/engine/engineDraw.js +18 -24
- package/engine/engineExport.js +16 -29
- package/engine/engineInput.js +84 -71
- package/engine/engineMedals.js +30 -38
- package/engine/engineObject.js +8 -8
- package/engine/engineParticles.js +5 -4
- package/engine/engineSettings.js +38 -38
- package/engine/engineTileLayer.js +15 -16
- package/engine/engineUtilities.js +26 -13
- package/engine/engineWebGL.js +38 -66
- package/engine/index.d.ts +65 -54
- package/examples/breakout/game.js +10 -10
- package/examples/breakout/gameObjects.js +7 -7
- package/examples/breakout/index.html +3 -3
- package/examples/empty/tiles.png +0 -0
- package/examples/module/game.js +5 -7
- package/examples/module/index.html +1 -1
- package/examples/particles/index.html +4 -14
- package/examples/platformer/index.html +6 -6
- package/examples/puzzle/index.html +2 -2
- package/examples/stress/index.html +1 -1
- package/favicon.png +0 -0
- package/game.js +6 -9
- package/index.html +13 -13
- package/package.json +1 -1
- package/README.md +0 -75
- package/engine/engine.all.release.module.js +0 -4464
package/engine/engineWebGL.js
CHANGED
|
@@ -27,7 +27,7 @@ let glContext;
|
|
|
27
27
|
let glTileTexture;
|
|
28
28
|
|
|
29
29
|
// WebGL internal variables not exposed to documentation
|
|
30
|
-
let glActiveTexture, glShader, glArrayBuffer,
|
|
30
|
+
let glActiveTexture, glShader, glArrayBuffer, glPositionData, glColorData, glBatchCount, glBatchAdditive, glAdditive;
|
|
31
31
|
|
|
32
32
|
///////////////////////////////////////////////////////////////////////////////
|
|
33
33
|
|
|
@@ -48,27 +48,25 @@ function glInit()
|
|
|
48
48
|
'uniform mat4 m;'+ // transform matrix
|
|
49
49
|
'attribute vec2 p,t;'+ // position, uv
|
|
50
50
|
'attribute vec4 c,a;'+ // color, additiveColor
|
|
51
|
-
'varying
|
|
52
|
-
'varying vec4 d,e;'+ // return color, additiveColor
|
|
51
|
+
'varying vec4 v,d,e;'+ // return uv, color, additiveColor
|
|
53
52
|
'void main(){'+ // shader entry point
|
|
54
53
|
'gl_Position=m*vec4(p,1,1);'+ // transform position
|
|
55
|
-
'v=t;d=c;e=a;'+
|
|
54
|
+
'v=vec4(t,p);d=c;e=a;'+ // pass stuff to fragment shader
|
|
56
55
|
'}' // end of shader
|
|
57
56
|
,
|
|
58
|
-
'precision highp float;'+
|
|
59
|
-
'varying
|
|
60
|
-
'
|
|
61
|
-
'
|
|
62
|
-
'
|
|
63
|
-
'
|
|
64
|
-
'}' // end of shader
|
|
57
|
+
'precision highp float;'+ // use highp for better accuracy
|
|
58
|
+
'varying vec4 v,d,e;'+ // uv, color, additiveColor
|
|
59
|
+
'uniform sampler2D s;'+ // texture
|
|
60
|
+
'void main(){'+ // shader entry point
|
|
61
|
+
'gl_FragColor=texture2D(s,v.xy)*d+e;'+ // modulate texture by color plus additive
|
|
62
|
+
'}' // end of shader
|
|
65
63
|
);
|
|
66
64
|
|
|
67
65
|
// init buffers
|
|
68
|
-
|
|
66
|
+
const vertexData = new ArrayBuffer(gl_VERTEX_BUFFER_SIZE);
|
|
69
67
|
glArrayBuffer = glContext.createBuffer();
|
|
70
|
-
glPositionData = new Float32Array(
|
|
71
|
-
glColorData = new Uint32Array(
|
|
68
|
+
glPositionData = new Float32Array(vertexData);
|
|
69
|
+
glColorData = new Uint32Array(vertexData);
|
|
72
70
|
glBatchCount = 0;
|
|
73
71
|
}
|
|
74
72
|
|
|
@@ -143,18 +141,19 @@ function glCreateTexture(image)
|
|
|
143
141
|
image && image.width && glContext.texImage2D(gl_TEXTURE_2D, 0, gl_RGBA, gl_RGBA, gl_UNSIGNED_BYTE, image);
|
|
144
142
|
|
|
145
143
|
// use point filtering for pixelated rendering
|
|
146
|
-
|
|
147
|
-
glContext.texParameteri(gl_TEXTURE_2D,
|
|
144
|
+
const filter = cavasPixelated ? gl_NEAREST : gl_LINEAR;
|
|
145
|
+
glContext.texParameteri(gl_TEXTURE_2D, gl_TEXTURE_MIN_FILTER, filter);
|
|
146
|
+
glContext.texParameteri(gl_TEXTURE_2D, gl_TEXTURE_MAG_FILTER, filter);
|
|
148
147
|
glContext.texParameteri(gl_TEXTURE_2D, gl_TEXTURE_WRAP_S, gl_CLAMP_TO_EDGE);
|
|
149
148
|
glContext.texParameteri(gl_TEXTURE_2D, gl_TEXTURE_WRAP_T, gl_CLAMP_TO_EDGE);
|
|
150
149
|
return texture;
|
|
151
150
|
}
|
|
152
151
|
|
|
153
152
|
// called automatically by engine before render
|
|
154
|
-
function glPreRender(
|
|
153
|
+
function glPreRender()
|
|
155
154
|
{
|
|
156
155
|
// clear and set to same size as main canvas
|
|
157
|
-
glContext.viewport(0, 0, glCanvas.width = width, glCanvas.height = height);
|
|
156
|
+
glContext.viewport(0, 0, glCanvas.width = mainCanvas.width, glCanvas.height = mainCanvas.height);
|
|
158
157
|
glContext.clear(gl_COLOR_BUFFER_BIT);
|
|
159
158
|
|
|
160
159
|
// set up the shader
|
|
@@ -162,7 +161,7 @@ function glPreRender(width, height, cameraX, cameraY, cameraScale)
|
|
|
162
161
|
glContext.activeTexture(gl_TEXTURE0);
|
|
163
162
|
glContext.bindTexture(gl_TEXTURE_2D, glActiveTexture = glTileTexture);
|
|
164
163
|
glContext.bindBuffer(gl_ARRAY_BUFFER, glArrayBuffer);
|
|
165
|
-
glContext.bufferData(gl_ARRAY_BUFFER,
|
|
164
|
+
glContext.bufferData(gl_ARRAY_BUFFER, gl_VERTEX_BUFFER_SIZE, gl_DYNAMIC_DRAW);
|
|
166
165
|
glSetBlendMode();
|
|
167
166
|
|
|
168
167
|
// set vertex attributes
|
|
@@ -180,14 +179,14 @@ function glPreRender(width, height, cameraX, cameraY, cameraScale)
|
|
|
180
179
|
initVertexAttribArray('a', gl_UNSIGNED_BYTE, 1, 4, 1); // additiveColor
|
|
181
180
|
|
|
182
181
|
// build the transform matrix
|
|
183
|
-
const sx = 2 * cameraScale / width;
|
|
184
|
-
const sy = 2 * cameraScale / height;
|
|
182
|
+
const sx = 2 * cameraScale / mainCanvas.width;
|
|
183
|
+
const sy = 2 * cameraScale / mainCanvas.height;
|
|
185
184
|
glContext.uniformMatrix4fv(glContext.getUniformLocation(glShader, 'm'), 0,
|
|
186
185
|
new Float32Array([
|
|
187
186
|
sx, 0, 0, 0,
|
|
188
187
|
0, sy, 0, 0,
|
|
189
188
|
1, 1, -1, 1,
|
|
190
|
-
-1-sx*
|
|
189
|
+
-1-sx*cameraPos.x, -1-sy*cameraPos.y, 0, 0
|
|
191
190
|
])
|
|
192
191
|
);
|
|
193
192
|
}
|
|
@@ -235,10 +234,10 @@ function glCopyToContext(context, forceDraw)
|
|
|
235
234
|
* @param uv0Y
|
|
236
235
|
* @param uv1X
|
|
237
236
|
* @param uv1Y
|
|
238
|
-
* @param
|
|
237
|
+
* @param rgba
|
|
239
238
|
* @param [rgbaAdditive=0]
|
|
240
239
|
* @memberof WebGL */
|
|
241
|
-
function glDraw(x, y, sizeX, sizeY, angle, uv0X, uv0Y, uv1X, uv1Y, rgba
|
|
240
|
+
function glDraw(x, y, sizeX, sizeY, angle, uv0X, uv0Y, uv1X, uv1Y, rgba, rgbaAdditive=0)
|
|
242
241
|
{
|
|
243
242
|
// flush if there is no room for more verts or if different blend mode
|
|
244
243
|
if (glBatchCount == gl_MAX_BATCH || glBatchAdditive != glAdditive)
|
|
@@ -249,43 +248,16 @@ function glDraw(x, y, sizeX, sizeY, angle, uv0X, uv0Y, uv1X, uv1Y, rgba=0xffffff
|
|
|
249
248
|
const cx = c*sizeX, cy = c*sizeY, sx = s*sizeX, sy = s*sizeY;
|
|
250
249
|
|
|
251
250
|
// setup 2 triangles to form a quad
|
|
252
|
-
let offset = glBatchCount++ * gl_VERTICES_PER_QUAD * gl_INDICIES_PER_VERT;
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
glPositionData[offset++] = y + cy - sx;
|
|
263
|
-
glPositionData[offset++] = uv1X; glPositionData[offset++] = uv0Y;
|
|
264
|
-
glColorData[offset++] = rgba; glColorData[offset++] = rgbaAdditive;
|
|
265
|
-
|
|
266
|
-
// vertex 2
|
|
267
|
-
glPositionData[offset++] = x - cx + sy;
|
|
268
|
-
glPositionData[offset++] = y + cy + sx;
|
|
269
|
-
glPositionData[offset++] = uv0X; glPositionData[offset++] = uv0Y;
|
|
270
|
-
glColorData[offset++] = rgba; glColorData[offset++] = rgbaAdditive;
|
|
271
|
-
|
|
272
|
-
// vertex 0
|
|
273
|
-
glPositionData[offset++] = x - cx - sy;
|
|
274
|
-
glPositionData[offset++] = y - cy + sx;
|
|
275
|
-
glPositionData[offset++] = uv0X; glPositionData[offset++] = uv1Y;
|
|
276
|
-
glColorData[offset++] = rgba; glColorData[offset++] = rgbaAdditive;
|
|
277
|
-
|
|
278
|
-
// vertex 3
|
|
279
|
-
glPositionData[offset++] = x + cx - sy;
|
|
280
|
-
glPositionData[offset++] = y - cy - sx;
|
|
281
|
-
glPositionData[offset++] = uv1X; glPositionData[offset++] = uv1Y;
|
|
282
|
-
glColorData[offset++] = rgba; glColorData[offset++] = rgbaAdditive;
|
|
283
|
-
|
|
284
|
-
// vertex 1
|
|
285
|
-
glPositionData[offset++] = x + cx + sy;
|
|
286
|
-
glPositionData[offset++] = y + cy - sx;
|
|
287
|
-
glPositionData[offset++] = uv1X; glPositionData[offset++] = uv0Y;
|
|
288
|
-
glColorData[offset++] = rgba; glColorData[offset++] = rgbaAdditive;
|
|
251
|
+
for(let i=6, offset = glBatchCount++ * gl_VERTICES_PER_QUAD * gl_INDICIES_PER_VERT; i--;)
|
|
252
|
+
{
|
|
253
|
+
const a = i-4&&i>1, b = i-5&&i-2&&i-1;
|
|
254
|
+
glPositionData[offset++] = x + (a?-cx:cx) + (b?sy:-sy);
|
|
255
|
+
glPositionData[offset++] = y + (b?cy:-cy) + (a?sx:-sx);
|
|
256
|
+
glPositionData[offset++] = a ? uv0X : uv1X;
|
|
257
|
+
glPositionData[offset++] = b ? uv0Y : uv1Y;
|
|
258
|
+
glColorData[offset++] = rgba;
|
|
259
|
+
glColorData[offset++] = rgbaAdditive;
|
|
260
|
+
}
|
|
289
261
|
}
|
|
290
262
|
|
|
291
263
|
///////////////////////////////////////////////////////////////////////////////
|
|
@@ -337,14 +309,13 @@ function glRenderPostProcess()
|
|
|
337
309
|
return;
|
|
338
310
|
|
|
339
311
|
// prepare to render post process shader
|
|
340
|
-
const width = mainCanvas.width, height = mainCanvas.height;
|
|
341
312
|
if (glEnable)
|
|
342
313
|
{
|
|
343
314
|
glFlush(); // clear out the buffer
|
|
344
315
|
mainContext.drawImage(glCanvas, 0, 0); // copy to the main canvas
|
|
345
316
|
}
|
|
346
|
-
else
|
|
347
|
-
glContext.viewport(0, 0, glCanvas.width = width, glCanvas.height = height);
|
|
317
|
+
else // set viewport
|
|
318
|
+
glContext.viewport(0, 0, glCanvas.width = mainCanvas.width, glCanvas.height = mainCanvas.height);
|
|
348
319
|
|
|
349
320
|
// setup shader program to draw one triangle
|
|
350
321
|
glContext.useProgram(glPostShader);
|
|
@@ -368,7 +339,7 @@ function glRenderPostProcess()
|
|
|
368
339
|
const uniformLocation = (name)=>glContext.getUniformLocation(glPostShader, name);
|
|
369
340
|
glContext.uniform1i(uniformLocation('iChannel0'), 0);
|
|
370
341
|
glContext.uniform1f(uniformLocation('iTime'), time);
|
|
371
|
-
glContext.uniform3f(uniformLocation('iResolution'), width, height, 1);
|
|
342
|
+
glContext.uniform3f(uniformLocation('iResolution'), mainCanvas.width, mainCanvas.height, 1);
|
|
372
343
|
glContext.drawArrays(gl_TRIANGLES, 0, 3);
|
|
373
344
|
}
|
|
374
345
|
|
|
@@ -408,4 +379,5 @@ gl_UNPACK_FLIP_Y_WEBGL = 37440,
|
|
|
408
379
|
gl_VERTICES_PER_QUAD = 6,
|
|
409
380
|
gl_INDICIES_PER_VERT = 6,
|
|
410
381
|
gl_MAX_BATCH = 1<<16,
|
|
411
|
-
gl_VERTEX_BYTE_STRIDE = (4 * 2) * 2 + (4) * 2
|
|
382
|
+
gl_VERTEX_BYTE_STRIDE = (4 * 2) * 2 + (4) * 2, // vec2 * 2 + (char * 4) * 2
|
|
383
|
+
gl_VERTEX_BUFFER_SIZE = gl_MAX_BATCH * gl_VERTICES_PER_QUAD * gl_VERTEX_BYTE_STRIDE;
|
package/engine/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/** Draw textured tile centered in world space, with color applied if using WebGL
|
|
2
2
|
* @param {Vector2} pos - Center of the tile in world space
|
|
3
|
-
* @param {Vector2} [size=new Vector2(1,1)] - Size of the tile in world space
|
|
3
|
+
* @param {Vector2} [size=new Vector2(1,1)] - Size of the tile in world space
|
|
4
4
|
* @param {Number} [tileIndex=-1] - Tile index to use, negative is untextured
|
|
5
5
|
* @param {Vector2} [tileSize=tileSizeDefault] - Tile size in source pixels
|
|
6
6
|
* @param {Color} [color=new Color(1,1,1)] - Color to modulate with
|
|
@@ -183,7 +183,7 @@ declare function glCreateProgram(vsSource: WebGLShader, fsSource: WebGLShader):
|
|
|
183
183
|
* @return {WebGLTexture}
|
|
184
184
|
* @memberof WebGL */
|
|
185
185
|
declare function glCreateTexture(image: new (width?: number, height?: number) => HTMLImageElement): WebGLTexture;
|
|
186
|
-
declare function glPreRender(
|
|
186
|
+
declare function glPreRender(): void;
|
|
187
187
|
/** Draw all sprites and clear out the buffer, called automatically by the system whenever necessary
|
|
188
188
|
* @memberof WebGL */
|
|
189
189
|
declare function glFlush(): void;
|
|
@@ -202,15 +202,19 @@ declare function glCopyToContext(context: CanvasRenderingContext2D, forceDraw?:
|
|
|
202
202
|
* @param uv0Y
|
|
203
203
|
* @param uv1X
|
|
204
204
|
* @param uv1Y
|
|
205
|
-
* @param
|
|
205
|
+
* @param rgba
|
|
206
206
|
* @param [rgbaAdditive=0]
|
|
207
207
|
* @memberof WebGL */
|
|
208
|
-
declare function glDraw(x: any, y: any, sizeX: any, sizeY: any, angle: any, uv0X: any, uv0Y: any, uv1X: any, uv1Y: any, rgba
|
|
208
|
+
declare function glDraw(x: any, y: any, sizeX: any, sizeY: any, angle: any, uv0X: any, uv0Y: any, uv1X: any, uv1Y: any, rgba: any, rgbaAdditive?: number): void;
|
|
209
209
|
/** Set up a post processing shader
|
|
210
210
|
* @param {String} shaderCode
|
|
211
211
|
* @memberof WebGL */
|
|
212
212
|
declare function glInitPostProcess(shaderCode: string): void;
|
|
213
213
|
declare function glRenderPostProcess(): void;
|
|
214
|
+
/** Set if game is paused
|
|
215
|
+
* @param {Boolean} paused
|
|
216
|
+
*/
|
|
217
|
+
declare function setPaused(_paused: any): void;
|
|
214
218
|
/** Start up LittleJS engine with your callback functions
|
|
215
219
|
* @param {Function} gameInit - Called once after the engine starts up, setup the game
|
|
216
220
|
* @param {Function} gameUpdate - Called every frame at 60 frames per second, handle input and update the game state
|
|
@@ -221,7 +225,7 @@ declare function glRenderPostProcess(): void;
|
|
|
221
225
|
*/
|
|
222
226
|
declare function engineInit(gameInit: Function, gameUpdate: Function, gameUpdatePost: Function, gameRender: Function, gameRenderPost: Function, tileImageSource?: string): void;
|
|
223
227
|
declare function enginePreRender(): void;
|
|
224
|
-
/**
|
|
228
|
+
/** Update each engine object, remove destroyed objects, and update time */
|
|
225
229
|
declare function engineObjectsUpdate(): void;
|
|
226
230
|
/** Destroy and remove all objects */
|
|
227
231
|
declare function engineObjectsDestroy(): void;
|
|
@@ -441,9 +445,13 @@ declare function randVector(length?: number): Vector2;
|
|
|
441
445
|
* @return {Color}
|
|
442
446
|
* @memberof Random */
|
|
443
447
|
declare function randColor(cA?: Color, cB?: Color, linear?: boolean): Color;
|
|
444
|
-
/**
|
|
448
|
+
/** Seed used by the randSeeded function
|
|
445
449
|
* @memberof Random */
|
|
446
450
|
declare let randSeed: number;
|
|
451
|
+
/** Set seed used by the randSeeded function, should not be 0
|
|
452
|
+
* @param {Number} seed
|
|
453
|
+
* @memberof Random */
|
|
454
|
+
declare function setRandSeed(seed: number): number;
|
|
447
455
|
/** Returns a seeded random value between the two values passed in using randSeed
|
|
448
456
|
* @param {Number} [valueA=1]
|
|
449
457
|
* @param {Number} [valueB=0]
|
|
@@ -463,6 +471,13 @@ declare function randSeeded(a?: number, b?: number): number;
|
|
|
463
471
|
* @memberof Utilities
|
|
464
472
|
*/
|
|
465
473
|
declare function vec2(x?: number, y?: number): Vector2;
|
|
474
|
+
/**
|
|
475
|
+
* Check if object is a valid Vector2
|
|
476
|
+
* @param {Vector2} vector
|
|
477
|
+
* @return {Boolean}
|
|
478
|
+
* @memberof Utilities
|
|
479
|
+
*/
|
|
480
|
+
declare function isVector2(v: any): boolean;
|
|
466
481
|
/**
|
|
467
482
|
* 2D Vector object with vector math library
|
|
468
483
|
* <br> - Functions do not change this so they can be chained together
|
|
@@ -714,6 +729,15 @@ declare class Timer {
|
|
|
714
729
|
* @return {Number} */
|
|
715
730
|
valueOf(): number;
|
|
716
731
|
}
|
|
732
|
+
/** Position of camera in world space
|
|
733
|
+
* @type {Vector2}
|
|
734
|
+
* @default
|
|
735
|
+
* @memberof Settings */
|
|
736
|
+
declare let cameraPos: Vector2;
|
|
737
|
+
/** Scale of camera in world space
|
|
738
|
+
* @default
|
|
739
|
+
* @memberof Settings */
|
|
740
|
+
declare let cameraScale: number;
|
|
717
741
|
/** The max size of the canvas, centered if window is larger
|
|
718
742
|
* @type {Vector2}
|
|
719
743
|
* @default
|
|
@@ -733,6 +757,14 @@ declare let cavasPixelated: number;
|
|
|
733
757
|
* @default
|
|
734
758
|
* @memberof Settings */
|
|
735
759
|
declare let fontDefault: string;
|
|
760
|
+
/** Enable webgl rendering, webgl can be disabled and removed from build (with some features disabled)
|
|
761
|
+
* @default
|
|
762
|
+
* @memberof Settings */
|
|
763
|
+
declare let glEnable: number;
|
|
764
|
+
/** Fixes slow rendering in some browsers by not compositing the WebGL canvas
|
|
765
|
+
* @default
|
|
766
|
+
* @memberof Settings */
|
|
767
|
+
declare let glOverlay: number;
|
|
736
768
|
/** Default size of tiles in pixels
|
|
737
769
|
* @type {Vector2}
|
|
738
770
|
* @default
|
|
@@ -783,23 +815,6 @@ declare let gravity: number;
|
|
|
783
815
|
* @default
|
|
784
816
|
* @memberof Settings */
|
|
785
817
|
declare let particleEmitRateScale: number;
|
|
786
|
-
/** Position of camera in world space
|
|
787
|
-
* @type {Vector2}
|
|
788
|
-
* @default
|
|
789
|
-
* @memberof Settings */
|
|
790
|
-
declare let cameraPos: Vector2;
|
|
791
|
-
/** Scale of camera in world space
|
|
792
|
-
* @default
|
|
793
|
-
* @memberof Settings */
|
|
794
|
-
declare let cameraScale: number;
|
|
795
|
-
/** Enable webgl rendering, webgl can be disabled and removed from build (with some features disabled)
|
|
796
|
-
* @default
|
|
797
|
-
* @memberof Settings */
|
|
798
|
-
declare let glEnable: number;
|
|
799
|
-
/** Fixes slow rendering in some browsers by not compositing the WebGL canvas
|
|
800
|
-
* @default
|
|
801
|
-
* @memberof Settings */
|
|
802
|
-
declare let glOverlay: number;
|
|
803
818
|
/** Should gamepads be allowed
|
|
804
819
|
* @default
|
|
805
820
|
* @memberof Settings */
|
|
@@ -834,14 +849,14 @@ declare let touchGamepadAlpha: number;
|
|
|
834
849
|
* @default
|
|
835
850
|
* @memberof Settings */
|
|
836
851
|
declare let vibrateEnable: number;
|
|
837
|
-
/** Volume scale to apply to all sound, music and speech
|
|
838
|
-
* @default
|
|
839
|
-
* @memberof Settings */
|
|
840
|
-
declare let soundVolume: number;
|
|
841
852
|
/** All audio code can be disabled and removed from build
|
|
842
853
|
* @default
|
|
843
854
|
* @memberof Settings */
|
|
844
855
|
declare let soundEnable: number;
|
|
856
|
+
/** Volume scale to apply to all sound, music and speech
|
|
857
|
+
* @default
|
|
858
|
+
* @memberof Settings */
|
|
859
|
+
declare let soundVolume: number;
|
|
845
860
|
/** Default range where sound no longer plays
|
|
846
861
|
* @default
|
|
847
862
|
* @memberof Settings */
|
|
@@ -858,18 +873,18 @@ declare let medalDisplayTime: number;
|
|
|
858
873
|
* @default
|
|
859
874
|
* @memberof Settings */
|
|
860
875
|
declare let medalDisplaySlideTime: number;
|
|
861
|
-
/**
|
|
862
|
-
* @default
|
|
863
|
-
* @memberof Settings */
|
|
864
|
-
declare let medalDisplayWidth: number;
|
|
865
|
-
/** Height of medal display
|
|
876
|
+
/** Size of medal display
|
|
866
877
|
* @default
|
|
867
878
|
* @memberof Settings */
|
|
868
|
-
declare let
|
|
879
|
+
declare let medalDisplaySize: Vector2;
|
|
869
880
|
/** Size of icon in medal display
|
|
870
881
|
* @default
|
|
871
882
|
* @memberof Settings */
|
|
872
883
|
declare let medalDisplayIconSize: number;
|
|
884
|
+
/** Set to stop medals from being unlockable (like if cheats are enabled)
|
|
885
|
+
* @default
|
|
886
|
+
* @memberof Settings */
|
|
887
|
+
declare let medalsPreventUnlock: any;
|
|
873
888
|
/**
|
|
874
889
|
* LittleJS Object Base Object Class
|
|
875
890
|
* <br> - Base object class used by the engine
|
|
@@ -991,10 +1006,6 @@ declare class EngineObject {
|
|
|
991
1006
|
isSolid: boolean;
|
|
992
1007
|
toString(): string;
|
|
993
1008
|
}
|
|
994
|
-
/** Tile sheet for batch rendering system
|
|
995
|
-
* @type {Image}
|
|
996
|
-
* @memberof Draw */
|
|
997
|
-
declare const tileImage: new (width?: number, height?: number) => HTMLImageElement;
|
|
998
1009
|
/** The primary 2D canvas visible to the user
|
|
999
1010
|
* @type {HTMLCanvasElement}
|
|
1000
1011
|
* @memberof Draw */
|
|
@@ -1015,6 +1026,13 @@ declare let overlayContext: CanvasRenderingContext2D;
|
|
|
1015
1026
|
* @type {Vector2}
|
|
1016
1027
|
* @memberof Draw */
|
|
1017
1028
|
declare let mainCanvasSize: Vector2;
|
|
1029
|
+
/** Tile sheet for batch rendering system
|
|
1030
|
+
* @type {Image}
|
|
1031
|
+
* @memberof Draw */
|
|
1032
|
+
declare const tileImage: new (width?: number, height?: number) => HTMLImageElement;
|
|
1033
|
+
declare let tileImageSize: any;
|
|
1034
|
+
declare let tileImageFixBleed: any;
|
|
1035
|
+
declare let drawCount: any;
|
|
1018
1036
|
/** Convert from screen to world space coordinates
|
|
1019
1037
|
* - if calling outside of render, you may need to manually set mainCanvasSize
|
|
1020
1038
|
* @param {Vector2} screenPos
|
|
@@ -1042,8 +1060,8 @@ declare function worldToScreen(worldPos: Vector2): Vector2;
|
|
|
1042
1060
|
declare let engineFontImage: any;
|
|
1043
1061
|
declare class FontImage {
|
|
1044
1062
|
/** Create an image font
|
|
1045
|
-
* @param {HTMLImageElement}
|
|
1046
|
-
* @param {Vector2} [tileSize=vec2(8)] -
|
|
1063
|
+
* @param {HTMLImageElement} [image] - Image for the font, if undefined default font is used
|
|
1064
|
+
* @param {Vector2} [tileSize=vec2(8)] - Size of the font source tiles
|
|
1047
1065
|
* @param {Vector2} [paddingSize=vec2(0,1)] - How much extra space to add between characters
|
|
1048
1066
|
* @param {Number} [startTileIndex=0] - Tile index in image where font starts
|
|
1049
1067
|
* @param {CanvasRenderingContext2D} [context=overlayContext] - context to draw to
|
|
@@ -1169,8 +1187,8 @@ declare function vibrateStop(): boolean;
|
|
|
1169
1187
|
* @memberof Input */
|
|
1170
1188
|
declare const isTouchDevice: boolean;
|
|
1171
1189
|
declare let touchGamepadTimer: Timer;
|
|
1172
|
-
declare let touchGamepadButtons: any
|
|
1173
|
-
declare let touchGamepadStick:
|
|
1190
|
+
declare let touchGamepadButtons: any;
|
|
1191
|
+
declare let touchGamepadStick: any;
|
|
1174
1192
|
/**
|
|
1175
1193
|
* Sound Object - Stores a zzfx sound for later use and can be played positionally
|
|
1176
1194
|
* <br>
|
|
@@ -1510,9 +1528,6 @@ declare class Particle extends EngineObject {
|
|
|
1510
1528
|
/** List of all medals
|
|
1511
1529
|
* @memberof Medals */
|
|
1512
1530
|
declare const medals: any[];
|
|
1513
|
-
/** Set to stop medals from being unlockable (like if cheats are enabled)
|
|
1514
|
-
* @memberof Medals */
|
|
1515
|
-
declare let medalsPreventUnlock: any;
|
|
1516
1531
|
declare let medalsDisplayQueue: any[];
|
|
1517
1532
|
declare let medalsSaveName: any;
|
|
1518
1533
|
declare let medalsDisplayTimeLast: any;
|
|
@@ -1554,7 +1569,7 @@ declare class Medal {
|
|
|
1554
1569
|
* @param {Number} y - Screen space Y position
|
|
1555
1570
|
* @param {Number} [size=medalDisplayIconSize] - Screen space size
|
|
1556
1571
|
*/
|
|
1557
|
-
renderIcon(
|
|
1572
|
+
renderIcon(pos: any, size?: number): void;
|
|
1558
1573
|
storageKey(): string;
|
|
1559
1574
|
}
|
|
1560
1575
|
declare let newgrounds: any;
|
|
@@ -1575,7 +1590,7 @@ declare class Newgrounds {
|
|
|
1575
1590
|
cipher: string;
|
|
1576
1591
|
host: string;
|
|
1577
1592
|
cryptoJS: any;
|
|
1578
|
-
session_id: string
|
|
1593
|
+
session_id: string;
|
|
1579
1594
|
medals: any;
|
|
1580
1595
|
scoreboards: any;
|
|
1581
1596
|
/** Send message to unlock a medal by id
|
|
@@ -1603,8 +1618,8 @@ declare class Newgrounds {
|
|
|
1603
1618
|
* @return {Object} - The response JSON object
|
|
1604
1619
|
*/
|
|
1605
1620
|
call(component: string, parameters?: any, async?: boolean): any;
|
|
1621
|
+
CryptoJS(): any;
|
|
1606
1622
|
}
|
|
1607
|
-
declare function CryptoJS(): any;
|
|
1608
1623
|
/** The WebGL canvas which appears above the main canvas and below the overlay canvas
|
|
1609
1624
|
* @type {HTMLCanvasElement}
|
|
1610
1625
|
* @memberof WebGL */
|
|
@@ -1620,7 +1635,6 @@ declare let glTileTexture: WebGLTexture;
|
|
|
1620
1635
|
declare let glActiveTexture: any;
|
|
1621
1636
|
declare let glShader: any;
|
|
1622
1637
|
declare let glArrayBuffer: any;
|
|
1623
|
-
declare let glVertexData: any;
|
|
1624
1638
|
declare let glPositionData: any;
|
|
1625
1639
|
declare let glColorData: any;
|
|
1626
1640
|
declare let glBatchCount: any;
|
|
@@ -1661,10 +1675,11 @@ declare const gl_VERTICES_PER_QUAD: 6;
|
|
|
1661
1675
|
declare const gl_INDICIES_PER_VERT: 6;
|
|
1662
1676
|
declare const gl_MAX_BATCH: number;
|
|
1663
1677
|
declare const gl_VERTEX_BYTE_STRIDE: number;
|
|
1678
|
+
declare const gl_VERTEX_BUFFER_SIZE: number;
|
|
1664
1679
|
/** Name of engine */
|
|
1665
1680
|
declare const engineName: "LittleJS";
|
|
1666
1681
|
/** Version of engine */
|
|
1667
|
-
declare const engineVersion: "1.4.
|
|
1682
|
+
declare const engineVersion: "1.4.9";
|
|
1668
1683
|
/** Frames per second to update objects
|
|
1669
1684
|
* @default */
|
|
1670
1685
|
declare const frameRate: 60;
|
|
@@ -1681,9 +1696,5 @@ declare let frame: number;
|
|
|
1681
1696
|
declare let time: number;
|
|
1682
1697
|
/** Actual clock time since start in seconds (not affected by pause or frame rate clamping) */
|
|
1683
1698
|
declare let timeReal: number;
|
|
1684
|
-
/** Is the game paused? Causes time and objects to not be updated
|
|
1699
|
+
/** Is the game paused? Causes time and objects to not be updated */
|
|
1685
1700
|
declare let paused: number;
|
|
1686
|
-
declare let tileImageSize: any;
|
|
1687
|
-
declare let tileImageFixBleed: any;
|
|
1688
|
-
declare let averageFPS: any;
|
|
1689
|
-
declare let drawCount: any;
|
|
@@ -8,22 +8,22 @@ let levelSize, ball, paddle, score, brickCount;
|
|
|
8
8
|
|
|
9
9
|
// sound effects
|
|
10
10
|
const sound_start = new Sound([,0,500,,.04,.3,1,2,,,570,.02,.02,,,,.04]);
|
|
11
|
-
const sound_break = new Sound([,,90,,.01,.03,4,,,,,,,9,50,.2,,.2,.01]
|
|
12
|
-
const sound_bounce = new Sound([,,1e3,,.03,.02,1,2,,,940,.03,,,,,.2,.6,,.06]
|
|
11
|
+
const sound_break = new Sound([,,90,,.01,.03,4,,,,,,,9,50,.2,,.2,.01]);
|
|
12
|
+
const sound_bounce = new Sound([,,1e3,,.03,.02,1,2,,,940,.03,,,,,.2,.6,,.06]);
|
|
13
13
|
|
|
14
14
|
///////////////////////////////////////////////////////////////////////////////
|
|
15
15
|
function gameInit()
|
|
16
16
|
{
|
|
17
17
|
canvasFixedSize = vec2(1280, 720); // 720p
|
|
18
|
-
levelSize = vec2(
|
|
18
|
+
levelSize = vec2(38, 20);
|
|
19
19
|
cameraPos = levelSize.scale(.5);
|
|
20
|
-
paddle = new Paddle(vec2(levelSize.x/2-12,
|
|
20
|
+
paddle = new Paddle(vec2(levelSize.x/2-12,1));
|
|
21
21
|
score = brickCount = 0;
|
|
22
22
|
|
|
23
23
|
// spawn bricks
|
|
24
24
|
const pos = vec2();
|
|
25
|
-
for (pos.x =
|
|
26
|
-
for (pos.y =
|
|
25
|
+
for (pos.x = 4; pos.x <= levelSize.x-4; pos.x += 2)
|
|
26
|
+
for (pos.y = 12; pos.y <= levelSize.y-2; pos.y += 1)
|
|
27
27
|
new Brick(pos);
|
|
28
28
|
|
|
29
29
|
initPostProcess(); // set up a post processing shader
|
|
@@ -35,7 +35,7 @@ function gameUpdate()
|
|
|
35
35
|
// spawn ball
|
|
36
36
|
if (!ball && (mouseWasPressed(0) || gamepadWasPressed(0)))
|
|
37
37
|
{
|
|
38
|
-
ball = new Ball(vec2(levelSize.x/2, levelSize.y/2
|
|
38
|
+
ball = new Ball(vec2(levelSize.x/2, levelSize.y/2));
|
|
39
39
|
sound_start.play();
|
|
40
40
|
}
|
|
41
41
|
}
|
|
@@ -59,11 +59,11 @@ function gameRenderPost()
|
|
|
59
59
|
{
|
|
60
60
|
// use built in image font for text
|
|
61
61
|
const font = new FontImage;
|
|
62
|
-
font.drawText('Score: ' + score, cameraPos.add(vec2(0,
|
|
62
|
+
font.drawText('Score: ' + score, cameraPos.add(vec2(0,9.6)), .1, 1);
|
|
63
63
|
if (!brickCount)
|
|
64
|
-
font.drawText('You Win!', cameraPos.add(vec2(0,-5)), .
|
|
64
|
+
font.drawText('You Win!', cameraPos.add(vec2(0,-5)), .2, 1);
|
|
65
65
|
else if (!ball)
|
|
66
|
-
font.drawText('Click to Play', cameraPos.add(vec2(0,-5)), .
|
|
66
|
+
font.drawText('Click to Play', cameraPos.add(vec2(0,-5)), .2, 1);
|
|
67
67
|
}
|
|
68
68
|
|
|
69
69
|
///////////////////////////////////////////////////////////////////////////////
|
|
@@ -9,7 +9,7 @@ class Paddle extends EngineObject
|
|
|
9
9
|
{
|
|
10
10
|
constructor(pos)
|
|
11
11
|
{
|
|
12
|
-
super(pos, vec2(
|
|
12
|
+
super(pos, vec2(5,.5));
|
|
13
13
|
|
|
14
14
|
// set to collide
|
|
15
15
|
this.setCollision();
|
|
@@ -38,7 +38,7 @@ class Brick extends EngineObject
|
|
|
38
38
|
{
|
|
39
39
|
constructor(pos)
|
|
40
40
|
{
|
|
41
|
-
super(pos, vec2(
|
|
41
|
+
super(pos, vec2(2,1), 1, vec2(32,16), 0, randColor());
|
|
42
42
|
|
|
43
43
|
// set to collide
|
|
44
44
|
this.setCollision();
|
|
@@ -62,7 +62,7 @@ class Brick extends EngineObject
|
|
|
62
62
|
0, vec2(16), // tileIndex, tileSize
|
|
63
63
|
color1, color2, // colorStartA, colorStartB
|
|
64
64
|
color1.scale(1,0), color2.scale(1,0), // colorEndA, colorEndB
|
|
65
|
-
.2,
|
|
65
|
+
.2, .5, 1, .05, .05,// time, sizeStart, sizeEnd, speed, angleSpeed
|
|
66
66
|
.99, .95, .4, PI, // damping, angleDamping, gravityScale, cone
|
|
67
67
|
.1, .5, 0, 1 // fadeRate, randomness, collide, additive
|
|
68
68
|
);
|
|
@@ -76,11 +76,11 @@ class Ball extends EngineObject
|
|
|
76
76
|
{
|
|
77
77
|
constructor(pos)
|
|
78
78
|
{
|
|
79
|
-
super(pos, vec2(
|
|
79
|
+
super(pos, vec2(.5), 0);
|
|
80
80
|
|
|
81
81
|
// make a bouncy ball
|
|
82
82
|
this.setCollision();
|
|
83
|
-
this.velocity = vec2(randSign(), -1).scale(.
|
|
83
|
+
this.velocity = vec2(randSign(), -1).scale(.1);
|
|
84
84
|
this.elasticity = 1;
|
|
85
85
|
this.damping = 1;
|
|
86
86
|
}
|
|
@@ -117,7 +117,7 @@ class Ball extends EngineObject
|
|
|
117
117
|
{
|
|
118
118
|
// put english on the ball when it collides with paddle
|
|
119
119
|
this.velocity = this.velocity.rotate(.2 * (this.pos.x - o.pos.x));
|
|
120
|
-
this.velocity.y = max(
|
|
120
|
+
this.velocity.y = max(-this.velocity.y, .2);
|
|
121
121
|
this.bounce();
|
|
122
122
|
return 0;
|
|
123
123
|
}
|
|
@@ -127,7 +127,7 @@ class Ball extends EngineObject
|
|
|
127
127
|
bounce()
|
|
128
128
|
{
|
|
129
129
|
// speed up
|
|
130
|
-
const speed = min(1.
|
|
130
|
+
const speed = min(1.05*this.velocity.length(), .5);
|
|
131
131
|
this.velocity = this.velocity.normalize(speed);
|
|
132
132
|
|
|
133
133
|
// scale bounce sound pitch by speed
|
|
@@ -5,6 +5,6 @@
|
|
|
5
5
|
<link rel=icon type=image/png href=../../favicon.png>
|
|
6
6
|
</head><body>
|
|
7
7
|
|
|
8
|
-
<script src=../../engine/engine.all.js?
|
|
9
|
-
<script src=gameObjects.js?
|
|
10
|
-
<script src=game.js?
|
|
8
|
+
<script src=../../engine/engine.all.js?123></script>
|
|
9
|
+
<script src=gameObjects.js?123></script>
|
|
10
|
+
<script src=game.js?123></script>
|
package/examples/empty/tiles.png
CHANGED
|
Binary file
|
package/examples/module/game.js
CHANGED
|
@@ -12,7 +12,7 @@ const Timer = LittleJS.Timer;
|
|
|
12
12
|
const vec2 = LittleJS.vec2;
|
|
13
13
|
|
|
14
14
|
// sound effects
|
|
15
|
-
const sound_click = new LittleJS.Sound([
|
|
15
|
+
const sound_click = new LittleJS.Sound([1,.5]);
|
|
16
16
|
|
|
17
17
|
// medals
|
|
18
18
|
const medal_example = new LittleJS.Medal(0, 'Example Medal', 'Welcome to LittleJS!');
|
|
@@ -26,8 +26,8 @@ function gameInit()
|
|
|
26
26
|
{
|
|
27
27
|
// create tile collision and visible tile layer
|
|
28
28
|
LittleJS.initTileCollision(vec2(32, 16));
|
|
29
|
-
const tileLayer = new LittleJS.TileLayer(vec2(), LittleJS.tileCollisionSize);
|
|
30
29
|
const pos = vec2();
|
|
30
|
+
const tileLayer = new LittleJS.TileLayer(pos, LittleJS.tileCollisionSize);
|
|
31
31
|
|
|
32
32
|
// get level data from the tiles image
|
|
33
33
|
const imageLevelDataRow = 1;
|
|
@@ -36,24 +36,22 @@ function gameInit()
|
|
|
36
36
|
for (pos.x = LittleJS.tileCollisionSize.x; pos.x--;)
|
|
37
37
|
for (pos.y = LittleJS.tileCollisionSize.y; pos.y--;)
|
|
38
38
|
{
|
|
39
|
-
const
|
|
40
|
-
if (
|
|
39
|
+
const imageData = mainContext.getImageData(pos.x, 16*(imageLevelDataRow+1)-pos.y-1, 1, 1).data;
|
|
40
|
+
if (imageData[0])
|
|
41
41
|
{
|
|
42
|
-
LittleJS.setTileCollisionData(pos, 1);
|
|
43
|
-
|
|
44
42
|
const tileIndex = 1;
|
|
45
43
|
const direction = LittleJS.randInt(4)
|
|
46
44
|
const mirror = LittleJS.randInt(2);
|
|
47
45
|
const color = LittleJS.randColor();
|
|
48
46
|
const data = new LittleJS.TileLayerData(tileIndex, direction, mirror, color);
|
|
49
47
|
tileLayer.setData(pos, data);
|
|
48
|
+
LittleJS.setTileCollisionData(pos, 1);
|
|
50
49
|
}
|
|
51
50
|
}
|
|
52
51
|
tileLayer.redraw();
|
|
53
52
|
|
|
54
53
|
// move camera to center of collision
|
|
55
54
|
LittleJS.setCameraPos(LittleJS.tileCollisionSize.scale(.5));
|
|
56
|
-
LittleJS.setCameraScale(32);
|
|
57
55
|
|
|
58
56
|
// enable gravity
|
|
59
57
|
LittleJS.setGravity(-.01);
|