Exemple #1
0
        /// <summary>
        /// Render the ship.
        /// </summary>
        /// <param name="elapsedTime">The amount of elapsed time, in seconds.</param>
        /// <param name="lineBatch">The LineBatch to render to.</param>
        public override void Draw(float elapsedTime, LineBatch lineBatch)
        {
            // if the ship isn't in the game, or it's dead, don't draw
            if ((playing == false) || (dead == true))
            {
                return;
            }
            // update the shield rotation
            shieldRotation += elapsedTime * shieldRotationPeriodPerSecond;
            // calculate the current color
            color = new Color(color.R, color.G, color.B, (byte)(255f * fadeInTimer /
                                                                fadeInTimerMaximum));
            // transform the shield polygon
            Matrix translationMatrix = Matrix.CreateTranslation(position.X,
                                                                position.Y, 0f);

            shieldPolygon.Transform(Matrix.CreateScale(1f + shieldRotationToScaleScalar
                                                       * (float)Math.Cos(shieldRotation * shieldRotationToScalePeriodScalar)) *
                                    Matrix.CreateRotationZ(shieldRotation) * translationMatrix);
            // draw the shield
            if (Safe)
            {
                lineBatch.DrawPolygon(shieldPolygon, color);
            }
            else if (shield > 0f)
            {
                lineBatch.DrawPolygon(shieldPolygon, new Color(color.R, color.G,
                                                               color.B, (byte)(255f * shield / shieldMaximum)), true);
            }
            base.Draw(elapsedTime, lineBatch);
        }
