littlejsengine 1.11.13 → 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.
Files changed (79) hide show
  1. package/dist/littlejs.d.ts +1418 -109
  2. package/dist/littlejs.esm.js +3495 -581
  3. package/dist/littlejs.esm.min.js +1 -1
  4. package/dist/littlejs.js +3258 -399
  5. package/dist/littlejs.min.js +1 -1
  6. package/dist/littlejs.release.js +3147 -379
  7. package/examples/box2d/game.js +73 -45
  8. package/examples/box2d/gameObjects.js +96 -92
  9. package/examples/box2d/index.html +2 -7
  10. package/examples/box2d/scenes.js +82 -92
  11. package/examples/breakout/game.js +62 -30
  12. package/examples/breakout/gameObjects.js +45 -47
  13. package/examples/breakout/index.html +1 -5
  14. package/examples/breakoutTutorial/game.js +36 -29
  15. package/examples/breakoutTutorial/index.html +1 -3
  16. package/examples/empty/game.js +5 -2
  17. package/examples/empty/index.html +1 -3
  18. package/examples/htmlMenu/game.js +25 -19
  19. package/examples/htmlMenu/index.html +5 -7
  20. package/examples/index.html +2 -3
  21. package/examples/module/game.js +32 -34
  22. package/examples/module/index.html +1 -1
  23. package/examples/particles/index.html +27 -22
  24. package/examples/platformer/game.js +71 -48
  25. package/examples/platformer/gameCharacter.js +42 -34
  26. package/examples/platformer/gameEffects.js +82 -75
  27. package/examples/platformer/gameLevel.js +67 -38
  28. package/examples/platformer/{gameLevelData.js → gameLevelData.json} +1 -11
  29. package/examples/platformer/gameObjects.js +70 -64
  30. package/examples/platformer/gamePlayer.js +12 -7
  31. package/examples/platformer/index.html +1 -9
  32. package/examples/puzzle/game.js +58 -42
  33. package/examples/puzzle/index.html +1 -3
  34. package/examples/shorts/base.html +2 -2
  35. package/examples/shorts/particles.js +1 -1
  36. package/examples/shorts/platformer.js +1 -1
  37. package/examples/shorts/tileLayer.js +5 -6
  38. package/examples/shorts/tiles.png +0 -0
  39. package/examples/starter/build.js +4 -4
  40. package/examples/starter/game.js +9 -12
  41. package/examples/starter/index.html +13 -13
  42. package/examples/stress/index.html +44 -43
  43. package/examples/typescript/build.js +17 -18
  44. package/examples/typescript/game.js +32 -34
  45. package/examples/typescript/game.ts +32 -34
  46. package/examples/typescript/index.html +1 -1
  47. package/examples/uiSystem/game.js +33 -36
  48. package/examples/uiSystem/index.html +1 -5
  49. package/package.json +3 -3
  50. package/plugins/box2d.js +1556 -640
  51. package/plugins/{Box2D_v2.3.1_min.wasm.js → box2d.wasm.js} +1 -1
  52. package/plugins/newgrounds.js +7 -8
  53. package/plugins/pluginExport.js +50 -0
  54. package/plugins/postProcess.js +94 -93
  55. package/plugins/uiSystem.js +145 -161
  56. package/plugins/zzfxm.js +163 -0
  57. package/reference.md +29 -27
  58. package/src/engine.js +15 -20
  59. package/src/engineAudio.js +74 -204
  60. package/src/engineBuild.js +29 -4
  61. package/src/engineDebug.js +105 -9
  62. package/src/engineDraw.js +27 -14
  63. package/src/engineExport.js +12 -8
  64. package/src/engineInput.js +3 -1
  65. package/src/engineObject.js +18 -14
  66. package/src/engineParticles.js +6 -1
  67. package/src/engineRelease.js +6 -1
  68. package/src/engineSettings.js +8 -8
  69. package/src/engineTileLayer.js +179 -96
  70. package/src/engineUtilities.js +5 -11
  71. package/src/engineWebGL.js +19 -7
  72. package/examples/starter/build/index.html +0 -2
  73. package/examples/starter/build/index.js +0 -1
  74. package/examples/starter/build/tiles.png +0 -0
  75. package/examples/starter/game.zip +0 -0
  76. package/examples/typescript/build/dist/littlejs.esm.js +0 -4834
  77. package/examples/typescript/build/examples/typescript/build.js +0 -24
  78. package/examples/typescript/build/examples/typescript/game.js +0 -102
  79. /package/plugins/{Box2D_v2.3.1_min.wasm.wasm → box2d.wasm.wasm} +0 -0
