C# 如果有一系列小行星,我怎么能让它们无限循环繁殖呢?

C# 如果有一系列小行星,我怎么能让它们无限循环繁殖呢?,c#,xna,html-helper,C#,Xna,Html Helper,我制作了一个类似于小行星的游戏,我制作了一个由int计数控制的小行星阵列,我在游戏开始时在屏幕上生成了10颗小行星 我想知道的是如何让小行星无限繁殖。我正在考虑使用循环,并尝试: if (asteroidcount <= 5) { asteroidcount += 10; } if(asteroccount如果没有更多关于游戏如何运行的代码或信息,很难回答,但猜测是这样的:如果数量下降到一定数量以下,你可能想在更大的游戏循环中加入更多的逻辑,并在游戏的每一帧或每一个时间步中添加

我制作了一个类似于小行星的游戏,我制作了一个由
int
计数控制的小行星阵列,我在游戏开始时在屏幕上生成了10颗小行星

我想知道的是如何让小行星无限繁殖。我正在考虑使用循环,并尝试:

if (asteroidcount <= 5)
{
    asteroidcount += 10;
} 

if(asteroccount如果没有更多关于游戏如何运行的代码或信息,很难回答,但猜测是这样的:如果数量下降到一定数量以下,你可能想在更大的游戏循环中加入更多的逻辑,并在游戏的每一帧或每一个时间步中添加更多的小行星

bool running = true;

while (running) 
{
    // Handle input etc
    // Handle game logic

    // Spawn more asteroids if there are too few of them!
    if (asteroidcount <= 5) 
    {
        asteroidcount += 10;
    }

    // Render

}
bool running=true;
(跑步时)
{
//处理输入等
//处理游戏逻辑
//如果小行星太少的话,会产生更多的小行星!

如果(asteroidcount没有更多关于游戏如何运行的代码或信息,很难回答,但猜测是这样的:如果数量下降到一定数量以下,你可能想在更大的游戏循环中加入更多的逻辑,并在游戏的每一帧或每一个时间步中添加更多的小行星

bool running = true;

while (running) 
{
    // Handle input etc
    // Handle game logic

    // Spawn more asteroids if there are too few of them!
    if (asteroidcount <= 5) 
    {
        asteroidcount += 10;
    }

    // Render

}
bool running=true;
(跑步时)
{
//处理输入等
//处理游戏逻辑
//如果小行星太少的话,会产生更多的小行星!

如果(asteroidcount我认为你需要尝试一种不同的方法。首先,你需要一个asteroid类,在那里你可以存储你可能需要的位置和其他变量

public class Asteroid
{
       public Vector2 Velocity;
       public Vector2 Position;
       public Asteroid(Vector2 velocity, vector2 position)
       {
        Velocity = velocity;
        Position = position;
       }
}
现在将这个
列表添加到你的游戏中,它将存储所有小行星。我之所以选择这个而不是阵列,是因为它更容易根据你有多少小行星来更改大小

List<Asteroid> Asteroids = new List<Asteroid>();
现在,在您的
Draw()
方法中,您可以添加以下内容

  spriteBatch.Begin();
  foreach (Asteroid a in Asteroids) //Draw each astroid
  {
       DrawAsteroid(a);
  }
  spriteBatch.End();
如果你想更新所有的小行星,你可以使用simlar方法。 在
Update()

方法呢,

public void UpdateAsteroid(Asteroid a, float elapsed)
{
       a.Position += a.Velocity * elapsed;
}

我认为你需要尝试一种不同的方法。首先,你需要一个小行星类,在那里你可以存储位置和你可能需要的其他变量

public class Asteroid
{
       public Vector2 Velocity;
       public Vector2 Position;
       public Asteroid(Vector2 velocity, vector2 position)
       {
        Velocity = velocity;
        Position = position;
       }
}
现在将这个
列表添加到你的游戏中,它将存储所有小行星。我之所以选择这个而不是阵列,是因为它更容易根据你有多少小行星来更改大小

List<Asteroid> Asteroids = new List<Asteroid>();
现在,在您的
Draw()
方法中,您可以添加以下内容

  spriteBatch.Begin();
  foreach (Asteroid a in Asteroids) //Draw each astroid
  {
       DrawAsteroid(a);
  }
  spriteBatch.End();
如果你想更新所有的小行星,你可以使用simlar方法。 在
Update()

方法呢,

public void UpdateAsteroid(Asteroid a, float elapsed)
{
       a.Position += a.Velocity * elapsed;
}

是C++还是C++?小行星是如何被一些不相关的整数控制的?这是C?C还是C++?小行星是如何被一些无关的整数控制的?谢谢你的回复,你有没有什么教程链接?谢谢回复,你有没有什么教程链接?