littlejsengine 1.9.7 → 1.9.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.
Files changed (48) hide show
  1. package/LICENSE +22 -0
  2. package/README.md +13 -8
  3. package/dist/littlejs.d.ts +75 -69
  4. package/dist/littlejs.esm.js +313 -354
  5. package/dist/littlejs.esm.min.js +1 -1
  6. package/dist/littlejs.js +307 -350
  7. package/dist/littlejs.min.js +1 -1
  8. package/dist/littlejs.release.js +244 -319
  9. package/examples/box2d/game.js +137 -0
  10. package/examples/box2d/index.html +12 -0
  11. package/examples/box2d/scenes.js +412 -0
  12. package/examples/box2d/tiles.png +0 -0
  13. package/examples/breakout/game.js +3 -3
  14. package/examples/breakout/index.html +4 -3
  15. package/examples/breakoutTutorial/index.html +2 -2
  16. package/examples/electron/build.js +1 -1
  17. package/examples/electron/index.html +2 -2
  18. package/examples/js13k/build.js +19 -1
  19. package/examples/js13k/index.html +13 -13
  20. package/examples/module/index.html +1 -1
  21. package/examples/particles/index.html +1 -1
  22. package/examples/platformer/gameEffects.js +2 -2
  23. package/examples/platformer/gameLevel.js +0 -1
  24. package/examples/platformer/index.html +8 -8
  25. package/examples/puzzle/index.html +2 -2
  26. package/examples/starter/build.js +1 -1
  27. package/examples/starter/index.html +13 -13
  28. package/examples/stress/index.html +1 -1
  29. package/examples/typescript/index.html +1 -1
  30. package/package.json +1 -1
  31. package/plugins/Box2D_v2.3.1_min.wasm.js +630 -0
  32. package/plugins/Box2D_v2.3.1_min.wasm.wasm +0 -0
  33. package/plugins/box2d.js +879 -0
  34. package/plugins/newgrounds.js +169 -0
  35. package/plugins/postProcess.js +102 -0
  36. package/src/engine.js +48 -29
  37. package/src/engineAudio.js +20 -12
  38. package/src/engineBuild.js +1 -1
  39. package/src/engineDebug.js +68 -33
  40. package/src/engineDraw.js +1 -1
  41. package/src/engineExport.js +6 -4
  42. package/src/engineInput.js +7 -4
  43. package/src/engineMedals.js +40 -171
  44. package/src/engineObject.js +33 -2
  45. package/src/engineRelease.js +5 -2
  46. package/src/engineSettings.js +14 -2
  47. package/src/engineUtilities.js +75 -2
  48. package/src/engineWebGL.js +1 -94
package/LICENSE CHANGED
@@ -19,3 +19,25 @@ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
19
  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
20
  OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
21
  SOFTWARE.
