コード例 #1
0
        /// <summary>
        /// Gets a new Horizontal Direction
        /// <param name="overrideRandom">If set, this direction will be used instead of random</param>
        /// </summary>
        public void GetNewHorzDirection(HorzDirection overrideRandom = HorzDirection.NotSet)
        {
            HorzDirection newHorzDirection;

            if (overrideRandom == HorzDirection.NotSet)
            {
                newHorzDirection = (HorzDirection)Random.Range(0, 4);
                while (newHorzDirection == HelperSingleton.Instance.GetOpposite(CalculationSingleton.Instance.ActualCreationScope.NextHorizontalDirection))
                {
                    newHorzDirection = (HorzDirection)Random.Range(0, 4);
                }
            }
            else
            {
                newHorzDirection = overrideRandom;
            }

            CalculationSingleton.Instance.ActualCreationScope.NextHorizontalDirection = newHorzDirection;
        }
コード例 #2
0
 /// <summary>
 /// Returns the Opposite of the actual HorzDirection enum
 /// </summary>
 /// <param name="direction"></param>
 /// <returns></returns>
 public HorzDirection GetOpposite(HorzDirection direction)
 {
     if (direction == HorzDirection.Backwards)
     {
         return(HorzDirection.Forward);
     }
     else if (direction == HorzDirection.Forward)
     {
         return(HorzDirection.Backwards);
     }
     else if (direction == HorzDirection.Left)
     {
         return(HorzDirection.Right);
     }
     else
     {
         return(HorzDirection.Left);
     }
 }
コード例 #3
0
        /// <summary>
        /// Returns the correct rotation for the given horizonzal rotations.
        /// </summary>
        /// <returns></returns>
        public void CalculateRotationForHorizontalCorner(HorzDirection actual = HorzDirection.NotSet, HorzDirection next = HorzDirection.NotSet)
        {
            WallDescriptor wallToUse = null;
            var            wall1     = ActualCreatedLevelBlock.transform.GetComponentsInChildren <WallDescriptor>().Where(wl => wl.WallNumber == 0).First();
            var            wall2     = ActualCreatedLevelBlock.transform.GetComponentsInChildren <WallDescriptor>().Where(wl => wl.WallNumber == 1).First();

            actual = actual == HorzDirection.NotSet
                ? ActualHorizontalDirection
                : actual;
            next = next == HorzDirection.NotSet
                ? NextHorizontalDirection
                : next;

            if (actual == HorzDirection.Backwards)
            {
                wallToUse = next == HorzDirection.Left
                    ? wall2
                    : wall1;
            }
            else if (actual == HorzDirection.Right)
            {
                wallToUse = next == HorzDirection.Backwards
                    ? wall2
                    : wall1;
            }
            else if (actual == HorzDirection.Forward)
            {
                wallToUse = next == HorzDirection.Right
                    ? wall2
                    : wall1;
            }
            else if (actual == HorzDirection.Left)
            {
                wallToUse = next == HorzDirection.Forward
                    ? wall2
                    : wall1;
            }

            wallToUse.RotateWallFacesDirection(next);
        }
コード例 #4
0
        /// <summary>
        /// Checks if the current move is allowed
        /// </summary>
        public bool IsMoveAllowed(HorzDirection desiredDirection)
        {
            Vector3 rayDirection = Vector3.one;

            switch (desiredDirection)
            {
            case HorzDirection.Left:
                rayDirection = PlayerSingleton.Instance.Player.transform.right * -1;
                break;

            case HorzDirection.Right:
                rayDirection = PlayerSingleton.Instance.Player.transform.right;
                break;

            case HorzDirection.Forward:
                rayDirection = PlayerSingleton.Instance.Player.transform.forward;
                break;

            case HorzDirection.Backwards:
                rayDirection = PlayerSingleton.Instance.Player.transform.forward * -1;
                break;
            }

            var        pos = new Vector3(Player.transform.position.x, Player.transform.position.y + 1.5f, Player.transform.position.z);
            var        ray = new Ray(pos, rayDirection);
            RaycastHit info;

            Physics.Raycast(ray, out info, 4.1f);

            if (info.transform == null ||
                info.transform.gameObject.tag == "Passable")
            {
                // Nothing in the way, or something is in the way, but it is on the white list.
                return(true);
            }
            else
            {
                if (info.transform.gameObject.tag == "RenderObject")
                {
                    // Seems to be an unpassble zone. But check if it is on the same height as we are!
                    var size = HelperSingleton.Instance.GetSize(info.transform.gameObject, false);

                    if ((info.transform.position.y - (size.z / 2)) > Player.transform.position.y || // <-- It' above us.
                        (size.z + info.transform.position.y - (size.z / 2)) < Player.transform.position.y)     // <-- It' below  us.
                    {
                        // Its either below us, or above us
                        return(true);
                    }

                    // Its in the way.
                    return(false);
                }

                if (HelperSingleton.Instance.GetTopMostGO(info.transform.gameObject, true).tag == "LevelBlock" ||
                    HelperSingleton.Instance.GetTopMostGO(info.transform.gameObject, true).tag == "Unpassable")
                {
                    // End of level reached, or object is on teh black list.
                    return(false);
                }

                return(true);
            }
        }
