littlejsengine 1.9.6 → 1.9.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/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
 
@@ -123,6 +123,15 @@ declare module "littlejsengine" {
123
123
  * @param {Boolean} [fill]
124
124
  * @memberof Debug */
125
125
  export function debugRect(pos: Vector2, size?: Vector2, color?: string, time?: number, angle?: number, fill?: boolean): void;
126
+ /** Draw a debug poly in world space
127
+ * @param {Vector2} pos
128
+ * @param {Array} points
129
+ * @param {String} [color]
130
+ * @param {Number} [time]
131
+ * @param {Number} [angle]
132
+ * @param {Boolean} [fill]
133
+ * @memberof Debug */
134
+ export function debugPoly(pos: Vector2, points: any[], color?: string, time?: number, angle?: number, fill?: boolean): void;
126
135
  /** Draw a debug circle in world space
127
136
  * @param {Vector2} pos
128
137
  * @param {Number} [radius]
@@ -146,14 +155,14 @@ declare module "littlejsengine" {
146
155
  * @param {Number} [time]
147
156
  * @memberof Debug */
148
157
  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
158
+ /** Draw a debug combined axis aligned bounding box in world space
150
159
  * @param {Vector2} pA - position A
151
160
  * @param {Vector2} sA - size A
152
161
  * @param {Vector2} pB - position B
153
162
  * @param {Vector2} sB - size B
154
163
  * @param {String} [color]
155
164
  * @memberof Debug */
156
- export function debugAABB(pA: Vector2, sA: Vector2, pB: Vector2, sB: Vector2, color?: string): void;
165
+ export function debugOverlap(pA: Vector2, sA: Vector2, pB: Vector2, sB: Vector2, color?: string): void;
157
166
  /** Draw a debug axis aligned bounding box in world space
158
167
  * @param {String} text
159
168
  * @param {Vector2} pos
@@ -173,6 +182,17 @@ declare module "littlejsengine" {
173
182
  * @param {String} [type]
174
183
  * @memberof Debug */
175
184
  export function debugSaveCanvas(canvas: HTMLCanvasElement, filename?: string, type?: string): void;
185
+ /** Save a text file to disk
186
+ * @param {String} text
187
+ * @param {String} [filename]
188
+ * @param {String} [type]
189
+ * @memberof Debug */
190
+ export function debugSaveText(text: string, filename?: string, type?: string): void;
191
+ /** Save a data url to disk
192
+ * @param {String} dataURL
193
+ * @param {String} filename
194
+ * @memberof Debug */
195
+ export function debugSaveDataURL(dataURL: string, filename: string): void;
176
196
  /**
177
197
  * LittleJS Engine Settings
178
198
  * - All settings for the engine are here
@@ -190,7 +210,7 @@ declare module "littlejsengine" {
190
210
  export let cameraScale: number;
191
211
  /** The max size of the canvas, centered if window is larger
192
212
  * @type {Vector2}
193
- * @default Vector2(1920,1200)
213
+ * @default Vector2(1920,1080)
194
214
  * @memberof Settings */
195
215
  export let canvasMaxSize: Vector2;
196
216
  /** Fixed size of the canvas, if enabled canvas size never changes
@@ -731,6 +751,11 @@ declare module "littlejsengine" {
731
751
  x: number;
732
752
  /** @property {Number} - Y axis location */
733
753
  y: number;
754
+ /** Sets values of this vector and returns self
755
+ * @param {Number} [x] - X axis location
756
+ * @param {Number} [y] - Y axis location
757
+ * @return {Vector2} */
758
+ set(x?: number, y?: number): Vector2;
734
759
  /** Returns a new vector that is a copy of this
735
760
  * @return {Vector2} */
736
761
  copy(): Vector2;
@@ -850,6 +875,13 @@ declare module "littlejsengine" {
850
875
  b: number;
851
876
  /** @property {Number} - Alpha */
852
877
  a: number;
878
+ /** Sets values of this color and returns self
879
+ * @param {Number} [r] - red
880
+ * @param {Number} [g] - green
881
+ * @param {Number} [b] - blue
882
+ * @param {Number} [a] - alpha
883
+ * @return {Color} */
884
+ set(r?: number, g?: number, b?: number, a?: number): Color;
853
885
  /** Returns a new color that is a copy of this
854
886
  * @return {Color} */
855
887
  copy(): Color;
@@ -897,7 +929,7 @@ declare module "littlejsengine" {
897
929
  * @param {Number} [alphaAmount]
898
930
  * @return {Color} */
899
931
  mutate(amount?: number, alphaAmount?: number): Color;
900
- /** Returns this color expressed as a rgb color code
932
+ /** Returns this color expressed as a hex color code
901
933
  * @param {Boolean} [useAlpha] - if alpha should be included in result
902
934
  * @return {String} */
903
935
  toString(useAlpha?: boolean): string;
@@ -1224,6 +1256,10 @@ declare module "littlejsengine" {
1224
1256
  /** Toggle fullsceen mode
1225
1257
  * @memberof Draw */
1226
1258
  export function toggleFullscreen(): void;
1259
+ /** Get the camera's visible area in world space
1260
+ * @return {Vector2}
1261
+ * @memberof Draw */
1262
+ export function getCameraSize(): Vector2;
1227
1263
  /**
1228
1264
  * LittleJS WebGL Interface
1229
1265
  * - All webgl used by the engine is wrapped up here
@@ -1265,11 +1301,6 @@ declare module "littlejsengine" {
1265
1301
  * @return {WebGLTexture}
1266
1302
  * @memberof WebGL */
1267
1303
  export function glCreateTexture(image: HTMLImageElement): WebGLTexture;
1268
- /** Set up a post processing shader
1269
- * @param {String} shaderCode
1270
- * @param {Boolean} includeOverlay
1271
- * @memberof WebGL */
1272
- export function glInitPostProcess(shaderCode: string, includeOverlay?: boolean): void;
1273
1304
  /**
1274
1305
  * LittleJS Input System
1275
1306
  * - Tracks keyboard down, pressed, and released
@@ -1381,16 +1412,6 @@ declare module "littlejsengine" {
1381
1412
  /** True if a touch device has been detected
1382
1413
  * @memberof Input */
1383
1414
  export const isTouchDevice: boolean;
1384
- /**
1385
- * LittleJS Audio System
1386
- * - <a href=https://killedbyapixel.github.io/ZzFX/>ZzFX Sound Effects</a> - ZzFX Sound Effect Generator
1387
- * - <a href=https://keithclark.github.io/ZzFXM/>ZzFXM Music</a> - ZzFXM Music System
1388
- * - Caches sounds and music for fast playback
1389
- * - Can attenuate and apply stereo panning to sounds
1390
- * - Ability to play mp3, ogg, and wave files
1391
- * - Speech synthesis functions
1392
- * @namespace Audio
1393
- */
1394
1415
  /**
1395
1416
  * Sound Object - Stores a sound for later use and can be played positionally
1396
1417
  *
@@ -1426,7 +1447,12 @@ declare module "littlejsengine" {
1426
1447
  * @return {AudioBufferSourceNode} - The audio source node
1427
1448
  */
1428
1449
  play(pos?: Vector2, volume?: number, pitch?: number, randomnessScale?: number, loop?: boolean): AudioBufferSourceNode;
1450
+ gainNode: GainNode;
1429
1451
  source: AudioBufferSourceNode;
1452
+ /** Set the sound volume
1453
+ * @param {Number} [volume] - How much to scale volume by
1454
+ */
1455
+ setVolume(volume?: number): void;
1430
1456
  /** Stop the last instance of this sound that was played */
1431
1457
  stop(): void;
1432
1458
  /** Get source of most recent instance of this sound that was played
@@ -1465,9 +1491,9 @@ declare module "littlejsengine" {
1465
1491
  * @param {Number} [randomness] - How much to randomize frequency each time sound plays
1466
1492
  * @param {Number} [range=soundDefaultRange] - World space max range of sound, will not play if camera is farther away
1467
1493
  * @param {Number} [taper=soundDefaultTaper] - At what percentage of range should it start tapering off
1494
+ * @param {Function} [onloadCallback] - callback function to call when sound is loaded
1468
1495
  */
1469
- constructor(filename: string, randomness?: number, range?: number, taper?: number);
1470
- randomness: number;
1496
+ constructor(filename: string, randomness?: number, range?: number, taper?: number, onloadCallback?: Function);
1471
1497
  }
1472
1498
  /**
1473
1499
  * Music Object - Stores a zzfx music track for later use
@@ -1516,9 +1542,9 @@ declare module "littlejsengine" {
1516
1542
  * @param {String} filename - Location of sound file to play
1517
1543
  * @param {Number} [volume] - How much to scale volume by
1518
1544
  * @param {Boolean} [loop] - True if the music should loop
1519
- * @return {HTMLAudioElement} - The audio element for this sound
1545
+ * @return {SoundWave} - The sound object for this file
1520
1546
  * @memberof Audio */
1521
- export function playAudioFile(filename: string, volume?: number, loop?: boolean): HTMLAudioElement;
1547
+ export function playAudioFile(filename: string, volume?: number, loop?: boolean): SoundWave;
1522
1548
  /** Speak text with passed in settings
1523
1549
  * @param {String} text - The text to speak
1524
1550
  * @param {String} [language] - The language/accent to use (examples: en, it, ru, ja, zh)
@@ -1537,20 +1563,31 @@ declare module "littlejsengine" {
1537
1563
  * @return {Number} - The frequency of the note
1538
1564
  * @memberof Audio */
1539
1565
  export function getNoteFrequency(semitoneOffset: number, rootFrequency?: number): number;
1566
+ /**
1567
+ * LittleJS Audio System
1568
+ * - <a href=https://killedbyapixel.github.io/ZzFX/>ZzFX Sound Effects</a> - ZzFX Sound Effect Generator
1569
+ * - <a href=https://keithclark.github.io/ZzFXM/>ZzFXM Music</a> - ZzFXM Music System
1570
+ * - Caches sounds and music for fast playback
1571
+ * - Can attenuate and apply stereo panning to sounds
1572
+ * - Ability to play mp3, ogg, and wave files
1573
+ * - Speech synthesis functions
1574
+ * @namespace Audio
1575
+ */
1540
1576
  /** Audio context used by the engine
1541
1577
  * @type {AudioContext}
1542
1578
  * @memberof Audio */
1543
1579
  export let audioContext: AudioContext;
1544
1580
  /** Play cached audio samples with given settings
1545
- * @param {Array} sampleChannels - Array of arrays of samples to play (for stereo playback)
1546
- * @param {Number} [volume] - How much to scale volume by
1547
- * @param {Number} [rate] - The playback rate to use
1548
- * @param {Number} [pan] - How much to apply stereo panning
1549
- * @param {Boolean} [loop] - True if the sound should loop when it reaches the end
1550
- * @param {Number} [sampleRate=44100] - Sample rate for the sound
1581
+ * @param {Array} sampleChannels - Array of arrays of samples to play (for stereo playback)
1582
+ * @param {Number} [volume] - How much to scale volume by
1583
+ * @param {Number} [rate] - The playback rate to use
1584
+ * @param {Number} [pan] - How much to apply stereo panning
1585
+ * @param {Boolean} [loop] - True if the sound should loop when it reaches the end
1586
+ * @param {Number} [sampleRate=44100] - Sample rate for the sound
1587
+ * @param {GainNode} [gainNode] - Optional gain node for volume control while playing
1551
1588
  * @return {AudioBufferSourceNode} - The audio node of the sound played
1552
1589
  * @memberof Audio */
1553
- export function playSamples(sampleChannels: any[], volume?: number, rate?: number, pan?: number, loop?: boolean, sampleRate?: number): AudioBufferSourceNode;
1590
+ export function playSamples(sampleChannels: any[], volume?: number, rate?: number, pan?: number, loop?: boolean, sampleRate?: number, gainNode?: GainNode): AudioBufferSourceNode;
1554
1591
  /** Generate and play a ZzFX sound
1555
1592
  *
1556
1593
  * <a href=https://killedbyapixel.github.io/ZzFX/>Create sounds using the ZzFX Sound Designer.</a>
@@ -1634,6 +1671,8 @@ declare module "littlejsengine" {
1634
1671
  spawnTime: number;
1635
1672
  /** @property {Array} - List of children of this object */
1636
1673
  children: any[];
1674
+ /** @property {Boolean} - Limit object speed using linear or circular math */
1675
+ clampSpeedLinear: boolean;
1637
1676
  /** @property {EngineObject} - Parent of object if in local space */
1638
1677
  parent: any;
1639
1678
  /** @property {Vector2} - Local position if child */
@@ -1658,6 +1697,18 @@ declare module "littlejsengine" {
1658
1697
  /** Destroy this object, destroy it's children, detach it's parent, and mark it for removal */
1659
1698
  destroy(): void;
1660
1699
  destroyed: number;
1700
+ /** Convert from local space to world space
1701
+ * @param {Vector2} pos - local space point */
1702
+ localToWorld(pos: Vector2): Vector2;
1703
+ /** Convert from world space to local space
1704
+ * @param {Vector2} pos - world space point */
1705
+ worldToLocal(pos: Vector2): Vector2;
1706
+ /** Convert from local space to world space for a vector (rotation only)
1707
+ * @param {Vector2} vec - local space vector */
1708
+ localToWorldVector(vec: Vector2): Vector2;
1709
+ /** Convert from world space to local space for a vector (rotation only)
1710
+ * @param {Vector2} vec - world space vector */
1711
+ worldToLocalVector(vec: Vector2): Vector2;
1661
1712
  /** Called to check if a tile collision should be resolved
1662
1713
  * @param {Number} tileData - the value of the tile at the position
1663
1714
  * @param {Vector2} pos - tile where the collision occured
@@ -1697,6 +1748,8 @@ declare module "littlejsengine" {
1697
1748
  /** Returns string containg info about this object for debugging
1698
1749
  * @return {String} */
1699
1750
  toString(): string;
1751
+ /** Render debug info for this object */
1752
+ renderDebugInfo(): void;
1700
1753
  }
1701
1754
  /**
1702
1755
  * LittleJS Tile Layer System
@@ -2005,9 +2058,9 @@ declare module "littlejsengine" {
2005
2058
  * @namespace Medals
2006
2059
  */
2007
2060
  /** List of all medals
2008
- * @type {Array}
2061
+ * @type {Object}
2009
2062
  * @memberof Medals */
2010
- export const medals: any[];
2063
+ export const medals: any;
2011
2064
  /** Set to stop medals from being unlockable (like if cheats are enabled)
2012
2065
  * @type {Boolean}
2013
2066
  * @default
@@ -2019,12 +2072,6 @@ declare module "littlejsengine" {
2019
2072
  * @param {String} saveName
2020
2073
  * @memberof Medals */
2021
2074
  export function medalsInit(saveName: string): void;
2022
- /** This can used to enable Newgrounds functionality
2023
- * @param {Number} app_id - The newgrounds App ID
2024
- * @param {String} [cipher] - The encryption Key (AES-128/Base64)
2025
- * @param {Object} [cryptoJS] - An instance of CryptoJS, if there is a cipher
2026
- * @memberof Medals */
2027
- export function newgroundsInit(app_id: number, cipher?: string, cryptoJS?: any): void;
2028
2075
  /**
2029
2076
  * Medal - Tracks an unlockable medal
2030
2077
  * @example
@@ -2065,50 +2112,4 @@ declare module "littlejsengine" {
2065
2112
  renderIcon(pos: Vector2, size?: number): void;
2066
2113
  storageKey(): string;
2067
2114
  }
2068
- /**
2069
- * Newgrounds API wrapper object
2070
- * @example
2071
- * // create a newgrounds object, replace the app id with your own
2072
- * const app_id = '53123:1ZuSTQ9l';
2073
- * newgrounds = new Newgrounds(app_id);
2074
- */
2075
- export class Newgrounds {
2076
- /** Create a newgrounds object
2077
- * @param {Number} app_id - The newgrounds App ID
2078
- * @param {String} [cipher] - The encryption Key (AES-128/Base64)
2079
- * @param {Object} [cryptoJS] - An instance of CryptoJS, if there is a cipher */
2080
- constructor(app_id: number, cipher?: string, cryptoJS?: any);
2081
- app_id: number;
2082
- cipher: string;
2083
- cryptoJS: any;
2084
- host: string;
2085
- session_id: string;
2086
- medals: any;
2087
- scoreboards: any;
2088
- /** Send message to unlock a medal by id
2089
- * @param {Number} id - The medal id */
2090
- unlockMedal(id: number): any;
2091
- /** Send message to post score
2092
- * @param {Number} id - The scoreboard id
2093
- * @param {Number} value - The score value */
2094
- postScore(id: number, value: number): any;
2095
- /** Get scores from a scoreboard
2096
- * @param {Number} id - The scoreboard id
2097
- * @param {String} [user] - A user's id or name
2098
- * @param {Number} [social] - If true, only social scores will be loaded
2099
- * @param {Number} [skip] - Number of scores to skip before start
2100
- * @param {Number} [limit] - Number of scores to include in the list
2101
- * @return {Object} - The response JSON object
2102
- */
2103
- getScores(id: number, user?: string, social?: number, skip?: number, limit?: number): any;
2104
- /** Send message to log a view */
2105
- logView(): any;
2106
- /** Send a message to call a component of the Newgrounds API
2107
- * @param {String} component - Name of the component
2108
- * @param {Object} [parameters] - Parameters to use for call
2109
- * @param {Boolean} [async] - If true, don't wait for response before continuing
2110
- * @return {Object} - The response JSON object
2111
- */
2112
- call(component: string, parameters?: any, async?: boolean): any;
2113
- }
2114
2115
  }