public static void TestGameHud()
        {
            Mission missionDummy = null;
            GameAsteroidManager asteroidManager = null;

            TestGame.Start(
                "TestGameHud",
                delegate
                {
                    Level firstLevel = Level.LoadAllLevels()[0];
                    asteroidManager = new GameAsteroidManager(firstLevel);
                    missionDummy = new Mission(firstLevel, asteroidManager);

                    // Make sure the textures are linked correctly
                    missionDummy.hudTexture = new Texture("Hud");
                    missionDummy.inGameTexture = new Texture("InGame");
                    missionDummy.levelTexture = asteroidManager.CurrentLevel.Texture;
                },
                delegate
                {
                    // Render sky cube map as our background.
                    BaseGame.skyCube.RenderSky(1.0f, BaseGame.SkyBackgroundColor);

                    // We just want to display the hud
                    missionDummy.ShowHudControls();

                    // Show on screen helper messages
                    missionDummy.ShowScreenMessages(asteroidManager);

                    /*tst
                    //missionDummy.hudTexture.RenderOnScreen(new Point(100, 100));
                    //missionDummy.inGameTexture.RenderOnScreen(new Point(400, 100));
                    Point rocketPos = new Point(100, 100);
                    float rocketRotation = Input.MousePos.X / 500.0f;
                    missionDummy.hudTexture.RenderOnScreenWithRotation(
                        rocketPos,
                        MiniMapFieldOfViewRect.Width / 2, rocketRotation,
                        MiniMapFieldOfViewRect,
                        new Vector2(MiniMapFieldOfViewRect.Width / 2,
                        MiniMapFieldOfViewRect.Width / 2.0f));
                    missionDummy.inGameTexture.RenderOnScreenWithRotation(
                        rocketPos, MiniMapRocketRect.Width / 3,
                        rocketRotation,
                        MiniMapRocketRect,
                        new Vector2(MiniMapRocketRect.Width / 2,
                        MiniMapRocketRect.Width / 2.0f));
                    //missionDummy.inGameTexture.RenderOnScreen(
                    //	new Rectangle(100, 100, MiniMapRocketRect.Width, MiniMapRocketRect.Height),
                    //	MiniMapRocketRect);
                    //*/
                });
        }
        /// <summary>
        /// Show screen messages
        /// </summary>
        private void ShowScreenMessages(GameAsteroidManager asteroidManager)
        {
            Vector3 pos = BaseGame.CameraPos;
            Point messagePos = new Point(BaseGame.Width / 2, BaseGame.Height / 5);

            // If game is over, show end screen and wait until user clicks
            // or presses space.
            if (Player.GameOver)
            {
                TextureFont.WriteTextCentered(messagePos.X, messagePos.Y,
                    Player.victory ? Texts.Victory : Texts.GameOver);
                TextureFont.WriteTextCentered(messagePos.X, messagePos.Y +
                    TextureFont.Height * 4 / 3,
                    Texts.YourHighscore + " " + Player.score + " " +
                    "(#" + (Highscores.GetRankFromCurrentScore(Player.score) + 1) + ")");
            } // if

            // If we just lost a life, display message and let user continue
            // by pressing the left mouse button.
            else if (Player.explosionTimeoutMs >= 0)
            {
                TextureFont.WriteTextCentered(messagePos.X, messagePos.Y,
                    Texts.YouLostALife);
                TextureFont.WriteTextCentered(messagePos.X, messagePos.Y +
                    TextureFont.Height * 4 / 3,
                    Texts.ClickToContinue);

                if (Input.MouseLeftButtonPressed ||
                    Input.GamePadAPressed ||
                    Input.GamePadBPressed ||
                    Input.GamePadXPressed ||
                    Input.GamePadYPressed ||
                    Input.GamePadStartPressed)
                    Player.explosionTimeoutMs = -1;
            } // if

            // Show countdown if a new life started
            else if (Player.lifeTimeMs < Player.LifeTimeZoomAndAccelerateMs)
            {
                float alpha = 1.0f - ((Player.lifeTimeMs % 1000) / 1000.0f);
                alpha *= 2.0f;
                if (alpha > 1.0f)
                    alpha = 1.0f;

                // Show "Get ready" for 3 seconds with countdown,
                // then display "Go!".
                if (Player.lifeTimeMs < 3000)
                {
                    TextureFont.WriteTextCentered(messagePos.X, messagePos.Y,
                        Texts.GetReady);
                    TextureFont.WriteTextCentered(messagePos.X, messagePos.Y +
                        TextureFont.Height * 4 / 3,
                        (3 - (int)(Player.lifeTimeMs / 1000)).ToString(),
                        Color.White, alpha);
                } // if
                else
                    TextureFont.WriteTextCentered(messagePos.X, messagePos.Y,
                        Texts.Go, Color.White, alpha);
            } // if

            // Show item helper messages
            else if (Player.itemMessageTimeoutMs > 0 &&
                String.IsNullOrEmpty(Player.currentItemMessage) == false)
            {
                Player.itemMessageTimeoutMs -= BaseGame.ElapsedTimeThisFrameInMs;
                if (Player.itemMessageTimeoutMs < 0)
                    Player.itemMessageTimeoutMs = 0;

                float alpha = 1.0f;
                if (Player.itemMessageTimeoutMs < 1000)
                    alpha = Player.itemMessageTimeoutMs / 1000.0f;

                TextureFont.WriteTextCentered(messagePos.X, messagePos.Y,
                    Player.currentItemMessage, Color.LightGray, alpha);
            } // if

            // Warning if nearly dead (only if that just happened)
            else if (Player.showHealthWarningTimeoutMs > 0)
            {
                float alpha = 1.0f;
                if (Player.showHealthWarningTimeoutMs < 1000)
                    alpha = Player.showHealthWarningTimeoutMs / 1000.0f;

                TextureFont.WriteTextCentered(messagePos.X, messagePos.Y,
                    Texts.WarningLowHealth, Color.Red, 1.0f);
            } // if

            // Warning if going out of fuel (less than 10%)
            else if (Player.fuel < 0.1f)
            {
                TextureFont.WriteTextCentered(messagePos.X, messagePos.Y,
                    Texts.WarningOutOfFuel, Color.Red, 1.0f);
            } // if

            // Warning if out of playable area!
            else if (pos.X / GameAsteroidManager.SectorWidth <
                -asteroidManager.CurrentLevel.Width / 2 ||
                pos.X / GameAsteroidManager.SectorWidth >
                +asteroidManager.CurrentLevel.Width / 2 ||
                pos.Y / GameAsteroidManager.SectorHeight <
                -asteroidManager.CurrentLevel.Width / 2 ||
                pos.Y / GameAsteroidManager.SectorHeight >
                +asteroidManager.CurrentLevel.Width / 2 ||
                pos.Z < 0)
            {
                TextureFont.WriteTextCentered(messagePos.X, messagePos.Y,
                    Texts.WarningOutOfLevel, Color.Red, 1.0f);
            } // if
        }
        /// <summary>
        /// Create mission
        /// </summary>
        public Mission(Level level, GameAsteroidManager asteroidManager)
        {
            // Set level for asteroid manager.
            asteroidManager.CurrentLevel = level;

            // Start new game.
            Player.Reset(level.Name);
        }
        public static void TestRenderSingleAsteroid()
        {
            //Model testModel1 = null;
            GameAsteroidManager asteroidManager = null;

            TestGame.Start(
                "TestRenderSingleAsteroid",
                delegate
                {
                    //testModel1 = new Model("asteroid1");
                    // Initialize asteroidManager and use last avialable level.
                    asteroidManager = new GameAsteroidManager(
                        Level.LoadAllLevels()[0]);
                },
                delegate
                {
                    // Render sky cube map as our background.
                    BaseGame.skyCube.RenderSky(1.0f, BaseGame.remSkyBackgroundColor);

                    asteroidManager.Render(null, null);

                    //tst: render asteroid in center
                    //asteroidManager.GetAsteroidModel(0).Render(
                    //	Matrix.CreateScale(15, 15, 15));
                    //testModel1.Render(Matrix.CreateScale(4));

                    BaseGame.MeshRenderManager.Render();

                    TextureFont.WriteText(2, 30,
                        "cam pos=" + BaseGame.CameraPos);
                });
        }
        /// <summary>
        /// Initialize textures and models for the game.
        /// </summary>
        protected override void Initialize()
        {
            base.Initialize();

            // Load all available levels
            levels = Level.LoadAllLevels();

            // Initialize asteroidManager and use last avialable level.
            asteroidManager = new GameAsteroidManager(levels[levels.Length - 1]);
            rocketModel = new Model("Rocket");

            // Load menu textures
            mainMenuTexture = new Texture("MainMenu.png");
            helperTexture = new Texture("ExtraButtons.png");
            helpScreenTexture = new Texture("HelpScreen.png");
            mouseCursorTexture = new Texture("MouseCursor.dds");

            hudTexture = new Texture("Hud.png");
            inGameTexture = new Texture("InGame.png");

            lightEffectTexture = new Texture("LightEffect.dds");

            explosionTexture = new AnimatedTexture("Explosion");

            // Create main menu screen
            gameScreens.Push(new MainMenu());

            //tst:
            //gameScreens.Push(new Mission(levels[0], asteroidManager));
            //inGame = gameScreens.Peek().GetType() == typeof(Mission);
            //camera.InGame = inGame;
        }
        }         // ResetLifeValues()

        #endregion

        #region Handle game logic
        /// <summary>
        /// Handle game logic
        /// </summary>
        /// <param name="asteroidManager">Asteroid manager</param>
        public static void HandleGameLogic(GameAsteroidManager asteroidManager)
        {
            if (gameTimeMs == 0)
            {
                // Start playing rocket motor
                Sound.PlayRocketMotorSound(0.86f);
                //obs: asteroidManager.PlayRocketMotorSound(0.86f);
            }             // if (gameTimeMs)

            // Increase explosion effect timeout if used
            if (explosionTimeoutMs >= 0)
            {
                explosionTimeoutMs -= BaseGame.ElapsedTimeThisFrameInMs;
                if (explosionTimeoutMs < 0)
                {
                    explosionTimeoutMs = 0;
                }
            }             // if (explosionTimeoutMs)
            else if (GameOver == false)
            {
                // Increase game time
                gameTimeMs += BaseGame.ElapsedTimeThisFrameInMs;

                // Same for rocket life time
                lifeTimeMs += BaseGame.ElapsedTimeThisFrameInMs;
            }             // else if

            if (explosionTimeoutMs2 >= 0)
            {
                explosionTimeoutMs2 -= BaseGame.ElapsedTimeThisFrameInMs;
                if (explosionTimeoutMs2 < 0)
                {
                    explosionTimeoutMs2 = 0;
                }
            }             // if (explosionTimeoutMs2)
            if (explosionTimeoutMs3 >= 0)
            {
                explosionTimeoutMs3 -= BaseGame.ElapsedTimeThisFrameInMs;
                if (explosionTimeoutMs3 < 0)
                {
                    explosionTimeoutMs3 = 0;
                }
            }             // if (explosionTimeoutMs3)

            if (cameraWobbelTimeoutMs > 0)
            {
                cameraWobbelTimeoutMs -= BaseGame.ElapsedTimeThisFrameInMs;
                if (cameraWobbelTimeoutMs < 0)
                {
                    cameraWobbelTimeoutMs = 0;
                }
            }             // if (cameraWobbelTimeoutMs)

            // Don't handle any more game logic if game is over.
            if (Player.GameOver)
            {
                return;
            }

            float oldHealth = Player.health;

            // Adjust rocket playback frequency to flying speed
            Sound.ChangeRocketMotorPitchEffect(
                -0.24f + speed * 0.6f);
            //0.66f + speed * 0.9f);

            // Check if too near to an asteroid. Check 3x3 sector in middle.
            if (CanControlRocket)
            {
                float playerCollision = asteroidManager.PlayerAsteroidCollision();

                if (playerCollision > 0.0f)
                {
                    // Frontal hits might kill us, side hits only hurt
                    // (but always at least 10%).
                    Player.health -= 0.1f + playerCollision * 4.25f;

                    // We shouldn't die on the first hit, even a frontal hit
                    // could be survived IF (and only if) we were at 100% health!
                    if (oldHealth == 1.0f &&
                        Player.health <= 0.0f)
                    {
                        // Restore to 10% (next hit will kill us!)
                        Player.health = 0.1f;
                    }     // if (oldHealth)
                }         // if (playerCollision)
            }             // if (CanControlRocket)

            // If we are below 0 fuel, that gonna hurt.
            if (Player.fuel < 0)
            {
                Player.fuel    = 0;
                Player.health -= BaseGame.MoveFactorPerSecond /
                                 Player.HurtFactorIfFuelIsEmpty;
            }             // if (Player.fuel)

            // Show health low warning if health is getting very low.
            if (oldHealth >= 0.25f && health < 0.25f ||
                oldHealth >= 0.1f && health < 0.1f)
            {
                showHealthWarningTimeoutMs = 8 * 1000;
            }
            if (showHealthWarningTimeoutMs > 0)
            {
                showHealthWarningTimeoutMs -= BaseGame.ElapsedTimeThisFrameInMs;
                if (showHealthWarningTimeoutMs < 0)
                {
                    showHealthWarningTimeoutMs = 0;
                }
            }             // if (showHealthWarningTimeoutMs)

            // Die if health is 0 or lower
            if (Player.health <= 0)
            {
                Player.health = 0;

                // Explode!
                Player.explosionTimeoutMs = MaxExplosionTimeoutMs;

                // Reset everything for the player, all items and stuff
                Player.ResetLifeValues();

                // If we have lifes left, reduce them.
                if (Player.lifes > 0)
                {
                    Sound.PlayExplosionSound();
                    Player.lifes--;
                }                 // if (Player.lifes)
                else
                {
                    victory = false;
                    // Play multiple explosions (a little later)
                    Player.explosionTimeoutMs2 = (int)(MaxExplosionTimeoutMs * 1.6f);
                    Player.explosionTimeoutMs3 = (int)(MaxExplosionTimeoutMs * 2.1f);
                    Player.SetGameOverAndUploadHighscore();
                    Sound.StopRocketMotorSound();
                    Sound.PlayDefeatSound();
                }                 // else

                // Use minimum possible speed
                Player.Speed = Player.MinSpeedWithoutItem;

                // Kill all asteroids in inner sectors (3x3)
                asteroidManager.KillAllInnerSectorAsteroids();
            }             // if (Player.health)

            // Reached target? Then we won!
            if (BaseGame.CameraPos.Z >=
                asteroidManager.CurrentLevel.Length * GameAsteroidManager.SectorDepth)
            {
                victory = true;

                // Add number of lifes left to score (10000 points per life)
                score += lifes * 10000;

                // If player took less than levelLength/2 seconds, add time bonus
                int maxGameTime = (asteroidManager.CurrentLevel.Length / 2) * 1000;
                if (gameTimeMs < maxGameTime)
                {
                    // Give 200 points per second, 12000 points per minute
                    // E.g. if we took only 4 minutes we get 4 * 12000 extra points =
                    // 48000 extra points.
                    score += (int)(maxGameTime - gameTimeMs) / 10;
                }

                // And add health and fuel we left to score
                score += (int)(health * 3000);
                score += (int)(fuel * 4000);

                // End game, upload highscore and stuff!
                Player.SetGameOverAndUploadHighscore();
                Sound.StopRocketMotorSound();
                Sound.PlayVictorySound();
            }     // if (BaseGame.CameraPos.Z)
        }         // HandleGameLogic(asteroidManager)
        /// <summary>
        /// Handle game logic
        /// </summary>
        /// <param name="asteroidManager">Asteroid manager</param>
        public static void HandleGameLogic(GameAsteroidManager asteroidManager)
        {
            if (gameTimeMs == 0)
            {
                // Start playing rocket motor
                Sound.PlayRocketMotorSound(0.86f);
                //obs: asteroidManager.PlayRocketMotorSound(0.86f);
            } // if (gameTimeMs)

            // Increase explosion effect timeout if used
            if (explosionTimeoutMs >= 0)
            {
                explosionTimeoutMs -= BaseGame.ElapsedTimeThisFrameInMs;
                if (explosionTimeoutMs < 0)
                    explosionTimeoutMs = 0;
            } // if (explosionTimeoutMs)
            else if (GameOver == false)
            {
                // Increase game time
                gameTimeMs += BaseGame.ElapsedTimeThisFrameInMs;

                // Same for rocket life time
                lifeTimeMs += BaseGame.ElapsedTimeThisFrameInMs;
            } // else if

            if (explosionTimeoutMs2 >= 0)
            {
                explosionTimeoutMs2 -= BaseGame.ElapsedTimeThisFrameInMs;
                if (explosionTimeoutMs2 < 0)
                    explosionTimeoutMs2 = 0;
            } // if (explosionTimeoutMs2)
            if (explosionTimeoutMs3 >= 0)
            {
                explosionTimeoutMs3 -= BaseGame.ElapsedTimeThisFrameInMs;
                if (explosionTimeoutMs3 < 0)
                    explosionTimeoutMs3 = 0;
            } // if (explosionTimeoutMs3)

            if (cameraWobbelTimeoutMs > 0)
            {
                cameraWobbelTimeoutMs -= BaseGame.ElapsedTimeThisFrameInMs;
                if (cameraWobbelTimeoutMs < 0)
                    cameraWobbelTimeoutMs = 0;
            } // if (cameraWobbelTimeoutMs)

            // Don't handle any more game logic if game is over.
            if (Player.GameOver)
                return;

            float oldHealth = Player.health;

            // Adjust rocket playback frequency to flying speed
            Sound.ChangeRocketMotorPitchEffect(
                -0.24f + speed * 0.6f);
                //0.66f + speed * 0.9f);

            // Check if too near to an asteroid. Check 3x3 sector in middle.
            if (CanControlRocket)
            {
                float playerCollision = asteroidManager.PlayerAsteroidCollision();

                if (playerCollision > 0.0f)
                {
                    // Frontal hits might kill us, side hits only hurt
                    // (but always at least 10%).
                    Player.health -= 0.1f + playerCollision * 4.25f;

                    // We shouldn't die on the first hit, even a frontal hit
                    // could be survived IF (and only if) we were at 100% health!
                    if (oldHealth == 1.0f &&
                        Player.health <= 0.0f)
                    {
                        // Restore to 10% (next hit will kill us!)
                        Player.health = 0.1f;
                    } // if (oldHealth)
                } // if (playerCollision)
            } // if (CanControlRocket)

            // If we are below 0 fuel, that gonna hurt.
            if (Player.fuel < 0)
            {
                Player.fuel = 0;
                Player.health -= BaseGame.MoveFactorPerSecond /
                    Player.HurtFactorIfFuelIsEmpty;
            } // if (Player.fuel)

            // Show health low warning if health is getting very low.
            if (oldHealth >= 0.25f && health < 0.25f ||
                oldHealth >= 0.1f && health < 0.1f)
                showHealthWarningTimeoutMs = 8 * 1000;
            if (showHealthWarningTimeoutMs > 0)
            {
                showHealthWarningTimeoutMs -= BaseGame.ElapsedTimeThisFrameInMs;
                if (showHealthWarningTimeoutMs < 0)
                    showHealthWarningTimeoutMs = 0;
            } // if (showHealthWarningTimeoutMs)

            // Die if health is 0 or lower
            if (Player.health <= 0)
            {
                Player.health = 0;

                // Explode!
                Player.explosionTimeoutMs = MaxExplosionTimeoutMs;

                // Reset everything for the player, all items and stuff
                Player.ResetLifeValues();

                // If we have lifes left, reduce them.
                if (Player.lifes > 0)
                {
                    Sound.PlayExplosionSound();
                    Player.lifes--;
                } // if (Player.lifes)
                else
                {
                    victory = false;
                    // Play multiple explosions (a little later)
                    Player.explosionTimeoutMs2 = (int)(MaxExplosionTimeoutMs * 1.6f);
                    Player.explosionTimeoutMs3 = (int)(MaxExplosionTimeoutMs * 2.1f);
                    Player.SetGameOverAndUploadHighscore();
                    Sound.StopRocketMotorSound();
                    Sound.PlayDefeatSound();
                } // else

                // Use minimum possible speed
                Player.Speed = Player.MinSpeedWithoutItem;

                // Kill all asteroids in inner sectors (3x3)
                asteroidManager.KillAllInnerSectorAsteroids();
            } // if (Player.health)

            // Reached target? Then we won!
            if (BaseGame.CameraPos.Z >=
                asteroidManager.CurrentLevel.Length * GameAsteroidManager.SectorDepth)
            {
                victory = true;

                // Add number of lifes left to score (10000 points per life)
                score += lifes * 10000;

                // If player took less than levelLength/2 seconds, add time bonus
                int maxGameTime = (asteroidManager.CurrentLevel.Length / 2) * 1000;
                if (gameTimeMs < maxGameTime)
                    // Give 200 points per second, 12000 points per minute
                    // E.g. if we took only 4 minutes we get 4 * 12000 extra points =
                    // 48000 extra points.
                    score += (int)(maxGameTime - gameTimeMs) / 10;

                // And add health and fuel we left to score
                score += (int)(health * 3000);
                score += (int)(fuel * 4000);

                // End game, upload highscore and stuff!
                Player.SetGameOverAndUploadHighscore();
                Sound.StopRocketMotorSound();
                Sound.PlayVictorySound();
            } // if (BaseGame.CameraPos.Z)
        }