littlejsengine 1.5.2 → 1.6.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 (72) hide show
  1. package/README.md +155 -33
  2. package/{engine/index.d.ts → build/littlejs.d.ts} +14 -6
  3. package/{engine/engine.all.module.js → build/littlejs.esm.js} +110 -99
  4. package/build/littlejs.esm.min.js +1 -0
  5. package/{engine/engine.all.js → build/littlejs.js} +102 -97
  6. package/build/littlejs.min.js +1 -0
  7. package/{engine/engine.all.release.js → build/littlejs.release.js} +95 -95
  8. package/examples/breakout/game.js +5 -0
  9. package/examples/breakout/gameObjects.js +41 -48
  10. package/examples/breakout/index.html +5 -4
  11. package/examples/breakoutTutorial/README.md +514 -0
  12. package/examples/breakoutTutorial/game.js +181 -0
  13. package/examples/breakoutTutorial/images/1.png +0 -0
  14. package/examples/breakoutTutorial/images/10.png +0 -0
  15. package/examples/breakoutTutorial/images/11.png +0 -0
  16. package/examples/breakoutTutorial/images/2.png +0 -0
  17. package/examples/breakoutTutorial/images/3.png +0 -0
  18. package/examples/breakoutTutorial/images/4.png +0 -0
  19. package/examples/breakoutTutorial/images/5.png +0 -0
  20. package/examples/breakoutTutorial/images/6.png +0 -0
  21. package/examples/breakoutTutorial/images/7.png +0 -0
  22. package/examples/breakoutTutorial/images/8.png +0 -0
  23. package/examples/breakoutTutorial/images/9.png +0 -0
  24. package/examples/breakoutTutorial/index.html +10 -0
  25. package/examples/electron/build.bat +52 -0
  26. package/{electron → examples/electron}/electron.js +18 -21
  27. package/{game.js → examples/electron/game.js} +1 -1
  28. package/examples/electron/index.html +2 -0
  29. package/examples/electron/package.json +20 -0
  30. package/examples/empty/game.js +11 -1
  31. package/examples/empty/index.html +2 -2
  32. package/examples/module/game.js +1 -1
  33. package/examples/module/index.html +3 -2
  34. package/examples/particles/index.html +3 -2
  35. package/examples/platformer/gameLevel.js +1 -1
  36. package/examples/platformer/gamePlayer.js +1 -1
  37. package/examples/platformer/index.html +8 -7
  38. package/examples/puzzle/index.html +4 -3
  39. package/{build.bat → examples/starter/build.bat} +17 -17
  40. package/examples/starter/game.js +111 -0
  41. package/examples/starter/index.html +27 -0
  42. package/examples/starter/tiles.png +0 -0
  43. package/examples/stress/index.html +3 -2
  44. package/examples/typescript/game.js +89 -89
  45. package/examples/typescript/game.ts +11 -11
  46. package/examples/typescript/index.html +3 -2
  47. package/package.json +4 -4
  48. package/{engine → src}/engine.js +1 -2
  49. package/{engine → src}/engineAudio.js +11 -11
  50. package/src/engineBuild.bat +132 -0
  51. package/{engine → src}/engineDebug.js +8 -2
  52. package/{engine → src}/engineDraw.js +19 -15
  53. package/{engine → src}/engineExport.js +8 -2
  54. package/{engine → src}/engineInput.js +54 -58
  55. package/{engine → src}/engineMedals.js +1 -1
  56. package/{engine → src}/engineObject.js +4 -4
  57. package/{engine → src}/engineRelease.js +1 -0
  58. package/{engine → src}/engineUtilities.js +4 -4
  59. package/electron/electronBuild.bat +0 -32
  60. package/electron/electronSetup.bat +0 -2
  61. package/electron/package.json +0 -21
  62. package/engine/engine.all.min.js +0 -1
  63. package/engine/engine.all.module.min.js +0 -1
  64. package/engine/engineBuild.bat +0 -127
  65. package/index.html +0 -26
  66. /package/{tiles.png → examples/electron/tiles.png} +0 -0
  67. /package/{favicon.png → examples/favicon.png} +0 -0
  68. /package/{engine → src}/engineFont.png +0 -0
  69. /package/{engine → src}/engineParticles.js +0 -0
  70. /package/{engine → src}/engineSettings.js +0 -0
  71. /package/{engine → src}/engineTileLayer.js +0 -0
  72. /package/{engine → src}/engineWebGL.js +0 -0
