ScrollingShooter.GameObjectManager.CreateProjectile C# (CSharp) Method

CreateProjectile() public method

Factory method for spawning a projectile
public CreateProjectile ( ProjectileType projectileType, Vector2 position, Vector2 velocity ) : ScrollingShooter.Projectile
projectileType ProjectileType The type of projectile to create
position Vector2 The position of the projectile in the game world
velocity Vector2
return ScrollingShooter.Projectile
        public Projectile CreateProjectile(ProjectileType projectileType, Vector2 position, Vector2 velocity)
        {
            Projectile projectile = null;
            uint id = NextID();

            switch (projectileType)
            {
                case ProjectileType.Bullet:
                    projectile = new Bullet(id, content, position);
                    break;

                case ProjectileType.Fireball:
                    projectile = new Fireball(id, content, position);
                    break;

                case ProjectileType.BubbleBullet:
                    projectile = new BubbleBullet(id, content, position);
                    break;

                case ProjectileType.Bomb:
                    projectile = new Bomb(id, content, position, true);
                    break;

                case ProjectileType.Blades:
                    projectile = new Blades(id, content);
                    break;

                case ProjectileType.DroneLaser:
                    projectile = new DroneLaser(id, content, position);
                    break;

                case ProjectileType.ToPlayerBullet:
                    projectile = new ToPlayerBullet(id, content, position);
                    break;

                case ProjectileType.ArrowProjectile:
                    projectile = new ArrowProjectile(id, content, position);
                    break;

                case ProjectileType.BirdCrap:
                    projectile = new BirdCrap(id, content, position);
                    break;
                case ProjectileType.EBullet:
                    projectile = new EBullet(id, content, position);
                    break;

                case ProjectileType.Frostball:
                    projectile = new Frostball(id, content, position);
                    break;

                case ProjectileType.BlueBeam:
                    projectile = new blueBeam(id, content, position);
                    break;

                //This method doesn't fit the trishield very well, so this code is a bit poor in quality.
                case ProjectileType.TrishieldBall:
                    for (int i = 0; i < 2; i++)
                    {
                        projectile = new TriShieldBall(id, content, 2 * MathHelper.Pi / 3 * i);
                        QueueGameObjectForCreation(projectile);
                        id = NextID();
                    }
                    projectile = new TriShieldBall(id, content, 4 * MathHelper.Pi / 3);
                    break;

                case ProjectileType.GenericEnemyBullet:
                    projectile = new GenericEnemyBullet(id, content, position);
                    break;

                case ProjectileType.DroneWave:
                    // waveIndex helps draw the wave to the left and right of the ship, while waveSpacing holds the vector difference of space between each drone.
                    // Drone count is managed by 2*i.
                    Vector2 waveIndex = new Vector2(-1, 1);
                    Vector2 waveSpacing = new Vector2(40, 30);
                    for (int i = 0; i < 5; i++)
                    {
                        projectile = new DroneWave(id, content, position + waveSpacing * waveIndex * i);
                        QueueGameObjectForCreation(projectile);
                        id = NextID();
                        projectile = new DroneWave(id, content, position + waveSpacing * i);
                        QueueGameObjectForCreation(projectile);
                        id = NextID();
                    }
                    break;

                case ProjectileType.TurretFireball:
                    projectile = new TurretFireball(id, content, position);
                    break;

                case ProjectileType.JetMinionBullet:
                    projectile = new JetMinionBullet(id, content, position);
                    break;

                case ProjectileType.EnergyBlast:
                    projectile = new EnergyBlast(id, content, position, ScrollingShooterGame.Game.Player.energyBlastLevel);
                    break;

                case ProjectileType.EnemyBullet:

                    // Bullet velocity
                    float bulletVel = 200f;

                    //ScrollingShooterGame.Game.projectiles.Add(new EnemyBullet(ScrollingShooterGame.Game.Content, this.position + offset, bulletVel * toPlayer));

                    Vector2 toPlayer = (new Vector2(ScrollingShooterGame.Game.Player.Bounds.Center.X,
                        ScrollingShooterGame.Game.Player.Bounds.Center.Y) - position);

                    toPlayer.Normalize();

                    projectile = new EnemyBullet(id, content, position, bulletVel * toPlayer);
                    break;
                case ProjectileType.EnemyBomb:
                    projectile = new Bomb(id, content, position, false);
                    break;

                case ProjectileType.ShotgunBullet:
                    projectile = new ShotgunBullet(id, content, position, BulletDirection.HardLeft);
                    for (int i = 1; i < 5; i++)
                    {
                        ShotgunBullet sb = new ShotgunBullet(NextID(), content, position, (BulletDirection)i);
                        sb.ObjectType = ObjectType.PlayerProjectile;
                        QueueGameObjectForCreation(sb);
                    };
                    break;

                case ProjectileType.BlimpShotgun:
                    projectile = new BlimpShotgun(id, content, position, BulletDirection.HardLeft);
                    for (int i = 1; i < 5; i++)
                    {
                        BlimpShotgun bs = new BlimpShotgun(NextID(), content, position, (BulletDirection)i);
                        bs.ObjectType = ObjectType.EnemyProjectile;
                        QueueGameObjectForCreation(bs);
                    };
                    break;

                case ProjectileType.Meteor:
                    projectile = new Meteor(id, content, position);
                    break;

                case ProjectileType.BigMeteor:
                    projectile = new BigMeteor(id, content, position);
                    break;

                case ProjectileType.EnemyFlameball:
                    projectile = new EnemyFlameball(id, content, position);
                    break;

                case ProjectileType.RGSabot:
                    projectile = new RGSabot(id, content, position);
                    break;

                case ProjectileType.BlimpBullet:
                    projectile = new BlimpBullet(id, content, position);
                    break;

                case ProjectileType.BirdWrath:
                    projectile = new BirdWrath(id, content, position);
                    break;

                case ProjectileType.FreezewaveProjectile:
                    projectile = new FreezewaveProjectile(id, content, position);
                    break;

                case ProjectileType.Photon:
                    projectile = new Photon(id, content, position);
                    break;

                case ProjectileType.Pincher:
                    projectile = new Pincher(id, content, position);
                    break;

                case ProjectileType.GreenOrb:
                    projectile = new GreenOrb(id, content, position);
                    break;

                case ProjectileType.AlienTurretOrb:
                    projectile = new AlienTurretOrb(id, content, position);
                    break;

                case ProjectileType.TwinJetMissile:
                    projectile = new Boss_TwinJetMissile(id, content, position);
                    break;

                case ProjectileType.TwinJetBullet:
                    projectile = new Boss_TwinJetBullet(id, content, position);
                    break;

                case ProjectileType.HomingMissile:
                    projectile = new HomingMissileProjectile(content, position, 1, id);
                    break;

                case ProjectileType.EnemyPsyBall:
                    projectile = new EnemyPsiBall(id, content, position);
                    break;

                case ProjectileType.EnemyLightningZap:
                    projectile = new EnemyLightningZap(id, content, position);
                    break;
                case ProjectileType.CobaltBomb:
                    projectile = new CobaltBomb(id, content, position);
                    break;

                default:
                    throw new NotImplementedException("The projectile type " + Enum.GetName(typeof(ProjectileType), projectileType) + " is not supported");
            }

            if ((int)projectileType < 100)
                projectile.ObjectType = ObjectType.PlayerProjectile;
            else
                projectile.ObjectType = ObjectType.EnemyProjectile;
            QueueGameObjectForCreation(projectile);
            return projectile;
        }

Same methods

GameObjectManager::CreateProjectile ( ProjectileType projectileType, Vector2 position ) : ScrollingShooter.Projectile