littlejsengine 1.0.14 → 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.
Files changed (99) hide show
  1. package/build.bat +5 -1
  2. package/docs/Audio.html +2268 -0
  3. package/docs/Color.html +2989 -0
  4. package/docs/Debug.html +2933 -0
  5. package/docs/Draw.html +4092 -0
  6. package/docs/EngineObject.html +4458 -0
  7. package/docs/Input.html +2482 -0
  8. package/docs/Medal.html +1007 -0
  9. package/docs/Medals.html +628 -0
  10. package/docs/Music.html +584 -0
  11. package/docs/Newgrounds.html +1399 -0
  12. package/docs/Particle.html +4535 -0
  13. package/docs/ParticleEmitter.html +7770 -0
  14. package/docs/Random.html +1774 -0
  15. package/docs/Settings.html +2679 -0
  16. package/docs/Sound.html +1249 -0
  17. package/docs/TileCollision.html +1409 -0
  18. package/docs/TileLayer.html +6948 -0
  19. package/docs/TileLayerData.html +1052 -0
  20. package/docs/Timer.html +1183 -0
  21. package/docs/Utilities.html +3281 -0
  22. package/docs/Vector2.html +4207 -0
  23. package/docs/WebGL.html +2327 -0
  24. package/docs/engine.js.html +429 -0
  25. package/docs/engineAudio.js.html +609 -0
  26. package/docs/engineDebug.js.html +725 -0
  27. package/docs/engineDraw.js.html +419 -0
  28. package/docs/engineInput.js.html +401 -0
  29. package/docs/engineMedals.js.html +461 -0
  30. package/docs/engineObject.js.html +518 -0
  31. package/docs/engineParticles.js.html +441 -0
  32. package/docs/engineSettings.js.html +349 -0
  33. package/docs/engineTileLayer.js.html +513 -0
  34. package/docs/engineUtilities.js.html +647 -0
  35. package/docs/engineWebGL.js.html +522 -0
  36. package/docs/fonts/MavenPro-Regular.ttf +0 -0
  37. package/docs/fonts/Montserrat-Regular.ttf +0 -0
  38. package/docs/fonts/Muli-Black.ttf +0 -0
  39. package/docs/fonts/OFL-hind.txt +93 -0
  40. package/docs/fonts/OFL-montserrat.txt +93 -0
  41. package/docs/global.html +1691 -0
  42. package/docs/index.css +6 -0
  43. package/docs/index.html +247 -0
  44. package/docs/scripts/fix-code-block.js +53 -0
  45. package/docs/scripts/fix-navbar.js +25 -0
  46. package/docs/scripts/linenumber.js +25 -0
  47. package/docs/scripts/misc.js +217 -0
  48. package/docs/scripts/resize.js +85 -0
  49. package/docs/scripts/search.js +83 -0
  50. package/docs/scripts/third-party/Apache-License-2.0.txt +202 -0
  51. package/docs/scripts/third-party/fuse.js +9 -0
  52. package/docs/scripts/third-party/lang-css.js +2 -0
  53. package/docs/scripts/third-party/prettify.js +28 -0
  54. package/docs/static/favicon.png +0 -0
  55. package/docs/static/index.css +4 -0
  56. package/docs/styles/clean-jsdoc-theme-base.css +393 -0
  57. package/docs/styles/clean-jsdoc-theme-dark.css +324 -0
  58. package/docs/styles/clean-jsdoc-theme-light.css +319 -0
  59. package/docs/styles/reset.css +346 -0
  60. package/docs/styles/third-party/ionicons.min.css +11 -0
  61. package/docs/styles/third-party/prettify-jsdoc.css +111 -0
  62. package/docs/styles/third-party/prettify-tomorrow.css +5 -0
  63. package/engine/engine.all.js +1997 -744
  64. package/engine/engine.all.min.js +1 -1
  65. package/engine/engine.all.release.js +1743 -569
  66. package/engine/engine.js +107 -39
  67. package/engine/engineAudio.js +152 -34
  68. package/engine/{build.bat → engineBuild.bat} +10 -10
  69. package/engine/{buildSetup.bat → engineBuildSetup.bat} +0 -0
  70. package/engine/engineDebug.js +105 -32
  71. package/engine/engineDraw.js +137 -32
  72. package/engine/engineInput.js +111 -37
  73. package/engine/{engineMedal.js → engineMedals.js} +129 -56
  74. package/engine/engineObject.js +117 -67
  75. package/engine/engineParticles.js +282 -0
  76. package/engine/engineRelease.js +3 -9
  77. package/engine/engineSettings.js +190 -0
  78. package/engine/engineTileLayer.js +147 -44
  79. package/engine/engineUtilities.js +488 -0
  80. package/engine/engineWebGL.js +113 -74
  81. package/examples/breakout/game.js +1 -1
  82. package/examples/breakout/gameObjects.js +3 -3
  83. package/examples/breakout/index.html +3 -3
  84. package/examples/platformer/game.js +5 -7
  85. package/examples/platformer/gameEffects.js +7 -7
  86. package/examples/platformer/gameLevel.js +2 -2
  87. package/examples/platformer/gameObjects.js +4 -5
  88. package/examples/platformer/gamePlayer.js +3 -3
  89. package/examples/platformer/index.html +6 -6
  90. package/examples/puzzle/game.js +1 -2
  91. package/examples/puzzle/index.html +2 -2
  92. package/examples/stress/index.html +2 -8
  93. package/game.js +5 -11
  94. package/index.html +13 -13
  95. package/package.json +4 -4
  96. package/tiles.png +0 -0
  97. package/engine/engineConfig.js +0 -64
  98. package/engine/engineParticle.js +0 -199
  99. package/engine/engineUtil.js +0 -147
