littlejsengine 1.10.4 → 1.11.1

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 (75) hide show
  1. package/LittleJS.zip +0 -0
  2. package/README.md +8 -78
  3. package/dist/littlejs.d.ts +60 -25
  4. package/dist/littlejs.esm.js +164 -63
  5. package/dist/littlejs.esm.min.js +1 -1
  6. package/dist/littlejs.js +160 -62
  7. package/dist/littlejs.min.js +1 -1
  8. package/dist/littlejs.release.js +160 -62
  9. package/examples/box2d/game.js +15 -4
  10. package/examples/box2d/gameObjects.js +10 -9
  11. package/examples/box2d/index.html +5 -5
  12. package/examples/box2d/scenes.js +4 -4
  13. package/examples/box2d/tiles.png +0 -0
  14. package/examples/breakout/index.html +3 -3
  15. package/examples/breakoutTutorial/index.html +2 -2
  16. package/examples/electron/game.js +3 -0
  17. package/examples/electron/index.html +2 -2
  18. package/examples/htmlMenu/index.html +3 -3
  19. package/examples/index.html +10 -3
  20. package/examples/js13k/game.js +3 -0
  21. package/examples/js13k/index.html +13 -13
  22. package/examples/module/game.js +4 -1
  23. package/examples/module/index.html +1 -1
  24. package/examples/particles/index.html +4 -1
  25. package/examples/platformer/game.js +19 -15
  26. package/examples/platformer/gameCharacter.js +3 -3
  27. package/examples/platformer/gameLevel.js +1 -0
  28. package/examples/platformer/index.html +8 -8
  29. package/examples/platformer/tiles.png +0 -0
  30. package/examples/puzzle/game.js +3 -2
  31. package/examples/puzzle/index.html +2 -2
  32. package/examples/starter/game.js +47 -10
  33. package/examples/starter/index.html +13 -13
  34. package/examples/starter/tiles.png +0 -0
  35. package/examples/stress/index.html +1 -1
  36. package/examples/typescript/game.js +2 -0
  37. package/examples/typescript/game.ts +3 -0
  38. package/examples/typescript/index.html +1 -1
  39. package/examples/uiSystem/game.js +23 -16
  40. package/examples/uiSystem/index.html +3 -14
  41. package/package.json +7 -2
  42. package/plugins/postProcess.js +2 -9
  43. package/plugins/uiSystem.js +85 -25
  44. package/reference.md +1 -1
  45. package/shortExamples/engine.html +71 -0
  46. package/shortExamples/index.html +47 -0
  47. package/shortExamples/index.js +0 -0
  48. package/shortExamples/tiles.png +0 -0
  49. package/src/engine.js +14 -12
  50. package/src/engineAudio.js +6 -9
  51. package/src/engineDraw.js +23 -7
  52. package/src/engineExport.js +4 -1
  53. package/src/engineInput.js +7 -3
  54. package/src/engineMedals.js +19 -5
  55. package/src/engineObject.js +8 -5
  56. package/src/engineSettings.js +13 -2
  57. package/src/engineTileLayer.js +9 -8
  58. package/src/engineUtilities.js +59 -10
  59. package/src/engineWebGL.js +1 -1
  60. package/examples/js13k/build/index.html +0 -1
  61. package/examples/js13k/build/index.js +0 -1
  62. package/examples/js13k/build/tiles.png +0 -0
  63. package/examples/js13k/game - Copy.zip +0 -0
  64. package/examples/js13k/game.zip +0 -0
  65. package/examples/starter/build/index.html +0 -2
  66. package/examples/starter/build/index.js +0 -1
  67. package/examples/starter/build/tiles.png +0 -0
  68. package/examples/starter/game.zip +0 -0
  69. package/examples/typescript/build/build/littlejs.esm.js +0 -4327
  70. package/examples/typescript/build/dist/littlejs.esm.js +0 -4425
  71. package/examples/typescript/build/examples/typescript/build.js +0 -24
  72. package/examples/typescript/build/examples/typescript/game.js +0 -100
  73. package/examples/typescript/build/examples/typescript/test/build/littlejs.esm.js +0 -3934
  74. package/examples/typescript/build/examples/typescript/test/examples/typescript/build.js +0 -86
  75. package/examples/typescript/build/examples/typescript/test/examples/typescript/game.js +0 -92
