Пример #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)
        {
            GraphicsDevice.Clear(Color.CornflowerBlue);

            base.Draw(gameTime);

            // Calculate and apply the world/view transform
            var offset = new Vector2(GraphicsDevice.Viewport.Width / 2, GraphicsDevice.Viewport.Height / 2) - player.Position;
            var t      = Matrix.CreateTranslation(offset.X, offset.Y, 0);

            spriteBatch.Begin(SpriteSortMode.Deferred, null, null, null, null, null, t);

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

            // Draw the platforms
            var platformQuery = platformAxis.QueryRange(player.Position.X - GraphicsDevice.Viewport.Width / 2, player.Position.X + GraphicsDevice.Viewport.Width / 2);

            foreach (Platform platform in platformQuery)
            {
                platform.Draw(spriteBatch);
            }
            Debug.WriteLine($"{platformQuery.Count()} Platforms rendered");

            var tokenQuery = tokenAxis.QueryRange(player.Position.X - GraphicsDevice.Viewport.Width / 2, player.Position.X + GraphicsDevice.Viewport.Width / 2);

            foreach (Token token in tokenQuery)
            {
                token.Draw(spriteBatch);
            }

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

            //Draw score
            Vector2 location = new Vector2(GraphicsDevice.Viewport.Width / 2 + player.Position.X, player.Position.Y - GraphicsDevice.Viewport.Height / 2);

            gameText.DrawScore(spriteBatch, "Score: " + score.ToString(), location);

            //Draw start game message if the beginning of the game
            if (state == GameState.Start)
            {
                gameText.Draw(spriteBatch, "Press Enter To Begin", player.Position);
            }

            //If game is over draw the end game and begin game message
            if (state == GameState.End)
            {
                gameText.Draw(spriteBatch, "Press Enter To Begin", player.Position);

                gameText.Draw(spriteBatch, "Game Over!", new Vector2(player.Position.X, player.Position.Y + GraphicsDevice.Viewport.Height / 4));

                playerDeathParticles.Draw(t);
            }

            spriteBatch.End();
        }
Пример #2
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)
        {
            GraphicsDevice.Clear(Color.CornflowerBlue);

            // TODO: Add your drawing code here
            var offset = new Vector2(GraphicsDevice.Viewport.Width / 2, GraphicsDevice.Viewport.Height / 2) - player.Position;
            var t      = Matrix.CreateTranslation(offset.X, offset.Y, 0);

            spriteBatch.Begin(SpriteSortMode.Deferred, null, null, null, null, null, t);

            // Draw the platforms
            platforms.ForEach(platform =>
            {
                platform.Draw(spriteBatch);
            });

            // Draw the tokens
            tokens.ForEach(token =>
            {
                token.Draw(spriteBatch);
            });

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

            Vector2 location = new Vector2(GraphicsDevice.Viewport.Width / 2 + player.Position.X, player.Position.Y - GraphicsDevice.Viewport.Height / 2);

            gameText.DrawScore(spriteBatch, "Score: " + score.ToString(), location);

            if (state == GameState.Start)
            {
                gameText.Draw(spriteBatch, "Press Enter To Begin", player.Position);
            }

            //Draw lava at bottom
            lava.Draw(spriteBatch, player.Position.X - GraphicsDevice.Viewport.Width / 2, player.Position.X + GraphicsDevice.Viewport.Width / 2, player.Position.Y + GraphicsDevice.Viewport.Height / 2);

            //If game is over draw the end game and begin game message
            if (state == GameState.End)
            {
                gameText.Draw(spriteBatch, "Press Enter To Begin", player.Position);

                gameText.Draw(spriteBatch, "Game Over!", new Vector2(player.Position.X, player.Position.Y + GraphicsDevice.Viewport.Height / 4));
            }

            spriteBatch.End();

            base.Draw(gameTime);
        }