@@ -1,18 +1,37 @@
1
- /*
2
- LittleJS WebGL Interface
3
- - All webgl used by the engine is wrapped up here
4
- - Can be disabled with glEnable to revert to 2D canvas rendering
5
- - Batches sprite rendering on GPU for incredibly fast performance
6
- - Sprite transform math is done in the shader where possible
7
- - For normal stuff you won't need to call any functions in this file
8
- - For advanced stuff there are helper functions to create shaders, textures, etc
9
- */
1
+ /**
2
+ * LittleJS WebGL Interface
3
+ * <br> - All webgl used by the engine is wrapped up here
4
+ * <br> - Can be disabled with glEnable to revert to 2D canvas rendering
5
+ * <br> - Batches sprite rendering on GPU for incredibly fast performance
6
+ * <br> - Sprite transform math is done in the shader where possible
7
+ * <br> - For normal stuff you won't need to call any functions in this file
8
+ * <br> - For advanced stuff there are helper functions to create shaders, textures, etc
9
+ * @namespace WebGL
10
+ */
10
11
 
11
12
  'use strict';
12
13
 
13
- let glCanvas, glContext, glTileTexture, glActiveTexture, glShader,
14
- glPositionData, glColorData, glBatchCount, glDirty, glAdditive;
14
+ /** The WebGL canvas which appears above the main canvas and below the overlay canvas
15
+ * @type {HTMLCanvasElement}
16
+ * @memberof WebGL */
17
+ let glCanvas;
15
18
 
19
+ /** 2d context for glCanvas
20
+ * @type {WebGLRenderingContext}
21
+ * @memberof WebGL */
22
+ let glContext;
23
+
24
+ /** Main tile sheet texture automatically loaded by engine
25
+ * @type {WebGLTexture}
26
+ * @memberof WebGL */
27
+ let glTileTexture;
28
+
29
+ // WebGL internal variables not exposed to documentation
30
+ let glActiveTexture, glShader, glPositionData, glColorData, glBatchCount, glBatchAdditive, glDirty, glAdditive;
31
+
32
+ ///////////////////////////////////////////////////////////////////////////////
33
+
34
+ // Init WebGL, called automatically by the engine
16
35
  function glInit()
17
36
  {
18
37
  if (!glEnable) return;
@@ -24,7 +43,7 @@ function glInit()
24
43
 
25
44
  if (glOverlay)
26
45
  {
27
- // firefox is much faster without copying the gl buffer so we just overlay it with some tradeoffs
46
+ // some browsers are much faster without copying the gl buffer so we just overlay it instead
28
47
  document.body.appendChild(glCanvas);
29
48
  glCanvas.style = mainCanvas.style.cssText;
30
49
  }
@@ -75,20 +94,21 @@ function glInit()
75
94
  initVertexAttribArray('b', gl_UNSIGNED_BYTE, 1, 4, 1); // additiveColor
76
95
  }
77
96
 
97
+ /** Set the WebGl blend mode, normally you should call setBlendMode instead
98
+ * @param {Boolean} [additive=0]
99
+ * @memberof WebGL */
78
100
  function glSetBlendMode(additive)
79
101
  {
80
102
  if (!glEnable) return;
81
103
 
82
- if (additive != glAdditive)
83
- glFlush();
84
-
85
104
  // setup blending
86
105
  glAdditive = additive;
87
- const destBlend = additive ? gl_ONE : gl_ONE_MINUS_SRC_ALPHA;
88
- glContext.blendFuncSeparate(gl_SRC_ALPHA, destBlend, gl_ONE, destBlend);
89
- glContext.enable(gl_BLEND);
90
106
  }
