littlejsengine 1.10.2 → 1.10.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 (42) hide show
  1. package/README.md +7 -15
  2. package/dist/littlejs.d.ts +49 -1
  3. package/dist/littlejs.esm.js +60 -37
  4. package/dist/littlejs.esm.min.js +1 -1
  5. package/dist/littlejs.js +46 -37
  6. package/dist/littlejs.min.js +1 -1
  7. package/dist/littlejs.release.js +46 -37
  8. package/examples/box2d/game.js +3 -0
  9. package/examples/breakoutTutorial/README.md +9 -7
  10. package/examples/breakoutTutorial/game.js +6 -6
  11. package/examples/js13k/build/index.html +1 -0
  12. package/examples/js13k/build/index.js +1 -0
  13. package/examples/js13k/build/tiles.png +0 -0
  14. package/examples/js13k/game - Copy.zip +0 -0
  15. package/examples/js13k/game.zip +0 -0
  16. package/examples/platformer/game.js +6 -4
  17. package/examples/platformer/gameCharacter.js +12 -11
  18. package/examples/platformer/gameEffects.js +3 -4
  19. package/examples/platformer/gameLevel.js +17 -33
  20. package/examples/platformer/gameObjects.js +9 -14
  21. package/examples/starter/build/index.html +2 -0
  22. package/examples/starter/build/index.js +1 -0
  23. package/examples/starter/build/tiles.png +0 -0
  24. package/examples/starter/game.zip +0 -0
  25. package/examples/typescript/build/build/littlejs.esm.js +4327 -0
  26. package/examples/typescript/build/dist/littlejs.esm.js +4425 -0
  27. package/examples/typescript/build/examples/typescript/build.js +24 -0
  28. package/examples/typescript/build/examples/typescript/game.js +100 -0
  29. package/examples/typescript/build/examples/typescript/test/build/littlejs.esm.js +3934 -0
  30. package/examples/typescript/build/examples/typescript/test/examples/typescript/build.js +86 -0
  31. package/examples/typescript/build/examples/typescript/test/examples/typescript/game.js +92 -0
  32. package/examples/typescript/game.ts +1 -1
  33. package/package.json +1 -1
  34. package/plugins/postProcess.js +8 -1
  35. package/src/engine.js +5 -13
  36. package/src/engineDraw.js +19 -18
  37. package/src/engineExport.js +14 -0
  38. package/src/engineInput.js +1 -3
  39. package/src/engineObject.js +1 -0
  40. package/src/engineTileLayer.js +2 -1
  41. package/src/engineUtilities.js +1 -0
  42. package/src/engineWebGL.js +17 -2
