Example #1
0
        /// <summary>
        /// This is called when the game should draw itself.
        /// </summary>
        protected override void Draw(GameTime gameTime)
        {
            gameView.Reset();
            //levelCompleted = 8;
            if (gameState == GameState.Start)
            {
                gameView.BeginSpritePass(BlendState.AlphaBlend);
                gameView.DrawOverlay(menuBackground, Color.White, true);
                gameView.EndSpritePass();
            }
            else if (gameState == GameState.ChooseLevel)
            {
                Texture2D levelUnlockedSpecific;
                levelUnlockedSpecific = tutorialUnlocked;
                if (levelCompleted == 0)
                {
                    levelUnlockedSpecific = level1Unlocked;
                }
                if (levelCompleted == 1)
                {
                    levelUnlockedSpecific = level2Unlocked;
                }
                if (levelCompleted == 2)
                {
                    levelUnlockedSpecific = level3Unlocked;
                }
                if (levelCompleted == 3)
                {
                    levelUnlockedSpecific = level4Unlocked;
                }
                if (levelCompleted == 4)
                {
                    levelUnlockedSpecific = level5Unlocked;
                }
                if (levelCompleted == 5)
                {
                    levelUnlockedSpecific = level6Unlocked;
                }
                if (levelCompleted == 6)
                {
                    levelUnlockedSpecific = level7Unlocked;
                }
                if (levelCompleted == 7)
                {
                    levelUnlockedSpecific = level8Unlocked;
                }
                if (levelCompleted == 8)
                {
                    levelUnlockedSpecific = level8Unlocked;
                }

                gameView.BeginSpritePass(BlendState.AlphaBlend);
                gameView.DrawOverlay(levelUnlockedSpecific, Color.White, false);
                gameView.EndSpritePass();

                int gridX = optionSelected % 3;
                int gridY = optionSelected / 3;

                gameView.BeginSpritePass(BlendState.AlphaBlend);
                gameView.DrawOverlay(selectionSparkleFilmstrip, Color.White, new Vector2(startX + gridX * incrementX, startY + gridY * incrementX),
                                     new Vector2(0.85f, 0.85f), 0.0f, animationFrame, 4, SpriteEffects.None);
                gameView.EndSpritePass();
            }
            else if (gameState == GameState.RaceBegin)
            {
                currentWorld.Draw(gameView);
                Vector2 pos          = new Vector2(gameView.Width, gameView.Height) / 2.0f;
                Vector2 scale        = new Vector2(1, 1); // To counter global scale
                int     lapFrameSize = (int)(countdownFilmstrip.Width / COUNTDOWN_FRAMES);
                gameView.BeginSpritePass(BlendState.AlphaBlend);
                gameView.DrawOverlay(countdownFilmstrip, Color.White, pos, scale, 0.0f, countdownAnimationFrame, COUNTDOWN_FRAMES, SpriteEffects.None);
                gameView.EndSpritePass();

                /*if (countdown == 3)
                 * {
                 *  gameView.BeginSpritePass(BlendState.AlphaBlend);
                 *  gameView.DrawOverlay(countdown3, Color.White, false);
                 *  gameView.EndSpritePass();
                 * }
                 * else if (countdown == 2)
                 * {
                 *  gameView.BeginSpritePass(BlendState.AlphaBlend);
                 *  gameView.DrawOverlay(countdown2, Color.White, false);
                 *  gameView.EndSpritePass();
                 * }
                 * else if (countdown == 1)
                 * {
                 *  gameView.BeginSpritePass(BlendState.AlphaBlend);
                 *  gameView.DrawOverlay(countdown1, Color.White, false);
                 *  gameView.EndSpritePass();
                 * }*/
            }
            else if (gameState == GameState.Game)
            {
                // World specific drawing
                currentWorld.Draw(gameView);

                if (countdownTimer > 0)
                {
                    Vector2 pos          = new Vector2(gameView.Width, gameView.Height) / 2.0f;
                    Vector2 scale        = new Vector2(1, 1); // To counter global scale
                    int     lapFrameSize = (int)(countdownFilmstrip.Width / COUNTDOWN_FRAMES);
                    gameView.BeginSpritePass(BlendState.AlphaBlend);
                    gameView.DrawOverlay(countdownFilmstrip, Color.White, pos, scale, 0.0f, countdownAnimationFrame, COUNTDOWN_FRAMES, SpriteEffects.None);
                    gameView.EndSpritePass();
                }

                // Final message
                if (currentWorld.Succeeded)
                {
                    switch (currentWorld.FinishingPlace)
                    {
                    case 1:
                        gameView.BeginSpritePass(BlendState.AlphaBlend);
                        gameView.DrawOverlay(firstplace, Color.White, false);
                        gameView.EndSpritePass();
                        break;

                    case 2:
                        gameView.BeginSpritePass(BlendState.AlphaBlend);
                        gameView.DrawOverlay(secondplace, Color.White, false);
                        gameView.EndSpritePass();
                        break;

                    case 3:
                        gameView.BeginSpritePass(BlendState.AlphaBlend);
                        gameView.DrawOverlay(thirdplace, Color.White, false);
                        gameView.EndSpritePass();
                        break;

                    case 4:
                        gameView.BeginSpritePass(BlendState.AlphaBlend);
                        gameView.DrawOverlay(fourthplace, Color.White, false);
                        gameView.EndSpritePass();
                        break;
                    }
                    if (optionSelected > levelCompleted)
                    {
                        levelCompleted = optionSelected;
                    }
                }
                if (currentWorld.Failed)
                {
                    gameView.BeginSpritePass(BlendState.AlphaBlend);
                    gameView.DrawOverlay(failure, Color.White, false);
                    gameView.EndSpritePass();
                }
            }
            else if (gameState == GameState.Pause)
            {
                currentWorld.Draw(gameView);
                gameView.BeginSpritePass(BlendState.AlphaBlend);
                //gameView.DrawOverlay(pause, Color.White, false);
                if (pauseOptionSelected == 0)
                {
                    gameView.DrawOverlay(pauseMenuResume, Color.White, false);
                }
                else if (pauseOptionSelected == 1)
                {
                    gameView.DrawOverlay(pauseMenuRestart, Color.White, false);
                }
                else if (pauseOptionSelected == 2)
                {
                    gameView.DrawOverlay(pauseMenuLevelSelect, Color.White, false);
                }
                gameView.EndSpritePass();
            }

            base.Draw(gameTime);
        }