littlejsengine 1.1.26 → 1.2.0

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.
@@ -47,21 +47,23 @@ function gameUpdatePost()
47
47
  ///////////////////////////////////////////////////////////////////////////////
48
48
  function gameRender()
49
49
  {
50
- // draw a grey square for the background
51
- drawRect(cameraPos, levelSize, new Color(.2,.2,.2));
50
+ // draw a the background
51
+ drawRect(cameraPos, levelSize.scale(2), new Color(.4,.4,.4));
52
+ drawRect(cameraPos, levelSize, new Color(.1,.1,.1));
52
53
  }
53
54
 
54
55
  ///////////////////////////////////////////////////////////////////////////////
55
56
  function gameRenderPost()
56
57
  {
57
- // draw text on top of everything
58
- drawText('Score: ' + score, cameraPos.add(vec2(0,21)), 2, new Color, .2);
58
+ // use built in image font for text
59
+ const font = new FontImage;
60
+ font.drawText('Score: ' + score, cameraPos.add(vec2(0,22)), .2, 1);
59
61
  if (!blockCount)
60
- drawText('You Win!', cameraPos.add(vec2(0,-5)), 2, new Color, .2);
62
+ font.drawText('You Win!', cameraPos.add(vec2(0,-5)), .25, 1);
61
63
  else if (!ball)
62
- drawText('Click to Play', cameraPos.add(vec2(0,-5)), 2, new Color, .2);
64
+ font.drawText('Click to Play', cameraPos.add(vec2(0,-5)), .25, 1);
63
65
  }
64
66
 
65
67
  ///////////////////////////////////////////////////////////////////////////////
66
68
  // Startup LittleJS Engine
67
- engineInit(gameInit, gameUpdate, gameUpdatePost, gameRender, gameRenderPost, 'tiles.png');
69
+ engineInit(gameInit, gameUpdate, gameUpdatePost, gameRender, gameRenderPost, 'tiles.png?1');
@@ -28,7 +28,7 @@ class Paddle extends EngineObject
28
28
  // move to mouse
29
29
  this.pos.x = mousePos.x;
30
30
  }
31
- this.pos.x = clamp(this.pos.x, levelSize.x - this.size.x/2, this.size.x/2);
31
+ this.pos.x = clamp(this.pos.x, this.size.x/2, levelSize.x - this.size.x/2);
32
32
  }
33
33
  }
34
34
 
@@ -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?92></script>
9
- <script src=game.js?92></script>
10
- <script src=gameObjects.js?92></script>
8
+ <script src=../../engine/engine.all.js?97></script>
9
+ <script src=game.js?97></script>
10
+ <script src=gameObjects.js?97></script>
@@ -33,7 +33,7 @@ function gameUpdate()
33
33
  }
34
34
 
35
35
  // mouse wheel = zoom
36
- cameraScale = clamp(cameraScale*(1-mouseWheel/10), 1e3, 1);
36
+ cameraScale = clamp(cameraScale*(1-mouseWheel/10), 1, 1e3);
37
37
 
38
38
  // T = drop test crate
39
39
  if (keyWasPressed(84))
@@ -89,7 +89,7 @@ function explosion(pos, radius=3)
89
89
  }
90
90
 
91
91
  // push
92
- const p = percent(d, radius, 2*radius);
92
+ const p = percent(d, 2*radius, radius);
93
93
  const force = o.pos.subtract(pos).normalize(p*radius*.2);
94
94
  o.applyForce(force);
95
95
  if (o.isDead && o.isDead())
@@ -46,7 +46,7 @@ function buildTerrain(size)
46
46
  {
47
47
  // big jump
48
48
  const jumpDelta = rand(19,-19);
49
- startGroundLevel = clamp(startGroundLevel + jumpDelta, 80, 20);
49
+ startGroundLevel = clamp(startGroundLevel + jumpDelta, 20, 80);
50
50
  groundLevel += jumpDelta;
51
51
  groundSlope = rand(-1,1);
52
52
  }
@@ -58,9 +58,9 @@ function buildTerrain(size)
58
58
  backgroundDelta = 0;
59
59
  if (rand() < .1)
60
60
  backgroundDeltaSlope = rand(-1,1);
