C# 小行星运动-XNA小行星克隆
我刚刚开始了一个XNA项目,我想让Atari在Monogame中制作小行星。目前,我掌握了船的运动情况。我刚刚修改了代码中的一些内容。现在的问题是小行星。我正试图研究如何制作它们,但没有任何好结果 我的代码:C# 小行星运动-XNA小行星克隆,c#,xna,C#,Xna,我刚刚开始了一个XNA项目,我想让Atari在Monogame中制作小行星。目前,我掌握了船的运动情况。我刚刚修改了代码中的一些内容。现在的问题是小行星。我正试图研究如何制作它们,但没有任何好结果 我的代码: private Texture2D texture; private Rectangle destinationRectangle; private Rectangle sourceRectangle; private float rotationSpeed;
private Texture2D texture;
private Rectangle destinationRectangle;
private Rectangle sourceRectangle;
private float rotationSpeed;
private Vector2 rotationOrigin;
private float rotationAngle;
private float speed;
private Vector2 velocity;
public Asteroide(Texture2D texture, int x, int y)
{
}
public Asteroide(Texture2D texture, int x, int y, int width, int height, float speed, float rotationSpeed)
{
this.texture = texture;
this.rotationSpeed = rotationSpeed;
destinationRectangle = new Rectangle(x - width / 2, y - height / 2, width, height);
sourceRectangle = new Rectangle(0, 0, width, height);
rotationOrigin = new Vector2(texture.Width * 0.5f, texture.Height * 0.5f);
this.speed = speed;
Random rnd = new Random();
int degree = rnd.Next(-45, 46);
double radian = degree * Math.PI / 180;
ChangeAngle(radian);
}
public void ChangeAngle(double radian)
{
velocity.X = (float)Math.Cos(radian) * speed;
velocity.Y = -1f * (float)Math.Sin(radian) * speed;
}
public void Update(GameTime gameTime)
{
Move(gameTime);
}
private void Move(GameTime gameTime)
{
destinationRectangle.X += (int)(velocity.X * gameTime.ElapsedGameTime.TotalSeconds);
destinationRectangle.Y += (int)(velocity.Y * gameTime.ElapsedGameTime.TotalSeconds);
}
private void Rotation(GameTime gameTime)
{
rotationAngle += rotationSpeed * (float) gameTime.ElapsedGameTime.TotalSeconds;
}
public void Draw(SpriteBatch spriteBatch)
{
spriteBatch.Draw(texture, destinationRectangle, sourceRectangle, Color.White, rotationAngle, rotationOrigin, SpriteEffects.None, 0f);
}
我想要的是一颗不断移动并产生各种大小小行星的小行星。它们应该覆盖大、中、小尺寸的所有屏幕。我知道我必须在某个地方使用随机数,但我不知道在哪里。请解释你得到的结果,以及为什么它与预期结果不同。我得到一颗小行星在某个位置,它向前移动并从屏幕上消失。我想要的是十颗小行星,它们的位置是随机的,并且在屏幕上以不同的角度和方向随机生成。好的,当有疑问的时候,你需要显示所有相关的代码。在这种情况下,小行星是如何实例化的?