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
@@ -13,7 +13,7 @@ function spawnBox(pos, size=1, color=WHITE, type=box2dBodyTypeDynamic, applyText
13
13
  {
14
14
  size = typeof size == 'number' ? vec2(size) : size; // square
15
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
+ o.drawSize = size.scale(1.02); // slightly enlarge to cover gaps
17
17
  o.addBox(size);
18
18
  return o;
19
19
  }
@@ -405,7 +405,7 @@ class ClothObject extends Box2dObject
405
405
  const stress = vec2(j.GetReactionForce(1)).length();
406
406
  if (stress > this.maxJointStress || d2 > maxLength2*4)
407
407
  {
408
- // remove stessed joint
408
+ // remove stressed joint
409
409
  box2dDestroyJoint(j);
410
410
  joints[i] = 0;
411
411
  }
@@ -463,7 +463,7 @@ function explosion(pos, radius=3, strength=300)
463
463
  // smoke
464
464
  new ParticleEmitter(
465
465
  pos, 0, // pos, angle
466
- radius/2, .2, 50*radius, PI,// emitSize, emitTime, emitRate, emiteCone
466
+ radius/2, .2, 50*radius, PI,// emitSize, emitTime, emitRate, emitCone
467
467
  spriteAtlas.dot, // tileInfo
468
468
  hsl(0,0,0), hsl(0,0,0), // colorStartA, colorStartB
469
469
  hsl(0,0,0,0), hsl(0,0,0,0), // colorEndA, colorEndB
@@ -475,7 +475,7 @@ function explosion(pos, radius=3, strength=300)
475
475
  // fire
476
476
  new ParticleEmitter(
477
477
  pos, 0, // pos, angle
478
- radius, .1, 100*radius, PI, // emitSize, emitTime, emitRate, emiteCone
478
+ radius, .1, 100*radius, PI, // emitSize, emitTime, emitRate, emitCone
479
479
  spriteAtlas.dot, // tileInfo
480
480
  hsl(0,1,.5), hsl(.15,1,.5), // colorStartA, colorStartB
481
481
  hsl(0,1,.5,0), hsl(.1, 1,.5,0), // colorEndA, colorEndB
@@ -1,5 +1,5 @@
1
1
  /*
2
- LittleJS Box2D Example - Secenes
2
+ LittleJS Box2D Example - Scenes
3
3
  - Each scene demonstrates a feature of Box2D
4
4
  - Feel free to use tis code in your own projects
5
5
  - 0 = Shapes: box, circle, poly, and edge
@@ -122,7 +122,7 @@ function loadScene(_scene)
122
122
  const oaB = oB.localToWorld(vec2(0,oB.size.y/2));
123
123
  box2dCreatePulleyJoint(oA, oB, aA.pos, aB.pos, oaA, oaB);
124
124
 
125
- // a line to make it look like conneting rope
125
+ // a line to make it look like connecting rope
126
126
  const line = new EngineObject(vec2(20,15), vec2(10,.2), 0, 0, BLACK);
127
127
  line.gravityScale = 0;
128
128
  line.renderOrder = -1;
@@ -24,7 +24,7 @@ function gameInit()
24
24
  canvasFixedSize = vec2(1280, 720); // 720p
25
25
  levelSize = vec2(38, 20);
26
26
  cameraPos = levelSize.scale(.5);
27
- paddle = new Paddle(vec2(levelSize.x/2-12,1));
27
+ paddle = new Paddle(vec2(levelSize.x/2-12, 1));
28
28
  score = brickCount = 0;
29
29
 
30
30
  // spawn bricks
@@ -5,27 +5,31 @@
5
5
  'use strict';
6
6
 
7
7
  ///////////////////////////////////////////////////////////////////////////////
8
- class Wall extends EngineObject
8
+ class PhysicsObject extends EngineObject
9
9
  {
10
- constructor(pos, size)
10
+ constructor(pos, size, tileInfo, angle, color)
11
11
  {
12
- super(pos, size);
13
-
14
- this.mass = 0; // make object have static physics
12
+ super(pos, size, tileInfo, angle, color);
15
13
  this.setCollision(); // make object collide
16
- this.color = hsl(0,0,0,0); // make object invisible
14
+ this.mass = 0; // make object have static physics
15
+ }
16
+ }
17
+
18
+ ///////////////////////////////////////////////////////////////////////////////
19
+ class Wall extends PhysicsObject
20
+ {
21
+ constructor(pos, size)
22
+ {
23
+ super(pos, size, 0, 0, new Color(0,0,0,0));
17
24
  }
18
25
  }
19
26
 
20
27
  ///////////////////////////////////////////////////////////////////////////////
21
- class Paddle extends EngineObject
28
+ class Paddle extends PhysicsObject
22
29
  {
23
30
  constructor(pos)
24
31
  {
25
32
  super(pos, vec2(5,.5));
26
-
27
- this.mass = 0; // make object have static physics
28
- this.setCollision(); // make object collide
29
33
  }
30
34
 
31
35
  update()
@@ -39,15 +43,12 @@ class Paddle extends EngineObject
39
43
  }
40
44
 
41
45
  ///////////////////////////////////////////////////////////////////////////////
42
- class Brick extends EngineObject
46
+ class Brick extends PhysicsObject
43
47
  {
44
48
  constructor(pos)
45
49
  {
46
50
  super(pos, vec2(2,1), tile(1, vec2(32,16)), 0, randColor());
47
51
  ++brickCount;
48
-
49
- this.mass = 0; // make object have static physics
50
- this.setCollision(); // make object collide
51
52
  }
52
53
 
53
54
  collideWithObject(o)
@@ -63,7 +64,7 @@ class Brick extends EngineObject
63
64
  const color2 = color1.lerp(hsl(), .5);
64
65
  new ParticleEmitter(
65
66
  this.pos, 0, // pos, angle
66
- this.size, .1, 200, PI, // emitSize, emitTime, emitRate, emiteCone
67
+ this.size, .1, 200, PI, // emitSize, emitTime, emitRate, emitCone
67
68
  tile(0, 16), // tileIndex, tileSize
68
69
  color1, color2, // colorStartA, colorStartB
69
70
  color1.scale(1,0), color2.scale(1,0), // colorEndA, colorEndB
@@ -84,22 +85,22 @@ class Brick extends EngineObject
84
85
  }
85
86
 
86
87
  ///////////////////////////////////////////////////////////////////////////////
87
- class Ball extends EngineObject
88
+ class Ball extends PhysicsObject
88
89
  {
89
90
  constructor(pos)
90
91
  {
91
92
  super(pos, vec2(.5), tile(0));
92
93
 
93
94
  // make a bouncy ball
94
- this.setCollision();
95
95
  this.velocity = vec2(0, -.1);
96
96
  this.elasticity = 1;
97
+ this.mass = 1;
97
98
 
98
99
  // attach a trail effect
99
100
  const color = hsl(0,0,.2);
100
101
  this.trailEffect = new ParticleEmitter(
101
102
  this.pos, 0, // pos, angle
102
- this.size, 0, 80, PI, // emitSize, emitTime, emitRate, emiteCone
103
+ this.size, 0, 80, PI, // emitSize, emitTime, emitRate, emitCone
103
104
  tile(0, 16), // tileIndex, tileSize
104
105
  color, color, // colorStartA, colorStartB
105
106
  color.scale(0), color.scale(0), // colorEndA, colorEndB
@@ -127,24 +128,22 @@ class Ball extends EngineObject
127
128
  {
128
129
  // prevent colliding with paddle if moving upwards
129
130
  if (o == paddle && this.velocity.y > 0)
130
- return 0;
131
-
132
- // speed up
133
- const speed = min(1.04*this.velocity.length(), .5);
134
- this.velocity = this.velocity.normalize(speed);
135
-
136
- // scale bounce sound pitch by speed
137
- sound_bounce.play(this.pos, 1, speed*2);
131
+ return false;
138
132
 
139
133
  if (o == paddle)
140
134
  {
141
135
  // put english on the ball when it collides with paddle
142
136
  this.velocity = this.velocity.rotate(.2 * (this.pos.x - o.pos.x));
143
137
  this.velocity.y = max(-this.velocity.y, .2);
144
- return 0;
138
+
139
+ // speed up
140
+ const speed = min(1.04*this.velocity.length(), .5);
141
+ this.velocity = this.velocity.normalize(speed);
142
+ sound_bounce.play(this.pos, 1, speed*2);
143
+
144
+ return false; // prevent default collision code
145
145
  }
146
146
 
147
- // prevent default collision with paddle
148
- return 1;
147
+ return true;
149
148
  }
150
149
  }
@@ -7,6 +7,6 @@
7
7
  </head><body>
8
8
 
9
9
  <script src=../../dist/littlejs.js?1105></script>
10
- <script src=../../plugins/postProcess.js></script>
10
+ <script src=../../plugins/postProcess.js?1105></script>
11
11
  <script src=gameObjects.js?1105></script>
12
12
  <script src=game.js?1105></script>
@@ -113,7 +113,7 @@ class Brick extends EngineObject
113
113
  const color = this.color;
114
114
  new ParticleEmitter(
115
115
  this.pos, 0, // pos, angle
116
- this.size, .1, 200, PI, // emitSize, emitTime, emitRate, emiteCone
116
+ this.size, .1, 200, PI, // emitSize, emitTime, emitRate, emitCone
117
117
  undefined, // tileInfo
118
118
  color, color, // colorStartA, colorStartB
119
119
  color.scale(1,0), color.scale(1,0), // colorEndA, colorEndB
@@ -16,8 +16,8 @@ iframe {width:480px; height:270px;}
16
16
  <a href="breakoutTutorial">Breakout Tutorial</a> - Tutorial Breakout example<br>
17
17
  <a href="puzzle">Puzzle</a> - Match 3 puzzle game with HD rendering and high score tracking<br>
18
18
  <a href="particles">Particle Designer</a> - Particle system editor and visualizer<br>
19
- <a href="js13k">JS13K Starter</a> - Special small size demo for JS13K Games<br>
20
19
  <a href="empty">Empty</a> - A blank hello world project for LittleJS<br>
20
+ <a href="module">LittleJS with Modules</a> - Loads LittleJS as a module<br>
21
21
  </p>
22
22
  <h2>Plugin Demos</h2>
23
23
  <p>
@@ -25,12 +25,6 @@ iframe {width:480px; height:270px;}
25
25
  <a href="uiSystem">UI System</a> - A simple hierarchical UI system using LittleJS rendering<br>
26
26
  <a href="htmlMenu">HTML UI Menu</a> - Example using html to create an overlay menu<br>
27
27
  </p>
28
- <h2>Environment Demos</h2>
29
- <p>
30
- <a href="module">LittleJS using modules</a> - Loads LittleJS as a module<br>
31
- <a href="typescript">LittleJS using TypeScript</a> - Uses LittleJS type definitions<br>
32
- <a href="electron">LittleJS building with Electron</a> - Builds to an executable<br>
33
- </p>
34
28
  <h2>Live Demos</h2>
35
29
  <p>
36
30
  <iframe id=iframe src="breakout"></iframe>
package/examples/logo.png CHANGED
Binary file
@@ -71,7 +71,7 @@ function gameInit()
71
71
  // create particle emitter
72
72
  particleEmitter = new LittleJS.ParticleEmitter(
73
73
  vec2(16,9), 0, // emitPos, emitAngle
74
- 1, 0, 500, Math.PI, // emitSize, emitTime, emitRate, emiteCone
74
+ 1, 0, 500, Math.PI, // emitSize, emitTime, emitRate, emitCone
75
75
  tile(0, 16), // tileIndex, tileSize
76
76
  hsl(1,1,1), hsl(0,0,0), // colorStartA, colorStartB
77
77
  hsl(0,0,0,0), hsl(0,0,0,0), // colorEndA, colorEndB
@@ -1,8 +1,8 @@
1
1
  /*
2
2
  Little JS Platforming Game
3
3
  - A basic platforming starter project
4
- - Platforming phyics and controls
5
- - Includes destructibe terrain
4
+ - Platforming physics and controls
5
+ - Includes destructible terrain
6
6
  - Control with keyboard, mouse, touch, or gamepad
7
7
  */
8
8
 
@@ -25,7 +25,7 @@ class Character extends GameObject
25
25
  this.dodgeTimer = new Timer;
26
26
  this.dodgeRechargeTimer = new Timer;
27
27
  this.deadTimer = new Timer;
28
- this.grendeThrowTimer = new Timer;
28
+ this.grenadeThrowTimer = new Timer;
29
29
  this.drawSize = vec2(1);
30
30
  this.color = hsl(rand(),1,.7);
31
31
  this.renderOrder = 10;
@@ -82,14 +82,14 @@ class Character extends GameObject
82
82
  if (!this.groundObject && this.getAliveTime() > .2)
83
83
  this.velocity.y += .2;
84
84
  }
85
- if (this.pressingThrow && !this.wasPressingThrow && !this.grendeThrowTimer.active())
85
+ if (this.pressingThrow && !this.wasPressingThrow && !this.grenadeThrowTimer.active())
86
86
  {
87
- // throw greande
87
+ // throw grenade
88
88
  const grenade = new Grenade(this.pos);
89
89
  grenade.velocity = this.velocity.add(vec2(this.getMirrorSign(),rand(.8,.7)).normalize(.2+rand(.02)));
90
90
  grenade.angleVelocity = this.getMirrorSign() * rand(.8,.5);
91
91
  sound_jump.play(this.pos);
92
- this.grendeThrowTimer.set(1);
92
+ this.grenadeThrowTimer.set(1);
93
93
  }
94
94
  this.wasPressingThrow = this.pressingThrow;
95
95
  }
@@ -276,7 +276,7 @@ class Character extends GameObject
276
276
  if (getTileCollisionData(pos.add(vec2(0,1))) // above
277
277
  && !getTileCollisionData(pos.add(vec2(1,0))) // left
278
278
  && !getTileCollisionData(pos.add(vec2(1,0)))) // right
279
- return false; // dont collide if something above it and nothing to left or right
279
+ return false; // don't collide if something above it and nothing to left or right
280
280
 
281
281
  // allow standing on top of ladders
282
282
  return !this.climbingLadder;
@@ -1,6 +1,6 @@
1
1
  /*
2
2
  LittleJS Platformer Example - Effects
3
- - Plays different particle effects which can be persistant
3
+ - Plays different particle effects which can be persistent
4
4
  - Destroys terrain and makes explosions
5
5
  - Outlines tiles based on neighbor types
6
6
  - Generates parallax background layers
@@ -39,7 +39,7 @@ function makeDebris(pos, color = hsl(), amount = 50, size=.2, elasticity = .3)
39
39
  {
40
40
  const color2 = color.lerp(hsl(), .5);
41
41
  const emitter = new ParticleEmitter(
42
- pos, 0, 1, .1, amount/.1, PI, // pos, angle, emitSize, emitTime, emitRate, emiteCone
42
+ pos, 0, 1, .1, amount/.1, PI, // pos, angle, emitSize, emitTime, emitRate, emitCone
43
43
  0, // tileInfo
44
44
  color, color2, // colorStartA, colorStartB
45
45
  color, color2, // colorEndA, colorEndB
@@ -97,7 +97,7 @@ function explosion(pos, radius=3)
97
97
  // smoke
98
98
  new ParticleEmitter(
99
99
  pos, 0, // pos, angle
100
- radius/2, .2, 50*radius, PI,// emitSize, emitTime, emitRate, emiteCone
100
+ radius/2, .2, 50*radius, PI,// emitSize, emitTime, emitRate, emitCone
101
101
  0, // tileInfo
102
102
  hsl(0,0,0), hsl(0,0,0), // colorStartA, colorStartB
103
103
  hsl(0,0,0,0), hsl(0,0,0,0), // colorEndA, colorEndB
@@ -109,7 +109,7 @@ function explosion(pos, radius=3)
109
109
  // fire
110
110
  new ParticleEmitter(
111
111
  pos, 0, // pos, angle
112
- radius/2, .1, 100*radius, PI, // emitSize, emitTime, emitRate, emiteCone
112
+ radius/2, .1, 100*radius, PI, // emitSize, emitTime, emitRate, emitCone
113
113
  0, // tileInfo
114
114
  rgb(1,.5,.1), rgb(1,.1,.1), // colorStartA, colorStartB
115
115
  rgb(1,.5,.1,0), rgb(1,.1,.1,0), // colorEndA, colorEndB
@@ -239,7 +239,7 @@ class Weapon extends EngineObject
239
239
 
240
240
  // shell effect
241
241
  this.addChild(this.shellEmitter = new ParticleEmitter(
242
- vec2(), 0, 0, 0, 0, .1, // pos, angle, emitSize, emitTime, emitRate, emiteCone
242
+ vec2(), 0, 0, 0, 0, .1, // pos, angle, emitSize, emitTime, emitRate, emitCone
243
243
  0, // tileInfo
244
244
  rgb(1,.8,.5), rgb(.9,.7,.5), // colorStartA, colorStartB
245
245
  rgb(1,.8,.5), rgb(.9,.7,.5), // colorEndA, colorEndB
@@ -360,7 +360,7 @@ class Bullet extends EngineObject
360
360
 
361
361
  // spark effects
362
362
  const emitter = new ParticleEmitter(
363
- this.pos, 0, 0, .1, 100, .5, // pos, angle, emitSize, emitTime, emitRate, emiteCone
363
+ this.pos, 0, 0, .1, 100, .5, // pos, angle, emitSize, emitTime, emitRate, emitCone
364
364
  0, // tileInfo
365
365
  rgb(1,1,0), rgb(1,0,0), // colorStartA, colorStartB
366
366
  rgb(1,1,0), rgb(1,0,0), // colorEndA, colorEndB
@@ -37,7 +37,7 @@ const tileColors =
37
37
  rgb(1,1,0),
38
38
  rgb(0,1,0),
39
39
  rgb(0,.6,1),
40
- rgb(.6,0,1),
40
+ rgb(.8,0,1),
41
41
  rgb(.5,.5,.5),
42
42
  ];
43
43
  const tileTypeCount = tileColors.length;
@@ -216,7 +216,7 @@ function gameRender()
216
216
  drawTile(drawPos, vec2(.5), tile(data, 64), color2);
217
217
  }
218
218
 
219
- // draw a grey square at top to cover up incomming tiles
219
+ // draw a grey square at top to cover up incoming tiles
220
220
  drawRect(cameraPos.subtract(cameraOffset).add(vec2(0,levelSize.y)), levelSize, backgroundColor);
221
221
  }
222
222
 
@@ -294,7 +294,7 @@ function clearMatches()
294
294
  const color2 = color1.lerp(hsl(), .5);
295
295
  new ParticleEmitter(
296
296
  pos.add(vec2(.5)), 0, // pos, angle
297
- .5, .1, 200, PI, // emitSize, emitTime, emitRate, emiteCone
297
+ .5, .1, 200, PI, // emitSize, emitTime, emitRate, emitCone
298
298
  0, // tileInfo
299
299
  color1, color2, // colorStartA, colorStartB
300
300
  color1.scale(1,0), color2.scale(1,0),// colorEndA, colorEndB
@@ -7,6 +7,8 @@
7
7
 
8
8
  'use strict';
9
9
 
10
+ // show the LittleJS splash screen
11
+ setShowSplashScreen(true);
10
12
 
11
13
  // fix texture bleeding by shrinking tile slightly
12
14
  tileFixBleedScale = .5;
@@ -64,13 +66,13 @@ function gameInit()
64
66
  // create particle emitter
65
67
  particleEmitter = new ParticleEmitter(
66
68
  vec2(16,9), 0, // emitPos, emitAngle
67
- 0, 0, 0, PI, // emitSize, emitTime, emitRate, emiteCone
69
+ 0, 0, 500, PI, // emitSize, emitTime, emitRate, emitCone
68
70
  tile(0, 16), // tileIndex, tileSize
69
71
  hsl(1,1,1), hsl(0,0,0), // colorStartA, colorStartB
70
72
  hsl(0,0,0,0), hsl(0,0,0,0), // colorEndA, colorEndB
71
73
  2, .2, .2, .1, .05, // time, sizeStart, sizeEnd, speed, angleSpeed
72
74
  .99, 1, 1, PI, // damping, angleDamping, gravityScale, cone
73
- .05, .5, true, true // fadeRate, randomness, collide, additive
75
+ .05, .8, true, true // fadeRate, randomness, collide, additive
74
76
  );
75
77
  particleEmitter.elasticity = .3; // bounce when it collides
76
78
  particleEmitter.trailScale = 2; // stretch in direction of motion
@@ -109,55 +111,19 @@ function gameUpdatePost()
109
111
  function gameRender()
110
112
  {
111
113
  // draw a grey square in the background without using webgl
112
- drawRect(vec2(16,8), vec2(202,214), hsl(0,0,.6), 0, false);
114
+ drawRect(vec2(16,8), vec2(20,14), hsl(0,0,.6), 0, false);
113
115
 
116
+ // draw the logo as a tile
117
+ drawTile(vec2(21,5), vec2(4.5), tile(3,128));
114
118
  }
115
119
 
116
120
  ///////////////////////////////////////////////////////////////////////////////
117
121
  function gameRenderPost()
118
122
  {
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);
123
+ // draw to overlay canvas for hud rendering
124
+ drawTextScreen('LittleJS Demo',
125
+ vec2(mainCanvasSize.x/2, 70), 80, // position, size
126
+ hsl(0,0,1), 6, hsl(0,0,0)); // color, outline size and color
161
127
  }
162
128
 
163
129
  ///////////////////////////////////////////////////////////////////////////////
Binary file
package/jsconfig.json CHANGED
@@ -5,6 +5,7 @@
5
5
  "./src/*.js",
6
6
  "./plugins/*.js",
7
7
  "./examples/**/*.js",
8
+ "./shortExamples/**/*.js",
8
9
  ],
