Ejemplo n.º 1
0
        protected static Rect TryMove(MovableElement movable, Direction direction)
        {
            Rect   rect1 = new Rect(new Point(movable.X, movable.Y), new Size(1, 1));
            double speed = movable.Speed;

            switch (direction)
            {
            case Direction.Up:
                rect1.Offset(-speed, 0);
                break;

            case Direction.Down:
                rect1.Offset(speed, 0);
                break;

            case Direction.Left:
                rect1.Offset(0, -speed);
                break;

            case Direction.Right:
                rect1.Offset(0, speed);
                break;
            }
            return(rect1);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Checks whether the specified element can be moved in the specified direction.
        /// </summary>
        /// <param name="movable">The element to check.</param>
        /// <param name="direction">Movement direction</param>
        /// <returns>True if the element can be moved in a specified direction, otherwise false.</returns>
        public bool CheckMovement(MovableElement movable, Direction direction)
        {
            if (direction == Direction.None)
            {
                return(false);
            }
            Rect rect = TryMove(movable, direction);

            return(CheckBoardMovementPossibility(rect, _gameBoard) && CheckMovement(movable, direction, _gameBoard));
        }
Ejemplo n.º 3
0
 /// <summary>
 /// Moves the element via given portal from one endpoint to another.
 /// </summary>
 /// <param name="movable">The element which should be moved.</param>
 /// <param name="portal">A portal object which gives information about where to move.</param>
 public static void MoveViaPortal(this MovableElement movable, Portal portal)
 {
     if (movable == null)
     {
         return;
     }
     if (portal?.ConnectedPortal != null)
     {
         movable.X = portal.ConnectedPortal.X;
         movable.Y = portal.ConnectedPortal.Y;
     }
 }
Ejemplo n.º 4
0
 public void HandleUIRelation(MovableElement activeElem)
 {
     if (!isUIon)
     {
         isUIon = true;
     }
     if (!UI.gameObject.activeInHierarchy)
     {
         UI.gameObject.SetActive(true);
     }
     UI.position = activeElem.transform.position;
     UIMovement.Instance.activeElement = activeElem;
     UIMovement.Instance.CheckMode();
 }
Ejemplo n.º 5
0
 /// <summary>
 ///     adjust buttons position according to element bounds
 /// </summary>
 /// <param name="me">Element</param>
 /// <param name="pos">Element position (2d)</param>
 /// <param name="size">Element size (2d)</param>
 private void SetOrigins(MovableElement me, Vector3 pos, Vector3 size)
 {
     oUp     = pos + size.y * me.associated2DObject.transform.up;
     oDown   = pos - size.y * me.associated2DObject.transform.up;
     oLeft   = pos - size.x * me.associated2DObject.transform.right;
     oRight  = pos + size.x * me.associated2DObject.transform.right;
     oUpLeft = pos - size.x * me.associated2DObject.transform.right +
               size.y * me.associated2DObject.transform.up;
     oUpRight = pos + size.x * me.associated2DObject.transform.right +
                size.y * me.associated2DObject.transform.up;
     oDownLeft = pos - size.x * me.associated2DObject.transform.right -
                 size.y * me.associated2DObject.transform.up;
     oDownRight = pos + size.x * me.associated2DObject.transform.right -
                  size.y * me.associated2DObject.transform.up;
 }
Ejemplo n.º 6
0
        protected Rect?TryMoveViaPortal(MovableElement movable, Direction direction)
        {
            Rect   m = TryMove(movable, direction);
            Portal p = null;

            foreach (var portal in _gameBoard.Elements.OfType <Portal>())
            {
                if (CheckCollision(portal, m))
                {
                    if (p == null)
                    {
                        m = new Rect(new Point(portal.X, portal.Y), new Size(1, 1));
                        p = portal;
                    }
                }
            }
            return(p != null ? (Rect?)new Rect(new Point(movable.X, movable.Y), new Size(1, 1)) : null);
        }
Ejemplo n.º 7
0
    public void CompleteGoal(MovableElement element)
    {
        if (audioSource != null)
        {
            Debug.Log("Play audio");
            audioSource.Play();
        }
        element.transform.position = goalPositions[completedGoals];
        element.transform.rotation = Quaternion.identity;
        element.GetComponent <Rigidbody2D>().Sleep();

        allMovables.Remove(element);

        completedGoals++;
        if (completedGoals == allGoals)
        {
            StartCoroutine(FinishGame());
        }
    }
Ejemplo n.º 8
0
        /// <summary>
        /// Checks whether there is the element of the specified type next to the given element in the specified direction.
        /// </summary>
        /// <typeparam name="T">Type of elements to check.</typeparam>
        /// <param name="movable">The element to be check.</param>
        /// <param name="direction">The direction in which elements would be tested.</param>
        /// <returns>True if there is the element of the specified type next to the given element in the specified direction, otherwise false.</returns>
        public bool IsElementNextTo <T>(MovableElement movable, Direction direction) where T : ICanCollide
        {
            if (movable == null)
            {
                return(false);
            }
            if (direction == Direction.None)
            {
                return(false);
            }
            Rect rect = TryMoveViaPortal(movable, direction) ?? TryMove(movable, direction);
            bool b    = true;

            foreach (var el in _gameBoard.Elements.OfType <T>())
            {
                if (el.Equals(movable))
                {
                    continue;
                }
                b = b && CheckCollision(el, rect);
            }
            return(CheckBoardMovementPossibility(rect, _gameBoard) && CheckMovement(movable, direction, _gameBoard) && b);
        }
Ejemplo n.º 9
0
        private bool CheckMovement(MovableElement movable, Direction direction, GameBoard board)
        {
            int ind        = (int)(((int)movable.X) * board.Rows + (int)movable.Y);
            var neighbours = _graph.Neighbours[ind];

            switch (direction)
            {
            case Direction.Left:
                return(neighbours.Contains(ind - 1));

            case Direction.Right:
                return(neighbours.Contains(ind + 1));

            case Direction.Up:
                return(neighbours.Contains((int)(ind - board.Rows)));

            case Direction.Down:
                return(neighbours.Contains((int)(ind + board.Rows)));

            default:
                return(false);
            }
        }