Exemplo n.º 1
0
        /// <summary>
        /// Places the given tile in the dungeon, at the same time as adding the tile to the
        /// internal array used for quick access.
        /// </summary>
        /// <param name="tile"></param>
        /// <param name="p"></param>
        private void place(Tile tile, Point p, IGenRoom origin)
        {
            grid[p.Col, p.Row]        = tile;
            gridOrigins[p.Col, p.Row] = origin;

            StaticTile obj;

            switch (tile)
            {
            case Tile.FLOOR:
                obj = StaticTile.Floor(p);
                break;

            case Tile.PATH:
                obj = StaticTile.Path(p);
                break;

            case Tile.DOOR:
                obj = StaticTile.Door(p);
                break;

            case Tile.VER_WALL:
                obj = StaticTile.VerWall(p);
                grid[p.Col, p.Row] = Tile.WALL;
                break;

            case Tile.HOR_WALL:
                obj = StaticTile.HorWall(p);
                grid[p.Col, p.Row] = Tile.WALL;
                break;

            case Tile.PATH_WALL:
                obj = StaticTile.PathWall(p);
                grid[p.Col, p.Row] = Tile.EMPTY;
                break;

            default:
                obj = new StaticTile(p, false);
                break;
            }

            dungeon.PlaceObject(obj, p);
        }
Exemplo n.º 2
0
            /// <summary>
            /// Moves the path forward using its current location, previous move, and other info to move, block by block.
            /// </summary>
            private void pathStep()
            {
                Point last = current;

                //First checks if it is not already next to another path
                if (!(adjCheck(new Point(current.Col + 1, current.Row)) ||
                      adjCheck(new Point(current.Col - 1, current.Row)) ||
                      adjCheck(new Point(current.Col, current.Row + 1)) ||
                      adjCheck(new Point(current.Col, current.Row - 1))))
                {
                    //If it is not, it will move in a random location within a few contraints
                    List <int> moves = new List <int>();

                    if (travelCol > 0)
                    {
                        moves.Add(0);
                    }
                    if (travelCol < 0)
                    {
                        moves.Add(1);
                    }
                    if (travelRow > 0)
                    {
                        moves.Add(2);
                    }
                    if (travelRow < 0)
                    {
                        moves.Add(3);
                    }

                    if (moves.Count == 0)
                    {
                        return;
                    }

                    int move = moves[gen.rand.Next(moves.Count)];
                    foreach (int el in moves)
                    {
                        if (el == prev)
                        {
                            if (gen.rand.Next(PATH_DIR_CHANGE) != 0)
                            {
                                move = prev;
                            }
                        }
                    }
                    prev = move;
                    switch (move)
                    {
                    case 0:
                        current = new Point(current.Col + 1, current.Row);
                        travelCol--;
                        break;

                    case 1:
                        current = new Point(current.Col - 1, current.Row);
                        travelCol++;
                        break;

                    case 2:
                        current = new Point(current.Col, current.Row + 1);
                        travelRow--;
                        break;

                    case 3:
                        current = new Point(current.Col, current.Row - 1);
                        travelRow++;
                        break;
                    }
                }

                ///Only starts pathing once it has left its starting room
                if (!active)
                {
                    switch (gen.grid[current.Col, current.Row])
                    {
                    case Tile.EMPTY:
                        active = true;
                        Visible.Add(last);
                        firstDoorVisible.AddRange(originRoom.Visible);
                        gen.placeDoor(last, this, firstDoorVisible);
                        placeWall(new Point(last.Col + 1, last.Row));
                        placeWall(new Point(last.Col - 1, last.Row));
                        placeWall(new Point(last.Col, last.Row + 1));
                        placeWall(new Point(last.Col, last.Row - 1));
                        break;

                    case Tile.PATH:
                        originRoom.Connect(gen.gridOrigins[current.Col, current.Row].Origin);
                        return;

                    case Tile.DOOR:
                        originRoom.Connect(gen.gridOrigins[current.Col, current.Row].Origin);
                        return;
                    }
                }

                if (active)
                {
                    switch (gen.grid[current.Col, current.Row])
                    {
                    case Tile.EMPTY:
                        gen.place(Tile.PATH, current, this);
                        Visible.Add(current);
                        break;

                    case Tile.WALL:
                        IGenRoom foundWall = gen.gridOrigins[current.Col, current.Row];
                        originRoom.Connect(foundWall.Origin);

                        Visible.Add(current);
                        firstDoorVisible.AddRange(Visible);

                        List <Point> doorVisible = new List <Point>(Visible);
                        doorVisible.AddRange(foundWall.Visible);
                        gen.placeDoor(current, this, doorVisible);

                        firstDoorVisible.AddRange(Visible);
                        return;

                    case Tile.PATH:
                        IGenRoom foundPath = gen.gridOrigins[current.Col, current.Row];
                        originRoom.Connect(foundPath.Origin);

                        firstDoorVisible.AddRange(Visible);
                        firstDoorVisible.AddRange(foundPath.Visible);
                        foundPath.Visible.AddRange(Visible);
                        return;
                    }
                }

                placeWall(new Point(current.Col + 1, current.Row));
                placeWall(new Point(current.Col - 1, current.Row));
                placeWall(new Point(current.Col, current.Row + 1));
                placeWall(new Point(current.Col, current.Row - 1));

                pathStep();
            }
Exemplo n.º 3
0
 /// <summary>
 /// Similiar to "place()", but used specifically for doors. Let's you pass visibility list.
 /// </summary>
 /// <param name="p"></param>
 /// <param name="origin"></param>
 /// <param name="visible"></param>
 private void placeDoor(Point p, IGenRoom origin, List <Point> visible)
 {
     grid[p.Col, p.Row]        = Tile.DOOR;
     gridOrigins[p.Col, p.Row] = origin;
     dungeon.PlaceObject(new VisibilityDoor(p, dungeon, visible), p);
 }