@@ -6,22 +6,22 @@
6
6
 
7
7
  'use strict';
8
8
 
9
- // import module
10
- import * as LittleJS from '../../dist/littlejs.esm.js';
11
- const {tile, vec2, hsl} = LittleJS;
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
- LittleJS.setShowSplashScreen(true);
14
+ LJS.setShowSplashScreen(true);
15
15
 
16
16
  // fix texture bleeding by shrinking tile slightly
17
- LittleJS.setTileFixBleedScale(.5);
17
+ LJS.setTileFixBleedScale(.5);
18
18
 
19
19
  // sound effects
20
- const sound_click = new LittleJS.Sound([1,.5]);
20
+ const sound_click = new LJS.Sound([1,.5]);
21
21
 
22
22
  // medals
23
- const medal_example = new LittleJS.Medal(0, 'Example Medal', 'Welcome to LittleJS!');
24
- LittleJS.medalsInit('Hello World');
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 LittleJS.TileLayer(pos, tileCollisionSize);
34
+ const tileLayer = new LJS.TileCollisionLayer(pos, vec2(32,16));
37
35
 
38
36
  // get level data from the tiles image
39
- const mainContext = LittleJS.mainContext;
40
- const tileImage = LittleJS.textureInfos[0].image;
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 = tileCollisionSize.x; pos.x--;)
44
- for (pos.y = tileCollisionSize.y; 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 + tileCollisionSize.y - pos.y);
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 = LittleJS.randInt(4)
54
- const mirror = !LittleJS.randInt(2);
55
- const color = LittleJS.randColor();
56
- const data = new LittleJS.TileLayerData(tileIndex, direction, mirror, color);
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
- LittleJS.setTileCollisionData(pos, 1);
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
- LittleJS.setCameraPos(tileCollisionSize.scale(.5));
66
- LittleJS.setCameraScale(32);
63
+ LJS.setCameraPos(tileLayer.size.scale(.5));
64
+ LJS.setCameraScale(32);
67
65
 
68
66
  // enable gravity
69
- LittleJS.setGravity(-.01);
67
+ LJS.setGravity(vec2(0,-.01));
70
68
 
71
69
  // create particle emitter