91
107
 
108
+ /** Set the WebGl texture, not normally necessary unless multiple tile sheets are used
109
+ * <br> - This may also flush the gl buffer resulting in more draw calls and worse performance
110
+ * @param {WebGLTexture} [texture=glTileTexture]
111
+ * @memberof WebGL */
92
112
  function glSetTexture(texture=glTileTexture)
93
113
  {
94
114
  if (!glEnable) return;
@@ -99,6 +119,11 @@ function glSetTexture(texture=glTileTexture)
99
119
  glContext.bindTexture(gl_TEXTURE_2D, glActiveTexture = texture);
100
120
  }
101
121
 
122
+ /** Compile WebGL shader of the given type, will throw errors if in debug mode
123
+ * @param {String} source
124
+ * @param type
125
+ * @return {WebGLShader}
126
+ * @memberof WebGL */
102
127
  function glCompileShader(source, type)
103
128
  {
104
129
  if (!glEnable) return;
@@ -114,6 +139,11 @@ function glCompileShader(source, type)
114
139
  return shader;
115
140
  }
116
141
 
142
+ /** Create WebGL program with given shaders
143
+ * @param {WebGLShader} vsSource
144
+ * @param {WebGLShader} fsSource
145
+ * @return {WebGLProgram}
146
+ * @memberof WebGL */
117
147
  function glCreateProgram(vsSource, fsSource)
118
148
  {
119
149
  if (!glEnable) return;
@@ -130,6 +160,12 @@ function glCreateProgram(vsSource, fsSource)
130
160
  return program;
131
161
  }
132
162
 
163
+ /** Create WebGL buffer
164
+ * @param bufferType
165
+ * @param size
166
+ * @param usage
167
+ * @return {WebGLBuffer}
168
+ * @memberof WebGL */
133
169
  function glCreateBuffer(bufferType, size, usage)
134
170
  {
135
171
  if (!glEnable) return;
@@ -141,15 +177,19 @@ function glCreateBuffer(bufferType, size, usage)
141
177
  return buffer;
142
178
  }
143
179
 
180
+ /** Create WebGL texture from an image and set the texture settings
181
+ * @param {Image} image
182
+ * @return {WebGLTexture}
183
+ * @memberof WebGL */
144
184
  function glCreateTexture(image)
145
185
  {
146
- if (!glEnable) return;
186
+ if (!glEnable || !image || !image.width) return;
147
187
 
148
188
  // build the texture
149
189
  const texture = glContext.createTexture();
150
190
  glContext.bindTexture(gl_TEXTURE_2D, texture);
151
191
  glContext.texImage2D(gl_TEXTURE_2D, 0, gl_RGBA, gl_RGBA, gl_UNSIGNED_BYTE, image);
152
-
192
+
153
193
  // use point filtering for pixelated rendering
154
194
  glContext.texParameteri(gl_TEXTURE_2D, gl_TEXTURE_MIN_FILTER, pixelated ? gl_NEAREST : gl_LINEAR);
155
195
  glContext.texParameteri(gl_TEXTURE_2D, gl_TEXTURE_MAG_FILTER, pixelated ? gl_NEAREST : gl_LINEAR);
@@ -158,6 +198,7 @@ function glCreateTexture(image)
158
198
  return texture;
159
199
  }
160
200
 
201
+ // called automatically by engine before render
161
202
  function glPreRender(width, height)
162
203
  {
163
204
  if (!glEnable) return;
@@ -185,24 +226,33 @@ function glPreRender(width, height)
185
226
  );
186
227
  }
187
228
 
229
+ /** Draw all sprites and clear out the buffer, called automatically by the system whenever necessary
230
+ * @memberof WebGL */
188
231
  function glFlush()
189
232
  {
190
233
  if (!glEnable || !glBatchCount) return;
191
234
 
235
+ const destBlend = glBatchAdditive ? gl_ONE : gl_ONE_MINUS_SRC_ALPHA;
236
+ glContext.blendFuncSeparate(gl_SRC_ALPHA, destBlend, gl_ONE, destBlend);
237
+ glContext.enable(gl_BLEND);
238
+
192
239
  // draw all the sprites in the batch and reset the buffer
193
240
  glContext.bufferSubData(gl_ARRAY_BUFFER, 0,
194
241
  glPositionData.subarray(0, glBatchCount * gl_VERTICES_PER_QUAD * gl_INDICIES_PER_VERT));
195
242
  glContext.drawArrays(gl_TRIANGLES, 0, glBatchCount * gl_VERTICES_PER_QUAD);
196
243
  glBatchCount = 0;
244
+ glBatchAdditive = glAdditive;
197
245
  }
