Beispiel #1
0
        public Point MidPointBetweenMapRooms(MapRoom r0, MapRoom r1)
        {
            Point r0c = new Point(Mathf.RoundToInt(r0.centerPoint.x), Mathf.RoundToInt(r0.centerPoint.y));
            Point r1c = new Point(Mathf.RoundToInt(r1.centerPoint.x), Mathf.RoundToInt(r1.centerPoint.y));

            return(new Point((r0c.X + r1c.X) / 2, (r0c.Y + r1c.Y) / 2));
        }
Beispiel #2
0
        /// <summary>
        /// Use hallway lines to create raycasts that will be used to find all unused rooms between hubrooms.
        /// </summary>
        /// <param name="hallwayLines">Lines that run from one hub room to another.</param>
        /// <param name="hubRooms">Main 'hub' rooms already discoverd.</param>
        /// <returns></returns>
        public List <MapRoom> FindHallwayRooms(List <Line> hallwayLines, List <MapRoom> hubRooms)
        {
            List <MapRoom> foundRooms = new List <MapRoom>();

            foreach (Line line in hallwayLines)
            {
                // Find heading
                Vector2 rayHeading = line.p0 - line.p1;

                // Find distance
                float rayDistance = rayHeading.magnitude;

                // Find direction
                Vector2 rayDirection = rayHeading / rayDistance;

                // Throw 2d Raycast
                RaycastHit2D[] roomsHit = Physics2D.RaycastAll(line.p1, rayDirection, rayDistance);

                // Check found rooms vs Hub rooms; Add to hallwayRooms if not a hub room.
                for (int i = 0; i < roomsHit.Length; i++)
                {
                    MapRoom room = roomsHit[i].transform.GetComponent <MapRoomHolder>().mapRoom;

                    if (!hubRooms.Contains(room) && !foundRooms.Contains(room))
                    {
                        room.roomType = RoomType.Hallway;
                        foundRooms.Add(room);
                    }
                }
            }

            return(foundRooms);
        }
Beispiel #3
0
        /// <summary>
        /// Checks if the mid point between these rooms is within the Y plane boundaries of both rooms.
        /// </summary>
        /// <param name="midPoint">Point between rooms</param>
        /// <param name="r0">First room</param>
        /// <param name="r1">Second room</param>
        /// <param name="buffer">Makes sure the point isn't directly on a room boundary</param>
        /// <returns></returns>
        public bool IsPointBetweenYBoundariesOfGivenRooms(Point midPoint, MapRoom r0, MapRoom r1, int buffer)
        {
            if (midPoint.Y >= r0.gridLocation.Y + buffer && midPoint.Y <= r0.endPoint.Y - buffer)
            {
                if (midPoint.Y >= r1.gridLocation.Y + buffer && midPoint.Y <= r1.endPoint.Y - buffer)
                {
                    return(true);
                }
            }

            return(false);
        }
        /// <summary>
        /// Updates location of all map rooms by their physical helper objects.
        /// </summary>
        public List <MapRoom> SnapMapRoomLocationToPhysicalRoomLocation()
        {
            if (physicalRooms == null)
            {
                throw new ArgumentNullException("Physical Rooms", "Physical Rooms have not been created yet. Use GeneratePhysicalRooms first");
            }

            List <MapRoom> snappedRooms = new List <MapRoom>();

            foreach (GameObject room in physicalRooms)
            {
                Point   location = new Point(Mathf.RoundToInt(room.transform.position.x), Mathf.RoundToInt(room.transform.position.y));
                MapRoom mapRoom  = room.GetComponent <MapRoomHolder>().mapRoom;
                mapRoom.gridLocation = location;
                snappedRooms.Add(mapRoom);
            }

            return(snappedRooms);
        }