littlejsengine 1.12.6 → 1.13.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 +15 -12
- package/dist/littlejs.d.ts +466 -236
- package/dist/littlejs.esm.js +6126 -5370
- package/dist/littlejs.esm.min.js +4 -1
- package/dist/littlejs.js +6093 -5359
- package/dist/littlejs.min.js +4 -1
- package/dist/littlejs.release.js +5614 -4907
- package/examples/box2d/game.js +2 -2
- package/examples/box2d/gameObjects.js +8 -7
- package/examples/box2d/index.html +1 -1
- package/examples/box2d/scenes.js +8 -8
- package/examples/breakout/game.js +1 -1
- package/examples/breakout/gameObjects.js +2 -2
- package/examples/breakout/index.html +1 -1
- package/examples/breakoutTutorial/README.md +46 -43
- package/examples/breakoutTutorial/game.js +3 -3
- package/examples/breakoutTutorial/index.html +1 -1
- package/examples/electron/build.bat +7 -0
- package/examples/electron/build.js +124 -0
- package/examples/electron/electron.js +35 -0
- package/examples/electron/game.js +140 -0
- package/examples/electron/index.html +13 -0
- package/examples/electron/package.json +12 -0
- package/examples/electron/tiles.png +0 -0
- package/examples/empty/game.js +1 -0
- package/examples/empty/index.html +1 -1
- package/examples/htmlMenu/game.js +1 -1
- package/examples/htmlMenu/index.html +1 -1
- package/examples/index.html +486 -182
- package/examples/module/game.js +6 -3
- package/examples/module/index.html +1 -1
- package/examples/particles/index.html +12 -3
- package/examples/platformer/game.js +4 -4
- package/examples/platformer/gameCharacter.js +6 -6
- package/examples/platformer/gameEffects.js +74 -57
- package/examples/platformer/gameLevel.js +61 -70
- package/examples/platformer/gameObjects.js +4 -4
- package/examples/platformer/index.html +1 -1
- package/examples/puzzle/index.html +1 -1
- package/examples/shorts/base.html +23 -3
- package/examples/shorts/blending.js +9 -5
- package/examples/shorts/box2d.js +1 -1
- package/examples/shorts/box2dCar.js +9 -13
- package/examples/shorts/clock.js +1 -1
- package/examples/shorts/colors.js +2 -2
- package/examples/shorts/flappyGame.js +52 -0
- package/examples/shorts/helloWorld.js +6 -3
- package/examples/shorts/hillGlideGame.js +56 -0
- package/examples/shorts/landerGame.js +32 -0
- package/examples/shorts/maze.js +47 -0
- package/examples/shorts/medals.js +42 -0
- package/examples/shorts/nineSlice.js +21 -0
- package/examples/shorts/piano.js +52 -0
- package/examples/shorts/platformer.js +24 -20
- package/examples/shorts/{pong.js → pongGame.js} +1 -1
- package/examples/shorts/raycasting.js +71 -0
- package/examples/shorts/shapes.js +9 -9
- package/examples/shorts/slidingPuzzle.js +42 -0
- package/examples/shorts/spaceGame.js +56 -0
- package/examples/shorts/starfield.js +15 -0
- package/examples/shorts/systemFont.js +1 -1
- package/examples/shorts/tileLayer.js +3 -5
- package/examples/shorts/tiles.png +0 -0
- package/examples/shorts/tiltedView.js +8 -7
- package/examples/shorts/topDown.js +18 -26
- package/examples/shorts/uiSystem.js +5 -7
- package/examples/starter/build.bat +6 -1
- package/examples/starter/build.js +9 -8
- package/examples/starter/game.js +7 -4
- package/examples/starter/index.html +23 -13
- package/examples/stress/index.html +7 -8
- package/examples/style.css +139 -0
- package/examples/typescript/build.js +2 -3
- package/examples/typescript/game.js +4 -4
- package/examples/typescript/game.ts +6 -3
- package/examples/typescript/index.html +1 -1
- package/examples/uiSystem/game.js +10 -25
- package/examples/uiSystem/index.html +1 -1
- package/package.json +2 -2
- package/plugins/box2d.js +22 -97
- package/plugins/drawUtilities.js +132 -0
- package/plugins/newgrounds.js +1 -1
- package/plugins/pluginExport.js +7 -1
- package/plugins/postProcess.js +9 -2
- package/plugins/uiSystem.js +155 -67
- package/plugins/zzfxm.js +1 -1
- package/reference.md +10 -10
- package/src/engine.js +56 -30
- package/src/engineAudio.js +15 -6
- package/src/engineBuild.bat +6 -1
- package/src/engineBuild.js +20 -5
- package/src/engineDebug.js +55 -28
- package/src/engineDraw.js +321 -177
- package/src/engineExport.js +27 -9
- package/src/engineInput.js +110 -38
- package/src/engineMedals.js +4 -4
- package/src/engineObject.js +71 -70
- package/src/engineParticles.js +33 -9
- package/src/engineSettings.js +69 -23
- package/src/engineTileLayer.js +312 -153
- package/src/engineUtilities.js +187 -135
- package/src/engineWebGL.js +70 -39
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
/*
|
|
2
|
+
Little JS Starter Project
|
|
3
|
+
- A simple starter project for LittleJS
|
|
4
|
+
- Demos all the main engine features
|
|
5
|
+
- Builds to a zip file
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
'use strict';
|
|
9
|
+
|
|
10
|
+
// show the LittleJS splash screen
|
|
11
|
+
setShowSplashScreen(true);
|
|
12
|
+
|
|
13
|
+
// fix texture bleeding by shrinking tile slightly
|
|
14
|
+
setTileFixBleedScale(.5);
|
|
15
|
+
|
|
16
|
+
// sound effects
|
|
17
|
+
const sound_click = new Sound([1,.5]);
|
|
18
|
+
|
|
19
|
+
// medals
|
|
20
|
+
const medal_example = new Medal(0, 'Example Medal', 'Welcome to LittleJS!');
|
|
21
|
+
medalsInit('Hello World');
|
|
22
|
+
|
|
23
|
+
// game variables
|
|
24
|
+
let particleEmitter;
|
|
25
|
+
|
|
26
|
+
///////////////////////////////////////////////////////////////////////////////
|
|
27
|
+
function gameInit()
|
|
28
|
+
{
|
|
29
|
+
// create tile collision and visible tile layer
|
|
30
|
+
const pos = vec2();
|
|
31
|
+
const tileLayer = new TileCollisionLayer(pos, vec2(32,16));
|
|
32
|
+
|
|
33
|
+
// get level data from the tiles image
|
|
34
|
+
const tileImage = textureInfos[0].image;
|
|
35
|
+
mainContext.drawImage(tileImage,0,0);
|
|
36
|
+
const imageData = mainContext.getImageData(0,0,tileImage.width,tileImage.height).data;
|
|
37
|
+
for (pos.x = tileLayer.size.x; pos.x--;)
|
|
38
|
+
for (pos.y = tileLayer.size.y; pos.y--;)
|
|
39
|
+
{
|
|
40
|
+
// check if this pixel is set
|
|
41
|
+
const i = pos.x + tileImage.width*(15 + tileLayer.size.y - pos.y);
|
|
42
|
+
if (!imageData[4*i])
|
|
43
|
+
continue;
|
|
44
|
+
|
|
45
|
+
// set tile data
|
|
46
|
+
const tileIndex = 1;
|
|
47
|
+
const direction = randInt(4)
|
|
48
|
+
const mirror = randBool();
|
|
49
|
+
const color = randColor();
|
|
50
|
+
const data = new TileLayerData(tileIndex, direction, mirror, color);
|
|
51
|
+
tileLayer.setData(pos, data);
|
|
52
|
+
tileLayer.setCollisionData(pos);
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
// draw tile layer with new data
|
|
56
|
+
tileLayer.redraw();
|
|
57
|
+
|
|
58
|
+
// setup camera
|
|
59
|
+
setCameraPos(vec2(16,8));
|
|
60
|
+
setCameraScale(32);
|
|
61
|
+
|
|
62
|
+
// enable gravity
|
|
63
|
+
setGravity(vec2(0,-.01));
|
|
64
|
+
|
|
65
|
+
// create particle emitter
|
|
66
|
+
particleEmitter = new ParticleEmitter(
|
|
67
|
+
vec2(16,9), 0, // emitPos, emitAngle
|
|
68
|
+
0, 0, 500, PI, // emitSize, emitTime, emitRate, emitCone
|
|
69
|
+
tile(0, 16), // tileIndex, tileSize
|
|
70
|
+
hsl(1,1,1), hsl(0,0,0), // colorStartA, colorStartB
|
|
71
|
+
hsl(0,0,0,0), hsl(0,0,0,0), // colorEndA, colorEndB
|
|
72
|
+
2, .2, .2, .1, .05, // time, sizeStart, sizeEnd, speed, angleSpeed
|
|
73
|
+
.99, 1, 1, PI, // damping, angleDamping, gravityScale, cone
|
|
74
|
+
.05, .5, true, true // fadeRate, randomness, collide, additive
|
|
75
|
+
);
|
|
76
|
+
particleEmitter.restitution = .3; // bounce when it collides
|
|
77
|
+
particleEmitter.trailScale = 2; // stretch in direction of motion
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
///////////////////////////////////////////////////////////////////////////////
|
|
81
|
+
function gameUpdate()
|
|
82
|
+
{
|
|
83
|
+
if (mouseWasPressed(0))
|
|
84
|
+
{
|
|
85
|
+
// play sound when mouse is pressed
|
|
86
|
+
sound_click.play(mousePos);
|
|
87
|
+
|
|
88
|
+
// change particle color and set to fade out
|
|
89
|
+
particleEmitter.colorStartA = hsl();
|
|
90
|
+
particleEmitter.colorStartB = randColor();
|
|
91
|
+
particleEmitter.colorEndA = particleEmitter.colorStartA.scale(1,0);
|
|
92
|
+
particleEmitter.colorEndB = particleEmitter.colorStartB.scale(1,0);
|
|
93
|
+
|
|
94
|
+
// unlock medals
|
|
95
|
+
medal_example.unlock();
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
if (mouseWheel)
|
|
99
|
+
{
|
|
100
|
+
// zoom in and out with mouse wheel
|
|
101
|
+
cameraScale -= sign(mouseWheel)*cameraScale/5;
|
|
102
|
+
cameraScale = clamp(cameraScale, 10, 300);
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
// move particles to mouse location if on screen
|
|
106
|
+
if (mousePosScreen.x)
|
|
107
|
+
{
|
|
108
|
+
particleEmitter.pos = mousePos;
|
|
109
|
+
particleEmitter.velocity = mouseDelta.scale(.3*timeDelta);
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
///////////////////////////////////////////////////////////////////////////////
|
|
114
|
+
function gameUpdatePost()
|
|
115
|
+
{
|
|
116
|
+
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
///////////////////////////////////////////////////////////////////////////////
|
|
120
|
+
function gameRender()
|
|
121
|
+
{
|
|
122
|
+
// draw a grey square in the background
|
|
123
|
+
drawRect(vec2(16,8), vec2(20,14), hsl(0,0,.6));
|
|
124
|
+
|
|
125
|
+
// draw the logo as a tile
|
|
126
|
+
drawTile(vec2(21,5), vec2(4.5), tile(3,128));
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
///////////////////////////////////////////////////////////////////////////////
|
|
130
|
+
function gameRenderPost()
|
|
131
|
+
{
|
|
132
|
+
// draw to overlay canvas for hud rendering
|
|
133
|
+
drawTextScreen('LittleJS Demo',
|
|
134
|
+
vec2(mainCanvasSize.x/2, 70), 80, // position, size
|
|
135
|
+
hsl(0,0,1), 6, hsl(0,0,0)); // color, outline size and color
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
///////////////////////////////////////////////////////////////////////////////
|
|
139
|
+
// Startup LittleJS Engine
|
|
140
|
+
engineInit(gameInit, gameUpdate, gameUpdatePost, gameRender, gameRenderPost, ['tiles.png']);
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
<!DOCTYPE html><head>
|
|
2
|
+
<title>LittleJS Starter Project</title>
|
|
3
|
+
<meta charset=utf-8>
|
|
4
|
+
<meta name=apple-mobile-web-app-capable content=yes>
|
|
5
|
+
<meta name=mobile-web-app-capable content=yes>
|
|
6
|
+
<link rel=icon type=image/png href=../favicon.png>
|
|
7
|
+
</head><body>
|
|
8
|
+
|
|
9
|
+
<!-- LittleJS Engine -->
|
|
10
|
+
<script src=../../dist/littlejs.js?1133></script>
|
|
11
|
+
|
|
12
|
+
<!-- Add your game scripts here -->
|
|
13
|
+
<script src=game.js?1133></script>
|
|
Binary file
|
package/examples/empty/game.js
CHANGED