Пример #1
0
 void UpdateAttachedDirection()
 {
     // Don't update the attached direction if we're charging a pounce
     //  (could be stuck to a wall or ceiling, shouldn't have to hold down the button)
     if (IsChargingPounce())
     {
         return;
     }
     Utility.Directions oldDirection = attachedDirection;
     attachedDirection = Utility.Directions.Null;
     if (input.isDown(PlayerInput.Key.left) && physicsEntity.IsOnLeftWall())
     {
         attachedDirection = Utility.Directions.Left;
     }
     else if (input.isDown(PlayerInput.Key.right) && physicsEntity.IsOnRightWall())
     {
         attachedDirection = Utility.Directions.Right;
     }
     else if (input.isDown(PlayerInput.Key.up) && physicsEntity.IsOnCeiling())
     {
         attachedDirection = Utility.Directions.Up;
     }
     if (oldDirection == Utility.Directions.Null && attachedDirection != Utility.Directions.Null)
     {
         wallClingAudioSource.Play();
     }
 }
Пример #2
0
 void HandlePounceInput()
 {
     // None of this is relevant on remote clients
     if (!HasAuthority())
     {
         return;
     }
     if (input.isJustPressed(PlayerInput.Key.action1))
     {
         // Action key just pressed
         PounceIndicator.Show();
         photonView.RPC("RpcSetRemoteIsChargingPounce", RpcTarget.All, true);
     }
     if (input.isDown(PlayerInput.Key.action1))
     {
         // Action key is down, so charge leap
         timeSpentCharging += Time.deltaTime;
         PounceIndicator.SetPercentage(PounceChargePercentage());
     }
     else if (input.isJustReleased(PlayerInput.Key.action1))
     {
         if (CanPounce())
         {
             // Pounce
             physicsEntity.AddVelocity(CalculatePounceVelocity());
             attachedDirection = Utility.Directions.Null;
             pounceAudioSource.Play();
             pounceSecondarySoundSet.PlayRandom();
         }
         ResetPounceCharge();
         PounceIndicator.Hide();
         photonView.RPC("RpcSetRemoteIsChargingPounce", RpcTarget.All, false);
     }
 }
    void FleeInDirection(Utility.Directions direction)
    {
        // Target a location that is the maximum movement unit away from the current position
        float offset = direction == Utility.Directions.Right ? FLEE_DISTANCE : -FLEE_DISTANCE;

        // Without running into obstacles (walls/beams)
        targetX   = FindTargetBeforeObstacle(owner.transform.position.x + offset);
        hasTarget = true;
    }
Пример #4
0
 public void Repel(Vector2 forceDirection, float force)
 {
     // Distribute the force between the x and y coordinates
     forceDirection.Normalize();
     forceDirection *= force;
     // Transfer this force to the physics entity to handle it
     physicsEntity.AddVelocity(forceDirection.x, forceDirection.y);
     // Allow hunters to jump up the same wall
     mostRecentWallClingDirection = Utility.Directions.Null;
 }
 public void SetRotateDirection(Utility.Directions newDirection)
 {
     if (direction == newDirection)
     {
         return;
     }
     direction = newDirection;
     // The origin of rotation is not at the center of the object, but rather the
     //  center of the sprite, so we need to account for that by changing its offset
     SetOffset();
     transform.eulerAngles = new Vector3(0, 0, Utility.DirectionToAngle(newDirection));
     isFlipped             = false;
 }
Пример #6
0
    void HandleWallClinging(bool wasClingingToWall)
    {
        if (physicsEntity.IsOnGround())
        {
            // After landing on the ground, make grabbing a wall in either direction
            //  reset the cling timer
            mostRecentWallClingDirection = Utility.Directions.Null;
        }
        // Convert cling direction to a Utility.Directions value for easy comparison
        Utility.Directions wallClingDirection = Utility.Directions.Null;
        if (isClingingToLeftWall)
        {
            wallClingDirection = Utility.Directions.Left;
        }
        else if (isClingingToRightWall)
        {
            wallClingDirection = Utility.Directions.Right;
        }
        // Don't reset the cling timer if this hunter has grabbed the same wall repeatedly
        bool isFirstClingOnThisWall = wallClingDirection != mostRecentWallClingDirection;
        // Whether or not this is the first frame we've grabbed this wall
        bool didJustGrabWall = !wasClingingToWall && IsClingingToWall;

        if (didJustGrabWall)
        {
            // Play wall cling sound
            animationSounds.PlayWallClingSound();
        }
        if (isFirstClingOnThisWall && didJustGrabWall)
        {
            // Reset cling time
            timeSpentClinging = 0;
            // Store direction
            mostRecentWallClingDirection = wallClingDirection;
        }
        // Reset physics entity's instructions from last frame
        physicsEntity.SetIsTryingToStickInDirection(Utility.Directions.Null);
        if (IsClingingToWall && timeSpentClinging <= MAX_CLING_TIME)
        {
            timeSpentClinging += Time.deltaTime;
            physicsEntity.SetIsTryingToStickInDirection(wallClingDirection);
            animator.SetBool("isClingingToWall", true);
            animator.SetFloat("wallClingProgress", timeSpentClinging / MAX_CLING_TIME);
        }
        else
        {
            animator.SetBool("isClingingToWall", false);
        }
    }
    public void SetIsTryingToStickInDirection(Utility.Directions direction, bool resetFirst = false)
    {
        if (resetFirst)
        {
            isTryingToStick.Reset();
        }
        switch (direction)
        {
        case Utility.Directions.Up:     isTryingToStick.above = true; break;

        case Utility.Directions.Down:   isTryingToStick.below = true; break;

        case Utility.Directions.Left:   isTryingToStick.left = true; break;

        case Utility.Directions.Right:  isTryingToStick.right = true; break;

        case Utility.Directions.Null:   isTryingToStick.Reset(); break;
        }
    }
    void FleeOrbAtPosition(Vector2 position)
    {
        Utility.Directions fleeDirection = position.x < owner.transform.position.x ?
                                           Utility.Directions.Right :
                                           Utility.Directions.Left;
        float reflexTime = Random.Range(MIN_REACTION_TIME, MAX_REACTION_TIME);

        if (alertReaction != null)
        {
            MatchManager.Instance.StopCoroutine(alertReaction);
        }
        alertReaction = MatchManager.Instance.StartCoroutine(Utility.WaitXSeconds(reflexTime, () => {
            if (owner == null)
            {
                // Owner was destroyed during this delay
                return;
            }
            FleeInDirection(fleeDirection);
        }));
    }