private void ResolveNeighbors(Vector2D tilesetOffset) { 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 == tilesetOffset) { 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 override void Update() { foreach (RoomBuilder rb in WatchedComponents) { if (rb.Build && (rb.Width != rb.Map.GetLength(0) || rb.Height != rb.Map.GetLength(1))) { rb.Refresh = true; } if (rb.Refresh) { bool[,] old = rb.Map; rb.Map = new bool[rb.Width, rb.Height]; for (int i = 0; i < Math.Min(old.GetLength(0), rb.Width); i++) { for (int j = 0; j < Math.Min(old.GetLength(1), rb.Height); j++) { rb.Map[i, j] = old[i, j]; } } rb.Refresh = false; } if (rb.Build) { Width = rb.Width; Height = rb.Height; TileMap = new RoomTileRaw[Width, Height]; for (int i = 0; i < Width; i++) { for (int j = 0; j < Height; j++) { TileMap[i, j] = new RoomTileRaw(rb.Map[i, j]); } } Current = rb; Random = new Random(rb.RandomSeed); ResolveNeighbors(); if (rb.OutputSprites) { List <Sprite> sprites = BuildSprites(); Renderable renderable = rb.Owner.Components.Get <Renderable>(); if (renderable == null) { return; } if (rb.Overwrite) { renderable.Sprites = sprites; } else { renderable.Sprites.AddRange(sprites); } } rb.Build = false; } } }
public bool CanBlend(RoomTileRaw other) { return((this.Enabled && other.Enabled) && (this.OutOfBounds || other.OutOfBounds || this.TileMapOffset == other.TileMapOffset)); }
private RoomTileRaw this[int x, int y] => (x >= 0 && y >= 0 && x < Width && y < Height) ? TileMap[x, y] : RoomTileRaw.CreateOutOfBounds();