Ejemplo n.º 1
0
        public PathFinder(Tile[,] map, Vector2 startLocation, Vector2 endLocation)
        {
            InitializeNodes(Game1.map, endLocation);

            this.StartNode = this.Nodes[(int)startLocation.X, (int)startLocation.Y];
            this.StartNode.State = NodeState.Open;

            this.EndNode = this.Nodes[(int)endLocation.X, (int)endLocation.Y];
        }
Ejemplo n.º 2
0
        private void InitializeNodes(Tile[,] map, Vector2 endLocation)
        {
            this.Width = map.GetLength(0);
            this.Height = map.GetLength(1);

            this.Nodes = new PathNode[this.Width, this.Height];
            for (int y = 0; y < this.Height; y++)
            {
                for (int x = 0; x < this.Width; x++)
                {
                    this.Nodes[x, y] = new PathNode(new Vector2(x, y), true, endLocation);
                }
            }
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Allows the game to perform any initialization it needs to before starting to run.
        /// This is where it can query for any required services and load any non-graphic
        /// related content.  Calling base.Initialize will enumerate through any components
        /// and initialize them as well.
        /// </summary>
        protected override void Initialize()
        {
            // TODO: Add your initialization logic here

            base.Initialize();

            this.IsMouseVisible = true;

            // Create the map.
            map = new Tile[MapX, MapY];

            // Create the camera.
            Camera = new Camera();

            // Initialize the camera viewport
            Camera.ViewportWidth = graphics.GraphicsDevice.Viewport.Width;
            Camera.ViewportHeight = graphics.GraphicsDevice.Viewport.Height;

            _RenderTarget = new RenderTarget2D(
                GraphicsDevice,
                MapX * TileSize,
                MapY * TileSize,
                false,
                GraphicsDevice.PresentationParameters.BackBufferFormat,
                DepthFormat.Depth24);

            Camera.CenterOn(new Vector2(100, 100));

            for (int x = 0; x < MapX; x++)
            {
                for (int y = 0; y < MapY; y++)
                {
                    if (y == 1 && x != 0 && x != MapX-1)
                    {
                        map[x, y] = new Tile(x, y, true, 2);
                    }
                    else if (y == 0 || x == 0 || y == MapY-1 || x == MapX-1)
                    {
                        map[x, y] = new Tile(x, y, true, 1);
                    }
                    else
                    {
                        map[x, y] = new Tile(x, y, false, 0);
                    }
                }

                testUnit = new Unit();
                testUnit.Initialize(2, 2);
                testUnit.Move(4, 4);
            }
        }