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); }
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); }
// 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"; }
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); }
// 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"; }
private void UpdateClusterBorder(TileCluster newCluster) { newCluster.border.Clear(); foreach (var tile in newCluster.tiles) { if (IsBorder(tile)) { newCluster.border.Add(tile); } } }
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; }
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)); } } } }
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); }
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)); } } } }
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(); } }
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)); } } } }
public void AddToCluster(TileCluster cluster) { currentCluster = cluster; }