198
246
 
247
+ /** Draw any sprites still in the buffer, copy to main canvas and clear
248
+ * @param {CanvasRenderingContext2D} context
249
+ * @param {Boolean} [forceDraw=0]
250
+ * @memberof WebGL */
199
251
  function glCopyToContext(context, forceDraw)
200
252
  {
201
253
  if (!glEnable || !glDirty) return;
202
254
 
203
- // draw any sprites still in the buffer, copy to main canvas and clear
204
255
  glFlush();
205
-
206
256
  if (!glOverlay || forceDraw)
207
257
  {
208
258
  // do not draw/clear in overlay mode because the canvas is visible
@@ -211,12 +261,25 @@ function glCopyToContext(context, forceDraw)
211
261
  }
212
262
  }
213
263
 
214
- function glDraw(x, y, sizeX, sizeY, angle=0, uv0X=0, uv0Y=0, uv1X=1, uv1Y=1, rgba=0xffffffff, rgbaAdditive=0x00000000)
264
+ /** Add a sprite to the gl draw list, used by all gl draw functions
265
+ * @param x
266
+ * @param y
267
+ * @param sizeX
268
+ * @param sizeY
269
+ * @param [angle=0]
270
+ * @param [uv0X=0]
271
+ * @param [uv0Y=0]
272
+ * @param [uv1X=1]
273
+ * @param [uv1Y=1]
274
+ * @param [rgba=0xffffffff]
275
+ * @param [rgbaAdditive=0]
276
+ * @memberof WebGL */
277
+ function glDraw(x, y, sizeX, sizeY, angle=0, uv0X=0, uv0Y=0, uv1X=1, uv1Y=1, rgba=0xffffffff, rgbaAdditive=0)
215
278
  {
216
279
  if (!glEnable) return;
217
-
218
- // flush if there is no room for more verts
219
- if (glBatchCount == gl_MAX_BATCH)
280
+
281
+ // flush if there is no room for more verts or if different blend mode
282
+ if (glBatchCount == gl_MAX_BATCH || glBatchAdditive != glAdditive)
220
283
  glFlush();
221
284
 
222
285
  // setup 2 triangles to form a quad
@@ -225,69 +288,45 @@ function glDraw(x, y, sizeX, sizeY, angle=0, uv0X=0, uv0Y=0, uv1X=1, uv1Y=1, rgb
225
288
 
226
289
  // vertex 0
227
290
  glPositionData[offset++] = angle;
228
- glPositionData[offset++] = x;
229
- glPositionData[offset++] = y;
230
- glPositionData[offset++] = -sizeX;
231
- glPositionData[offset++] = -sizeY;
232
- glPositionData[offset++] = uv0X;
233
- glPositionData[offset++] = uv1Y;
234
- glColorData[offset++] = rgba;
235
- glColorData[offset++] = rgbaAdditive;
291
+ glPositionData[offset++] = x; glPositionData[offset++] = y;
292
+ glPositionData[offset++] = -sizeX; glPositionData[offset++] = -sizeY;
293
+ glPositionData[offset++] = uv0X; glPositionData[offset++] = uv1Y;
294
+ glColorData[offset++] = rgba; glColorData[offset++] = rgbaAdditive;
236
295
 
237
296
  // vertex 1
238
297
  glPositionData[offset++] = angle;
239
- glPositionData[offset++] = x;
240
- glPositionData[offset++] = y;
241
- glPositionData[offset++] = sizeX;
242
- glPositionData[offset++] = sizeY;
243
- glPositionData[offset++] = uv1X;
244
- glPositionData[offset++] = uv0Y;
245
- glColorData[offset++] = rgba;
246
- glColorData[offset++] = rgbaAdditive;
298
+ glPositionData[offset++] = x; glPositionData[offset++] = y;
299
+ glPositionData[offset++] = sizeX; glPositionData[offset++] = sizeY;
300
+ glPositionData[offset++] = uv1X; glPositionData[offset++] = uv0Y;
301
+ glColorData[offset++] = rgba; glColorData[offset++] = rgbaAdditive;
247
302
 
248
303
  // vertex 2
249
304
  glPositionData[offset++] = angle;
250
- glPositionData[offset++] = x;
251
- glPositionData[offset++] = y;
252
- glPositionData[offset++] = -sizeX;
253
- glPositionData[offset++] = sizeY;
254
- glPositionData[offset++] = uv0X;
255
- glPositionData[offset++] = uv0Y;
256
- glColorData[offset++] = rgba;
257
- glColorData[offset++] = rgbaAdditive;
305
+ glPositionData[offset++] = x; glPositionData[offset++] = y;
306
+ glPositionData[offset++] = -sizeX; glPositionData[offset++] = sizeY;
307
+ glPositionData[offset++] = uv0X; glPositionData[offset++] = uv0Y;
308
+ glColorData[offset++] = rgba; glColorData[offset++] = rgbaAdditive;
258
309
 
259
310
  // vertex 0
260
311
  glPositionData[offset++] = angle;
261
- glPositionData[offset++] = x;
262
- glPositionData[offset++] = y;
263
- glPositionData[offset++] = -sizeX;
264
- glPositionData[offset++] = -sizeY;
265
- glPositionData[offset++] = uv0X;
266
- glPositionData[offset++] = uv1Y;
267
- glColorData[offset++] = rgba;
268
- glColorData[offset++] = rgbaAdditive;
312
+ glPositionData[offset++] = x; glPositionData[offset++] = y;
313
+ glPositionData[offset++] = -sizeX; glPositionData[offset++] = -sizeY;
314
+ glPositionData[offset++] = uv0X; glPositionData[offset++] = uv1Y;
315
+ glColorData[offset++] = rgba; glColorData[offset++] = rgbaAdditive;
269
316
 
270
317
  // vertex 3
271
318
  glPositionData[offset++] = angle;
272
- glPositionData[offset++] = x;
273
- glPositionData[offset++] = y;
274
- glPositionData[offset++] = sizeX;
275
- glPositionData[offset++] = -sizeY;
276
- glPositionData[offset++] = uv1X;
277
- glPositionData[offset++] = uv1Y;
278
- glColorData[offset++] = rgba;
279
- glColorData[offset++] = rgbaAdditive;
319
+ glPositionData[offset++] = x; glPositionData[offset++] = y;
320
+ glPositionData[offset++] = sizeX; glPositionData[offset++] = -sizeY;
321
+ glPositionData[offset++] = uv1X; glPositionData[offset++] = uv1Y;
322
+ glColorData[offset++] = rgba; glColorData[offset++] = rgbaAdditive;
280
323
 
281
324
  // vertex 1
282
325
  glPositionData[offset++] = angle;
283
- glPositionData[offset++] = x;
284
- glPositionData[offset++] = y;
285
- glPositionData[offset++] = sizeX;
286
- glPositionData[offset++] = sizeY;
287
- glPositionData[offset++] = uv1X;
288
- glPositionData[offset++] = uv0Y;
289
- glColorData[offset++] = rgba;
290
- glColorData[offset++] = rgbaAdditive;
326
+ glPositionData[offset++] = x; glPositionData[offset++] = y;
327
+ glPositionData[offset++] = sizeX; glPositionData[offset++] = sizeY;
328
+ glPositionData[offset++] = uv1X; glPositionData[offset++] = uv0Y;
329
+ glColorData[offset++] = rgba; glColorData[offset++] = rgbaAdditive;
291
330
  }
292
331
 
293
332
  ///////////////////////////////////////////////////////////////////////////////
@@ -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
- fixedWidth = 1280, fixedHeight = 720; // 720p
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));
@@ -18,7 +18,7 @@ class Paddle extends EngineObject
18
18
 
