littlejsengine 1.5.0 → 1.5.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.
@@ -113,7 +113,9 @@ function initPostProcess()
113
113
  float dx = 2.*p.x - 1., dy = 2.*p.y - 1.;
114
114
  c *= 1.-pow((dx*dx + dy*dy)/vignette, 6.);
115
115
  }`;
116
- glInitPostProcess(televisionShader);
116
+
117
+ const includeOverlay = true;
118
+ glInitPostProcess(televisionShader, includeOverlay);
117
119
  }
118
120
 
119
121
  ///////////////////////////////////////////////////////////////////////////////
@@ -5,6 +5,6 @@
5
5
  <link rel=icon type=image/png href=../../favicon.png>
6
6
  </head><body>
7
7
 
8
- <script src=../../engine/engine.all.js?123></script>
9
- <script src=gameObjects.js?123></script>
10
- <script src=game.js?123></script>
8
+ <script src=../../engine/engine.all.js?125></script>
9
+ <script src=gameObjects.js?125></script>
10
+ <script src=game.js?125></script>
@@ -6,4 +6,4 @@
6
6
  </head><body>
7
7
 
8
8
  <!-- Add your game scripts here -->
9
- <script src=game.js?123 type=module></script>
9
+ <script src=game.js?125 type=module></script>
@@ -15,7 +15,7 @@ button
15
15
  </style>
16
16
  </head><body>
17
17
 
18
- <script src=../../engine/engine.all.js?123></script>
18
+ <script src=../../engine/engine.all.js?125></script>
19
19
  <script>
20
20
 
21
21
  'use strict';
@@ -16,6 +16,8 @@ function gameInit()
16
16
  // setup game
17
17
  score = deaths = 0;
18
18
  gravity = -.01;
19
+ objectDefaultDamping = .99;
20
+ objectDefaultAngleDamping = .99;
19
21
  cameraScale = 4*16;
20
22
  gameTimer.set();
21
23
  buildLevel();
@@ -64,9 +64,9 @@ class GameObject extends EngineObject
64
64
 
65
65
  class Crate extends GameObject
66
66
  {
67
- constructor(pos, typeOverride)
67
+ constructor(pos)
68
68
  {
69
- super(pos, objectDefaultSize, 2, vec2(16), (randInt(4))*PI/2);
69
+ super(pos, vec2(1), 2, vec2(16), (randInt(4))*PI/2);
70
70
 
71
71
  this.color = (new Color).setHSLA(rand(),1,.8);
72
72
  this.health = 5;
@@ -90,7 +90,7 @@ class Crate extends GameObject
90
90
 
91
91
  class Enemy extends GameObject
92
92
  {
93
- constructor(pos, typeOverride)
93
+ constructor(pos)
94
94
  {
95
95
  super(pos, vec2(.9,.9), 8, vec2(16));
96
96
 
@@ -5,9 +5,9 @@
5
5
  <link rel=icon type=image/png href=../../favicon.png>
6
6
  </head><body>
7
7
 
8
- <script src=../../engine/engine.all.js?123></script>
9
- <script src=gameObjects.js?123></script>
10
- <script src=gamePlayer.js?123></script>
11
- <script src=gameEffects.js?123></script>
12
- <script src=gameLevel.js?123></script>
13
- <script src=game.js?123></script>
8
+ <script src=../../engine/engine.all.js?125></script>
9
+ <script src=gameObjects.js?125></script>
10
+ <script src=gamePlayer.js?125></script>
11
+ <script src=gameEffects.js?125></script>
12
+ <script src=gameLevel.js?125></script>
13
+ <script src=game.js?125></script>
@@ -5,5 +5,5 @@
5
5
  <link rel=icon type=image/png href=../../favicon.png>
6
6
  </head><body>
7
7
 
8
- <script src=../../engine/engine.all.js?123></script>
9
- <script src=game.js?123></script>
8
+ <script src=../../engine/engine.all.js?125></script>
9
+ <script src=game.js?125></script>
@@ -5,7 +5,7 @@
5
5
  <link rel=icon type=image/png href=../../favicon.png>
6
6
  </head><body>
7
7
 
8
- <script src=../../engine/engine.all.min.js?123></script>
8
+ <script src=../../engine/engine.all.min.js?125></script>
9
9
  <script>
10
10
 
11
11
  /*
@@ -20,7 +20,7 @@
20
20
  'use strict';
21
21
 
22
22
  // keep our own list of simple sprites and track fps
23
- let sprites, timeMS, showFPS, statsDisplay, spriteColor, spriteAdditiveColor, musicSource;
23
+ let sprites, timeMS, showFPS, statsDisplay, spriteColor, spriteAdditiveColor;
24
24
 
25
25
  ///////////////////////////////////////////////////////////////////////////////
26
26
 
@@ -60,8 +60,8 @@ function gameInit()
60
60
  ///////////////////////////////////////////////////////////////////////////////
61
61
  function gameUpdate()
62
62
  {
63
- if (!musicSource && mouseWasPressed(0))
64
- musicSource = music.play();
63
+ if (!music.isPlaying() && mouseWasPressed(0))
64
+ music.play();
65
65
 
66
66
  // mouse click = change color
67
67
  if (mouseWasPressed(0) || mouseIsDown(2))
@@ -1,89 +1,89 @@
1
- /*
2
- LittleJS Hello World Starter Game
3
- */
4
- 'use strict';
5
- // import module
6
- import * as LittleJS from '../../engine/engine.all.module.js';
7
- const { Vector2, Color, Timer, vec2 } = LittleJS;
8
- // sound effects
9
- const sound_click = new LittleJS.Sound([1, .5]);
10
- // medals
11
- const medal_example = new LittleJS.Medal(0, 'Example Medal', 'Welcome to LittleJS!');
12
- LittleJS.medalsInit('Hello World');
13
- // game variables
14
- let particleEmiter;
15
- ///////////////////////////////////////////////////////////////////////////////
16
- function gameInit() {
17
- // create tile collision and visible tile layer
18
- LittleJS.initTileCollision(vec2(32, 16));
19
- const pos = vec2();
20
- const tileLayer = new LittleJS.TileLayer(pos, LittleJS.tileCollisionSize);
21
- // get level data from the tiles image
22
- const imageLevelDataRow = 1;
23
- const mainContext = LittleJS.mainContext;
24
- mainContext.drawImage(LittleJS.tileImage, 0, 0);
25
- for (pos.x = LittleJS.tileCollisionSize.x; pos.x--;)
26
- for (pos.y = LittleJS.tileCollisionSize.y; pos.y--;) {
27
- const imageData = mainContext.getImageData(pos.x, 16 * (imageLevelDataRow + 1) - pos.y - 1, 1, 1).data;
28
- if (imageData[0]) {
29
- const tileIndex = 1;
30
- const direction = LittleJS.randInt(4);
31
- const mirror = LittleJS.randInt(2) ? true : false;
32
- const color = LittleJS.randColor();
33
- const data = new LittleJS.TileLayerData(tileIndex, direction, mirror, color);
34
- tileLayer.setData(pos, data);
35
- LittleJS.setTileCollisionData(pos, 1);
36
- }
37
- }
38
- tileLayer.redraw();
39
- // move camera to center of collision
40
- LittleJS.setCameraPos(LittleJS.tileCollisionSize.scale(.5));
41
- // enable gravity
42
- LittleJS.setGravity(-.01);
43
- // create particle emitter
44
- const center = LittleJS.tileCollisionSize.scale(.5).add(vec2(0, 9));
45
- particleEmiter = new LittleJS.ParticleEmitter(center, 0, // emitPos, emitAngle
46
- 1, 0, 500, Math.PI, // emitSize, emitTime, emitRate, emiteCone
47
- 0, vec2(16), // tileIndex, tileSize
48
- new Color(1, 1, 1), new Color(0, 0, 0), // colorStartA, colorStartB
49
- new Color(1, 1, 1, 0), new Color(0, 0, 0, 0), // colorEndA, colorEndB
50
- 2, .2, .2, .1, .05, // time, sizeStart, sizeEnd, speed, angleSpeed
51
- .99, 1, 1, Math.PI, // damping, angleDamping, gravityScale, cone
52
- .05, .5, true, true // fadeRate, randomness, collide, additive
53
- );
54
- particleEmiter.elasticity = .3; // bounce when it collides
55
- particleEmiter.trailScale = 2; // stretch in direction of motion
56
- }
57
- ///////////////////////////////////////////////////////////////////////////////
58
- function gameUpdate() {
59
- if (LittleJS.mouseWasPressed(0)) {
60
- // play sound when mouse is pressed
61
- sound_click.play(LittleJS.mousePos);
62
- // change particle color and set to fade out
63
- particleEmiter.colorStartA = new Color;
64
- particleEmiter.colorStartB = LittleJS.randColor();
65
- particleEmiter.colorEndA = particleEmiter.colorStartA.scale(1, 0);
66
- particleEmiter.colorEndB = particleEmiter.colorStartB.scale(1, 0);
67
- // unlock medals
68
- medal_example.unlock();
69
- }
70
- // move particles to mouse location if on screen
71
- if (LittleJS.mousePosScreen.x)
72
- particleEmiter.pos = LittleJS.mousePos;
73
- }
74
- ///////////////////////////////////////////////////////////////////////////////
75
- function gameUpdatePost() {
76
- }
77
- ///////////////////////////////////////////////////////////////////////////////
78
- function gameRender() {
79
- // draw a grey square in the background without using webgl
80
- LittleJS.drawRect(LittleJS.cameraPos, LittleJS.tileCollisionSize.add(vec2(5)), new Color(.2, .2, .2), 0, false);
81
- }
82
- ///////////////////////////////////////////////////////////////////////////////
83
- function gameRenderPost() {
84
- // draw to overlay canvas for hud rendering
85
- LittleJS.drawTextScreen('LittleJS with TypeScript', vec2(LittleJS.mainCanvasSize.x / 2, 80), 80);
86
- }
87
- ///////////////////////////////////////////////////////////////////////////////
88
- // Startup LittleJS Engine
89
- LittleJS.engineInit(gameInit, gameUpdate, gameUpdatePost, gameRender, gameRenderPost, 'tiles.png');
1
+ /*
2
+ LittleJS Hello World Starter Game
3
+ */
4
+ 'use strict';
5
+ // import module
6
+ import * as LittleJS from '../../engine/engine.all.module.js';
7
+ const { Vector2, Color, Timer, vec2 } = LittleJS;
8
+ // sound effects
9
+ const sound_click = new LittleJS.Sound([1, .5]);
10
+ // medals
11
+ const medal_example = new LittleJS.Medal(0, 'Example Medal', 'Welcome to LittleJS!');
12
+ LittleJS.medalsInit('Hello World');
13
+ // game variables
14
+ let particleEmiter;
15
+ ///////////////////////////////////////////////////////////////////////////////
16
+ function gameInit() {
17
+ // create tile collision and visible tile layer
18
+ LittleJS.initTileCollision(vec2(32, 16));
19
+ const pos = vec2();
20
+ const tileLayer = new LittleJS.TileLayer(pos, LittleJS.tileCollisionSize);
21
+ // get level data from the tiles image
22
+ const imageLevelDataRow = 1;
23
+ const mainContext = LittleJS.mainContext;
24
+ mainContext.drawImage(LittleJS.tileImage, 0, 0);
25
+ for (pos.x = LittleJS.tileCollisionSize.x; pos.x--;)
26
+ for (pos.y = LittleJS.tileCollisionSize.y; pos.y--;) {
27
+ const imageData = mainContext.getImageData(pos.x, 16 * (imageLevelDataRow + 1) - pos.y - 1, 1, 1).data;
28
+ if (imageData[0]) {
29
+ const tileIndex = 1;
30
+ const direction = LittleJS.randInt(4);
31
+ const mirror = LittleJS.randInt(2) ? true : false;
32
+ const color = LittleJS.randColor();
33
+ const data = new LittleJS.TileLayerData(tileIndex, direction, mirror, color);
34
+ tileLayer.setData(pos, data);
35
+ LittleJS.setTileCollisionData(pos, 1);
36
+ }
37
+ }
38
+ tileLayer.redraw();
39
+ // move camera to center of collision
40
+ LittleJS.setCameraPos(LittleJS.tileCollisionSize.scale(.5));
41
+ // enable gravity
42
+ LittleJS.setGravity(-.01);
43
+ // create particle emitter
44
+ const center = LittleJS.tileCollisionSize.scale(.5).add(vec2(0, 9));
45
+ particleEmiter = new LittleJS.ParticleEmitter(center, 0, // emitPos, emitAngle
46
+ 1, 0, 500, Math.PI, // emitSize, emitTime, emitRate, emiteCone
47
+ 0, vec2(16), // tileIndex, tileSize
48
+ new Color(1, 1, 1), new Color(0, 0, 0), // colorStartA, colorStartB
49
+ new Color(1, 1, 1, 0), new Color(0, 0, 0, 0), // colorEndA, colorEndB
50
+ 2, .2, .2, .1, .05, // time, sizeStart, sizeEnd, speed, angleSpeed
51
+ .99, 1, 1, Math.PI, // damping, angleDamping, gravityScale, cone
52
+ .05, .5, true, true // fadeRate, randomness, collide, additive
53
+ );
54
+ particleEmiter.elasticity = .3; // bounce when it collides
55
+ particleEmiter.trailScale = 2; // stretch in direction of motion
56
+ }
57
+ ///////////////////////////////////////////////////////////////////////////////
58
+ function gameUpdate() {
59
+ if (LittleJS.mouseWasPressed(0)) {
60
+ // play sound when mouse is pressed
61
+ sound_click.play(LittleJS.mousePos);
62
+ // change particle color and set to fade out
63
+ particleEmiter.colorStartA = new Color;
64
+ particleEmiter.colorStartB = LittleJS.randColor();
65
+ particleEmiter.colorEndA = particleEmiter.colorStartA.scale(1, 0);
66
+ particleEmiter.colorEndB = particleEmiter.colorStartB.scale(1, 0);
67
+ // unlock medals
68
+ medal_example.unlock();
69
+ }
70
+ // move particles to mouse location if on screen
71
+ if (LittleJS.mousePosScreen.x)
72
+ particleEmiter.pos = LittleJS.mousePos;
73
+ }
74
+ ///////////////////////////////////////////////////////////////////////////////
75
+ function gameUpdatePost() {
76
+ }
77
+ ///////////////////////////////////////////////////////////////////////////////
78
+ function gameRender() {
79
+ // draw a grey square in the background without using webgl
80
+ LittleJS.drawRect(LittleJS.cameraPos, LittleJS.tileCollisionSize.add(vec2(5)), new Color(.2, .2, .2), 0, false);
81
+ }
82
+ ///////////////////////////////////////////////////////////////////////////////
83
+ function gameRenderPost() {
84
+ // draw to overlay canvas for hud rendering
85
+ LittleJS.drawTextScreen('LittleJS with TypeScript', vec2(LittleJS.mainCanvasSize.x / 2, 80), 80);
86
+ }
87
+ ///////////////////////////////////////////////////////////////////////////////
88
+ // Startup LittleJS Engine
89
+ LittleJS.engineInit(gameInit, gameUpdate, gameUpdatePost, gameRender, gameRenderPost, 'tiles.png');
@@ -6,4 +6,4 @@
6
6
  </head><body>
7
7
 
8
8
  <!-- Add your game scripts here -->
9
- <script src=game.js?123 type=module></script>
9
+ <script src=game.js?125 type=module></script>
package/index.html CHANGED
@@ -6,21 +6,21 @@
6
6
  </head><body>
7
7
 
8
8
  <!-- LittleJS engine scripts -->
9
- <script src=engine/engineDebug.js?123></script>
10
- <script src=engine/engineUtilities.js?123></script>
11
- <script src=engine/engineSettings.js?123></script>
12
- <script src=engine/engineObject.js?123></script>
13
- <script src=engine/engineDraw.js?123></script>
14
- <script src=engine/engineInput.js?123></script>
15
- <script src=engine/engineAudio.js?123></script>
16
- <script src=engine/engineTileLayer.js?123></script>
17
- <script src=engine/engineParticles.js?123></script>
18
- <script src=engine/engineMedals.js?123></script>
19
- <script src=engine/engineWebGL.js?123></script>
20
- <script src=engine/engine.js?123></script>
9
+ <script src=engine/engineDebug.js?125></script>
10
+ <script src=engine/engineUtilities.js?125></script>
11
+ <script src=engine/engineSettings.js?125></script>
12
+ <script src=engine/engineObject.js?125></script>
13
+ <script src=engine/engineDraw.js?125></script>
14
+ <script src=engine/engineInput.js?125></script>
15
+ <script src=engine/engineAudio.js?125></script>
16
+ <script src=engine/engineTileLayer.js?125></script>
17
+ <script src=engine/engineParticles.js?125></script>
18
+ <script src=engine/engineMedals.js?125></script>
19
+ <script src=engine/engineWebGL.js?125></script>
20
+ <script src=engine/engine.js?125></script>
21
21
 
22
22
  <!-- You can also include all engine scripts like this... -->
23
23
  <!-- <script src=engine/engine.all.js></script> -->
24
24
 
25
25
  <!-- Add your game scripts here -->
26
- <script src=game.js?123></script>
26
+ <script src=game.js?125></script>
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "littlejsengine",
3
- "version": "1.5.0",
3
+ "version": "1.5.1",
4
4
  "description": "LittleJS - Tiny and Fast HTML5 Game Engine",
5
5
  "main": "engine/engine.all.module.js",
6
6
  "repository": {
@@ -26,10 +26,10 @@
26
26
  "build": "build.bat"
27
27
  },
28
28
  "dependencies": {
29
- "ect-bin": "^1.4.1",
30
- "google-closure-compiler": "^20221102.0.1",
31
- "roadroller": "^2.1.0",
32
- "typescript": "^4.9.5",
33
- "uglify-js": "^3.17.4"
29
+ "ect-bin": "~1.4.1",
30
+ "google-closure-compiler": "~20230502.0.0",
31
+ "roadroller": "~2.1.0",
32
+ "typescript": "~5.1.6",
33
+ "uglify-js": "~3.17.4"
34
34
  }
35
35
  }