Beispiel #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);
        }
Beispiel #2
0
        // Take tiles from the level (or duplicate them) and put them into a tile grid.
        public TileGrid CreateTileGrid(Rectangle2I area, bool duplicate)
        {
            TileGrid tileGrid = new TileGrid(area.Size, roomLayerCount);

            BaseTileDataInstance[] tiles = GetTilesInArea(area).ToArray();

            foreach (BaseTileDataInstance baseTileOriginal in tiles)
            {
                // Duplicate the tile if specified, else remove the original.
                BaseTileDataInstance baseTile;
                if (duplicate)
                {
                    baseTile = baseTileOriginal.Duplicate();
                }
                else
                {
                    baseTile = baseTileOriginal;
                    baseTileOriginal.Room.Remove(baseTileOriginal);
                }

                // Add the tile to the tile grid.
                if (baseTile is TileDataInstance)
                {
                    TileDataInstance tile = (TileDataInstance)baseTile;
                    tile.Location += tile.Room.Location * roomSize;
                    tile.Location -= area.Point;
                    tileGrid.PlaceTile(tile, tile.Location, tile.Layer);
                }
                else if (baseTile is EventTileDataInstance)
                {
                    EventTileDataInstance eventTile = (EventTileDataInstance)baseTile;
                    eventTile.Position += eventTile.Room.Location * roomSize * GameSettings.TILE_SIZE;
                    eventTile.Position -= area.Point * GameSettings.TILE_SIZE;
                    tileGrid.AddEventTile(eventTile);
                }
            }

            return(tileGrid);
        }
Beispiel #3
0
        // Take tiles from the level (or duplicate them) and put them into a tile grid.
        public TileGrid CreateTileGrid(Rectangle2I area, bool duplicate)
        {
            TileGrid tileGrid = new TileGrid(area.Size, roomLayerCount);
            BaseTileDataInstance[] tiles = GetTilesInArea(area).ToArray();

            foreach (BaseTileDataInstance baseTileOriginal in tiles) {
                // Duplicate the tile if specified, else remove the original.
                BaseTileDataInstance baseTile;
                if (duplicate) {
                    baseTile = baseTileOriginal.Duplicate();
                }
                else {
                    baseTile = baseTileOriginal;
                    baseTileOriginal.Room.Remove(baseTileOriginal);
                }

                // Add the tile to the tile grid.
                if (baseTile is TileDataInstance) {
                    TileDataInstance tile = (TileDataInstance) baseTile;
                    tile.Location += tile.Room.Location * roomSize;
                    tile.Location -= area.Point;
                    tileGrid.PlaceTile(tile, tile.Location, tile.Layer);

                }
                else if (baseTile is EventTileDataInstance) {
                    EventTileDataInstance eventTile = (EventTileDataInstance) baseTile;
                    eventTile.Position += eventTile.Room.Location * roomSize * GameSettings.TILE_SIZE;
                    eventTile.Position -= area.Point * GameSettings.TILE_SIZE;
                    tileGrid.AddEventTile(eventTile);
                }
            }

            return tileGrid;
        }
Beispiel #4
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;
        }