littlejsengine 1.11.17 → 1.12.4

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 (62) hide show
  1. package/dist/littlejs.d.ts +112 -43
  2. package/dist/littlejs.esm.js +586 -500
  3. package/dist/littlejs.esm.min.js +1 -1
  4. package/dist/littlejs.js +2993 -122
  5. package/dist/littlejs.min.js +1 -1
  6. package/dist/littlejs.release.js +2992 -119
  7. package/examples/box2d/game.js +70 -39
  8. package/examples/box2d/gameObjects.js +81 -77
  9. package/examples/box2d/index.html +2 -7
  10. package/examples/box2d/scenes.js +80 -90
  11. package/examples/breakout/game.js +63 -28
  12. package/examples/breakout/gameObjects.js +45 -47
  13. package/examples/breakout/index.html +1 -5
  14. package/examples/breakoutTutorial/game.js +36 -29
  15. package/examples/breakoutTutorial/index.html +1 -3
  16. package/examples/empty/game.js +5 -2
  17. package/examples/empty/index.html +1 -3
  18. package/examples/htmlMenu/game.js +24 -15
  19. package/examples/htmlMenu/index.html +5 -7
  20. package/examples/index.html +2 -3
  21. package/examples/module/game.js +32 -34
  22. package/examples/module/index.html +1 -1
  23. package/examples/particles/index.html +27 -22
  24. package/examples/platformer/game.js +71 -45
  25. package/examples/platformer/gameCharacter.js +42 -34
  26. package/examples/platformer/gameEffects.js +82 -75
  27. package/examples/platformer/gameLevel.js +67 -38
  28. package/examples/platformer/{gameLevelData.js → gameLevelData.json} +1 -11
  29. package/examples/platformer/gameObjects.js +70 -64
  30. package/examples/platformer/gamePlayer.js +12 -7
  31. package/examples/platformer/index.html +1 -9
  32. package/examples/puzzle/game.js +59 -40
  33. package/examples/puzzle/index.html +1 -3
  34. package/examples/shorts/base.html +2 -2
  35. package/examples/shorts/particles.js +1 -1
  36. package/examples/shorts/platformer.js +1 -1
  37. package/examples/shorts/tileLayer.js +5 -6
  38. package/examples/shorts/tiles.png +0 -0
  39. package/examples/starter/game.js +9 -12
  40. package/examples/starter/index.html +13 -13
  41. package/examples/stress/index.html +44 -44
  42. package/examples/typescript/build.js +17 -18
  43. package/examples/typescript/game.js +32 -34
  44. package/examples/typescript/game.ts +32 -34
  45. package/examples/typescript/index.html +1 -1
  46. package/examples/uiSystem/game.js +34 -31
  47. package/examples/uiSystem/index.html +1 -5
  48. package/package.json +1 -1
  49. package/plugins/box2d.js +6 -2
  50. package/plugins/pluginExport.js +1 -2
  51. package/reference.md +29 -27
  52. package/src/engine.js +1 -1
  53. package/src/engineBuild.js +13 -6
  54. package/src/engineDebug.js +1 -3
  55. package/src/engineExport.js +2 -6
  56. package/src/engineInput.js +3 -1
  57. package/src/engineObject.js +18 -14
  58. package/src/engineSettings.js +6 -6
  59. package/src/engineTileLayer.js +179 -96
  60. package/examples/typescript/build/dist/littlejs.esm.js +0 -4834
  61. package/examples/typescript/build/examples/typescript/build.js +0 -24
  62. package/examples/typescript/build/examples/typescript/game.js +0 -102