9
10
  "exclude": [
10
11
  ]
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "littlejsengine",
3
- "version": "1.11.2",
3
+ "version": "1.11.5",
4
4
  "description": "LittleJS - Tiny and Fast HTML5 Game Engine",
5
5
  "main": "dist/littlejs.esm.js",
6
6
  "types": "dist/littlejs.d.ts",
package/plugins/box2d.js CHANGED
@@ -69,7 +69,7 @@ class Box2dObject extends EngineObject
69
69
  {
70
70
  const isAsleep = !this.getIsAwake();
71
71
  const isStatic = this.getIsStatic();
72
- const color = rgb(isAsleep,isAsleep,isStatic,.5);
72
+ const color = rgb(isAsleep?1:0 ,isAsleep?1:0, isStatic?1:0, .5);
73
73
  this.box2dDrawFixtures(color);
74
74
  }
75
75
 
@@ -353,7 +353,7 @@ function box2dBoxCastAll(pos, size)
353
353
 
354
354
  let queryObjects = [];
355
355
  box2dWorld.QueryAABB(queryCallback, aabb);
356
- debugRaycast && debugRect(pos, size, raycstResult ? '#f00' : '#00f', .02);
356
+ debugRaycast && debugRect(pos, size, queryObjects.length ? '#f00' : '#00f', .02);
357
357
  return queryObjects;
