Exemplo n.º 1
0
        private void FireParticles(GameTime gameTime, ParticleManager <ParticleState> particleManager)
        {
            double t = gameTime.TotalGameTime.TotalSeconds;

            var        direction = new Vector2((float)Math.Sin(Ship.Rotation), (float)Math.Cos(Ship.Rotation) * -1);
            float      aimAngle  = direction.ToAngle();
            Quaternion rot       = Quaternion.CreateFromYawPitchRoll(0, 0, aimAngle);

            // The primary velocity of the particles is 3 pixels/frame in the direction opposite to which the ship is travelling.
            Vector2 baseVel = direction.ScaleTo(2);

            // Calculate the sideways velocity for the two side streams. The direction is perpendicular to the ship's velocity and the
            // magnitude varies sinusoidally.
            var         perpVel   = new Vector2(baseVel.Y, -baseVel.X) * (0.6f * (float)Math.Sin(t * 10));
            var         sideColor = new Color(200, 38, 9);   // deep red
            var         midColor  = new Color(255, 187, 30); // orange-yellow
            var         pos       = Ship.Position;           // position of the ship's exhaust pipe.
            const float alpha     = 0.7f;

            // middle particle stream
            Vector2 velMid = baseVel + random.NextVector2(0, 1);

            particleManager.CreateLineParticle(pos, Color.White * alpha, 60f, new Vector2(0.5f, 1),
                                               new ParticleState(velMid, ParticleType.Enemy));
            particleManager.CreateGlowParticle(pos, midColor * alpha, 60f, new Vector2(0.5f, 1),
                                               new ParticleState(velMid, ParticleType.Enemy));

            // side particle streams
            Vector2 vel1 = baseVel + perpVel + random.NextVector2(0, 0.3f);
            Vector2 vel2 = baseVel - perpVel + random.NextVector2(0, 0.3f);

            particleManager.CreateLineParticle(pos, Color.White * alpha, 60f, new Vector2(0.5f, 1),
                                               new ParticleState(vel1, ParticleType.Enemy));
            particleManager.CreateLineParticle(pos, Color.White * alpha, 60f, new Vector2(0.5f, 1),
                                               new ParticleState(vel2, ParticleType.Enemy));

            particleManager.CreateGlowParticle(
                pos, sideColor * alpha, 60f, new Vector2(0.5f, 1),
                new ParticleState(vel1, ParticleType.Enemy)
                );
            particleManager.CreateGlowParticle(
                pos, sideColor * alpha, 60f, new Vector2(0.5f, 1),
                new ParticleState(vel2, ParticleType.Enemy)
                );
        }