C# 屏幕上只有一颗子弹。我怎样才能解决这个问题?

C# 屏幕上只有一颗子弹。我怎样才能解决这个问题?,c#,xna,C#,Xna,我希望每个敌人都能独立射击。如果敌人的子弹离开了屏幕,敌人可以发射新的子弹。不早。 但就目前而言,他们的屏幕上总是只有一颗子弹,而不是三颗。我有三个敌人,所以他们在屏幕上最多同时有三颗子弹,而不是一颗。 怎么了 public class Map { Texture2D myEnemy, myBullet; Player Player; List<Enemy> enemieslist = new List<Enemy>(); List<

我希望每个敌人都能独立射击。如果敌人的子弹离开了屏幕,敌人可以发射新的子弹。不早。 但就目前而言,他们的屏幕上总是只有一颗子弹,而不是三颗。我有三个敌人,所以他们在屏幕上最多同时有三颗子弹,而不是一颗。 怎么了

public class Map
{
    Texture2D myEnemy, myBullet;
    Player Player;
    List<Enemy> enemieslist = new List<Enemy>();
    List<Bullet> bulletslist = new List<Bullet>();

    float fNextEnemy = 0.0f;
    float fEnemyFreq = 3.0f;
    int fMaxEnemy = 3;

    Vector2 Startposition = new Vector2(200, 200);
    Vector2 currentEnemyPosition;

    GraphicsDeviceManager graphicsDevice; 

    public Map(GraphicsDeviceManager device) 
    { 
        graphicsDevice = device;

    } 

    public void Load(ContentManager content)
    {
    myEnemy = content.Load<Texture2D>("enemy");
    myBullet = content.Load<Texture2D>("bullet"); 
    Player = new Player(graphicsDevice);
    Player.Load(content);
    }

    public void Update(GameTime gameTime)
    {
        Player.Update(gameTime);
        float delta = (float)gameTime.ElapsedGameTime.TotalSeconds;

         for(int i = enemieslist.Count - 1; i >= 0; i--) 
        {
        // Update Enemy
        Enemy enemy = enemieslist[i];
        enemy.Update(gameTime, this.graphicsDevice, Player.playershape.Position, delta);
        currentEnemyPosition = enemy.Bulletstartposition;
        // Try to remove an enemy
        if (enemy.Remove == true)
        {
            enemieslist.Remove(enemy);
            enemy.Remove = false;
        }

        // Does the enemy shot?
        if ((enemy.Shot == true) && (bulletslist.Count < 1))
        // New bullet
          {
          Vector2 bulletDirection = Vector2.Normalize(Player.playershape.Position - currentEnemyPosition) * 200f;
          bulletslist.Add(new Bullet(currentEnemyPosition, bulletDirection, Player.playershape.Position));
          enemy.Shot = false;
          }
        }

        this.fNextEnemy += delta;
        //New enemy
        if (fMaxEnemy > 0)
        {
        if ((this.fNextEnemy >= fEnemyFreq) && (enemieslist.Count < 3))
        {
            Vector2 enemyDirection = Vector2.Normalize(Player.playershape.Position - Startposition) * 100f;
            enemieslist.Add(new Enemy(Startposition, enemyDirection, Player.playershape.Position));
            fMaxEnemy -= 1;
            fNextEnemy -= fEnemyFreq;
        }
        }

    for(int i = bulletslist.Count - 1; i >= 0; i--) 
    {
        // Update Bullet
        Bullet bullets = bulletslist[i];   
        bullets.Update(gameTime, this.graphicsDevice, delta);

        // Try to remove a bullet... Collision, hit, or outside screen.
        if (bullets.Remove == true)
            bulletslist.Remove(bullets);
        bullets.Remove = false;
    }              
  }

    public void Draw(SpriteBatch batch)
    {

        Player.Draw(batch);
        foreach (Enemy enemies in enemieslist)
        {
            enemies.Draw(batch, myEnemy);
        } 
        foreach (Bullet bullets in bulletslist)
        {
            bullets.Draw(batch, myBullet);
        } 
    }      
}