61
- backgroundDelta = clamp(backgroundDelta, 3, -1)
61
+ backgroundDelta = clamp(backgroundDelta, -1, 3)
62
62
 
63
- groundLevel = clamp(groundLevel, levelSize.y-20, 20);
63
+ groundLevel = clamp(groundLevel, 20, levelSize.y-20);
64
64
  for (let y=0; y < size.y; y++)
65
65
  {
66
66
  const pos = vec2(x,y);
@@ -25,7 +25,7 @@ class GameObject extends EngineObject
25
25
  // flash white when damaged
26
26
  if (!this.isDead() && this.damageTimer.isSet())
27
27
  {
28
- const a = .5*percent(this.damageTimer.get(), 0, .15);
28
+ const a = .5*percent(this.damageTimer.get(), .15, 0);
29
29
  this.additiveColor = new Color(a,a,a,0);
30
30
  }
31
31
  else
@@ -126,7 +126,12 @@ class Character extends GameObject
126
126
  {
127
127
  // update jumping and ground check
128
128
  if (this.groundObject || this.climbingWall)
129
+ {
130
+ if (!this.groundTimer.isSet())
131
+ sound_walk.play(this.pos); // land sound
132
+
129
133
  this.groundTimer.set(.1);
134
+ }
130
135
 
131
136
  if (this.groundTimer.active() && !this.dodgeTimer.active())
132
137
  {
@@ -169,7 +174,7 @@ class Character extends GameObject
169
174
 
170
175
  // apply movement acceleration and clamp
171
176
  const maxCharacterSpeed = .2;
172
- this.velocity.x = clamp(this.velocity.x + moveInput.x * .042, maxCharacterSpeed, -maxCharacterSpeed);
177
+ this.velocity.x = clamp(this.velocity.x + moveInput.x * .042, -maxCharacterSpeed, maxCharacterSpeed);
173
178
 
174
179
  // track last pos for ladder collision code
175
180
  this.lastPos = this.pos.copy();
@@ -189,16 +194,16 @@ class Character extends GameObject
189
194
 
190
195
  // update walk sound
191
196
  this.walkSoundTime += speed;
192
- if (speed > .01 && ((this.climbingLadder || this.groundTimer.active()) && !this.dodgeTimer.active()))
197
+ if (speed > .001 && ((this.climbingLadder || this.groundTimer.active()) && !this.dodgeTimer.active()))
193
198
  {
194
199
  if (this.walkSoundTime > 1)
195
200
  {
196
- this.walkSoundTime = 0;
201
+ this.walkSoundTime = this.walkSoundTime%1;
197
202
  sound_walk.play(this.pos);
198
203
  }
199
204
  }
200
205
  else
201
- this.walkSoundTime = .5;
206
+ this.walkSoundTime = 0;
202
207
 
203
208
  // update mirror
204
209
  if (moveInput.x && !this.dodgeTimer.active())
@@ -292,8 +297,8 @@ class Player extends Character
292
297
  // player controls
293
298
  this.holdingJump = keyIsDown(38) || gamepadIsDown(0);
294
299
  this.holdingShoot = mouseIsDown(0) || keyIsDown(90) || gamepadIsDown(2);
295
- this.pressedDodge = mouseIsDown(1) || keyIsDown(88) || gamepadIsDown(3);
296
- this.pressingThrow = mouseIsDown(2) || keyIsDown(67) || gamepadIsDown(1);
300
+ this.pressingThrow = mouseIsDown(1) || keyIsDown(67) || gamepadIsDown(1);
301
+ this.pressedDodge = mouseIsDown(2) || keyIsDown(88) || gamepadIsDown(3);
297
302
 
298
303
  // movement control
299
304
  this.moveInput = isUsingGamepad ? gamepadStick(0) :
@@ -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?92></script>
9
- <script src=gameObjects.js?92></script>
10
- <script src=gamePlayer.js?92></script>
11
- <script src=gameEffects.js?92></script>
12
- <script src=gameLevel.js?92></script>
13
- <script src=game.js?92></script>
8
+ <script src=../../engine/engine.all.js?97></script>
9
+ <script src=gameObjects.js?97></script>
10
+ <script src=gamePlayer.js?97></script>
11
+ <script src=gameEffects.js?97></script>
12
+ <script src=gameLevel.js?97></script>
13
+ <script src=game.js?97></script>
Binary file
@@ -100,7 +100,7 @@ function gameUpdate()
100
100
 
101
101
  if (keepFalling)
102
102
  {
103
- const p = percent(comboCount, 0, 9);
103
+ const p = percent(comboCount, 9, 0);
104
104
  fallTimer.set(fallTime*p);
105
105
  sound_fall.play();
106
106
  }
@@ -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?92></script>
9
- <script src=game.js?92></script>
8
+ <script src=../../engine/engine.all.js?97></script>
9
+ <script src=game.js?97></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?92></script>
8
+ <script src=../../engine/engine.all.min.js?97></script>
9
9
  <script>
10
10
 
11
11
  /*
@@ -83,7 +83,7 @@ function gameUpdate()
83
83
  });
84
84
 
85
85
  // mouse wheel = zoom
86
- cameraScale = clamp(cameraScale*(1-mouseWheel/10), 1e3, 1);
86
+ cameraScale = clamp(cameraScale*(1-mouseWheel/10), 1, 1e3);
87
87
  }
88
88
 
89
89
  ///////////////////////////////////////////////////////////////////////////////
@@ -96,7 +96,7 @@ function gameRender()
96
96
  {
97
97
  // track fps and update stats
98
98
  const frameTimeMS = Date.now();
99
- showFPS = lerp(.05, 1e3/(frameTimeMS - timeMS||1), showFPS);
99
+ showFPS = lerp(.05, showFPS, 1e3/(frameTimeMS - timeMS||1));
100
100
  timeMS = frameTimeMS;
101
101
 
102
102
  const spriteCount = sprites.length
package/game.js CHANGED
@@ -16,7 +16,6 @@ const sound_click = new Sound([.5,.5]);
16
16
 
17
17
  // medals
18
18
  const medal_example = new Medal(0, 'Example Medal', 'Medal description goes here.');
19
- const medal_tenClicks = new Medal(1, 'Ten Clicks!', 'You have clicked 10 times.', '🖱️');
20
19
  medalsInit('Hello World');
21
20
 
22
21
  ///////////////////////////////////////////////////////////////////////////////
@@ -86,8 +85,6 @@ function gameUpdate()
86
85
 
87
86
  // unlock medals
88
87
  medal_example.unlock();
89
- if (++clickCount == 10)
90
- medal_tenClicks.unlock();
91
88
  }
92
89
 
93
90
  // move particles to mouse location if on screen
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?92></script>
10
- <script src=engine/engineUtilities.js?92></script>
11
- <script src=engine/engineSettings.js?92></script>
12
- <script src=engine/engineObject.js?92></script>
13
- <script src=engine/engineDraw.js?92></script>
14
- <script src=engine/engineInput.js?92></script>
15
- <script src=engine/engineAudio.js?92></script>
16
- <script src=engine/engineTileLayer.js?92></script>
17
- <script src=engine/engineParticles.js?92></script>
18
- <script src=engine/engineMedals.js?92></script>
19
- <script src=engine/engineWebGL.js?92></script>
20
- <script src=engine/engine.js?92></script>
9
+ <script src=engine/engineDebug.js?97></script>
10
+ <script src=engine/engineUtilities.js?97></script>
11
+ <script src=engine/engineSettings.js?97></script>
12
+ <script src=engine/engineObject.js?97></script>
13
+ <script src=engine/engineDraw.js?97></script>
14
+ <script src=engine/engineInput.js?97></script>
15
+ <script src=engine/engineAudio.js?97></script>
16
+ <script src=engine/engineTileLayer.js?97></script>
17
+ <script src=engine/engineParticles.js?97></script>
18
+ <script src=engine/engineMedals.js?97></script>
19
+ <script src=engine/engineWebGL.js?97></script>
20
+ <script src=engine/engine.js?97></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?92></script>
26
+ <script src=game.js?97></script>
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "littlejsengine",
3
- "version": "1.1.26",
3
+ "version": "1.2.0",
4
4
  "description": "LittleJS - Tiny and Fast HTML5 Game Engine",
5
5
  "main": "engine/engine.all.js",
6
6
  "repository": {