I'm just trying to create a very simple game with HTML5 and JS, now at the moment I have a ship that can fire a bullet. If you hold the spare bar the bullet is moved correctly and works fine. But if you press space bar in the middle of a shot, it will create a new bullet but the speed will be like doubled. Here is the code
function Bullet(x,y)
{
this.xPos = x;
this.yPos = y;
this.speed = 5;
this.alive = true;
this.lifeTimer = 0;
}
tempBullet = new Bullet( -100, -100);
bullets[0] = tempBullet;
if (32 in keysDown && player.fired == false) //space
{
//Create new bullet
var bulletDone = false;
player.fired = true;
player.firedTimer = 1;
tempBullet = new Bullet( player.xPos + 14, player.yPos);
for( i = 0; i < bullets.length; i++ )
{
if( bullets[i].alive == false )
{
bulletDone = true;
bullets[i] = tempBullet;
}
}
if( bulletDone == false )
{
bullets[bullets.length] = tempBullet;
}
}
if( player.firedTimer >= 1 )
{
player.firedTimer++;
}
if( player.firedTimer >= 60 )
{
player.firedTimer = 0;
player.fired = false;
}
These are code snippets, the rest is stuff that would just get in the way. Am I re-using the old assets in my bullets array wrongly?
Cheers for the help and read