Exemple #1
0
		protected void PlaceGrids(int fallbackTheme = TileID.Dirt)
		{
			ushort[] theme = GetTileTheme(fallbackTheme);
			ushort[] wallTheme = GetWallTheme(fallbackTheme);
			for (int t = 5; t >= 0; t--)
			{
				ushort type = Framing.GetTileSafely(StartPositionX, StartPositionY + t).type;
				ushort[] newTheme = GetTileTheme(type);
				if (newTheme != null)
				{
					theme = newTheme;
					wallTheme = GetWallTheme(type);
					break;
				}
			}

			StartPositionY += 3;

			for (int X = 0; X < TileGrid.GetLength(1); X++)
			{
				for (int Y = 0; Y < TileGrid.GetLength(0); Y++)
				{
					int i = StartPositionX + X;
					int j = StartPositionY + Y;
					var tile = Framing.GetTileSafely(i, j);

					if (TileGrid[Y, X] != 0)
					{
						WorldGen.PlaceTile(i,
							j,
							// Need to offset type by 1 since 0 is automatically handled
							theme[TileGrid[Y, X] - 1],
							true,
							true,
							-1,
							0);
					}

					if (WallGrid[Y, X] != 0)
					{
						tile.wall = wallTheme[WallGrid[Y, X] - 1];
					}

					byte slope = SlopeGrid[Y, X];
					if (slope == 5)
					{
						tile.halfBrick(true);
					}
					else
					{
						//tile.halfBrick(false);
						tile.slope(slope);
					}
				}
			}
		}
Exemple #2
0
    public string ToString()
    {
        string str = "Height = " + TileGrid.GetLength(0) + " Width = " + TileGrid.GetLength(1) + "\n";

        for (int row = 0; row < Height; ++row)
        {
            for (int col = 0; col < width; ++col)
            {
                str += this[row, col].Id + " ";
            }
            str += "\n";
        }

        return(str);
    }
    private TileGrid AssembleGrid()
    {
        double sqrt = Math.Sqrt(_tiles.Count);
        int    side = Convert.ToInt32(sqrt);

        if (!sqrt.Equals(side))
        {
            throw new Exception("Tiles cannot be arranged into squares");
        }
        Dictionary <int, List <Tile> > edges = new Dictionary <int, List <Tile> >();

        foreach (Tile tile in _tiles)
        {
            foreach (var edge in tile.Edges)
            {
                int hash = Tile.GetEdgeHash(edge);
                if (edges.ContainsKey(hash))
                {
                    edges[hash].Add(tile);
                }
                else
                {
                    edges[hash] = new List <Tile>()
                    {
                        tile
                    }
                };
            }
        }
        TileGrid grid   = new TileGrid(side, side);
        Tile     corner = _tiles.First(tile => tile.EdgeHashes.Count(hash => edges[hash].Count == 1) == 2);

        grid[0, 0] = corner;
        foreach (Tile rotation in corner.Rotations)
        {
            if (edges[rotation.TopEdgeHash].Count != 1)
            {
                continue;
            }
            if (edges[rotation.LeftEdgeHash].Count != 1)
            {
                continue;
            }
            break;
        }
        _tiles.Remove(corner);
        for (int r = 0; r < grid.GetLength(0); r++)
        {
            for (int c = 0; c < grid.GetLength(1); c++)
            {
                if (grid[r, c] != null)
                {
                    continue;
                }
                foreach (Tile tile in _tiles)
                {
                    bool inserted = grid.InsertAt(r, c, tile);
                    if (inserted)
                    {
                        break;
                    }
                }
                _tiles.Remove(corner);
            }
        }
        return(grid);
    }