littlejsengine 1.13.1 → 1.14.2

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 (83) hide show
  1. package/README.md +15 -11
  2. package/copyToGithub.bat +28 -0
  3. package/dist/littlejs.d.ts +430 -304
  4. package/dist/littlejs.esm.js +1745 -982
  5. package/dist/littlejs.esm.min.js +1 -1
  6. package/dist/littlejs.js +1716 -965
  7. package/dist/littlejs.min.js +1 -1
  8. package/dist/littlejs.release.js +1673 -922
  9. package/examples/box2d/game.js +2 -2
  10. package/examples/box2d/gameObjects.js +2 -2
  11. package/examples/box2d/scenes.js +1 -1
  12. package/examples/breakout/game.js +30 -25
  13. package/examples/breakoutTutorial/README.md +44 -41
  14. package/examples/breakoutTutorial/game.js +2 -2
  15. package/examples/electron/build.bat +7 -0
  16. package/examples/electron/build.js +124 -0
  17. package/examples/electron/electron.js +35 -0
  18. package/examples/electron/game.js +140 -0
  19. package/examples/electron/index.html +13 -0
  20. package/examples/electron/package.json +12 -0
  21. package/examples/electron/tiles.png +0 -0
  22. package/examples/empty/game.js +1 -0
  23. package/examples/htmlMenu/game.js +1 -1
  24. package/examples/index.html +332 -160
  25. package/examples/module/game.js +5 -2
  26. package/examples/particles/index.html +12 -3
  27. package/examples/platformer/gameEffects.js +20 -19
  28. package/examples/platformer/gameLevel.js +6 -1
  29. package/examples/shorts/base.html +1 -1
  30. package/examples/shorts/blending.js +9 -5
  31. package/examples/shorts/box2d.js +1 -1
  32. package/examples/shorts/box2dCar.js +1 -1
  33. package/examples/shorts/clock.js +1 -1
  34. package/examples/shorts/colors.js +2 -2
  35. package/examples/shorts/flappyGame.js +2 -1
  36. package/examples/shorts/helloWorld.js +1 -1
  37. package/examples/shorts/maze.js +1 -1
  38. package/examples/shorts/music.js +106 -0
  39. package/examples/shorts/nineSlice.js +9 -9
  40. package/examples/shorts/parallax.js +71 -0
  41. package/examples/shorts/piano.js +9 -10
  42. package/examples/shorts/postProcess.js +25 -8
  43. package/examples/shorts/raycasting.js +2 -2
  44. package/examples/shorts/shapes.js +7 -15
  45. package/examples/shorts/slidingPuzzle.js +2 -2
  46. package/examples/shorts/song.mp3 +0 -0
  47. package/examples/shorts/starfield.js +5 -7
  48. package/examples/shorts/systemFont.js +1 -1
  49. package/examples/shorts/uiSystem.js +16 -8
  50. package/examples/starter/build.js +9 -8
  51. package/examples/starter/game.js +5 -2
  52. package/examples/starter/index.html +2 -2
  53. package/examples/stress/index.html +13 -8
  54. package/examples/style.css +19 -6
  55. package/examples/typescript/build.js +1 -1
  56. package/examples/typescript/game.js +2 -2
  57. package/examples/typescript/game.ts +5 -2
  58. package/examples/uiSystem/game.js +13 -12
  59. package/package.json +2 -2
  60. package/plugins/box2d.js +24 -97
  61. package/plugins/drawUtilities.js +29 -23
  62. package/plugins/newgrounds.js +6 -6
  63. package/plugins/pluginExport.js +1 -1
  64. package/plugins/postProcess.js +7 -0
  65. package/plugins/uiSystem.js +106 -82
  66. package/plugins/zzfxm.js +10 -10
  67. package/reference.md +90 -54
  68. package/src/engine.js +28 -23
  69. package/src/engineAudio.js +285 -110
  70. package/src/engineBuild.js +9 -9
  71. package/src/engineDebug.js +28 -28
  72. package/src/engineDraw.js +346 -202
  73. package/src/engineExport.js +28 -16
  74. package/src/engineInput.js +58 -68
  75. package/src/engineMedals.js +29 -29
  76. package/src/engineObject.js +28 -25
  77. package/src/engineParticles.js +67 -60
  78. package/src/engineRelease.js +1 -1
  79. package/src/engineSettings.js +70 -16
  80. package/src/engineTileLayer.js +34 -34
  81. package/src/engineUtilities.js +69 -62
  82. package/src/engineWebGL.js +467 -65
  83. /package/examples/shorts/{playSound.js → sound.js} +0 -0
@@ -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?1136></script>
11
+
12
+ <!-- Add your game scripts here -->
13
+ <script src=game.js?1136></script>
@@ -0,0 +1,12 @@
1
+ {
2
+ "name": "littlejsgame",
3
+ "version": "1.0.0",
4
+ "main": "electron.js",
5
+ "scripts": {
6
+ "build": "node build.js"
7
+ },
8
+ "devDependencies": {
9
+ "electron": "^38.2.0",
10
+ "electron-packager": "^17.1.2"
11
+ }
12
+ }
Binary file
@@ -8,6 +8,7 @@
8
8
 
9
9
  // import LittleJS module
10
10
  import * as LJS from '../../dist/littlejs.esm.js';
11
+ const {vec2, rgb} = LJS;
11
12
 
12
13
  ///////////////////////////////////////////////////////////////////////////////
13
14
  function gameInit()
@@ -61,7 +61,7 @@ function gameRender()
61
61
  {
62
62
  // test game rendering
63
63
  LJS.drawRect(vec2(), vec2(1e3), hsl(0,0,.2));
64
- for(let i=0; i<1e3; ++i)
64
+ for (let i=0; i<1e3; ++i)
65
65
  {
66
66
  const time = LJS.time;
67
67
  const pos = vec2(30*Math.sin(i+time/9),20*Math.sin(i*i+time/9));