TileData NextTile() { // Empty list for valid tiles to spawn next List <TileData> validTiles = new List <TileData>(); // Empty TileData object TileData nextTile; // Initiate variable that will tell us which data object to look at for our next tile choice TileData.Direction nextDirection = TileData.Direction.North; // Loop through each to match the exit direction of the previous tile to teh appropriate TileData list switch (previousTile.exitDirection) { case TileData.Direction.North: nextDirection = TileData.Direction.South; spawnPoint = spawnPoint + new Vector3(0, 0, previousTile.tileSize.y); break; case TileData.Direction.East: nextDirection = TileData.Direction.West; spawnPoint = spawnPoint + new Vector3(previousTile.tileSize.x, 0, 0); break; case TileData.Direction.South: nextDirection = TileData.Direction.North; spawnPoint = spawnPoint + new Vector3(0, 0, -previousTile.tileSize.y); break; case TileData.Direction.West: nextDirection = TileData.Direction.East; spawnPoint = spawnPoint + new Vector3(-previousTile.tileSize.x, 0, 0); break; default: break; } // Loop through all our data object arrays for (int i = 0; i < tileData.Length; i++) { // Add our array if available tiles to the list we can pool from if exit and entry directions match if (tileData[i].entryDirection == nextDirection) { validTiles.Add(tileData[i]); } } // Pick a random tile from our list to be the next tile nextTile = validTiles[Random.Range(0, validTiles.Count)]; return(nextTile); }
public static Sprite decideSprite(TileData.Direction start, TileData.Direction end) // hardcoded { Sprite sprite = null; if (start == TileData.Direction.UP) { switch (end) { case TileData.Direction.UNSET: case TileData.Direction.DOWN: sprite = TSprites.vertTile; break; case TileData.Direction.LEFT: sprite = TSprites.ULTile; break; case TileData.Direction.RIGHT: sprite = TSprites.URTile; break; } } else if (start == TileData.Direction.DOWN) { switch (end) { case TileData.Direction.UNSET: case TileData.Direction.UP: sprite = TSprites.vertTile; break; case TileData.Direction.LEFT: sprite = TSprites.DLTile; break; case TileData.Direction.RIGHT: sprite = TSprites.DRTile; break; } } else if (start == TileData.Direction.LEFT) { switch (end) { case TileData.Direction.UP: sprite = TSprites.ULTile; break; case TileData.Direction.DOWN: sprite = TSprites.DLTile; break; case TileData.Direction.UNSET: case TileData.Direction.RIGHT: sprite = TSprites.horiTile; break; } } else if (start == TileData.Direction.RIGHT) { switch (end) { case TileData.Direction.UP: sprite = TSprites.URTile; break; case TileData.Direction.DOWN: sprite = TSprites.DRTile; break; case TileData.Direction.UNSET: case TileData.Direction.LEFT: sprite = TSprites.horiTile; break; } } return(sprite); }