littlejsengine 1.7.21 → 1.8.3

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 (52) hide show
  1. package/README.md +28 -55
  2. package/build/littlejs.d.ts +595 -552
  3. package/build/littlejs.esm.js +626 -535
  4. package/build/littlejs.esm.min.js +1 -1
  5. package/build/littlejs.js +542 -264
  6. package/build/littlejs.min.js +1 -1
  7. package/build/littlejs.release.js +542 -264
  8. package/examples/breakout/game.js +17 -14
  9. package/examples/breakout/gameObjects.js +29 -8
  10. package/examples/breakout/index.html +3 -3
  11. package/examples/breakoutTutorial/README.md +3 -3
  12. package/examples/breakoutTutorial/game.js +4 -4
  13. package/examples/breakoutTutorial/index.html +2 -2
  14. package/examples/electron/game.js +3 -2
  15. package/examples/electron/index.html +2 -2
  16. package/examples/empty/game.js +1 -1
  17. package/examples/favicon.png +0 -0
  18. package/examples/js13k/game.js +20 -15
  19. package/examples/js13k/index.html +14 -14
  20. package/examples/module/game.js +5 -4
  21. package/examples/module/index.html +1 -1
  22. package/examples/particles/index.html +19 -22
  23. package/examples/platformer/game.js +3 -3
  24. package/examples/platformer/gameEffects.js +21 -19
  25. package/examples/platformer/gameLevel.js +6 -6
  26. package/examples/platformer/gameObjects.js +18 -18
  27. package/examples/platformer/gamePlayer.js +4 -3
  28. package/examples/platformer/index.html +6 -6
  29. package/examples/platformer/tiles.png +0 -0
  30. package/examples/platformer/tilesLevel.png +0 -0
  31. package/examples/puzzle/game.js +10 -8
  32. package/examples/puzzle/index.html +2 -2
  33. package/examples/screenshot.jpg +0 -0
  34. package/examples/starter/game.js +32 -21
  35. package/examples/starter/index.html +13 -13
  36. package/examples/starter/tiles.png +0 -0
  37. package/examples/stress/index.html +4 -4
  38. package/examples/typescript/game.js +4 -3
  39. package/examples/typescript/game.ts +5 -4
  40. package/examples/typescript/index.html +1 -1
  41. package/package.json +2 -1
  42. package/src/engine.js +59 -52
  43. package/src/engineAudio.js +2 -1
  44. package/src/engineDraw.js +171 -55
  45. package/src/engineExport.js +84 -271
  46. package/src/engineMedals.js +13 -45
  47. package/src/engineObject.js +13 -13
  48. package/src/engineParticles.js +17 -17
  49. package/src/engineSettings.js +195 -2
  50. package/src/engineTileLayer.js +23 -22
  51. package/src/engineUtilities.js +6 -6
  52. package/src/engineWebGL.js +43 -50
@@ -1,200 +1,79 @@
1
1
  /**
2
2
  * LittleJS Module Export
3
- * - Export engine as a module with functions where necessary
3
+ * - Export engine as a module
4
4
  */
5
5
 
