Example #1
0
    private void DecideToJump()
    {
        int jumpRoll = Random.Range(1, 100);

        if (jumpRoll <= JumpChance &&
            Time.time >= _lastJump + JumpDelay)
        {
            _movement.Jump();
            _lastJump = Time.time;
        }
    }
Example #2
0
    private void FightOrFlight()
    {
        if (_isFleeing != null)
        {
            return;
        }

        if (Time.time < _lastThought + thinkDelay)
        {
            return;
        }

        _lastThought = Time.time;
        _movement.ClearHorizontalMovement();

        Random generator = new Random((int)DateTime.Now.Ticks);
        int    roll      = generator.Next(0, 99);

        // Default is for the slime to do their 'threatening wiggle'...
        _animation = _facingLeft ? moveLeft : moveRight;

        if (roll >= attackChance)
        {
            _isFleeing   = false;
            _isAttacking = true;
            _facingLeft  = !(_sense.PlayerLocation.position.x > transform.position.x);

            MoveInDirection();
            _movement.Jump();

            _animation = _facingLeft ? attackLeft : attackRight;
        }

        if (roll <= fleeChance)
        {
            _isFleeing   = true;
            _isAttacking = false;

            _facingLeft = _sense.PlayerLocation.position.x > transform.position.x;
            MoveInDirection();
        }
    }
Example #3
0
 private void CheckJump()
 {
     if (Input.GetButtonUp("Jump"))
     {
         if (_movement.MovementType == SidescrollingMovementType.Jumping)
         {
             isJumping = false;
             _movement.HaltJump();
         }
     }
     else if (Input.GetButtonDown("Jump"))
     {
         if (_movement.MovementType == SidescrollingMovementType.Grounded)
         {
             DebugMessage("Player is jumping!");
             isJumping = true;
             _movement.Jump();
         }
     }
 }
Example #4
0
    protected void DetectJumpCommand()
    {
        if (!canJump)
        {
            return;
        }

        if (_control.GetAxis(JumpAxis) == 0)
        {
            if (_movement.MovementType == SidescrollingMovementType.Jumping)
            {
                _movement.HaltJump();
            }

            return;
        }

        _movement.Jump();
        _isJumping = true;
    }