public PathfindAStar(MapBuilder map)
        {
            levelWidth = map.Width;
            levelHeight = map.Height;

            InitializeSearchNodes(map);
        }
        protected override void LoadContent()
        {
            Random rnd = new Random();

            vertexDeclaration = new VertexDeclaration(new VertexElement[]
                {
                    new VertexElement(0, VertexElementFormat.Vector3, VertexElementUsage.Position, 0),
                    new VertexElement(12, VertexElementFormat.Vector3, VertexElementUsage.Normal, 0),
                    new VertexElement(24, VertexElementFormat.Vector2, VertexElementUsage.TextureCoordinate, 0)
                }
            );

            models.Add(new Ground(
                Game.Content.Load<Model>(@"Models/Ground/Ground")));

            models.Add(new Pickup(
                Game.Content.Load<Model>(@"Models/Battery/BatteryModel"),
                new Vector3(rnd.Next(MapBuilder.MINX, MapBuilder.MAXX), 30, rnd.Next(MapBuilder.MINY, MapBuilder.MAXY))));

            models.Add(new Pickup(
                Game.Content.Load<Model>(@"Models/Battery/BatteryModel"),
                new Vector3(rnd.Next(MapBuilder.MINX, MapBuilder.MAXX), 30, rnd.Next(MapBuilder.MINY, MapBuilder.MAXY))));

            ///
            /// Build a map using tiles
            ///
            if (!bBuiltMap) {

                mapBuilder = new MapBuilder(this.game);
                models.AddRange(mapBuilder.Render());

                bBuiltMap = true;
            }

            // need to keep hold of the players model
            playerModel = new Player(
                  Game.Content.Load<Model>(@"Models/Vehicles/PlayerCarModel"),
                  ((Game1)Game).GraphicsDevice,
                  ((Game1)Game).camera,
                  (Game1)game);
            models.Add(playerModel);

            Enemy enemy = new Enemy(
                Game.Content.Load<Model>(@"Models/Vehicles/BuggyFullHP"),
                ((Game1)Game).GraphicsDevice,
                ((Game1)Game).camera,
                new Vector3(rnd.Next(MapBuilder.MINX, MapBuilder.MAXX), 0, MapBuilder.MAXY),
                playerModel,
                (Game1)game);
            models.Add(enemy);

            /*
            MonsterTruck enemyTruck = new MonsterTruck(
                Game.Content.Load<Model>(@"Models/Vehicles/MonsterTruckFull"),
                ((Game1)Game).GraphicsDevice,
                ((Game1)Game).camera,
                new Vector3(rnd.Next(MapBuilder.MINX, MapBuilder.MAXX), 0, MapBuilder.MAXY),
                playerModel,
                uiManager);
            models.Add(enemyTruck);
            */

            base.LoadContent();
        }
        private void InitializeSearchNodes(MapBuilder map)
        {
            searchNodes = new NodeRecord[levelWidth, levelHeight];

            for (int x = 0; x < levelWidth; x++) {
                for (int y = 0; y < levelHeight; y++) {
                    NodeRecord node = new NodeRecord();
                    node.position = new Point(x, y);

                    node.movable = map.GetIndex(y, x) == 0;

                    if (node.movable == true) {
                        node.connections = new NodeRecord[4];
                        searchNodes[x, y] = node;
                    }
                }
            }

            for (int x = 0; x < levelWidth; x++) {
                for (int y = 0; y < levelHeight; y++) {
                    NodeRecord node = searchNodes[x, y];

                    if (node == null || node.movable == false) {
                        continue;
                    }

                    // implement diagonal in assignment...
                    Point[] connections = new Point[]
                    {
                        new Point (x, y - 1), // up
                        new Point (x, y + 1), // down
                        new Point (x - 1, y), // left
                        new Point (x + 1, y), // right
                    };

                    // loop through connections
                    for (int i = 0; i < connections.Length; i++) {
                        Point position = connections[i];

                        if (position.X < 0 || position.X > levelWidth - 1 ||
                            position.Y < 0 || position.Y > levelHeight - 1) {
                            continue;
                        }

                        NodeRecord connection = searchNodes[position.X, position.Y];

                        if (connection == null || connection.movable == false) {
                            continue;
                        }

                        node.connections[i] = connection;
                    }
                }
            }
        }