0

私はゲームを作っています。私の問題は、スペース キーをクリックすると 1 発の弾丸が発射されることですが、もう一度実行しても何も起こりません。ゲーム開始時の弾数は 30 発で、画面左上の見えないところに格納されるようにしました。スペースをクリックすると、X、Y 値を使用して船の先端から発射されます。

ここをクリックして、私が何を意味するかを確認してください: http://www.taffatech.com/DarkOrbit.html - これまでに 1 つの火災しか確認できないためです。

ここに弾丸オブジェクトがあります

function Bullet() //space weapon uses this
{
this.srcX = 0;
this.srcY = 1240;
this.drawX = -20;
this.drawY = 0;
this.width = 11;
this.height = 4;
this.bulletSpeed = 3;
this.bulletReset = -20;
}

Bullet.prototype.draw = function()
{

this.drawX += this.bulletSpeed;
ctxPlayer.drawImage(spriteImage,this.srcX,this.srcY,this.width,this.height,this.drawX,this.drawY,this.width,this.height);

if (this.drawX > canvasWidth)
  {
  this.drawX = this.bulletReset;

  }

}

Bullet.prototype.fire = function(startX, startY)
{

   this.drawX = startX;
   this.drawY = startY;

}

これがプレイヤー オブジェクトです: (船)

function Player()  //Object
{

//////Your ships values
this.PlayerHullMax = 1000;
this.PlayerHull = 1000;
this.PlayerShieldMax = 1000;
this.PlayerShield = 347;
this.SpaceCrystal = 2684;
this.Speed = 5; //should be around 2 pixels every-time draw is called by interval, directly linked to the fps global variable
////////////

///////////flags
this.isUpKey = false;  
this.isDownKey = false;
this.isLeftKey = false;
this.isRightKey = false;
////////space Weapon
this.noseX = this.drawX + 100;
this.noseY = this.drawY + 30;

this.isSpaceBar =  false;
this.isShooting = false;
this.bullets = [];
this.currentBullet = 0;
this.bulletAmount = 30;

for(var i = 0; i < this.bulletAmount; i++) //
   {

     this.bullets[this.bullets.length] = new Bullet();

   }
/////////////

////Pick Ship
this.type = "Cruiser";
this.srcX = PlayerSrcXPicker(this.type);
this.srcY = PlayerSrcYPicker(this.type);
this.drawX = PlayerdrawXPicker(this.type);
this.drawY = PlayerdrawYPicker(this.type);
this.playerWidth = PlayerWidthPicker(this.type);
this.playerHeight = PlayerHeightPicker(this.type);
////


}

Player.prototype.draw = function()
{
ClearPlayerCanvas();
ctxPlayer.globalAlpha=1;
this.checkDirection(); //must before draw pic to canvas because you have new coords now from the click

this.noseX = this.drawX + (this.playerWidth-10);
this.noseY = this.drawY + (this.playerHeight/2);
this.checkShooting();
this.drawAllBullets();



ctxPlayer.drawImage(spriteImage,this.srcX,this.srcY,this.playerWidth,this.playerHeight,this.drawX,this.drawY,this.playerWidth,this.playerHeight);

};


Player.prototype.drawAllBullets = function()
{

  for(var i = 0; i < this.bullets.length; i++)
   {
     if(this.bullets[i].drawX >= 0)
     {

       this.bullets[i].draw();

     }

   }
}


Player.prototype.checkShooting = function()
{

   if(this.isSpaceBar == true && this.isShooting == false)
   {

        this.isShooting = true;
        this.bullets[this.currentBullet].fire(this.noseX, this.noseY);
        this.currentBullet++;

      if(this.currentBullet >= this.bullets.length)
      {
        this.currentBullet = 0;
      }


      else if(this.isSpaceBar == false)
      {

        this.isShooting = false;
      }

     }
}

これは、どのキーがダウンしているかを確認するメソッドです。

if (KeyID === 32 )  //spacebar
{

Player1.isSpaceBar = true;
e.preventDefault(); //webpage dont scroll when playing

}

これは、どのキーがアップしているかを確認するメソッドです。

if (KeyID === 32 )  //left and a keyboard buttons
{

Player1.isSpaceBar = false;
e.preventDefault(); //webpage dont scroll when playing

}

必要なその他の情報は、お尋ねください。

4

1 に答える 1