littlejsengine 1.14.19 → 1.14.28
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/dist/littlejs.d.ts +217 -38
- package/dist/littlejs.esm.js +879 -324
- package/dist/littlejs.esm.min.js +1 -1
- package/dist/littlejs.js +861 -324
- package/dist/littlejs.min.js +1 -1
- package/dist/littlejs.release.js +799 -325
- package/examples/box2d/gameObjects.js +6 -10
- package/examples/box2d/scenes.js +2 -2
- package/examples/breakout/gameObjects.js +1 -1
- package/examples/electron/game.js +1 -41
- package/examples/electron/index.html +2 -2
- package/examples/htmlMenu/game.js +1 -1
- package/examples/index.html +19 -10
- package/examples/module/game.js +5 -7
- package/examples/particles/index.html +6 -9
- package/examples/platformer/gameCharacter.js +4 -3
- package/examples/platformer/gameEffects.js +7 -2
- package/examples/platformer/gameObjects.js +6 -11
- package/examples/shorts/animation.js +2 -2
- package/examples/shorts/base.html +4 -1
- package/examples/shorts/box2d.js +2 -2
- package/examples/shorts/box2dCar.js +18 -7
- package/examples/shorts/box2dPool.js +108 -0
- package/examples/shorts/cameraDrag.js +22 -0
- package/examples/shorts/debugDraw.js +37 -0
- package/examples/shorts/flappyGame.js +1 -0
- package/examples/shorts/fps.js +90 -0
- package/examples/shorts/helloWorld.js +1 -1
- package/examples/shorts/hillGlideGame.js +1 -3
- package/examples/shorts/input.js +59 -0
- package/examples/shorts/landerGame.js +1 -3
- package/examples/shorts/medals.js +15 -9
- package/examples/shorts/music.js +15 -17
- package/examples/shorts/musicPlayer.js +24 -24
- package/examples/shorts/platformer.js +0 -2
- package/examples/shorts/postProcess.js +1 -1
- package/examples/shorts/sequencer.js +3 -3
- package/examples/shorts/slidingPuzzle.js +1 -1
- package/examples/shorts/spaceGame.js +1 -3
- package/examples/shorts/spriteAtlas.js +6 -8
- package/examples/shorts/starfield.js +1 -1
- package/examples/shorts/tileRaycast.js +39 -0
- package/examples/shorts/tiles.png +0 -0
- package/examples/shorts/tiltedView.js +1 -4
- package/examples/shorts/timers.js +1 -2
- package/examples/shorts/topDown.js +0 -2
- package/examples/starter/game.js +5 -7
- package/examples/starter/index.html +2 -2
- package/examples/typescript/game.js +3 -2
- package/examples/typescript/game.ts +5 -7
- package/examples/uiSystem/game.js +2 -2
- package/package.json +1 -1
- package/plugins/box2d.js +170 -50
- package/plugins/pluginExport.js +2 -0
- package/plugins/uiSystem.js +55 -27
- package/src/engine.js +19 -16
- package/src/engineAudio.js +27 -15
- package/src/engineDebug.js +64 -0
- package/src/engineDraw.js +88 -32
- package/src/engineExport.js +16 -0
- package/src/engineInput.js +35 -25
- package/src/engineMedals.js +2 -2
- package/src/engineObject.js +55 -10
- package/src/engineParticles.js +36 -20
- package/src/engineRelease.js +2 -1
- package/src/engineSettings.js +20 -1
- package/src/engineTileLayer.js +64 -59
- package/src/engineUtilities.js +213 -59
- package/src/engineWebGL.js +13 -8
- package/examples/shorts/raycasting.js +0 -79
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
let spriteAtlas;
|
|
2
|
-
|
|
3
1
|
function gameInit()
|
|
4
2
|
{
|
|
5
3
|
// create a table of all sprites
|
|
@@ -18,12 +16,12 @@ function gameInit()
|
|
|
18
16
|
function gameRender()
|
|
19
17
|
{
|
|
20
18
|
// draw a sprite from the atlas
|
|
21
|
-
let pos = vec2(
|
|
22
|
-
let angle = 0;
|
|
23
|
-
let size = vec2(9);
|
|
24
|
-
let mirror = 0;
|
|
25
|
-
let color = hsl(0,0,1);
|
|
26
|
-
let additive = hsl(0,0,0,0);
|
|
19
|
+
let pos = vec2(sin(time)*5,-3);// world position
|
|
20
|
+
let angle = 0; // world space angle
|
|
21
|
+
let size = vec2(9); // world space size
|
|
22
|
+
let mirror = 0; // should tile be mirrored?
|
|
23
|
+
let color = hsl(0,0,1); // color to multiply by
|
|
24
|
+
let additive = hsl(0,0,0,0); // color to add to
|
|
27
25
|
drawTile(pos, size, spriteAtlas.iconBig, color, angle, mirror, additive);
|
|
28
26
|
|
|
29
27
|
// draw more sprites from the atlas
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
function gameInit()
|
|
2
|
+
{
|
|
3
|
+
// create tile layer
|
|
4
|
+
const pos = vec2();
|
|
5
|
+
const tileLayer = new TileCollisionLayer(pos, vec2(28,16), 0);
|
|
6
|
+
cameraPos = tileLayer.size.scale(.5); // setup camera
|
|
7
|
+
for (pos.x = tileLayer.size.x; pos.x--;)
|
|
8
|
+
for (pos.y = tileLayer.size.y; pos.y--;)
|
|
9
|
+
{
|
|
10
|
+
// create random solid tiles away from level center
|
|
11
|
+
if (rand() < .7 || cameraPos.distanceSquared(pos) < 9)
|
|
12
|
+
continue;
|
|
13
|
+
|
|
14
|
+
// set tile data
|
|
15
|
+
const data = new TileLayerData(1);
|
|
16
|
+
tileLayer.setData(pos, data);
|
|
17
|
+
tileLayer.setCollisionData(pos);
|
|
18
|
+
}
|
|
19
|
+
tileLayer.redraw();
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
function gameRenderPost()
|
|
23
|
+
{
|
|
24
|
+
// cast ray from camera center to mouse
|
|
25
|
+
drawLine(cameraPos, mousePos, .1, CYAN);
|
|
26
|
+
const normal = vec2();
|
|
27
|
+
const hit = tileCollisionRaycast(cameraPos, mousePos, 0, normal);
|
|
28
|
+
if (hit)
|
|
29
|
+
{
|
|
30
|
+
// draw hit tile
|
|
31
|
+
const tilePos = hit.floor().add(vec2(.5));
|
|
32
|
+
drawRect(tilePos, vec2(1), RED);
|
|
33
|
+
|
|
34
|
+
// draw hit point and normal
|
|
35
|
+
drawRect(hit, vec2(.2), GREEN);
|
|
36
|
+
drawLine(cameraPos, hit, .1, RED);
|
|
37
|
+
drawLine(hit, hit.add(normal), .1, YELLOW);
|
|
38
|
+
}
|
|
39
|
+
}
|
|
Binary file
|
|
@@ -3,14 +3,13 @@ class GameObject extends EngineObject
|
|
|
3
3
|
update()
|
|
4
4
|
{
|
|
5
5
|
this.renderOrder = -this.pos.y; // sort by y position
|
|
6
|
-
super.update();
|
|
7
6
|
}
|
|
8
7
|
|
|
9
8
|
render()
|
|
10
9
|
{
|
|
11
10
|
// adjust draw postion to be at the bottom of the object
|
|
12
11
|
const drawSize = this.drawSize || this.size;
|
|
13
|
-
const offset =
|
|
12
|
+
const offset = this.getUp(drawSize.y/2);
|
|
14
13
|
const pos = this.pos.add(offset);
|
|
15
14
|
drawTile(pos, drawSize, this.tileInfo, this.color, this.angle);
|
|
16
15
|
}
|
|
@@ -20,8 +19,6 @@ class Player extends GameObject
|
|
|
20
19
|
{
|
|
21
20
|
update()
|
|
22
21
|
{
|
|
23
|
-
super.update();
|
|
24
|
-
|
|
25
22
|
// apply movement controls
|
|
26
23
|
const moveInput = keyDirection().clampLength(1).scale(.2);
|
|
27
24
|
this.velocity = this.velocity.add(moveInput);
|
package/examples/starter/game.js
CHANGED
|
@@ -65,16 +65,17 @@ function gameInit()
|
|
|
65
65
|
// create particle emitter
|
|
66
66
|
particleEmitter = new ParticleEmitter(
|
|
67
67
|
vec2(16,9), 0, // emitPos, emitAngle
|
|
68
|
-
0, 0, 500,
|
|
68
|
+
0, 0, 500, 3.14, // emitSize, emitTime, rate, cone
|
|
69
69
|
tile(0, 16), // tileIndex, tileSize
|
|
70
70
|
hsl(1,1,1), hsl(0,0,0), // colorStartA, colorStartB
|
|
71
71
|
hsl(0,0,0,0), hsl(0,0,0,0), // colorEndA, colorEndB
|
|
72
|
-
1, .2, .2, .1, .05,
|
|
73
|
-
.99, 1, 1,
|
|
74
|
-
.05, .5, true, true
|
|
72
|
+
1, .2, .2, .1, .05, // time, sizeStart, sizeEnd, speed, angleSpeed
|
|
73
|
+
.99, 1, 1, 3.14, // damping, angleDamping, gravityScale, cone
|
|
74
|
+
.05, .5, true, true // fadeRate, randomness, collide, additive
|
|
75
75
|
);
|
|
76
76
|
particleEmitter.restitution = .3; // bounce when it collides
|
|
77
77
|
particleEmitter.trailScale = 2; // stretch as it moves
|
|
78
|
+
particleEmitter.velocityInheritance = .3; // inherit emitter velocity
|
|
78
79
|
}
|
|
79
80
|
|
|
80
81
|
///////////////////////////////////////////////////////////////////////////////
|
|
@@ -104,10 +105,7 @@ function gameUpdate()
|
|
|
104
105
|
|
|
105
106
|
// move particles to mouse location if on screen
|
|
106
107
|
if (mousePosScreen.x)
|
|
107
|
-
{
|
|
108
108
|
particleEmitter.pos = mousePos;
|
|
109
|
-
particleEmitter.velocity = mouseDelta.scale(.3*timeDelta);
|
|
110
|
-
}
|
|
111
109
|
}
|
|
112
110
|
|
|
113
111
|
///////////////////////////////////////////////////////////////////////////////
|
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
</head><body>
|
|
8
8
|
|
|
9
9
|
<!-- LittleJS Engine -->
|
|
10
|
-
<script src=../../dist/littlejs.js?
|
|
10
|
+
<script src=../../dist/littlejs.js?1.15.0></script>
|
|
11
11
|
|
|
12
12
|
<!-- LittleJS Engine Source
|
|
13
13
|
<script src=../../src/engineDebug.js></script>
|
|
@@ -31,4 +31,4 @@
|
|
|
31
31
|
-->
|
|
32
32
|
|
|
33
33
|
<!-- Add your game scripts here -->
|
|
34
|
-
<script src=game.js?
|
|
34
|
+
<script src=game.js?1.15.0></script>
|
|
@@ -52,16 +52,17 @@ function gameInit() {
|
|
|
52
52
|
LJS.setGravity(vec2(0, -.01));
|
|
53
53
|
// create particle emitter
|
|
54
54
|
particleEmitter = new LJS.ParticleEmitter(vec2(16, 9), 0, // emitPos, emitAngle
|
|
55
|
-
|
|
55
|
+
0, 0, 500, 3.14, // emitSize, emitTime, rate, cone
|
|
56
56
|
tile(0, 16), // tileIndex, tileSize
|
|
57
57
|
hsl(1, 1, 1), hsl(0, 0, 0), // colorStartA, colorStartB
|
|
58
58
|
hsl(0, 0, 0, 0), hsl(0, 0, 0, 0), // colorEndA, colorEndB
|
|
59
59
|
1, .2, .2, .1, .05, // time, sizeStart, sizeEnd, speed, angleSpeed
|
|
60
|
-
.99, 1, 1,
|
|
60
|
+
.99, 1, 1, 3.14, // damping, angleDamping, gravityScale, cone
|
|
61
61
|
.05, .5, true, true // fadeRate, randomness, collide, additive
|
|
62
62
|
);
|
|
63
63
|
particleEmitter.restitution = .3; // bounce when it collides
|
|
64
64
|
particleEmitter.trailScale = 2; // stretch as it moves
|
|
65
|
+
particleEmitter.velocityInheritance = .3; // inherit emitter velocity
|
|
65
66
|
}
|
|
66
67
|
///////////////////////////////////////////////////////////////////////////////
|
|
67
68
|
function gameUpdate() {
|
|
@@ -69,16 +69,17 @@ function gameInit()
|
|
|
69
69
|
// create particle emitter
|
|
70
70
|
particleEmitter = new LJS.ParticleEmitter(
|
|
71
71
|
vec2(16,9), 0, // emitPos, emitAngle
|
|
72
|
-
|
|
72
|
+
0, 0, 500, 3.14, // emitSize, emitTime, rate, cone
|
|
73
73
|
tile(0, 16), // tileIndex, tileSize
|
|
74
74
|
hsl(1,1,1), hsl(0,0,0), // colorStartA, colorStartB
|
|
75
75
|
hsl(0,0,0,0), hsl(0,0,0,0), // colorEndA, colorEndB
|
|
76
|
-
1, .2, .2, .1, .05,
|
|
77
|
-
.99, 1, 1,
|
|
78
|
-
.05, .5, true, true
|
|
76
|
+
1, .2, .2, .1, .05, // time, sizeStart, sizeEnd, speed, angleSpeed
|
|
77
|
+
.99, 1, 1, 3.14, // damping, angleDamping, gravityScale, cone
|
|
78
|
+
.05, .5, true, true // fadeRate, randomness, collide, additive
|
|
79
79
|
);
|
|
80
80
|
particleEmitter.restitution = .3; // bounce when it collides
|
|
81
81
|
particleEmitter.trailScale = 2; // stretch stretch as it moves
|
|
82
|
+
particleEmitter.velocityInheritance = .3; // inherit emitter velocity
|
|
82
83
|
}
|
|
83
84
|
|
|
84
85
|
///////////////////////////////////////////////////////////////////////////////
|
|
@@ -101,10 +102,7 @@ function gameUpdate()
|
|
|
101
102
|
|
|
102
103
|
// move particles to mouse location if on screen
|
|
103
104
|
if (LJS.mousePosScreen.x)
|
|
104
|
-
{
|
|
105
105
|
particleEmitter.pos = LJS.mousePos;
|
|
106
|
-
particleEmitter.velocity = LJS.mouseDelta.scale(.3*LJS.timeDelta);
|
|
107
|
-
}
|
|
108
106
|
}
|
|
109
107
|
|
|
110
108
|
///////////////////////////////////////////////////////////////////////////////
|
|
@@ -64,7 +64,7 @@ function createUI()
|
|
|
64
64
|
// example button
|
|
65
65
|
const button1 = new LJS.UIButton(vec2(0,140), vec2(350, 50), 'Test Button');
|
|
66
66
|
uiMenu.addChild(button1);
|
|
67
|
-
button1.onClick = ()=> uiBackground.color = hsl(
|
|
67
|
+
button1.onClick = ()=> uiBackground.color = hsl(LJS.rand(),1,.7);
|
|
68
68
|
|
|
69
69
|
// example checkbox
|
|
70
70
|
const checkbox = new LJS.UICheckbox(vec2(-140,-20), vec2(40));
|
|
@@ -114,7 +114,7 @@ function gameRender()
|
|
|
114
114
|
// test game rendering
|
|
115
115
|
for (let i=0; i<1e3; ++i)
|
|
116
116
|
{
|
|
117
|
-
const pos = vec2(30*
|
|
117
|
+
const pos = vec2(30*LJS.sin(i+LJS.time/9),20*LJS.sin(i*i+LJS.time/9));
|
|
118
118
|
LJS.drawTile(pos, vec2(2), tile(3,128), hsl(i/9,1,.4), LJS.time+i, !(i%2), hsl(i/9,1,.1,0));
|
|
119
119
|
}
|
|
120
120
|
}
|