}         // RemoveCurrentGameScreen()

        #endregion

        #region Render background
        /// <summary>
        /// Render menu background
        /// </summary>
        public void RenderMenuBackground()
        {
            // Make sure alpha blending is enabled.
            BaseGame.EnableAlphaBlending();

            Rectangle upperRect = new Rectangle(
                BaseGame.ResolutionRect.X,
                BaseGame.ResolutionRect.Y,
                BaseGame.ResolutionRect.Width,
                BaseGame.ResolutionRect.Height -
                (int)Math.Round(70 * BaseGame.Height / 768.0f));

            mainMenuTexture.RenderOnScreen(
                upperRect,
                // Skip last 70 pixels, done when rendering bottom link buttons
                new Rectangle(0, 0, 1024, 768 - 70));

            // Show all bottom link buttons (they are part of the background)
            if (RenderBottomLinkButton(BottomLinkButton.ExDream))
            {
#if !XBOX360
                Process.Start("http://www.exDream.com");
                // Give some time to os, won't help much, but anyway ...
                Thread.Sleep(100);
#endif
            }             // if
            if (RenderBottomLinkButton(BottomLinkButton.RocketCommander))
            {
#if !XBOX360
                Process.Start("http://www.RocketCommander.com");
                Thread.Sleep(100);
#endif
            }             // if
            if (RenderBottomLinkButton(BottomLinkButton.Microsoft))
            {
#if !XBOX360
                Process.Start("http://www.Microsoft.com");
                Thread.Sleep(100);
#endif
            }     // if
        }         // RenderMenuBackground()
        /// <summary>
        /// Render, most performance critical method of the game.
        /// Renders all asteroids and handles all physics, updating, etc.
        /// We use instancing to speed up asteroid rendering!
        /// </summary>
        public void Render(Texture inGameTexture, Texture lightEffectTexture)
        {
            #region Initialize
            // Use alpha blending for blending out asteroids
            BaseGame.EnableAlphaBlending();

            // Get camera position, no need to call the property 1 mio times.
            Vector3 cameraPos = BaseGame.CameraPos;

            // Empty display distance list
            remToDisplayDistance.Clear();
            #endregion

            #region Show target behind asteroids
            // Show target icon behind all asteroids and items (only in game)
            if (inGameTexture != null)
            {
                // First find out where the target is.
                Point screenPos = BaseGame.Convert3DPointTo2D(TargetPosition);
                bool isVisible = BaseGame.IsInFrontOfCamera(TargetPosition);

                if (isVisible &&
                    screenPos.X >= 0 && screenPos.X < BaseGame.Width &&
                    screenPos.Y >= 0 && screenPos.Y < BaseGame.Height)
                {
                    // From Mission.cs:70.
                    Rectangle TargetIconRect = new Rectangle(106, 49, 61, 61);

                    // Render target icon centered at screenPos
                    // Note: This will be blurred because we render it before
                    // the glow/bloom/motion blur shader is applied, but if we
                    // render after that we can't render behind the asteroids.
                    // See Mission.RenderTarget!
                    inGameTexture.RenderOnScreen(new Rectangle(
                        screenPos.X - TargetIconRect.Width / 2,
                        screenPos.Y - TargetIconRect.Height / 2,
                        TargetIconRect.Width, TargetIconRect.Height),
                        TargetIconRect, Color.White, SpriteBlendMode.Additive);
                } // if (isVisible)
            } // if (inGameTexture)
            #endregion

            #region Show glow behind items
            // Show glow behind all items
            for (int num = 0; num < Level.NumOfItemTypes; num++)
            {
                // Go through all items of this type
                foreach (Vector3 pos in items[num])
                {
                    // Get distance to viewer
                    float distance = (pos - cameraPos).Length();

                    // Skip if out of visible range * 6
                    if (distance > MaxViewDepth * 6 ||
                        BaseGame.IsInFrontOfCamera(pos) == false)
                        continue;

                    // Convert to screen coordinates
                    Point screenPos = BaseGame.Convert3DPointTo2D(pos);
                    int glowSize = 36 * BaseGame.Width / 1024;

                    // If not visible, skip!
                    if (screenPos.X < -glowSize ||
                        screenPos.Y < -glowSize ||
                        screenPos.X > BaseGame.Width + glowSize ||
                        screenPos.Y > BaseGame.Height + glowSize)
                        continue;

                    // Calculate alpha
                    float alpha = 1.0f;
                    if (distance > MaxViewDepth * 4)
                        alpha = 1.0f -
                            ((distance - MaxViewDepth * 4) / (MaxViewDepth * (6 - 4)));

                    // Show glow with help of light effect
                    if (lightEffectTexture != null)
                        lightEffectTexture.RenderOnScreen(
                            new Rectangle(screenPos.X - glowSize, screenPos.Y - glowSize,
                            glowSize * 2, glowSize * 2),
                            lightEffectTexture.GfxRectangle,
                            ColorHelper.ApplyAlphaToColor(ItemColors[num], alpha * 0.5f),
                            SpriteBlendMode.Additive);

                    // And display distance to item below it (not here, see below).
                    float textAlpha = alpha * 1.5f *
                        (1.0f - (distance / (MaxViewDepth * 6)));
                    AddDistanceToBeDisplayed(screenPos, distance,
                        textAlpha < 1.0f ? textAlpha : 1.0f);
                } // foreach (pos)
            } // for (num)

            // Flush all glow sprites on the screen (before rendering asteroids!)
            SpriteHelper.DrawSprites();
            #endregion

            #region Render 3d models, especially the asteroids
            // Draw goal at target position
            goalModel.Render(Matrix.CreateScale(100) *
                Matrix.CreateRotationX(-(float)Math.PI / 2.0f) *
                Matrix.CreateTranslation(TargetPosition));

            // Call base render method, target and item glow is behind of the
            // asteroids.
            base.RenderAsteroids();
            #endregion
        }
