littlejsengine 1.18.4 → 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.
Files changed (177) hide show
  1. package/COPYRIGHT.txt +38 -0
  2. package/FAQ.md +633 -0
  3. package/README.md +19 -1
  4. package/dist/littlejs.d.ts +349 -54
  5. package/dist/littlejs.esm.js +1469 -448
  6. package/dist/littlejs.esm.min.js +1 -1
  7. package/dist/littlejs.js +1438 -436
  8. package/dist/littlejs.min.js +1 -1
  9. package/dist/littlejs.release.js +1438 -436
  10. package/package.json +8 -1
  11. package/plugins/box2d.js +32 -7
  12. package/{src/engineMedals.js → plugins/medalSystem.js} +248 -196
  13. package/plugins/pathFinder.js +758 -0
  14. package/plugins/pluginExport.js +19 -0
  15. package/plugins/tween.js +1 -1
  16. package/plugins/tweenSystem.js +509 -0
  17. package/plugins/uiSystem.js +150 -11
  18. package/src/engine.js +2 -141
  19. package/src/engineAudio.js +8 -5
  20. package/src/engineBuild.mjs +4 -2
  21. package/src/engineDebug.js +1 -1
  22. package/src/engineDraw.js +21 -3
  23. package/src/engineExport.js +12 -12
  24. package/src/engineInput.js +1 -1
  25. package/src/engineLogo.js +146 -0
  26. package/src/engineMath.js +10 -3
  27. package/src/engineObject.js +11 -5
  28. package/src/engineParticles.js +6 -3
  29. package/src/engineRelease.js +1 -1
  30. package/src/engineSettings.js +0 -47
  31. package/src/engineUtilities.js +7 -2
  32. package/src/engineWebGL.js +34 -7
  33. package/src/jsconfig.json +3 -1
  34. package/.github/workflows/test.yml +0 -17
  35. package/AI.md +0 -173
  36. package/CLAUDE.md +0 -1
  37. package/examples/box2d/game.js +0 -192
  38. package/examples/box2d/gameObjects.js +0 -564
  39. package/examples/box2d/index.html +0 -9
  40. package/examples/box2d/scenes.js +0 -194
  41. package/examples/box2d/tiles.png +0 -0
  42. package/examples/breakout/game.js +0 -175
  43. package/examples/breakout/gameObjects.js +0 -147
  44. package/examples/breakout/index.html +0 -8
  45. package/examples/breakout/tiles.png +0 -0
  46. package/examples/breakoutTutorial/README.md +0 -521
  47. package/examples/breakoutTutorial/game.js +0 -191
  48. package/examples/breakoutTutorial/images/1.png +0 -0
  49. package/examples/breakoutTutorial/images/10.png +0 -0
  50. package/examples/breakoutTutorial/images/11.png +0 -0
  51. package/examples/breakoutTutorial/images/2.png +0 -0
  52. package/examples/breakoutTutorial/images/3.png +0 -0
  53. package/examples/breakoutTutorial/images/4.png +0 -0
  54. package/examples/breakoutTutorial/images/5.png +0 -0
  55. package/examples/breakoutTutorial/images/6.png +0 -0
  56. package/examples/breakoutTutorial/images/7.png +0 -0
  57. package/examples/breakoutTutorial/images/8.png +0 -0
  58. package/examples/breakoutTutorial/images/9.png +0 -0
  59. package/examples/breakoutTutorial/index.html +0 -8
  60. package/examples/electron/build.mjs +0 -127
  61. package/examples/electron/electron.js +0 -35
  62. package/examples/electron/game.js +0 -54
  63. package/examples/electron/index.html +0 -13
  64. package/examples/electron/package.json +0 -5
  65. package/examples/electron/tiles.png +0 -0
  66. package/examples/empty/game.js +0 -51
  67. package/examples/empty/index.html +0 -5
  68. package/examples/empty/tiles.png +0 -0
  69. package/examples/favicon.png +0 -0
  70. package/examples/games.jpg +0 -0
  71. package/examples/htmlMenu/game.js +0 -82
  72. package/examples/htmlMenu/index.html +0 -45
  73. package/examples/htmlMenu/tiles.png +0 -0
  74. package/examples/index.html +0 -62
  75. package/examples/logo.png +0 -0
  76. package/examples/logo2.png +0 -0
  77. package/examples/module/build.mjs +0 -124
  78. package/examples/module/game.js +0 -132
  79. package/examples/module/index.html +0 -10
  80. package/examples/module/tiles.png +0 -0
  81. package/examples/particles/index.html +0 -426
  82. package/examples/particles/tiles.png +0 -0
  83. package/examples/platformer/data/gameLevelData.tmx +0 -143
  84. package/examples/platformer/data/gameLevelData.tsx +0 -4
  85. package/examples/platformer/game.js +0 -147
  86. package/examples/platformer/gameCharacter.js +0 -309
  87. package/examples/platformer/gameEffects.js +0 -278
  88. package/examples/platformer/gameLevel.js +0 -205
  89. package/examples/platformer/gameLevelData.json +0 -171
  90. package/examples/platformer/gameObjects.js +0 -378
  91. package/examples/platformer/gamePlayer.js +0 -35
  92. package/examples/platformer/index.html +0 -9
  93. package/examples/platformer/tiles.png +0 -0
  94. package/examples/platformer/tilesLevel.png +0 -0
  95. package/examples/puzzle/game.js +0 -331
  96. package/examples/puzzle/index.html +0 -8
  97. package/examples/puzzle/tiles.png +0 -0
  98. package/examples/screenshot.jpg +0 -0
  99. package/examples/shorts/animation.js +0 -18
  100. package/examples/shorts/base.html +0 -54
  101. package/examples/shorts/blending.js +0 -14
  102. package/examples/shorts/box2d.js +0 -51
  103. package/examples/shorts/box2dCar.js +0 -59
  104. package/examples/shorts/box2dPool.js +0 -107
  105. package/examples/shorts/box2dTileLayer.js +0 -48
  106. package/examples/shorts/cameraDrag.js +0 -22
  107. package/examples/shorts/clock.js +0 -21
  108. package/examples/shorts/colors.js +0 -25
  109. package/examples/shorts/debugDraw.js +0 -37
  110. package/examples/shorts/empty.js +0 -30
  111. package/examples/shorts/flappyGame.js +0 -55
  112. package/examples/shorts/fontImage.js +0 -17
  113. package/examples/shorts/fps.js +0 -90
  114. package/examples/shorts/helloWorld.js +0 -11
  115. package/examples/shorts/hillGlideGame.js +0 -63
  116. package/examples/shorts/input.js +0 -64
  117. package/examples/shorts/landerGame.js +0 -57
  118. package/examples/shorts/maze.js +0 -48
  119. package/examples/shorts/medals.js +0 -51
  120. package/examples/shorts/music.js +0 -78
  121. package/examples/shorts/musicPlayer.js +0 -137
  122. package/examples/shorts/nineSlice.js +0 -40
  123. package/examples/shorts/parallax.js +0 -72
  124. package/examples/shorts/particles.js +0 -28
  125. package/examples/shorts/piano.js +0 -44
  126. package/examples/shorts/platformer.js +0 -45
  127. package/examples/shorts/pongGame.js +0 -41
  128. package/examples/shorts/postProcess.js +0 -62
  129. package/examples/shorts/sequencer.js +0 -124
  130. package/examples/shorts/shader.js +0 -29
  131. package/examples/shorts/shapes.js +0 -21
  132. package/examples/shorts/slidingPuzzle.js +0 -52
  133. package/examples/shorts/song.mp3 +0 -0
  134. package/examples/shorts/sound.js +0 -36
  135. package/examples/shorts/spaceGame.js +0 -58
  136. package/examples/shorts/spriteAtlas.js +0 -31
  137. package/examples/shorts/starfield.js +0 -15
  138. package/examples/shorts/texture.js +0 -16
  139. package/examples/shorts/textureWrapped.js +0 -12
  140. package/examples/shorts/tileLayer.js +0 -48
  141. package/examples/shorts/tileRaycast.js +0 -39
  142. package/examples/shorts/tiles.png +0 -0
  143. package/examples/shorts/tiltedView.js +0 -63
  144. package/examples/shorts/timers.js +0 -53
  145. package/examples/shorts/topDown.js +0 -38
  146. package/examples/shorts/tween.js +0 -24
  147. package/examples/shorts/uiSystem.js +0 -61
  148. package/examples/shorts/video.webm +0 -0
  149. package/examples/shorts/videoPlayer.js +0 -34
  150. package/examples/shorts.js +0 -743
  151. package/examples/starter/build.bat +0 -7
  152. package/examples/starter/build.mjs +0 -126
  153. package/examples/starter/game.js +0 -137
  154. package/examples/starter/index.html +0 -35
  155. package/examples/starter/tiles.png +0 -0
  156. package/examples/stress/index.html +0 -173
  157. package/examples/style.css +0 -150
  158. package/examples/tweenSystem/game.js +0 -171
  159. package/examples/tweenSystem/index.html +0 -10
  160. package/examples/tweenSystem/tiles.png +0 -0
  161. package/examples/typescript/build.mjs +0 -60
  162. package/examples/typescript/game.js +0 -100
  163. package/examples/typescript/game.ts +0 -132
  164. package/examples/typescript/index.html +0 -10
  165. package/examples/typescript/tiles.png +0 -0
  166. package/examples/typescript/tsconfig.json +0 -17
  167. package/examples/uiSystem/game.js +0 -139
  168. package/examples/uiSystem/index.html +0 -10
  169. package/examples/uiSystem/tiles.png +0 -0
  170. package/jsconfig.json +0 -12
  171. package/plugins/desktop.ini +0 -2
  172. package/reference.md +0 -448
  173. package/test/math.test.mjs +0 -774
  174. package/test/setup.mjs +0 -22
  175. package/test/smoke.test.mjs +0 -274
  176. package/test/tween.test.mjs +0 -576
  177. package/test/util.test.mjs +0 -80