358
358
  }
359
359
 
@@ -374,7 +374,7 @@ function box2dBoxCast(pos, size)
374
374
 
375
375
  let queryObject;
376
376
  box2dWorld.QueryAABB(queryCallback, aabb);
377
- debugRaycast && debugRect(pos, size, raycstResult ? '#f00' : '#00f', .02);
377
+ debugRaycast && debugRect(pos, size, queryObject ? '#f00' : '#00f', .02);
378
378
  return queryObject;
379
379
  }
380
380
 
@@ -416,7 +416,7 @@ function box2dPointCast(pos, dynamicOnly=true)
416
416
  return true; // continue getting results
417
417
  if (!fixture.TestPoint(pos.getBox2d()))
418
418
  return true; // continue getting results
419
- queryResult = fixture.GetBody().object;
419
+ queryObject = fixture.GetBody().object;
420
420
  return false; // stop getting results
421
421
  };
422
422
 
@@ -424,10 +424,10 @@ function box2dPointCast(pos, dynamicOnly=true)
424
424
  aabb.set_lowerBound(pos.getBox2d());
425
425
  aabb.set_upperBound(pos.getBox2d());
426
426
 
427
- let queryResult;
428
- debugRaycast && debugRect(pos, vec2(), queryResult ? '#f00' : '#00f', .02);
427
+ let queryObject;
428
+ debugRaycast && debugRect(pos, vec2(), queryObject ? '#f00' : '#00f', .02);
429
429
  box2dWorld.QueryAABB(queryCallback, aabb);