package/README.md CHANGED
@@ -1,62 +1,182 @@
1
- # ![LittleJS Logo](favicon.png) LittleJS - The Tiny JavaScript Game Engine That Can
1
+ # ![LittleJS Logo](examples/favicon.png) LittleJS - The Tiny JavaScript Game Engine That Can
2
2
 
3
3
  ## All aboard!
4
4
 
5
5
  LittleJS is a super lightweight JavaScript game engine with a fast hybrid rendering system. It provides a comprehensive set of tools including rendering, physics, particles, sound effects, music, input handling, and debug tools. The code is very clean and well documented with a variety of examples to get you started. Choo-Choo! 🚂
6
6
  <div align="center">
7
7
 
8
- ## [Demo](https://killedbyapixel.github.io/LittleJS) | [Docs](https://killedbyapixel.github.io/LittleJS/docs) | [Trailer](https://youtu.be/chuBzGjv7Ms) | [Discord](https://discord.gg/zb7hcGkyZe)
8
+ ## [Demo](https://killedbyapixel.github.io/LittleJS/examples/starter/) | [Docs](https://killedbyapixel.github.io/LittleJS/docs) | [Trailer](https://youtu.be/chuBzGjv7Ms) | [Discord](https://discord.gg/zb7hcGkyZe) | [Tutorial](https://github.com/KilledByAPixel/LittleJS/tree/main/examples/breakoutTutorial)
9
9
  </div>
10
10
 
11
11
  ![LittleJS Screenshot](examples/screenshot.jpg)
12
12
 
13
- ## Examples
13
+ ## Demos
14
14
 
15
- ### [Hello World](https://killedbyapixel.github.io/LittleJS/) - Clean project with only a few things to get you started
16
- ### [Puzzle Game](https://killedbyapixel.github.io/LittleJS/examples/puzzle) - Match 3 puzzle game with HD rendering and high score tracking
17
- ### [Platformer](https://killedbyapixel.github.io/LittleJS/examples/platformer) - Platformer/shooter with procedural generation and destruction
18
- ### [Breakout](https://killedbyapixel.github.io/LittleJS/examples/breakout) - Breakout game with post processing effect
19
- ### [Stress Test](https://killedbyapixel.github.io/LittleJS/examples/stress) - Max sprite/object test and music system demo
20
- ### [Particle System Designer](https://killedbyapixel.github.io/LittleJS/examples/particles) - Particle system editor and visualizer
15
+ ### [Starter Project](https://killedbyapixel.github.io/LittleJS/examples/starter/) - Clean example with only a few things to get you started
16
+ ### [Puzzle Game](https://killedbyapixel.github.io/LittleJS/examples/puzzle/) - Match 3 puzzle game with HD rendering and high score tracking
17
+ ### [Platformer](https://killedbyapixel.github.io/LittleJS/examples/platformer/) - Platformer/shooter with procedural generation and destruction
18
+ ### [Breakout](https://killedbyapixel.github.io/LittleJS/examples/breakout/) - Breakout game with post processing effect
19
+ ### [Stress Test](https://killedbyapixel.github.io/LittleJS/examples/stress/) - Max sprite/object test and music system demo
20
+ ### [Particle System Designer](https://killedbyapixel.github.io/LittleJS/examples/particles/) - Particle system editor and visualizer
21
21
 
22
- ## Features
22
+ ## About LittleJS
23
23
 
