Example #1
0
        /// <summary>
        /// This is called when the game should draw itself.
        /// </summary>
        /// <param name="gameTime">Provides a snapshot of timing values.</param>
        protected override void Draw(GameTime gameTime)
        {
            spriteBatch.Begin(SpriteSortMode.Deferred, null, null, null, null, null, cameraView.GetViewMatrix());

            //Call Title
            if (gameState == TITLE)
            {
                spriteBatch.Draw(title, new Vector2(0, 0), Color.White);
            }

            //Call Game
            else if (gameState == GAME || gameState == PAUSED)
            {
                //Draw the parallaxing background
                for (int j = 0; j < numParallax; j++)
                {
                    for (int i = 0; i < 2; i++)                                                                                           //Canonly have 2 backgrounds. They need to be > 1920 in width.
                    {
                        spriteBatch.Draw(parallaxImage[j], new Vector2(parallaxPosition[i, j].X, parallaxPosition[i, j].Y), Color.White); //Parallaxing bg
                    }
                }

                //Draw the stages over the player
                for (int i = 0; i < stages.Count(); i++)
                {
                    if (stages.ElementAt(i).position.X > -stages.ElementAt(i).width&& stages.ElementAt(i).position.X < screenWidth)
                    {
                        spriteBatch.Draw(stages.ElementAt(i).bg, stages.ElementAt(i).position, Color.White);
                        spriteBatch.Draw(stages.ElementAt(i).color_map, stages.ElementAt(i).position, Color.White);
                    }

                    //Set up the rectangle for checking collisions and painting the sky.
                    stages.ElementAt(i).rectangle = new Rectangle((int)stages.ElementAt(i).position.X, (int)stages.ElementAt(i).position.Y,
                                                                  stages.ElementAt(i).width, stages.ElementAt(i).height);
                }
                //Draw the firworks
                for (int i = 0; i < fireworks.Count(); i++)
                {
                    fireworks.ElementAt(i).Draw(spriteBatch);
                }

                //Draw the fragments
                for (int i = 0; i < fragments.Count(); i++)
                {
                    fragments.ElementAt(i).Draw(spriteBatch);
                }

                //Draw the player
                player.Draw(spriteBatch);

                spriteBatch.End();

                //Start drawing stuff that doesn't scroll with the camera view.
                spriteBatch.Begin();

                //Draw the hearts
                for (int i = 0; i < lives; i++)
                {
                    spriteBatch.Draw(heart_sprite, new Vector2(heart_x + i * heart_sprite.Width, heart_y), Color.White);
                }

                //Draw the Score
                spriteBatch.DrawString(scoreFont, "Best: " + ((displayedScore > highscores.score[0]) ? displayedScore : highscores.score[0]) + "\nCurrent: " + displayedScore,
                                       new Vector2(20, 20), Color.Black);

                //Paused
                if (gameState == PAUSED)
                {
                    if (Windows8._windowState == WindowState.Snap1Quarter)
                    {
                        spriteBatch.Draw(paused, new Vector2(-45, (screenHeight / 2) - paused.Height / 2), Color.White);
                    }
                    else//This is the normal spot to draw the pause image.
                    {
                        spriteBatch.Draw(paused, new Vector2((screenWidth / 2) - paused.Width / 2, (screenHeight / 2) - paused.Height / 2), Color.White);
                    }
                }
            }
            //Game Over
            else if (gameState == GAMEOVER)
            {
                spriteBatch.Draw(gameover, new Vector2(0, 0), Color.White);

                /*spriteBatch.DrawString(scoreFont, "Score: " + displayedScore + "\nBest: " + highScore,
                 *                      new Vector2(screenWidth/2 - 100, screenHeight/2 - 20), Color.Black);*/
                spriteBatch.DrawString(scoreFont, "Score: " + displayedScore, new Vector2(screenWidth / 2 - 100, screenHeight / 3 - 20), Color.Black);
                for (int i = 0; i < 10; i++)
                {
                    spriteBatch.DrawString(scoreFont, (i + 1) + ": " + highscores.score[i], new Vector2(screenWidth / 2 - 100, screenHeight / 3 + +20 + 20 * i), Color.Black);
                }
            }

            spriteBatch.End();
            base.Draw(gameTime);
        }