littlejsengine 1.11.2 → 1.11.5

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 (73) hide show
  1. package/.vscode/launch.json +14 -0
  2. package/README.md +16 -18
  3. package/dist/littlejs.d.ts +41 -30
  4. package/dist/littlejs.esm.js +165 -143
  5. package/dist/littlejs.esm.min.js +1 -1
  6. package/dist/littlejs.js +161 -142
  7. package/dist/littlejs.min.js +1 -1
  8. package/dist/littlejs.release.js +157 -135
  9. package/examples/box2d/gameObjects.js +4 -4
  10. package/examples/box2d/scenes.js +2 -2
  11. package/examples/breakout/game.js +1 -1
  12. package/examples/breakout/gameObjects.js +28 -29
  13. package/examples/breakout/index.html +1 -1
  14. package/examples/breakoutTutorial/game.js +1 -1
  15. package/examples/index.html +1 -7
  16. package/examples/logo.png +0 -0
  17. package/examples/module/game.js +1 -1
  18. package/examples/platformer/game.js +2 -2
  19. package/examples/platformer/gameCharacter.js +5 -5
  20. package/examples/platformer/gameEffects.js +4 -4
  21. package/examples/platformer/gameObjects.js +2 -2
  22. package/examples/puzzle/game.js +3 -3
  23. package/examples/starter/game.js +11 -45
  24. package/examples/starter/tiles.png +0 -0
  25. package/jsconfig.json +1 -0
  26. package/package.json +1 -1
  27. package/plugins/box2d.js +10 -10
  28. package/plugins/newgrounds.js +1 -1
  29. package/plugins/postProcess.js +8 -8
  30. package/shortExamples/base.html +36 -0
  31. package/shortExamples/code/blending.js +12 -0
  32. package/shortExamples/code/helloWorld.js +7 -0
  33. package/shortExamples/code/particles.js +28 -0
  34. package/shortExamples/code/playSound.js +36 -0
  35. package/shortExamples/code/pong.js +40 -0
  36. package/shortExamples/code/shapes.js +24 -0
  37. package/shortExamples/code/spriteAtlas.js +27 -0
  38. package/shortExamples/code/systemFont.js +14 -0
  39. package/shortExamples/code/texture.js +12 -0
  40. package/shortExamples/code/tileLayer.js +50 -0
  41. package/shortExamples/index.html +242 -0
  42. package/shortExamples/tiles.png +0 -0
  43. package/src/engine.js +17 -3
  44. package/src/engineAudio.js +4 -4
  45. package/src/engineBuild.js +2 -1
  46. package/src/engineDebug.js +4 -7
  47. package/src/engineDraw.js +50 -25
  48. package/src/engineExport.js +4 -1
  49. package/src/engineInput.js +1 -1
  50. package/src/engineObject.js +8 -8
  51. package/src/engineParticles.js +7 -7
  52. package/src/engineSettings.js +5 -5
  53. package/src/engineTileLayer.js +6 -2
  54. package/src/engineUtilities.js +5 -5
  55. package/src/engineWebGL.js +52 -74
  56. package/examples/electron/build.js +0 -107
  57. package/examples/electron/electron.js +0 -43
  58. package/examples/electron/game.js +0 -131
  59. package/examples/electron/index.html +0 -13
  60. package/examples/electron/package.json +0 -22
  61. package/examples/electron/tiles.png +0 -0
  62. package/examples/js13k/build.bat +0 -2
  63. package/examples/js13k/build.js +0 -131
  64. package/examples/js13k/game.js +0 -118
  65. package/examples/js13k/index.html +0 -21
  66. package/examples/js13k/tiles.png +0 -0
  67. package/examples/typescript/build.bat +0 -5
  68. package/examples/typescript/build.js +0 -33
  69. package/examples/typescript/game.js +0 -102
  70. package/examples/typescript/game.ts +0 -134
  71. package/examples/typescript/index.html +0 -10
  72. package/examples/typescript/tiles.png +0 -0
  73. package/examples/typescript/tsconfig.json +0 -8