72
- particleEmitter = new LittleJS.ParticleEmitter(
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 (LittleJS.mouseWasPressed(0))
87
+ if (LJS.mouseWasPressed(0))
90
88
  {
91
89
  // play sound when mouse is pressed
92
- sound_click.play(LittleJS.mousePos);
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 = LittleJS.randColor();
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 (LittleJS.mousePosScreen.x)
106
- particleEmitter.pos = LittleJS.mousePos;
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
- LittleJS.drawRect(vec2(16,8), vec2(20,14), hsl(0,0,.6), 0, false);
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
- LittleJS.drawTile(vec2(21,5), vec2(4.5), tile(3,128));
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
- LittleJS.drawTextScreen('LittleJS with TypeScript', vec2(LittleJS.mainCanvasSize.x/2, 80), 80);
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
- LittleJS.engineInit(gameInit, gameUpdate, gameUpdatePost, gameRender, gameRenderPost, ['tiles.png']);
132
+ LJS.engineInit(gameInit, gameUpdate, gameUpdatePost, gameRender, gameRenderPost, ['tiles.png']);
@@ -7,4 +7,4 @@
7
7
  </head><body>
8
8
 
9
9
  <!-- Add your game scripts here -->
10
- <script src=game.js type=module></script>
10
+ <script src=game.js type=module></script>
@@ -6,11 +6,12 @@
6
6
 
7
7
  'use strict';
8
8
 
9
- // show the LittleJS splash screen
10
- setShowSplashScreen(true);
9
+ // import LittleJS module
10
+ import * as LJS from '../../dist/littlejs.esm.js';
11
+ const {vec2, hsl, tile} = LJS;
11
12
 
12
13
  // sound effects
13
- const sound_ui = new Sound([1,0]);
14
+ const sound_ui = new LJS.Sound([1,0]);
14
15
 
15
16
  // UI system
16
17
  let uiRoot, uiMenu;
@@ -18,43 +19,43 @@ const getMenuVisible =()=> uiMenu.visible;
18
19
  const setMenuVisible =(visible)=> uiMenu.visible = visible;
19
20
 
20
21
  // use a fixed size canvas
21
- canvasFixedSize = vec2(1920, 1080); // 1080p
22
- canvasPixelated = false;
22
+ LJS.setCanvasFixedSize(vec2(1920, 1080)); // 1080p
23
+ LJS.setCanvasPixelated(false);
23
24
 
24
25
  function createUI()
25
26
  {
26
27
  // setup root to attach all ui elements to
27
- uiRoot = new UIObject();
28
- 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),
29
30
  'LittleJS UI System Example\nM = Toggle menu');
30
- uiInfo.textColor = WHITE;
31
+ uiInfo.textColor = LJS.WHITE;
31
32
  uiInfo.lineWidth = 8;
32
33
  uiRoot.addChild(uiInfo);
33
34
 
34
35
  // setup example menu
35
- uiMenu = new UIObject(vec2(0,450));
36
+ uiMenu = new LJS.UIObject(vec2(0,450));
36
37
  uiRoot.addChild(uiMenu);
37
- const uiBackground = new UIObject(vec2(0,0), vec2(450,580));
38
+ const uiBackground = new LJS.UIObject(vec2(0,0), vec2(450,580));
38
39
  uiBackground.lineWidth = 8;
39
40
  uiMenu.addChild(uiBackground);
40
41
 
41
42
  // example large text
42
- 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');
43
44
  uiMenu.addChild(textTitle);
44
- textTitle.textColor = RED;
45
+ textTitle.textColor = LJS.RED;
45
46
  textTitle.lineWidth = 4;
46
- textTitle.lineColor = BLUE;
47
+ textTitle.lineColor = LJS.BLUE;
47
48
 
48
49
  // example multiline text
49
- 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.')
50
51
  uiMenu.addChild(textTest);
51
52
 
52
53
  // example tile image
53
- 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))
54
55
  uiMenu.addChild(tileTest);
55
56
 
56
57
  // example checkbox
57
- const checkbox = new UICheckbox(vec2(-140,-20), vec2(40));
58
+ const checkbox = new LJS.UICheckbox(vec2(-140,-20), vec2(40));
58
59
  uiMenu.addChild(checkbox);
59
60
  checkbox.onPress = ()=>
60
61
  {
@@ -64,18 +65,18 @@ function createUI()
64
65
  }
65
66
 
66
67
  // text attached to checkbox
67
- 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');
68
69
  checkbox.addChild(checkboxText);
69
70
 
70
71
  // example scrollbar
71
- const scrollbar = new UIScrollbar(vec2(0,60), vec2(350, 50));
72
+ const scrollbar = new LJS.UIScrollbar(vec2(0,60), vec2(350, 50));
72
73
  uiMenu.addChild(scrollbar);