6
- /** Set position of camera in world space
7
- * @param {Vector2} pos
8
- * @memberof Settings */
9
- function setCameraPos(pos) { cameraPos = pos; }
10
-
11
- /** Set scale of camera in world space
12
- * @param {Number} scale
13
- * @memberof Settings */
14
- function setCameraScale(scale) { cameraScale = scale; }
15
-
16
- /** Set max size of the canvas
17
- * @param {Vector2} size
18
- * @memberof Settings */
19
- function setCanvasMaxSize(size) { canvasMaxSize = size; }
20
-
21
- /** Set fixed size of the canvas
22
- * @param {Vector2} size
23
- * @memberof Settings */
24
- function setCanvasFixedSize(size) { canvasFixedSize = size; }
25
-
26
- /** Disables anti aliasing for pixel art if true
27
- * @param {Boolean} pixelated
28
- * @memberof Settings */
29
- function setCanvasPixelated(pixelated) { canvasPixelated = pixelated; }
30
-
31
- /** Set default font used for text rendering
32
- * @param {String} font
33
- * @memberof Settings */
34
- function setFontDefault(font) { fontDefault = font; }
35
-
36
- /** Set if webgl rendering is enabled
37
- * @param {Boolean} enable
38
- * @memberof Settings */
39
- function setGlEnable(enable) { glEnable = enable; }
40
-
41
- /** Set to not composite the WebGL canvas
42
- * @param {Boolean} overlay
43
- * @memberof Settings */
44
- function setGlOverlay(overlay) { glOverlay = overlay; }
45
-
46
- /** Set default size of tiles in pixels
47
- * @param {Vector2} size
48
- * @memberof Settings */
49
- function setTileSizeDefault(size) { tileSizeDefault = size; }
50
-
51
- /** Set to prevent tile bleeding from neighbors in pixels
52
- * @param {Number} scale
53
- * @memberof Settings */
54
- function setTileFixBleedScale(scale) { tileFixBleedScale = scale; }
55
-
56
- /** Set if collisions between objects are enabled
57
- * @param {Boolean} enable
58
- * @memberof Settings */
59
- function setEnablePhysicsSolver(enable) { enablePhysicsSolver = enable; }
60
-
61
- /** Set default object mass for collison calcuations
62
- * @param {Number} mass
63
- * @memberof Settings */
64
- function setObjectDefaultMass(mass) { objectDefaultMass = mass; }
65
-
66
- /** Set how much to slow velocity by each frame
67
- * @param {Number} damping
68
- * @memberof Settings */
69
- function setObjectDefaultDamping(damp) { objectDefaultDamping = damp; }
70
-
71
- /** Set how much to slow angular velocity each frame
72
- * @param {Number} damping
73
- * @memberof Settings */
74
- function setObjectDefaultAngleDamping(damp) { objectDefaultAngleDamping = damp; }
75
-
76
- /** Set how much to bounce when a collision occur
77
- * @param {Number} elasticity
78
- * @memberof Settings */
79
- function setObjectDefaultElasticity(elasticity) { objectDefaultElasticity = elasticity; }
80
-
81
- /** Set how much to slow when touching
82
- * @param {Number} friction
83
- * @memberof Settings */
84
- function setObjectDefaultFriction(friction) { objectDefaultFriction = friction; }
85
-
86
- /** Set max speed to avoid fast objects missing collisions
87
- * @param {Number} speed
88
- * @memberof Settings */
89
- function setObjectMaxSpeed(speed) { objectMaxSpeed = speed; }
90
-
91
- /** Set how much gravity to apply to objects along the Y axis
92
- * @param {Number} gravity
93
- * @memberof Settings */
94
- function setGravity(g) { gravity = g; }
95
-
96
- /** Set to scales emit rate of particles
97
- * @param {Number} scale
98
- * @memberof Settings */
99
- function setParticleEmitRateScale(scale) { particleEmitRateScale = scale; }
100
-
101
- /** Set if gamepads are enabled
102
- * @param {Boolean} enable
103
- * @memberof Settings */
104
- function setGamepadsEnable(enable) { gamepadsEnable = enable; }
105
-
106
- /** Set if the dpad input is also routed to the left analog stick
107
- * @param {Boolean} enable
108
- * @memberof Settings */
109
- function setGamepadDirectionEmulateStick(enable) { gamepadDirectionEmulateStick = enable; }
110
-
111
- /** Set if true the WASD keys are also routed to the direction keys
112
- * @param {Boolean} enable
113
- * @memberof Settings */
114
- function setInputWASDEmulateDirection(enable) { inputWASDEmulateDirection = enable; }
115
-
116
- /** Set if touch gamepad should appear on mobile devices
117
- * @param {Boolean} enable
118
- * @memberof Settings */
119
- function setTouchGamepadEnable(enable) { touchGamepadEnable = enable; }
120
-
121
- /** Set if touch gamepad should be analog stick or 8 way dpad
122
- * @param {Boolean} analog
123
- * @memberof Settings */
124
- function setTouchGamepadAnalog(analog) { touchGamepadAnalog = analog; }
125
-
126
- /** Set size of virutal gamepad for touch devices in pixels
127
- * @param {Number} size
128
- * @memberof Settings */
129
- function setTouchGamepadSize(size) { touchGamepadSize = size; }
130
-
131
- /** Set transparency of touch gamepad overlay
132
- * @param {Number} alpha
133
- * @memberof Settings */
134
- function setTouchGamepadAlpha(alpha) { touchGamepadAlpha = alpha; }
135
-
136
- /** Set to allow vibration hardware if it exists
137
- * @param {Boolean} enable
138
- * @memberof Settings */
139
- function setVibrateEnable(enable) { vibrateEnable = enable; }
140
-
141
- /** Set to disable all audio code
142
- * @param {Boolean} enable
143
- * @memberof Settings */
144
- function setSoundEnable(enable) { soundEnable = enable; }
145
-
146
- /** Set volume scale to apply to all sound, music and speech
147
- * @param {Number} volume
148
- * @memberof Settings */
149
- function setSoundVolume(volume) { soundVolume = volume; }
150
-
151
- /** Set default range where sound no longer plays
152
- * @param {Number} range
153
- * @memberof Settings */
154
- function setSoundDefaultRange(range) { soundDefaultRange = range; }
155
-
156
- /** Set default range percent to start tapering off sound
157
- * @param {Number} taper
158
- * @memberof Settings */
159
- function setSoundDefaultTaper(taper) { soundDefaultTaper = taper; }
160
-
161
- /** Set how long to show medals for in seconds
162
- * @param {Number} time
163
- * @memberof Settings */
164
- function setMedalDisplayTime(time) { medalDisplayTime = time; }
165
-
166
- /** Set how quickly to slide on/off medals in seconds
167
- * @param {Number} time
168
- * @memberof Settings */
169
- function setMedalDisplaySlideTime(time) { medalDisplaySlideTime = time; }
170
-
171
- /** Set size of medal display
172
- * @param {Vector2} size
173
- * @memberof Settings */
174
- function setMedalDisplaySize(size) { medalDisplaySize = size; }
175
-
176
- /** Set size of icon in medal display
177
- * @param {Number} size
178
- * @memberof Settings */
179
- function setMedalDisplayIconSize(size) { medalDisplayIconSize = size; }
6
+ export {
180
7
 
181
- /** Set to stop medals from being unlockable
182
- * @param {Boolean} preventUnlock
183
- * @memberof Settings */
184
- function setMedalsPreventUnlock(preventUnlock) { medalsPreventUnlock = preventUnlock; }
8
+ // Engine
9
+ engineName,
10
+ engineVersion,
11
+ frameRate,
12
+ timeDelta,
13
+ engineObjects,
14
+ frame,
15
+ time,
16
+ timeReal,
17
+ paused,
18
+ setPaused,
19
+ engineInit,
20
+ engineObjectsUpdate,
21
+ engineObjectsDestroy,
22
+ engineObjectsCallback,
23
+
24
+ // Globals
25
+ debug,
26
+ showWatermark,
185
27
 
186
- /** Set if watermark with FPS should be shown
187
- * @param {Boolean} show
188
- * @memberof Debug */
189
- function setShowWatermark(show) { showWatermark = show; }
28
+ // Debug
29
+ ASSERT,
30
+ debugRect,
31
+ debugCircle,
32
+ debugPoint,
33
+ debugLine,
34
+ debugAABB,
35
+ debugText,
36
+ debugClear,
37
+ debugSaveCanvas,
190
38
 
191
- /** Set key code used to toggle debug mode, Esc by default
192
- * @param {Number} key
193
- * @memberof Debug */
194
- function setDebugKey(key) { debugKey = key; }
39
+ // Settings
40
+ cameraPos,
41
+ cameraScale,
42
+ canvasMaxSize,
43
+ canvasFixedSize,
44
+ canvasPixelated,
45
+ fontDefault,
46
+ tileSizeDefault,
47
+ tileFixBleedScale,
48
+ enablePhysicsSolver,
49
+ objectDefaultMass,
50
+ objectDefaultDamping,
51
+ objectDefaultAngleDamping,
52
+ objectDefaultElasticity,
53
+ objectDefaultFriction,
54
+ objectMaxSpeed,
55
+ gravity,
56
+ particleEmitRateScale,
57
+ glEnable,
58
+ glOverlay,
59
+ gamepadsEnable,
60
+ gamepadDirectionEmulateStick,
61
+ inputWASDEmulateDirection,
62
+ touchGamepadEnable,
63
+ touchGamepadAnalog,
64
+ touchGamepadSize,
65
+ touchGamepadAlpha,
66
+ vibrateEnable,
67
+ soundEnable,
68
+ soundVolume,
69
+ soundDefaultRange,
70
+ soundDefaultTaper,
71
+ medalDisplayTime,
72
+ medalDisplaySlideTime,
73
+ medalDisplaySize,
74
+ medalDisplayIconSize,
195
75
 
196
- export {
197
- // Setters for global variables
76
+ // Setters for globals
198
77
  setCameraPos,
199
78
  setCameraScale,
200
79
  setCanvasMaxSize,
@@ -234,58 +113,6 @@ export {
234
113
  setShowWatermark,
235
114
  setDebugKey,
236
115
 
237
- // Settings
238
- canvasMaxSize,
239
- canvasFixedSize,
240
- canvasPixelated,
241
- fontDefault,
242
- tileSizeDefault,
243
- tileFixBleedScale,
244
- enablePhysicsSolver,
245
- objectDefaultMass,
246
- objectDefaultDamping,
247
- objectDefaultAngleDamping,
248
- objectDefaultElasticity,
249
- objectDefaultFriction,
250
- objectMaxSpeed,
251
- gravity,
252
- particleEmitRateScale,
253
- cameraPos,
254
- cameraScale,
255
- glEnable,
256
- glOverlay,
257
- gamepadsEnable,
258
- gamepadDirectionEmulateStick,
259
- inputWASDEmulateDirection,
260
- touchGamepadEnable,
261
- touchGamepadAnalog,
262
- touchGamepadSize,
263
- touchGamepadAlpha,
264
- vibrateEnable,
265
- soundEnable,
266
- soundVolume,
267
- soundDefaultRange,
268
- soundDefaultTaper,
269
- medalDisplayTime,
270
- medalDisplaySlideTime,
271
- medalDisplaySize,
272
- medalDisplayIconSize,
273
-
274
- // Globals
275
- debug,
276
- showWatermark,
277
-
278
- // Debug
279
- ASSERT,
280
- debugRect,
281
- debugCircle,
282
- debugPoint,
283
- debugLine,
284
- debugAABB,
285
- debugText,
286
- debugClear,
287
- debugSaveCanvas,
288
-
289
116
  // Utilities
290
117
  PI,
291
118
  abs,
@@ -323,11 +150,11 @@ export {
323
150
  rgb,
324
151
  hsl,
325
152
 
326
- // Base
327
- EngineObject,
328
-
329
153
  // Draw
330
- tileImage,
154
+ textureInfos,
155
+ tile,
156
+ TileInfo,
157
+ TextureInfo,
331
158
  mainCanvas,
332
159
  mainContext,
333
160
  overlayCanvas,
@@ -347,6 +174,15 @@ export {
347
174
  isFullscreen,
348
175
  toggleFullscreen,
349
176
 
177
+ // WebGL
178
+ glCanvas,
179
+ glContext,
180
+ glSetTexture,
181
+ glCompileShader,
182
+ glCreateProgram,
183
+ glCreateTexture,
184
+ glInitPostProcess,
185
+
350
186
  // Input
351
187
  keyIsDown,
352
188
  keyWasPressed,
@@ -381,6 +217,9 @@ export {
381
217
  playSamples,
382
218
  zzfx,
383
219
 
220
+ // Base Object
221
+ EngineObject,
222
+
384
223
  // Tiles
385
224
  tileCollision,
386
225
  tileCollisionSize,
@@ -403,30 +242,4 @@ export {
403
242
  newgroundsInit,
404
243
  Medal,
405
244
  Newgrounds,
406
-
407
- // WebGL
408
- glCanvas,
409
- glContext,
410
- glSetBlendMode,
411
- glSetTexture,
412
- glCompileShader,
413
- glCreateProgram,
414
- glCreateTexture,
415
- glInitPostProcess,
416
-
417
- // Engine
418
- engineName,
419
- engineVersion,
420
- frameRate,
421
- timeDelta,
422
- engineObjects,
423
- frame,
424
- time,
425
- timeReal,
426
- paused,
427
- setPaused,
428
- engineInit,
429
- engineObjectsUpdate,
430
- engineObjectsDestroy,
431
- engineObjectsCallback,
432
245
  };
@@ -31,7 +31,7 @@ function medalsInit(saveName)
31
31
  }
32
32
 
33
33
  /**
34
- * Medal Object - Tracks an unlockable medal
34
+ * Medal - Tracks an unlockable medal
35
35
  * @example
36
36
  * // create a medal
37
37
  * const medal_example = new Medal(0, 'Example Medal', 'More info about the medal goes here.', '🎖️');
@@ -44,7 +44,7 @@ function medalsInit(saveName)
44
44
  */
45
45
  class Medal
46
46
  {
47
- /** Create an medal object and adds it to the list of medals
47
+ /** Create a medal object and adds it to the list of medals
48
48
  * @param {Number} id - The unique identifier of the medal
49
49
  * @param {String} name - Name of the medal
50
50
  * @param {String} [description] - Description of the medal
@@ -156,33 +156,33 @@ let newgrounds;
156
156
  /** This can used to enable Newgrounds functionality
157
157
  * @param {Number} app_id - The newgrounds App ID
158
158
  * @param {String} [cipher] - The encryption Key (AES-128/Base64)
159
+ * @param {Object} [cryptoJS] - An instance of CryptoJS, if there is a cipher
159
160
  * @memberof Medals */
160
- function newgroundsInit(app_id, cipher) { newgrounds = new Newgrounds(app_id, cipher); }
161
+ function newgroundsInit(app_id, cipher, cryptoJS)
162
+ { newgrounds = new Newgrounds(app_id, cipher, cryptoJS); }
161
163
 
162
164
  /**
163
165
  * Newgrounds API wrapper object
164
166
  * @example
165
- * // create a newgrounds object, replace the app id and cipher with your own
167
+ * // create a newgrounds object, replace the app id with your own
166
168
  * const app_id = '53123:1ZuSTQ9l';
167
- * const cipher = 'enF0vGH@Mj/FRASKL23Q==';
168
- * newgrounds = new Newgrounds(app_id, cipher);
169
+ * newgrounds = new Newgrounds(app_id);
169
170
  */
170
171
  class Newgrounds
171
172
  {
172
173
  /** Create a newgrounds object
173
174
  * @param {Number} app_id - The newgrounds App ID
174
- * @param {String} [cipher] - The encryption Key (AES-128/Base64) */
175
- constructor(app_id, cipher)
175
+ * @param {String} [cipher] - The encryption Key (AES-128/Base64)
176
+ * @param {Object} [cryptoJS] - An instance of CryptoJS, if there is a cipher */
177
+ constructor(app_id, cipher, cryptoJS)
176
178
  {
177
- ASSERT(!newgrounds && app_id);
179
+ ASSERT(!newgrounds && app_id); // can only be one newgrounds object
180
+ ASSERT(!cipher || cryptoJS); // must provide cryptojs if there is a cipher
178
181
 
179
182
  this.app_id = app_id;
180
183
  this.cipher = cipher;
184
+ this.cryptoJS = cryptoJS;
181
185
  this.host = location ? location.hostname : '';
182
-
183
- // create an instance of CryptoJS for encrypted calls
184
- if (cipher)
185
- this.cryptoJS = this.CryptoJS();
186
186
 
187
187
  // get session id from url search params
188
188
  const url = new URL(location.href);
@@ -286,36 +286,4 @@ class Newgrounds
286
286
  debugMedals && console.log(xmlHttp.responseText);
287
287
  return xmlHttp.responseText && JSON.parse(xmlHttp.responseText);
288
288
  }
289
-
290
- CryptoJS()
291
- {
292
- ///////////////////////////////////////////////////////////////////////////////
293
- // Crypto-JS - https://github.com/brix/crypto-js - MIT License
294
- //
295
- // [The MIT License (MIT)](http://opensource.org/licenses/MIT)
296
- //
297
- // Copyright (c) 2009-2013 Jeff Mott
298
- // Copyright (c) 2013-2016 Evan Vosberg
299
- //
300
- // Permission is hereby granted, free of charge, to any person obtaining a copy
301
- // of this software and associated documentation files (the "Software"), to deal
302
- // in the Software without restriction, including without limitation the rights
303
- // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
304
- // copies of the Software, and to permit persons to whom the Software is
305
- // furnished to do so, subject to the following conditions:
306
- //
307
- // The above copyright notice and this permission notice shall be included in
308
- // all copies or substantial portions of the Software.
309
- //
310
- // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
311
- // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
312
- // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
313
- // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
314
- // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
315
- // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
316
- // THE SOFTWARE.
317
- return eval(Function("[M='GBMGXz^oVYPPKKbB`agTXU|LxPc_ZBcMrZvCr~wyGfWrwk@ATqlqeTp^N?p{we}jIpEnB_sEr`l?YDkDhWhprc|Er|XETG?pTl`e}dIc[_N~}fzRycIfpW{HTolvoPB_FMe_eH~BTMx]yyOhv?biWPCGc]kABencBhgERHGf{OL`Dj`c^sh@canhy[secghiyotcdOWgO{tJIE^JtdGQRNSCrwKYciZOa]Y@tcRATYKzv|sXpboHcbCBf`}SKeXPFM|RiJsSNaIb]QPc[D]J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}DRPdryEsSaKS~tIaeF[s]I~xxHVrcNe@Jjxa@jlhZueLQqHh_]twVMqG_EGuwyab{nxOF?`HCle}nBZzlTQjkLmoXbXhOtBglFoMz?eqre`HiE@vNwBulglmQjj]DB@pPkPUgA^sjOAUNdSu_`oAzar?n?eMnw{{hYmslYi[TnlJD'",...']charCodeAtUinyxpf',"for(;e<10359;c[e++]=p-=128,A=A?p-A&&A:p==34&&p)for(p=1;p<128;y=f.map((n,x)=>(U=r[n]*2+1,U=Math.log(U/(h-U)),t-=a[x]*U,U/500)),t=~-h/(1+Math.exp(t))|1,i=o%h<t,o=o%h+(i?t:h-t)*(o>>17)-!i*t,f.map((n,x)=>(U=r[n]+=(i*h/2-r[n]<<13)/((C[n]+=C[n]<5)+1/20)>>13,a[x]+=y[x]*(i-t/h))),p=p*2+i)for(f='010202103203210431053105410642065206541'.split(t=0).map((n,x)=>(U=0,[...n].map((n,x)=>(U=U*997+(c[e-n]|0)|0)),h*32-1&U*997+p+!!A*129)*12+x);o<h*32;o=o*64|M.charCodeAt(d++)&63);for(C=String.fromCharCode(...c);r=/[\0-#?@\\\\~]/.exec(C);)with(C.split(r))C=join(shift());return C")([],[],1<<17,[0,0,0,0,0,0,0,0,0,0,0,0],new Uint16Array(51e6).fill(1<<15),new Uint8Array(51e6),0,0,0,0));
318
- // end of Crypto-JS
319
- ///////////////////////////////////////////////////////////////////////////////
320
- }
321
289
  }
@@ -32,18 +32,20 @@
32
32
  class EngineObject
33
33
  {
34
34
  /** Create an engine object and adds it to the list of objects
35
- * @param {Vector2} [position=Vector2()] - World space position of the object
36
- * @param {Vector2} [size=Vector2(1,1)] - World space size of the object
37
- * @param {Number} [tileIndex=-1] - Tile to use to render object (-1 is untextured)
38
- * @param {Vector2} [tileSize=tileSizeDefault] - Size of tile in source pixels
39
- * @param {Number} [angle=0] - Angle the object is rotated by
40
- * @param {Color} [color=Color()] - Color to apply to tile when rendered
41
- * @param {Number} [renderOrder=0] - Objects sorted by renderOrder before being rendered
35
+ * @param {Vector2} [pos=Vector2()] - World space position of the object
36
+ * @param {Vector2} [size=Vector2(1,1)] - World space size of the object
37
+ * @param {TileInfo} [tileInfo] - Tile info to render object (undefined is untextured)
38
+ * @param {Number} [angle=0] - Angle the object is rotated by
39
+ * @param {Color} [color=Color()] - Color to apply to tile when rendered
40
+ * @param {Number} [renderOrder=0] - Objects sorted by renderOrder before being rendered
42
41
  */
43
- constructor(pos=vec2(), size=vec2(1), tileIndex=-1, tileSize=tileSizeDefault, angle=0, color, renderOrder=0)
42
+ constructor(pos=vec2(), size=vec2(1), tileInfo, angle=0, color, renderOrder=0)
44
43
  {
45
44
  // set passed in params
46
45
  ASSERT(isVector2(pos) && isVector2(size)); // ensure pos and size are vec2s
46
+ ASSERT(typeof tileInfo !== 'number' || !tileInfo); // prevent old style calls
47
+ ASSERT(!(renderOrder instanceof Color)); // prevent old style calls
48
+ // to fix old calls, replace with tile(tileIndex, tileSize)
47
49
 
48
50
  /** @property {Vector2} - World space position of the object */
49
51
  this.pos = pos.copy();
@@ -51,10 +53,8 @@ class EngineObject
51
53
  this.size = size;
52
54
  /** @property {Vector2} - Size of object used for drawing, uses size if not set */
53
55
  this.drawSize;
54
- /** @property {Number} - Tile to use to render object (-1 is untextured) */
55
- this.tileIndex = tileIndex;
56
- /** @property {Vector2} - Size of tile in source pixels */
57
- this.tileSize = tileSize;
56
+ /** @property {TileInfo} - Tile info to render object (undefined is untextured) */
57
+ this.tileInfo = tileInfo;
58
58
  /** @property {Number} - Angle to rotate the object */
59
59
  this.angle = angle;
60
60
  /** @property {Color} - Color to apply when rendered */
@@ -270,7 +270,7 @@ class EngineObject
270
270
  render()
271
271
  {
272
272
  // default object render
273
- drawTile(this.pos, this.drawSize || this.size, this.tileIndex, this.tileSize, this.color, this.angle, this.mirror, this.additiveColor);
273
+ drawTile(this.pos, this.drawSize || this.size, this.tileInfo, this.color, this.angle, this.mirror, this.additiveColor);
274
274
  }
275
275
 
276
276
  /** Destroy this object, destroy it's children, detach it's parent, and mark it for removal */
@@ -13,7 +13,7 @@
13
13
  * let particleEmiter = new ParticleEmitter
14
14
  * (
15
15
  * pos, 0, 1, 0, 500, PI, // pos, angle, emitSize, emitTime, emitRate, emiteCone
16
- * 0, vec2(16), // tileIndex, tileSize
16
+ * tile(0, 16), // tileInfo
17
17
  * new Color(1,1,1), new Color(0,0,0), // colorStartA, colorStartB
18
18
  * new Color(1,1,1,0), new Color(0,0,0,0), // colorEndA, colorEndB
19
19
  * 2, .2, .2, .1, .05, // particleTime, sizeStart, sizeEnd, particleSpeed, particleAngleSpeed
@@ -30,8 +30,7 @@ class ParticleEmitter extends EngineObject
30
30
  * @param {Number} [emitTime=0] - How long to stay alive (0 is forever)
31
31
  * @param {Number} [emitRate=100] - How many particles per second to spawn, does not emit if 0
32
32
  * @param {Number} [emitConeAngle=PI] - Local angle to apply velocity to particles from emitter
33
- * @param {Number} [tileIndex=-1] - Index into tile sheet, if <0 no texture is applied
34
- * @param {Vector2} [tileSize=tileSizeDefault] - Tile size for particles
33
+ * @param {TileInfo} [tileInfo] - Tile info to render particles (undefined is untextured)
35
34
  * @param {Color} [colorStartA=Color()] - Color at start of life 1, randomized between start colors
36
35
  * @param {Color} [colorStartB=Color()] - Color at start of life 2, randomized between start colors
37
36
  * @param {Color} [colorEndA=Color(1,1,1,0)] - Color at end of life 1, randomized between end colors
@@ -61,8 +60,7 @@ class ParticleEmitter extends EngineObject
61
60
  emitTime = 0,
62
61
  emitRate = 100,
63
62
  emitConeAngle = PI,
64
- tileIndex = -1,
65
- tileSize = tileSizeDefault,
63
+ tileInfo,
66
64
  colorStartA = new Color,
67
65
  colorStartB = new Color,
68
66
  colorEndA = new Color(1,1,1,0),
@@ -85,7 +83,7 @@ class ParticleEmitter extends EngineObject
85
83
  localSpace
86
84
  )
87
85
  {
88
- super(pos, vec2(), tileIndex, tileSize, angle, undefined, renderOrder);
86
+ super(pos, vec2(), tileInfo, angle, undefined, renderOrder);
89
87
 
90
88
  // emitter settings
91
89
  /** @property {Number} - World space size of the emitter (float for circle diameter, vec2 for rect) */
@@ -184,7 +182,7 @@ class ParticleEmitter extends EngineObject
184
182
  angle += this.angle;
185
183
  }
186
184
 
187
- const particle = new Particle(pos, this.tileIndex, this.tileSize, angle);
185
+ const particle = new Particle(pos, this.tileInfo, this.tileSize, angle);
188
186
 
189
187
  // randomness scales each paremeter by a percentage
190
188
  const randomness = this.randomness;
@@ -244,12 +242,11 @@ class Particle extends EngineObject
244
242
  /**
245
243
  * Create a particle with the given settings
246
244
  * @param {Vector2} position - World space position of the particle
247
- * @param {Number} [tileIndex=-1] - Tile to use to render, untextured if -1
248
- * @param {Vector2} [tileSize=tileSizeDefault] - Size of tile in source pixels
245
+ * @param {TileInfo} [tileInfo] - Tile info to render particles (undefined is untextured)
249
246
  * @param {Number} [angle=0] - Angle to rotate the particle
250
247
  */
251
- constructor(pos, tileIndex, tileSize, angle)
252
- { super(pos, vec2(), tileIndex, tileSize, angle); }
248
+ constructor(pos, tileInfo, angle)
249
+ { super(pos, vec2(), tileInfo, angle); }
253
250
 
254
251
  /** Render the particle, automatically called each frame, sorted by renderOrder */
255
252
  render()
@@ -283,14 +280,17 @@ class Particle extends EngineObject
283
280
  if (this.localSpaceEmitter)
284
281
  velocity = velocity.rotate(-this.localSpaceEmitter.angle);
285
282
  const speed = velocity.length();
286
- const direction = velocity.scale(1/speed);
287
- const trailLength = speed * this.trailScale;
288
- size.y = max(size.x, trailLength);
289
- angle = direction.angle();
290
- drawTile(pos.add(direction.multiply(vec2(0,-trailLength/2))), size, this.tileIndex, this.tileSize, color, angle, this.mirror);
283
+ if (speed)
284
+ {
285
+ const direction = velocity.scale(1/speed);
286
+ const trailLength = speed * this.trailScale;
287
+ size.y = max(size.x, trailLength);
288
+ angle = direction.angle();
289
+ drawTile(pos.add(direction.multiply(vec2(0,-trailLength/2))), size, this.tileInfo, color, angle, this.mirror);
290
+ }
291
291
  }
292
292
  else
293
- drawTile(pos, size, this.tileIndex, this.tileSize, color, angle, this.mirror);
293
+ drawTile(pos, size, this.tileInfo, color, angle, this.mirror);
294
294
  this.additive && setBlendMode();
295
295
  debugParticles && debugRect(pos, size, '#f005', 0, angle);
296
296