@@ -0,0 +1,24 @@
1
+ #!/usr/bin/env node
2
+ /**
3
+ * LittleJS Build System
4
+ */
5
+ 'use strict';
6
+ const PROGRAM_NAME = 'game';
7
+ const BUILD_FOLDER = 'build';
8
+ const ROOT_FOLDER = 'examples/typescript';
9
+ const sourceFiles = [
10
+ 'game.js',
11
+ // add your game's scripts here
12
+ ];
13
+ console.log(`Building TypeScript for ${PROGRAM_NAME}...`);
14
+ const startTime = Date.now();
15
+ const fs = require('node:fs');
16
+ const child_process = require('node:child_process');
17
+ console.log(`Removing old build filder...`);
18
+ fs.rmSync(BUILD_FOLDER, { recursive: true, force: true });
19
+ console.log(`Compiling TypeScript...`);
20
+ child_process.execSync(`npx tsc --outDir "./${BUILD_FOLDER}"`, { stdio: 'inherit' });
21
+ console.log(`Moving js files to root...`);
22
+ for (const file of sourceFiles)
23
+ fs.copyFileSync(`${BUILD_FOLDER}/${ROOT_FOLDER}/${file}`, `${file}`);
24
+ console.log(`TypeScript built in ${((Date.now() - startTime) / 1e3).toFixed(2)} seconds!`);
@@ -0,0 +1,100 @@
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 { Vector2, Color, Timer, tile, vec2, hsl, rgb } = LittleJS;
10
+ // show the LittleJS splash screen
11
+ LittleJS.setShowSplashScreen(true);
12
+ // sound effects
13
+ const sound_click = new LittleJS.Sound([1, .5]);
14
+ // medals
15
+ const medal_example = new LittleJS.Medal(0, 'Example Medal', 'Welcome to LittleJS!');
16
+ LittleJS.medalsInit('Hello World');
17
+ // game variables
18
+ let particleEmitter;
19
+ ///////////////////////////////////////////////////////////////////////////////
20
+ function gameInit() {
21
+ // create tile collision and visible tile layer
22
+ const tileCollisionSize = vec2(32, 16);
23
+ LittleJS.initTileCollision(tileCollisionSize);
24
+ const pos = vec2();
25
+ const tileLayer = new LittleJS.TileLayer(pos, tileCollisionSize);
26
+ // get level data from the tiles image
27
+ const mainContext = LittleJS.mainContext;
28
+ const tileImage = LittleJS.textureInfos[0].image;
29
+ mainContext.drawImage(tileImage, 0, 0);
30
+ const imageData = mainContext.getImageData(0, 0, tileImage.width, tileImage.height).data;
31
+ for (pos.x = tileCollisionSize.x; pos.x--;)
32
+ for (pos.y = tileCollisionSize.y; pos.y--;) {
33
+ // check if this pixel is set
34
+ const i = pos.x + tileImage.width * (15 + tileCollisionSize.y - pos.y);
35
+ if (!imageData[4 * i])
36
+ continue;
37
+ // set tile data
38
+ const tileIndex = 1;
39
+ const direction = LittleJS.randInt(4);
40
+ const mirror = !LittleJS.randInt(2);
41
+ const color = LittleJS.randColor();
42
+ const data = new LittleJS.TileLayerData(tileIndex, direction, mirror, color);
43
+ tileLayer.setData(pos, data);
44
+ LittleJS.setTileCollisionData(pos, 1);
45
+ }
46
+ // draw tile layer with new data
47
+ tileLayer.redraw();
48
+ // move camera to center of collision
49
+ LittleJS.setCameraPos(tileCollisionSize.scale(.5));
50
+ LittleJS.setCameraScale(48);
51
+ // enable gravity
52
+ LittleJS.setGravity(-.01);
53
+ // create particle emitter
54
+ particleEmitter = new LittleJS.ParticleEmitter(vec2(16, 9), 0, // emitPos, emitAngle
55
+ 1, 0, 500, Math.PI, // emitSize, emitTime, emitRate, emiteCone
56
+ tile(0, 16), // tileIndex, tileSize
57
+ hsl(1, 1, 1), hsl(0, 0, 0), // colorStartA, colorStartB
58
+ hsl(0, 0, 0, 0), hsl(0, 0, 0, 0), // colorEndA, colorEndB
59
+ 2, .2, .2, .1, .05, // time, sizeStart, sizeEnd, speed, angleSpeed
60
+ .99, 1, 1, Math.PI, // damping, angleDamping, gravityScale, cone
61
+ .05, .5, true, true // fadeRate, randomness, collide, additive
62
+ );
63
+ particleEmitter.elasticity = .3; // bounce when it collides
64
+ particleEmitter.trailScale = 2; // stretch in direction of motion
65
+ }
66
+ ///////////////////////////////////////////////////////////////////////////////
67
+ function gameUpdate() {
68
+ if (LittleJS.mouseWasPressed(0)) {
69
+ // play sound when mouse is pressed
70
+ sound_click.play(LittleJS.mousePos);
71
+ // change particle color and set to fade out
72
+ particleEmitter.colorStartA = hsl();
73
+ particleEmitter.colorStartB = LittleJS.randColor();
74
+ particleEmitter.colorEndA = particleEmitter.colorStartA.scale(1, 0);
75
+ particleEmitter.colorEndB = particleEmitter.colorStartB.scale(1, 0);
76
+ // unlock medals
77
+ medal_example.unlock();
78
+ }
79
+ // move particles to mouse location if on screen
80
+ if (LittleJS.mousePosScreen.x)
81
+ particleEmitter.pos = LittleJS.mousePos;
82
+ }
83
+ ///////////////////////////////////////////////////////////////////////////////
84
+ function gameUpdatePost() {
85
+ }
86
+ ///////////////////////////////////////////////////////////////////////////////
87
+ function gameRender() {
88
+ // draw a grey square in the background without using webgl
89
+ LittleJS.drawRect(vec2(16, 8), vec2(20, 14), hsl(0, 0, .6), 0, false);
90
+ // draw the logo as a tile
91
+ LittleJS.drawTile(vec2(21, 5), vec2(4.5), tile(3, 128));
92
+ }
93
+ ///////////////////////////////////////////////////////////////////////////////
94
+ function gameRenderPost() {
95
+ // draw to overlay canvas for hud rendering
96
+ LittleJS.drawTextScreen('LittleJS with TypeScript', vec2(LittleJS.mainCanvasSize.x / 2, 80), 80);
97
+ }
98
+ ///////////////////////////////////////////////////////////////////////////////
99
+ // Startup LittleJS Engine
100
+ LittleJS.engineInit(gameInit, gameUpdate, gameUpdatePost, gameRender, gameRenderPost);