19
19
  update()
20
20
  {
21
- if (usingGamepad)
21
+ if (isUsingGamepad)
22
22
  {
23
23
  // control with gamepad
24
24
  this.pos.x += gamepadStick(0).x;
@@ -56,11 +56,11 @@ class Block extends EngineObject
56
56
  const color1 = this.color;
57
57
  const color2 = color1.lerp(new Color, .5);
58
58
  new ParticleEmitter(
59
- this.pos, this.size, .1, 400, PI, // pos, emitSize, emitTime, emitRate, emiteCone
59
+ this.pos, this.size, .1, 200, PI, // pos, emitSize, emitTime, emitRate, emiteCone
60
60
  0, vec2(16), // tileIndex, tileSize
61
61
  color1, color2, // colorStartA, colorStartB
62
62
  color1.scale(1,0), color2.scale(1,0), // colorEndA, colorEndB
63
- .2, .6, .6, .1, .05, // particleTime, sizeStart, sizeEnd, particleSpeed, particleAngleSpeed
63
+ .2, 1, 1, .1, .05, // particleTime, sizeStart, sizeEnd, particleSpeed, particleAngleSpeed
64
64
  .99, .95, .4, PI, .1, // damping, angleDamping, gravityScale, particleCone, fadeRate,
65
65
  1, 0, 1 // randomness, collide, additive, randomColorLinear, renderOrder
66
66
  );
@@ -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.js?48></script>
7
- <script src=game.js?48></script>
8
- <script src=gameObjects.js?48></script>
6
+ <script src=../../engine/engine.all.min.js?60></script>
7
+ <script src=game.js?60></script>
8
+ <script src=gameObjects.js?60></script>
@@ -5,8 +5,6 @@
5
5
 
6
6
  'use strict';
7
7
 
8
- const lowGraphicsMode = glOverlay = !isChrome; // fix slow rendering when not chrome
9
-
10
8
  let score, deaths;
11
9
 
12
10
  ///////////////////////////////////////////////////////////////////////////////
@@ -34,8 +32,8 @@ function gameUpdate()
34
32
  // mouse wheel = zoom
35
33
  cameraScale = clamp(cameraScale*(1-mouseWheel/10), 1e3, 1);
36
34
 
37
- // C = drop crate
38
- if (keyWasPressed(67))
35
+ // T = drop test crate
36
+ if (keyWasPressed(84))
39
37
  new Crate(mousePos);
40
38
 
41
39
  // E = drop enemy
@@ -72,7 +70,7 @@ function gameRender()
72
70
  function gameRenderPost()
73
71
  {
74
72
  // draw to overlay canvas for hud rendering
75
- const drawOverlayText = (text, x, y, size=70) =>
73
+ const drawText = (text, x, y, size=70) =>
76
74
  {
77
75
  overlayContext.textAlign = 'center';
78
76
  overlayContext.textBaseline = 'top';
@@ -82,8 +80,8 @@ function gameRenderPost()
82
80
  overlayContext.strokeText(text, x, y);
83
81
  overlayContext.fillText(text, x, y);
84
82
  }
85
- drawOverlayText('Score: ' + score, overlayCanvas.width*1/3, 20);
86
- drawOverlayText('Deaths: ' + deaths, overlayCanvas.width*2/3, 20);
83
+ drawText('Score: ' + score, overlayCanvas.width*1/3, 20);
84
+ drawText('Deaths: ' + deaths, overlayCanvas.width*2/3, 20);
87
85
  }
88
86
 
89
87
  ///////////////////////////////////////////////////////////////////////////////
@@ -74,12 +74,12 @@ function explosion(pos, radius=3)
74
74
  {
75
75
  const h = (cleanupRadius**2 - x**2)**.5;
76
76
  for (let y = -h; y < h; ++y)
77
- decorateTile(pos.add(vec2(x,y)).int());
77
+ decorateTile(pos.add(vec2(x,y)).floor());
78
78
  }
79
79
 
80
80
  // kill/push objects
81
81
  const maxRangeSquared = (radius*1.5)**2;
82
- forEachObject(pos, radius*3, (o)=>
82
+ engineObjectsCallback(pos, radius*3, (o)=>
83
83
  {
84
84
  const d = o.pos.distance(pos);
85
85
  if (o.isGameObject)
@@ -126,7 +126,7 @@ function explosion(pos, radius=3)
126
126
  function destroyTile(pos, makeSound = 1, cleanNeighbors = 1)
127
127
  {
128
128
  // pos must be an int
129
- pos = pos.int();
129
+ pos = pos.floor();
130
130
 
131
131
  // destroy tile
132
132
  const tileType = getTileCollisionData(pos);
@@ -170,9 +170,9 @@ function decorateBackgroundTile(pos)
170
170
  if (neighborTileDataA > 0 | neighborTileDataB > 0)
171
171
  continue;
172
172
 
173
- const directionVector = vec2().setAngle(i*PI/2+PI/4, 10).int();
173
+ const directionVector = vec2().setAngle(i*PI/2+PI/4, 10).floor();
174
174
  const drawPos = pos.add(vec2(.5)) // center
175
- .scale(16).add(directionVector).int(); // direction offset
175
+ .scale(16).add(directionVector).floor(); // direction offset
176
176
 
177
177
  // clear rect without any scaling to prevent blur from filtering
178
178
  const s = 2;
@@ -235,7 +235,7 @@ function drawStars()
235
235
  // draw stars and planets
236
236
  randSeed = skySeed;
237
237
  const largeStarCount = 9;
238
- for (let i = lowGraphicsMode ? 400 : 1e3; i--;)
238
+ for (let i = 1e3; i--;)
239
239
  {
240
240
  let size = randSeeded(6, 1);
241
241
  let speed = randSeeded() < .9 ? randSeeded(5) : randSeeded(99,9);
@@ -254,7 +254,7 @@ function drawStars()
254
254
  (randSeeded(w)+time*speed)%w-extraSpace,
255
255
  (randSeeded(h)+time*speed*randSeeded())%h-extraSpace);
256
256
 
257
- if (lowGraphicsMode)
257
+ if (glOverlay)
258
258
  {
259
259
  // drawing stars with gl is too slow in low graphics mode, just draw rects
260
260
  mainContext.fillStyle = color.rgba();
@@ -129,7 +129,7 @@ function buildTerrain(size)
129
129
  function generateLevel()
130
130
  {
131
131
  // clear old level
132
- destroyAllObjects();
132
+ engineObjectsDestroy();
133
133
 
134
134
  // randomize ground level hills
135
135
  buildTerrain(levelSize);
@@ -206,7 +206,7 @@ function buildLevel()
206
206
  // warm up level
207
207
  warmup = 1;
208
208
  for (let i=5*FPS; i--;)
209
- engineUpdateObjects();
209
+ engineObjectsUpdate();
210
210
  warmup = 0;
211
211
 
212
212
  // spawn player
@@ -66,7 +66,7 @@ class Crate extends GameObject
66
66
  {
67
67
  constructor(pos, typeOverride)
68
68
  {
69
- super(pos, defaultObjectSize, 2, vec2(16), (randInt(4))*PI/2);
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;
@@ -217,7 +217,7 @@ class Weapon extends EngineObject
217
217
  3, .1, .1, .15, .1, // particleTime, sizeStart, sizeEnd, particleSpeed, particleAngleSpeed
218
218
  1, .95, 1, 0, 0, // damping, angleDamping, gravityScale, particleCone, fadeRate,
219
219
  .1, 1 // randomness, collide, additive, randomColorLinear, renderOrder
220
- ));
220
+ ), vec2(.1,0), -.8);
221
221
  this.shellEmitter.elasticity = .5;
222
222
  this.shellEmitter.particleDestroyCallback = persistentParticleDestroyCallback;
223
223
  }
@@ -242,12 +242,11 @@ class Weapon extends EngineObject
242
242
  sound_shoot.play(this.pos);
243
243
  this.localAngle = -rand(.2,.15);
244
244
  this.recoilTimer.set(.4);
245
- const direction = vec2(this.getMirrorSign(this.bulletSpeed), 0);
245
+ const direction = vec2(this.bulletSpeed*this.getMirrorSign(), 0);
246
246
  const velocity = direction.rotate(rand(-1,1)*this.bulletSpread);
247
247
  new Bullet(this.pos, this.parent, velocity, this.damage);
248
248
 
249
249
  // spawn shell particle
250
- this.shellEmitter.localAngle = -.8*this.getMirrorSign();
251
250
  this.shellEmitter.emitParticle();
252
251
  }
253
252
  }
@@ -278,7 +277,7 @@ class Bullet extends EngineObject
278
277
  update()
279
278
  {
280
279
  // check if hit someone
281
- forEachObject(this.pos, this.size, (o)=>
280
+ engineObjectsCallback(this.pos, this.size, (o)=>
282
281
  {
283
282
  if (o.isGameObject)
284
283
  this.collideWithObject(o)
@@ -59,9 +59,9 @@ class Character extends GameObject
59
59
  if (this.dodgeTimer.active())
60
60
  {
61
61
  // update roll
62
- this.angle = this.getMirrorSign(2*PI*this.dodgeTimer.getPercent());
62
+ this.angle = this.getMirrorSign()*2*PI*this.dodgeTimer.getPercent();
63
63
  if (this.groundObject)
64
- this.velocity.x += this.getMirrorSign(.1);
64
+ this.velocity.x += this.getMirrorSign()*.1;
65
65
  }
66
66
  else
67
67
  {
@@ -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 = usingGamepad ? gamepadStick(0) :
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.js?48></script>
7
- <script src=gameObjects.js?48></script>
8
- <script src=gamePlayer.js?48></script>
9
- <script src=gameEffects.js?48></script>
10
- <script src=gameLevel.js?48></script>
11
- <script src=game.js?48></script>
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>
@@ -6,7 +6,6 @@
6
6
 
7
7
  'use strict';
8
8
 
9
- glOverlay = !isChrome; // fix slow rendering when not chrome
10
9
  pixelated = 0; // do not use pixelated rendering
11
10
 
12
11
  const fallTime = .2;
@@ -43,7 +42,7 @@ const setTile = (pos, data) => level[pos.x + pos.y * levelSize.x] = data;
43
42
  function gameInit()
44
43
  {
45
44
  // setup canvas
46
- fixedWidth = 1920, fixedHeight = 1080; // 1080p
45
+ fixedSize = vec2(1920, 1080); // 1080p
47
46
  mainCanvas.style.background = backgroundColor.rgba();
48
47
 
49
48
  // load high score
@@ -3,5 +3,5 @@
3
3
  <link rel=icon type=image/png href=../../favicon.png>
4
4
  </head><body>
5
5
 
6
- <script src=../../engine/engine.all.js?48></script>
7
- <script src=game.js?48></script>
6
+ <script src=../../engine/engine.all.min.js?60></script>
7
+ <script src=game.js?60></script>
@@ -3,7 +3,7 @@
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?48></script>
6
+ <script src=../../engine/engine.all.min.js?60></script>
7
7
  <script>
8
8
 
9
9
  /*
@@ -17,9 +17,6 @@
17
17
 
18
18
  'use strict';
19
19
 
20
- // use glOverlay for faster rendering by making the glCanvas visible
21
- glOverlay = 1;
22
-
23
20
  // keep our own list of simple sprites and track fps
24
21
  let sprites, timeMS, showFPS, statsDisplay, spriteColor, spriteAdditiveColor, musicSource;
25
22
 
@@ -61,11 +58,8 @@ function gameInit()
61
58
  ///////////////////////////////////////////////////////////////////////////////
62
59
  function gameUpdate()
63
60
  {
64
- if (!musicSource && hadInput)
65
- {
66
- // play music when there is input
61
+ if (!musicSource && mouseWasPressed(0))
67
62
  musicSource = music.play();
68
- }
69
63
 
70
64
  // mouse click = change color
71
65
  if (mouseWasPressed(0) || mouseIsDown(2))
package/game.js CHANGED
@@ -4,8 +4,6 @@
4
4
 
5
5
  'use strict';
6
6
 
7
- glOverlay = !isChrome; // fix slow rendering when not chrome
8
-
9
7
  // game variables
10
8
  let particleEmiter, clickCount = 0;
11
9
 
@@ -62,7 +60,7 @@ function gameInit()
62
60
  new Color(1,1,1,0), new Color(0,0,0,0), // colorEndA, colorEndB
63
61
  2, .2, .2, .1, .05, // particleTime, sizeStart, sizeEnd, particleSpeed, particleAngleSpeed
64
62
  .99, 1, 1, PI, .05, // damping, angleDamping, gravityScale, particleCone, fadeRate,
65
- .5, 1 // randomness, collide, additive, randomColorLinear, renderOrder
63
+ .5, 1, 1 // randomness, collide, additive, randomColorLinear, renderOrder
66
64
  );
67
65
  particleEmiter.elasticity = .3;
68
66
  particleEmiter.trailScale = 2;
@@ -102,19 +100,15 @@ function gameUpdatePost()
102
100
  ///////////////////////////////////////////////////////////////////////////////
103
101
  function gameRender()
104
102
  {
105
- // draw a grey square without using webgl
106
- drawCanvas2D(cameraPos, tileCollisionSize.add(vec2(5)), 0, 0, (context)=>
107
- {
108
- context.fillStyle='#333'
109
- context.fillRect(-.5,-.5,1,1);
110
- });
103
+ // draw a grey square in the background without using webgl
104
+ drawRect(cameraPos, tileCollisionSize.add(vec2(5)), new Color(.2,.2,.2), 0, 0);
111
105
  }
112
106
 
113
107
  ///////////////////////////////////////////////////////////////////////////////
114
108
  function gameRenderPost()
115
109
  {
116
110
  // draw to overlay canvas for hud rendering
117
- const drawOverlayText = (text, x, y, size=70) =>
111
+ const drawText = (text, x, y, size=70) =>
118
112
  {
119
113
  overlayContext.textAlign = 'center';
120
114
  overlayContext.textBaseline = 'top';
@@ -124,7 +118,7 @@ function gameRenderPost()
124
118
  overlayContext.strokeText(text, x, y);
125
119
  overlayContext.fillText(text, x, y);
126
120
  }
127
- drawOverlayText('Hello World', overlayCanvas.width/2, 40);
121
+ drawText('Hello World', overlayCanvas.width/2, 40);
128
122
  }
129
123
 
130
124
  ///////////////////////////////////////////////////////////////////////////////