littlejsengine 1.18.2 → 1.18.7
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/COPYRIGHT.txt +38 -0
- package/FAQ.md +633 -0
- package/LICENSE +5 -27
- package/README.md +19 -1
- package/dist/littlejs.d.ts +550 -57
- package/dist/littlejs.esm.js +2208 -492
- package/dist/littlejs.esm.min.js +1 -1
- package/dist/littlejs.js +2165 -480
- package/dist/littlejs.min.js +1 -1
- package/dist/littlejs.release.js +2166 -481
- package/package.json +8 -1
- package/plugins/box2d.js +36 -9
- package/{src/engineMedals.js → plugins/medalSystem.js} +248 -196
- package/plugins/pathFinder.js +758 -0
- package/plugins/pluginExport.js +26 -0
- package/plugins/tween.js +509 -0
- package/plugins/tweenSystem.js +509 -0
- package/plugins/uiSystem.js +151 -12
- package/src/engine.js +9 -145
- package/src/engineAudio.js +8 -5
- package/src/engineBuild.mjs +4 -1
- package/src/engineDebug.js +1 -1
- package/src/engineDraw.js +154 -5
- package/src/engineExport.js +17 -12
- package/src/engineInput.js +27 -1
- package/src/engineLogo.js +146 -0
- package/src/engineMath.js +10 -3
- package/src/engineObject.js +11 -5
- package/src/engineParticles.js +6 -3
- package/src/engineRelease.js +1 -1
- package/src/engineSettings.js +17 -47
- package/src/engineUtilities.js +7 -2
- package/src/engineWebGL.js +31 -8
- package/src/jsconfig.json +3 -1
- package/.claude/settings.local.json +0 -7
- package/.github/workflows/test.yml +0 -17
- package/AI.md +0 -172
- package/CLAUDE.md +0 -1
- package/examples/box2d/game.js +0 -192
- package/examples/box2d/gameObjects.js +0 -564
- package/examples/box2d/index.html +0 -9
- package/examples/box2d/scenes.js +0 -194
- package/examples/box2d/tiles.png +0 -0
- package/examples/breakout/game.js +0 -175
- package/examples/breakout/gameObjects.js +0 -147
- package/examples/breakout/index.html +0 -8
- package/examples/breakout/tiles.png +0 -0
- package/examples/breakoutTutorial/README.md +0 -521
- package/examples/breakoutTutorial/game.js +0 -191
- 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 +0 -8
- package/examples/electron/build.mjs +0 -127
- package/examples/electron/electron.js +0 -35
- package/examples/electron/game.js +0 -54
- package/examples/electron/index.html +0 -13
- package/examples/electron/package.json +0 -5
- package/examples/electron/tiles.png +0 -0
- package/examples/empty/game.js +0 -51
- package/examples/empty/index.html +0 -5
- package/examples/empty/tiles.png +0 -0
- package/examples/favicon.png +0 -0
- package/examples/games.jpg +0 -0
- package/examples/htmlMenu/game.js +0 -82
- package/examples/htmlMenu/index.html +0 -45
- package/examples/htmlMenu/tiles.png +0 -0
- package/examples/index.html +0 -800
- package/examples/logo.png +0 -0
- package/examples/logo2.png +0 -0
- package/examples/module/build.mjs +0 -124
- package/examples/module/game.js +0 -132
- package/examples/module/index.html +0 -10
- package/examples/module/tiles.png +0 -0
- package/examples/particles/index.html +0 -426
- package/examples/particles/tiles.png +0 -0
- package/examples/platformer/data/gameLevelData.tmx +0 -143
- package/examples/platformer/data/gameLevelData.tsx +0 -4
- package/examples/platformer/game.js +0 -147
- package/examples/platformer/gameCharacter.js +0 -309
- package/examples/platformer/gameEffects.js +0 -278
- package/examples/platformer/gameLevel.js +0 -205
- package/examples/platformer/gameLevelData.json +0 -171
- package/examples/platformer/gameObjects.js +0 -378
- package/examples/platformer/gamePlayer.js +0 -35
- package/examples/platformer/index.html +0 -9
- package/examples/platformer/tiles.png +0 -0
- package/examples/platformer/tilesLevel.png +0 -0
- package/examples/puzzle/game.js +0 -331
- package/examples/puzzle/index.html +0 -8
- package/examples/puzzle/tiles.png +0 -0
- package/examples/screenshot.jpg +0 -0
- package/examples/shorts/animation.js +0 -18
- package/examples/shorts/base.html +0 -54
- package/examples/shorts/blending.js +0 -14
- package/examples/shorts/box2d.js +0 -51
- package/examples/shorts/box2dCar.js +0 -59
- package/examples/shorts/box2dPool.js +0 -107
- package/examples/shorts/box2dTileLayer.js +0 -48
- package/examples/shorts/cameraDrag.js +0 -22
- package/examples/shorts/clock.js +0 -21
- package/examples/shorts/colors.js +0 -25
- package/examples/shorts/debugDraw.js +0 -37
- package/examples/shorts/empty.js +0 -30
- package/examples/shorts/flappyGame.js +0 -55
- package/examples/shorts/fontImage.js +0 -17
- package/examples/shorts/fps.js +0 -90
- package/examples/shorts/helloWorld.js +0 -11
- package/examples/shorts/hillGlideGame.js +0 -63
- package/examples/shorts/input.js +0 -64
- package/examples/shorts/landerGame.js +0 -57
- package/examples/shorts/maze.js +0 -48
- package/examples/shorts/medals.js +0 -51
- package/examples/shorts/music.js +0 -78
- package/examples/shorts/musicPlayer.js +0 -137
- package/examples/shorts/nineSlice.js +0 -40
- package/examples/shorts/parallax.js +0 -72
- package/examples/shorts/particles.js +0 -28
- package/examples/shorts/piano.js +0 -44
- package/examples/shorts/platformer.js +0 -45
- package/examples/shorts/pongGame.js +0 -41
- package/examples/shorts/postProcess.js +0 -62
- package/examples/shorts/sequencer.js +0 -124
- package/examples/shorts/shader.js +0 -29
- package/examples/shorts/shapes.js +0 -21
- package/examples/shorts/slidingPuzzle.js +0 -52
- package/examples/shorts/song.mp3 +0 -0
- package/examples/shorts/sound.js +0 -36
- package/examples/shorts/spaceGame.js +0 -58
- package/examples/shorts/spriteAtlas.js +0 -31
- package/examples/shorts/starfield.js +0 -15
- package/examples/shorts/texture.js +0 -16
- package/examples/shorts/tileLayer.js +0 -48
- package/examples/shorts/tileRaycast.js +0 -39
- package/examples/shorts/tiles.png +0 -0
- package/examples/shorts/tiltedView.js +0 -63
- package/examples/shorts/timers.js +0 -53
- package/examples/shorts/topDown.js +0 -38
- package/examples/shorts/uiSystem.js +0 -61
- package/examples/shorts/video.webm +0 -0
- package/examples/shorts/videoPlayer.js +0 -34
- package/examples/starter/build.bat +0 -7
- package/examples/starter/build.mjs +0 -126
- package/examples/starter/game.js +0 -137
- package/examples/starter/index.html +0 -35
- package/examples/starter/tiles.png +0 -0
- package/examples/stress/index.html +0 -173
- package/examples/style.css +0 -150
- package/examples/typescript/build.mjs +0 -60
- package/examples/typescript/game.js +0 -100
- package/examples/typescript/game.ts +0 -132
- package/examples/typescript/index.html +0 -10
- package/examples/typescript/tiles.png +0 -0
- package/examples/typescript/tsconfig.json +0 -17
- package/examples/uiSystem/game.js +0 -139
- package/examples/uiSystem/index.html +0 -10
- package/examples/uiSystem/tiles.png +0 -0
- package/jsconfig.json +0 -12
- package/plugins/desktop.ini +0 -2
- package/reference.md +0 -447
- package/test/math.test.mjs +0 -774
- package/test/setup.mjs +0 -22
- package/test/smoke.test.mjs +0 -258
- package/test/util.test.mjs +0 -80
package/examples/box2d/scenes.js
DELETED
|
@@ -1,194 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
LittleJS Box2D Example - Scenes
|
|
3
|
-
- Each scene demonstrates a feature of Box2D
|
|
4
|
-
- Feel free to use tis code in your own projects
|
|
5
|
-
- 0 = Shapes: box, circle, poly, and edge
|
|
6
|
-
- 1 = Pyramid stack
|
|
7
|
-
- 2 = Dominoes chain reaction
|
|
8
|
-
- 3 = Car with controls
|
|
9
|
-
- 4 = Rope with box attached
|
|
10
|
-
- 5 = Raycasts in all directions
|
|
11
|
-
- 6 = Joints demo with every joint type
|
|
12
|
-
- 7 = Contacts begin and end callbacks
|
|
13
|
-
- 8 = Mobile object with multiple bodies
|
|
14
|
-
- 9 = Cloth object grid using rope joints
|
|
15
|
-
- 10 = Softbody object grid using weld joints
|
|
16
|
-
*/
|
|
17
|
-
|
|
18
|
-
'use strict';
|
|
19
|
-
|
|
20
|
-
// import game module
|
|
21
|
-
import * as LJS from '../../dist/littlejs.esm.js';
|
|
22
|
-
import * as GameObjects from './gameObjects.js';
|
|
23
|
-
import * as Game from './game.js';
|
|
24
|
-
const {vec2} = LJS;
|
|
25
|
-
|
|
26
|
-
export let scene, sceneName;
|
|
27
|
-
|
|
28
|
-
export function loadScene(_scene)
|
|
29
|
-
{
|
|
30
|
-
scene = _scene;
|
|
31
|
-
|
|
32
|
-
if (scene == 0)
|
|
33
|
-
{
|
|
34
|
-
sceneName = 'Shapes';
|
|
35
|
-
GameObjects.spawnRandomEdges();
|
|
36
|
-
GameObjects.spawnBox(vec2(11,8), 4, LJS.randColor(), LJS.box2d.bodyTypeStatic, false);
|
|
37
|
-
GameObjects.spawnCircle(vec2(20,8), 4, LJS.randColor(), LJS.box2d.bodyTypeStatic, false);
|
|
38
|
-
GameObjects.spawnRandomPoly(vec2(29,8), 4, LJS.randColor(), LJS.box2d.bodyTypeStatic);
|
|
39
|
-
for (let i=500;i--;)
|
|
40
|
-
GameObjects.spawnRandomObject(vec2(LJS.rand(1,39), LJS.rand(10,50)));
|
|
41
|
-
}
|
|
42
|
-
if (scene == 1)
|
|
43
|
-
{
|
|
44
|
-
sceneName = 'Pyramid';
|
|
45
|
-
GameObjects.spawnPyramid(vec2(20,0), 15);
|
|
46
|
-
GameObjects.spawnBox(vec2(10,2), 4, LJS.randColor());
|
|
47
|
-
GameObjects.spawnCircle(vec2(30,2), 4, LJS.randColor());
|
|
48
|
-
}
|
|
49
|
-
if (scene == 2)
|
|
50
|
-
{
|
|
51
|
-
sceneName = 'Dominoes';
|
|
52
|
-
GameObjects.spawnDominoes(vec2(11,13), 8);
|
|
53
|
-
GameObjects.spawnDominoes(vec2(3,0), 10, vec2(1,4));
|
|
54
|
-
GameObjects.spawnCircle(vec2(10.2,20), 1.5, LJS.randColor());
|
|
55
|
-
GameObjects.spawnCircle(vec2(31.9,15), 2.5, LJS.randColor());
|
|
56
|
-
GameObjects.spawnBox(vec2(16,13), vec2(32,1), LJS.randColor(), LJS.box2d.bodyTypeStatic, false);
|
|
57
|
-
GameObjects.spawnBox(vec2(24,8), vec2(34,1), LJS.randColor(), LJS.box2d.bodyTypeStatic, false, -.15);
|
|
58
|
-
}
|
|
59
|
-
if (scene == 3)
|
|
60
|
-
{
|
|
61
|
-
sceneName = 'Car';
|
|
62
|
-
new GameObjects.CarObject(vec2(10,2));
|
|
63
|
-
GameObjects.spawnBox(vec2(20,0), vec2(10,2), LJS.randColor(), LJS.box2d.bodyTypeStatic, false, -.2);
|
|
64
|
-
GameObjects.spawnPyramid(vec2(32,0), 6);
|
|
65
|
-
}
|
|
66
|
-
if (scene == 4)
|
|
67
|
-
{
|
|
68
|
-
sceneName = 'Rope';
|
|
69
|
-
const startPos = vec2(20, 14);
|
|
70
|
-
const angle = LJS.PI/2;
|
|
71
|
-
const color = LJS.randColor();
|
|
72
|
-
const count = 10;
|
|
73
|
-
const endObject = GameObjects.spawnRope(startPos, count, angle, color);
|
|
74
|
-
|
|
75
|
-
// connect box to end
|
|
76
|
-
const endPos = endObject.localToWorld(vec2(0,-endObject.size.y/2));
|
|
77
|
-
const o = GameObjects.spawnBox(endPos, 3, LJS.randColor());
|
|
78
|
-
o.setAngularDamping(.5);
|
|
79
|
-
o.setFilterData(2, 2);
|
|
80
|
-
new LJS.Box2dRevoluteJoint(endObject, o);
|
|
81
|
-
GameObjects.spawnPyramid(vec2(20,0), 7);
|
|
82
|
-
}
|
|
83
|
-
if (scene == 5)
|
|
84
|
-
{
|
|
85
|
-
sceneName = 'Raycasts';
|
|
86
|
-
GameObjects.spawnRandomEdges();
|
|
87
|
-
for (let i=100;i--;)
|
|
88
|
-
GameObjects.spawnRandomObject(vec2(LJS.rand(1,39), LJS.rand(20)), 2, LJS.box2d.bodyTypeStatic, LJS.rand(LJS.PI*2));
|
|
89
|
-
}
|
|
90
|
-
if (scene == 6)
|
|
91
|
-
{
|
|
92
|
-
sceneName = 'Joints';
|
|
93
|
-
{
|
|
94
|
-
// prismatic joint
|
|
95
|
-
const o1 = GameObjects.spawnBox(vec2(20,8), vec2(3,2), LJS.randColor());
|
|
96
|
-
new LJS.Box2dPrismaticJoint(Game.groundObject, o1, o1.pos, vec2(1,0), true);
|
|
97
|
-
const o2 = GameObjects.spawnBox(vec2(20,15), vec2(2,3), LJS.randColor());
|
|
98
|
-
new LJS.Box2dPrismaticJoint(Game.groundObject, o2, o2.pos, vec2(0,1), true);
|
|
99
|
-
|
|
100
|
-
// lines to make it look line a track
|
|
101
|
-
const l1 = new LJS.EngineObject(vec2(20, 8), vec2(39,.5), 0, 0, LJS.GRAY);
|
|
102
|
-
const l2 = new LJS.EngineObject(vec2(20,50), vec2(.5,99), 0, 0, LJS.GRAY);
|
|
103
|
-
l1.gravityScale = l2.gravityScale = 0;
|
|
104
|
-
l1.renderOrder = l2.renderOrder = -2;
|
|
105
|
-
}
|
|
106
|
-
{
|
|
107
|
-
// pulley joint
|
|
108
|
-
const anchorA = vec2(14,15);
|
|
109
|
-
const anchorB = vec2(26,15);
|
|
110
|
-
const oA = new GameObjects.PulleyJointObjects(vec2(15,8), vec2(1,2), LJS.randColor(), anchorA);
|
|
111
|
-
const oB = new GameObjects.PulleyJointObjects(vec2(25,8), vec2(1,2), LJS.randColor(), anchorB);
|
|
112
|
-
const aA = GameObjects.spawnCircle(anchorA, 2, LJS.randColor(), LJS.box2d.bodyTypeStatic);
|
|
113
|
-
const aB = GameObjects.spawnCircle(anchorB, 2, LJS.randColor(), LJS.box2d.bodyTypeStatic);
|
|
114
|
-
const oaA = oA.localToWorld(vec2(0,oA.size.y/2));
|
|
115
|
-
const oaB = oB.localToWorld(vec2(0,oB.size.y/2));
|
|
116
|
-
new LJS.Box2dPulleyJoint(oA, oB, aA.pos, aB.pos, oaA, oaB);
|
|
117
|
-
|
|
118
|
-
// a line to make it look like connecting rope
|
|
119
|
-
const line = new LJS.EngineObject(vec2(20,15), vec2(10,.2), 0, 0, LJS.BLACK);
|
|
120
|
-
line.gravityScale = 0;
|
|
121
|
-
line.renderOrder = -1;
|
|
122
|
-
}
|
|
123
|
-
{
|
|
124
|
-
// gear joint
|
|
125
|
-
const o1 = GameObjects.spawnCircle(vec2(23.5,3), 3, LJS.randColor());
|
|
126
|
-
const j1 = new LJS.Box2dRevoluteJoint(Game.groundObject, o1, o1.pos);
|
|
127
|
-
const o2 = GameObjects.spawnCircle(vec2(28,3), 6, LJS.randColor());
|
|
128
|
-
o1.tileInfo = o2.tileInfo = Game.spriteAtlas.gear;
|
|
129
|
-
const j2 = new LJS.Box2dRevoluteJoint(Game.groundObject, o2, o2.pos);
|
|
130
|
-
new LJS.Box2dGearJoint(o1, o2, j1, j2, 2);
|
|
131
|
-
}
|
|
132
|
-
{
|
|
133
|
-
// weld joint
|
|
134
|
-
const o1 = GameObjects.spawnBox(vec2(15,2), 4, LJS.randColor());
|
|
135
|
-
const o2 = GameObjects.spawnBox(vec2(17,2), 2, LJS.randColor());
|
|
136
|
-
new LJS.Box2dWeldJoint(o1, o2);
|
|
137
|
-
}
|
|
138
|
-
{
|
|
139
|
-
// distance joint
|
|
140
|
-
const o1 = new LJS.Box2dStaticObject(vec2(30,11), vec2(4), Game.spriteAtlas.circleOutline, 0, LJS.randColor());
|
|
141
|
-
o1.renderOrder = -2;
|
|
142
|
-
const o2 = GameObjects.spawnCircle(vec2(30,8), 2, LJS.randColor());
|
|
143
|
-
new LJS.Box2dDistanceJoint(o1, o2);
|
|
144
|
-
}
|
|
145
|
-
{
|
|
146
|
-
// motor joint
|
|
147
|
-
const o = new LJS.Box2dStaticObject(vec2(10,8), vec2(4), Game.spriteAtlas.circleOutline, 0, LJS.randColor());
|
|
148
|
-
o.renderOrder = -2;
|
|
149
|
-
new GameObjects.MotorJointObject(vec2(10,8), vec2(2), LJS.randColor(), o);
|
|
150
|
-
}
|
|
151
|
-
{
|
|
152
|
-
// friction joint
|
|
153
|
-
const o = GameObjects.spawnBox(vec2(10,15), 3, LJS.randColor());
|
|
154
|
-
o.tileInfo = Game.spriteAtlas.squareOutline2;
|
|
155
|
-
o.setGravityScale(0);
|
|
156
|
-
const joint = new LJS.Box2dFrictionJoint(Game.groundObject, o);
|
|
157
|
-
joint.setMaxForce(200);
|
|
158
|
-
joint.setMaxTorque(200);
|
|
159
|
-
}
|
|
160
|
-
}
|
|
161
|
-
if (scene == 7)
|
|
162
|
-
{
|
|
163
|
-
sceneName = 'Contacts';
|
|
164
|
-
new GameObjects.ContactTester(vec2(15,8), vec2(5), LJS.RED, LJS.RED);
|
|
165
|
-
new GameObjects.ContactTester(vec2(25,8), vec2(5), LJS.CYAN, LJS.CYAN, false, false);
|
|
166
|
-
for (let i=200;i--;)
|
|
167
|
-
GameObjects.spawnRandomObject(vec2(LJS.rand(1,39), LJS.rand(10,50)));
|
|
168
|
-
}
|
|
169
|
-
if (scene == 8)
|
|
170
|
-
{
|
|
171
|
-
sceneName = 'Mobile';
|
|
172
|
-
const pos = vec2(20, 16);
|
|
173
|
-
const mobile = new GameObjects.MobileObject(pos, 12, 2, 5);
|
|
174
|
-
new LJS.Box2dRevoluteJoint(Game.groundObject, mobile, pos);
|
|
175
|
-
}
|
|
176
|
-
if (scene == 9)
|
|
177
|
-
{
|
|
178
|
-
sceneName = 'Cloth'
|
|
179
|
-
new GameObjects.ClothObject(vec2(20, 9), vec2(15), vec2(24), LJS.randColor());
|
|
180
|
-
}
|
|
181
|
-
if (scene == 10)
|
|
182
|
-
{
|
|
183
|
-
sceneName = 'Softbodies';
|
|
184
|
-
for (let i=3;i--;)
|
|
185
|
-
new GameObjects.SoftBodyObject(vec2(20, 3+i*7), vec2(6-i), vec2(9-i), LJS.randColor());
|
|
186
|
-
}
|
|
187
|
-
if (scene == 11)
|
|
188
|
-
{
|
|
189
|
-
sceneName = 'Ragdolls';
|
|
190
|
-
new GameObjects.RagdollObject(vec2(20,5));
|
|
191
|
-
new GameObjects.RagdollObject(vec2(10,8), 2);
|
|
192
|
-
GameObjects.spawnPyramid(vec2(30,0), 6);
|
|
193
|
-
}
|
|
194
|
-
}
|
package/examples/box2d/tiles.png
DELETED
|
Binary file
|
|
@@ -1,175 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
Little JS Breakout Game
|
|
3
|
-
- A simple breakout game
|
|
4
|
-
- Includes sound and particles
|
|
5
|
-
- Uses a post processing effect
|
|
6
|
-
- Control with mouse, touch, or gamepad
|
|
7
|
-
*/
|
|
8
|
-
|
|
9
|
-
'use strict';
|
|
10
|
-
|
|
11
|
-
// import LittleJS module
|
|
12
|
-
import * as LJS from '../../dist/littlejs.esm.js';
|
|
13
|
-
import * as GameObjects from './gameObjects.js';
|
|
14
|
-
const {vec2, hsl} = LJS;
|
|
15
|
-
|
|
16
|
-
///////////////////////////////////////////////////////////////////////////////
|
|
17
|
-
// game objects
|
|
18
|
-
export let ball, score, brickCount, paddle;
|
|
19
|
-
export const levelSize = vec2(38, 20);
|
|
20
|
-
|
|
21
|
-
export function changeBrickCount(delta)
|
|
22
|
-
{
|
|
23
|
-
brickCount += delta;
|
|
24
|
-
|
|
25
|
-
// increase score when brick is destroyed
|
|
26
|
-
if (delta < 0)
|
|
27
|
-
score -= delta;
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
///////////////////////////////////////////////////////////////////////////////
|
|
31
|
-
function gameReset()
|
|
32
|
-
{
|
|
33
|
-
// reset game objects
|
|
34
|
-
LJS.engineObjectsDestroy();
|
|
35
|
-
score = 0;
|
|
36
|
-
brickCount = 0;
|
|
37
|
-
|
|
38
|
-
// spawn bricks
|
|
39
|
-
const pos = vec2();
|
|
40
|
-
for (pos.x = 4; pos.x <= levelSize.x-4; pos.x += 2)
|
|
41
|
-
for (pos.y = 12; pos.y <= levelSize.y-2; pos.y += 1)
|
|
42
|
-
new GameObjects.Brick(pos);
|
|
43
|
-
|
|
44
|
-
// create walls
|
|
45
|
-
new GameObjects.Wall(vec2(-.5,levelSize.y/2), vec2(1,100)); // top
|
|
46
|
-
new GameObjects.Wall(vec2(levelSize.x+.5,levelSize.y/2), vec2(1,100)); // left
|
|
47
|
-
new GameObjects.Wall(vec2(levelSize.x/2,levelSize.y+.5), vec2(100,1)); // right
|
|
48
|
-
|
|
49
|
-
// spawn player paddle
|
|
50
|
-
paddle = new GameObjects.Paddle(vec2(levelSize.x/2-12, 1));
|
|
51
|
-
|
|
52
|
-
// reset ball
|
|
53
|
-
ball = 0;
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
///////////////////////////////////////////////////////////////////////////////
|
|
57
|
-
function gameInit()
|
|
58
|
-
{
|
|
59
|
-
LJS.setCanvasFixedSize(vec2(1920, 1080)); // 1080p
|
|
60
|
-
LJS.setCameraPos(levelSize.scale(.5)); // center camera
|
|
61
|
-
LJS.setCameraScale(48);
|
|
62
|
-
|
|
63
|
-
// set up a post processing shader
|
|
64
|
-
setupPostProcess();
|
|
65
|
-
|
|
66
|
-
// start a new game
|
|
67
|
-
gameReset();
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
///////////////////////////////////////////////////////////////////////////////
|
|
71
|
-
function gameUpdate()
|
|
72
|
-
{
|
|
73
|
-
// spawn ball
|
|
74
|
-
if (!ball && (LJS.mouseWasPressed(0) || LJS.gamepadWasPressed(0)))
|
|
75
|
-
ball = new GameObjects.Ball(vec2(levelSize.x/2, levelSize.y/2));
|
|
76
|
-
|
|
77
|
-
if (ball && ball.pos.y < -1)
|
|
78
|
-
{
|
|
79
|
-
// destroy ball if it goes below the level
|
|
80
|
-
ball.destroy();
|
|
81
|
-
ball = 0;
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
if (LJS.keyWasPressed('KeyR'))
|
|
85
|
-
gameReset();
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
///////////////////////////////////////////////////////////////////////////////
|
|
89
|
-
function gameUpdatePost()
|
|
90
|
-
{
|
|
91
|
-
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
///////////////////////////////////////////////////////////////////////////////
|
|
95
|
-
function gameRender()
|
|
96
|
-
{
|
|
97
|
-
// draw a the background
|
|
98
|
-
LJS.drawRect(LJS.cameraPos, levelSize.scale(2), hsl(0,0,.5));
|
|
99
|
-
LJS.drawRect(LJS.cameraPos, levelSize, hsl(0,0,.02));
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
///////////////////////////////////////////////////////////////////////////////
|
|
103
|
-
function gameRenderPost()
|
|
104
|
-
{
|
|
105
|
-
// use built in image font for text
|
|
106
|
-
const font = LJS.engineFontImage;
|
|
107
|
-
font.drawText('Score: ' + score, LJS.cameraPos.add(vec2(0,9.2)), 1);
|
|
108
|
-
if (!brickCount)
|
|
109
|
-
font.drawText('You Win!', LJS.cameraPos.add(vec2(0,-5)), 2);
|
|
110
|
-
else if (!ball)
|
|
111
|
-
font.drawText('Click to Play', LJS.cameraPos.add(vec2(0,-5)), 2);
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
///////////////////////////////////////////////////////////////////////////////
|
|
115
|
-
// an example shader that can be used to apply a post processing effect
|
|
116
|
-
function setupPostProcess()
|
|
117
|
-
{
|
|
118
|
-
const televisionShader = `
|
|
119
|
-
// Simple TV Shader Code
|
|
120
|
-
float hash(vec2 p)
|
|
121
|
-
{
|
|
122
|
-
p=fract(p*.3197);
|
|
123
|
-
return fract(1.+sin(51.*p.x+73.*p.y)*13753.3);
|
|
124
|
-
}
|
|
125
|
-
|
|
126
|
-
void mainImage(out vec4 c, vec2 p)
|
|
127
|
-
{
|
|
128
|
-
// setup the shader
|
|
129
|
-
vec2 uv = p;
|
|
130
|
-
p /= iResolution.xy;
|
|
131
|
-
c = texture(iChannel0, p);
|
|
132
|
-
|
|
133
|
-
// static noise
|
|
134
|
-
const float staticAlpha = .1;
|
|
135
|
-
const float staticScale = .002;
|
|
136
|
-
c += staticAlpha * hash(floor(p/staticScale) + mod(iTime*500., 1e3));
|
|
137
|
-
|
|
138
|
-
// scan lines
|
|
139
|
-
const float scanlineScale = 2.;
|
|
140
|
-
const float scanlineAlpha = .6;
|
|
141
|
-
c *= 1. - scanlineAlpha*cos(p.y*2.*iResolution.y/scanlineScale);
|
|
142
|
-
|
|
143
|
-
{
|
|
144
|
-
// bloom effect
|
|
145
|
-
const float blurSize = .002;
|
|
146
|
-
const float bloomIntensity = .2;
|
|
147
|
-
|
|
148
|
-
// 5-tap Gaussian blur
|
|
149
|
-
vec4 bloom = vec4(0);
|
|
150
|
-
bloom += texture(iChannel0, p + vec2(-2.*blurSize, 0)) * .12;
|
|
151
|
-
bloom += texture(iChannel0, p + vec2( -blurSize, 0)) * .24;
|
|
152
|
-
bloom += texture(iChannel0, p) * .28;
|
|
153
|
-
bloom += texture(iChannel0, p + vec2( blurSize, 0)) * .24;
|
|
154
|
-
bloom += texture(iChannel0, p + vec2( 2.*blurSize, 0)) * .12;
|
|
155
|
-
bloom += texture(iChannel0, p + vec2(0, -2.*blurSize)) * .12;
|
|
156
|
-
bloom += texture(iChannel0, p + vec2(0, -blurSize)) * .24;
|
|
157
|
-
bloom += texture(iChannel0, p) * .28;
|
|
158
|
-
bloom += texture(iChannel0, p + vec2(0, blurSize)) * .24;
|
|
159
|
-
bloom += texture(iChannel0, p + vec2(0, 2.*blurSize)) * .12;
|
|
160
|
-
c += bloom * bloomIntensity;
|
|
161
|
-
}
|
|
162
|
-
|
|
163
|
-
// black vignette around edges
|
|
164
|
-
const float vignette = 2.;
|
|
165
|
-
const float vignettePow = 6.;
|
|
166
|
-
float dx = 2.*p.x-1., dy = 2.*p.y-1.;
|
|
167
|
-
c *= 1.-pow((dx*dx + dy*dy)/vignette, vignettePow);
|
|
168
|
-
}`;
|
|
169
|
-
|
|
170
|
-
new LJS.PostProcessPlugin(televisionShader);
|
|
171
|
-
}
|
|
172
|
-
|
|
173
|
-
///////////////////////////////////////////////////////////////////////////////
|
|
174
|
-
// Startup LittleJS Engine
|
|
175
|
-
LJS.engineInit(gameInit, gameUpdate, gameUpdatePost, gameRender, gameRenderPost, ['tiles.png']);
|
|
@@ -1,147 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
LittleJS Breakout Objects
|
|
3
|
-
*/
|
|
4
|
-
|
|
5
|
-
'use strict';
|
|
6
|
-
|
|
7
|
-
// import LittleJS module
|
|
8
|
-
import * as LJS from '../../dist/littlejs.esm.js';
|
|
9
|
-
import * as Game from './game.js';
|
|
10
|
-
const {tile, vec2, hsl} = LJS;
|
|
11
|
-
|
|
12
|
-
///////////////////////////////////////////////////////////////////////////////
|
|
13
|
-
// sound effects
|
|
14
|
-
const sound_start = new LJS.Sound([,0,500,,.04,.3,1,2,,,570,.02,.02,,,,.04]);
|
|
15
|
-
const sound_break = new LJS.Sound([,,90,,.01,.03,4,,,,,,,9,50,.2,,.2,.01]);
|
|
16
|
-
const sound_bounce = new LJS.Sound([,,1e3,,.03,.02,1,2,,,940,.03,,,,,.2,.6,,.06]);
|
|
17
|
-
|
|
18
|
-
///////////////////////////////////////////////////////////////////////////////
|
|
19
|
-
export class PhysicsObject extends LJS.EngineObject
|
|
20
|
-
{
|
|
21
|
-
constructor(pos, size, tileInfo, angle, color)
|
|
22
|
-
{
|
|
23
|
-
super(pos, size, tileInfo, angle, color);
|
|
24
|
-
this.setCollision(); // make object collide
|
|
25
|
-
this.mass = 0; // make object have static physics
|
|
26
|
-
}
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
///////////////////////////////////////////////////////////////////////////////
|
|
30
|
-
export class Wall extends PhysicsObject
|
|
31
|
-
{
|
|
32
|
-
constructor(pos, size)
|
|
33
|
-
{
|
|
34
|
-
super(pos, size, 0, 0, hsl(0,0,0,0));
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
///////////////////////////////////////////////////////////////////////////////
|
|
39
|
-
export class Paddle extends PhysicsObject
|
|
40
|
-
{
|
|
41
|
-
constructor(pos)
|
|
42
|
-
{
|
|
43
|
-
super(pos, vec2(5,.5));
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
update()
|
|
47
|
-
{
|
|
48
|
-
// control with gamepad or mouse
|
|
49
|
-
this.pos.x = LJS.isUsingGamepad ? this.pos.x + LJS.gamepadStick(0).x : LJS.mousePos.x;
|
|
50
|
-
|
|
51
|
-
// keep paddle in bounds of level
|
|
52
|
-
this.pos.x = LJS.clamp(this.pos.x, this.size.x/2, Game.levelSize.x - this.size.x/2);
|
|
53
|
-
}
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
///////////////////////////////////////////////////////////////////////////////
|
|
57
|
-
export class Brick extends PhysicsObject
|
|
58
|
-
{
|
|
59
|
-
constructor(pos)
|
|
60
|
-
{
|
|
61
|
-
super(pos, vec2(2,1), tile(1, vec2(32,16)), 0, LJS.randColor());
|
|
62
|
-
Game.changeBrickCount(1);
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
collideWithObject(o)
|
|
66
|
-
{
|
|
67
|
-
// destroy brick when hit with ball
|
|
68
|
-
this.destroy();
|
|
69
|
-
Game.changeBrickCount(-1);
|
|
70
|
-
sound_break.play(this.pos);
|
|
71
|
-
|
|
72
|
-
// make explosion effect
|
|
73
|
-
const color1 = this.color;
|
|
74
|
-
const color2 = color1.lerp(hsl(), .5);
|
|
75
|
-
new LJS.ParticleEmitter(
|
|
76
|
-
this.pos, 0, // pos, angle
|
|
77
|
-
this.size, .1, 200, 3.14, // emitSize, emitTime, rate, cone
|
|
78
|
-
tile(0, 16), // tileIndex, tileSize
|
|
79
|
-
color1, color2, // colorStartA, colorStartB
|
|
80
|
-
color1.scale(1,0), color2.scale(1,0), // colorEndA, colorEndB
|
|
81
|
-
.3, .8, .3, .05, .05,// time, sizeStart, sizeEnd, speed, angleSpeed
|
|
82
|
-
.99, .95, .4, 3.14, // damp, angleDamp, gravity, cone
|
|
83
|
-
.1, .8, 0, 1 // fade, randomness, collide, additive
|
|
84
|
-
);
|
|
85
|
-
|
|
86
|
-
// set ball trail color
|
|
87
|
-
if (o.trailEffect)
|
|
88
|
-
{
|
|
89
|
-
o.trailEffect.colorStartA = this.color;
|
|
90
|
-
o.trailEffect.colorStartB = this.color.lerp(hsl(), .5);
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
return 1;
|
|
94
|
-
}
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
///////////////////////////////////////////////////////////////////////////////
|
|
98
|
-
export class Ball extends PhysicsObject
|
|
99
|
-
{
|
|
100
|
-
constructor(pos)
|
|
101
|
-
{
|
|
102
|
-
super(pos, vec2(.5), tile(0));
|
|
103
|
-
|
|
104
|
-
// make a bouncy ball
|
|
105
|
-
this.velocity = vec2(0, -.1);
|
|
106
|
-
this.restitution = 1;
|
|
107
|
-
this.mass = 1;
|
|
108
|
-
|
|
109
|
-
// attach a trail effect
|
|
110
|
-
const color = hsl(0,0,.2);
|
|
111
|
-
this.trailEffect = new LJS.ParticleEmitter(
|
|
112
|
-
this.pos, 0, // pos, angle
|
|
113
|
-
this.size, 0, 80, 3.14, // emitSize, emitTime, rate, cone
|
|
114
|
-
tile(0, 16), // tileIndex, tileSize
|
|
115
|
-
color, color, // colorStartA, colorStartB
|
|
116
|
-
color.scale(0), color.scale(0), // colorEndA, colorEndB
|
|
117
|
-
2, .4, 1, .001, .05,// time, sizeStart, sizeEnd, speed, angleSpeed
|
|
118
|
-
.99, .95, 0, 3.14, // damp, angleDamp, gravity, cone
|
|
119
|
-
.1, .5, 0, 1 // fade, randomness, collide, additive
|
|
120
|
-
);
|
|
121
|
-
this.addChild(this.trailEffect);
|
|
122
|
-
sound_start.play(this.pos);
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
collideWithObject(o)
|
|
126
|
-
{
|
|
127
|
-
// only need special handling when colliding with paddle
|
|
128
|
-
if (o != Game.paddle)
|
|
129
|
-
return true;
|
|
130
|
-
|
|
131
|
-
// prevent colliding with paddle if moving upwards
|
|
132
|
-
if (this.velocity.y > 0)
|
|
133
|
-
return false;
|
|
134
|
-
|
|
135
|
-
// put english on the ball when it collides with paddle
|
|
136
|
-
this.velocity = this.velocity.rotate(.2 * (o.pos.x - this.pos.x));
|
|
137
|
-
this.velocity.y = LJS.max(-this.velocity.y, .2);
|
|
138
|
-
|
|
139
|
-
// speed up
|
|
140
|
-
const speed = LJS.min(1.04*this.getSpeed(), .5);
|
|
141
|
-
this.velocity = this.velocity.normalize(speed);
|
|
142
|
-
sound_bounce.play(this.pos, 1, speed*2);
|
|
143
|
-
|
|
144
|
-
// prevent default collision code
|
|
145
|
-
return false;
|
|
146
|
-
}
|
|
147
|
-
}
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
<!DOCTYPE html><head>
|
|
2
|
-
<title>LittleJS Breakout Game</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
|
-
<script src=game.js type=module></script>
|
|
Binary file
|