littlejsengine 1.6.0 → 1.6.6
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 +138 -34
- package/build/littlejs.d.ts +104 -92
- package/build/littlejs.esm.js +414 -342
- package/build/littlejs.esm.min.js +1 -1
- package/build/littlejs.js +365 -296
- package/build/littlejs.min.js +1 -1
- package/build/littlejs.release.js +359 -291
- 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/favicon.png +0 -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/game.js +1 -1
- 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 +4 -4
- package/src/engine.js +29 -31
- package/src/engineAudio.js +53 -29
- package/src/engineBuild.bat +3 -1
- package/src/engineDebug.js +25 -24
- package/src/engineDraw.js +43 -39
- package/src/engineExport.js +49 -46
- package/src/engineInput.js +83 -74
- package/src/engineMedals.js +31 -8
- package/src/engineObject.js +25 -25
- package/src/engineParticles.js +3 -6
- package/src/engineRelease.js +19 -19
- package/src/engineSettings.js +4 -4
- package/src/engineTileLayer.js +18 -14
- package/src/engineUtilities.js +43 -34
- package/src/engineWebGL.js +8 -8
package/README.md
CHANGED
|
@@ -2,42 +2,76 @@
|
|
|
2
2
|
|
|
3
3
|
## All aboard!
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
|
|
6
|
+
LittleJS is a super lightweight JavaScript game engine designed for modern web development. With its fast hybrid rendering system, it offers a comprehensive suite of game development tools from rendering to sound effects. The code is very clean and well documented with a variety of examples to get you started. Choo-Choo! 🚂
|
|
6
7
|
<div align="center">
|
|
7
8
|
|
|
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)
|
|
9
|
+
## [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
10
|
</div>
|
|
10
11
|
|
|
11
12
|

