예제 #1
0
파일: Game1.cs 프로젝트: mkbiltek2019/refer
        protected override void LoadContent()
        {
            // Create a new SpriteBatch, which can be used to draw textures.
            spriteBatch = new SpriteBatch(GraphicsDevice);

            viewport = this.GraphicsDevice.Viewport;
            ball     = Texture2DExtensions.CreateBall(this.GraphicsDevice,
                                                      BALL_RADIUS * BALL_SCALE);

            ballCenter   = new Vector2(ball.Width / 2, ball.Height / 2);
            ballPosition = new Vector2(viewport.Width / 2, viewport.Height / 2);
        }
예제 #2
0
파일: Game1.cs 프로젝트: mkbiltek2019/refer
        protected override void LoadContent()
        {
            // Create a new SpriteBatch, which can be used to draw textures.
            spriteBatch = new SpriteBatch(GraphicsDevice);

            viewport     = this.GraphicsDevice.Viewport;
            screenCenter = new Vector2(viewport.Width / 2, viewport.Height / 2);

            ball = Texture2DExtensions.CreateBall(this.GraphicsDevice,
                                                  BALL_RADIUS * BALL_SCALE);

            ballCenter   = new Vector2(ball.Width / 2, ball.Height / 2);
            ballPosition = screenCenter;

            tinyTexture = new Texture2D(this.GraphicsDevice, 1, 1);
            tinyTexture.SetData <Color>(new Color[] { Color.White });

            segoe96 = this.Content.Load <SpriteFont>("Segoe96");
        }
예제 #3
0
파일: Game1.cs 프로젝트: mkbiltek2019/refer
        protected override void LoadContent()
        {
            // Create a new SpriteBatch, which can be used to draw textures.
            spriteBatch = new SpriteBatch(GraphicsDevice);

            viewport = this.GraphicsDevice.Viewport;

            // Create texture for the walls of the maze
            tinyTexture = new Texture2D(this.GraphicsDevice, 1, 1);
            tinyTexture.SetData <Color>(new Color[] { Color.White });

            // Create ball
            ball = Texture2DExtensions.CreateBall(this.GraphicsDevice,
                                                  BALL_RADIUS * BALL_SCALE);

            ballCenter   = new Vector2(ball.Width / 2, ball.Height / 2);
            ballPosition = new Vector2((viewport.Width / mazeGrid.Width) / 2,
                                       (viewport.Height / mazeGrid.Height) / 2);

            // Initialize borders collection
            borders.Clear();

            // Create Line2D objects for walls of the maze
            int cellWidth     = viewport.Width / mazeGrid.Width;
            int cellHeight    = viewport.Height / mazeGrid.Height;
            int halfWallWidth = WALL_WIDTH / 2;

            for (int x = 0; x < mazeGrid.Width; x++)
            {
                for (int y = 0; y < mazeGrid.Height; y++)
                {
                    MazeCell mazeCell = mazeGrid.Cells[x, y];
                    Vector2  ll       = new Vector2(x * cellWidth, (y + 1) * cellHeight);
                    Vector2  ul       = new Vector2(x * cellWidth, y * cellHeight);
                    Vector2  ur       = new Vector2((x + 1) * cellWidth, y * cellHeight);
                    Vector2  lr       = new Vector2((x + 1) * cellWidth, (y + 1) * cellHeight);
                    Vector2  right    = halfWallWidth * Vector2.UnitX;
                    Vector2  left     = -right;
                    Vector2  down     = halfWallWidth * Vector2.UnitY;
                    Vector2  up       = -down;

                    if (mazeCell.HasLeft)
                    {
                        borders.Add(new Line2D(ll + down, ll + down + right));
                        borders.Add(new Line2D(ll + down + right, ul + up + right));
                        borders.Add(new Line2D(ul + up + right, ul + up));
                    }
                    if (mazeCell.HasTop)
                    {
                        borders.Add(new Line2D(ul + left, ul + left + down));
                        borders.Add(new Line2D(ul + left + down, ur + right + down));
                        borders.Add(new Line2D(ur + right + down, ur + right));
                    }
                    if (mazeCell.HasRight)
                    {
                        borders.Add(new Line2D(ur + up, ur + up + left));
                        borders.Add(new Line2D(ur + up + left, lr + down + left));
                        borders.Add(new Line2D(lr + down + left, lr + down));
                    }
                    if (mazeCell.HasBottom)
                    {
                        borders.Add(new Line2D(lr + right, lr + right + up));
                        borders.Add(new Line2D(lr + right + up, ll + left + up));
                        borders.Add(new Line2D(ll + left + up, ll + left));
                    }
                }
            }
        }