Ejemplo n.º 1
0
        /// <summary>
        /// Loads graphics content for this screen. The background texture is quite
        /// big, so we use our own local ContentManager to load it. This allows us
        /// to unload before going from the menus into the game itself, wheras if we
        /// used the shared ContentManager provided by the ScreenManager, the content
        /// would remain loaded forever.
        /// </summary>
        public override void LoadContent()
        {
            lineBatch        = new LineBatch(ScreenManager.GraphicsDevice);
            titleTexture     = ScreenManager.Game.Content.Load <Texture2D>("Textures/title");
            refractionEffect = ScreenManager.Game.Content.Load <Effect>("Effects/refraction");
            waterfallTexture = ScreenManager.Game.Content.Load <Texture2D>("Textures/waterfall");

            int viewportWidth  = ScreenManager.GraphicsDevice.Viewport.Width;
            int viewportHeight = ScreenManager.GraphicsDevice.Viewport.Height;

            // update the projection in the line-batch
            lineBatch.SetProjection(Matrix.CreateOrthographicOffCenter(0.0f,
                                                                       viewportWidth, viewportHeight, 0.0f, 0.0f, 1.0f));

            // recreate the particle systems
            particleSystems.Clear();
            for (int i = 0; i < 8; i++)
            {
                //particleSystems.Add(new ParticleSystem(
                //   new Vector2(random.Next(viewportWidth), random.Next(viewportHeight)),
                //   Vector2.Zero, 100, 256, 128,
                //   1f + 2f * (float)random.NextDouble(), 0.075f, explosionColors));
                particleSystems.Add(new ParticleSystem(
                                        new Vector2(random.Next(viewportWidth), random.Next(viewportHeight)),
                                        Vector2.Zero, 64, 256f, 1024f, 3f, 0.05f, explosionColors));
                particleSystems.Add(new ParticleSystem(
                                        new Vector2(random.Next(viewportWidth), random.Next(viewportHeight)),
                                        Vector2.Zero, 128, 64f, 256f, 3f, 0.05f, explosionColors));
            }
            base.LoadContent();
        }
Ejemplo n.º 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, Rendering.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);
                        // 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));
                        if (alpha < 1)
                        {
                            break;
                        }
                        // draw the "blur" polygon
                        lineBatch.DrawPolygon(polygon,
                                              new Color(color.R, color.G, color.B, alpha));
                    }
                }
            }
        }