littlejsengine 1.6.0 → 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.
- package/README.md +133 -33
- package/build/littlejs.d.ts +13 -5
- package/build/littlejs.esm.js +106 -95
- package/build/littlejs.esm.min.js +1 -1
- package/build/littlejs.js +98 -93
- package/build/littlejs.min.js +1 -1
- package/build/littlejs.release.js +91 -91
- package/examples/breakout/game.js +5 -0
- package/examples/breakout/gameObjects.js +41 -48
- package/examples/breakout/index.html +3 -3
- package/examples/breakoutTutorial/README.md +514 -0
- package/examples/breakoutTutorial/game.js +181 -0
- package/examples/breakoutTutorial/images/1.png +0 -0
- package/examples/breakoutTutorial/images/10.png +0 -0
- package/examples/breakoutTutorial/images/11.png +0 -0
- package/examples/breakoutTutorial/images/2.png +0 -0
- package/examples/breakoutTutorial/images/3.png +0 -0
- package/examples/breakoutTutorial/images/4.png +0 -0
- package/examples/breakoutTutorial/images/5.png +0 -0
- package/examples/breakoutTutorial/images/6.png +0 -0
- package/examples/breakoutTutorial/images/7.png +0 -0
- package/examples/breakoutTutorial/images/8.png +0 -0
- package/examples/breakoutTutorial/images/9.png +0 -0
- package/examples/breakoutTutorial/index.html +10 -0
- package/examples/empty/game.js +10 -0
- package/examples/module/index.html +1 -1
- package/examples/particles/index.html +1 -1
- package/examples/platformer/gameLevel.js +1 -1
- package/examples/platformer/gamePlayer.js +1 -1
- package/examples/platformer/index.html +6 -6
- package/examples/puzzle/index.html +2 -2
- package/examples/starter/build.bat +3 -2
- package/examples/starter/game.js +9 -9
- package/examples/starter/index.html +13 -13
- package/examples/stress/index.html +1 -1
- package/examples/typescript/game.js +89 -89
- package/examples/typescript/game.ts +10 -10
- package/examples/typescript/index.html +1 -1
- package/package.json +3 -3
- package/src/engine.js +1 -2
- package/src/engineAudio.js +11 -11
- package/src/engineBuild.bat +3 -1
- package/src/engineDebug.js +8 -2
- package/src/engineDraw.js +19 -15
- package/src/engineExport.js +8 -2
- package/src/engineInput.js +51 -55
- package/src/engineObject.js +4 -4
- package/src/engineRelease.js +1 -0
- package/src/engineUtilities.js +4 -4
package/README.md
CHANGED
|
@@ -5,39 +5,70 @@
|
|
|
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/examples/starter/) | [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
|

|
|
12
12
|
|
|
13
|
-
##
|
|
13
|
+
## Demos
|
|
14
14
|
|
|
15
|
-
### [Starter Project](https://killedbyapixel.github.io/LittleJS/examples/starter/) - Clean
|
|
15
|
+
### [Starter Project](https://killedbyapixel.github.io/LittleJS/examples/starter/) - Clean example with only a few things to get you started
|
|
16
16
|
### [Puzzle Game](https://killedbyapixel.github.io/LittleJS/examples/puzzle/) - Match 3 puzzle game with HD rendering and high score tracking
|
|
17
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
|
|
18
|
+
### [Breakout](https://killedbyapixel.github.io/LittleJS/examples/breakout/) - Breakout game with post processing effect
|
|
19
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/
|
|
20
|
+
### [Particle System Designer](https://killedbyapixel.github.io/LittleJS/examples/particles/) - Particle system editor and visualizer
|
|
21
21
|
|
|
22
|
-
##
|
|
22
|
+
## About LittleJS
|
|
23
23
|
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
-
|
|
29
|
-
-
|
|
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
|
-
|
|
34
|
-
|
|
35
|
-
|
|
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
|
-
-
|
|
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
|
-
|
|
40
|
-
|
|
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
|
|
|
@@ -52,42 +83,111 @@ LittleJS can also be imported as a module. There are two module flavors that are
|
|
|
52
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
|
|
53
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
|
-
|
|
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.
|
|
56
87
|
|
|
57
|
-
|
|
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.
|
|
58
89
|
|
|
59
|
-
|
|
90
|
+
## LittleJS Setup
|
|
60
91
|
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
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
|
+
}
|
|
67
148
|
|
|
68
|
-
|
|
149
|
+
render()
|
|
150
|
+
{
|
|
151
|
+
// draw object as a sprite
|
|
152
|
+
super.render();
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
```
|
|
69
156
|
|
|
70
|
-
|
|
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.
|
|
71
160
|
|
|
72
161
|
- [engine.js](https://github.com/KilledByAPixel/LittleJS/blob/main/src/engine.js) - Top level engine init, update, and render
|
|
73
162
|
- [engineSettings.js](https://github.com/KilledByAPixel/LittleJS/blob/main/src/engineSettings.js) - Global engine settings
|
|
74
163
|
- [engineObject.js](https://github.com/KilledByAPixel/LittleJS/blob/main/src/engineObject.js) - Base object class and physics
|
|
75
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
|
|
76
166
|
- [engineInput.js](https://github.com/KilledByAPixel/LittleJS/blob/main/src/engineInput.js) - Input for keyboard, mouse, touch, and gamepad
|
|
77
167
|
- [engineUtilities.js](https://github.com/KilledByAPixel/LittleJS/blob/main/src/engineUtilities.js) - Vector2, Color, and Timer clases and math functions
|
|
78
168
|
|
|
79
169
|
Optional Components, these components are built to synergize with the rest of the engine but are not necessary.
|
|
80
170
|
|
|
81
|
-
- [engineAudio.js](https://github.com/KilledByAPixel/LittleJS/blob/main/src/engineAudio.js) - Spacial sound effects, and zzfx sound generator
|
|
82
171
|
- [engineTileLayer.js](https://github.com/KilledByAPixel/LittleJS/blob/main/src/engineTileLayer.js) - Tile layer rendering and collision
|
|
83
172
|
- [engineParticles.js](https://github.com/KilledByAPixel/LittleJS/blob/main/src/engineParticles.js) - Particle system with fast rendering and collision
|
|
84
173
|
- [engineWebGL.js](https://github.com/KilledByAPixel/LittleJS/blob/main/src/engineWebGL.js) - Super fast rendering with WebGL and post processing
|
|
85
174
|
- [engineMedals.js](https://github.com/KilledByAPixel/LittleJS/blob/main/src/engineMedals.js) - Achievement tracker with Newgrounds integration
|
|
86
175
|
- [engineDebug.js](https://github.com/KilledByAPixel/LittleJS/blob/main/src/engineDebug.js) - Debug rendering system and information overlay
|
|
87
176
|
|
|
177
|
+
## Debugging
|
|
178
|
+
|
|
179
|
+
Debug builds of LittleJS have a special menu that can be opened by pressing ~ (tilde).
|
|
180
|
+
|
|
181
|
+
- ~: Debug Overlay
|
|
182
|
+
- 1: Debug Physics
|
|
183
|
+
- 2: Debug Particles
|
|
184
|
+
- 3: Debug Gamepads
|
|
185
|
+
- 4: God Mode
|
|
186
|
+
- 5: Save Screenshot
|
|
187
|
+
|
|
88
188
|
## Games Made With LittleJS
|
|
89
189
|
|
|
90
|
-
Here are a few
|
|
190
|
+
Here are a few of the amazing games people are making with LittleJS.
|
|
91
191
|
|
|
92
192
|
- [Space Huggers](https://www.newgrounds.com/portal/view/819609) - Run and gun platformer with procedural levels
|
|
93
193
|
- [Undergrowth](https://undergrowth.squidband.uk/) - An interactive music videogame for the band Squid
|
package/build/littlejs.d.ts
CHANGED
|
@@ -155,6 +155,10 @@ declare module "littlejs.esm" {
|
|
|
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 "littlejs.esm" {
|
|
|
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 =
|
|
661
|
-
* let e =
|
|
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 "littlejs.esm" {
|
|
|
798
802
|
* @return {Color}
|
|
799
803
|
* @memberof Utilities
|
|
800
804
|
*/
|
|
801
|
-
export function
|
|
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 "littlejs.esm" {
|
|
|
808
812
|
* @return {Color}
|
|
809
813
|
* @memberof Utilities
|
|
810
814
|
*/
|
|
811
|
-
export function
|
|
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 "littlejs.esm" {
|
|
|
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 "littlejs.esm" {
|
|
|
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
|
|
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
|