@@ -254,7 +254,7 @@ declare module "littlejsengine" {
254
254
  * @default Vector2()
255
255
  * @memberof Settings */
256
256
  export let canvasFixedSize: Vector2;
257
- /** Use nearest neighbor scaling algorithm for canvas for more pixelated look
257
+ /** Use nearest neighbor canvas scaling for more pixelated look
258
258
  * - Must be set before startup to take effect
259
259
  * - If enabled sets css image-rendering:pixelated
260
260
  * @type {boolean}
@@ -327,11 +327,11 @@ declare module "littlejsengine" {
327
327
  * @default
328
328
  * @memberof Settings */
329
329
  export let objectMaxSpeed: number;
330
- /** How much gravity to apply to objects along the Y axis, negative is down
331
- * @type {number}
330
+ /** How much gravity to apply to objects, negative Y is down
331
+ * @type {Vector2}
332
332
  * @default
333
333
  * @memberof Settings */
334
- export let gravity: number;
334
+ export let gravity: Vector2;
335
335
  /** Scales emit rate of particles, useful for low graphics mode (0 disables particle emitters)
336
336
  * @type {number}
337
337
  * @default
@@ -506,10 +506,10 @@ declare module "littlejsengine" {
506
506
  * @param {number} speed
507
507
  * @memberof Settings */
508
508
  export function setObjectMaxSpeed(speed: number): void;
509
- /** Set how much gravity to apply to objects along the Y axis
510
- * @param {number} newGravity
509
+ /** Set how much gravity to apply to objects
510
+ * @param {Vector2} newGravity
511
511
  * @memberof Settings */
512
- export function setGravity(newGravity: number): void;
512
+ export function setGravity(newGravity: Vector2): void;
513
513
  /** Set to scales emit rate of particles
514
514
  * @param {number} scale
515
515
  * @memberof Settings */
@@ -1885,7 +1885,7 @@ declare module "littlejsengine" {
1885
1885
  /** @property {boolean} - Limit object speed using linear or circular math */
1886
1886
  clampSpeedLinear: boolean;
1887
1887
  /** @property {EngineObject} - Object we are standing on, if any */
1888
- groundObject: any;
1888
+ groundObject: EngineObject | TileCollisionLayer;
1889
1889
  /** @property {EngineObject} - Parent of object if in local space */
1890
1890
  parent: any;
1891
1891
  /** @property {Vector2} - Local position if child */
@@ -1967,42 +1967,27 @@ declare module "littlejsengine" {
1967
1967
  * LittleJS Tile Layer System
1968
1968
  * - Caches arrays of tiles to off screen canvas for fast rendering
1969
1969
  * - Unlimited numbers of layers, allocates canvases as needed
1970
- * - Interfaces with EngineObject for collision
1971
- * - Collision layer is separate from visible layers
1972
- * - It is recommended to have a visible layer that matches the collision
1973
1970
  * - Tile layers can be drawn to using their context with canvas2d
1974
1971
  * - Drawn directly to the main canvas without using WebGL
1972
+ * - Tile layers can also have collision with EngineObjects
1975
1973
  * @namespace TileCollision
1976
1974
  */
1977
- /** The tile collision layer grid, use setTileCollisionData and getTileCollisionData to access
1978
- * @type {Array<number>}
1979
- * @memberof TileCollision */
1980
- export let tileCollision: Array<number>;
1981
- /** Size of the tile collision layer 2d grid
1982
- * @type {Vector2}
1983
- * @memberof TileCollision */
1984
- export let tileCollisionSize: Vector2;
1985
- /** Clear and initialize tile collision
1986
- * @param {Vector2} size - width and height of tile collision 2d grid
1987
- * @memberof TileCollision */
1988
- export function initTileCollision(size: Vector2): void;
1989
- /** Set tile collision data for a given cell in the grid
1990
- * @param {Vector2} pos
1991
- * @param {number} [data]
1975
+ /** Keep track of all tile layers with collision
1976
+ * @type {Array<TileCollisionLayer>}
1992
1977
  * @memberof TileCollision */
1993
- export function setTileCollisionData(pos: Vector2, data?: number): void;
1978
+ export let tileCollisionLayers: Array<TileCollisionLayer>;
1994
1979
  /** Get tile collision data for a given cell in the grid
1995
- * @param {Vector2} pos
1996
- * @return {number}
1997
- * @memberof TileCollision */
1980
+ * @param {Vector2} pos
1981
+ * @return {number}
1982
+ * @memberof TileCollision */
1998
1983
  export function getTileCollisionData(pos: Vector2): number;
1999
- /** Check if collision with another object should occur
1984
+ /** Check if a tile layer collides with another object
2000
1985
  * @param {Vector2} pos
2001
1986
  * @param {Vector2} [size=(0,0)]
2002
1987
  * @param {EngineObject} [object]
2003
- * @return {boolean}
1988
+ * @return {TileCollisionLayer}
2004
1989
  * @memberof TileCollision */
2005
- export function tileCollisionTest(pos: Vector2, size?: Vector2, object?: EngineObject): boolean;
1990
+ export function tileCollisionTest(pos: Vector2, size?: Vector2, object?: EngineObject): TileCollisionLayer;
2006
1991
  /** Return the center of first tile hit, undefined if nothing was hit.
2007
1992
  * This does not return the exact intersection, but the center of the tile hit.
2008
1993
  * @param {Vector2} posStart
@@ -2012,7 +1997,7 @@ declare module "littlejsengine" {
2012
1997
  * @memberof TileCollision */
2013
1998
  export function tileCollisionRaycast(posStart: Vector2, posEnd: Vector2, object?: EngineObject): Vector2;
2014
1999
  /**
2015
- * Tile layer data object stores info about how to render a tile
2000
+ * Tile layer data object stores info about how to draw a tile
2016
2001
  * @example
2017
2002
  * // create tile layer data with tile index 0 and random orientation and color
2018
2003
  * const tileIndex = 0;
@@ -2044,20 +2029,18 @@ declare module "littlejsengine" {
2044
2029
  * - Each Tile layer is rendered to an off screen canvas
2045
2030
  * - To allow dynamic modifications, layers are rendered using canvas 2d
2046
2031
  * - Some devices like mobile phones are limited to 4k texture resolution
2047
- * - So with 16x16 tiles this limits layers to 256x256 on mobile devices
2032
+ * - For with 16x16 tiles this limits layers to 256x256 on mobile devices
2048
2033
  * @extends EngineObject
2049
2034
  * @example
2050
- * // create tile collision and visible tile layer
2051
- * initTileCollision(vec2(200,100));
2052
- * const tileLayer = new TileLayer();
2035
+ * const tileLayer = new TileLayer(vec2(), vec2(200,100));
2053
2036
  */
2054
2037
  export class TileLayer extends EngineObject {
2055
2038
  /** Create a tile layer object
2056
- * @param {Vector2} [position=(0,0)] - World space position
2057
- * @param {Vector2} [size=tileCollisionSize] - World space size
2058
- * @param {TileInfo} [tileInfo] - Tile info for layer
2059
- * @param {Vector2} [scale=(1,1)] - How much to scale this layer when rendered
2060
- * @param {number} [renderOrder] - Objects are sorted by renderOrder
2039
+ * @param {Vector2} [position=(0,0)] - World space position
2040
+ * @param {Vector2} [size=(1,1)] - World space size
2041
+ * @param {TileInfo} [tileInfo] - Tile info for layer
2042
+ * @param {Vector2} [scale=(1,1)] - How much to scale this layer when rendered
2043
+ * @param {number} [renderOrder] - Objects are sorted by renderOrder
2061
2044
  */
2062
2045
  constructor(position?: Vector2, size?: Vector2, tileInfo?: TileInfo, scale?: Vector2, renderOrder?: number);
2063
2046
  /** @property {HTMLCanvasElement} - The canvas used by this tile layer */
@@ -2118,6 +2101,48 @@ declare module "littlejsengine" {
2118
2101
  * @param {number} [angle=0] */
2119
2102
  drawRect(pos: Vector2, size?: Vector2, color?: Color, angle?: number): void;
2120
2103
  }
2104
+ /**
2105
+ * Tile Collision Layer - a tile layer with collision
2106
+ * - adds collision data and functions to TileLayer
2107
+ * - there can be multiple tile collision layers
2108
+ * - tile collison layers should not overlap each other
2109
+ * @extends TileLayer
2110
+ */
2111
+ export class TileCollisionLayer extends TileLayer {
2112
+ /** Create a tile layer object
2113
+ * @param {Vector2} [position=(0,0)] - World space position
2114
+ * @param {Vector2} [size=(0,0)] - World space size
2115
+ * @param {TileInfo} [tileInfo] - Tile info for layer
2116
+ * @param {number} [renderOrder] - Objects are sorted by renderOrder
2117
+ */
2118
+ constructor(position?: Vector2, size?: Vector2, tileInfo?: TileInfo, renderOrder?: number);
2119
+ /** @property {Array<number>} - The tile collision grid */
2120
+ collisionData: any[];
2121
+ /** Clear and initialize tile collision to new size
2122
+ * @param {Vector2} size - width and height of tile collision 2d grid */
2123
+ initCollision(size: Vector2): void;
2124
+ /** Set tile collision data for a given cell in the grid
2125
+ * @param {Vector2} pos
2126
+ * @param {number} [data] */
2127
+ setCollisionData(pos: Vector2, data?: number): void;
2128
+ /** Get tile collision data for a given cell in the grid
2129
+ * @param {Vector2} pos
2130
+ * @return {number} */
2131
+ getCollisionData(pos: Vector2): number;
2132
+ /** Check if collision with another object should occur
2133
+ * @param {Vector2} pos
2134
+ * @param {Vector2} [size=(0,0)]
2135
+ * @param {EngineObject} [object]
2136
+ * @return {boolean} */
2137
+ collisionTest(pos: Vector2, size?: Vector2, object?: EngineObject): boolean;
2138
+ /** Return the center of first tile hit, undefined if nothing was hit.
2139
+ * This does not return the exact intersection, but the center of the tile hit.
2140
+ * @param {Vector2} posStart
2141
+ * @param {Vector2} posEnd
2142
+ * @param {EngineObject} [object]
2143
+ * @return {Vector2} */
2144
+ collisionRaycast(posStart: Vector2, posEnd: Vector2, object?: EngineObject): Vector2;
2145
+ }
2121
2146
  /**
2122
2147
  * LittleJS Particle System
2123
2148
  */
@@ -2330,6 +2355,15 @@ declare module "littlejsengine" {
2330
2355
  renderIcon(pos: Vector2, size: number): void;
2331
2356
  storageKey(): string;
2332
2357
  }
2358
+ /**
2359
+ * LittleJS Newgrounds API
2360
+ * - NewgroundsMedal extends Medal with Newgrounds API functionality
2361
+ * - Call new NewgroundsPlugin() to setup Newgrounds
2362
+ * - Uses CryptoJS for encryption if optional cipher is provided
2363
+ * - Keeps connection alive and logs views
2364
+ * - Functions to interact with scoreboards
2365
+ * - Functions to unlock medals
2366
+ */
2333
2367
  /** Global Newgrounds object
2334
2368
  * @type {NewgroundsPlugin}
2335
2369
  * @memberof Medal */
@@ -2387,6 +2421,12 @@ declare module "littlejsengine" {
2387
2421
  */
2388
2422
  export class NewgroundsMedal extends Medal {
2389
2423
  }
2424
+ /**
2425
+ * LittleJS Post Processing Plugin
2426
+ * - Supports shadertoy style post processing shaders
2427
+ * - call new new PostProcessPlugin() to setup post processing
2428
+ * - can be enabled to pass other canvases through a final shader
2429
+ */
2390
2430
  /** Global Post Process plugin object
2391
2431
  * @type {PostProcessPlugin} */
2392
2432
  export let postProcess: PostProcessPlugin;
@@ -2409,6 +2449,9 @@ declare module "littlejsengine" {
2409
2449
  /** @property {boolean} - Should overlay canvas be included in post processing */
2410
2450
  includeOverlay: boolean;
2411
2451
  }
2452
+ /**
2453
+ * LittleJS ZzFXM Plugin
2454
+ */
2412
2455
  /**
2413
2456
  * Music Object - Stores a zzfx music track for later use
2414
2457
  *
@@ -2452,6 +2495,15 @@ declare module "littlejsengine" {
2452
2495
  */
2453
2496
  playMusic(volume?: number, loop?: boolean): AudioBufferSourceNode;
2454
2497
  }
2498
+ /**
2499
+ * LittleJS User Interface Plugin
2500
+ * - call new UISystemPlugin() to setup the UI system
2501
+ * - Nested Menus
2502
+ * - Text
2503
+ * - Buttons
2504
+ * - Checkboxes
2505
+ * - Images
2506
+ */
2455
2507
  /** Global UI system plugin object
2456
2508
  * @type {UISystemPlugin} */
2457
2509
  export let uiSystem: UISystemPlugin;
@@ -2662,6 +2714,20 @@ declare module "littlejsengine" {
2662
2714
  text: string;
2663
2715
  handleColor: Color;
2664
2716
  }
2717
+ /**
2718
+ * LittleJS Box2D Physics Plugin
2719
+ * - Box2dObject extends EngineObject with Box2D physics
2720
+ * - Call box2dEngineInit() to start instead of normal engineInit()
2721
+ * - You will also need to include box2d.wasm.js
2722
+ * - Uses box2d.js super fast web assembly port of Box2D
2723
+ * - More info: https://github.com/kripken/box2d.js
2724
+ * - Fully wraps everything in Box2d
2725
+ * - Functions to create polygon, circle, and edge shapes
2726
+ * - Raycasting and querying
2727
+ * - Joint creation
2728
+ * - Contact begin and end callbacks
2729
+ * - Debug physics drawing
2730
+ */
2665
2731
  /** Global Box2d Plugin object
2666
2732
  * @type {Box2dPlugin} */
2667
2733
  export let box2d: Box2dPlugin;
@@ -2669,6 +2735,9 @@ declare module "littlejsengine" {
2669
2735
  * @type {boolean}
2670
2736
  * @default */
2671
2737
  export let box2dDebug: boolean;
2738
+ /** Enable Box2D debug drawing
2739
+ * @param {boolean} enable */
2740
+ export function box2dSetDebug(enable: boolean): void;
2672
2741
  /** Box2d Init - Startup LittleJS engine with your callback functions
2673
2742
  * @param {Function|function():Promise} gameInit - Called once after the engine starts up
2674
2743
  * @param {Function} gameUpdate - Called every frame before objects are updated