Esempio n. 1
0
        protected override void Draw(GameTime gameTime)
        {
            GraphicsDevice.Clear(Color.Black);

            spriteBatch.Begin();

            starsFront.Draw(spriteBatch);
            starsBack.Draw(spriteBatch);

            if (!gameStarted)
            {
                String title      = "Star    Shooter";
                String pressSpace = "Press Space to start";

                // Measure the size of text in the given font
                Vector2 titleSize      = stateFont.MeasureString(title);
                Vector2 pressSpaceSize = scoreFont.MeasureString(pressSpace);

                // Draw the text horizontally centered
                spriteBatch.DrawString(stateFont, title, new Vector2(screenWidth / 2 - titleSize.X / 2, screenHeight / 3), Color.Fuchsia);
                spriteBatch.DrawString(scoreFont, pressSpace, new Vector2(screenWidth / 2 - pressSpaceSize.X / 2, screenHeight / 2), Color.White * ((float)alpha / 255));
            }
            else
            {
                lives.Draw(spriteBatch, screenWidth);
                swarm.Draw(spriteBatch);
                ship.Draw(spriteBatch, alpha, shipDirection);

                var     scoreString = ((int)score).ToString("d5");
                Vector2 scoreSize   = scoreFont.MeasureString(scoreString);

                spriteBatch.DrawString(scoreFont, scoreString, new Vector2(10, 10), Color.White);
            }

            if (paused)
            {
                String title      = "Paused";
                String pressSpace = "Press Space to resume";

                // Measure the size of text in the given font
                Vector2 titleSize      = stateFontMedium.MeasureString(title);
                Vector2 pressSpaceSize = scoreFont.MeasureString(pressSpace);

                // Draw the text horizontally centered
                spriteBatch.DrawString(stateFontMedium, title, new Vector2(screenWidth / 2 - titleSize.X / 2, screenHeight / 3), Color.Fuchsia);
                spriteBatch.DrawString(scoreFont, pressSpace, new Vector2(screenWidth / 2 - pressSpaceSize.X / 2, screenHeight / 2), Color.White * ((float)alpha / 255));
            }

            if (gameOver)
            {
                // Draw game over texture
                spriteBatch.Draw(gameOverTexture, new Vector2(screenWidth / 2 - gameOverTexture.Width / 2, screenHeight / 4 - gameOverTexture.Width / 2), Color.White);
                String pressEnter = "Press Enter to restart!";
                String yourScore  = $"Your score: {score.ToString("d5")}";
                // Measure the size of text in the given font
                Vector2 pressEnterSize = scoreFont.MeasureString(pressEnter);
                Vector2 yourScoreSize  = scoreFont.MeasureString(yourScore);
                // Draw the text horizontally centered
                spriteBatch.DrawString(scoreFont, pressEnter, new Vector2(screenWidth / 2 - pressEnterSize.X / 2, screenHeight - 200), Color.White * ((float)alpha / 255));
                spriteBatch.DrawString(scoreFont, yourScore, new Vector2(screenWidth / 2 - yourScoreSize.X / 2, screenHeight - 500), Color.White);
            }

            spriteBatch.End();
            // TODO: Add your drawing code here

            base.Draw(gameTime);
        }