22
+
23
+ -------------------------------------------------------------------------------
24
+
25
+ This project uses the Box2D physics engine, which is licensed under the zlib license.
26
+ Copyright (c) 2006 Erin Catto (Box2D)
27
+ Copyright (c) 2011 The box2d.js contributors
28
+
29
+ This software is provided 'as-is', without any express or implied
30
+ warranty. In no event will the authors be held liable for any damages
31
+ arising from the use of this software.
32
+
33
+ Permission is granted to anyone to use this software for any purpose,
34
+ including commercial applications, and to alter it and redistribute it
35
+ freely, subject to the following restrictions:
36
+
37
+ 1. The origin of this software must not be misrepresented; you must not
38
+ claim that you wrote the original software. If you use this software
39
+ in a product, an acknowledgment in the product documentation would be
40
+ appreciated but is not required.
41
+ 2. Altered source versions must be plainly marked as such, and must not be
42
+ misrepresented as being the original software.
43
+ 3. This notice may not be removed or altered from any source distribution.
package/README.md CHANGED
@@ -86,14 +86,15 @@ Learn how to make a simple game from scratch with [The Breakout Tutorial.](https
86
86
 
87
87
  Join our vibrant community on [Discord](https://discord.gg/zb7hcGkyZe) to get help, share your projects, and collaborate with others!
88
88
 
89
- ## Demos
89
+ ## Examples
90
90
 
91
- These examples are for both learning and using as starter projects to create your own games.
91
+ These demos are for both learning and using as starter projects to create your own games.
92
92
 
93
93
  - [Starter Project](https://killedbyapixel.github.io/LittleJS/examples/starter/) - Clean example with only a few things to get you started
94
94
  - [Breakout](https://killedbyapixel.github.io/LittleJS/examples/breakout/) - Block breaking game with post-processing effects
95
95
  - [Puzzle Game](https://killedbyapixel.github.io/LittleJS/examples/puzzle/) - Match 3 puzzle game with HD rendering and high score tracking
96
96
  - [Platformer](https://killedbyapixel.github.io/LittleJS/examples/platformer/) - Platformer/shooter with level data from [Tiled Editor](https://github.com/mapeditor/tiled)
97
+ - [Box2D Demo](https://killedbyapixel.github.io/LittleJS/examples/box2d/) - Box2D plugin demonstration and testbed
97
98
  - [Stress Test](https://killedbyapixel.github.io/LittleJS/examples/stress/) - Max sprite/object test and music system demo
98
99
  - [Particle System Designer](https://killedbyapixel.github.io/LittleJS/examples/particles/) - Particle system editor and visualizer
99
100
 
@@ -194,16 +195,20 @@ Debug builds of LittleJS have a special menu that can be opened by pressing the
194
195
 
195
196
  Here are a few of the amazing games people made using LittleJS...
196
197
 
197
- - [Space Huggers](https://www.newgrounds.com/portal/view/819609) - Run and gun platformer with procedural levels
198
- - [Undergrowth](https://undergrowth.squidband.uk/) - An interactive music videogame for the band Squid
199
- - [Space Huggers - JS13K Edition](https://github.com/KilledByAPixel/SpaceHuggers) - Original js13k game with source code
200
- - [Isletopia](https://store.steampowered.com/app/1861260/Isletopia) - Relaxing strategy game of greenifying barren islands
198
+ - [Space Huggers](https://github.com/KilledByAPixel/SpaceHuggers) - Original js13k game with source code by [KilledByAPixel](https://frankforce.com/)
199
+ - [Undergrowth](https://undergrowth.squidband.uk/) - An interactive music videogame for the band Squid by [KilledByAPixel](https://frankforce.com/)
200
+ - [Isletopia](https://store.steampowered.com/app/1861260/Isletopia) - Relaxing strategy game of greenifying barren islands by [Gamex Studio](https://x.com/gamesgamex)
201
201
  - [Dead Again](https://js13kgames.com/entries/dead-again) - Top down survial horror by [sanojian & repsej](https://github.com/sanojian/js13k_2022)
202
202
  - [Hel's Trial](https://js13kgames.com/entries/hels-trial) - Turn based RPG by [Sebastian Dorn](https://github.com/sebadorn/js13k-2022-death)
203
203
  - [Bit Butcher](https://js13kgames.com/entries/bit-butcher) - Survival crafting game by [Deathray Games](https://github.com/deathraygames/bit-butcher)
204
204
  - [Necrotic Commander](https://js13kgames.com/entries/necrotic-commander) - Tower defense game by [Daniel Jeffery](https://github.com/d-jeffery/NecroticCommander)
205
- - [Boxing up Bamboo](https://patrickgh3.itch.io/boxing-up-bamboo) - A challenging puzzle game by [Patrick Traynor](https://cwpat.me/about)
206
- - [Samurai Sam](https://dev.js13kgames.com/2023/games/samurai-sam) - A Fruit Ninja inspired game by [John Edvard](https://reitgames.com)
205
+ - [Boxing up Bamboo](https://patrickgh3.itch.io/boxing-up-bamboo) - Challenging puzzle game by [Patrick Traynor](https://cwpat.me/about)
206
+ - [Samurai Sam](https://dev.js13kgames.com/2023/games/samurai-sam) - Fruit Ninja inspired rhythm game by [John Edvard](https://reitgames.com)
207
+ - [brrr!](https://snowfrog.itch.io/brrr) - Base defense and shooting game by [Snowfrog](https://www.snowfrog.dev/)
208
+ - [Wands of Triskaidekai](https://js13kgames.com/2024/games/wands-of-triskaidekai) - Platformer with experimental gameplay by [gregwoodsfrontier](https://github.com/gregwoodsfrontier)
209
+ - [Data Warrior: 13kb limit](https://js13kgames.com/2024/games/data-warrior-13kb-limit) - Vampire Survivors-like game by [rndD](https://github.com/rndD)
210
+ - [The Way of the Dodo](https://js13kgames.com/2024/games/the-way-of-the-dodo) - Single button platformer by [repsej](https://github.com/repsej)
211
+ - [Wendol Village](https://js13kgames.com/2024/games/wendol-village) - Warcraft-like RTS game by [sanojian](https://github.com/sanojian)
207
212
 
208
213
  ![LittleJS Logo](examples/favicon.png)
209
214
 
@@ -85,6 +85,11 @@ declare module "littlejsengine" {
85
85
  * @param {Array} [objects=engineObjects] - List of objects to check
86
86
  * @memberof Engine */
87
87
  export function engineObjectsCallback(pos?: Vector2, size?: number | Vector2, callbackFunction?: Function, objects?: any[]): void;
88
+ /** Add a new update function for a plugin
89
+ * @param {Function} [updateFunction]
90
+ * @param {Function} [renderFunction]
91
+ * @memberof Engine */
92
+ export function engineAddPlugin(updateFunction?: Function, renderFunction?: Function): void;
88
93
  /**
89
94
  * LittleJS Debug System
90
95
  * - Press Esc to show debug overlay with mouse pick
@@ -123,6 +128,15 @@ declare module "littlejsengine" {
123
128
  * @param {Boolean} [fill]
124
129
  * @memberof Debug */
125
130
  export function debugRect(pos: Vector2, size?: Vector2, color?: string, time?: number, angle?: number, fill?: boolean): void;
131
+ /** Draw a debug poly in world space
132
+ * @param {Vector2} pos
133
+ * @param {Array} points
134
+ * @param {String} [color]
135
+ * @param {Number} [time]
136
+ * @param {Number} [angle]
137
+ * @param {Boolean} [fill]
138
+ * @memberof Debug */
139
+ export function debugPoly(pos: Vector2, points: any[], color?: string, time?: number, angle?: number, fill?: boolean): void;
126
140
  /** Draw a debug circle in world space
127
141
  * @param {Vector2} pos
128
142
  * @param {Number} [radius]
@@ -146,14 +160,14 @@ declare module "littlejsengine" {
146
160
  * @param {Number} [time]
147
161
  * @memberof Debug */
148
162
  export function debugLine(posA: Vector2, posB: Vector2, color?: string, thickness?: number, time?: number): void;
149
- /** Draw a debug axis aligned bounding box in world space
163
+ /** Draw a debug combined axis aligned bounding box in world space
150
164
  * @param {Vector2} pA - position A
151
165
  * @param {Vector2} sA - size A
152
166
  * @param {Vector2} pB - position B
153
167
  * @param {Vector2} sB - size B
154
168
  * @param {String} [color]
155
169
  * @memberof Debug */
156
- export function debugAABB(pA: Vector2, sA: Vector2, pB: Vector2, sB: Vector2, color?: string): void;
170
+ export function debugOverlap(pA: Vector2, sA: Vector2, pB: Vector2, sB: Vector2, color?: string): void;
157
171
  /** Draw a debug axis aligned bounding box in world space
158
172
  * @param {String} text
159
173
  * @param {Vector2} pos
@@ -173,6 +187,17 @@ declare module "littlejsengine" {
173
187
  * @param {String} [type]
174
188
  * @memberof Debug */
175
189
  export function debugSaveCanvas(canvas: HTMLCanvasElement, filename?: string, type?: string): void;
190
+ /** Save a text file to disk
191
+ * @param {String} text
192
+ * @param {String} [filename]
193
+ * @param {String} [type]
194
+ * @memberof Debug */
195
+ export function debugSaveText(text: string, filename?: string, type?: string): void;
196
+ /** Save a data url to disk
197
+ * @param {String} dataURL
198
+ * @param {String} filename
199
+ * @memberof Debug */
200
+ export function debugSaveDataURL(dataURL: string, filename: string): void;
176
201
  /**
177
202
  * LittleJS Engine Settings
178
203
  * - All settings for the engine are here
@@ -190,7 +215,7 @@ declare module "littlejsengine" {
190
215
  export let cameraScale: number;
191
216
  /** The max size of the canvas, centered if window is larger
192
217
  * @type {Vector2}
193
- * @default Vector2(1920,1200)
218
+ * @default Vector2(1920,1080)
194
219
  * @memberof Settings */
195
220
  export let canvasMaxSize: Vector2;
196
221
  /** Fixed size of the canvas, if enabled canvas size never changes
@@ -450,6 +475,10 @@ declare module "littlejsengine" {
450
475
  * @param {Number} scale
451
476
  * @memberof Settings */
452
477
  export function setParticleEmitRateScale(scale: number): void;
478
+ /** Set if touch input is allowed
479
+ * @param {Boolean} enable
480
+ * @memberof Settings */
481
+ export function setTouchInputEnable(enable: boolean): void;
453
482
  /** Set if gamepads are enabled
454
483
  * @param {Boolean} enable
455
484
  * @memberof Settings */
@@ -731,6 +760,11 @@ declare module "littlejsengine" {
731
760
  x: number;
732
761
  /** @property {Number} - Y axis location */
733
762
  y: number;
763
+ /** Sets values of this vector and returns self
764
+ * @param {Number} [x] - X axis location
765
+ * @param {Number} [y] - Y axis location
766
+ * @return {Vector2} */
767
+ set(x?: number, y?: number): Vector2;
734
768
  /** Returns a new vector that is a copy of this
735
769
  * @return {Vector2} */
736
770
  copy(): Vector2;
@@ -850,6 +884,13 @@ declare module "littlejsengine" {
850
884
  b: number;
851
885
  /** @property {Number} - Alpha */
852
886
  a: number;
887
+ /** Sets values of this color and returns self
888
+ * @param {Number} [r] - red
889
+ * @param {Number} [g] - green
890
+ * @param {Number} [b] - blue
891
+ * @param {Number} [a] - alpha
892
+ * @return {Color} */
893
+ set(r?: number, g?: number, b?: number, a?: number): Color;
853
894
  /** Returns a new color that is a copy of this
854
895
  * @return {Color} */
855
896
  copy(): Color;
@@ -1269,16 +1310,12 @@ declare module "littlejsengine" {
1269
1310
  * @return {WebGLTexture}
1270
1311
  * @memberof WebGL */
1271
1312
  export function glCreateTexture(image: HTMLImageElement): WebGLTexture;
1272
- /** Set up a post processing shader
1273
- * @param {String} shaderCode
1274
- * @param {Boolean} includeOverlay
1275
- * @memberof WebGL */
1276
- export function glInitPostProcess(shaderCode: string, includeOverlay?: boolean): void;
1277
1313
  /**
1278
1314
  * LittleJS Input System
1279
1315
  * - Tracks keyboard down, pressed, and released
1280
1316
  * - Tracks mouse buttons, position, and wheel
1281
1317
  * - Tracks multiple analog gamepads
1318
+ * - Touch input is handled as mouse input
1282
1319
  * - Virtual gamepad for touch devices
1283
1320
  * @namespace Input
1284
1321
  */
@@ -1308,6 +1345,7 @@ declare module "littlejsengine" {
1308
1345
  * - Tracks keyboard down, pressed, and released
1309
1346
  * - Tracks mouse buttons, position, and wheel
1310
1347
  * - Tracks multiple analog gamepads
1348
+ * - Touch input is handled as mouse input
1311
1349
  * - Virtual gamepad for touch devices
1312
1350
  * @namespace Input
1313
1351
  */
@@ -1420,7 +1458,12 @@ declare module "littlejsengine" {
1420
1458
  * @return {AudioBufferSourceNode} - The audio source node
1421
1459
  */
1422
1460
  play(pos?: Vector2, volume?: number, pitch?: number, randomnessScale?: number, loop?: boolean): AudioBufferSourceNode;
1461
+ gainNode: GainNode;
1423
1462
  source: AudioBufferSourceNode;
1463
+ /** Set the sound volume
1464
+ * @param {Number} [volume] - How much to scale volume by
1465
+ */
1466
+ setVolume(volume?: number): void;
1424
1467
  /** Stop the last instance of this sound that was played */
1425
1468
  stop(): void;
1426
1469
  /** Get source of most recent instance of this sound that was played
@@ -1546,15 +1589,16 @@ declare module "littlejsengine" {
1546
1589
  * @memberof Audio */
1547
1590
  export let audioContext: AudioContext;
1548
1591
  /** Play cached audio samples with given settings
1549
- * @param {Array} sampleChannels - Array of arrays of samples to play (for stereo playback)
1550
- * @param {Number} [volume] - How much to scale volume by
1551
- * @param {Number} [rate] - The playback rate to use
1552
- * @param {Number} [pan] - How much to apply stereo panning
1553
- * @param {Boolean} [loop] - True if the sound should loop when it reaches the end
1554
- * @param {Number} [sampleRate=44100] - Sample rate for the sound
1592
+ * @param {Array} sampleChannels - Array of arrays of samples to play (for stereo playback)
1593
+ * @param {Number} [volume] - How much to scale volume by
1594
+ * @param {Number} [rate] - The playback rate to use
1595
+ * @param {Number} [pan] - How much to apply stereo panning
1596
+ * @param {Boolean} [loop] - True if the sound should loop when it reaches the end
1597
+ * @param {Number} [sampleRate=44100] - Sample rate for the sound
1598
+ * @param {GainNode} [gainNode] - Optional gain node for volume control while playing
1555
1599
  * @return {AudioBufferSourceNode} - The audio node of the sound played
1556
1600
  * @memberof Audio */
1557
- export function playSamples(sampleChannels: any[], volume?: number, rate?: number, pan?: number, loop?: boolean, sampleRate?: number): AudioBufferSourceNode;
1601
+ export function playSamples(sampleChannels: any[], volume?: number, rate?: number, pan?: number, loop?: boolean, sampleRate?: number, gainNode?: GainNode): AudioBufferSourceNode;
1558
1602
  /** Generate and play a ZzFX sound
1559
1603
  *
1560
1604
  * <a href=https://killedbyapixel.github.io/ZzFX/>Create sounds using the ZzFX Sound Designer.</a>
@@ -1664,6 +1708,18 @@ declare module "littlejsengine" {
1664
1708
  /** Destroy this object, destroy it's children, detach it's parent, and mark it for removal */
1665
1709
  destroy(): void;
1666
1710
  destroyed: number;
1711
+ /** Convert from local space to world space
1712
+ * @param {Vector2} pos - local space point */
1713
+ localToWorld(pos: Vector2): Vector2;
1714
+ /** Convert from world space to local space
1715
+ * @param {Vector2} pos - world space point */
1716
+ worldToLocal(pos: Vector2): Vector2;
1717
+ /** Convert from local space to world space for a vector (rotation only)
1718
+ * @param {Vector2} vec - local space vector */
1719
+ localToWorldVector(vec: Vector2): Vector2;
1720
+ /** Convert from world space to local space for a vector (rotation only)
1721
+ * @param {Vector2} vec - world space vector */
1722
+ worldToLocalVector(vec: Vector2): Vector2;
1667
1723
  /** Called to check if a tile collision should be resolved
1668
1724
  * @param {Number} tileData - the value of the tile at the position
1669
1725
  * @param {Vector2} pos - tile where the collision occured
@@ -1703,6 +1759,8 @@ declare module "littlejsengine" {
1703
1759
  /** Returns string containg info about this object for debugging
1704
1760
  * @return {String} */
1705
1761
  toString(): string;
1762
+ /** Render debug info for this object */
1763
+ renderDebugInfo(): void;
1706
1764
  }
1707
1765
  /**
1708
1766
  * LittleJS Tile Layer System
@@ -2011,9 +2069,9 @@ declare module "littlejsengine" {
2011
2069
  * @namespace Medals
2012
2070
  */
2013
2071
  /** List of all medals
2014
- * @type {Array}
2072
+ * @type {Object}
2015
2073
  * @memberof Medals */
2016
- export const medals: any[];
2074
+ export const medals: any;
2017
2075
  /** Set to stop medals from being unlockable (like if cheats are enabled)
2018
2076
  * @type {Boolean}
2019
2077
  * @default
@@ -2025,12 +2083,6 @@ declare module "littlejsengine" {
2025
2083
  * @param {String} saveName
2026
2084
  * @memberof Medals */
2027
2085
  export function medalsInit(saveName: string): void;
2028
- /** This can used to enable Newgrounds functionality
2029
- * @param {Number} app_id - The newgrounds App ID
2030
- * @param {String} [cipher] - The encryption Key (AES-128/Base64)
2031
- * @param {Object} [cryptoJS] - An instance of CryptoJS, if there is a cipher
2032
- * @memberof Medals */
2033
- export function newgroundsInit(app_id: number, cipher?: string, cryptoJS?: any): void;
2034
2086
  /**
2035
2087
  * Medal - Tracks an unlockable medal
2036
2088
  * @example
@@ -2071,50 +2123,4 @@ declare module "littlejsengine" {
2071
2123
  renderIcon(pos: Vector2, size?: number): void;
2072
2124
  storageKey(): string;
2073
2125
  }
2074
- /**
2075
- * Newgrounds API wrapper object
2076
- * @example
2077
- * // create a newgrounds object, replace the app id with your own
2078
- * const app_id = '53123:1ZuSTQ9l';
2079
- * newgrounds = new Newgrounds(app_id);
2080
- */
2081
- export class Newgrounds {
2082
- /** Create a newgrounds object
2083
- * @param {Number} app_id - The newgrounds App ID
2084
- * @param {String} [cipher] - The encryption Key (AES-128/Base64)
2085
- * @param {Object} [cryptoJS] - An instance of CryptoJS, if there is a cipher */
2086
- constructor(app_id: number, cipher?: string, cryptoJS?: any);
2087
- app_id: number;
2088
- cipher: string;
2089
- cryptoJS: any;
2090
- host: string;
2091
- session_id: string;
2092
- medals: any;
2093
- scoreboards: any;
2094
- /** Send message to unlock a medal by id
2095
- * @param {Number} id - The medal id */
2096
- unlockMedal(id: number): any;
2097
- /** Send message to post score
2098
- * @param {Number} id - The scoreboard id
2099
- * @param {Number} value - The score value */
2100
- postScore(id: number, value: number): any;
2101
- /** Get scores from a scoreboard
2102
- * @param {Number} id - The scoreboard id
2103
- * @param {String} [user] - A user's id or name
2104
- * @param {Number} [social] - If true, only social scores will be loaded
2105
- * @param {Number} [skip] - Number of scores to skip before start
2106
- * @param {Number} [limit] - Number of scores to include in the list
2107
- * @return {Object} - The response JSON object
2108
- */
2109
- getScores(id: number, user?: string, social?: number, skip?: number, limit?: number): any;
2110
- /** Send message to log a view */
2111
- logView(): any;
2112
- /** Send a message to call a component of the Newgrounds API
2113
- * @param {String} component - Name of the component
2114
- * @param {Object} [parameters] - Parameters to use for call
2115
- * @param {Boolean} [async] - If true, don't wait for response before continuing
2116
- * @return {Object} - The response JSON object
2117
- */
2118
- call(component: string, parameters?: any, async?: boolean): any;
2119
- }
2120
2126
  }