// Spawns a bullet public void SpawnBullet() { for (double i = 0; i < directions; i += (Math.PI / 2)) { // Determines the velocity of the bullet float rotation = GetRightRotation(); float xVel = Gun.Bullet.Velocity * (float)Math.Cos((double)rotation + i); float yVel = Gun.Bullet.Velocity * (float)Math.Sin((double)rotation + i); Vector2 velocity = new Vector2(xVel, yVel); // Creates the bullet if (Gun.Equals(level.Green)) { Bullet b1 = null; if (BulletPool.Count > 0) { b1 = BulletPool.Pop(); b1.Type = Gun.Bullet; b1.Velocity = velocity; b1.level = level; b1.Reset(); } else { b1 = new Bullet(Gun.Bullet, velocity, level); } Bullet b2 = null; if (BulletPool.Count > 0) { b2 = BulletPool.Pop(); b2.Type = Gun.Bullet; b2.Velocity = velocity; b2.level = level; b2.Reset(); } else { b2 = new Bullet(Gun.Bullet, velocity, level); } Vector2 topShot = new Vector2(Position.X, Position.Y); Vector2 botShot = new Vector2(Position.X, Position.Y); topShot.X += (float)(Math.Cos(GetRightRotation() + (MathHelper.Pi / 2) + i)) * 10; topShot.Y += (float)(Math.Sin(GetRightRotation() + (MathHelper.Pi / 2) + i)) * 10; botShot.X -= (float)(Math.Cos(GetRightRotation() + (MathHelper.Pi / 2) + i)) * 10; botShot.Y -= (float)(Math.Sin(GetRightRotation() + (MathHelper.Pi / 2) + i)) * 10; /* b1.Position.X = topShot.X + (float)(Math.Cos(GetRightRotation() + i)) * 15; b1.Position.Y = topShot.Y + (float)(Math.Sin(GetRightRotation() + i)) * 15; b2.Position.X = botShot.X + (float)(Math.Cos(GetRightRotation() + i)) * 15; b2.Position.Y = botShot.Y + (float)(Math.Sin(GetRightRotation() + i)) * 15; * */ b2.Position = b1.Position = Position; b2.rotTime = MathHelper.Pi; Bullets.Add(b1); Bullets.Add(b2); // Play the sound effect if (i % (Math.PI) == 0) { level.GreenLaserSound.Play(Game1.Global.SoundEffectVolume, 0, 0); } } else if (Gun.Equals(level.Red)) { for (float j = -(MathHelper.Pi / 6); j <= MathHelper.Pi / 6; j += (MathHelper.Pi / 3) / 5) { Bullet b = null; if (BulletPool.Count > 0) { b = BulletPool.Pop(); b.Type = Gun.Bullet; b.Velocity = velocity; b.level = level; b.Reset(); } else { b = new Bullet(Gun.Bullet, velocity, level); } b.Position.X = Position.X + (float)(Math.Cos(GetRightRotation() + i)) * 20; b.Position.Y = Position.Y + (float)(Math.Sin(GetRightRotation() + i)) * 20; b.Velocity.X = b.Velocity.X + 5.0f * (float)(Math.Cos(GetRightRotation() + i + j)); b.Velocity.Y = b.Velocity.Y + 5.0f * (float)(Math.Sin(GetRightRotation() + i + j)); Bullets.Add(b); } // Sound effect if (i % (Math.PI) == 0) { level.RedSound.Play(Game1.Global.SoundEffectVolume, 0, 0); } } else if (Gun.Equals(level.Blue)) { Bullet b = null; if (BulletPool.Count > 0) { b = BulletPool.Pop(); b.Type = Gun.Bullet; b.Velocity = velocity; b.level = level; b.Reset(); } else { b = new Bullet(Gun.Bullet, velocity, level); } b.Position.X = Position.X + (float)(Math.Cos(GetRightRotation() + i)) * 40; b.Position.Y = Position.Y + (float)(Math.Sin(GetRightRotation() + i)) * 40; Bullets.Add(b); // Sound effect if (i % (Math.PI) == 0) { level.BlueSound.Play(Game1.Global.SoundEffectVolume, 0, 0); } } else if (Gun.Equals(level.Yellow)) { Bullet b = null; if (BulletPool.Count > 0) { b = BulletPool.Pop(); b.Type = Gun.Bullet; b.Velocity = velocity; b.level = level; b.Reset(); } else { b = new Bullet(Gun.Bullet, velocity, level); } b.Position.X = Position.X + (float)(Math.Cos(GetRightRotation() + i)) * 50; b.Position.Y = Position.Y + (float)(Math.Sin(GetRightRotation() + i)) * 50; b.Acceleration = velocity / 10.0f; Bullets.Add(b); // Sound effect if (i % (Math.PI) == 0) { level.YellowSound.Play(Game1.Global.SoundEffectVolume, 0, 0); } } else { Bullet b = null; if (BulletPool.Count > 0) { b = BulletPool.Pop(); b.Type = Gun.Bullet; b.Velocity = velocity; b.level = level; b.Reset(); } else { b = new Bullet(Gun.Bullet, velocity, level); } b.Position = Position; // Adds the bullet onscreen Bullets.Add(b); } } }
// Spawns a trailing particle (for bullets) public void SpawnTrailingParticle(Bullet b) { /* Particle p = null; if (b.Type.Equals(GreenBullet)) { p = new Particle(RegularParticle, b.Position); p.Velocity = Vector2.Zero; p.Position -= b.Velocity; Vector2 offset = new Vector2((float)(r.Next(-5, 5)), (float)(r.Next(-5, 5))); p.Position += offset; p.TrailParticle = true; } Particles.Add(p); * */ }