コード例 #1
0
        /// <summary>
        /// Draws the background screen.
        /// </summary>
        public override void Draw(GameTime gameTime)
        {
            SpriteBatch spriteBatch = ScreenManager.SpriteBatch;

            starField.Draw(spriteBatch);
            asteroidManager.Draw(spriteBatch);
        }
コード例 #2
0
ファイル: Game1.cs プロジェクト: russperlow/Asteroids
        /// <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)
        {
            GraphicsDevice.Clear(Color.CornflowerBlue);

            // TODO: Add your drawing code here
            spriteBatch.Begin();
            spriteBatch.Draw(background, new Rectangle(0, 0, GraphicsDevice.Viewport.Width, GraphicsDevice.Viewport.Height), Color.White);

            switch (currState)
            {
            case GameStates.MainMenu:
                spriteBatch.DrawString(font, "Press Space to Play Game", new Vector2((GraphicsDevice.Viewport.Width / 2) - (font.MeasureString("Press Space to Play Game").Length() / 2), GraphicsDevice.Viewport.Height / 2), Color.White);
                break;

            case GameStates.GamePlaying:
                bm.Draw(spriteBatch);
                am.Draw(spriteBatch);
                ship.Draw(spriteBatch);
                break;

            case GameStates.GameOver:
                spriteBatch.DrawString(font, "Game Over! Final Score: " + ship.Score + "\nPress Space to Continue", new Vector2((GraphicsDevice.Viewport.Width / 2) - (font.MeasureString("Game Over! Final Score: " + ship.Score).Length() / 2), GraphicsDevice.Viewport.Height / 2), Color.White);
                break;
            }
            spriteBatch.End();
            base.Draw(gameTime);
        }
コード例 #3
0
        /// <summary>
        /// Draws the gameplay screen.
        /// </summary>
        public override void Draw(GameTime gameTime)
        {
            ScreenManager.GraphicsDevice.Clear(ClearOptions.Target, Color.Black, 0, 0);

            SpriteBatch spriteBatch = ScreenManager.SpriteBatch;

            // Draw the starfield
            starField.Draw(spriteBatch);

            // Render Players
            if (networkSession == null)
            {
                players.ForEach(delegate(Player p)
                {
                    p.Draw(spriteBatch);
                });
            }
            else
            {
                foreach (NetworkGamer gamer in networkSession.AllGamers)
                {
                    Player p = gamer.Tag as Player;
                    p.Draw(spriteBatch);
                }
            }

            // Render Asteroids
            asteroidManager.Draw(spriteBatch);

            // If the game is transitioning on or off, fade it out to black.
            if (TransitionPosition > 0 || pauseAlpha > 0)
            {
                float alpha = MathHelper.Lerp(1f - TransitionAlpha, 1f, pauseAlpha / 2);

                ScreenManager.FadeBackBufferToBlack(alpha);
            }
        }