Example #1
0
        // Return a copy of this tile grid.
        public TileGrid Duplicate()
        {
            TileGrid duplicate = new TileGrid(size, layerCount);

            // Duplicate tiles.
            for (int x = 0; x < size.X; x++)
            {
                for (int y = 0; y < size.Y; y++)
                {
                    for (int i = 0; i < layerCount; i++)
                    {
                        TileGridTile tile = tiles[x, y, i];
                        if (tile.Tile != null && tile.Location == new Point2I(x, y))
                        {
                            TileDataInstance tileCopy = new TileDataInstance();
                            tileCopy.Clone(tile.Tile);
                            duplicate.PlaceTile(tileCopy, x, y, i);
                        }
                    }
                }
            }

            // Duplicate event tiles.
            foreach (EventTileDataInstance eventTile in eventTiles)
            {
                EventTileDataInstance copy = new EventTileDataInstance();
                copy.Clone(eventTile);
                duplicate.AddEventTile(copy);
            }

            return(duplicate);
        }
Example #2
0
        public void RemoveTile(int x, int y, int layer)
        {
            TileGridTile tile = tiles[x, y, layer];

            if (tile.Tile != null)
            {
                RemoveTile(tile);
            }
        }
Example #3
0
        public TileDataInstance GetTileIfAtLocation(int x, int y, int layer)
        {
            TileGridTile tile = tiles[x, y, layer];

            if (tile.Location.X == x && tile.Location.Y == y && tile.Layer == layer)
            {
                return(tile.Tile);
            }
            return(null);
        }
Example #4
0
        private void RemoveTile(TileGridTile tile)
        {
            Point2I size = tile.Tile.Size;

            for (int x = 0; x < size.X; x++)
            {
                for (int y = 0; y < size.Y; y++)
                {
                    Point2I loc = new Point2I(tile.Location.X + x, tile.Location.Y + y);
                    if (loc.X < Width && loc.Y < Height)
                    {
                        tiles[loc.X, loc.Y, tile.Layer].Set(null, loc.X, loc.Y, tile.Layer);
                    }
                }
            }
        }
Example #5
0
 public void RemoveTile(TileDataInstance tile)
 {
     if (tile == null)
     {
         return;
     }
     for (int x = 0; x < size.X; x++)
     {
         for (int y = 0; y < size.Y; y++)
         {
             for (int i = 0; i < layerCount; i++)
             {
                 TileGridTile t = tiles[x, y, i];
                 if (t.Tile == tile)
                 {
                     RemoveTile(t);
                     return;
                 }
             }
         }
     }
 }
Example #6
0
        public void PlaceTile(TileDataInstance tile, Point2I location, int layer)
        {
            Point2I size = tile.Size;

            for (int x = 0; x < size.X; x++)
            {
                for (int y = 0; y < size.Y; y++)
                {
                    Point2I loc = new Point2I(location.X + x, location.Y + y);
                    if (loc.X < Width && loc.Y < Height)
                    {
                        // Remove existing tile.
                        TileGridTile t = tiles[loc.X, loc.Y, layer];
                        if (t.Tile != null)
                        {
                            RemoveTile(t);
                        }
                        tiles[loc.X, loc.Y, layer].Set(tile, location.X, location.Y, layer);
                    }
                }
            }
        }
Example #7
0
        public IEnumerable <BaseTileDataInstance> GetTiles()
        {
            // Iterate tiles.
            for (int x = 0; x < size.X; x++)
            {
                for (int y = 0; y < size.Y; y++)
                {
                    for (int i = 0; i < layerCount; i++)
                    {
                        TileGridTile tile = tiles[x, y, i];
                        if (tile.Tile != null && tile.Location == new Point2I(x, y))
                        {
                            yield return(tile.Tile);
                        }
                    }
                }
            }

            // Iterate event tiles.
            foreach (EventTileDataInstance eventTile in eventTiles)
            {
                yield return(eventTile);
            }
        }
Example #8
0
 private void RemoveTile(TileGridTile tile)
 {
     Point2I size = tile.Tile.Size;
     for (int x = 0; x < size.X; x++) {
         for (int y = 0; y < size.Y; y++) {
             Point2I loc = new Point2I(tile.Location.X + x, tile.Location.Y + y);
             if (loc.X < Width && loc.Y < Height)
                 tiles[loc.X, loc.Y, tile.Layer].Set(null, loc.X, loc.Y, tile.Layer);
         }
     }
 }