コード例 #1
0
ファイル: Map.cs プロジェクト: Thinny-Hendrix/MoonCow
        public Map(Game1 game, int[,] newMap)
        {
            mapSize = new Vector2(newMap.GetLength(0), newMap.GetLength(1));
            map = new MapNode[(int)mapSize.X, (int)mapSize.Y];

            //Generate array of mapNodes from int array
            //As each node is created, it's position and traversable values must be set
            //The model data will also need to bet set for each node here

            for(int y = 0; y < mapSize.Y; y++)
            {
                for (int x = 0; x < mapSize.X; x++)
                {
                    map[x, y] = new MapNode(game, newMap[x, y], new Vector2(x,y));

                    //add enemy spawn points to a list for easy access
                    if(newMap[x,y] == 7 || newMap[x,y] == 8 ||
                        newMap[x, y] == 9 || newMap[x, y] == 10)
                    {
                        enemySpawn.Add(new Vector2(x, y));
                    }

                    if (newMap[x, y] == 24)
                    {
                        coreLocation = new Vector2(x, y);
                    }
                }
            }

            linkNeighbors();
            game.asteroidManager.generateField();
            game.hud.hudMap.minimap.drawMap(map);
        }
コード例 #2
0
ファイル: Pathfinder.cs プロジェクト: Thinny-Hendrix/MoonCow
        /// <summary>
        /// Use the parent field of the search nodes to trace a path from the end node to the start node.
        /// </summary>
        protected List<Vector2> findFinalPath(MapNode startNode, MapNode endNode)
        {
            closedList.Add(endNode);
            MapNode parentTile = endNode.parent;

            // Trace back through the nodes using the parent fields to find the best path.
            while (parentTile != startNode)
            {
                closedList.Add(parentTile);
                parentTile = parentTile.parent;
            }

            List<Vector2> finalPath = new List<Vector2>();

            // Reverse the path and transform into world space.
            for (int i = closedList.Count - 1; i >= 0; i--)
            {
                finalPath.Add(new Vector2(closedList[i].position.X, closedList[i].position.Y));
            }
            return finalPath; //Yay!
        }
コード例 #3
0
 public void addPos(MapNode pos)
 {
     astNodes.Add(pos);
 }