@@ -1,29 +0,0 @@
1
- const shader = `
2
- void mainImage(out vec4 c, vec2 p)
3
- {
4
- // normalize coordinates
5
- vec2 uv = (p - iResolution.xy * .5) / iResolution.y;
6
-
7
- // get distance and angle from center
8
- float distance = length(uv);
9
- float angle = atan(uv.y, uv.x);
10
-
11
- // color based on angle and distance
12
- c.rgb = vec3(
13
- .5 + .5 * sin(angle + iTime),
14
- .5 + .5 * sin(angle + iTime * 2.),
15
- .5 + .5 * sin(distance * 5. - iTime)
16
- );
17
-
18
- // apply glow in center
19
- c += .1 / (distance + .1);
20
-
21
- // apply sine wave brightness
22
- c *= .5 + .5 * sin(distance * 20. - iTime * 3.);
23
- }
24
- `;
25
-
26
- function gameInit()
27
- {
28
- new PostProcessPlugin(shader);
29
- }
@@ -1,21 +0,0 @@
1
- function gameRender()
2
- {
3
- // circles and ellipses
4
- drawEllipse(vec2(-6,5), vec2(3,2), YELLOW, .5);
5
- drawCircle(vec2(0,5), 2+oscillate(.5), RED);
6
- drawEllipse(vec2(6,5), vec2(2,4), CLEAR_BLACK, .3, .5, CYAN)
7
-
8
- // polygon shapes
9
- drawRectGradient(vec2(-6,0), vec2(5,4), RED, BLUE)
10
- drawRegularPoly(vec2(), vec2(4), 3, PURPLE, .3, WHITE, time);
11
- let starPath = []
12
- for (let i=10; i--;)
13
- starPath.push(vec2(0,2*(i%2?.4:1)).rotate(i/10*PI*2));
14
- drawPoly(starPath, BLUE, .1, GREEN, vec2(6, 0));
15
-
16
- // rects and lines
17
- drawRect(vec2(0,-5), vec2(4,3), ORANGE, time);
18
- drawLine(vec2(-5,-7), vec2(5,-3), 1, hsl(0,0,1,.5));
19
- const zPath = [vec2(5,-3), vec2(-5,-3), vec2(5,-7), vec2(-5,-7)];
20
- drawLineList(zPath, .4, MAGENTA);
21
- }
@@ -1,52 +0,0 @@
1
- const gridSize = vec2(4,3);
2
- const pieceSize = vec2(5,4);
3
- let emptyGridPos = vec2();
4
-
5
- class PuzzlePiece extends EngineObject
6
- {
7
- constructor(gridPos, size)
8
- {
9
- const x = gridPos.x, y = gridPos.y;
10
- const color = rgb(x/(gridSize.x-1), y/(gridSize.y-1), 1);
11
- super(gridPos.multiply(size), size, 0, 0, color);
12
- this.gridPos = gridPos;
13
- this.text = x + y*gridSize.x;
14
- this.moveTimer = new Timer;
15
- this.lastPos = this.pos;
16
- }
17
-
18
- update()
19
- {
20
- const deltaX = emptyGridPos.x - this.gridPos.x;
21
- const deltaY = emptyGridPos.y - this.gridPos.y;
22
- if (mouseWasPressed(0))
23
- if (this.isOverlapping(mousePos))
24
- if (abs(deltaX) + abs(deltaY) === 1)
25
- {
26
- // swap with empty space when clicked on
27
- this.lastPos = this.pos;
28
- this.pos = emptyGridPos.multiply(this.size);
29
- [emptyGridPos, this.gridPos] = [this.gridPos, emptyGridPos];
30
- this.moveTimer.set(.2);
31
- }
32
- }
33
-
34
- render()
35
- {
36
- const movePercent = this.moveTimer.getPercent();
37
- const pos = this.lastPos.lerp(this.pos, movePercent);
38
- drawRect(pos, this.size, this.color);
39
- drawText(this.text, pos, 2.5, BLACK);
40
- }
41
- }
42
-
43
- function gameInit()
44
- {
45
- // create puzzle pieces
46
- for (let x=gridSize.x; x--;)
47
- for (let y=gridSize.y; y--;)
48
- (x||y) && new PuzzlePiece(vec2(x,y), pieceSize);
49
-
50
- // center camera on grid
51
- cameraPos = gridSize.subtract(vec2(1)).multiply(pieceSize).scale(.5);
52
- }
Binary file
@@ -1,36 +0,0 @@
1
- function gameInit()
2
- {
3
- // initialize UI system
4
- new UISystemPlugin;
5
- uiSystem.defaultShadowColor = BLACK;
6
- canvasClearColor = hsl(.6,.3,.2);
7
-
8
- // create a grid of buttons with different sounds
9
- const w = 200, h = 150, gap = 20;
10
- function makeSoundButton(pos, icon, sound)
11
- {
12
- pos = pos.multiply(vec2(w+gap, h+gap));
13
- pos = pos.add(mainCanvasSize.scale(.5));
14
- const button = new UIButton(pos, vec2(w, h), icon);
15
- button.textHeight = 100;
16
- button.onClick = ()=> sound.play();
17
- }
18
- makeSoundButton(vec2(-1, 1),'💰',
19
- new Sound([,,1675,,.06,.24,1,1.82,,,837,.06]));
20
- makeSoundButton(vec2( 0, 1),'🥊',
21
- new Sound([,,925,.04,.3,.6,1,.3,,6.27,-184,.09,.17]));
22
- makeSoundButton(vec2( 1, 1),'✨',
23
- new Sound([,,539,0,.04,.29,1,1.92,,,567,.02,.02,,,,.04]));
24
- makeSoundButton(vec2(-1, 0),'🐁',
25
- new Sound([,.2,1e3,.02,,.01,2,,18,,475,.01,.01]));
26
- makeSoundButton(vec2( 0, 0),'🎹',
27
- new Sound([1.5,.5,270,,.1,,1,1.5,,,,,,,,.1,.01]));
28
- makeSoundButton(vec2( 1, 0),'🏌️',
29
- new Sound([,,150,.05,,.05,,1.3,,,,,,3]));
30
- makeSoundButton(vec2(-1,-1),'🌊',
31
- new Sound([,.2,40,.5,,1.5,,11,,,,,,199]));
32
- makeSoundButton(vec2( 0,-1),'🛰️',
33
- new Sound([,.5,847,.02,.3,.9,1,1.67,,,-294,.04,.13,,,,.1]));
34
- makeSoundButton(vec2( 1,-1),'⚡',
35
- new Sound([,,471,,.09,.47,4,1.06,-6.7,,,,,.9,61,.1,,.82,.1]));
36
- }
@@ -1,58 +0,0 @@
1
- class Player extends EngineObject
2
- {
3
- constructor(pos)
4
- {
5
- super(pos, vec2(1,2), tile(8), 0, CYAN);
6
- this.damping = .97;
7
- this.angleDamping = .95;
8
- this.shootTimer = new Timer;
9
- }
10
-
11
- update()
12
- {
13
- // space ship controls
14
- const moveInput = keyDirection();
15
- this.applyAngularAcceleration(moveInput.x * .005);
16
- const accel = vec2().setAngle(this.angle, moveInput.y*.02);
17
- this.applyAcceleration(accel);
18
- if (!this.shootTimer.active())
19
- if (keyIsDown('Space') || mouseIsDown(0))
20
- {
21
- // shoot bullet
22
- const pos = this.pos.add(vec2(0,1).rotate(cameraAngle));
23
- const bullet = new EngineObject(pos, vec2(.2,.5), 0, this.angle);
24
- bullet.velocity = this.getUp(.5);
25
- bullet.velocity = bullet.velocity.add(this.velocity);
26
- this.shootTimer.set(.1);
27
- }
28
-
29
- // move camera with player
30
- cameraPos = this.pos;
31
- cameraAngle = this.angle;
32
- }
33
- }
34
-
35
- function gameInit()
36
- {
37
- new Player(vec2(0,4));
38
- }
39
-
40
- function gameRender()
41
- {
42
- // draw wrapped starfield with parallax
43
- const range = 32, halfRange = range/2;
44
-
45
- // precreate variables to avoid overhead
46
- const pos = vec2(), size = vec2(), color = rgb();
47
- const x = cameraPos.x, y = cameraPos.y;
48
- for (let i=1e3; i--;)
49
- {
50
- // use math to generate random star positions
51
- const parallax = i%.13-1;
52
- pos.x = mod(i**2.1 + x*parallax, range) + x - halfRange;
53
- pos.y = mod(i**3.1 + y*parallax, range) + y - halfRange;
54
- size.x = size.y = i%.07 + .03;
55
- color.a = .1+i%.9;
56
- drawRect(pos, size, color);
57
- }
58
- }
@@ -1,31 +0,0 @@
1
- function gameInit()
2
- {
3
- // create a table of all sprites
4
- const gameTile = (i, size=16)=> tile(i, size);
5
- spriteAtlas =
6
- {
7
- circle: gameTile(0),
8
- crate: gameTile(1),
9
- icon: gameTile(2),
10
- circleBig: gameTile(2, 128),
11
- iconBig: gameTile(3, 128),
12
- };
13
- canvasClearColor = GRAY;
14
- }
15
-
16
- function gameRender()
17
- {
18
- // draw a sprite from the atlas
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
25
- drawTile(pos, size, spriteAtlas.iconBig, color, angle, mirror, additive);
26
-
27
- // draw more sprites from the atlas
28
- drawTile(vec2(-7,4), vec2(5), spriteAtlas.crate);
29
- drawTile(vec2( 0,4), vec2(5), spriteAtlas.circle);
30
- drawTile(vec2( 7,4), vec2(5), spriteAtlas.circleBig);
31
- }
@@ -1,15 +0,0 @@
1
- function gameRender()
2
- {
3
- // precreate variables to avoid overhead
4
- const pos = vec2(), size = vec2(), color = rgb();
5
- for (let i=2e3; i--;)
6
- {
7
- // use math to generate random star positions
8
- const offset = time*(9+i**2.1%15) + i**2.3;
9
- pos.x = offset%70 - 35;
10
- pos.y = i/110 - 9;
11
- size.x = size.y = i%.11 + .07;
12
- color.set(1,1,1,sin(i)**4);
13
- drawRect(pos, size, color);
14
- }
15
- }
@@ -1,16 +0,0 @@
1
- function gameRender()
2
- {
3
- // show the full texture
4
- let pos = vec2(); // world position to draw
5
- let size = vec2(15); // world size of the tile
6
- let color = hsl(0,0,1); // color to multiply the tile by
7
- let tilePos = vec2(); // top left corner in pixels
8
- let tileSize = vec2(256); // source size in pixels
9
- let tileInfo = new TileInfo(tilePos, tileSize); // tile info
10
-
11
- // draw background
12
- drawRect(pos, size, GRAY);
13
-
14
- // draw the tile
15
- drawTile(pos, size, tileInfo, color);
16
- }
@@ -1,12 +0,0 @@
1
- function gameRender()
2
- {
3
- // draw a wrapped texture
4
- drawTextureWrapped(vec2(-6, 2), vec2(12, 6), vec2(3, 2));
5
-
6
- // draw red tinted wrapped and rotating
7
- drawTextureWrapped(vec2(9, 2), vec2(6, 6), vec2(2), 0, RED, time);
8
-
9
- // animated wrap count
10
- const wraps = 2 - sin(time);
11
- drawTextureWrapped(vec2(0, -5), vec2(12, 4), vec2(wraps, 1/16));
12
- }
@@ -1,48 +0,0 @@
1
- function gameInit()
2
- {
3
- cameraPos = vec2(16); // setup camera
4
- gravity.y = -.01; // enable gravity
5
- canvasClearColor = hsl(0,0,.2); // background color
6
-
7
- // create tile layer
8
- const pos = vec2();
9
- const tileLayer = new TileCollisionLayer(pos, vec2(32));
10
- for (pos.x = tileLayer.size.x; pos.x--;)
11
- for (pos.y = tileLayer.size.y; pos.y--;)
12
- {
13
- // check if tile should be solid
14
- if (randBool(.7))
15
- continue;
16
-
17
- // set tile data
18
- const tileIndex = 11;
19
- const direction = randInt(4)
20
- const mirror = randBool();
21
- const color = randColor(WHITE, hsl(0,0,.2));
22
- const data = new TileLayerData(tileIndex, direction, mirror, color);
23
- tileLayer.setData(pos, data);
24
- tileLayer.setCollisionData(pos);
25
- }
26
- tileLayer.redraw(); // redraw tile layer with new data
27
- }
28
-
29
- function gameUpdate()
30
- {
31
- if (mouseWasPressed(0))
32
- {
33
- // create particle emitter to test the collision
34
- const hue = rand();
35
- const particleEmitter = new ParticleEmitter(
36
- mousePos, 0,
37
- 0, 0.1, 500, PI,
38
- tile(0, 16),
39
- hsl(hue,1,.5), hsl(hue,1,1),
40
- hsl(hue,1,.5,0), hsl(hue,1,1,0),
41
- 2, .2, .2, .2, .05,
42
- .99, 1, 1, PI,
43
- .05, .8, true
44
- );
45
- particleEmitter.restitution = .5; // bounce when it collides
46
- particleEmitter.trailScale = 2; // stretch as it moves
47
- }
48
- }
@@ -1,39 +0,0 @@
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
@@ -1,63 +0,0 @@
1
- class GameObject extends EngineObject
2
- {
3
- update()
4
- {
5
- this.renderOrder = -this.pos.y; // sort by y position
6
- }
7
-
8
- render()
9
- {
10
- // adjust draw position to be at the bottom of the object
11
- const drawSize = this.drawSize || this.size;
12
- const offset = this.getUp(drawSize.y/2);
13
- const pos = this.pos.add(offset);
14
- drawTile(pos, drawSize, this.tileInfo, this.color, this.angle);
15
- }
16
- }
17
-
18
- class Player extends GameObject
19
- {
20
- update()
21
- {
22
- super.update();
23
-
24
- // apply movement controls
25
- const moveInput = keyDirection().clampLength(1).scale(.2);
26
- this.velocity = this.velocity.add(moveInput);
27
- this.setCollision(); // make object collide
28
-
29
- // move camera with player
30
- cameraPos = this.pos.add(vec2(0,2));
31
- }
32
- }
33
-
34
- function gameInit()
35
- {
36
- // setup level
37
- objectDefaultDamping = .7;
38
- const player = new Player(vec2(), vec2(3,1), tile(5), 0, RED);
39
- player.drawSize = vec2(3);
40
-
41
- // create background objects
42
- for (let i=1; i<300; ++i)
43
- {
44
- const pos = randInCircle(90);
45
- const size = vec2(rand(59), rand(59));
46
- const color = hsl(.4,.2,rand(.4,.5),.8);
47
- new EngineObject(pos, size, 0, 0, color, -1e5);
48
- }
49
-
50
- // create world objects
51
- for (let i=1; i<1e3; ++i)
52
- {
53
- const pos = randInCircle(7+i,7);
54
- const isRock = randBool();
55
- const size = vec2(isRock ? rand(2,4) : rand(1,2));
56
- const color = hsl(.1,isRock ? 0 : .5,rand(.2,.3));
57
- const o = new GameObject(pos, size, 0, 0, color);
58
- o.setCollision(); // make object collide
59
- o.mass = 0; // make object have static physics
60
- o.angle = rand(-.1,.1); // random tilt
61
- o.drawSize = vec2(size.x, isRock ? rand(2,4) : rand(5,10));
62
- }
63
- }
@@ -1,53 +0,0 @@
1
- const timerSound = new Sound([2,0,999,,,,,1.5,,.3,-99,.1,1.63,,,.11]);
2
-
3
- function gameInit()
4
- {
5
- // setup ui system plugin
6
- new UISystemPlugin();
7
- uiSystem.defaultCornerRadius = 10;
8
- uiSystem.defaultShadowColor = BLACK;
9
- canvasClearColor = hsl(.3,.3,.2);
10
-
11
- // create timer button
12
- const pos = mainCanvasSize.scale(.5).add(vec2(0, -40));
13
- timerButton = new UIButton(pos, vec2(200, 90), 'Start');
14
- timerButton.timer = new Timer;
15
- timerButton.onClick = ()=>
16
- {
17
- timerButton.isSet = true;
18
- if (timerButton.timer.isSet())
19
- {
20
- timerSound.play(0, .5, 2);
21
- timerButton.timer.unset();
22
- timerButton.text = 'Start';
23
- }
24
- else
25
- {
26
- timerSound.play(0, .5, .5);
27
- timerButton.timer.set(3);
28
- timerButton.text = 'Stop';
29
- }
30
- }
31
-
32
- // create non-interactive slider to display timer
33
- timerSlider = new UISlider(vec2(0, 100), vec2(400, 50));
34
- timerSlider.interactive = false;
35
- timerSlider.update = ()=>
36
- {
37
- if (timerButton.isSet && timerButton.timer.elapsed())
38
- {
39
- timerSound.play();
40
- timerButton.isSet = 0;
41
- }
42
-
43
- // update the timer display
44
- const t = timerButton.timer.get();
45
- const timeText = t.toFixed(2) + 's';
46
- const isSet = timerButton.timer.isSet();
47
- const setTime = timerButton.timer.getSetTime();
48
- timerSlider.text = timeText;
49
- timerSlider.value = setTime ? 1+t/setTime : 1;
50
- timerSlider.color = isSet ? t < 0 ? CYAN : RED : GRAY;
51
- }
52
- timerButton.addChild(timerSlider);
53
- }
@@ -1,38 +0,0 @@
1
- class Player extends EngineObject
2
- {
3
- constructor(pos)
4
- {
5
- super(pos, vec2(2), tile(5), 0, RED);
6
- this.setCollision(); // make object collide
7
- this.renderOrder = 1; // render player on top
8
- }
9
-
10
- update()
11
- {
12
- // apply movement controls
13
- const moveInput = keyDirection().clampLength(1).scale(.2);
14
- this.velocity = this.velocity.add(moveInput);
15
-
16
- // move camera with player
17
- cameraPos = this.pos;
18
- }
19
- }
20
-
21
- function gameInit()
22
- {
23
- // setup level
24
- canvasClearColor = hsl(.3,.2,.6);
25
- objectDefaultDamping = .7;
26
- new Player;
27
-
28
- // create collision objects
29
- for (let i=300; i--;)
30
- {
31
- const pos = randInCircle(15+i,7);
32
- const size = vec2(rand(4,9),rand(4,9));
33
- const color = hsl(.1,.5,rand(.2));
34
- const o = new EngineObject(pos, size, 0, 0, color);
35
- o.setCollision(); // make object collide
36
- o.mass = 0; // make object have static physics
37
- }
38
- }
@@ -1,24 +0,0 @@
1
- const slider = { pos: vec2(-3, 1) };
2
- const pulser = { color: RED };
3
- let bouncerY = 4;
4
-
5
- function gameInit()
6
- {
7
- // tween using the Tween class directly
8
- new Tween((y) => bouncerY = y, 4, -3, 1.5,
9
- { ease: Ease.OUT(Ease.BOUNCE) }).pingPong();
10
-
11
- // tweens using tweenProperty helper
12
- tweenProperty(slider, 'pos', vec2(-3, 1), vec2(3, -1), 2,
13
- { ease: Ease.IN_OUT(Ease.SINE) }).pingPong();
14
-
15
- // tween using built in color class
16
- tweenProperty(pulser, 'color', RED, BLUE, 1).pingPong();
17
- }
18
-
19
- function gameRender()
20
- {
21
- drawRect(vec2(-6, bouncerY), vec2(2), GREEN);
22
- drawRect(slider.pos, vec2(2), CYAN);
23
- drawRect(vec2(6, 0), vec2(2), pulser.color);
24
- }
@@ -1,61 +0,0 @@
1
- function gameInit()
2
- {
3
- // setup ui system plugin
4
- new UISystemPlugin;
5
- uiSystem.defaultSoundPress = new Sound([.5,0,220]);
6
- uiSystem.defaultSoundClick = new Sound([.5,0,440]);
7
- uiSystem.defaultCornerRadius = 8;
8
- uiSystem.defaultShadowColor = BLACK;
9
-
10
- // setup example menu
11
- let navigationIndex = 0;
12
- const uiMenu = new UIObject(mainCanvasSize.scale(.5), vec2(700,450));
13
- canvasClearColor = hsl(0,0,.8);
14
-
15
- // example text
16
- uiMenu.addChild(new UIText(vec2(-100,-120), vec2(450, 80),
17
- 'LittleJS UI\nSystem Demo'));
18
-
19
- // example image
20
- uiMenu.addChild(new UITile(vec2(230,-140), vec2(170), tile(3, 128)));
21
-
22
- // example checkbox
23
- const checkbox = new UICheckbox(vec2(-170,0), vec2(50));
24
- checkbox.navigationIndex = ++navigationIndex;
25
- checkbox.onChange = ()=> button1.disabled = checkbox.checked;
26
- uiMenu.addChild(checkbox);
27
-
28
- // example button
29
- const textInput = new UITextInput(vec2(50,0), vec2(300, 80), 'Text Input');
30
- textInput.textHeight = 60;
31
- textInput.maxLength = 16;
32
- textInput.navigationIndex = ++navigationIndex;
33
- uiMenu.addChild(textInput);
34
- textInput.onChange = ()=> canvasClearColor = randColor();
35
-
36
- // example slider
37
- const slider = new UISlider(vec2(0,90), vec2(400, 50),
38
- soundVolume, 'Volume');
39
- slider.navigationIndex = ++navigationIndex;
40
- uiMenu.addChild(slider);
41
- slider.onChange = ()=> setSoundVolume(slider.value);
42
-
43
- // exit button
44
- const button1 = new UIButton(vec2(0,170), vec2(200, 50), 'Exit Menu');
45
- button1.textHeight = 40;
46
- button1.navigationIndex = ++navigationIndex;
47
- button1.navigationAutoSelect = true;
48
- uiMenu.addChild(button1);
49
- button1.onClick = ()=> uiSystem.showConfirmDialog('Exit menu?',
50
- ()=> { uiMenu.visible=false; buttonBack.visible=true; });
51
-
52
- // example button that returns to menu
53
- const buttonBack = new UIButton(mainCanvasSize.scale(.5), vec2(200),
54
- 'Back\nto\nMenu');
55
- buttonBack.visible = false;
56
- buttonBack.textHeight = 60;
57
- buttonBack.navigationIndex = ++navigationIndex;
58
- buttonBack.navigationAutoSelect = true;
59
- buttonBack.onClick = ()=>
60
- { uiMenu.visible=true; buttonBack.visible=false; }
61
- }
Binary file
@@ -1,34 +0,0 @@
1
- function gameInit()
2
- {
3
- new UISystemPlugin;
4
- uiSystem.defaultCornerRadius = 20;
5
- uiSystem.defaultShadowColor = BLACK;
6
- canvasClearColor = hsl(0,0,.1);
7
-
8
- // video player
9
- const center = mainCanvasSize.scale(.5);
10
- const videoPos = center.add(vec2(0, -50));
11
- const videoSize = vec2(480, 270);
12
- const filename = 'video.webm';
13
- const autoplay = true;
14
- videoPlayer = new UIVideo(videoPos, videoSize, filename, autoplay);
15
- videoPlayer.lineWidth = 5;
16
- videoPlayer.lineColor = WHITE;
17
-
18
- // play/pause button
19
- const buttonSize = vec2(200, 100);
20
- const playButtonPos = center.add(vec2(-130, 170));
21
- const playButton = new UIButton(playButtonPos, buttonSize);
22
- playButton.onClick = ()=> videoPlayer.isPaused() ?
23
- videoPlayer.play() : videoPlayer.pause();
24
- playButton.onUpdate = ()=> playButton.text =
25
- videoPlayer.isPaused() ? 'Play' : 'Pause';
26
-
27
- // status text
28
- const statusTextPos = center.add(vec2(130, 170));
29
- const statusText = new UIText(statusTextPos, vec2(250, 90));
30
- statusText.textColor = WHITE;
31
- statusText.onUpdate = ()=> statusText.text =
32
- videoPlayer.hasEnded() ? 'Ended' :
33
- videoPlayer.isPlaying() ? 'Playing' : 'Paused';
34
- }