Exemplo n.º 1
0
        /// <summary>
        /// Load graphics content for the game.
        /// </summary>
        public override void LoadContent()
        {
            if (content == null)
            {
                content = new ContentManager(ScreenManager.Game.Services, "Content");
            }
            spriteBatch = new SpriteBatch(ScreenManager.GraphicsDevice);
            lineBatch   = new LineBatch(ScreenManager.GraphicsDevice);
            spriteFont  = content.Load <SpriteFont>("Fonts/retroSmall");
            starTexture = content.Load <Texture2D>("Textures/blank");

            // update the projection in the line-batch
            lineBatch.SetProjection(Matrix.CreateOrthographicOffCenter(0.0f,
                                                                       ScreenManager.GraphicsDevice.Viewport.Width,
                                                                       ScreenManager.GraphicsDevice.Viewport.Height, 0.0f, 0.0f, 1.0f));
#if ANDROID || IOS
            gamePadTexture = content.Load <Texture2D>("Textures/gamepad");

            ThumbStickDefinition thumbStickLeft = new ThumbStickDefinition();
            thumbStickLeft.Position    = new Vector2(10, 400);
            thumbStickLeft.Texture     = gamePadTexture;
            thumbStickLeft.TextureRect = new Rectangle(2, 2, 68, 68);

            GamePad.LeftThumbStickDefinition = thumbStickLeft;

            ThumbStickDefinition thumbStickRight = new ThumbStickDefinition();
            thumbStickRight.Position    = new Vector2(240, 400);
            thumbStickRight.Texture     = gamePadTexture;
            thumbStickRight.TextureRect = new Rectangle(2, 2, 68, 68);

            GamePad.RightThumbStickDefinition = thumbStickRight;
#endif
        }
Exemplo n.º 2
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);
        }
 /// <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 override void Draw(float elapsedTime, LineBatch lineBatch)
 {
     if (lineBatch == null)
     {
         throw new ArgumentNullException("lineBatch");
     }
     // draw a simple line
     lineBatch.DrawLine(position,
                        position - velocity * lineLengthVelocityPercent, Color.Yellow);
 }
 /// <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 override void Draw(float elapsedTime, LineBatch lineBatch)
 {
     if (lineBatch == null)
     {
         throw new ArgumentNullException("lineBatch");
     }
     // draw a simple line
     lineBatch.DrawLine(position,
         position - velocity * lineLengthVelocityPercent, Color.Yellow);
 }
Exemplo n.º 5
0
 /// <summary>
 /// Draw the walls.
 /// </summary>
 /// <param name="lineBatch">The LineBatch to render to.</param>
 public void DrawWalls(LineBatch lineBatch)
 {
     if (lineBatch == null)
     {
         throw new ArgumentNullException("lineBatch");
     }
     // draw each wall-line
     for (int wall = 0; wall < walls.Length / 2; wall++)
     {
         lineBatch.DrawLine(walls[wall * 2], walls[wall * 2 + 1], Color.Yellow);
     }
 }
Exemplo n.º 6
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));
                    }
                }
            }
        }
Exemplo n.º 7
0
 /// <summary>
 /// Unload graphics content used by the game.
 /// </summary>
 public override void UnloadContent()
 {
     if (spriteBatch != null)
     {
         spriteBatch.Dispose();
         spriteBatch = null;
     }
     if (lineBatch != null)
     {
         lineBatch.Dispose();
         lineBatch = null;
     }
     content.Unload();
 }
Exemplo n.º 8
0
 /// <summary>
 /// Render the particle system.
 /// </summary>
 /// <param name="lineBatch">The line batch which draws all the particles</param>
 public virtual void Draw(LineBatch lineBatch)
 {
     if (lifeRemaining > 0f)
     {
         if (lineBatch == null)
         {
             throw new ArgumentNullException("lineBatch");
         }
         for (int i = 0; i < particles.Length; i++)
         {
             lineBatch.DrawLine(particles[i].Position,
                                particles[i].Position - particles[i].Velocity * tailLength,
                                particles[i].Color);
         }
     }
 }
Exemplo n.º 9
0
        /// <summary>
        /// Load graphics content for the game.
        /// </summary>
        public override void LoadContent()
        {
            if (content == null)
            {
                content = new ContentManager(ScreenManager.Game.Services, "Content");
            }
            spriteBatch = new SpriteBatch(ScreenManager.GraphicsDevice);
            lineBatch   = new LineBatch(ScreenManager.GraphicsDevice);
            spriteFont  = content.Load <SpriteFont>("Fonts/retroSmall");
            starTexture = content.Load <Texture2D>("Textures/blank");

            // update the projection in the line-batch
            lineBatch.SetProjection(Matrix.CreateOrthographicOffCenter(0.0f,
                                                                       ScreenManager.GraphicsDevice.Viewport.Width,
                                                                       ScreenManager.GraphicsDevice.Viewport.Height, 0.0f, 0.0f, 1.0f));
        }
Exemplo n.º 10
0
        /// <summary>
        /// Draw the walls.
        /// </summary>
        /// <param name="lineBatch">The LineBatch to render to.</param>
        public void DrawWalls(LineBatch lineBatch)
        {
            if (lineBatch == null)
            {
                throw new ArgumentNullException(nameof(lineBatch));
            }

            // draw each wall-line
            if (Walls != null)
            {
                for (int wall = 0; wall < Walls.Length / 2; wall++)
                {
                    lineBatch.DrawLine(Walls[wall * 2], Walls[wall * 2 + 1], Color);
                }
            }
        }