430
- return queryResult;
430
+ return queryObject;
431
431
  }
432
432
 
433
433
  // box aabb cast and return all the fixtures
@@ -437,8 +437,8 @@ function box2dBoxCastAllFixtures(pos, size)
437
437
  queryCallback.ReportFixture = function(fixturePointer)
438
438
  {
439
439
  const fixture = box2d.wrapPointer(fixturePointer, box2d.b2Fixture);
440
- if (!queryObjects.includes(fixture))
441
- queryObjects.push(fixture); // add if not already in list
440
+ if (!queryFixtures.includes(fixture))
441
+ queryFixtures.push(fixture); // add if not already in list
442
442
  return true; // continue getting results
443
443
  };
444
444
 
@@ -448,7 +448,7 @@ function box2dBoxCastAllFixtures(pos, size)
448
448
 
449
449
  let queryFixtures = [];
450
450
  box2dWorld.QueryAABB(queryCallback, aabb);
451
- debugRaycast && debugRect(pos, size, raycstResult ? '#f00' : '#00f', .02);
451
+ debugRaycast && debugRect(pos, size, queryFixtures.length ? '#f00' : '#00f', .02);
452
452
  return queryFixtures;
453
453
  }
454
454
 
@@ -12,7 +12,7 @@
12
12
 