Exemple #2
0
        /// <summary>
        /// Render the actor.
        /// </summary>
        /// <param name="elapsedTime">The amount of elapsed time, in seconds.</param>
        /// <param name="lineBatch">The LineBatch to render to.</param>
        public virtual void Draw(float elapsedTime, LineBatch lineBatch)
        {
            if (polygon != null)
            {
                if (lineBatch == null)
                {
                    throw new ArgumentNullException(nameof(lineBatch));
                }

                // create the transformation
                Matrix rotationMatrix = Matrix.CreateRotationZ(rotation);
                Matrix worldMatrix    = rotationMatrix *
                                        Matrix.CreateTranslation(position.X, position.Y, 0f);
                // transform the polygon
                polygon.Transform(worldMatrix);
                // draw the polygon
                lineBatch.DrawPolygon(polygon, color);

                // draw the motion blur
                if (useMotionBlur && velocity.LengthSquared() > 1024f)
                {
                    // draw several "blur" polygons behind the real polygon
                    Vector2 backwards = Vector2.Normalize(position - lastPosition);
                    float   speed     = velocity.Length();
                    for (int i = 1; i < speed / 16; ++i)
                    {
                        // calculate the "blur" polygon's position
                        Vector2 blurPosition = this.position - backwards * (i * 4);
                        //Vector2 blurPosition = this.position - backwards * (i * 20);

                        // calculate the transformation for the "blur" polygon
                        Matrix blurWorld = rotationMatrix *
                                           Matrix.CreateTranslation(blurPosition.X, blurPosition.Y, 0);
                        // transform the polygon to the "blur" location
                        polygon.Transform(blurWorld);
                        // calculate the alpha of the "blur" location
                        //byte alpha = (byte)(160 / (i + 1));
                        byte alpha = (byte)(WorldRules.BlurIntensity * 100 / (i + 1));
                        if (alpha < 1)
                        {
                            break;
                        }

                        // draw the "blur" polygon
                        lineBatch.DrawPolygon(polygon,
                                              new Color(color.R, color.G, color.B, alpha));
                    }
                }
            }
        }
 /// <summary>
 /// Render the ship.
 /// </summary>
 /// <param name="elapsedTime">The amount of elapsed time, in seconds.</param>
 /// <param name="lineBatch">The LineBatch to render to.</param>
 public override void Draw(float elapsedTime, LineBatch lineBatch)
 {
     // if the ship isn't in the game, or it's dead, don't draw
     if ((playing == false) || (dead == true))
     {
         return;
     }
     // update the shield rotation
     shieldRotation += elapsedTime * shieldRotationPeriodPerSecond;
     // calculate the current color
     color = new Color(color.R, color.G, color.B, (byte)(255f * fadeInTimer /
         fadeInTimerMaximum));
     // transform the shield polygon
     Matrix translationMatrix = Matrix.CreateTranslation(position.X,
         position.Y, 0f);
     shieldPolygon.Transform(Matrix.CreateScale(1f + shieldRotationToScaleScalar
         * (float)Math.Cos(shieldRotation * shieldRotationToScalePeriodScalar)) *
         Matrix.CreateRotationZ(shieldRotation) * translationMatrix);
     // draw the shield
     if (Safe)
     {
         lineBatch.DrawPolygon(shieldPolygon, color);
     }
     else if (shield > 0f)
     {
         lineBatch.DrawPolygon(shieldPolygon, new Color(color.R, color.G,
             color.B, (byte)(255f * shield / shieldMaximum)), true);
     }
     base.Draw(elapsedTime, lineBatch);
 }
        /// <summary>
        /// Render the actor.
        /// </summary>
        /// <param name="elapsedTime">The amount of elapsed time, in seconds.</param>
        /// <param name="lineBatch">The LineBatch to render to.</param>
        public virtual void Draw(float elapsedTime, LineBatch lineBatch)
        {
            if (polygon != null)
            {
                if (lineBatch == null)
                {
                    throw new ArgumentNullException("lineBatch");
                }
                // create the transformation
                Matrix rotationMatrix = Matrix.CreateRotationZ(rotation);
                Matrix world =  rotationMatrix *
                    Matrix.CreateTranslation(position.X, position.Y, 0f);
                // transform the polygon
                polygon.Transform(world);
                // draw the polygon
                lineBatch.DrawPolygon(polygon, color);

                // draw the motion blur
                if (useMotionBlur && velocity.LengthSquared() > 1024f)
                {
                    // draw several "blur" polygons behind the real polygon
                    Vector2 backwards = Vector2.Normalize(position - lastPosition);
                    float speed = velocity.Length();
                    for (int i = 1; i < speed / 16; ++i)
                    {
                        // calculate the "blur" polygon's position
                        Vector2 blurPosition = this.position - backwards * (i * 4);
                        //Vector2 blurPosition = this.position - backwards * (i * 20);

                        // calculate the transformation for the "blur" polygon
                        Matrix blurWorld = rotationMatrix *
                            Matrix.CreateTranslation(blurPosition.X, blurPosition.Y, 0);
                        // transform the polygon to the "blur" location
                        polygon.Transform(blurWorld);
                        // calculate the alpha of the "blur" location
                        //byte alpha = (byte)(160 / (i + 1));
                        byte alpha = (byte)( WorldRules.BlurIntensity * 100/ (i + 1));
                        if (alpha < 1)
                            break;

                        // draw the "blur" polygon
                        lineBatch.DrawPolygon(polygon,
                            new Color(color.R, color.G, color.B, alpha));
                    }
                }
            }
        }
