예제 #1
0
        /// <summary>
        /// Checks if the user tapped or swiped.
        /// </summary>
        public void GetInputUp()
        {
            //Gets the moment the player lifts up on the screen or mouse button.
            if (Input.GetMouseButtonUp(0))
            {
                Vector2 endTap = Input.mousePosition;
                // the distance between when the player tapped down and when the player lifted up.
                float distanceMoved = Vector2.Distance(endTap, startTap);
                EnemyProtection.SwipeDirection direction = EnemyProtection.SwipeDirection.up;

                //If the two tap points are far enough apart and if you targeted an enemy.
                if (distanceMoved > swipeDistanceNeeded)
                {
                    //check if the player moved their finger vertical or horzontal
                    if (System.Math.Abs(endTap.y - startTap.y) > (System.Math.Abs(endTap.x - startTap.x)))
                    {
                        //Checks if they moved up or down.
                        if (endTap.y > startTap.y)
                        {
                            direction = EnemyProtection.SwipeDirection.up;
                            //Debug.Log("direction = " + direction + " and distanceMoved = " + distanceMoved);
                        }
                        else
                        {
                            direction = EnemyProtection.SwipeDirection.down;
                            //Debug.Log("direction = " + direction + " and distanceMoved = " + distanceMoved);
                        }
                    }
                    else
                    {
                        //Checks if they moved left or right.
                        if (endTap.x > startTap.x)
                        {
                            direction = EnemyProtection.SwipeDirection.right;
                            //Debug.Log("direction = " + direction + " and distanceMoved = " + distanceMoved);
                        }
                        else
                        {
                            direction = EnemyProtection.SwipeDirection.left;
                            //Debug.Log("direction = " + direction + " and distanceMoved = " + distanceMoved);
                        }
                    }
                }
                else
                {
                    direction = EnemyProtection.SwipeDirection.tap;
                    //Debug.Log("direction = " + direction + " and distanceMoved = " + distanceMoved);
                }

                if (targetedEnemy != null)
                {
                    targetedEnemy.TakeDamage(1, direction);

                    //Once we send damage, we make it null to refresh the tap process.
                    targetedEnemy = null;
                }
            }
        }
예제 #2
0
 /// <summary>
 /// Overload of Take damage to account for player's swipe direction.
 /// </summary>
 /// <param name="amount">Amount of damage</param>
 /// <param name="direction">Direction of swipe</param>
 public void TakeDamage(int amount, EnemyProtection.SwipeDirection direction = EnemyProtection.SwipeDirection.tap)
 {
     if (canTakeDamage)
     {
         currentLife -= amount;
     }
     else
     {
         enemyProtection.SwipedByPlayer(direction);
     }
     if (currentLife <= 0)
     {
         BeenKilled();
     }
     else
     {
         beenHit.Invoke();
     }
 }
예제 #3
0
 /// <summary>
 /// Returns a sprite that represetns a swipe direction
 /// </summary>
 /// <param name="swipe">The direction of swipe</param>
 /// <returns>Siwpe sprite</returns>
 public Sprite GetSwipeDirectionSprite(EnemyProtection.SwipeDirection swipe)
 {
     if (swipe == EnemyProtection.SwipeDirection.up)
     {
         return(swipeUp);
     }
     else if (swipe == EnemyProtection.SwipeDirection.down)
     {
         return(swipeDown);
     }
     else if (swipe == EnemyProtection.SwipeDirection.right)
     {
         return(swipeRight);
     }
     else if (swipe == EnemyProtection.SwipeDirection.left)
     {
         return(swipeLeft);
     }
     else
     {
         return(tap);
     }
 }
예제 #4
0
 /// <summary>
 /// Called the GetSwipeDirectionSprite function from swipeDirectionDisplay.
 /// </summary>
 /// <param name="swipe">Direction of swipe</param>
 /// <returns>Image for direction of swipe</returns>
 public Sprite GetSwipeDirectionSprite(EnemyProtection.SwipeDirection swipe)
 {
     return(swipeDirectionDisplay.GetSwipeDirectionSprite(swipe));
 }