예제 #1
0
    // 更新房间边缘瓦片集
    public void UpdateEdgeTiles(TileType[,] map)
    {
        edgeTiles.Clear();

        // 遍历上下左右四格,判断是否有墙
        foreach (CaveCoord tile in tiles)
        {
            for (int i = 0; i < 4; i++)
            {
                int x = tile.tileX + GameMathf.UpDownLeftRight[i, 0];
                int y = tile.tileY + GameMathf.UpDownLeftRight[i, 1];
                if (GameMathf.XYIsInRange(x, y, map.GetLength(0), map.GetLength(1)) && map[x, y] == TileType.Wall)
                {
                    edgeTiles.Add(tile);
                    continue;
                }
            }
        }
    }
예제 #2
0
    //获取该点周围8个点为实体墙(map[x,y] == TileType.Wall)的个数。
    private int GetSurroundingWallCount(int gridX, int gridY)
    {
        int wallCount = 0;

        for (int neighbourX = gridX - 1; neighbourX <= gridX + 1; neighbourX++)
        {
            for (int neighbourY = gridY - 1; neighbourY <= gridY + 1; neighbourY++)
            {
                if (!GameMathf.XYIsInRange(neighbourX, neighbourY, width, height))  // 如果不在地图范围内,直接假定为墙
                {
                    wallCount++;
                }
                else if (!(neighbourX == gridX && neighbourY == gridY))     // 在范围内,且不是本身的点
                {
                    wallCount += map[neighbourX, neighbourY] == TileType.Wall ? 1 : 0;
                }
            }
        }

        return(wallCount);
    }