Ejemplo n.º 1
0
 void InitializeMap()
 {
     grid = new DungeonTile[width, height];
     for (int i = 0; i < width; ++i)
     {
         for (int j = 0; j < height; ++j)
         {
             int      rndValue = rnd.Next(0, 100);
             TileType t        = rndValue < chanceToStartAlive ? TileType.PATH : TileType.WALL;
             grid[i, j] = new DungeonTile(t, i, j);
         }
     }
 }
Ejemplo n.º 2
0
 public void AddTile(DungeonTile tile)
 {
     tiles.Add(tile);
 }
Ejemplo n.º 3
0
 public bool ContainTile(DungeonTile tile)
 {
     return(tiles.Contains(tile));
 }
Ejemplo n.º 4
0
        void CreateTunnel(Vector2Int p1, Vector2 p2, Cave cave)
        {
            int         steps       = 0;
            int         startX      = p1.x;
            int         startY      = p1.y;
            DungeonTile currentTile = grid[startX, startY];

            while (true)
            {
                ++steps;
                double n      = 1;
                double s      = 1;
                double e      = 1;
                double w      = 1;
                double weigth = 1;
                if (startX < p2.x)
                {
                    e += weigth;
                }
                else if (startX > p2.x)
                {
                    w += weigth;
                }
                else if (startY < p2.y)
                {
                    s += weigth;
                }
                else if (startY > p2.y)
                {
                    n += weigth;
                }

                double total = n + s + e + w;
                n /= total;
                s /= total;
                e /= total;
                w /= total;

                int dx = 0;
                int dy = 0;

                double value = rnd.NextDouble();

                if (0 <= value && value < n)
                {
                    dx = 0;
                    dy = -1;
                }
                else if (n <= value && value <= n + s)
                {
                    dx = 0;
                    dy = 1;
                }
                else if (n + s <= value && value <= n + s + e)
                {
                    dx = 1;
                    dy = 0;
                }
                else
                {
                    dx = -1;
                    dy = 0;
                }
                if (ValidPosition(startX + dx, startY + dy))
                {
                    startX = startX + dx;
                    startY = startY + dy;
                    if (grid[startX, startY].type == TileType.WALL)
                    {
                        grid[startX, startY].SetTileType(TileType.PATH);
                        mainCave.AddTile(grid[startX, startY]);
                    }
                    SetCellType(startX + 1, startY, TileType.PATH);
                    SetCellType(startX + 1, startY + 1, TileType.PATH);
                    if (cave.ContainTile(grid[startX, startY]))
                    {
                        break;
                    }
                }
            }
        }