Esempio n. 1
0
 protected Directions GetRelativeDirection(HallwayComponent hallway, Vector3 diff)
 {
     if (Mathf.Abs(diff.x) > Mathf.Abs(diff.z))
     {
         if (diff.x > 0)
         {
             return(Directions.East);
         }
         else
         {
             return(Directions.West);
         }
     }
     else
     if (diff.z > 0)
     {
         return(Directions.North);
     }
     else
     {
         return(Directions.South);
     }
 }
Esempio n. 2
0
 protected override Wall[] CreateConnectingWall(HallwayComponent hallway, Vector3 wallCenter)
 {
     return(new Wall[0]);
 }
Esempio n. 3
0
        private static void CreateHallwaysRecursive(Map map, Room currentRoom, Room previousRoom, Directions?direction, List <RoomComponent> hallwayComponents)
        {
            if (direction.HasValue)
            {
                float xPos = currentRoom.Location.X * ROOM_OFFSET_FACTOR;
                float zPos = currentRoom.Location.Y * ROOM_OFFSET_FACTOR;

                if (direction.Value == Directions.West)
                {
                    xPos += HALLWAY_OFFSET_AMOUNT;
                }
                else if (direction.Value == Directions.East)
                {
                    xPos -= HALLWAY_OFFSET_AMOUNT;
                }
                else if (direction.Value == Directions.South)
                {
                    zPos += HALLWAY_OFFSET_AMOUNT;
                }
                else
                {
                    zPos -= HALLWAY_OFFSET_AMOUNT;
                }


                HallwayComponent hallwayComp = null;

                if (direction.Value == Directions.North || direction.Value == Directions.South)
                {
                    hallwayComp = CreateRoom <HallwayComponent>(HALLWAY_LENGTH, HALLWAY_WIDTH, HALLWAY_HEIGHT, new Vector3(xPos, 0, zPos));
                }
                else
                {
                    hallwayComp = CreateRoom <HallwayComponent>(HALLWAY_WIDTH, HALLWAY_LENGTH, HALLWAY_HEIGHT, new Vector3(xPos, 0, zPos));
                }


                hallwayComp.SetExit(direction.Value, currentRoom.UnityRoomComponent);
                hallwayComponents.Add(hallwayComp);

                previousRoom.UnityRoomComponent.SetExit(direction.Value, hallwayComp);
            }

            if (direction != Directions.South && currentRoom.NorthExit != null)
            {
                CreateHallwaysRecursive(map, map.GetNeighboringRoom(currentRoom, Directions.North), currentRoom, Directions.North, hallwayComponents);
            }

            if (direction != Directions.North && currentRoom.SouthExit != null)
            {
                CreateHallwaysRecursive(map, map.GetNeighboringRoom(currentRoom, Directions.South), currentRoom, Directions.South, hallwayComponents);
            }

            if (direction != Directions.East && currentRoom.WestExit != null)
            {
                CreateHallwaysRecursive(map, map.GetNeighboringRoom(currentRoom, Directions.West), currentRoom, Directions.West, hallwayComponents);
            }

            if (direction != Directions.West && currentRoom.EastExit != null)
            {
                CreateHallwaysRecursive(map, map.GetNeighboringRoom(currentRoom, Directions.East), currentRoom, Directions.East, hallwayComponents);
            }
        }
Esempio n. 4
0
        protected virtual Wall[] CreateConnectingWall(HallwayComponent hallway, Vector3 wallCenter)
        {
            // Prep maths
            Vector3    diff = this.transform.position - hallway.transform.position;
            Directions relativeDirection = GetRelativeDirection(hallway, diff);
            Vector2    openingSize       = hallway.GetExitSize(relativeDirection);
            float      wallWidth         = GetWallWidth(relativeDirection);

            float sideGapAdjustment = openingSize.x / 2 - Wall.THICKNESS;
            float sidePieceWidth    = (wallWidth - openingSize.x) / 2 + Wall.THICKNESS;
            float doorPieceHeight   = this.Height - openingSize.y;
            float centerPieceHeight = Height - hallway.Height;



            // Create piece and take ownership
            var leftPiece   = new Wall(this, sidePieceWidth, Height);
            var rightPiece  = new Wall(this, sidePieceWidth, Height);
            var centerPiece = new Wall(this, hallway.Width - Wall.THICKNESS * 2, centerPieceHeight);

            TakeOwnershipOfChildren(leftPiece, rightPiece, centerPiece);



            // Position pieces
            leftPiece.Instance.transform.Rotate(new Vector3(0, 90, 0));
            leftPiece.SetLocalPosition(-sideGapAdjustment - sidePieceWidth / 2, wallWidth / 2 - Wall.THICKNESS / 2);

            rightPiece.Instance.transform.Rotate(new Vector3(0, 90, 0));
            rightPiece.SetLocalPosition(sideGapAdjustment + sidePieceWidth / 2, wallWidth / 2 - Wall.THICKNESS / 2);

            centerPiece.SetLocalPosition(0, Height - Wall.THICKNESS, wallWidth / 2 - Wall.THICKNESS / 2, 90);



            // rotate this shit
            switch (relativeDirection)
            {
            case Directions.North:
                leftPiece.Instance.transform.RotateAround(this.transform.position, Vector3.up, 180);
                rightPiece.Instance.transform.RotateAround(this.transform.position, Vector3.up, 180);
                centerPiece.Instance.transform.RotateAround(this.transform.position, Vector3.up, 180);
                break;

            case Directions.East:
                leftPiece.Instance.transform.RotateAround(this.transform.position, Vector3.up, -90);
                rightPiece.Instance.transform.RotateAround(this.transform.position, Vector3.up, -90);
                centerPiece.Instance.transform.RotateAround(this.transform.position, Vector3.up, -90);
                break;

            case Directions.West:
                leftPiece.Instance.transform.RotateAround(this.transform.position, Vector3.up, 90);
                rightPiece.Instance.transform.RotateAround(this.transform.position, Vector3.up, 90);
                centerPiece.Instance.transform.RotateAround(this.transform.position, Vector3.up, 90);
                break;
            }

            return(new Wall[] {
                leftPiece, rightPiece, centerPiece
            });
        }