Example #1
0
        protected override void Draw(GameTime gameTime)
        {
            fpsMonitor.Frame();
            GraphicsDevice.Clear(Color.CornflowerBlue);


            Viewport viewport   = GraphicsDevice.Viewport;
            Int32    viewWidth  = viewport.Width;
            Int32    viewHeight = viewport.Height;



            //
            // Draw edges of the universe
            //
            spriteBatch.Begin();

            // left
            spriteBatch.FillRectangle(
                new Vector2((minX - 5 - cameraX) * pixelsPerDot, (minY - 5 - cameraY) * pixelsPerDot),
                new Vector2(5 * pixelsPerDot, (height + 10) * pixelsPerDot),
                Color.Gray);
            // right
            spriteBatch.FillRectangle(
                new Vector2((maxX - cameraX) * pixelsPerDot, (minY - 5 - cameraY) * pixelsPerDot),
                new Vector2(5 * pixelsPerDot, (height + 10) * pixelsPerDot),
                Color.Gray);
            // top
            spriteBatch.FillRectangle(
                new Vector2((minX - cameraX) * pixelsPerDot, (minY - 5 - cameraY) * pixelsPerDot),
                new Vector2(width * pixelsPerDot, 5 * pixelsPerDot),
                Color.Gray);
            // bottom
            spriteBatch.FillRectangle(
                new Vector2((minX - cameraX) * pixelsPerDot, (maxY - cameraY) * pixelsPerDot),
                new Vector2(width * pixelsPerDot, 5 * pixelsPerDot),
                Color.Gray);
            spriteBatch.End();



            spriteBatch.Begin();

            // draw grid
            Vector2 one, two;

            one.Y = (minY - cameraY) * pixelsPerDot;
            two.Y = (maxY - cameraY) * pixelsPerDot;
            for (int i = (int)minX; i <= (int)maxX; i += gridWidth)
            {
                one.X = (i - cameraX) * pixelsPerDot;
                two.X = (i - cameraX) * pixelsPerDot;
                spriteBatch.DrawLine(one, two, Color.Black);
            }

            one.X = (minX - cameraX) * pixelsPerDot;
            two.X = (maxX - cameraX) * pixelsPerDot;
            for (int i = (int)minY; i <= (int)maxY; i += gridHeight)
            {
                one.Y = (i - cameraY) * pixelsPerDot;
                two.Y = (i - cameraY) * pixelsPerDot;
                spriteBatch.DrawLine(one, two, Color.Black);
            }

            spriteBatch.End();


            spriteBatch.Begin();

            if (pixelsPerDot == 1)
            {
                Vector2 vector;
                for (int i = 0; i < dots.Count; i++)
                {
                    Dot dot = dots[i];
                    vector.X = (dot.x - cameraX) * pixelsPerDot;
                    vector.Y = (dot.y - cameraY) * pixelsPerDot;
                    spriteBatch.Draw(Primitives2D.pixel, vector, Color.White);
                }
            }
            else if (pixelsPerDot > 1)
            {
                Rectangle rectangle;
                for (int i = 0; i < dots.Count; i++)
                {
                    Dot dot = dots[i];
                    rectangle.X      = ((Int32)dot.x - cameraX) * pixelsPerDot;
                    rectangle.Y      = ((Int32)dot.y - cameraY) * pixelsPerDot;
                    rectangle.Width  = pixelsPerDot;
                    rectangle.Height = pixelsPerDot;
                    spriteBatch.FillRectangle(rectangle, Color.White);
                }
            }

            spriteBatch.End();

            spriteBatch.Begin();
            spriteBatch.DrawString(miramonte18Font, String.Format("Camera {0}x{1} FPS {2} UPS {3}", cameraX, cameraY,
                                                                  fpsMonitor.CalculateFps(), updatesPerSecondMonitor.CalculateFps()), new Vector2(0, 0), Color.Black);
            spriteBatch.End();

            base.Draw(gameTime);
        }
Example #2
0
        protected override void Draw(GameTime gameTime)
        {
            //
            // Create Center Translation Matrix
            //
            Int32 viewWidth     = GraphicsDevice.Viewport.Width;
            Int32 viewWidthHalf = viewWidth / 2;

            Int32 viewHeight     = GraphicsDevice.Viewport.Height;
            Int32 viewHeightHalf = viewHeight / 2;

            //Matrix centerTranslationMatrix = Matrix.CreateTranslation(viewWidthHalf, viewHeightHalf, 0);


            fpsMonitor.Frame();

            GraphicsDevice.Clear(backgroundColor);


            //
            // Draw Lines
            //
            spriteBatch.Begin(SpriteSortMode.Deferred, null, null, null, null, null, gameWorldMatrix);
            spriteBatch.DrawLine(-maxWidthOrHeight, 0, maxWidthOrHeight, 0, Color.White); // Horizontal Line
            spriteBatch.DrawLine(0, -maxWidthOrHeight, 0, maxWidthOrHeight, Color.White); // Vertical Line
            spriteBatch.End();


            //
            // Draw Obstacles
            //
            for (int i = 0; i < obstacles.Count; i++)
            {
                Obstacle obstacle = obstacles[i];
                UInt32   stepDistanceToObstacle = obstacleDistances[i];

                obstacle.Draw(spriteBatch, gameWorldMatrix, stepDistanceToObstacle);
            }

            //
            // Draw Player Position
            //

            // Get player angle
            float angle = (float)(playerPosition * 2 * Math.PI) / (float)PlayerPositionRange;

            spriteBatch.Begin(SpriteSortMode.Deferred, null, null, null, null, null,
                              Matrix.CreateTranslation(-playerIconWidth / 2, -85, 0) * Matrix.CreateRotationZ(angle) * gameWorldMatrix);
            spriteBatch.FillRectangle(new Vector2(0, 0), new Vector2(playerIconWidth, 20), Color.White, 0);
            spriteBatch.End();

            /*
             * spriteBatch.GraphicsDevice.FillQuad(
             *  new Vector2(0, 0),
             *  new Vector2(0, 10),
             *  new Vector2(10, 10),
             *  new Vector2(10, 0),
             *  Color.White);
             */
            spriteBatch.GraphicsDevice.FillQuad(
                new Vector2(-.2f, -.2f),
                new Vector2(-.2f, 0),
                new Vector2(0, 0),
                new Vector2(0, -.2f), Matrix.CreateRotationZ(angle),
                Color.White);

            //
            // Draw Debug Messages
            //
            spriteBatch.Begin();
            spriteBatch.DrawString(miramonte18Font, String.Format("FPS {0} PlayerPosition {1,-3} Angle {2} BackColor {3}",
                                                                  fpsMonitor.CalculateFps(), playerPosition, angle, backgroundColor),
                                   new Vector2(10, 20), Color.Black);
            spriteBatch.End();
        }