C# 如何在XNA中进行多镜头拍摄?

C# 如何在XNA中进行多镜头拍摄?,c#,xna,game-development,C#,Xna,Game Development,我试图模拟一种同时发射多发子弹的枪(类似于散开的子弹)。我想我必须创建另一个子弹阵列,然后像下面一样,但方向不同 以下是我到目前为止的情况: foreach (GameObject bullet in bullets) { // Find a bullet that isn't alive if (!bullet.alive) { //And set it to alive bullet.alive = true; if

我试图模拟一种同时发射多发子弹的枪(类似于散开的子弹)。我想我必须创建另一个子弹阵列,然后像下面一样,但方向不同

以下是我到目前为止的情况:

foreach (GameObject bullet in bullets) 
{
    // Find a bullet that isn't alive
    if (!bullet.alive)
    {
        //And set it to alive
        bullet.alive = true;

        if (flip == SpriteEffects.FlipHorizontally) //Facing right
        {
            float armCos = (float)Math.Cos(arm.rotation - MathHelper.PiOver2);
            float armSin = (float)Math.Sin(arm.rotation - MathHelper.PiOver2);

            // Set the initial position of our bullets at the end of our gun arm
            // 42 is obtained by taking the width of the Arm_Gun texture / 2
            // and subtracting the width of the Bullet texture / 2. ((96/2)=(12/2))
            bullet.position = new Vector2(arm.position.X + 42 * armCos, arm.position.Y + 42 * armSin);

            // And give it a velocity of the direction we're aiming.
            // Increae/decrease speed by changeing 15.0f
            bullet.Velocity = new Vector2(
                (float)Math.Cos(arm.rotation - MathHelper.PiOver4 + MathHelper.Pi + MathHelper.PiOver2),
                (float)Math.Sin(arm.rotation - MathHelper.PiOver4 + MathHelper.Pi + MathHelper.PiOver2)) * 15.0f;
        }

        else //Facing left
        {
            float armCos = (float)Math.Cos(arm.rotation + MathHelper.PiOver2);
            float armSin = (float)Math.Sin(arm.rotation + MathHelper.PiOver2);

            //Set the initial position of our bullet at the end of our gun arm
            //42 is obtained be taking the width of the Arm_Gun texture / 2
            //and subtracting the width of the Bullet texture / 2. ((96/2)-(12/2))
            bullet.position = new Vector2(arm.position.X - 42 * armCos, arm.position.Y - 42 * armSin);

            //And give it a velocity of the direction we're aiming.
            //Increase/decrease speed by changing 15.0f
            bullet.Velocity = new Vector2(-armCos, -armSin) * 15.0f;
        }
        return;
    }// End if
}// End foreach

一种简单的方法是使用for循环并将旋转度增加一个固定的量

下面是一个伪代码示例

var spawnPoint = new Vector2(x, y);

for (int angle = 45; angle <= 135; angle += 45)
{
    Bullet.ShootInDirection( spawnPoint, MathHelper.ToRadians(angle) );
}
var spawnPoint=newvector2(x,y);

对于(int angle=45;angle)这是否允许所有三颗子弹同时射击?是的,它们将同时射击。这只是一个
for
循环。