13
13
  ///////////////////////////////////////////////////////////////////////////////
14
14
 
15
- /** Newgrounds medal auto unlocks in newgronds API */
15
+ /** Newgrounds medal auto unlocks in newgrounds API */
16
16
  class NewgroundsMedal extends Medal
17
17
  {
18
18
  /** Create a medal object and adds it to the list of medals */
@@ -76,26 +76,26 @@ function initPostProcess(shaderCode, includeOverlay=false)
76
76
 
77
77
  // setup shader program to draw one triangle
78
78
  glContext.useProgram(glPostShader);
79
- glContext.bindBuffer(gl_ARRAY_BUFFER, glGeometryBuffer);
80
- glContext.pixelStorei(gl_UNPACK_FLIP_Y_WEBGL, 1);
81
- glContext.disable(gl_BLEND);
79
+ glContext.bindBuffer(glContext.ARRAY_BUFFER, glGeometryBuffer);
80
+ glContext.pixelStorei(glContext.UNPACK_FLIP_Y_WEBGL, 1);
81
+ glContext.disable(glContext.BLEND);
82
82
 
83
83
  // set textures, pass in the 2d canvas and gl canvas in separate texture channels
84
- glContext.activeTexture(gl_TEXTURE0);
85
- glContext.bindTexture(gl_TEXTURE_2D, glPostTexture);
86
- glContext.texImage2D(gl_TEXTURE_2D, 0, gl_RGBA, gl_RGBA, gl_UNSIGNED_BYTE, mainCanvas);
84
+ glContext.activeTexture(glContext.TEXTURE0);
85
+ glContext.bindTexture(glContext.TEXTURE_2D, glPostTexture);
86
+ glContext.texImage2D(glContext.TEXTURE_2D, 0, glContext.RGBA, glContext.RGBA, glContext.UNSIGNED_BYTE, mainCanvas);
87
87
 
88
88
  // set vertex position attribute
89
89
  const vertexByteStride = 8;
90
90
  const pLocation = glContext.getAttribLocation(glPostShader, 'p');
91
91
  glContext.enableVertexAttribArray(pLocation);
92
- glContext.vertexAttribPointer(pLocation, 2, gl_FLOAT, false, vertexByteStride, 0);
92
+ glContext.vertexAttribPointer(pLocation, 2, glContext.FLOAT, false, vertexByteStride, 0);
93
93
 
94
94
  // set uniforms and draw
95
95
  const uniformLocation = (name)=>glContext.getUniformLocation(glPostShader, name);
96
96
  glContext.uniform1i(uniformLocation('iChannel0'), 0);
97
97
  glContext.uniform1f(uniformLocation('iTime'), time);
98
98
  glContext.uniform3f(uniformLocation('iResolution'), mainCanvas.width, mainCanvas.height, 1);
99
- glContext.drawArrays(gl_TRIANGLE_STRIP, 0, 4);
99
+ glContext.drawArrays(glContext.TRIANGLE_STRIP, 0, 4);
100
100
  }
