title: JavaScript game; bullets in array; when I shoot, ALL bullets in array refire from wherever the player is
body: <p>There's a fiddle of the whole thing here - <a href="http://jsfiddle.net/Ey2eK/1/" rel="nofollow">http://jsfiddle.net/Ey2eK/1/</a></p>
  
  <p>But I think the problem parts are these functions. This one loads at the end of my main game loop:</p>
  
  <pre><code> playerBullets.forEach(function() {
              if (this.x &gt; WIDTH || this.x &lt; 0 || this.y &gt; HEIGHT || this.y &lt; 0) { this.active = false;}
              playerBullets = playerBullets.filter(function(bullet) {
              return this.active;});
  
              bulletUpdate(this);
              bulletDraw(this);
            }); 
  </code></pre>
  
  <p>OK, so what I'm trying to do here is cycle through the playerBullets array, for each bullet, first I check if it's out of bounds and delete the bullet if it is, then I load bulletUpdate to update the bullets position, which is this formula:</p>
  
  <pre><code>bulletUpdate = function() {
      this.x += this.xVelocity;
      this.y += this.yVelocity;
    }; 
  </code></pre>
  
  <p>What I'm intending here is that for each bullet in the array, it's x and y positions are increased by it's velocity variables.</p>
  
  <p>Then after I've calculated the new position of the bullet, I draw it with bulletDraw:</p>
  
  <pre><code>bulletDraw = function() {
      c.beginPath();
      c.save();
      c.translate(this.x,this.y);
      if (deltaX &lt; 0) {
      c.rotate(this.angle);
      }
      else {
      c.rotate(this.angle);
      c.scale(-1,1);
      }
      c.translate(-this.x,-this.y);
      c.fillStyle = "#000000";
      c.rect(this.x, this.y, 2, 2);
      c.fill();
      c.restore();
      c.closePath();
    }; 
  </code></pre>
  
  <p>Basically drawing a little dot at the new this.x and this.y. </p>
  
  <p>However, what actually seems to happen is that every time I click, bullets are redrawn from wherever the player is now. It's hard to explain but check out the Fiddle - <a href="http://jsfiddle.net/Ey2eK/1/" rel="nofollow">http://jsfiddle.net/Ey2eK/1/</a>  and click a few times in the game area, you'll see (don't worry about the bullets only going in one direction, I'll work on that later).</p>
  
  <p>What I want is for the bullets to carry on their journey as normal bullets should, so that eventually I can kill zombies with them.</p>
  
  <p>Thanks for any help you might offer! I'm seriously stuck with this one.</p>