Exemple #5
0
        /// <summary>
        /// Render the power-up.
        /// </summary>
        /// <param name="elapsedTime">The amount of elapsed time, in seconds.</param>
        /// <param name="lineBatch">The LineBatch to render to.</param>
        public override void Draw(float elapsedTime, LineBatch lineBatch)
        {
            // update the scale period
            scalePeriodElapsed += elapsedTime * timeToScalePeriod;
            while (scalePeriodElapsed < 0)
            {
                scalePeriodElapsed += MathHelper.TwoPi;
            }
            while (scalePeriodElapsed > MathHelper.TwoPi)
            {
                scalePeriodElapsed -= MathHelper.TwoPi;
            }
            // draw the polygons
            if (polygon != null)
            {
                if (lineBatch == null)
                {
                    throw new ArgumentNullException(nameof(lineBatch));
                }

                // calculate the transformation
                Matrix scaleMatrix = Matrix.CreateScale(0.8f +
                                                        0.1f * (float)Math.Cos(scalePeriodElapsed));
                Matrix world = scaleMatrix *
                               Matrix.CreateTranslation(position.X, position.Y, 0f);
                // transform the polygons
                polygon.Transform(world);
                innerPolygon.Transform(world);
                // draw the polygons
                lineBatch.DrawPolygon(polygon, Color.White);
                if (innerPolygon != null)
                {
                    lineBatch.DrawPolygon(innerPolygon, color, true);
                }
                // draw the motion blur
                if (useMotionBlur && velocity.LengthSquared() > 1024f)
                {
                    // draw several "blur" polygons behind the real polygons
                    Vector2 backwards = Vector2.Normalize(position - lastPosition);
                    float   speed     = velocity.Length();
                    for (int i = 1; i < speed / 16; ++i)
                    {
                        // calculate the "blur" position
                        Vector2 blurPosition = this.position - backwards * (i * 4);
                        // calculate the transformation
                        Matrix blurWorld = scaleMatrix *
                                           Matrix.CreateTranslation(blurPosition.X, blurPosition.Y, 0);
                        // transform the polygons
                        polygon.Transform(blurWorld);
                        if (innerPolygon != null)
                        {
                            innerPolygon.Transform(blurWorld);
                        }
                        // calculate the alpha of the "blur" polygons polygons
                        byte alpha = (byte)(160 / (i + 1));
                        if (alpha < 1)
                        {
                            break;
                        }
                        // draw the "blur" polygons
                        lineBatch.DrawPolygon(polygon, new Color(255, 255, 255, (int)alpha));
                        if (innerPolygon != null)
                        {
                            lineBatch.DrawPolygon(innerPolygon,
                                                  new Color(color.R, color.G, color.B, alpha), true);
                        }
                    }
                }
            }
        }
 /// <summary>
 /// Render the power-up.
 /// </summary>
 /// <param name="elapsedTime">The amount of elapsed time, in seconds.</param>
 /// <param name="lineBatch">The LineBatch to render to.</param>
 public override void Draw(float elapsedTime, LineBatch lineBatch)
 {
     // update the scale period
     scalePeriodElapsed += elapsedTime * timeToScalePeriod;
     while (scalePeriodElapsed < 0)
     {
         scalePeriodElapsed += MathHelper.TwoPi;
     }
     while (scalePeriodElapsed > MathHelper.TwoPi)
     {
         scalePeriodElapsed -= MathHelper.TwoPi;
     }
     // draw the polygons
     if (polygon != null)
     {
         if (lineBatch == null)
         {
             throw new ArgumentNullException("lineBatch");
         }
         // calculate the transformation
         Matrix scaleMatrix = Matrix.CreateScale(0.8f +
             0.1f * (float)Math.Cos(scalePeriodElapsed));
         Matrix world = scaleMatrix *
             Matrix.CreateTranslation(position.X, position.Y, 0f);
         // transform the polygons
         polygon.Transform(world);
         innerPolygon.Transform(world);
         // draw the polygons
         lineBatch.DrawPolygon(polygon, Color.White);
         if (innerPolygon != null)
         {
             lineBatch.DrawPolygon(innerPolygon, color, true);
         }
         // draw the motion blur
         if (useMotionBlur && velocity.LengthSquared() > 1024f)
         {
             // draw several "blur" polygons behind the real polygons
             Vector2 backwards = Vector2.Normalize(position - lastPosition);
             float speed = velocity.Length();
             for (int i = 1; i < speed / 16; ++i)
             {
                 // calculate the "blur" position
                 Vector2 blurPosition = this.position - backwards * (i * 4);
                 // calculate the transformation
                 Matrix blurWorld = scaleMatrix *
                     Matrix.CreateTranslation(blurPosition.X, blurPosition.Y, 0);
                 // transform the polygons
                 polygon.Transform(blurWorld);
                 if (innerPolygon != null)
                 {
                     innerPolygon.Transform(blurWorld);
                 }
                 // calculate the alpha of the "blur" polygons polygons
                 byte alpha = (byte)(160 / (i + 1));
                 if (alpha < 1)
                     break;
                 // draw the "blur" polygons
                 lineBatch.DrawPolygon(polygon, new Color(255, 255, 255, alpha));
                 if (innerPolygon != null)
                 {
                     lineBatch.DrawPolygon(innerPolygon,
                         new Color(color.R, color.G, color.B, alpha), true);
                 }
             }
         }
     }
 }