101
101
  }
@@ -0,0 +1,36 @@
1
+ <!DOCTYPE html><head><meta charset=utf-8></head><body>
2
+
3
+ <!-- LittleJS Engine -->
4
+ <script src=../src/engineDebug.js?1105></script>
5
+ <script src=../src/engineUtilities.js?1105></script>
6
+ <script src=../src/engineSettings.js?1105></script>
7
+ <script src=../src/engineObject.js?1105></script>
8
+ <script src=../src/engineDraw.js?1105></script>
9
+ <script src=../src/engineInput.js?1105></script>
10
+ <script src=../src/engineAudio.js?1105></script>
11
+ <script src=../src/engineTileLayer.js?1105></script>
12
+ <script src=../src/engineParticles.js?1105></script>
13
+ <script src=../src/engineMedals.js?1105></script>
14
+ <script src=../src/engineWebGL.js?1105></script>
15
+ <script src=../src/engine.js?1105></script>\
16
+ <script>
17
+
18
+ 'use strict';
19
+
20
+ // use fixed size canvas for examples
21
+ canvasFixedSize = vec2(960, 540);
22
+
23
+ // allow improved scaling
24
+ canvasPixelated = false;
25
+
26
+ // disable watermark
27
+ showWatermark = false;
28
+
29
+ // these functions can be overridden for each example
30
+ function gameInit() {}
31
+ function gameUpdate() {}
32
+ function gameUpdatePost() {}
33
+ function gameRender() {}
34
+ function gameRenderPost() {}
35
+
36
+ </script>
@@ -0,0 +1,12 @@
1
+ function gameRender()
2
+ {
3
+ // additive blend
4
+ setBlendMode(1);
5
+ drawTile(vec2(1, 3), vec2(6), tile(0), rgb(1,0,0));
6
+ drawTile(vec2(-1,3), vec2(6), tile(0), rgb(0,0,1));
7
+
8
+ // alpha blend
9
+ setBlendMode(0);
10
+ drawTile(vec2(1, -3), vec2(6), tile(0), rgb(1,0,0,.5));
11
+ drawTile(vec2(-1,-3), vec2(6), tile(0), rgb(0,0,1,.5));
12
+ }