littlejsengine 1.11.17 → 1.12.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/dist/littlejs.d.ts +112 -43
- package/dist/littlejs.esm.js +586 -500
- package/dist/littlejs.esm.min.js +1 -1
- package/dist/littlejs.js +2993 -122
- package/dist/littlejs.min.js +1 -1
- package/dist/littlejs.release.js +2992 -119
- package/examples/box2d/game.js +70 -39
- package/examples/box2d/gameObjects.js +81 -77
- package/examples/box2d/index.html +2 -7
- package/examples/box2d/scenes.js +80 -90
- package/examples/breakout/game.js +63 -28
- package/examples/breakout/gameObjects.js +45 -47
- package/examples/breakout/index.html +1 -5
- package/examples/breakoutTutorial/game.js +36 -29
- package/examples/breakoutTutorial/index.html +1 -3
- package/examples/empty/game.js +5 -2
- package/examples/empty/index.html +1 -3
- package/examples/htmlMenu/game.js +24 -15
- package/examples/htmlMenu/index.html +5 -7
- package/examples/index.html +2 -3
- package/examples/module/game.js +32 -34
- package/examples/module/index.html +1 -1
- package/examples/particles/index.html +27 -22
- package/examples/platformer/game.js +71 -45
- package/examples/platformer/gameCharacter.js +42 -34
- package/examples/platformer/gameEffects.js +82 -75
- package/examples/platformer/gameLevel.js +67 -38
- package/examples/platformer/{gameLevelData.js → gameLevelData.json} +1 -11
- package/examples/platformer/gameObjects.js +70 -64
- package/examples/platformer/gamePlayer.js +12 -7
- package/examples/platformer/index.html +1 -9
- package/examples/puzzle/game.js +59 -40
- package/examples/puzzle/index.html +1 -3
- package/examples/shorts/base.html +2 -2
- package/examples/shorts/particles.js +1 -1
- package/examples/shorts/platformer.js +1 -1
- package/examples/shorts/tileLayer.js +5 -6
- package/examples/shorts/tiles.png +0 -0
- package/examples/starter/game.js +9 -12
- package/examples/starter/index.html +13 -13
- package/examples/stress/index.html +44 -44
- package/examples/typescript/build.js +17 -18
- package/examples/typescript/game.js +32 -34
- package/examples/typescript/game.ts +32 -34
- package/examples/typescript/index.html +1 -1
- package/examples/uiSystem/game.js +34 -31
- package/examples/uiSystem/index.html +1 -5
- package/package.json +1 -1
- package/plugins/box2d.js +6 -2
- package/plugins/pluginExport.js +1 -2
- package/reference.md +29 -27
- package/src/engine.js +1 -1
- package/src/engineBuild.js +13 -6
- package/src/engineDebug.js +1 -3
- package/src/engineExport.js +2 -6
- package/src/engineInput.js +3 -1
- package/src/engineObject.js +18 -14
- package/src/engineSettings.js +6 -6
- package/src/engineTileLayer.js +179 -96
- package/examples/typescript/build/dist/littlejs.esm.js +0 -4834
- package/examples/typescript/build/examples/typescript/build.js +0 -24
- package/examples/typescript/build/examples/typescript/game.js +0 -102
|
@@ -6,22 +6,22 @@
|
|
|
6
6
|
|
|
7
7
|
'use strict';
|
|
8
8
|
|
|
9
|
-
// import module
|
|
10
|
-
import * as
|
|
11
|
-
const {tile, vec2, hsl} =
|
|
9
|
+
// import LittleJS module
|
|
10
|
+
import * as LJS from '../../dist/littlejs.esm.js';
|
|
11
|
+
const {tile, vec2, hsl} = LJS;
|
|
12
12
|
|
|
13
13
|
// show the LittleJS splash screen
|
|
14
|
-
|
|
14
|
+
LJS.setShowSplashScreen(true);
|
|
15
15
|
|
|
16
16
|
// fix texture bleeding by shrinking tile slightly
|
|
17
|
-
|
|
17
|
+
LJS.setTileFixBleedScale(.5);
|
|
18
18
|
|
|
19
19
|
// sound effects
|
|
20
|
-
const sound_click = new
|
|
20
|
+
const sound_click = new LJS.Sound([1,.5]);
|
|
21
21
|
|
|
22
22
|
// medals
|
|
23
|
-
const medal_example = new
|
|
24
|
-
|
|
23
|
+
const medal_example = new LJS.Medal(0, 'Example Medal', 'Welcome to LittleJS!');
|
|
24
|
+
LJS.medalsInit('Hello World');
|
|
25
25
|
|
|
26
26
|
// game variables
|
|
27
27
|
let particleEmitter;
|
|
@@ -30,46 +30,44 @@ let particleEmitter;
|
|
|
30
30
|
function gameInit()
|
|
31
31
|
{
|
|
32
32
|
// create tile collision and visible tile layer
|
|
33
|
-
const tileCollisionSize = vec2(32, 16);
|
|
34
|
-
LittleJS.initTileCollision(tileCollisionSize);
|
|
35
33
|
const pos = vec2();
|
|
36
|
-
const tileLayer = new
|
|
34
|
+
const tileLayer = new LJS.TileCollisionLayer(pos, vec2(32,16));
|
|
37
35
|
|
|
38
36
|
// get level data from the tiles image
|
|
39
|
-
const mainContext =
|
|
40
|
-
const tileImage =
|
|
37
|
+
const mainContext = LJS.mainContext;
|
|
38
|
+
const tileImage = LJS.textureInfos[0].image;
|
|
41
39
|
mainContext.drawImage(tileImage, 0, 0);
|
|
42
40
|
const imageData = mainContext.getImageData(0,0,tileImage.width,tileImage.height).data;
|
|
43
|
-
for (pos.x =
|
|
44
|
-
for (pos.y =
|
|
41
|
+
for (pos.x = tileLayer.size.x; pos.x--;)
|
|
42
|
+
for (pos.y = tileLayer.size.y; pos.y--;)
|
|
45
43
|
{
|
|
46
44
|
// check if this pixel is set
|
|
47
|
-
const i = pos.x + tileImage.width*(15 +
|
|
45
|
+
const i = pos.x + tileImage.width*(15 + tileLayer.size.y - pos.y);
|
|
48
46
|
if (!imageData[4*i])
|
|
49
47
|
continue;
|
|
50
48
|
|
|
51
49
|
// set tile data
|
|
52
50
|
const tileIndex = 1;
|
|
53
|
-
const direction =
|
|
54
|
-
const mirror = !
|
|
55
|
-
const color =
|
|
56
|
-
const data = new
|
|
51
|
+
const direction = LJS.randInt(4)
|
|
52
|
+
const mirror = !LJS.randInt(2);
|
|
53
|
+
const color = LJS.randColor();
|
|
54
|
+
const data = new LJS.TileLayerData(tileIndex, direction, mirror, color);
|
|
57
55
|
tileLayer.setData(pos, data);
|
|
58
|
-
|
|
56
|
+
tileLayer.setCollisionData(pos);
|
|
59
57
|
}
|
|
60
58
|
|
|
61
59
|
// draw tile layer with new data
|
|
62
60
|
tileLayer.redraw();
|
|
63
61
|
|
|
64
62
|
// move camera to center of collision
|
|
65
|
-
|
|
66
|
-
|
|
63
|
+
LJS.setCameraPos(tileLayer.size.scale(.5));
|
|
64
|
+
LJS.setCameraScale(32);
|
|
67
65
|
|
|
68
66
|
// enable gravity
|
|
69
|
-
|
|
67
|
+
LJS.setGravity(vec2(0,-.01));
|
|
70
68
|
|
|
71
69
|
// create particle emitter
|
|
72
|
-
particleEmitter = new
|
|
70
|
+
particleEmitter = new LJS.ParticleEmitter(
|
|
73
71
|
vec2(16,9), 0, // emitPos, emitAngle
|
|
74
72
|
1, 0, 500, Math.PI, // emitSize, emitTime, emitRate, emitCone
|
|
75
73
|
tile(0, 16), // tileIndex, tileSize
|
|
@@ -86,14 +84,14 @@ function gameInit()
|
|
|
86
84
|
///////////////////////////////////////////////////////////////////////////////
|
|
87
85
|
function gameUpdate()
|
|
88
86
|
{
|
|
89
|
-
if (
|
|
87
|
+
if (LJS.mouseWasPressed(0))
|
|
90
88
|
{
|
|
91
89
|
// play sound when mouse is pressed
|
|
92
|
-
sound_click.play(
|
|
90
|
+
sound_click.play(LJS.mousePos);
|
|
93
91
|
|
|
94
92
|
// change particle color and set to fade out
|
|
95
93
|
particleEmitter.colorStartA = hsl();
|
|
96
|
-
particleEmitter.colorStartB =
|
|
94
|
+
particleEmitter.colorStartB = LJS.randColor();
|
|
97
95
|
particleEmitter.colorEndA = particleEmitter.colorStartA.scale(1,0);
|
|
98
96
|
particleEmitter.colorEndB = particleEmitter.colorStartB.scale(1,0);
|
|
99
97
|
|
|
@@ -102,8 +100,8 @@ function gameUpdate()
|
|
|
102
100
|
}
|
|
103
101
|
|
|
104
102
|
// move particles to mouse location if on screen
|
|
105
|
-
if (
|
|
106
|
-
particleEmitter.pos =
|
|
103
|
+
if (LJS.mousePosScreen.x)
|
|
104
|
+
particleEmitter.pos = LJS.mousePos;
|
|
107
105
|
}
|
|
108
106
|
|
|
109
107
|
///////////////////////////////////////////////////////////////////////////////
|
|
@@ -116,19 +114,19 @@ function gameUpdatePost()
|
|
|
116
114
|
function gameRender()
|
|
117
115
|
{
|
|
118
116
|
// draw a grey square in the background without using webgl
|
|
119
|
-
|
|
117
|
+
LJS.drawRect(vec2(16,8), vec2(20,14), hsl(0,0,.6), 0, false);
|
|
120
118
|
|
|
121
119
|
// draw the logo as a tile
|
|
122
|
-
|
|
120
|
+
LJS.drawTile(vec2(21,5), vec2(4.5), tile(3,128));
|
|
123
121
|
}
|
|
124
122
|
|
|
125
123
|
///////////////////////////////////////////////////////////////////////////////
|
|
126
124
|
function gameRenderPost()
|
|
127
125
|
{
|
|
128
126
|
// draw to overlay canvas for hud rendering
|
|
129
|
-
|
|
127
|
+
LJS.drawTextScreen('LittleJS with TypeScript', vec2(LJS.mainCanvasSize.x/2, 80), 80);
|
|
130
128
|
}
|
|
131
129
|
|
|
132
130
|
///////////////////////////////////////////////////////////////////////////////
|
|
133
131
|
// Startup LittleJS Engine
|
|
134
|
-
|
|
132
|
+
LJS.engineInit(gameInit, gameUpdate, gameUpdatePost, gameRender, gameRenderPost, ['tiles.png']);
|
|
@@ -6,8 +6,12 @@
|
|
|
6
6
|
|
|
7
7
|
'use strict';
|
|
8
8
|
|
|
9
|
+
// import LittleJS module
|
|
10
|
+
import * as LJS from '../../dist/littlejs.esm.js';
|
|
11
|
+
const {vec2, hsl, tile} = LJS;
|
|
12
|
+
|
|
9
13
|
// sound effects
|
|
10
|
-
const sound_ui = new Sound([1,0]);
|
|
14
|
+
const sound_ui = new LJS.Sound([1,0]);
|
|
11
15
|
|
|
12
16
|
// UI system
|
|
13
17
|
let uiRoot, uiMenu;
|
|
@@ -15,43 +19,43 @@ const getMenuVisible =()=> uiMenu.visible;
|
|
|
15
19
|
const setMenuVisible =(visible)=> uiMenu.visible = visible;
|
|
16
20
|
|
|
17
21
|
// use a fixed size canvas
|
|
18
|
-
|
|
19
|
-
|
|
22
|
+
LJS.setCanvasFixedSize(vec2(1920, 1080)); // 1080p
|
|
23
|
+
LJS.setCanvasPixelated(false);
|
|
20
24
|
|
|
21
25
|
function createUI()
|
|
22
26
|
{
|
|
23
27
|
// setup root to attach all ui elements to
|
|
24
|
-
uiRoot = new UIObject();
|
|
25
|
-
const uiInfo = new UIText(vec2(0,90), vec2(1e3, 70),
|
|
28
|
+
uiRoot = new LJS.UIObject();
|
|
29
|
+
const uiInfo = new LJS.UIText(vec2(0,90), vec2(1e3, 70),
|
|
26
30
|
'LittleJS UI System Example\nM = Toggle menu');
|
|
27
|
-
uiInfo.textColor = WHITE;
|
|
31
|
+
uiInfo.textColor = LJS.WHITE;
|
|
28
32
|
uiInfo.lineWidth = 8;
|
|
29
33
|
uiRoot.addChild(uiInfo);
|
|
30
34
|
|
|
31
35
|
// setup example menu
|
|
32
|
-
uiMenu = new UIObject(vec2(0,450));
|
|
36
|
+
uiMenu = new LJS.UIObject(vec2(0,450));
|
|
33
37
|
uiRoot.addChild(uiMenu);
|
|
34
|
-
const uiBackground = new UIObject(vec2(0,0), vec2(450,580));
|
|
38
|
+
const uiBackground = new LJS.UIObject(vec2(0,0), vec2(450,580));
|
|
35
39
|
uiBackground.lineWidth = 8;
|
|
36
40
|
uiMenu.addChild(uiBackground);
|
|
37
41
|
|
|
38
42
|
// example large text
|
|
39
|
-
const textTitle = new UIText(vec2(0,-220), vec2(500, 90), 'Test Title');
|
|
43
|
+
const textTitle = new LJS.UIText(vec2(0,-220), vec2(500, 90), 'Test Title');
|
|
40
44
|
uiMenu.addChild(textTitle);
|
|
41
|
-
textTitle.textColor = RED;
|
|
45
|
+
textTitle.textColor = LJS.RED;
|
|
42
46
|
textTitle.lineWidth = 4;
|
|
43
|
-
textTitle.lineColor = BLUE;
|
|
47
|
+
textTitle.lineColor = LJS.BLUE;
|
|
44
48
|
|
|
45
49
|
// example multiline text
|
|
46
|
-
const textTest = new UIText(vec2(-60,-140), vec2(300, 50), 'Test Text\nSecond text line.')
|
|
50
|
+
const textTest = new LJS.UIText(vec2(-60,-140), vec2(300, 50), 'Test Text\nSecond text line.')
|
|
47
51
|
uiMenu.addChild(textTest);
|
|
48
52
|
|
|
49
53
|
// example tile image
|
|
50
|
-
const tileTest = new UITile(vec2(150,-130), vec2(110), tile(3,128))
|
|
54
|
+
const tileTest = new LJS.UITile(vec2(150,-130), vec2(110), tile(3,128))
|
|
51
55
|
uiMenu.addChild(tileTest);
|
|
52
56
|
|
|
53
57
|
// example checkbox
|
|
54
|
-
const checkbox = new UICheckbox(vec2(-140,-20), vec2(40));
|
|
58
|
+
const checkbox = new LJS.UICheckbox(vec2(-140,-20), vec2(40));
|
|
55
59
|
uiMenu.addChild(checkbox);
|
|
56
60
|
checkbox.onPress = ()=>
|
|
57
61
|
{
|
|
@@ -61,18 +65,18 @@ function createUI()
|
|
|
61
65
|
}
|
|
62
66
|
|
|
63
67
|
// text attached to checkbox
|
|
64
|
-
const checkboxText = new UIText(vec2(170,0), vec2(300, 40), 'Test Checkbox');
|
|
68
|
+
const checkboxText = new LJS.UIText(vec2(170,0), vec2(300, 40), 'Test Checkbox');
|
|
65
69
|
checkbox.addChild(checkboxText);
|
|
66
70
|
|
|
67
71
|
// example scrollbar
|
|
68
|
-
const scrollbar = new UIScrollbar(vec2(0,60), vec2(350, 50));
|
|
72
|
+
const scrollbar = new LJS.UIScrollbar(vec2(0,60), vec2(350, 50));
|
|
69
73
|
uiMenu.addChild(scrollbar);
|
|
70
74
|
scrollbar.onChange = ()=> console.log('New scrollbar value:', scrollbar.value);
|
|
71
75
|
scrollbar.onPress = ()=> sound_ui.play(0,.3,2);
|
|
72
76
|
scrollbar.onRelease = ()=> sound_ui.play(0,.3,4);
|
|
73
77
|
|
|
74
78
|
// example button
|
|
75
|
-
const button1 = new UIButton(vec2(0,140), vec2(350, 50), 'Test Button');
|
|
79
|
+
const button1 = new LJS.UIButton(vec2(0,140), vec2(350, 50), 'Test Button');
|
|
76
80
|
uiMenu.addChild(button1);
|
|
77
81
|
button1.onPress = ()=>
|
|
78
82
|
{
|
|
@@ -81,7 +85,7 @@ function createUI()
|
|
|
81
85
|
}
|
|
82
86
|
|
|
83
87
|
// exit button
|
|
84
|
-
const button2 = new UIButton(vec2(0,220), vec2(350, 50), 'Exit Menu');
|
|
88
|
+
const button2 = new LJS.UIButton(vec2(0,220), vec2(350, 50), 'Exit Menu');
|
|
85
89
|
uiMenu.addChild(button2);
|
|
86
90
|
button2.onPress = ()=>
|
|
87
91
|
{
|
|
@@ -94,7 +98,7 @@ function createUI()
|
|
|
94
98
|
///////////////////////////////////////////////////////////////////////////////
|
|
95
99
|
function gameInit()
|
|
96
100
|
{
|
|
97
|
-
new UISystemPlugin;
|
|
101
|
+
new LJS.UISystemPlugin;
|
|
98
102
|
createUI();
|
|
99
103
|
}
|
|
100
104
|
|
|
@@ -106,27 +110,26 @@ function gameUpdate()
|
|
|
106
110
|
///////////////////////////////////////////////////////////////////////////////
|
|
107
111
|
function gameUpdatePost()
|
|
108
112
|
{
|
|
109
|
-
//
|
|
110
|
-
|
|
113
|
+
// toggle menu visibility
|
|
114
|
+
if (LJS.keyWasPressed('KeyM'))
|
|
115
|
+
setMenuVisible(!getMenuVisible());
|
|
111
116
|
|
|
112
|
-
//
|
|
113
|
-
|
|
114
|
-
paused = menuVisible;
|
|
117
|
+
// center ui
|
|
118
|
+
uiRoot.pos.x = LJS.mainCanvasSize.x/2;
|
|
115
119
|
|
|
116
|
-
//
|
|
117
|
-
|
|
118
|
-
setMenuVisible(!menuVisible);
|
|
120
|
+
// pause when menu is visible
|
|
121
|
+
LJS.setPaused(getMenuVisible())
|
|
119
122
|
}
|
|
120
123
|
|
|
121
124
|
///////////////////////////////////////////////////////////////////////////////
|
|
122
125
|
function gameRender()
|
|
123
126
|
{
|
|
124
127
|
// test game rendering
|
|
125
|
-
drawRect(vec2(), vec2(1e3), hsl(0,0,.2));
|
|
128
|
+
LJS.drawRect(vec2(), vec2(1e3), hsl(0,0,.2));
|
|
126
129
|
for(let i=0; i<1e3; ++i)
|
|
127
130
|
{
|
|
128
|
-
const pos = vec2(30*Math.sin(i+time/9),20*Math.sin(i*i+time/9));
|
|
129
|
-
drawTile(pos, vec2(2), tile(3,128), hsl(i/9,1,.4), time+i, !(i%2), hsl(i/9,1,.1,0));
|
|
131
|
+
const pos = vec2(30*Math.sin(i+LJS.time/9),20*Math.sin(i*i+LJS.time/9));
|
|
132
|
+
LJS.drawTile(pos, vec2(2), tile(3,128), hsl(i/9,1,.4), LJS.time+i, !(i%2), hsl(i/9,1,.1,0));
|
|
130
133
|
}
|
|
131
134
|
}
|
|
132
135
|
|
|
@@ -137,4 +140,4 @@ function gameRenderPost()
|
|
|
137
140
|
|
|
138
141
|
///////////////////////////////////////////////////////////////////////////////
|
|
139
142
|
// Startup LittleJS Engine
|
|
140
|
-
engineInit(gameInit, gameUpdate, gameUpdatePost, gameRender, gameRenderPost, ['tiles.png']);
|
|
143
|
+
LJS.engineInit(gameInit, gameUpdate, gameUpdatePost, gameRender, gameRenderPost, ['tiles.png']);
|
|
@@ -6,9 +6,5 @@
|
|
|
6
6
|
<link rel=icon type=image/png href=../favicon.png>
|
|
7
7
|
</head><body>
|
|
8
8
|
|
|
9
|
-
<!-- LittleJS Engine -->
|
|
10
|
-
<script src=../../dist/littlejs.js?11115></script>
|
|
11
|
-
|
|
12
9
|
<!-- Add your game scripts here -->
|
|
13
|
-
<script src
|
|
14
|
-
<script src=game.js?11115></script>
|
|
10
|
+
<script src=game.js type=module></script>
|
package/package.json
CHANGED
package/plugins/box2d.js
CHANGED
|
@@ -24,6 +24,10 @@ let box2d;
|
|
|
24
24
|
* @default */
|
|
25
25
|
let box2dDebug = false;
|
|
26
26
|
|
|
27
|
+
/** Enable Box2D debug drawing
|
|
28
|
+
* @param {boolean} enable */
|
|
29
|
+
function box2dSetDebug(enable) { box2dDebug = enable; }
|
|
30
|
+
|
|
27
31
|
///////////////////////////////////////////////////////////////////////////////
|
|
28
32
|
/**
|
|
29
33
|
* Box2D Object - extend with your own custom physics objects
|
|
@@ -1427,7 +1431,7 @@ class Box2dPlugin
|
|
|
1427
1431
|
* @param {number} [frames] */
|
|
1428
1432
|
step(frames=1)
|
|
1429
1433
|
{
|
|
1430
|
-
box2d.world.SetGravity(box2d.vec2dTo(
|
|
1434
|
+
box2d.world.SetGravity(box2d.vec2dTo(gravity));
|
|
1431
1435
|
for (let i=frames; i--;)
|
|
1432
1436
|
box2d.world.Step(timeDelta, this.velocityIterations, this.positionIterations);
|
|
1433
1437
|
}
|
|
@@ -1568,8 +1572,8 @@ class Box2dPlugin
|
|
|
1568
1572
|
aabb.set_upperBound(box2d.vec2dTo(pos));
|
|
1569
1573
|
|
|
1570
1574
|
let queryObject;
|
|
1571
|
-
debugRaycast && debugRect(pos, vec2(), queryObject ? '#f00' : '#00f', .02);
|
|
1572
1575
|
box2d.world.QueryAABB(queryCallback, aabb);
|
|
1576
|
+
debugRaycast && debugRect(pos, vec2(), queryObject ? '#f00' : '#00f', .02);
|
|
1573
1577
|
return queryObject;
|
|
1574
1578
|
}
|
|
1575
1579
|
|
package/plugins/pluginExport.js
CHANGED
package/reference.md
CHANGED
|
@@ -13,7 +13,7 @@ To start LittleJS, you need to create a few functions and pass them to engineIni
|
|
|
13
13
|
|
|
14
14
|
```javascript
|
|
15
15
|
// Start up LittleJS engine with your callback functions
|
|
16
|
-
engineInit(init, update, updatePost, render, renderPost, imageSources=[
|
|
16
|
+
engineInit(init, update, updatePost, render, renderPost, imageSources=[]);
|
|
17
17
|
```
|
|
18
18
|
|
|
19
19
|
## LittleJS Utilities Classes and Functions
|
|
@@ -29,7 +29,7 @@ engineInit(init, update, updatePost, render, renderPost, imageSources=['tiles.pn
|
|
|
29
29
|
vec2(x=0, y=x) // Create a 2D vector with Vector or floats
|
|
30
30
|
rgb(r=1, g=1, b=1, a=1) // Create a color object with RGBA values
|
|
31
31
|
hsl(h=0, s=0, l=1, a=1) // Create a color object with HSLA values
|
|
32
|
-
tile(pos=(
|
|
32
|
+
tile(pos, size=(16,16), texture=0, padding=0) // Create a tile info object
|
|
33
33
|
|
|
34
34
|
// Helper functions
|
|
35
35
|
abs(value) // Get absolute value
|
|
@@ -131,12 +131,12 @@ Timer.valueOf() // Get how long since elapsed, 0 if not set
|
|
|
131
131
|
|
|
132
132
|
```javascript
|
|
133
133
|
// Drawing functions
|
|
134
|
-
drawTile(pos, size=(1,1), tileInfo, color, angle=0, mirror, additiveColor)
|
|
135
|
-
drawRect(pos, size=(1,1), color=
|
|
136
|
-
drawLine(posA, posB, thickness=.1, color=
|
|
134
|
+
drawTile(pos, size=(1,1), tileInfo, color=WHITE, angle=0, mirror, additiveColor)
|
|
135
|
+
drawRect(pos, size=(1,1), color=WHITE, angle=0)
|
|
136
|
+
drawLine(posA, posB, thickness=.1, color=WHITE)
|
|
137
137
|
drawCanvas2D(pos, size, angle, mirror, drawFunction)
|
|
138
|
-
drawText(text, pos, size=1, color=
|
|
139
|
-
drawTextScreen(text, pos, size=1, color=
|
|
138
|
+
drawText(text, pos, size=1, color=WHITE, lineWidth, lineColor)
|
|
139
|
+
drawTextScreen(text, pos, size=1, color=WHITE, lineWidth, lineColor)
|
|
140
140
|
setBlendMode(additive)
|
|
141
141
|
toggleFullscreen()
|
|
142
142
|
isFullscreen()
|
|
@@ -172,10 +172,15 @@ getCameraSize() // Get the camera's visible area in world space
|
|
|
172
172
|
canvasMaxSize = (1920, 1200) // The max size of the canvas
|
|
173
173
|
canvasFixedSize = (0, 0) // Fixed size of the canvas
|
|
174
174
|
fontDefault = 'arial' // Default font used for text rendering
|
|
175
|
-
canvasPixelated = true //
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
175
|
+
canvasPixelated = true // Use nearest neighbor canvas scaling for more pixelated look
|
|
176
|
+
tilesPixelated = true // Disable filtering for crisper pixel art
|
|
177
|
+
showSplashScreen = false // Show the LittleJS splash screen on startup
|
|
178
|
+
glEnable = true // Enable fast WebGL rendering
|
|
179
|
+
glOverlay = true // Prevent compositing the WebGL canvas
|
|
180
|
+
|
|
181
|
+
// Tile sheet settings
|
|
182
|
+
tileSizeDefault = (16,16) // Default size of tiles in pixels
|
|
183
|
+
tileFixBleedScale = .3 // How much smaller to draw tiles to prevent bleeding
|
|
179
184
|
```
|
|
180
185
|
|
|
181
186
|
## LittleJS Audio System
|
|
@@ -224,7 +229,7 @@ soundDefaultTaper = .7 // Default range percent to taper off sound (0-1)
|
|
|
224
229
|
keyIsDown(key) // Is key down?
|
|
225
230
|
keyWasPressed(key) // Was key pressed this frame?
|
|
226
231
|
keyWasReleased(key) // Was key released this frame?
|
|
227
|
-
keyDirection() // Get input vector from arrow keys or wasd
|
|
232
|
+
keyDirection(up, down, left, right) // Get input vector from arrow keys or wasd
|
|
228
233
|
|
|
229
234
|
// Mouse / Touch
|
|
230
235
|
mousePos // World space mouse position
|
|
@@ -276,7 +281,7 @@ touchGamepadAlpha = .3 // Transparency of touch gamepad overlay
|
|
|
276
281
|
|
|
277
282
|
```javascript
|
|
278
283
|
// Engine Object
|
|
279
|
-
EngineObject(pos
|
|
284
|
+
EngineObject(pos, size=(1,1), tileInfo, angle=0, color, renderOrder=0)
|
|
280
285
|
EngineObject.update() // Update object, called automatically
|
|
281
286
|
EngineObject.render() // Render object, called automatically
|
|
282
287
|
EngineObject.destroy() // Destroy this object and children
|
|
@@ -317,7 +322,7 @@ objectDefaultAngleDamping = 1 // How much to slow angular velocity each frame (0
|
|
|
317
322
|
objectDefaultElasticity = 0 // How much to bounce when a collision occurs (0-1)
|
|
318
323
|
objectDefaultFriction = .8 // How much to slow when touching (0-1)
|
|
319
324
|
objectMaxSpeed = 1 // Clamp max speed to avoid fast objects missing collisions
|
|
320
|
-
gravity = 0
|
|
325
|
+
gravity = (0,0) // How much gravity to apply to objects
|
|
321
326
|
|
|
322
327
|
// Engine Object functions
|
|
323
328
|
engineObjectsCollect(pos, size, objects=engineObjects)k
|
|
@@ -336,15 +341,8 @@ engineObjectsDestroy()
|
|
|
336
341
|
- Drawn directly to the main canvas without using WebGL
|
|
337
342
|
|
|
338
343
|
```javascript
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
initTileCollision(size) // Clear and initialize tile collision
|
|
342
|
-
setTileCollisionData(pos, data=0) // Set tile collision data at pos
|
|
343
|
-
getTileCollisionData(pos) // Get tile collision data at pos
|
|
344
|
-
tileCollisionTest(pos, size=(0,0), object) // Check if collision should occur
|
|
345
|
-
tileCollisionRaycast(posStart, posEnd, object) // Return the center of tile if hit
|
|
346
|
-
|
|
347
|
-
// Tile Layer Object
|
|
344
|
+
|
|
345
|
+
// LittleJS Layer System
|
|
348
346
|
TileLayer(position, size, tileInfo, scale) // Create a tile layer object
|
|
349
347
|
TileLayer.setData(layerPos, data, redraw) // Set data at position
|
|
350
348
|
TileLayer.getData(layerPos) // Get data at position
|
|
@@ -355,12 +353,16 @@ TileLayer.drawTile(pos, size=(1,1), tileInfo, color, angle, mirror) // Draw tile
|
|
|
355
353
|
TileLayer.drawCanvas2D(pos, size, angle, mirror, drawFunction) // Draw to 2D canvas
|
|
356
354
|
|
|
357
355
|
// Tile Layer Data Object
|
|
358
|
-
TileLayerData(tile, direction=0, mirror=false, color=
|
|
356
|
+
TileLayerData(tile, direction=0, mirror=false, color=WHITE) // Create tile data object
|
|
359
357
|
TileLayerData.clear() // Clear this tile data
|
|
360
358
|
|
|
361
|
-
// Tile
|
|
362
|
-
|
|
363
|
-
|
|
359
|
+
// Tile Collision Layer
|
|
360
|
+
TileCollisionLayer(position, size, tileInfo=tile()) // Create a tile collision layer object
|
|
361
|
+
TileCollisionLayer.size // Size of the tile collision layer
|
|
362
|
+
TileCollisionLayer.setCollisionData(pos, data=1) // Set tile collision data at pos
|
|
363
|
+
getTileCollisionData(pos) // Get tile collision data at pos
|
|
364
|
+
tileCollisionTest(pos, size=(0,0), object) // Check if collision should occur
|
|
365
|
+
tileCollisionRaycast(posStart, posEnd, object) // Return the center of tile if hit
|
|
364
366
|
```
|
|
365
367
|
|
|
366
368
|
## LittleJS Particle System
|
package/src/engine.js
CHANGED
package/src/engineBuild.js
CHANGED
|
@@ -35,7 +35,6 @@ const enginePluginFiles =
|
|
|
35
35
|
`${PLUGIN_FOLDER}/zzfxm.js`,
|
|
36
36
|
`${PLUGIN_FOLDER}/uiSystem.js`,
|
|
37
37
|
`${PLUGIN_FOLDER}/box2d.js`,
|
|
38
|
-
`${PLUGIN_FOLDER}/pluginExport.js`,
|
|
39
38
|
];
|
|
40
39
|
const asciiArt =`
|
|
41
40
|
~~~~°°°°ooo°oOo°ooOooOooOo.
|
|
@@ -65,7 +64,11 @@ Build
|
|
|
65
64
|
(
|
|
66
65
|
'Build Engine -- all',
|
|
67
66
|
`${BUILD_FOLDER}/${ENGINE_NAME}.js`,
|
|
68
|
-
[
|
|
67
|
+
[
|
|
68
|
+
`${SOURCE_FOLDER}/engineDebug.js`,
|
|
69
|
+
...engineSourceFiles,
|
|
70
|
+
...enginePluginFiles
|
|
71
|
+
],
|
|
69
72
|
[], true
|
|
70
73
|
);
|
|
71
74
|
|
|
@@ -73,7 +76,11 @@ Build
|
|
|
73
76
|
(
|
|
74
77
|
'Build Engine -- release',
|
|
75
78
|
`${BUILD_FOLDER}/${ENGINE_NAME}.release.js`,
|
|
76
|
-
[
|
|
79
|
+
[
|
|
80
|
+
`${SOURCE_FOLDER}/engineRelease.js`,
|
|
81
|
+
...engineSourceFiles,
|
|
82
|
+
...enginePluginFiles
|
|
83
|
+
],
|
|
77
84
|
[], true
|
|
78
85
|
);
|
|
79
86
|
|
|
@@ -92,7 +99,7 @@ Build
|
|
|
92
99
|
[
|
|
93
100
|
`${BUILD_FOLDER}/${ENGINE_NAME}.js`,
|
|
94
101
|
`${SOURCE_FOLDER}/engineExport.js`,
|
|
95
|
-
|
|
102
|
+
`${PLUGIN_FOLDER}/pluginExport.js`
|
|
96
103
|
],
|
|
97
104
|
[typeScriptBuildStep]
|
|
98
105
|
);
|
|
@@ -104,9 +111,9 @@ Build
|
|
|
104
111
|
[
|
|
105
112
|
`${BUILD_FOLDER}/${ENGINE_NAME}.release.js`,
|
|
106
113
|
`${SOURCE_FOLDER}/engineExport.js`,
|
|
107
|
-
|
|
114
|
+
`${PLUGIN_FOLDER}/pluginExport.js`
|
|
108
115
|
],
|
|
109
|
-
[
|
|
116
|
+
[uglifyBuildStep]
|
|
110
117
|
);
|
|
111
118
|
|
|
112
119
|
console.log(`Engine built in ${((Date.now() - startTime)/1e3).toFixed(2)} seconds!`);
|
package/src/engineDebug.js
CHANGED
|
@@ -329,11 +329,9 @@ function debugRender()
|
|
|
329
329
|
}
|
|
330
330
|
}
|
|
331
331
|
|
|
332
|
-
if (
|
|
332
|
+
if (tileCollisionLayers.length) // show floored tile pick if there is tile collision
|
|
333
333
|
drawRect(mousePos.floor().add(vec2(.5)), vec2(1), rgb(0,0,1,.5), 0, false);
|
|
334
334
|
mainContext = saveContext;
|
|
335
|
-
|
|
336
|
-
//glCopyToContext(mainContext = saveContext);
|
|
337
335
|
}
|
|
338
336
|
|
|
339
337
|
{
|
package/src/engineExport.js
CHANGED
|
@@ -2,8 +2,6 @@
|
|
|
2
2
|
* LittleJS Module Export
|
|
3
3
|
*/
|
|
4
4
|
|
|
5
|
-
'use strict';
|
|
6
|
-
|
|
7
5
|
export
|
|
8
6
|
{
|
|
9
7
|
// Engine
|
|
@@ -279,15 +277,13 @@ export
|
|
|
279
277
|
EngineObject,
|
|
280
278
|
|
|
281
279
|
// Tiles
|
|
282
|
-
|
|
283
|
-
tileCollisionSize,
|
|
284
|
-
initTileCollision,
|
|
285
|
-
setTileCollisionData,
|
|
280
|
+
tileCollisionLayers,
|
|
286
281
|
getTileCollisionData,
|
|
287
282
|
tileCollisionTest,
|
|
288
283
|
tileCollisionRaycast,
|
|
289
284
|
TileLayerData,
|
|
290
285
|
TileLayer,
|
|
286
|
+
TileCollisionLayer,
|
|
291
287
|
|
|
292
288
|
// Particles
|
|
293
289
|
ParticleEmitter,
|
package/src/engineInput.js
CHANGED
|
@@ -314,7 +314,9 @@ function gamepadsUpdate()
|
|
|
314
314
|
const button = gamepad.buttons[j];
|
|
315
315
|
const wasDown = gamepadIsDown(j,i);
|
|
316
316
|
data[j] = button.pressed ? wasDown ? 1 : 3 : wasDown ? 4 : 0;
|
|
317
|
-
|
|
317
|
+
if (!button.value || button.value > .9) // must be a full press
|
|
318
|
+
if (!i && button.pressed)
|
|
319
|
+
isUsingGamepad = true;
|
|
318
320
|
}
|
|
319
321
|
|
|
320
322
|
if (gamepadDirectionEmulateStick)
|