@@ -12,7 +12,8 @@
12
12
  function spawnBox(pos, size=1, color=WHITE, type=box2dBodyTypeDynamic, applyTexture=true, angle=0)
13
13
  {
14
14
  size = typeof size == 'number' ? vec2(size) : size; // square
15
- const o = new Box2dObject(pos, size, applyTexture && tile(3), angle, color, type);
15
+ const o = new Box2dObject(pos, size, applyTexture && spriteAtlas.squareOutline, angle, color, type);
16
+ o.drawSize = size.scale(1.02); // slightly enarge to cover gaps
16
17
  o.addBox(size);
17
18
  return o;
18
19
  }
@@ -20,7 +21,7 @@ function spawnBox(pos, size=1, color=WHITE, type=box2dBodyTypeDynamic, applyText
20
21
  function spawnCircle(pos, diameter=1, color=WHITE, type=box2dBodyTypeDynamic, applyTexture=true, angle=0)
21
22
  {
22
23
  const size = vec2(diameter);
23
- const o = new Box2dObject(pos, size, applyTexture && tile(2), angle, color, type);
24
+ const o = new Box2dObject(pos, size, applyTexture && spriteAtlas.circleOutline, angle, color, type);
24
25
  o.addCircle(diameter);
25
26
  return o;
26
27
  }
@@ -115,7 +116,7 @@ class CarObject extends Box2dObject
115
116
  const damping = .7;
116
117
  const frequencyHz = 4;
117
118
  const maxTorque = 50;
118
- const sprite = tile(4);
119
+ const sprite = spriteAtlas.wheel;
119
120
 
120
121
  // create wheels
121
122
  this.wheels = [];
@@ -208,7 +209,7 @@ class PulleyJointObjects extends Box2dObject
208
209
  {
209
210
  constructor(pos, size, color, connectionPos)
210
211
  {
211
- super(pos, size, tile(3), 0, color);
212
+ super(pos, size, spriteAtlas.squareOutline, 0, color);
212
213
  this.addBox(size);
213
214
  this.connectionPos = connectionPos;
214
215
  }
@@ -228,7 +229,7 @@ class MotorJointObject extends Box2dObject
228
229
  {
229
230
  constructor(pos, size, color, otherObject)
230
231
  {
231
- super(pos, size, tile(4), 0, color);
232
+ super(pos, size, spriteAtlas.wheel, 0, color);
232
233
  this.addCircle(size.x);
233
234
  this.connectionPos = pos;
234
235
  const joint = box2dCreateMotorJoint(otherObject, this);
@@ -265,7 +266,7 @@ class SoftBodyObject extends Box2dObject
265
266
  const mass = .1;
266
267
  const center = vec2(x-nodeSize.x/2, y-nodeSize.y/2);
267
268
  const p = pos.add(center.multiply(spacing));
268
- const o = new Box2dObject(p, vec2(objectDiameter*1.1), tile(0), 0, color);
269
+ const o = new Box2dObject(p, vec2(objectDiameter*1.1), spriteAtlas.circle, 0, color);
269
270
  o.addCircle(objectDiameter);
270
271
  o.setMass(mass);
271
272
  o.setAngularDamping(10);
@@ -336,7 +337,7 @@ class ClothObject extends Box2dObject
336
337
  const mass = .5;
337
338
  const center = vec2(x-nodeSize.x/2, y-nodeSize.y/2);
338
339
  const p = pos.add(center.multiply(spacing));
339
- const o = new Box2dObject(p, vec2(.4), tile(0), 0, color);
340
+ const o = new Box2dObject(p, vec2(.4), spriteAtlas.circle, 0, color);
340
341
  o.addCircle(objectDiameter);
341
342
  o.setFilterData(2, 2);
342
343
  o.setLinearDamping(1);
@@ -463,7 +464,7 @@ function explosion(pos, radius=3, strength=300)
463
464
  new ParticleEmitter(
464
465
  pos, 0, // pos, angle
465
466
  radius/2, .2, 50*radius, PI,// emitSize, emitTime, emitRate, emiteCone
466
- tile(1), // tileInfo
467
+ spriteAtlas.dot, // tileInfo
467
468
  hsl(0,0,0), hsl(0,0,0), // colorStartA, colorStartB
468
469
  hsl(0,0,0,0), hsl(0,0,0,0), // colorEndA, colorEndB
469
470
  1, 1, 2, .1, .1, // time, sizeStart, sizeEnd, speed, angleSpeed
@@ -475,7 +476,7 @@ function explosion(pos, radius=3, strength=300)
475
476
  new ParticleEmitter(
476
477
  pos, 0, // pos, angle
477
478
  radius, .1, 100*radius, PI, // emitSize, emitTime, emitRate, emiteCone
478
- tile(1), // tileInfo
479
+ spriteAtlas.dot, // tileInfo
479
480
  hsl(0,1,.5), hsl(.15,1,.5), // colorStartA, colorStartB
480
481
  hsl(0,1,.5,0), hsl(.1, 1,.5,0), // colorEndA, colorEndB
481
482
  .7, 1, .5, .1, .1, // time, sizeStart, sizeEnd, speed, angleSpeed
@@ -7,8 +7,8 @@
7
7
  </head><body>
8
8
 
9
9
  <script src=../../dist/littlejs.js></script>
10
- <script src=../../plugins/Box2D_v2.3.1_min.wasm.js?1100></script>
11
- <script src=../../plugins/box2d.js?1100></script>
12
- <script src=scenes.js?1100></script>
13
- <script src=gameObjects.js?1100></script>
14
- <script src=game.js?1100></script>
10
+ <script src=../../plugins/Box2D_v2.3.1_min.wasm.js?1105></script>
11
+ <script src=../../plugins/box2d.js?1105></script>
12
+ <script src=scenes.js?1105></script>
13
+ <script src=gameObjects.js?1105></script>
14
+ <script src=game.js?1105></script>
@@ -132,7 +132,7 @@ function loadScene(_scene)
132
132
  const o1 = spawnCircle(vec2(23.5,3), 3, randColor());
133
133
  const j1 = box2dCreateRevoluteJoint(groundObject, o1, o1.pos);
134
134
  const o2 = spawnCircle(vec2(28,3), 6, randColor());
135
- o1.tileInfo = o2.tileInfo = tile(5);
135
+ o1.tileInfo = o2.tileInfo = spriteAtlas.gear;
136
136
  const j2 = box2dCreateRevoluteJoint(groundObject, o2, o2.pos);
137
137
  box2dCreateGearJoint(o1, o2, j1, j2, 2);
138
138
  }
@@ -144,21 +144,21 @@ function loadScene(_scene)
144
144
  }
145
145
  {
146
146
  // distance joint
147
- const o1 = new Box2dObject(vec2(30,11), vec2(4), tile(2), 0, randColor(), box2dBodyTypeStatic);
147
+ const o1 = new Box2dObject(vec2(30,11), vec2(4), spriteAtlas.circleOutline, 0, randColor(), box2dBodyTypeStatic);
148
148
  o1.renderOrder = -2;
149
149
  const o2 = spawnCircle(vec2(30,8), 2, randColor());
150
150
  box2dCreateDistanceJoint(o1, o2);
151
151
  }
152
152
  {
153
153
  // motor joint
154
- const o = new Box2dObject(vec2(10,8), vec2(4), tile(2), 0, randColor(), box2dBodyTypeStatic);
154
+ const o = new Box2dObject(vec2(10,8), vec2(4), spriteAtlas.circleOutline, 0, randColor(), box2dBodyTypeStatic);
155
155
  o.renderOrder = -2;
156
156
  new MotorJointObject(vec2(10,8), vec2(2), randColor(), o);
157
157
  }
158
158
  {
159
159
  // friction joint
160
160
  const o = spawnBox(vec2(10,15), 3, randColor());
161
- o.tileInfo = tile(6);
161
+ o.tileInfo = spriteAtlas.squareOutline2;
162
162
  const joint = box2dCreateFrictionJoint(groundObject, o);
163
163
  joint.SetMaxForce(200);
164
164
  joint.SetMaxTorque(200);
Binary file
@@ -6,7 +6,7 @@
6
6
  <link rel=icon type=image/png href=../favicon.png>
7
7
  </head><body>
8
8
 
9
- <script src=../../dist/littlejs.js?1100></script>
9
+ <script src=../../dist/littlejs.js?1105></script>
10
10
  <script src=../../plugins/postProcess.js></script>
11
- <script src=gameObjects.js?1100></script>
12
- <script src=game.js?1100></script>
11
+ <script src=gameObjects.js?1105></script>
12
+ <script src=game.js?1105></script>
@@ -6,5 +6,5 @@
6
6
  <link rel=icon type=image/png href=../favicon.png>
7
7
  </head><body>
8
8
 
9
- <script src=../../dist/littlejs.js?1100></script>
10
- <script src=game.js?1100></script>
9
+ <script src=../../dist/littlejs.js?1105></script>
10
+ <script src=game.js?1105></script>
@@ -10,6 +10,9 @@
10
10
  // show the LittleJS splash screen
11
11
  setShowSplashScreen(true);
12
12
 
13
+ // fix texture bleeding by shrinking tile slightly
14
+ tileFixBleedScale = .5;
15
+
13
16
  // sound effects
14
17
  const sound_click = new Sound([1,.5]);
15
18
 
@@ -7,7 +7,7 @@
7
7
  </head><body>
8
8
 
9
9
  <!-- LittleJS Engine -->
10
- <script src=../../dist/littlejs.js?1100></script>
10
+ <script src=../../dist/littlejs.js?1105></script>
11
11
 
12
12
  <!-- Add your game scripts here -->
13
- <script src=game.js?1100></script>
13
+ <script src=game.js?1105></script>
@@ -32,7 +32,7 @@
32
32
  <!-- setup html menu system -->
33
33
  <div class="topDiv">
34
34
  <div id="menu" class="menuDiv">
35
- <h1><i style="font-size:30px">Test Menu</i></h1>
35
+ <b style="font-size:50px">Test Menu</b>
36
36
  This is an example menu using html elements.
37
37
  <input value="Test Input" onchange="alert('New text: ' + this.value)">
38
38
  <input type="range" onchange="alert('New value: ' + this.value)">
@@ -52,5 +52,5 @@ setMenuVisible(false);
52
52
  </script>
53
53
 
54
54
  <!-- Add your game scripts here -->
55
- <script src=../../dist/littlejs.js?1100></script>
56
- <script src=game.js?1100></script>
55
+ <script src=../../dist/littlejs.js?1105></script>
56
+ <script src=game.js?1105></script>
@@ -1,11 +1,12 @@
1
1
  <head>
2
2
  <title>LittleJS Examples</title>
3
+ <style>
4
+ iframe {width:480px; height:270px;}
5
+ </style>
3
6
  <link rel=icon type=image/png href=../favicon.png>
4
7
  <body>
5
8
  <h1>All LittleJS Engine Examples</h1>
6
- <p>
7
- <img src=screenshot.jpg width=500>
8
- </p>
9
+ <img src=screenshot.jpg width=480>
9
10
  <h2>Main Demos</h2>
10
11
  <p>
11
12
  <a href="starter">Starter</a> - Clean example with only a few things to get you started<br>
@@ -30,4 +31,10 @@
30
31
  <a href="typescript">LittleJS using TypeScript</a> - Uses LittleJS type definitions<br>
31
32
  <a href="electron">LittleJS building with Electron</a> - Builds to an executable<br>
32
33
  </p>
34
+ <h2>Live Demos</h2>
35
+ <p>
36
+ <iframe id=iframe src="breakout"></iframe>
37
+ <iframe id=iframe src="platformer"></iframe>
38
+ <iframe id=iframe src="puzzle"></iframe>
39
+ </p>
33
40
  </body>
@@ -7,6 +7,9 @@
7
7
 
8
8
  'use strict';
9
9
 
10
+ // fix texture bleeding by shrinking tile slightly
11
+ tileFixBleedScale = .5;
12
+
10
13
  // sound effects
11
14
  const sound_click = new Sound([1,.5]);
12
15
 
@@ -4,18 +4,18 @@
4
4
  </head><body>
5
5
 
6
6
  <!-- LittleJS Engine -->
7
- <script src=../../src/engineDebug.js?1100></script>
8
- <script src=../../src/engineUtilities.js?1100></script>
9
- <script src=../../src/engineSettings.js?1100></script>
10
- <script src=../../src/engineObject.js?1100></script>
11
- <script src=../../src/engineDraw.js?1100></script>
12
- <script src=../../src/engineInput.js?1100></script>
13
- <script src=../../src/engineAudio.js?1100></script>
14
- <script src=../../src/engineTileLayer.js?1100></script>
15
- <script src=../../src/engineParticles.js?1100></script>
16
- <script src=../../src/engineMedals.js?1100></script>
17
- <script src=../../src/engineWebGL.js?1100></script>
18
- <script src=../../src/engine.js?1100></script>
7
+ <script src=../../src/engineDebug.js?1105></script>
8
+ <script src=../../src/engineUtilities.js?1105></script>
9
+ <script src=../../src/engineSettings.js?1105></script>
10
+ <script src=../../src/engineObject.js?1105></script>
11
+ <script src=../../src/engineDraw.js?1105></script>
12
+ <script src=../../src/engineInput.js?1105></script>
13
+ <script src=../../src/engineAudio.js?1105></script>
14
+ <script src=../../src/engineTileLayer.js?1105></script>
15
+ <script src=../../src/engineParticles.js?1105></script>
16
+ <script src=../../src/engineMedals.js?1105></script>
17
+ <script src=../../src/engineWebGL.js?1105></script>
18
+ <script src=../../src/engine.js?1105></script>
19
19
 
20
20
  <!-- Add your game scripts here -->
21
- <script src=game.js?1100></script>
21
+ <script src=game.js?1105></script>
@@ -13,6 +13,9 @@ const {tile, vec2, hsl} = LittleJS;
13
13
  // show the LittleJS splash screen
14
14
  LittleJS.setShowSplashScreen(true);
15
15
 
16
+ // fix texture bleeding by shrinking tile slightly
17
+ LittleJS.setTileFixBleedScale(.5);
18
+
16
19
  // sound effects
17
20
  const sound_click = new LittleJS.Sound([1,.5]);
18
21
 
@@ -123,7 +126,7 @@ function gameRender()
123
126
  function gameRenderPost()
124
127
  {
125
128
  // draw to overlay canvas for hud rendering
126
- LittleJS.drawTextScreen('LittleJS with Modules', vec2(LittleJS.mainCanvasSize.x/2, 80), 80);
129
+ LittleJS.drawTextOverlay('LittleJS with Modules', vec2(LittleJS.mainCanvasSize.x/2, 80), 80);
127
130
  }
128
131
 
129
132
  ///////////////////////////////////////////////////////////////////////////////
@@ -7,4 +7,4 @@
7
7
  </head><body>
8
8
 
9
9
  <!-- Add your game scripts here -->
10
- <script src=game.js?1100 type=module></script>
10
+ <script src=game.js?1105 type=module></script>
@@ -10,11 +10,14 @@ button { margin:1px; }
10
10
  </style>
11
11
  </head><body>
12
12
 
13
- <script src=../../dist/littlejs.js?1100></script>
13
+ <script src=../../dist/littlejs.js?1105></script>
14
14
  <script>
15
15
 
16
16
  'use strict';
17
17
 
18
+ // fix texture bleeding by shrinking tiles slightly
19
+ tileFixBleedScale = .5;
20
+
18
21
  let particleEditor = 0, particleSystem, particleSystemDiv, particleSystemCode;
19
22
  let inputExpand;
20
23
  let restartTimer = new Timer();
@@ -16,36 +16,36 @@ let spriteAtlas, score, deaths;
16
16
  // enable touch gamepad on touch devices
17
17
  touchGamepadEnable = true;
18
18
 
19
- // fix texture bleeding by shrinking tile slightly
20
- tileFixBleedScale = .1;
21
-
22
19
  ///////////////////////////////////////////////////////////////////////////////
23
20
  function gameInit()
24
21
  {
22
+ // engine settings
23
+ gravity = -.01;
24
+ objectDefaultDamping = .99;
25
+ objectDefaultAngleDamping = .99;
26
+ cameraScale = 4*16;
27
+
25
28
  // create a table of all sprites
29
+ const gameTile = (i, size=16)=> tile(i, size, 0, 1);
26
30
  spriteAtlas =
27
31
  {
28
32
  // large tiles
29
- circle: tile(0),
30
- crate: tile(2),
31
- player: tile(3),
32
- enemy: tile(5),
33
- coin: tile(6),
33
+ circle: gameTile(0),
34
+ crate: gameTile(1),
35
+ player: gameTile(2),
36
+ enemy: gameTile(4),
37
+ coin: gameTile(5),
34
38
 
35
39
  // small tiles
36
- gun: tile(2,8),
37
- grenade: tile(3,8),
40
+ gun: gameTile(vec2(0,2),8),
41
+ grenade: gameTile(vec2(1,2),8),
38
42
  };
43
+
39
44
  // setup level
40
45
  buildLevel();
41
46
 
42
47
  // init game
43
48
  score = deaths = 0;
44
- gravity = -.01;
45
- objectDefaultDamping = .99;
46
- objectDefaultAngleDamping = .99;
47
- cameraScale = 4*16;
48
- cameraPos = getCameraTarget();
49
49
  }
50
50
 
51
51
  ///////////////////////////////////////////////////////////////////////////////
@@ -77,6 +77,10 @@ function gameUpdate()
77
77
  // M = move player to mouse
78
78
  if (keyWasPressed('KeyM'))
79
79
  player.pos = mousePos;
80
+
81
+ // R = restart level
82
+ if (keyWasPressed('KeyR'))
83
+ buildLevel();
80
84
  }
81
85
 
82
86
  ///////////////////////////////////////////////////////////////////////////////
@@ -15,7 +15,7 @@ class Character extends GameObject
15
15
  {
16
16
  constructor(pos)
17
17
  {
18
- super(pos, vec2(.6,.95), tile());
18
+ super(pos, vec2(.6,.95));
19
19
 
20
20
  this.weapon = new Weapon(pos, this);
21
21
  this.lastPos = pos;
@@ -178,7 +178,7 @@ class Character extends GameObject
178
178
 
179
179
  // apply movement acceleration and clamp
180
180
  const maxCharacterSpeed = .2;
181
- this.velocity.x = clamp(this.velocity.x + moveInput.x * .042, -maxCharacterSpeed, maxCharacterSpeed);
181
+ this.velocity.x = clamp(this.velocity.x + moveInput.x * .04, -maxCharacterSpeed, maxCharacterSpeed);
182
182
 
183
183
  // track last pos for ladder collision code
184
184
  this.lastPos = this.pos.copy();
@@ -226,7 +226,7 @@ class Character extends GameObject
226
226
  if (!this.isDead())
227
227
  {
228
228
  // bounce pos with walk cycle
229
- bodyPos = bodyPos.add(vec2(0,.05*Math.sin(this.walkCyclePercent*PI)));
229
+ bodyPos = bodyPos.add(vec2(0,.01+.05*Math.sin(this.walkCyclePercent*PI)));
230
230
 
231
231
  // make bottom flush
232
232
  bodyPos = bodyPos.add(vec2(0,(this.drawSize.y-this.size.y)/2));
@@ -35,6 +35,7 @@ function buildLevel()
35
35
 
36
36
  // spawn player
37
37
  player = new Player(playerStartPos);
38
+ cameraPos = getCameraTarget();
38
39
  }
39
40
 
40
41
  function loadLevel(level=0)
@@ -7,11 +7,11 @@
7
7
  <link rel=icon type=image/png href=../favicon.png>
8
8
  </head><body>
9
9
 
10
- <script src=../../dist/littlejs.js?1100></script>
11
- <script src=gameObjects.js?1100></script>
12
- <script src=gameCharacter.js?1100></script>
13
- <script src=gamePlayer.js?1100></script>
14
- <script src=gameEffects.js?1100></script>
15
- <script src=gameLevel.js?1100></script>
16
- <script src=gameLevelData.js?1100></script>
17
- <script src=game.js?1100></script>
10
+ <script src=../../dist/littlejs.js?1105></script>
11
+ <script src=gameObjects.js?1105></script>
12
+ <script src=gameCharacter.js?1105></script>
13
+ <script src=gamePlayer.js?1105></script>
14
+ <script src=gameEffects.js?1105></script>
15
+ <script src=gameLevel.js?1105></script>
16
+ <script src=gameLevelData.js?1105></script>
17
+ <script src=game.js?1105></script>
Binary file
@@ -13,6 +13,7 @@ setShowSplashScreen(true);
13
13
 
14
14
  // do not use pixelated rendering
15
15
  setCanvasPixelated(false);
16
+ setTilesPixelated(false);
16
17
 
17
18
  const fallTime = .2;
18
19
  const cameraOffset = vec2(0,-.5);
@@ -223,8 +224,8 @@ function gameRender()
223
224
  function gameRenderPost()
224
225
  {
225
226
  // draw text on top of everything
226
- drawText('Score: ' + score, cameraPos.add(vec2(-3,-3.1)), .9, hsl(), .1);
227
- drawText('Best: ' + bestScore, cameraPos.add(vec2( 3,-3.1)), .9, hsl(), .1);
227
+ drawTextOverlay('Score: ' + score, cameraPos.add(vec2(-3,-3.1)), .9, hsl(), .1);
228
+ drawTextOverlay('Best: ' + bestScore, cameraPos.add(vec2( 3,-3.1)), .9, hsl(), .1);
228
229
  }
229
230
 
230
231
  ///////////////////////////////////////////////////////////////////////////////
@@ -6,5 +6,5 @@
6
6
  <link rel=icon type=image/png href=../favicon.png>
7
7
  </head><body>
8
8
 
9
- <script src=../../dist/littlejs.js?1100></script>
10
- <script src=game.js?1100></script>
9
+ <script src=../../dist/littlejs.js?1105></script>
10
+ <script src=game.js?1105></script>
@@ -7,8 +7,9 @@
7
7
 
8
8
  'use strict';
9
9
 
10
- // show the LittleJS splash screen
11
- setShowSplashScreen(true);
10
+
11
+ // fix texture bleeding by shrinking tile slightly
12
+ tileFixBleedScale = .5;
12
13
 
13
14
  // sound effects
14
15
  const sound_click = new Sound([1,.5]);
@@ -63,7 +64,7 @@ function gameInit()
63
64
  // create particle emitter
64
65
  particleEmitter = new ParticleEmitter(
65
66
  vec2(16,9), 0, // emitPos, emitAngle
66
- 0, 0, 500, PI, // emitSize, emitTime, emitRate, emiteCone
67
+ 0, 0, 0, PI, // emitSize, emitTime, emitRate, emiteCone
67
68
  tile(0, 16), // tileIndex, tileSize
68
69
  hsl(1,1,1), hsl(0,0,0), // colorStartA, colorStartB
69
70
  hsl(0,0,0,0), hsl(0,0,0,0), // colorEndA, colorEndB
@@ -108,19 +109,55 @@ function gameUpdatePost()
108
109
  function gameRender()
109
110
  {
110
111
  // draw a grey square in the background without using webgl
111
- drawRect(vec2(16,8), vec2(20,14), hsl(0,0,.6), 0, false);
112
+ drawRect(vec2(16,8), vec2(202,214), hsl(0,0,.6), 0, false);
112
113
 
113
- // draw the logo as a tile
114
- drawTile(vec2(21,5), vec2(4.5), tile(3,128));
115
114
  }
116
115
 
117
116
  ///////////////////////////////////////////////////////////////////////////////
118
117
  function gameRenderPost()
119
118
  {
120
- // draw to overlay canvas for hud rendering
121
- drawTextScreen('LittleJS Engine Demo',
122
- vec2(mainCanvasSize.x/2, 70), 80, // position, size
123
- hsl(0,0,1), 6, hsl(0,0,0)); // color, outline size and color
119
+ drawNineSlice(vec2(10,10), vec2(4,4), tile(1))
120
+ }
121
+
122
+ function drawNineSlice(pos, size, tileInfo, context=overlayContext)
123
+ {
124
+ // calculate the size of a slice
125
+ const s = tileInfo.size.x / 3;
126
+
127
+ // define the 9 parts as [x, y, width, height]
128
+ const part1 = [0, 0, s, s];
129
+ const part2 = [s, 0, s, s];
130
+ const part3 = [s * 2, 0, s, s];
131
+ const part4 = [0, s, s, s];
132
+ const part5 = [s, s, s, s];
133
+ const part6 = [s * 2, s, s, s];
134
+ const part7 = [0, s * 2, s, s];
135
+ const part8 = [s, s * 2, s, s];
136
+ const part9 = [s * 2, s * 2, s, s];
137
+
138
+ // target width/height (try different values!)
139
+ const width = 16 * size.x;
140
+ const height = 16 * size.y;
141
+
142
+ const img = tileInfo.getTextureInfo().image;
143
+
144
+ const originPos = pos.subtract(size.divide(vec2(2))).add(vec2( - 0.5));
145
+
146
+ // draw the corners
147
+ //context.imageSmoothingEnabled = false
148
+ context.drawImage(img, ...part1, originPos.x + 0, originPos.y + 0, s + 1, s + 1); // top left
149
+ context.drawImage(img, ...part3, originPos.x + width - s, originPos.y + 0, s + 1, s + 1); // top right
150
+ context.drawImage(img, ...part7, originPos.x + 0, originPos.y + height - s, s + 1, s + 1); // bottom left
151
+ context.drawImage(img, ...part9, originPos.x + width - s, originPos.y + height - s, s + 1, s + 1); // bottom right
152
+
153
+ // draw the edges
154
+ context.drawImage(img, ...part2, originPos.x + s, originPos.y + 0, width - 2 * s + 1, s + 1); // top
155
+ context.drawImage(img, ...part8, originPos.x + s, originPos.y + height - s, width - 2 * s + 1, s + 1); // bottom
156
+ context.drawImage(img, ...part4, originPos.x + 0, originPos.y + s, s + 1, height - 2 * s + 1); // left
157
+ context.drawImage(img, ...part6, originPos.x + width - s, originPos.y + s, s + 1, height - 2 * s + 1); // right
158
+
159
+ // draw the center
160
+ context.drawImage(img, ...part5, originPos.x + s, originPos.y + s, width - 2 * s + 1, height - 2 * s + 1);
124
161
  }
125
162
 
126
163
  ///////////////////////////////////////////////////////////////////////////////
@@ -7,18 +7,18 @@
7
7
  </head><body>
8
8
 
9
9
  <!-- LittleJS Engine -->
10
- <script src=../../src/engineDebug.js?1100></script>
11
- <script src=../../src/engineUtilities.js?1100></script>
12
- <script src=../../src/engineSettings.js?1100></script>
13
- <script src=../../src/engineObject.js?1100></script>
14
- <script src=../../src/engineDraw.js?1100></script>
15
- <script src=../../src/engineInput.js?1100></script>
16
- <script src=../../src/engineAudio.js?1100></script>
17
- <script src=../../src/engineTileLayer.js?1100></script>
18
- <script src=../../src/engineParticles.js?1100></script>
19
- <script src=../../src/engineMedals.js?1100></script>
20
- <script src=../../src/engineWebGL.js?1100></script>
21
- <script src=../../src/engine.js?1100></script>
10
+ <script src=../../src/engineDebug.js?1105></script>
11
+ <script src=../../src/engineUtilities.js?1105></script>
12
+ <script src=../../src/engineSettings.js?1105></script>
13
+ <script src=../../src/engineObject.js?1105></script>
14
+ <script src=../../src/engineDraw.js?1105></script>
15
+ <script src=../../src/engineInput.js?1105></script>
16
+ <script src=../../src/engineAudio.js?1105></script>
17
+ <script src=../../src/engineTileLayer.js?1105></script>
18
+ <script src=../../src/engineParticles.js?1105></script>
19
+ <script src=../../src/engineMedals.js?1105></script>
20
+ <script src=../../src/engineWebGL.js?1105></script>
21
+ <script src=../../src/engine.js?1105></script>
22
22
 
23
23
  <!-- Add your game scripts here -->
24
- <script src=game.js?1100></script>
24
+ <script src=game.js?1105></script>
Binary file
@@ -7,7 +7,7 @@
7
7
  </head><body>
8
8
 
9
9
  <!-- LittleJS Engine -->
10
- <script src=../../dist/littlejs.min.js?1100></script>
10
+ <script src=../../dist/littlejs.min.js?1105></script>
11
11
  <script>
12
12
 
13
13
  /*
@@ -9,6 +9,8 @@ import * as LittleJS from '../../dist/littlejs.esm.js';
9
9
  const { tile, vec2, hsl } = LittleJS;
10
10
  // show the LittleJS splash screen
11
11
  LittleJS.setShowSplashScreen(true);
12
+ // fix texture bleeding by shrinking tile slightly
13
+ LittleJS.setTileFixBleedScale(.5);
12
14
  // sound effects
13
15
  const sound_click = new LittleJS.Sound([1, .5]);
14
16
  // medals
@@ -13,6 +13,9 @@ const {tile, vec2, hsl} = LittleJS;
13
13
  // show the LittleJS splash screen
14
14
  LittleJS.setShowSplashScreen(true);
15
15
 
16
+ // fix texture bleeding by shrinking tile slightly
17
+ LittleJS.setTileFixBleedScale(.5);
18
+
16
19
  // sound effects
17
20
  const sound_click = new LittleJS.Sound([1,.5]);
18
21
 
@@ -7,4 +7,4 @@
7
7
  </head><body>
8
8
 
9
9
  <!-- Add your game scripts here -->
10
- <script src=game.js?1100 type=module></script>
10
+ <script src=game.js?1105 type=module></script>