24
- - Very small footprint with no dependencies
25
- - Can update and render 10,000+ objects at 60fps, often many times more
26
- - Object oriented system with fast 2D physics and collision handling for axis aligned boxes
27
- - Positional audio effects with [ZzFX](https://killedbyapixel.github.io/ZzFX/) and music with [ZzFXM](https://keithclark.github.io/ZzFXM/), mp3s, or wavs
28
- - Input processing system with keyboard, mouse, gamepad, and touch support
29
- - Particle effects system (particle editor/designer in progress)
30
- - Medal system tracks and displays achievements with Newgrounds integration
31
- - Several easy to understand example projects you can build on
24
+ LittleJS is a small but powerful game engine with many features and no depenencies.
25
+
26
+ Graphics
27
+
28
+ - Fast sprite and tile map rendering engine with WebGL
29
+ - Update and render 10,000+ objects at 60fps, often many times more
32
30
  - Apply [Shadertoy](https://www.shadertoy.com) compatible shaders for post processinge effects
33
- - Debug tools and debug rendering system
34
- - [Full documentation](https://killedbyapixel.github.io/LittleJS/docs) automatically generated from the source code block tags with [JSDoc](https://github.com/jsdoc/jsdoc)
35
- - Build system automatically combines everything, minifies, and removes unused code
31
+
32
+ Audio
33
+
34
+ - Positional sound effects with [ZzFX](https://killedbyapixel.github.io/ZzFX/) sound effect generator
35
+ - Music with [ZzFXM](https://keithclark.github.io/ZzFXM/), mp3, or wav audio
36
+
37
+ Input
38
+
39
+ - Input processing system for keyboard, mouse, gamepad, and touch
40
+
41
+ Physics
42
+
43
+ - 2D physics engine with collision handling for axis aligned boxes
44
+ - Very fast collision handling for tile maps
45
+
46
+ Flexability
47
+
48
+ - Designed to work with all modern web bowsers and mobile devices
49
+ - Compatible with TypeScript and includes [an example TS project](https://killedbyapixel.github.io/LittleJS/examples/typescript)
36
50
  - For size coding competitions like [js13kGames](https://js13kgames.com/), starter project builds to a 7KB zip file
37
- - Easily build a Windows executable with [Electron](https://www.electronjs.org/) for distribution on platforms like Steam
51
+ - Build to a Windows executable with [Electron](https://www.electronjs.org/) for distribution on platforms like Steam
38
52
  - Open Source with the [MIT license](https://github.com/KilledByAPixel/LittleJS/blob/main/LICENSE) so it can be used for anything you want
39
- - Can be imported as a JavaScript module and includes [an example module project](https://killedbyapixel.github.io/LittleJS/examples/module)
40
- - Compatible with TypeScript and includes [an example TS project](https://killedbyapixel.github.io/LittleJS/examples/typescript)
53
+
54
+ Extra Systems
55
+
56
+ - Debug rendering system
57
+ - Particle effects system and design tool
58
+ - Bitmap font rendering and includes a built in engine font
59
+ - Medal system tracks and displays achievements with Newgrounds integration
60
+
61
+ ## How to use LittleJS
62
+
63
+ To use LittleJS download the latest package from GitHub or call ```npm install littlejsengine```. This package contains the engine and several small examples.
64
+
65
+ [You can use the empty example template as a starting point.](https://github.com/KilledByAPixel/LittleJS/blob/main/examples/empty/game.js) This file contians just the minimal setup to start the engine. You can also download and include [littlejs.js](https://github.com/KilledByAPixel/LittleJS/blob/main/build/littlejs.js) or [littlejs.min.js](https://github.com/KilledByAPixel/LittleJS/blob/main/build/littlejs.min.js).
66
+
67
+ If your game loads any files like images you will need to run a local web server. I recommend an editor that does this automatically like [Visual Studio Code](https://code.visualstudio.com/) with the [Live Server plugin](https://marketplace.visualstudio.com/items?itemName=ritwickdey.LiveServer). You can also use [http-server](https://www.npmjs.com/package/http-server) via npm.
68
+
69
+ ## Tutorial
70
+
71
+ - [Breakout Tutorial](https://github.com/KilledByAPixel/LittleJS/blob/main/examples/breakoutTutorial) - Shows how to make a simple game from scatch with LittleJS.
41
72
 
42
73
  ## Builds
43
74
 
44
75
  To easily include LittleJS in your game, you can use one of the 3 pre-built js files. These are also built automatically by the build scripts.
45
76
 
46
- - [engine.all.js](https://github.com/KilledByAPixel/LittleJS/blob/main/engine/engine.all.js) - The full game engine with debug mode available
47
- - [engine.all.release.js](https://github.com/KilledByAPixel/LittleJS/blob/main/engine/engine.all.release.js) - The engine optimized for release builds
48
- - [engine.all.min.js](https://github.com/KilledByAPixel/LittleJS/blob/main/engine/engine.all.min.js) - The engine in release mode and minified
77
+ - [littlejs.js](https://github.com/KilledByAPixel/LittleJS/blob/main/build/littlejs.js) - The full game engine with debug mode available
78
+ - [littlejs.release.js](https://github.com/KilledByAPixel/LittleJS/blob/main/build/littlejs.release.js) - The engine optimized for release builds
79
+ - [littlejs.min.js](https://github.com/KilledByAPixel/LittleJS/blob/main/build/littlejs.min.js) - The engine in release mode and minified
49
80
 
50
- LittleJS can also be imported as a module. There are two module includes that are automatically built.
81
+ LittleJS can also be imported as a module. There are two module flavors that are automatically built.
51
82
 
52
- - [engine.all.module.js](https://github.com/KilledByAPixel/LittleJS/blob/main/engine/engine.all.module.js) - The engine exported as a module with debug mode available
53
- - [engine.all.module.min.js](https://github.com/KilledByAPixel/LittleJS/blob/main/engine/engine.all.module.min.js) - The engine exported as a module in release mode
83
+ - [littlejs.esm.js](https://github.com/KilledByAPixel/LittleJS/blob/main/build/littlejs.esm.js) - The engine exported as a module with debug mode available
84
+ - [littlejs.esm.min.js](https://github.com/KilledByAPixel/LittleJS/blob/main/build/littlejs.esm.min.js) - The engine exported as a minified module in release mode
54
85
 
55
- The hello world example includes a batch file [build.bat](https://github.com/KilledByAPixel/LittleJS/blob/main/build.bat) that compresses everything into a tiny zip file using Google Closure, UglifyJS, Roadroller, and ECT. You must run [buildSetup.bat](https://github.com/KilledByAPixel/LittleJS/blob/main/buildSetup.bat) to install the necessary npm dependencies.
86
+ To rebuild the engine you must first run ```npm install``` to setup the necessary npm dependencies. Then call ```npm run build``` to build the engine.
87
+
88
+ The starter project example also includes a batch file [build.bat](https://github.com/KilledByAPixel/LittleJS/blob/main/examples/starter/build.bat) that compresses everything into a tiny zip file using Google Closure, UglifyJS, Roadroller, and ECT.
89
+
90
+ ## LittleJS Setup
91
+
92
+ To start LittleJS, you must create 5 functions and pass them to engineInit. A canvas will automatically be created and added to the document.
93
+
94
+ ```javascript
95
+ function gameInit()
96
+ {
97
+ // called once after the engine starts up
98
+ // setup the game
99
+ }
100
+
101
+ function gameUpdate()
102
+ {
103
+ // called every frame at 60 frames per second
104
+ // handle input and update the game state
105
+ }
106
+
107
+ function gameUpdatePost()
108
+ {
109
+ // called after physics and objects are updated
110
+ // setup camera and prepare for render
111
+ }
112
+
113
+ function gameRender()
114
+ {
115
+ // called before objects are rendered
116
+ // draw any background effects that appear behind objects
117
+ }
118
+
119
+ function gameRenderPost()
120
+ {
121
+ // called after objects are rendered
122
+ // draw effects or hud that appear above all objects
123
+ }
124
+
125
+ // Startup LittleJS Engine
126
+ engineInit(gameInit, gameUpdate, gameUpdatePost, gameRender, gameRenderPost, 'tiles.png');
127
+ ```
128
+
129
+ ## LittleJS Objects
130
+
131
+ Though not required, LittleJS is intended to be used as an object oriented system by extending the base class [EngineObject](https://github.com/KilledByAPixel/LittleJS/blob/main/src/engineObject.js) with your own. This lightweight class provides many useful features including physics, collision, parent/child system, and sorted rendering. Engine objects are automatically added to the global list of objects where they will be updated and rendered until destroyed.
132
+
133
+ Here is a template you can use to make objects that behave however you want. See the examples for a complete demonstration.
134
+
135
+ ```javascript
136
+ class MyObject extends EngineObject
137
+ {
138
+ constructor(pos, size, tileIndex, tileSize, angle)
139
+ {
140
+ super(pos, size, tileIndex, tileSize, angle);
141
+ }
142
+
143
+ update()
144
+ {
145
+ // update object physics and position
146
+ super.update();
147
+ }
148
+
149
+ render()
150
+ {
151
+ // draw object as a sprite
152
+ super.render();
153
+ }
154
+ }
155
+ ```
156
+
157
+ ## Engine Source Code
158
+
159
+ This engine is made with simplicity in mind using clean easy to read code. There are only a few files used by the entire engine.
160
+
161
+ - [engine.js](https://github.com/KilledByAPixel/LittleJS/blob/main/src/engine.js) - Top level engine init, update, and render
162
+ - [engineSettings.js](https://github.com/KilledByAPixel/LittleJS/blob/main/src/engineSettings.js) - Global engine settings
163
+ - [engineObject.js](https://github.com/KilledByAPixel/LittleJS/blob/main/src/engineObject.js) - Base object class and physics
164
+ - [engineDraw.js](https://github.com/KilledByAPixel/LittleJS/blob/main/src/engineDraw.js) - Code for canvas drawing and text
165
+ - [engineAudio.js](https://github.com/KilledByAPixel/LittleJS/blob/main/src/engineAudio.js) - Spacial sound effects, and zzfx sound generator
166
+ - [engineInput.js](https://github.com/KilledByAPixel/LittleJS/blob/main/src/engineInput.js) - Input for keyboard, mouse, touch, and gamepad
167
+ - [engineUtilities.js](https://github.com/KilledByAPixel/LittleJS/blob/main/src/engineUtilities.js) - Vector2, Color, and Timer clases and math functions
168
+
169
+ Optional Components, these components are built to synergize with the rest of the engine but are not necessary.
170
+
171
+ - [engineTileLayer.js](https://github.com/KilledByAPixel/LittleJS/blob/main/src/engineTileLayer.js) - Tile layer rendering and collision
172
+ - [engineParticles.js](https://github.com/KilledByAPixel/LittleJS/blob/main/src/engineParticles.js) - Particle system with fast rendering and collision
173
+ - [engineWebGL.js](https://github.com/KilledByAPixel/LittleJS/blob/main/src/engineWebGL.js) - Super fast rendering with WebGL and post processing
174
+ - [engineMedals.js](https://github.com/KilledByAPixel/LittleJS/blob/main/src/engineMedals.js) - Achievement tracker with Newgrounds integration
175
+ - [engineDebug.js](https://github.com/KilledByAPixel/LittleJS/blob/main/src/engineDebug.js) - Debug rendering system and information overlay
56
176
 
57
177
  ## Debugging
58
178
 
59
- Debug builds of LittleJS have a special menu that can be opened by pressing ~, the tilde key.
179
+ Debug builds of LittleJS have a special menu that can be opened by pressing ~ (tilde).
60
180
 
61
181
  - ~: Debug Overlay
62
182
  - 1: Debug Physics
@@ -67,6 +187,8 @@ Debug builds of LittleJS have a special menu that can be opened by pressing ~, t
67
187
 
68
188
  ## Games Made With LittleJS
69
189
 
190
+ Here are a few of the amazing games people are making with LittleJS.
191
+
70
192
  - [Space Huggers](https://www.newgrounds.com/portal/view/819609) - Run and gun platformer with procedural levels
71
193
  - [Undergrowth](https://undergrowth.squidband.uk/) - An interactive music videogame for the band Squid
72
194
  - [Space Huggers - JS13K Edition](https://github.com/KilledByAPixel/SpaceHuggers) - Original js13k game with source code
@@ -78,4 +200,4 @@ Debug builds of LittleJS have a special menu that can be opened by pressing ~, t
78
200
  - [Boxing up Bamboo](https://patrickgh3.itch.io/boxing-up-bamboo) - A challenging puzzle game by [Patrick Traynor](https://cwpat.me/about)
79
201
  - Send me your games!
80
202
 
81
- ![LittleJS Logo](favicon.png)
203
+ ![LittleJS Logo](examples/favicon.png)
@@ -1,4 +1,4 @@
1
- declare module "engine.all.module" {
1
+ declare module "littlejs.esm" {
2
2
  /**
3
3
  * LittleJS Module Export
4
4
  * <br> - Export engine as a module with extra functions where necessary
@@ -155,6 +155,10 @@ declare module "engine.all.module" {
155
155
  * @param {Boolean} enable
156
156
  * @memberof Debug */
157
157
  export function setGodMode(enable: boolean): boolean;
158
+ /** Set key code used to toggle debug mode, Esc by default
159
+ * @param {Number} key
160
+ * @memberof Debug */
161
+ export function setDebugKey(key: number): number;
158
162
  /** The max size of the canvas, centered if window is larger
159
163
  * @type {Vector2}
160
164
  * @default Vector2(1920,1200)
@@ -657,8 +661,8 @@ declare module "engine.all.module" {
657
661
  * let a = new Color; // white
658
662
  * let b = new Color(1, 0, 0); // red
659
663
  * let c = new Color(0, 0, 0, 0); // transparent black
660
- * let d = colorRGBA(0, 0, 1); // blue using rgb color
661
- * let e = colorHSLA(.3, 1, .5); // green using hsl color
664
+ * let d = RGB(0, 0, 1); // blue using rgb color
665
+ * let e = HSL(.3, 1, .5); // green using hsl color
662
666
  */
663
667
  export class Color {
664
668
  /** Create a color with the components passed in, white by default
@@ -798,7 +802,7 @@ declare module "engine.all.module" {
798
802
  * @return {Color}
799
803
  * @memberof Utilities
800
804
  */
801
- export function colorRGBA(r?: number, g?: number, b?: number, a?: number): Color;
805
+ export function rgb(r?: number, g?: number, b?: number, a?: number): Color;
802
806
  /**
803
807
  * Create a color object with HSLA values
804
808
  * @param {Number} [h=0]
@@ -808,7 +812,7 @@ declare module "engine.all.module" {
808
812
  * @return {Color}
809
813
  * @memberof Utilities
810
814
  */
811
- export function colorHSLA(h?: number, s?: number, l?: number, a?: number): Color;
815
+ export function hsl(h?: number, s?: number, l?: number, a?: number): Color;
812
816
  /**
813
817
  * LittleJS Object Base Object Class
814
818
  * <br> - Base object class used by the engine
@@ -1039,6 +1043,8 @@ declare module "engine.all.module" {
1039
1043
  * @param {Number} [lineWidth=0]
1040
1044
  * @param {Color} [lineColor=Color(0,0,0)]
1041
1045
  * @param {String} [textAlign='center']
1046
+ * @param {String} [font=fontDefault]
1047
+ * @param {CanvasRenderingContext2D} [context=overlayContext]
1042
1048
  * @memberof Draw */
1043
1049
  export function drawTextScreen(text: string, pos: Vector2, size?: number, color?: Color, lineWidth?: number, lineColor?: Color, textAlign?: string, font?: string, context?: CanvasRenderingContext2D): void;
1044
1050
  /** Draw text on overlay canvas in world space
@@ -1050,8 +1056,10 @@ declare module "engine.all.module" {
1050
1056
  * @param {Number} [lineWidth=0]
1051
1057
  * @param {Color} [lineColor=Color(0,0,0)]
1052
1058
  * @param {String} [textAlign='center']
1059
+ * @param {String} [font=fontDefault]
1060
+ * @param {CanvasRenderingContext2D} [context=overlayContext]
1053
1061
  * @memberof Draw */
1054
- export function drawText(text: string, pos: Vector2, size?: number, color?: Color, lineWidth?: number, lineColor?: Color, textAlign?: string, font: any): void;
1062
+ export function drawText(text: string, pos: Vector2, size?: number, color?: Color, lineWidth?: number, lineColor?: Color, textAlign?: string, font?: string, context?: CanvasRenderingContext2D): void;
1055
1063
  export let engineFontImage: any;
1056
1064
  /**
1057
1065
  * Font Image Object - Draw text on a 2D canvas by using characters in an image