public class Enemy
{
 private float nextShot = 0;
 private float shotFrequency = 2.0f;  

    Vector2 vPos;
    Vector2 vMove;
    Vector2 vPlayer;
    public Vector2 Bulletstartposition;
    public bool Remove;
    public bool Shot;

    public Enemy(Vector2 Pos, Vector2 Move, Vector2 Player)
    {
        this.vPos = Pos;
        this.vMove = Move;
        this.vPlayer = Player;
        this.Remove = false;
        this.Shot = false;
    }

    public void Update(GameTime gameTime, GraphicsDeviceManager graphics, Vector2 PlayerPos, float delta)
    {           
        nextShot += delta;

        if (nextShot >= shotFrequency)
            {
            this.Shot = true;
            nextShot -= shotFrequency;
            }

        if (!Remove)
        {
            this.vMove = Vector2.Normalize(PlayerPos - this.vPos) * 100f;
            this.vPos += this.vMove * delta;
            Bulletstartposition = this.vPos;

            if (this.vPos.X > graphics.PreferredBackBufferWidth + 1)
            {
                this.Remove = true;
            }

            else if (this.vPos.X < -20)
            {
                this.Remove = true;
            }

            if (this.vPos.Y > graphics.PreferredBackBufferHeight + 1)
            {
                this.Remove = true;
            }

            else if (this.vPos.Y < -20)
            {
                this.Remove = true;
            }
        }
    }

    public void Draw(SpriteBatch spriteBatch, Texture2D myTexture)
    {
        if (!Remove)
        {
            spriteBatch.Draw(myTexture, this.vPos, Color.White);
        }
    }
}

public class Bullet
{
    Vector2 vPos;
    Vector2 vMove;
    Vector2 vPlayer;
    public bool Remove;

    public Bullet(Vector2 Pos, Vector2 Move, Vector2 Player)
    {
        this.Remove = false;
        this.vPos = Pos;
        this.vMove = Move;
        this.vPlayer = Player;
    }

    public void Update(GameTime gameTime, GraphicsDeviceManager graphics, float delta)
    {
            if (!Remove)
            {
                this.vPos += this.vMove * delta;                  

                if (this.vPos.X > graphics.PreferredBackBufferWidth +1)
                {
                    this.Remove = true;
                }

                else if (this.vPos.X < -20)
                {
                    this.Remove = true;
                }

                if (this.vPos.Y > graphics.PreferredBackBufferHeight +1)
                {
                    this.Remove = true;
                }

                else if (this.vPos.Y < -20)
                {
                    this.Remove = true;
                }
            }         
    }

