private void SpawnRemainingTiles(List <Tile> activeTiles) { int currentIndex = activeTiles.Count - 1; Tile currentTile = activeTiles[currentIndex]; if (currentTile.IsInitialized) { activeTiles.RemoveAt(currentIndex); return; } Enums.CardinalDirection direction = currentTile.GetRandomUnintializedDirection(); MapVector2 newTilePosition = currentTile.TilePosition + direction.ToMapVector2(); if (this.IsValidCoordinate(newTilePosition)) { Tile neighbor = GetTile(newTilePosition); if (neighbor == null) { neighbor = CreateTile(newTilePosition); BuildConnector(currentTile, neighbor, direction); activeTiles.Add(neighbor); } else { BuildWall(currentTile, neighbor, direction); } } else { BuildWall(currentTile, null, direction); } }
//Enums.CardinalDirection direction; public void InitializeEdge(Tile thisTile, Tile otherTile, Enums.CardinalDirection direction) { this.thisTile = thisTile; this.otherTile = otherTile; //this.direction = direction; thisTile.SetEdge(direction, this); this.transform.parent = thisTile.transform; this.name = "Edge " + direction.ToString(); switch (direction) { case Enums.CardinalDirection.North: this.transform.localPosition = new Vector3(0f, 1f, 75f); break; case Enums.CardinalDirection.East: this.transform.localPosition = new Vector3(75f, 1f, 75f); break; case Enums.CardinalDirection.South: this.transform.localPosition = new Vector3(75f, 1f, 0f); break; case Enums.CardinalDirection.West: this.transform.localPosition = new Vector3(0f, 1f, 0f); break; default: break; } this.transform.localRotation = direction.ToRotation(); }
private void BuildConnector(Tile tile1, Tile tile2, Enums.CardinalDirection direction) { TileEdge connector = Instantiate(Resources.Load <GameObject>("Blocks/Connector")).GetComponent <TileEdge>(); connector.InitializeEdge(tile1, tile2, direction); connector = Instantiate(Resources.Load <GameObject>("Blocks/Connector")).GetComponent <TileEdge>(); connector.InitializeEdge(tile2, tile1, direction.GetOpposite()); }
private void BuildWall(Tile tile1, Tile tile2, Enums.CardinalDirection direction) { TileEdge wall = Instantiate(Resources.Load <GameObject>("Blocks/Wall")).GetComponent <TileEdge>(); wall.InitializeEdge(tile1, tile2, direction); if (tile2 != null) { wall = Instantiate(Resources.Load <GameObject>("Blocks/Wall")).GetComponent <TileEdge>(); wall.InitializeEdge(tile2, tile1, direction.GetOpposite()); } }
public static Quaternion ToRotation(this CardinalDirection direction) { return(cardinalRotations[(int)direction]); }
public static CardinalDirection GetOpposite(this CardinalDirection direction) { return(cardinalOpposites[(int)direction]); }
public static MapVector2 ToMapVector2(this CardinalDirection direction) { return(directionVectors[(int)direction]); }
public void SetEdge(Enums.CardinalDirection direction, TileEdge edge) { this.edges[(int)direction] = edge; this.initializedEdgeCount += 1; }
public TileEdge GetEdge(Enums.CardinalDirection direction) { return(this.edges[(int)direction]); }