73
74
  scrollbar.onChange = ()=> console.log('New scrollbar value:', scrollbar.value);
74
75
  scrollbar.onPress = ()=> sound_ui.play(0,.3,2);
75
76
  scrollbar.onRelease = ()=> sound_ui.play(0,.3,4);
76
77
 
77
78
  // example button
78
- 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');
79
80
  uiMenu.addChild(button1);
80
81
  button1.onPress = ()=>
81
82
  {
@@ -84,7 +85,7 @@ function createUI()
84
85
  }
85
86
 
86
87
  // exit button
87
- 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');
88
89
  uiMenu.addChild(button2);
89
90
  button2.onPress = ()=>
90
91
  {
@@ -97,7 +98,7 @@ function createUI()
97
98
  ///////////////////////////////////////////////////////////////////////////////
98
99
  function gameInit()
99
100
  {
100
- initUISystem();
101
+ new LJS.UISystemPlugin;
101
102
  createUI();
102
103
  }
103
104
 
@@ -109,30 +110,26 @@ function gameUpdate()
109
110
  ///////////////////////////////////////////////////////////////////////////////
110
111
  function gameUpdatePost()
111
112
  {
112
- // center ui
113
- uiRoot.pos.x = mainCanvasSize.x/2;
113
+ // toggle menu visibility
114
+ if (LJS.keyWasPressed('KeyM'))
115
+ setMenuVisible(!getMenuVisible());
114
116
 
115
- // menu system
116
- const menuVisible = getMenuVisible();
117
- paused = menuVisible;
117
+ // center ui
118
+ uiRoot.pos.x = LJS.mainCanvasSize.x/2;
118
119
 
119
- // toggle menu visibility
120
- if (keyWasPressed('KeyM'))
121
- setMenuVisible(!menuVisible);
120
+ // pause when menu is visible
121
+ LJS.setPaused(getMenuVisible())
122
122
  }
123
123
 
124
124
  ///////////////////////////////////////////////////////////////////////////////
125
125
  function gameRender()
126
126
  {
127
127
  // test game rendering
128
- drawRect(vec2(), vec2(1e3), hsl(0,0,.2));
129
-
130
- // test game rendering
131
- drawRect(vec2(), vec2(1e3), hsl(0,0,.2));
128
+ LJS.drawRect(vec2(), vec2(1e3), hsl(0,0,.2));
132
129
  for(let i=0; i<1e3; ++i)
133
130
  {
134
- const pos = vec2(30*Math.sin(i+time/9),20*Math.sin(i*i+time/9));
135
- 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));
136
133
  }
137
134
  }
138
135
 
@@ -143,4 +140,4 @@ function gameRenderPost()
143
140
 
144
141
  ///////////////////////////////////////////////////////////////////////////////
145
142
  // Startup LittleJS Engine
146
- 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?1117></script>
11
-
12
9
  <!-- Add your game scripts here -->
13
- <script src=../../plugins/uiSystem.js?1117></script>
14
- <script src=game.js?1117></script>
10
+ <script src=game.js type=module></script>
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "littlejsengine",
3
- "version": "1.11.13",
3
+ "version": "1.12.4",
4
4
  "description": "LittleJS - Tiny and Fast HTML5 Game Engine",
5
5
  "main": "dist/littlejs.esm.js",
6
6
  "types": "dist/littlejs.d.ts",
@@ -33,10 +33,10 @@
33
33
  "build": "node src/engineBuild.js"
34
34
  },
35
35
  "devDependencies": {
36
+ "bestzip": "^2.2.1",
36
37
  "google-closure-compiler": "~20230502.0.0",
37
38
  "roadroller": "~2.1.0",
38
- "uglify-js": "~3.17.4",
39
39
  "typescript": "~5.1.6",
40
- "ect-bin": "~1.4.1"
40
+ "uglify-js": "~3.17.4"
41
41
  }
42
42
  }