    public void Draw(SpriteBatch spriteBatch, Texture2D myTexture)
    {
        if (!Remove)
        {
            spriteBatch.Draw(myTexture, this.vPos, Color.White);
        }
    }
}
公共类映射
{
我的敌人,我的子弹;
玩家;
List enemieslist=新列表();
列表公告列表=新列表();
浮点数fnextemy=0.0f;
浮动fEnemyFreq=3.0f;
int-fmax=3;
矢量2起始位置=新矢量2(200200);
矢量2当前位置;
GraphicsDeviceManager图形设备;
公共地图(GraphicsDeviceManager设备)
{ 
图形设备=设备;
} 
公共无效加载(ContentManager内容)
{
myEnemy=content.Load(“敌人”);
myBullet=content.Load(“bullet”);
玩家=新玩家(图形设备);
Player.Load(内容);
}
公开作废更新(游戏时间游戏时间)
{
玩家更新(游戏时间);
浮点增量=(浮点)gameTime.ElapsedGameTime.TotalSeconds;
对于(int i=enemieslist.Count-1;i>=0;i--)
{
//更新敌人
敌人=敌人[我];
更新(游戏时间,this.graphicsDevice,Player.playershape.Position,delta);
currentEnemyPosition=敌人。BullettStartPosition;
//设法消灭敌人
if(敌方移除==真)
{
敌人。清除(敌人);
敌人。移除=假;
}
//敌人开枪了吗?
如果((敌方射击==真)和(&(bulletslist.Count<1))
//新子弹
{
Vector2 bulletDirection=Vector2.规格化(Player.playershape.Position-currentEneyPosition)*200f;
bulletslist.Add(新的Bullet(当前我的位置,bulletDirection,Player.playershape.Position));
敌人。射击=假;
}
}
this.fnextemy+=delta;
//新敌人
如果(Fmax>0)
{
如果((this.fnextemy>=fEnemyFreq)和(&(enemieslist.Count<3))
{
Vector2 enemyDirection=Vector2.规范化(Player.playershape.Position-Startposition)*100f;
敌人列表。添加(新敌人(起始位置,敌人方向,玩家。玩家。位置));
fmax-=1;
fnextemy-=fEnemyFreq;
}
}
对于(int i=bulletslist.Count-1;i>=0;i--)
{
//更新项目符号
子弹=子弹列表[i];
更新(游戏时间,this.graphicsDevice,delta);
//尝试移除子弹…碰撞、击中或屏幕外。
if(bullets.Remove==true)
子弹列表。移除(子弹);
move=false;
}              
}
公共作废取款(SpriteBatch批量)
{
玩家。抽签(批量);
foreach(敌人列表中的敌人)
{
敌人。抽签(批,我的敌人);
} 
foreach(bulletslist中的子弹)
{
项目符号。绘制(批次,myBullet);
} 
}      
}
公敌
{
私有浮动nextShot=0;
私人浮动频率=2.0f;
向量2 VPO;
矢量2运动;
向量2层;
公共矢量2 BullettStartPosition;
公共房屋拆迁;
公共枪杀;
公敌(矢量2位置,矢量2移动,矢量2玩家)
{
this.vPos=Pos;
this.vMove=移动;
this.vPlayer=播放器;
这个.Remove=false;
这个.Shot=false;
}
public void更新(游戏时间游戏时间、图形管理员图形、矢量2播放器、浮动增量)
{           
nextShot+=delta;
如果(下一次拍摄>=拍摄频率)
{
这个.Shot=true;
nextShot-=拍摄频率;
}
如果(!删除)
{
this.vMove=Vector2.Normalize(PlayerPos-this.vPos)*100f;
this.vPos+=this.vMove*delta;
Bulletstartposition=this.vPos;
if(this.vPos.X>graphics.PreferredBackBufferWidth+1)
{
这个.Remove=true;
}
否则如果(此.vPos.X<-20)
{
这个.Remove=true;
}
if(this.vPos.Y>graphics.PreferredBackBufferHeight+1)
{
这个.Remove=true;
}
否则如果(此.vPos.Y<-20)
{
这个.Remove=true;
}
}
}
公共空白绘制(SpriteBatch SpriteBatch,纹理2D myTexture)
{
如果(!删除)
{
spriteBatch.Draw(myTexture,this.vPos,Color.White);
}
}
}
公营子弹
{
向量2 VPO;
矢量2运动;
向量2层;
公共房屋拆迁;
公共子弹(矢量2位置,矢量2移动,矢量2播放器)
{
这个.Remove=false;
this.vPos=Pos;
this.vMove=移动;
this.vPlayer=播放器;
}
公共无效更新(游戏时间游戏时间,图形管理员图形,浮动增量)
{
如果(!删除)
{
this.vPos+=this.vMove*delta;
if(this.vPos.X>graphics.PreferredBackBufferWidth+1)
{
这个.Remove=true;
}
否则如果(此.vPos.X<-20)
{
这个.Remove=true;
}
if(this.vPos.Y>graphics.PreferredBackBufferHeight+1)
{
这个.Remove=true;
}
否则如果(此.vPos.Y<-20)
{
这个.Remove=true;
}
}         
}
公共空白绘制(SpriteBatch SpriteBatch,纹理2D myTexture)
{
如果(!删除)
{
s
// Does the enemy shot?
if ((enemy.Shot == true) && (enemy.Bullet == null))
{
    …
}