Esempio n. 2
0
        protected override void Draw(GameTime gameTime)
        {
            GraphicsDevice.Clear(Color.Black);
            var gamePad = Input.IsGamePadConnected();

            spriteBatch.Begin();

            starsFront.Draw(spriteBatch);
            starsBack.Draw(spriteBatch);

            if (!gameStarted)
            {
                string title          = "Star    Shooter";
                string gamePadA       = Input.IsGamePadConnected() ? " (A)" : string.Empty;
                string pressSpace     = $"Press Space{gamePadA} to start";
                string leftThumbstick = Input.IsGamePadConnected() ? " or the left thumbstick" : string.Empty;
                string instructions   = $"Use 'W', 'A', 'S' and 'D'{leftThumbstick} to move the ship";

                // Measure the size of text in the given font
                Vector2 titleSize        = Art.StateFont.MeasureString(title);
                Vector2 pressSpaceSize   = Art.ScoreFont.MeasureString(pressSpace);
                Vector2 instructionsSize = Art.ScoreFontSmall.MeasureString(instructions);

                // Draw the text horizontally centered
                spriteBatch.DrawString(Art.StateFont, title, new Vector2(screenWidth / 2 - titleSize.X / 2, screenHeight / 3), Color.Fuchsia);
                spriteBatch.DrawString(Art.ScoreFont, pressSpace, new Vector2(screenWidth / 2 - pressSpaceSize.X / 2, screenHeight / 2), Color.White * ((float)alpha / 255));
                spriteBatch.DrawString(Art.ScoreFontSmall, instructions, new Vector2(screenWidth / 2 - instructionsSize.X / 2, screenHeight / 1.2f), Color.White);
            }
            else
            {
                lives.Draw(spriteBatch, screenWidth);
                swarm.Draw(spriteBatch);
                ship.Draw(spriteBatch, alpha);

                ParticleManager.Draw(spriteBatch);

                var     scoreString = ((int)score).ToString("d5");
                Vector2 scoreSize   = Art.ScoreFont.MeasureString(scoreString);

                spriteBatch.DrawString(Art.ScoreFont, scoreString, new Vector2(10, 10), Color.White);
            }

            if (paused)
            {
                string title          = "Paused";
                string gamePadA       = Input.IsGamePadConnected() ? " (A)" : string.Empty;
                string pressSpace     = $"Press Space{gamePadA} to resume";
                string leftThumbstick = Input.IsGamePadConnected() ? " or the left thumbstick" : string.Empty;
                string instructions   = $"Use 'W', 'A', 'S' and 'D'{leftThumbstick} to move the ship";

                // Measure the size of text in the given font
                Vector2 titleSize        = Art.StateFontMedium.MeasureString(title);
                Vector2 pressSpaceSize   = Art.ScoreFont.MeasureString(pressSpace);
                Vector2 instructionsSize = Art.ScoreFontSmall.MeasureString(instructions);

                // Draw the text horizontally centered
                spriteBatch.DrawString(Art.StateFontMedium, title, new Vector2(screenWidth / 2 - titleSize.X / 2, screenHeight / 3), Color.Fuchsia);
                spriteBatch.DrawString(Art.ScoreFont, pressSpace, new Vector2(screenWidth / 2 - pressSpaceSize.X / 2, screenHeight / 2), Color.White * ((float)alpha / 255));
                spriteBatch.DrawString(Art.ScoreFontSmall, instructions, new Vector2(screenWidth / 2 - instructionsSize.X / 2, screenHeight / 1.2f), Color.White);
            }

            if (gameOver)
            {
                // Draw game over texture
                spriteBatch.Draw(Art.GameOver, new Vector2(screenWidth / 2 - Art.GameOver.Width / 2, screenHeight / 4 - Art.GameOver.Width / 2), Color.White);
                string gamePadStart = Input.IsGamePadConnected() ? " (start)" : string.Empty;
                String pressEnter   = $"Press Enter{gamePadStart} to restart!";
                String yourScore    = $"Your score: {score.ToString("d5")}";
                // Measure the size of text in the given font
                Vector2 pressEnterSize = Art.ScoreFont.MeasureString(pressEnter);
                Vector2 yourScoreSize  = Art.ScoreFont.MeasureString(yourScore);
                // Draw the text horizontally centered
                spriteBatch.DrawString(Art.ScoreFont, pressEnter, new Vector2(screenWidth / 2 - pressEnterSize.X / 2, screenHeight - 200), Color.White * ((float)alpha / 255));
                spriteBatch.DrawString(Art.ScoreFont, yourScore, new Vector2(screenWidth / 2 - yourScoreSize.X / 2, screenHeight - 500), Color.White);
            }

            spriteBatch.End();
            // TODO: Add your drawing code here

            base.Draw(gameTime);
        }