Exemple #3
0
        }                                           // ShowAllItems(useShader)

        #endregion

        #region Render
        /// <summary>
        /// Render, most performance critical method of the game.
        /// Renders all asteroids and handles all physics, updating, etc.
        /// We use instancing to speed up asteroid rendering!
        /// </summary>
        public void Render(Texture inGameTexture, Texture lightEffectTexture)
        {
            #region Initialize
            // Use alpha blending for blending out asteroids
            BaseGame.EnableAlphaBlending();

            // Get camera position, no need to call the property 1 mio times.
            Vector3 cameraPos = BaseGame.CameraPos;

            // Empty display distance list
            remToDisplayDistance.Clear();
            #endregion

            #region Show target behind asteroids
            // Show target icon behind all asteroids and items (only in game)
            if (inGameTexture != null)
            {
                // First find out where the target is.
                Point screenPos = BaseGame.Convert3DPointTo2D(TargetPosition);
                bool  isVisible = BaseGame.IsInFrontOfCamera(TargetPosition);

                if (isVisible &&
                    screenPos.X >= 0 && screenPos.X < BaseGame.Width &&
                    screenPos.Y >= 0 && screenPos.Y < BaseGame.Height)
                {
                    // From Mission.cs:70.
                    Rectangle TargetIconRect = new Rectangle(106, 49, 61, 61);

                    // Render target icon centered at screenPos
                    // Note: This will be blurred because we render it before
                    // the glow/bloom/motion blur shader is applied, but if we
                    // render after that we can't render behind the asteroids.
                    // See Mission.RenderTarget!
                    inGameTexture.RenderOnScreen(new Rectangle(
                                                     screenPos.X - TargetIconRect.Width / 2,
                                                     screenPos.Y - TargetIconRect.Height / 2,
                                                     TargetIconRect.Width, TargetIconRect.Height),
                                                 TargetIconRect, Color.White, SpriteBlendMode.Additive);
                }         // if (isVisible)
            }             // if (inGameTexture)
            #endregion

            #region Show glow behind items
            // Show glow behind all items
            for (int num = 0; num < Level.NumOfItemTypes; num++)
            {
                // Go through all items of this type
                foreach (Vector3 pos in items[num])
                {
                    // Get distance to viewer
                    float distance = (pos - cameraPos).Length();

                    // Skip if out of visible range * 6
                    if (distance > MaxViewDepth * 6 ||
                        BaseGame.IsInFrontOfCamera(pos) == false)
                    {
                        continue;
                    }

                    // Convert to screen coordinates
                    Point screenPos = BaseGame.Convert3DPointTo2D(pos);
                    int   glowSize  = 36 * BaseGame.Width / 1024;

                    // If not visible, skip!
                    if (screenPos.X < -glowSize ||
                        screenPos.Y < -glowSize ||
                        screenPos.X > BaseGame.Width + glowSize ||
                        screenPos.Y > BaseGame.Height + glowSize)
                    {
                        continue;
                    }

                    // Calculate alpha
                    float alpha = 1.0f;
                    if (distance > MaxViewDepth * 4)
                    {
                        alpha = 1.0f -
                                ((distance - MaxViewDepth * 4) / (MaxViewDepth * (6 - 4)));
                    }

                    // Show glow with help of light effect
                    if (lightEffectTexture != null)
                    {
                        lightEffectTexture.RenderOnScreen(
                            new Rectangle(screenPos.X - glowSize, screenPos.Y - glowSize,
                                          glowSize * 2, glowSize * 2),
                            lightEffectTexture.GfxRectangle,
                            ColorHelper.ApplyAlphaToColor(ItemColors[num], alpha * 0.5f),
                            SpriteBlendMode.Additive);
                    }

                    // And display distance to item below it (not here, see below).
                    float textAlpha = alpha * 1.5f *
                                      (1.0f - (distance / (MaxViewDepth * 6)));
                    AddDistanceToBeDisplayed(screenPos, distance,
                                             textAlpha < 1.0f ? textAlpha : 1.0f);
                }         // foreach (pos)
            }             // for (num)

            // Flush all glow sprites on the screen (before rendering asteroids!)
            SpriteHelper.DrawSprites();
            #endregion

            #region Render 3d models, especially the asteroids
            // Draw goal at target position
            goalModel.Render(Matrix.CreateScale(100) *
                             Matrix.CreateRotationX(-(float)Math.PI / 2.0f) *
                             Matrix.CreateTranslation(TargetPosition));

            // Call base render method, target and item glow is behind of the
            // asteroids.
            base.RenderAsteroids();
            #endregion
        }         // Render()