Exemplo n.º 11
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");

            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 < 4; i++)
            {
                particleSystems.Add(new ParticleSystem(
                   new Vector2(random.Next(viewportWidth), random.Next(viewportHeight)),
                   Vector2.Zero, 64, 256, 128,
                   1f + 2f * (float)random.NextDouble(), 0.05f, explosionColors));
            }

            base.LoadContent();
        }
Exemplo n.º 12
0
        /// <summary>
        /// Draw the walls.
        /// </summary>
        /// <param name="lineBatch">The LineBatch to render to.</param>
        public void DrawWalls(LineBatch lineBatch)
        {
            if (lineBatch == null)
            {
                throw new ArgumentNullException(nameof(lineBatch));
            }

            // draw each wall-line
            if (Walls != null)
            {
                int viewportWidth  = lineBatch.GraphicsDevice.Viewport.Width;
                int viewportHeight = lineBatch.GraphicsDevice.Viewport.Height;

                Vector2 startLine;
                Vector2 endLine;

                for (int wall = 0; wall < Walls.Length / 2; wall++)
                {
                    startLine = new Vector2(Walls[wall * 2].X * viewportWidth, Walls[wall * 2].Y * viewportHeight);
                    endLine   = new Vector2(Walls[wall * 2 + 1].X * viewportWidth, Walls[wall * 2 + 1].Y * viewportHeight);
                    lineBatch.DrawLine(startLine, endLine, Color);
                }
            }
        }
Exemplo n.º 13
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);
 }
Exemplo n.º 14
0
 /// <summary>
 /// Unload graphics content used by the game.
 /// </summary>
 public override void UnloadContent()
 {
     if (spriteBatch != null)
     {
         spriteBatch.Dispose();
         spriteBatch = null;
     }
     if (lineBatch != null)
     {
         lineBatch.Dispose();
         lineBatch = null;
     }
     content.Unload();
 }
Exemplo n.º 15
0
        /// <summary>
        /// Load graphics content for the game.
        /// </summary>
        public override void LoadContent()
        {
            if (content == null)
            {
                content = new ContentManager(ScreenManager.Game.Services, "Content");
            }
            spriteBatch = new SpriteBatch(ScreenManager.GraphicsDevice);
            lineBatch = new LineBatch(ScreenManager.GraphicsDevice);
            spriteFont = content.Load<SpriteFont>("Fonts/retroSmall");
            starTexture = content.Load<Texture2D>("Textures/blank");

            // update the projection in the line-batch
            lineBatch.SetProjection(Matrix.CreateOrthographicOffCenter(0.0f,
                ScreenManager.GraphicsDevice.Viewport.Width,
                ScreenManager.GraphicsDevice.Viewport.Height, 0.0f, 0.0f, 1.0f));
            #if ANDROID || IOS
            gamePadTexture = content.Load<Texture2D>("Textures/gamepad");

            ThumbStickDefinition thumbStickLeft = new ThumbStickDefinition();
            thumbStickLeft.Position = new Vector2(10,400);
            thumbStickLeft.Texture = gamePadTexture;
            thumbStickLeft.TextureRect = new Rectangle(2,2,68,68);

            GamePad.LeftThumbStickDefinition = thumbStickLeft;

            ThumbStickDefinition thumbStickRight = new ThumbStickDefinition();
            thumbStickRight.Position = new Vector2(240,400);
            thumbStickRight.Texture = gamePadTexture;
            thumbStickRight.TextureRect = new Rectangle(2,2,68,68);

            GamePad.RightThumbStickDefinition = thumbStickRight;
            #endif
        }
Exemplo n.º 16
0
 /// <summary>
 /// Draw the walls.
 /// </summary>
 /// <param name="lineBatch">The LineBatch to render to.</param>
 public void DrawWalls(LineBatch lineBatch)
 {
     if (lineBatch == null)
     {
         throw new ArgumentNullException("lineBatch");
     }
     // draw each wall-line
     for (int wall = 0; wall < walls.Length / 2; wall++)
     {
         lineBatch.DrawLine(walls[wall * 2], walls[wall * 2 + 1], Color.Yellow);
     }
 }
Exemplo n.º 17
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("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));
                    }
                }
            }
        }
Exemplo n.º 18
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>
        /// 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");

            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 < 4; i++)
            {
                particleSystems.Add(new ParticleSystem(
                   new Vector2(random.Next(viewportWidth), random.Next(viewportHeight)),
                   Vector2.Zero, 64, 256, 128,
                   1f + 2f * (float)random.NextDouble(), 0.05f, explosionColors));
            }

            base.LoadContent();
        }
Exemplo n.º 20
0
 /// <summary>
 /// Render the particle system.
 /// </summary>
 /// <param name="lineBatch">The line batch which draws all the particles</param>
 public virtual void Draw(LineBatch lineBatch)
 {
     if (lifeRemaining > 0f)
     {
         if (lineBatch == null)
         {
             throw new ArgumentNullException("lineBatch");
         }
         for (int i = 0; i < particles.Length; i++)
         {
             lineBatch.DrawLine(particles[i].Position,
                 particles[i].Position - particles[i].Velocity * tailLength,
                 particles[i].Color);
         }
     }
 }
Exemplo n.º 21
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("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);
                 }
             }
         }
     }
 }