littlejsengine 1.9.11 → 1.10.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 +9 -13
- package/dist/littlejs.d.ts +129 -10
- package/dist/littlejs.esm.js +220 -75
- package/dist/littlejs.esm.min.js +1 -1
- package/dist/littlejs.js +188 -73
- package/dist/littlejs.min.js +1 -1
- package/dist/littlejs.release.js +187 -72
- package/examples/box2d/game.js +4 -1
- package/examples/box2d/index.html +7 -6
- package/examples/breakout/game.js +1 -1
- package/examples/breakout/index.html +5 -4
- package/examples/breakoutTutorial/README.md +9 -7
- package/examples/breakoutTutorial/game.js +6 -6
- package/examples/breakoutTutorial/index.html +4 -3
- package/examples/electron/game.js +1 -1
- package/examples/electron/index.html +4 -3
- package/examples/empty/game.js +1 -1
- package/examples/empty/index.html +2 -1
- package/examples/htmlMenu/game.js +67 -0
- package/examples/htmlMenu/index.html +56 -0
- package/examples/htmlMenu/tiles.png +0 -0
- package/examples/index.html +33 -0
- package/examples/js13k/build/index.html +1 -0
- package/examples/js13k/build/index.js +1 -0
- package/examples/js13k/build/tiles.png +0 -0
- package/examples/js13k/game - Copy.zip +0 -0
- package/examples/js13k/game.js +1 -1
- package/examples/js13k/game.zip +0 -0
- package/examples/js13k/index.html +17 -14
- package/examples/module/game.js +1 -1
- package/examples/module/index.html +3 -2
- package/examples/particles/index.html +4 -3
- package/examples/platformer/game.js +7 -5
- package/examples/platformer/gameCharacter.js +12 -11
- package/examples/platformer/gameEffects.js +3 -4
- package/examples/platformer/gameLevel.js +18 -34
- package/examples/platformer/gameObjects.js +9 -15
- package/examples/platformer/index.html +10 -9
- package/examples/puzzle/game.js +1 -1
- package/examples/puzzle/index.html +4 -3
- package/examples/starter/build/index.html +2 -0
- package/examples/starter/build/index.js +1 -0
- package/examples/starter/build/tiles.png +0 -0
- package/examples/starter/game.js +4 -4
- package/examples/starter/game.zip +0 -0
- package/examples/starter/index.html +15 -14
- package/examples/stress/index.html +3 -2
- package/examples/typescript/build/build/littlejs.esm.js +4327 -0
- package/examples/typescript/build/dist/littlejs.esm.js +4425 -0
- package/examples/typescript/build/examples/typescript/build.js +24 -0
- package/examples/typescript/build/examples/typescript/game.js +100 -0
- package/examples/typescript/build/examples/typescript/test/build/littlejs.esm.js +3934 -0
- package/examples/typescript/build/examples/typescript/test/examples/typescript/build.js +86 -0
- package/examples/typescript/build/examples/typescript/test/examples/typescript/game.js +92 -0
- package/examples/typescript/game.js +1 -1
- package/examples/typescript/game.ts +1 -1
- package/examples/typescript/index.html +3 -2
- package/examples/uiSystem/game.js +134 -0
- package/examples/uiSystem/index.html +25 -0
- package/examples/uiSystem/tiles.png +0 -0
- package/jsconfig.json +11 -0
- package/package.json +1 -1
- package/plugins/box2d.js +2 -1
- package/plugins/postProcess.js +14 -8
- package/plugins/uiSystem.js +243 -0
- package/src/engine.js +42 -22
- package/src/engineAudio.js +10 -13
- package/src/engineDebug.js +1 -1
- package/src/engineDraw.js +102 -27
- package/src/engineExport.js +32 -2
- package/src/engineInput.js +1 -3
- package/src/engineObject.js +1 -0
- package/src/engineSettings.js +1 -1
- package/src/engineTileLayer.js +2 -1
- package/src/engineUtilities.js +2 -1
- package/src/engineWebGL.js +26 -4
package/src/engineExport.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
/**
|
|
1
|
+
/**
|
|
2
2
|
* LittleJS Module Export
|
|
3
3
|
* - Export engine as a module
|
|
4
4
|
*/
|
|
@@ -20,8 +20,9 @@ export {
|
|
|
20
20
|
engineObjectsUpdate,
|
|
21
21
|
engineObjectsDestroy,
|
|
22
22
|
engineObjectsCallback,
|
|
23
|
+
engineObjectsRaycast,
|
|
23
24
|
engineAddPlugin,
|
|
24
|
-
|
|
25
|
+
|
|
25
26
|
// Globals
|
|
26
27
|
debug,
|
|
27
28
|
debugOverlay,
|
|
@@ -140,6 +141,7 @@ export {
|
|
|
140
141
|
smoothStep,
|
|
141
142
|
nearestPowerOfTwo,
|
|
142
143
|
isOverlapping,
|
|
144
|
+
isIntersecting,
|
|
143
145
|
wave,
|
|
144
146
|
formatTime,
|
|
145
147
|
|
|
@@ -159,6 +161,20 @@ export {
|
|
|
159
161
|
vec2,
|
|
160
162
|
rgb,
|
|
161
163
|
hsl,
|
|
164
|
+
isColor,
|
|
165
|
+
|
|
166
|
+
// Default Colors
|
|
167
|
+
WHITE,
|
|
168
|
+
BLACK,
|
|
169
|
+
GRAY,
|
|
170
|
+
RED,
|
|
171
|
+
ORANGE,
|
|
172
|
+
YELLOW,
|
|
173
|
+
GREEN,
|
|
174
|
+
CYAN,
|
|
175
|
+
BLUE,
|
|
176
|
+
PURPLE,
|
|
177
|
+
MAGENTA,
|
|
162
178
|
|
|
163
179
|
// Draw
|
|
164
180
|
textureInfos,
|
|
@@ -175,6 +191,9 @@ export {
|
|
|
175
191
|
drawTile,
|
|
176
192
|
drawRect,
|
|
177
193
|
drawLine,
|
|
194
|
+
drawPoly,
|
|
195
|
+
drawEllipse,
|
|
196
|
+
drawCircle,
|
|
178
197
|
drawCanvas2D,
|
|
179
198
|
setBlendMode,
|
|
180
199
|
drawTextScreen,
|
|
@@ -195,6 +214,17 @@ export {
|
|
|
195
214
|
glDraw,
|
|
196
215
|
glFlush,
|
|
197
216
|
glSetTexture,
|
|
217
|
+
glSetAntialias,
|
|
218
|
+
glAntialias,
|
|
219
|
+
glShader,
|
|
220
|
+
glActiveTexture,
|
|
221
|
+
glArrayBuffer,
|
|
222
|
+
glGeometryBuffer,
|
|
223
|
+
glPositionData,
|
|
224
|
+
glColorData,
|
|
225
|
+
glInstanceCount,
|
|
226
|
+
glAdditive,
|
|
227
|
+
glBatchAdditive,
|
|
198
228
|
|
|
199
229
|
// Input
|
|
200
230
|
keyIsDown,
|
package/src/engineInput.js
CHANGED
|
@@ -167,7 +167,6 @@ function inputInit()
|
|
|
167
167
|
|
|
168
168
|
onkeydown = (e)=>
|
|
169
169
|
{
|
|
170
|
-
if (debug && e.target != document.body) return;
|
|
171
170
|
if (!e.repeat)
|
|
172
171
|
{
|
|
173
172
|
isUsingGamepad = false;
|
|
@@ -180,7 +179,6 @@ function inputInit()
|
|
|
180
179
|
|
|
181
180
|
onkeyup = (e)=>
|
|
182
181
|
{
|
|
183
|
-
if (debug && e.target != document.body) return;
|
|
184
182
|
inputData[0][e.code] = 4;
|
|
185
183
|
if (inputWASDEmulateDirection)
|
|
186
184
|
inputData[0][remapKey(e.code)] = 4;
|
|
@@ -382,7 +380,7 @@ function touchInputInit()
|
|
|
382
380
|
// set event pos and pass it along
|
|
383
381
|
const p = vec2(e.touches[0].clientX, e.touches[0].clientY);
|
|
384
382
|
mousePosScreen = mouseToScreen(p);
|
|
385
|
-
wasTouching ? isUsingGamepad =
|
|
383
|
+
wasTouching ? isUsingGamepad = touchGamepadEnable : inputData[0][button] = 3;
|
|
386
384
|
}
|
|
387
385
|
else if (wasTouching)
|
|
388
386
|
inputData[0][button] = inputData[0][button] & 2 | 4;
|
package/src/engineObject.js
CHANGED
package/src/engineSettings.js
CHANGED
|
@@ -89,7 +89,7 @@ let tileSizeDefault = vec2(16);
|
|
|
89
89
|
* @type {Number}
|
|
90
90
|
* @default
|
|
91
91
|
* @memberof Settings */
|
|
92
|
-
let tileFixBleedScale =
|
|
92
|
+
let tileFixBleedScale = 0;
|
|
93
93
|
|
|
94
94
|
///////////////////////////////////////////////////////////////////////////////
|
|
95
95
|
// Object settings
|
package/src/engineTileLayer.js
CHANGED
|
@@ -70,6 +70,7 @@ function tileCollisionTest(pos, size=vec2(), object)
|
|
|
70
70
|
if (tileData && (!object || object.collideWithTile(tileData, vec2(x, y))))
|
|
71
71
|
return true;
|
|
72
72
|
}
|
|
73
|
+
return false;
|
|
73
74
|
}
|
|
74
75
|
|
|
75
76
|
/** Return the center of first tile hit (does not return the exact intersection)
|
|
@@ -93,7 +94,7 @@ function tileCollisionRaycast(posStart, posEnd, object)
|
|
|
93
94
|
let xi = unit.x * (delta.x < 0 ? posStart.x - pos.x : pos.x - posStart.x + 1);
|
|
94
95
|
let yi = unit.y * (delta.y < 0 ? posStart.y - pos.y : pos.y - posStart.y + 1);
|
|
95
96
|
|
|
96
|
-
while (
|
|
97
|
+
while (true)
|
|
97
98
|
{
|
|
98
99
|
// check for tile collision
|
|
99
100
|
const tileData = getTileCollisionData(pos);
|
package/src/engineUtilities.js
CHANGED
|
@@ -483,6 +483,7 @@ class Vector2
|
|
|
483
483
|
* @param {Number} [length] */
|
|
484
484
|
setDirection(direction, length=1)
|
|
485
485
|
{
|
|
486
|
+
direction = mod(direction, 4);
|
|
486
487
|
ASSERT(direction==0 || direction==1 || direction==2 || direction==3);
|
|
487
488
|
return vec2(direction%2 ? direction-1 ? -length : length : 0,
|
|
488
489
|
direction%2 ? 0 : direction ? -length : length);
|
|
@@ -735,7 +736,7 @@ class Color
|
|
|
735
736
|
* @return {String} */
|
|
736
737
|
toString(useAlpha = true)
|
|
737
738
|
{
|
|
738
|
-
const toHex = (c)=> ((c=c*255|0)<16 ? '0' : '') + c.toString(16);
|
|
739
|
+
const toHex = (c)=> ((c=clamp(c)*255|0)<16 ? '0' : '') + c.toString(16);
|
|
739
740
|
return '#' + toHex(this.r) + toHex(this.g) + toHex(this.b) + (useAlpha ? toHex(this.a) : '');
|
|
740
741
|
}
|
|
741
742
|
|
package/src/engineWebGL.js
CHANGED
|
@@ -22,6 +22,11 @@ let glCanvas;
|
|
|
22
22
|
* @memberof WebGL */
|
|
23
23
|
let glContext;
|
|
24
24
|
|
|
25
|
+
/** Shoule webgl be setup with antialiasing, must be set before calling engineInit
|
|
26
|
+
* @type {Boolean}
|
|
27
|
+
* @memberof WebGL */
|
|
28
|
+
let glAntialias = true;
|
|
29
|
+
|
|
25
30
|
// WebGL internal variables not exposed to documentation
|
|
26
31
|
let glShader, glActiveTexture, glArrayBuffer, glGeometryBuffer, glPositionData, glColorData, glInstanceCount, glAdditive, glBatchAdditive;
|
|
27
32
|
|
|
@@ -34,10 +39,11 @@ function glInit()
|
|
|
34
39
|
|
|
35
40
|
// create the canvas and textures
|
|
36
41
|
glCanvas = document.createElement('canvas');
|
|
37
|
-
glContext = glCanvas.getContext('webgl2');
|
|
42
|
+
glContext = glCanvas.getContext('webgl2', {antialias:glAntialias});
|
|
38
43
|
|
|
39
44
|
// some browsers are much faster without copying the gl buffer so we just overlay it instead
|
|
40
|
-
|
|
45
|
+
const rootElement = mainCanvas.parentElement;
|
|
46
|
+
glOverlay && rootElement.appendChild(glCanvas);
|
|
41
47
|
|
|
42
48
|
// setup vertex and fragment shaders
|
|
43
49
|
glShader = glCreateProgram(
|
|
@@ -92,7 +98,8 @@ function glPreRender()
|
|
|
92
98
|
// set up the shader
|
|
93
99
|
glContext.useProgram(glShader);
|
|
94
100
|
glContext.activeTexture(gl_TEXTURE0);
|
|
95
|
-
|
|
101
|
+
if (textureInfos[0])
|
|
102
|
+
glContext.bindTexture(gl_TEXTURE_2D, glActiveTexture = textureInfos[0].glTexture);
|
|
96
103
|
|
|
97
104
|
// set vertex attributes
|
|
98
105
|
let offset = glAdditive = glBatchAdditive = 0;
|
|
@@ -190,8 +197,14 @@ function glCreateTexture(image)
|
|
|
190
197
|
// build the texture
|
|
191
198
|
const texture = glContext.createTexture();
|
|
192
199
|
glContext.bindTexture(gl_TEXTURE_2D, texture);
|
|
193
|
-
if (image)
|
|
200
|
+
if (image && image.width)
|
|
194
201
|
glContext.texImage2D(gl_TEXTURE_2D, 0, gl_RGBA, gl_RGBA, gl_UNSIGNED_BYTE, image);
|
|
202
|
+
else
|
|
203
|
+
{
|
|
204
|
+
// create a white texture
|
|
205
|
+
const whitePixel = new Uint8Array([255, 255, 255, 255]);
|
|
206
|
+
glContext.texImage2D(gl_TEXTURE_2D, 0, gl_RGBA, 1, 1, 0, gl_RGBA, gl_UNSIGNED_BYTE, whitePixel);
|
|
207
|
+
}
|
|
195
208
|
|
|
196
209
|
// use point filtering for pixelated rendering
|
|
197
210
|
const filter = canvasPixelated ? gl_NEAREST : gl_LINEAR;
|
|
@@ -234,6 +247,15 @@ function glCopyToContext(context, forceDraw=false)
|
|
|
234
247
|
context.drawImage(glCanvas, 0, 0);
|
|
235
248
|
}
|
|
236
249
|
|
|
250
|
+
/** Set antialiasing for webgl canvas
|
|
251
|
+
* @param {Boolean} [antialias]
|
|
252
|
+
* @memberof WebGL */
|
|
253
|
+
function glSetAntialias(antialias=true)
|
|
254
|
+
{
|
|
255
|
+
ASSERT(!glCanvas, 'must be called before engineInit');
|
|
256
|
+
glAntialias = antialias;
|
|
257
|
+
}
|
|
258
|
+
|
|
237
259
|
/** Add a sprite to the gl draw list, used by all gl draw functions
|
|
238
260
|
* @param {Number} x
|
|
239
261
|
* @param {Number} y
|