示例#1
0
    private TileCluster CreateNewClusterFromTile(Tile tile)
    {
        var newCluster = new TileCluster();

        var visitedTiles = new List <Tile>();
        var toExplore    = new Queue <Tile>();

        newCluster.tiles.Add(tile);
        toExplore.Enqueue(tile);

        while (toExplore.Count > 0)
        {
            var current = toExplore.Dequeue();
            foreach (var neighbor in Map.Instance.GetNeighbors(current))
            {
                if (neighbor.type.isWalkable && !visitedTiles.Contains(neighbor))
                {
                    visitedTiles.Add(neighbor);
                    newCluster.tiles.Add(neighbor);
                    toExplore.Enqueue(neighbor);
                }
            }
        }

        return(newCluster);
    }
示例#2
0
	public void activate(TileCluster tc){
		IVector2 pos = new IVector2(this.transform.position.x,this.transform.position.y);
		Map map = GameObject.FindObjectOfType<Map>();
		TileCluster t = tc.copy();
		t.x += pos.x;
		t.y += pos.y;
		map.populateCluster(t);
	}
示例#3
0
	// Use this for initialization
	void Start () {
		towerCluster = new TileCluster();
		towerCluster.x = 1;
		towerCluster.y = 1;
		towerCluster.width = 4;
		towerCluster.height = 0;
		towerCluster.background = true;
		towerCluster.likeliness = 1;
		towerCluster.description = "the tower";
	}
示例#4
0
    public void activate(TileCluster tc)
    {
        IVector2    pos = new IVector2(this.transform.position.x, this.transform.position.y);
        Map         map = GameObject.FindObjectOfType <Map>();
        TileCluster t   = tc.copy();

        t.x += pos.x;
        t.y += pos.y;
        map.populateCluster(t);
    }
示例#5
0
 // Use this for initialization
 void Start()
 {
     towerCluster             = new TileCluster();
     towerCluster.x           = 1;
     towerCluster.y           = 1;
     towerCluster.width       = 4;
     towerCluster.height      = 0;
     towerCluster.background  = true;
     towerCluster.likeliness  = 1;
     towerCluster.description = "the tower";
 }
示例#6
0
 private void UpdateClusterBorder(TileCluster newCluster)
 {
     newCluster.border.Clear();
     foreach (var tile in newCluster.tiles)
     {
         if (IsBorder(tile))
         {
             newCluster.border.Add(tile);
         }
     }
 }
示例#7
0
	public TileCluster copy(){
		TileCluster tc = this;
		TileCluster t = new TileCluster();
		t.background = tc.background;
		t.description = tc.description;
		t.height = tc.height;
		t.likeliness = tc.likeliness;
		t.tileType = tc.tileType;
		t.width = tc.width;
		t.x = tc.x;
		t.y = tc.y;
		return t;
	}
示例#8
0
 public void populateCluster(TileCluster t)
 {
     for (int x = t.x; x < t.x + t.width; x++)
     {
         for (int y = t.y; y < t.y + t.height; y++)
         {
             if (Random.value < t.likeliness)
             {
                 byte layerID = (byte)(t.background?(BACKGROUND_ID):FOREGROUND_ID);
                 setByte(new IVector2(x, y), layerID, ((byte)TileSpecList.getTileSpecInt(t.tileType)));
                 updateTileSpec(new IVector2(x, y));
             }
         }
     }
 }
示例#9
0
    public TileCluster copy()
    {
        TileCluster tc = this;
        TileCluster t  = new TileCluster();

        t.background  = tc.background;
        t.description = tc.description;
        t.height      = tc.height;
        t.likeliness  = tc.likeliness;
        t.tileType    = tc.tileType;
        t.width       = tc.width;
        t.x           = tc.x;
        t.y           = tc.y;
        return(t);
    }
示例#10
0
    public void draw()
    {
        Map         m   = GameObject.FindObjectOfType <Map>();
        IVector2    pos = new IVector2(this.transform.position.x, this.transform.position.y);
        TileCluster t   = towerCluster.copy();

        for (int x = t.x; x < t.x + t.width; x++)
        {
            for (int y = t.y; y < t.y + t.height + 2; y++)
            {
                if (Random.value < t.likeliness)
                {
                    m.setTile(new IVector2(pos.x + x, pos.y + y), (byte)0, (byte)TileSpecList.getTileSpecInt(towerCluster.tileType));
                }
            }
        }
    }
示例#11
0
    public void displayRectList(Map map)
    {
        for (int i = 0; i < map.rects.Count; i++)
        {
            TileCluster currentRect = map.rects[i];

            EditorGUILayout.BeginHorizontal();
            EditorGUIUtility.labelWidth = 20;
            EditorGUILayout.IntField("X", currentRect.x);
            EditorGUIUtility.labelWidth = 20;
            EditorGUILayout.IntField("Y", currentRect.y);
            EditorGUILayout.EndHorizontal();
            EditorGUILayout.BeginHorizontal();
            EditorGUIUtility.labelWidth = 40;
            EditorGUILayout.IntField("Width", currentRect.width);
            EditorGUIUtility.labelWidth = 45;
            EditorGUILayout.IntField("Height", currentRect.height);
            EditorGUILayout.EndHorizontal();
            EditorGUILayout.Space();
        }
    }
示例#12
0
	public void populateCluster(TileCluster t){
		for(int x = t.x; x < t.x + t.width; x++){
			for(int y = t.y; y < t.y + t.height; y++){
				if(Random.value < t.likeliness){
					byte layerID = (byte)(t.background?(BACKGROUND_ID):FOREGROUND_ID);
					setByte(new IVector2(x,y),layerID,((byte)TileSpecList.getTileSpecInt(t.tileType)));
					updateTileSpec(new IVector2(x,y));
				}
			}
		}
	}
示例#13
0
 public void AddToCluster(TileCluster cluster)
 {
     currentCluster = cluster;
 }