@@ -1,102 +0,0 @@
1
- /*
2
- Little JS TypeScript Demo
3
- - A simple starter project
4
- - Shows how to use LittleJS with TypeScript
5
- */
6
- 'use strict';
7
- // import module
8
- import * as LittleJS from '../../dist/littlejs.esm.js';
9
- const { tile, vec2, hsl } = LittleJS;
10
- // show the LittleJS splash screen
11
- LittleJS.setShowSplashScreen(true);
12
- // fix texture bleeding by shrinking tile slightly
13
- LittleJS.setTileFixBleedScale(.5);
14
- // sound effects
15
- const sound_click = new LittleJS.Sound([1, .5]);
16
- // medals
17
- const medal_example = new LittleJS.Medal(0, 'Example Medal', 'Welcome to LittleJS!');
18
- LittleJS.medalsInit('Hello World');
19
- // game variables
20
- let particleEmitter;
21
- ///////////////////////////////////////////////////////////////////////////////
22
- function gameInit() {
23
- // create tile collision and visible tile layer
24
- const tileCollisionSize = vec2(32, 16);
25
- LittleJS.initTileCollision(tileCollisionSize);
26
- const pos = vec2();
27
- const tileLayer = new LittleJS.TileLayer(pos, tileCollisionSize);
28
- // get level data from the tiles image
29
- const mainContext = LittleJS.mainContext;
30
- const tileImage = LittleJS.textureInfos[0].image;
31
- mainContext.drawImage(tileImage, 0, 0);
32
- const imageData = mainContext.getImageData(0, 0, tileImage.width, tileImage.height).data;
33
- for (pos.x = tileCollisionSize.x; pos.x--;)
34
- for (pos.y = tileCollisionSize.y; pos.y--;) {
35
- // check if this pixel is set
36
- const i = pos.x + tileImage.width * (15 + tileCollisionSize.y - pos.y);
37
- if (!imageData[4 * i])
38
- continue;
39
- // set tile data
40
- const tileIndex = 1;
41
- const direction = LittleJS.randInt(4);
42
- const mirror = !LittleJS.randInt(2);
43
- const color = LittleJS.randColor();
44
- const data = new LittleJS.TileLayerData(tileIndex, direction, mirror, color);
45
- tileLayer.setData(pos, data);
46
- LittleJS.setTileCollisionData(pos, 1);
47
- }
48
- // draw tile layer with new data
49
- tileLayer.redraw();
50
- // move camera to center of collision
51
- LittleJS.setCameraPos(tileCollisionSize.scale(.5));
52
- LittleJS.setCameraScale(48);
53
- // enable gravity
54
- LittleJS.setGravity(-.01);
55
- // create particle emitter
56
- particleEmitter = new LittleJS.ParticleEmitter(vec2(16, 9), 0, // emitPos, emitAngle
57
- 1, 0, 500, Math.PI, // emitSize, emitTime, emitRate, emiteCone
58
- tile(0, 16), // tileIndex, tileSize
59
- hsl(1, 1, 1), hsl(0, 0, 0), // colorStartA, colorStartB
60
- hsl(0, 0, 0, 0), hsl(0, 0, 0, 0), // colorEndA, colorEndB
61
- 2, .2, .2, .1, .05, // time, sizeStart, sizeEnd, speed, angleSpeed
62
- .99, 1, 1, Math.PI, // damping, angleDamping, gravityScale, cone
63
- .05, .5, true, true // fadeRate, randomness, collide, additive
64
- );
65
- particleEmitter.elasticity = .3; // bounce when it collides
66
- particleEmitter.trailScale = 2; // stretch in direction of motion
67
- }
68
- ///////////////////////////////////////////////////////////////////////////////
69
- function gameUpdate() {
70
- if (LittleJS.mouseWasPressed(0)) {
71
- // play sound when mouse is pressed
72
- sound_click.play(LittleJS.mousePos);
73
- // change particle color and set to fade out
74
- particleEmitter.colorStartA = hsl();
75
- particleEmitter.colorStartB = LittleJS.randColor();
76
- particleEmitter.colorEndA = particleEmitter.colorStartA.scale(1, 0);
77
- particleEmitter.colorEndB = particleEmitter.colorStartB.scale(1, 0);
78
- // unlock medals
79
- medal_example.unlock();
80
- }
81
- // move particles to mouse location if on screen
82
- if (LittleJS.mousePosScreen.x)
83
- particleEmitter.pos = LittleJS.mousePos;
84
- }
85
- ///////////////////////////////////////////////////////////////////////////////
86
- function gameUpdatePost() {
87
- }
88
- ///////////////////////////////////////////////////////////////////////////////
89
- function gameRender() {
90
- // draw a grey square in the background without using webgl
91
- LittleJS.drawRect(vec2(16, 8), vec2(20, 14), hsl(0, 0, .6), 0, false);
92
- // draw the logo as a tile
93
- LittleJS.drawTile(vec2(21, 5), vec2(4.5), tile(3, 128));
94
- }
95
- ///////////////////////////////////////////////////////////////////////////////
96
- function gameRenderPost() {
97
- // draw to overlay canvas for hud rendering
98
- LittleJS.drawTextScreen('LittleJS with TypeScript', vec2(LittleJS.mainCanvasSize.x / 2, 80), 80);
99
- }
100
- ///////////////////////////////////////////////////////////////////////////////
101
- // Startup LittleJS Engine
102
- LittleJS.engineInit(gameInit, gameUpdate, gameUpdatePost, gameRender, gameRenderPost, ['tiles.png']);
@@ -1,134 +0,0 @@
1
- /*
2
- Little JS TypeScript Demo
3
- - A simple starter project
4
- - Shows how to use LittleJS with TypeScript
5
- */
6
-
7
- 'use strict';
8
-
9
- // import module
10
- import * as LittleJS from '../../dist/littlejs.esm.js';
11
- const {tile, vec2, hsl} = LittleJS;
12
-
13
- // show the LittleJS splash screen
14
- LittleJS.setShowSplashScreen(true);
15
-
16
- // fix texture bleeding by shrinking tile slightly
17
- LittleJS.setTileFixBleedScale(.5);
18
-
19
- // sound effects
20
- const sound_click = new LittleJS.Sound([1,.5]);
21
-
22
- // medals
23
- const medal_example = new LittleJS.Medal(0, 'Example Medal', 'Welcome to LittleJS!');
24
- LittleJS.medalsInit('Hello World');
25
-
26
- // game variables
27
- let particleEmitter;
28
-
29
- ///////////////////////////////////////////////////////////////////////////////
30
- function gameInit()
31
- {
32
- // create tile collision and visible tile layer
33
- const tileCollisionSize = vec2(32, 16);
34
- LittleJS.initTileCollision(tileCollisionSize);
35
- const pos = vec2();
36
- const tileLayer = new LittleJS.TileLayer(pos, tileCollisionSize);
37
-
38
- // get level data from the tiles image
39
- const mainContext = LittleJS.mainContext;
40
- const tileImage = LittleJS.textureInfos[0].image;
41
- mainContext.drawImage(tileImage, 0, 0);
42
- 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--;)
45
- {
46
- // check if this pixel is set
47
- const i = pos.x + tileImage.width*(15 + tileCollisionSize.y - pos.y);
48
- if (!imageData[4*i])
49
- continue;
50
-
51
- // set tile data
52
- 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);
57
- tileLayer.setData(pos, data);
58
- LittleJS.setTileCollisionData(pos, 1);
59
- }
60
-
61
- // draw tile layer with new data
62
- tileLayer.redraw();
63
-
64
- // move camera to center of collision
65
- LittleJS.setCameraPos(tileCollisionSize.scale(.5));
66
- LittleJS.setCameraScale(48);
67
-
68
- // enable gravity
69
- LittleJS.setGravity(-.01);
70
-
71
- // create particle emitter
72
- particleEmitter = new LittleJS.ParticleEmitter(
73
- vec2(16,9), 0, // emitPos, emitAngle
74
- 1, 0, 500, Math.PI, // emitSize, emitTime, emitRate, emiteCone
75
- tile(0, 16), // tileIndex, tileSize
76
- hsl(1,1,1), hsl(0,0,0), // colorStartA, colorStartB
77
- hsl(0,0,0,0), hsl(0,0,0,0), // colorEndA, colorEndB
78
- 2, .2, .2, .1, .05, // time, sizeStart, sizeEnd, speed, angleSpeed
79
- .99, 1, 1, Math.PI, // damping, angleDamping, gravityScale, cone
80
- .05, .5, true, true // fadeRate, randomness, collide, additive
81
- );
82
- particleEmitter.elasticity = .3; // bounce when it collides
83
- particleEmitter.trailScale = 2; // stretch in direction of motion
84
- }
85
-
86
- ///////////////////////////////////////////////////////////////////////////////
87
- function gameUpdate()
88
- {
89
- if (LittleJS.mouseWasPressed(0))
90
- {
91
- // play sound when mouse is pressed
92
- sound_click.play(LittleJS.mousePos);
93
-
94
- // change particle color and set to fade out
95
- particleEmitter.colorStartA = hsl();
96
- particleEmitter.colorStartB = LittleJS.randColor();
97
- particleEmitter.colorEndA = particleEmitter.colorStartA.scale(1,0);
98
- particleEmitter.colorEndB = particleEmitter.colorStartB.scale(1,0);
99
-
100
- // unlock medals
101
- medal_example.unlock();
102
- }
103
-
104
- // move particles to mouse location if on screen
105
- if (LittleJS.mousePosScreen.x)
106
- particleEmitter.pos = LittleJS.mousePos;
107
- }
108
-
109
- ///////////////////////////////////////////////////////////////////////////////
110
- function gameUpdatePost()
111
- {
112
-
113
- }
114
-
115
- ///////////////////////////////////////////////////////////////////////////////
116
- function gameRender()
117
- {
118
- // 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);
120
-
121
- // draw the logo as a tile
122
- LittleJS.drawTile(vec2(21,5), vec2(4.5), tile(3,128));
123
- }
124
-
125
- ///////////////////////////////////////////////////////////////////////////////
126
- function gameRenderPost()
127
- {
128
- // draw to overlay canvas for hud rendering
129
- LittleJS.drawTextScreen('LittleJS with TypeScript', vec2(LittleJS.mainCanvasSize.x/2, 80), 80);
130
- }
131
-
132
- ///////////////////////////////////////////////////////////////////////////////
133
- // Startup LittleJS Engine
134
- LittleJS.engineInit(gameInit, gameUpdate, gameUpdatePost, gameRender, gameRenderPost, ['tiles.png']);
@@ -1,10 +0,0 @@
1
- <!DOCTYPE html><head>
2
- <title>LittleJS TypeScript Demo</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
- <!-- Add your game scripts here -->
10
- <script src=game.js?1105 type=module></script>
Binary file
@@ -1,8 +0,0 @@
1
- {
2
- "compilerOptions": {
3
- "allowJs": true,
4
- "module": "es2020",
5
- "target": "es2020",
6
- "outDir": "build"
7
- }
8
- }