/// <summary>
        /// Creates an empty area using a specified tileset at the specified global coordinate
        /// </summary>
        /// <param name="tileSetpath"></param>
        /// <param name="location"></param>
        /// <returns></returns>
        public static Area makeEmptyArea(string tileSetpath, Point location)
        {
            Area a = new Area(tileSetpath, location);

            // default area
            for (int i = 0; i < WIDTH_IN_TILES; ++i)
                for (int j = 0; j < HEIGHT_IN_TILES; ++j)
                {
                    a.Tiles[i, j] = 3;
                    //if (j == HEIGHT_IN_TILES - 1)
                    //{
                    //    a.Tiles[i, j] = 4;
                    //}
                }

            a.initializeTileColliders();
            a.initializeAreaTransitions(null, null, null, null);

            return a;
        }
        public static void populateArea(Area a)
        {
            EnvironmentFillInfo efi = getCrateriaEnvironmentFillInfo(); // TODO data-drive this bad boy

            Dictionary<Point, GridUtils.TileConfigurer> tileConfigs =
                new Dictionary<Point, GridUtils.TileConfigurer>();

            Dictionary<Point, bool> tilesToFix = new Dictionary<Point, bool>();
            //Dictionary<Point, bool> fixedTiles = new Dictionary<Point,bool>();

            // mark all cells hit by the fractals, and which sides they are hit on, using
            //  grid intersection tests
            HashSet<Point> markedCellsSet = new HashSet<Point>(); // prevents duplicates
            // important because adding another fractal may change our interpretation
            //  of a tile, so we do all fractals first then figure out the tiles
            foreach (LineFractalInfo lfi in a.fractals)
            {
                // mark cells hit by fractal
                List<Point> markedCells = GridUtils.getGridIntersects(lfi.fractal, 40, 40, tileConfigs);

                // and add them all to a total set of hit cells
                foreach (Point p in markedCells)
                {
                    markedCellsSet.Add(p);
                }
            }

            // now that we know where all cells have been hit and where, we can figure out
            //  what type of tile they are, and also flag their neighbors for correction if
            //  necessary
            foreach (Point p in markedCellsSet)
            {
                if (p.X <= a.Tiles.GetUpperBound(0) &&
                    p.Y <= a.Tiles.GetUpperBound(1) &&
                    p.X >= 0 &&
                    p.Y >= 0)
                {
                    switch (tileConfigs[p].getType())
                    {
                        case GridUtils.TILE_TYPE.EMPTY:
                            a.Tiles[p.X, p.Y] = efi.EMPTY;
                            break;
                        case GridUtils.TILE_TYPE.FILL:
                            a.Tiles[p.X, p.Y] = efi.FILL;
                            break;
                        case GridUtils.TILE_TYPE.FILL_LEFT:
                            a.Tiles[p.X, p.Y] = efi.FILL_LEFT;
                            tilesToFix[new Point(p.X - 1, p.Y)] = false;
                            break;
                        case GridUtils.TILE_TYPE.FILL_RIGHT:
                            a.Tiles[p.X, p.Y] = efi.FILL_RIGHT;
                            tilesToFix[new Point(p.X + 1, p.Y)] = false;
                            break;
                        case GridUtils.TILE_TYPE.FILL_TOP:
                            a.Tiles[p.X, p.Y] = efi.FILL_TOP;
                            tilesToFix[new Point(p.X, p.Y - 1)] = false;
                            break;
                        case GridUtils.TILE_TYPE.FILL_BOTTOM:
                            a.Tiles[p.X, p.Y] = efi.FILL_BOTTOM;
                            tilesToFix[new Point(p.X, p.Y + 1)] = false;
                            break;
                        case GridUtils.TILE_TYPE.FILL_TOPLEFT:
                            a.Tiles[p.X, p.Y] = efi.FILL_TOPLEFT;
                            break;
                        case GridUtils.TILE_TYPE.FILL_TOPRIGHT:
                            a.Tiles[p.X, p.Y] = efi.FILL_TOPRIGHT;
                            break;
                        case GridUtils.TILE_TYPE.FILL_BOTTOMLEFT:
                            a.Tiles[p.X, p.Y] = efi.FILL_BOTTOMLEFT;
                            break;
                        case GridUtils.TILE_TYPE.FILL_BOTTOMRIGHT:
                            a.Tiles[p.X, p.Y] = efi.FILL_BOTTOMRIGHT;
                            break;
                        case GridUtils.TILE_TYPE.EMPTY_TOPLEFT:
                            a.Tiles[p.X, p.Y] = efi.EMPTY_TOPLEFT;
                            break;
                        case GridUtils.TILE_TYPE.EMPTY_TOPRIGHT:
                            a.Tiles[p.X, p.Y] = efi.EMPTY_TOPRIGHT;
                            break;
                        case GridUtils.TILE_TYPE.EMPTY_BOTTOMLEFT:
                            a.Tiles[p.X, p.Y] = efi.EMPTY_BOTTOMLEFT;
                            break;
                        case GridUtils.TILE_TYPE.EMPTY_BOTTOMRIGHT:
                            a.Tiles[p.X, p.Y] = efi.EMPTY_BOTTOMRIGHT;
                            break;
                        default:
                            a.Tiles[p.X, p.Y] = efi.OTHER;
                            break;
                    }

                    // if not empty, mark that we've set it - if empty it probably means
                    //  a tile which a fractal double backed on, so we don't want to make
                    //  any guarantees
                    if (tileConfigs[p].getType() != GridUtils.TILE_TYPE.EMPTY)
                    {
                        tilesToFix[p] = true;
                    }
                }
            }

            // copy list of tiles to fix into an array since we modify it
            //  while we are traversing it, then use recursion to flood the changes
            Point[] points = new Point[tilesToFix.Count];
            tilesToFix.Keys.CopyTo(points, 0);
            foreach (Point p in points)
            {
                fill(p, tilesToFix, a.Tiles, efi);
            }

            foreach (Point p in tilesToFix.Keys)
            {
                a.FixedTiles.Add(p);
            }
            a.initializeTileColliders();
        }
Exemple #3
0
        /// <summary>
        /// Creates an empty area using a specified tileset at the specified global coordinate
        /// </summary>
        /// <param name="tileSetpath"></param>
        /// <param name="location"></param>
        /// <returns></returns>
        public static Area makeEmptyArea(string tileSetpath, Point location)
        {
            Area a = new Area(tileSetpath, location);

            // default area
            /*for (int i = 0; i < WIDTH_IN_TILES; ++i)
                for (int j = 0; j < HEIGHT_IN_TILES; ++j)
                {
                    a.Tiles[i, j] = 3;
                }*/

            // whoever came up with this map format was drunk,
            // it's stored rotated counter-clockwise 90 degrees AND THEN horizontally flipped
            // what the shit, right?
            a.Tiles = AreaDefinitions.areaAt(location);

            a.initializeTileColliders();
            a.initializeAreaTransitions(null, null, null, null);

            return a;
        }