private void ResolveNeighbors(Vector2D offset) { for (int x = 0; x < Width; x++) { for (int y = 0; y < Height; y++) { if (!TileMap[x, y].Initialized && TileMap[x, y].Enabled && TileMap[x, y].TileMapOffset == offset) { RoomTileRaw tile = TileMap[x, y]; byte primaryNeighbors = (byte)( ((this[x, y + 1].CanBlend(tile) ? 1 : 0) << 3) + ((this[x + 1, y].CanBlend(tile) ? 1 : 0) << 2) + ((this[x, y - 1].CanBlend(tile) ? 1 : 0) << 1) + ((this[x - 1, y].CanBlend(tile) ? 1 : 0))); byte secondaryNeighbors = (byte)( ((this[x - 1, y + 1].CanBlend(tile) ? 1 : 0) << 3) + ((this[x + 1, y + 1].CanBlend(tile) ? 1 : 0) << 2) + ((this[x + 1, y - 1].CanBlend(tile) ? 1 : 0) << 1) + ((this[x - 1, y - 1].CanBlend(tile) ? 1 : 0))); tile.Neighbors = (byte)(primaryNeighbors + (secondaryNeighbors << 4)); tile.Initialized = true; TileMap[x, y] = tile; } } } }
public void Fill(Rectangle rectangle, RoomTileRaw tileInfo) { for (int x = (int)rectangle.X; x < rectangle.X + rectangle.Width; x++) { for (int y = (int)rectangle.Y; y < rectangle.Y + rectangle.Height; y++) { Set(x, y, tileInfo); } } }
private RoomTileRaw this[int x, int y] => (x >= 0 && y >= 0 && x < Width && y < Height) ? TileMap[x, y] : RoomTileRaw.CreateOutOfBounds();
public void Set(int x, int y, RoomTileRaw tileInfo) { TileMap[x, y] = tileInfo; }
public bool CanBlend(RoomTileRaw other) { return((this.Enabled && other.Enabled) && (this.OutOfBounds || other.OutOfBounds || this.TileMapOffset == other.TileMapOffset)); }