|
|
12
13
|
|
|
13
|
-
##
|
|
14
|
+
## Demos
|
|
14
15
|
|
|
15
|
-
### [Starter Project](https://killedbyapixel.github.io/LittleJS/examples/starter/) - Clean
|
|
16
|
+
### [Starter Project](https://killedbyapixel.github.io/LittleJS/examples/starter/) - Clean example with only a few things to get you started
|
|
16
17
|
### [Puzzle Game](https://killedbyapixel.github.io/LittleJS/examples/puzzle/) - Match 3 puzzle game with HD rendering and high score tracking
|
|
17
18
|
### [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
|
+
### [Breakout](https://killedbyapixel.github.io/LittleJS/examples/breakout/) - Breakout game with post processing effect
|
|
19
20
|
### [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/
|
|
21
|
+
### [Particle System Designer](https://killedbyapixel.github.io/LittleJS/examples/particles/) - Particle system editor and visualizer
|
|
21
22
|
|
|
22
|
-
##
|
|
23
|
+
## About LittleJS
|
|
23
24
|
|
|
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
|
|
25
|
+
LittleJS is a small but powerful game engine with many features and no depenencies.
|
|
26
|
+
|
|
27
|
+
### Graphics
|
|
28
|
+
|
|
29
|
+
- Fast sprite and tile map rendering engine with WebGL
|
|
30
|
+
- Update and render 10,000+ objects at 60fps, often many times more
|
|
32
31
|
- Apply [Shadertoy](https://www.shadertoy.com) compatible shaders for post processinge effects
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
32
|
+
|
|
33
|
+
### Audio
|
|
34
|
+
|
|
35
|
+
- Positional sound effects with [ZzFX](https://killedbyapixel.github.io/ZzFX/) sound effect generator
|
|
36
|
+
- Music with [ZzFXM](https://keithclark.github.io/ZzFXM/), mp3, or wav audio
|
|
37
|
+
|
|
38
|
+
### Input
|
|
39
|
+
|
|
40
|
+
- Input processing system for keyboard, mouse, gamepad, and touch
|
|
41
|
+
- On screen touch gamepad for mobile devices
|
|
42
|
+
|
|
43
|
+
### Physics
|
|
44
|
+
|
|
45
|
+
- Kinematic physics object update
|
|
46
|
+
- 2D physics engine with collision handling for axis aligned boxes
|
|
47
|
+
- Very fast collision handling for tile maps
|
|
48
|
+
|
|
49
|
+
### Flexability
|
|
50
|
+
|
|
51
|
+
- Designed to work with all modern web bowsers and mobile devices
|
|
52
|
+
- Compatible with TypeScript and includes [an example TS project](https://killedbyapixel.github.io/LittleJS/examples/typescript)
|
|
36
53
|
- For size coding competitions like [js13kGames](https://js13kgames.com/), starter project builds to a 7KB zip file
|
|
37
|
-
-
|
|
54
|
+
- Build to a Windows executable with [Electron](https://www.electronjs.org/) for distribution on platforms like Steam
|
|
38
55
|
- 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
|
-
|
|
56
|
+
|
|
57
|
+
### Extra Systems
|
|
58
|
+
|
|
59
|
+
- Debug rendering system
|
|
60
|
+
- Particle effects system and design tool
|
|
61
|
+
- Bitmap font rendering and includes a built in engine font
|
|
62
|
+
- Medal system tracks and displays achievements with Newgrounds integration
|
|
63
|
+
|
|
64
|
+
## How to use LittleJS
|
|
65
|
+
|
|
66
|
+
To use LittleJS download the latest package from GitHub or call ```npm install littlejsengine```. This package contains the engine and several small examples.
|
|
67
|
+
|
|
68
|
+
[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).
|
|
69
|
+
|
|
70
|
+
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.
|
|
71
|
+
|
|
72
|
+
## Tutorial
|
|
73
|
+
|
|
74
|
+
- [Breakout Tutorial](https://github.com/KilledByAPixel/LittleJS/blob/main/examples/breakoutTutorial) - Shows how to make a simple game from scatch with LittleJS.
|
|
41
75
|
|
|
42
76
|
## Builds
|
|
43
77
|
|
|
@@ -52,42 +86,111 @@ LittleJS can also be imported as a module. There are two module flavors that are
|
|
|
52
86
|
- [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
87
|
- [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
88
|
|
|
55
|
-
|
|
89
|
+
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
90
|
|
|
57
|
-
|
|
91
|
+
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
92
|
|
|
59
|
-
|
|
93
|
+
## LittleJS Setup
|
|
60
94
|
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
95
|
+
To start LittleJS, you must create 5 functions and pass them to engineInit. A canvas will automatically be created and added to the document.
|
|
96
|
+
|
|
97
|
+
```javascript
|
|
98
|
+
function gameInit()
|
|
99
|
+
{
|
|
100
|
+
// called once after the engine starts up
|
|
101
|
+
// setup the game
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
function gameUpdate()
|
|
105
|
+
{
|
|
106
|
+
// called every frame at 60 frames per second
|
|
107
|
+
// handle input and update the game state
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
function gameUpdatePost()
|
|
111
|
+
{
|
|
112
|
+
// called after physics and objects are updated
|
|
113
|
+
// setup camera and prepare for render
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
function gameRender()
|
|
117
|
+
{
|
|
118
|
+
// called before objects are rendered
|
|
119
|
+
// draw any background effects that appear behind objects
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
function gameRenderPost()
|
|
123
|
+
{
|
|
124
|
+
// called after objects are rendered
|
|
125
|
+
// draw effects or hud that appear above all objects
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
// Startup LittleJS Engine
|
|
129
|
+
engineInit(gameInit, gameUpdate, gameUpdatePost, gameRender, gameRenderPost, 'tiles.png');
|
|
130
|
+
```
|
|
131
|
+
|
|
132
|
+
## LittleJS Objects
|
|
133
|
+
|
|
134
|
+
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.
|
|
135
|
+
|
|
136
|
+
Here is a template you can use to make objects that behave however you want. See the examples for a complete demonstration.
|
|
137
|
+
|
|
138
|
+
```javascript
|
|
139
|
+
class MyObject extends EngineObject
|
|
140
|
+
{
|
|
141
|
+
constructor(pos, size, tileIndex, tileSize, angle)
|
|
142
|
+
{
|
|
143
|
+
super(pos, size, tileIndex, tileSize, angle);
|
|
144
|
+
}
|
|
67
145
|
|
|
68
|
-
|
|
146
|
+
update()
|
|
147
|
+
{
|
|
148
|
+
// update object physics and position
|
|
149
|
+
super.update();
|
|
150
|
+
}
|
|
69
151
|
|
|
70
|
-
|
|
152
|
+
render()
|
|
153
|
+
{
|
|
154
|
+
// draw object as a sprite
|
|
155
|
+
super.render();
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
```
|
|
159
|
+
|
|
160
|
+
## Engine Source Code
|
|
161
|
+
|
|
162
|
+
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
163
|
|
|
72
164
|
- [engine.js](https://github.com/KilledByAPixel/LittleJS/blob/main/src/engine.js) - Top level engine init, update, and render
|
|
73
165
|
- [engineSettings.js](https://github.com/KilledByAPixel/LittleJS/blob/main/src/engineSettings.js) - Global engine settings
|
|
74
166
|
- [engineObject.js](https://github.com/KilledByAPixel/LittleJS/blob/main/src/engineObject.js) - Base object class and physics
|
|
75
167
|
- [engineDraw.js](https://github.com/KilledByAPixel/LittleJS/blob/main/src/engineDraw.js) - Code for canvas drawing and text
|
|
168
|
+
- [engineAudio.js](https://github.com/KilledByAPixel/LittleJS/blob/main/src/engineAudio.js) - Spacial sound effects, and zzfx sound generator
|
|
76
169
|
- [engineInput.js](https://github.com/KilledByAPixel/LittleJS/blob/main/src/engineInput.js) - Input for keyboard, mouse, touch, and gamepad
|
|
77
170
|
- [engineUtilities.js](https://github.com/KilledByAPixel/LittleJS/blob/main/src/engineUtilities.js) - Vector2, Color, and Timer clases and math functions
|
|
78
171
|
|
|
79
172
|
Optional Components, these components are built to synergize with the rest of the engine but are not necessary.
|
|
80
173
|
|
|
81
|
-
- [engineAudio.js](https://github.com/KilledByAPixel/LittleJS/blob/main/src/engineAudio.js) - Spacial sound effects, and zzfx sound generator
|
|
82
174
|
- [engineTileLayer.js](https://github.com/KilledByAPixel/LittleJS/blob/main/src/engineTileLayer.js) - Tile layer rendering and collision
|
|
83
175
|
- [engineParticles.js](https://github.com/KilledByAPixel/LittleJS/blob/main/src/engineParticles.js) - Particle system with fast rendering and collision
|
|
84
176
|
- [engineWebGL.js](https://github.com/KilledByAPixel/LittleJS/blob/main/src/engineWebGL.js) - Super fast rendering with WebGL and post processing
|
|
85
177
|
- [engineMedals.js](https://github.com/KilledByAPixel/LittleJS/blob/main/src/engineMedals.js) - Achievement tracker with Newgrounds integration
|
|
86
178
|
- [engineDebug.js](https://github.com/KilledByAPixel/LittleJS/blob/main/src/engineDebug.js) - Debug rendering system and information overlay
|
|
87
179
|
|
|
180
|
+
## Debugging
|
|
181
|
+
|
|
182
|
+
Debug builds of LittleJS have a special menu that can be opened by pressing the Esc key.
|
|
183
|
+
|
|
184
|
+
- Esc: Debug Overlay
|
|
185
|
+
- 1: Debug Physics
|
|
186
|
+
- 2: Debug Particles
|
|
187
|
+
- 3: Debug Gamepads
|
|
188
|
+
- 4: God Mode
|
|
189
|
+
- 5: Save Screenshot
|
|
190
|
+
|
|
88
191
|
## Games Made With LittleJS
|
|
89
192
|
|
|
90
|
-
Here are a few
|
|
193
|
+
Here are a few of the amazing games people are making with LittleJS.
|
|
91
194
|
|
|
92
195
|
- [Space Huggers](https://www.newgrounds.com/portal/view/819609) - Run and gun platformer with procedural levels
|
|
93
196
|
- [Undergrowth](https://undergrowth.squidband.uk/) - An interactive music videogame for the band Squid
|
|
@@ -98,6 +201,7 @@ Here are a few examples of amazing games made useing LittleJS.
|
|
|
98
201
|
- [Bit Butcher](https://js13kgames.com/entries/bit-butcher) - Survival crafting game by [Deathray Games](https://github.com/deathraygames/bit-butcher)
|
|
99
202
|
- [Necrotic Commander](https://js13kgames.com/entries/necrotic-commander) - Tower defense game by [Daniel Jeffery](https://github.com/d-jeffery/NecroticCommander)
|
|
100
203
|
- [Boxing up Bamboo](https://patrickgh3.itch.io/boxing-up-bamboo) - A challenging puzzle game by [Patrick Traynor](https://cwpat.me/about)
|
|
204
|
+
- [Samurai Sam](https://dev.js13kgames.com/2023/games/samurai-sam) - A Fruit Ninja inspired game by [John Edvard](https://reitgames.com)
|
|
101
205
|
- Send me your games!
|
|
102
206
|
|
|
103
207
|

|