コード例 #1
0
 void UpdateTransform()
 {
     if (RoomTransform != null)
     {
         transform.position   = RoomTransform.position;
         transform.rotation   = RoomTransform.rotation;
         transform.localScale = Vector3.one * RoomTransform.TransformVector(Vector3.forward).magnitude;  //Apply rig scaling
     }
 }
コード例 #2
0
    public RoomGenerator()
    {
        m_gridSystem = new GridSystem();
        m_directions.Add(Direction.up, new IntVector2(0, 1));
        m_directions.Add(Direction.down, new IntVector2(0, -1));
        m_directions.Add(Direction.left, new IntVector2(-1, 0));
        m_directions.Add(Direction.right, new IntVector2(1, 0));

        m_availablePositions = new Stack <RoomTransform>();
        m_transform          = new RoomTransform(new IntVector2(5, 5), Direction.none, 0);
    }
コード例 #3
0
    private RoomTransform SetTiles(RoomTransform transform, int roomSize)
    {
        List <RoomTransform> transforms = GetTransformations(transform, roomSize);

        // if the current transform has options to place a room with the given size
        if (transforms.Count > 0)
        {
            RoomTransform selectedTransform = transform;
            // choose a random option
            int selected = Random.Range(0, transforms.Count - 1);
            for (int i = 0; i < transforms.Count; i++)
            {
                if (i == selected)
                {
                    SetTiles(GetTiles(transforms[selected].centerPosition, roomSize));
                    selectedTransform = transforms[selected];
                }

                else
                {
                    // push only 75% of the total possible paths to the stack
                    if (Random.Range(0, 100) > 50 && roomSize > 3 || roomSize == 9)
                    {
                        m_availablePositions.Push(transforms[i]);
                    }
                }
            }

            // the compiler does not know this will never be triggered
            return(selectedTransform);
        }
        // if there are still options stacked
        else if (m_availablePositions.Count > 0)
        {
            RoomTransform target = m_availablePositions.Pop();
            SetTiles(GetTiles(target.centerPosition, target.roomSize));
            return(new RoomTransform(target));
        }

        // if there are no more options, clear the builder
        else
        {
            Clear();
            return(transform);
        }
    }
コード例 #4
0
    List <RoomTransform> GetTransformations(RoomTransform transform, int roomSize)
    {
        List <RoomTransform> transforms = new List <RoomTransform>();

        for (int i = 0; i < 4; i++)
        {
            int toEdge = 0;
            if (m_transform.direction != Direction.none)
            {
                // if i is backwards, skip
                if (i == (((int)transform.direction + 2) % 4))
                {
                    continue;
                }

                // from the center to the edge of the placed tiles
                toEdge = (int)(((float)m_transform.roomSize / 2f) - .5);
            }

            // from the edge to the edge to the edge of a new room with the given size
            int toRoomCenter = toEdge + (int)(((float)roomSize / 2f) + .5);

            // the center of the new possible
            IntVector2 newRoomCenter = new IntVector2
            {
                // the position at the edge of the selected side
                X = transform.centerPosition.X + (toRoomCenter * m_directions[(Direction)i].X),
                Y = transform.centerPosition.Y + (toRoomCenter * m_directions[(Direction)i].Y)
            };

            // create a transform with the given position and direction
            RoomTransform target = new RoomTransform(newRoomCenter, (Direction)i, roomSize);

            // add to the possible targets when all tiles are free
            if (IsPositionValid(target, roomSize))
            {
                transforms.Add(target);
            }
        }
        return(transforms);
    }
コード例 #5
0
    public void GenerateRooms(World2D world)
    {
        m_generating = true;
        while (m_generating)
        {
            int roomSize = GetRoomSize();

            // update the current transform to the new room's center after placing it
            m_transform = SetTiles(m_transform, roomSize);
        }

        // generate walls
        new WallGenerator(m_gridSystem);
        new DoorGenerator(m_gridSystem);
        new SectionGenerator(m_gridSystem, TileType.s01Wall, TileType.s02Wall, TileType.s03Wall, TileType.s04Wall);
        SpawnPointGenerator s = new SpawnPointGenerator(m_gridSystem, world);

        world.spawnpointGenerator = s;
        world.gridSystem          = m_gridSystem;
        m_playerList = s.SpawnPointList;
    }
コード例 #6
0
 public RoomTransform(RoomTransform a)
 {
     centerPosition = a.centerPosition; direction = a.direction; roomSize = a.roomSize;
 }
コード例 #7
0
    bool IsPositionValid(RoomTransform transform, int roomSize)
    {
        List <IntVector2> positions = GetTiles(transform.centerPosition, roomSize);

        return(m_gridSystem.IsAvailable(positions));
    }