コード例 #5
0
        /// <summary>
        /// Rotates a specific wall that it is facing a certain direction.
        /// This means, if a raycast would be done between the wall and the target, it would NEVER cross the floor
        /// </summary>
        /// <param name="rotateTo"></param>
        public void RotateTo(HorzDirection rotateTo)
        {
            switch (rotateTo)
            {
            case HorzDirection.Left:
                if (WallNumber == 0)
                {
                    this.gameObject.transform.parent.transform.rotation = Quaternion.Euler(new Vector3(0, 270, 0));
                }
                if (WallNumber == 1)
                {
                    this.gameObject.transform.parent.transform.rotation = Quaternion.Euler(new Vector3(0, 180, 0));
                }
                if (WallNumber == 2)
                {
                    this.gameObject.transform.parent.transform.rotation = Quaternion.Euler(new Vector3(0, 90, 0));
                }
                if (WallNumber == 3)
                {
                    this.gameObject.transform.parent.transform.rotation = Quaternion.Euler(new Vector3(0, 0, 0));
                }
                break;

            case HorzDirection.Right:
                if (WallNumber == 0)
                {
                    this.gameObject.transform.parent.transform.rotation = Quaternion.Euler(new Vector3(0, 90, 0));
                }
                if (WallNumber == 1)
                {
                    this.gameObject.transform.parent.transform.rotation = Quaternion.Euler(new Vector3(0, 0, 0));
                }
                if (WallNumber == 2)
                {
                    this.gameObject.transform.parent.transform.rotation = Quaternion.Euler(new Vector3(0, 270, 0));
                }
                if (WallNumber == 3)
                {
                    this.gameObject.transform.parent.transform.rotation = Quaternion.Euler(new Vector3(0, 180, 0));
                }
                break;

            case HorzDirection.Forward:
                if (WallNumber == 0)
                {
                    this.gameObject.transform.parent.transform.rotation = Quaternion.Euler(new Vector3(0, 180, 0));
                }
                if (WallNumber == 1)
                {
                    this.gameObject.transform.parent.transform.rotation = Quaternion.Euler(new Vector3(0, 90, 0));
                }
                if (WallNumber == 2)
                {
                    this.gameObject.transform.parent.transform.rotation = Quaternion.Euler(new Vector3(0, 0, 0));
                }
                if (WallNumber == 3)
                {
                    this.gameObject.transform.parent.transform.rotation = Quaternion.Euler(new Vector3(0, 270, 0));
                }
                break;

            case HorzDirection.Backwards:
                if (WallNumber == 0)
                {
                    this.gameObject.transform.parent.transform.rotation = Quaternion.Euler(new Vector3(0, 0, 0));
                }
                if (WallNumber == 1)
                {
                    this.gameObject.transform.parent.transform.rotation = Quaternion.Euler(new Vector3(0, 270, 0));
                }
                if (WallNumber == 2)
                {
                    this.gameObject.transform.parent.transform.rotation = Quaternion.Euler(new Vector3(0, 180, 0));
                }
                if (WallNumber == 3)
                {
                    this.gameObject.transform.parent.transform.rotation = Quaternion.Euler(new Vector3(0, 90, 0));
                }
                break;

            default:
                break;
            }
        }
コード例 #6
0
 /// <summary>
 /// If this is called, the Wall is rotated that if faces a certain direction, but on the long side
 /// This means, if a raycast would be done between the wall and the target, it would always cross the floor
 /// </summary>
 /// <param name="rotateTo"></param>
 public void RotateWallFacesDirection(HorzDirection rotateTo)
 {
     RotateTo(HelperSingleton.Instance.GetOpposite(rotateTo));
 }