示例#1
0
    // Update is called once per frame
    void Update()
    {
        if (Input.GetKeyDown(KeyCode.A))
        {
            j_dir     = JumpDirection.LEFT;
            isJumping = true;
            endPos    = leftEndPos;
        }
        else if (Input.GetKeyDown(KeyCode.D))
        {
            j_dir     = JumpDirection.RIGHT;
            isJumping = true;
            endPos    = rightEndPos;
        }

        if (isJumping && !isDJumping)
        {
            JumpRotation();
            Jumping();
        }

        if (isDJumping)
        {
            DoubleJumping();
        }
    }
示例#2
0
        private void JumpSelect(JumpDirection direction)
        {
            // choose our selection start point for the selection right before we jump
            VirtualSnapshotPoint start = View.Caret.Position.VirtualBufferPosition;

            if (!View.Selection.IsEmpty)
            {
                // we already have a selection, if our caret is at a higher position
                // than the end of our selection, then our selection starts at our end
                // point - all other possible cases (i.e. our caret is > selection start)
                // the selection start is our start point
                start = View.Selection.Start;
                if (View.Caret.Position.VirtualBufferPosition < View.Selection.End)
                {
                    start = View.Selection.End;
                }
            }

            Jump(direction);

            // use the new caret position as our selection end point
            VirtualSnapshotPoint end = View.Caret.Position.VirtualBufferPosition;

            View.Selection.Select(start, end);
        }
    void setJumpState(JumpState state)
    {
        leftDashIndicator.SetActive(state == JumpState.Dash && velocity.x < 0);
        rightDashIndicator.SetActive(state == JumpState.Dash && velocity.x >= 0);

        if (jumpState != JumpState.Ascending && state == JumpState.Ascending)
        {
            jumpStartTime = Time.time;
        }
        jumpState      = state;
        jumpStateStart = Time.time;
        if (velocity.x == 0)
        {
            jumpDirection = JumpDirection.Neutral;
        }
        else if (velocity.x > 0)
        {
            jumpDirection = JumpDirection.Right;
        }
        else
        {
            jumpDirection = JumpDirection.Left;
        }

        if (state == JumpState.Grounded)
        {
            jumpCount = 0;
        }
        if (state == JumpState.Ascending)
        {
            jumpCount++;
        }
    }
示例#4
0
 // Update is called once per frame
 void Update()
 {
     if (jumpDirection != JumpDirection.None)
     {
         print("Jump time: " + jumpTime + "Time passed: " + timePassed);
         timePassed += Time.deltaTime;// * jumpTime;
         float multiplier = jumpDirection == JumpDirection.Left ? -1 : 1;
         if (timePassed > jumpTime)
         {
             jumpDirection = JumpDirection.None;
             timePassed    = jumpTime;
             //return;
         }
         float x = timePassed / jumpTime * 4;
         float d = 1.4f;
         float y = (-Mathf.Pow(x, 2f) + (d + 4f) * x) / d;
         x *= multiplier;
         Vector3 newPosition = new Vector3(x + 8, y, -1);
         pig.position = newPosition;
     }
     else
     {
         if (Input.GetKeyDown("left"))
         {
             currentIndex++;
             JumpLeft();
         }
         else if (Input.GetKeyDown("right"))
         {
             currentIndex++;
             JumpRight();
         }
     }
 }
示例#5
0
        private void Start()
        {
            _jumpDirection = GetComponent <PlatformController>().Direction;
            _movementTime  = Random.Range(1.5f, 3f);
            _range         = Random.Range(4f, 8f);


            var position = transform.position;

            switch (_jumpDirection)
            {
            case JumpDirection.Left:
                _finalPosition = new Vector3(position.x - _range / 2, position.y, position.z);
                break;

            case JumpDirection.Right:
                _finalPosition = new Vector3(position.x, position.y, position.z - _range / 2);
                break;

            default:
                throw new ArgumentOutOfRangeException();
            }

            transform.DOMove(_finalPosition, _movementTime / 2)
            .OnComplete(Move)
            .SetEase(Ease.Linear);
        }
示例#6
0
    IEnumerator JumpCoroutine(JumpDirection direction, Clickable clickable)
    {
        SetMovementState(AlienMovementState.Jump, direction);
        readyToJump = false;

        library.audioController.Jump();

        switch (direction)
        {
        case JumpDirection.RightUp: yield return(childAnim.GetComponent <Animator>().PlayAnimation(1)); break;

        case JumpDirection.LeftUp: yield return(childAnim.GetComponent <Animator>().PlayAnimation(2)); break;

        case JumpDirection.RightDown: yield return(childAnim.GetComponent <Animator>().PlayAnimation(3)); break;

        case JumpDirection.LeftDown: yield return(childAnim.GetComponent <Animator>().PlayAnimation(4)); break;
        }

        transform.position = childAnim.transform.position;
        transform.GetComponent <RectTransform>().anchoredPosition = new Vector2(transform.GetComponent <RectTransform>().anchoredPosition.x, transform.GetComponent <RectTransform>().anchoredPosition.y - fChild.GetComponent <RectTransform>().anchoredPosition.y);

        //      SetLastTarget(clickable);

        currentFloor = clickable.GetFloor();

        MoveToTarget();
    }
示例#7
0
        private void GenerateCoin(JumpDirection direction)
        {
            var lastPlatform    = _platformSystem.LastPlatform();
            var preLastPlatform = _platformSystem.PreLastPlatform();

            var lastPlatformPosition    = lastPlatform.transform.position;
            var preLastPlatformPosition = preLastPlatform.transform.position;

            var   positionX = preLastPlatformPosition.x + (lastPlatformPosition.x - preLastPlatformPosition.x) / 2;
            float positionY;
            var   positionZ = preLastPlatformPosition.z + (lastPlatformPosition.z - preLastPlatformPosition.z) / 2;
            float rotationY;

            switch (direction)
            {
            case JumpDirection.Left:
                positionY = (lastPlatformPosition.z - preLastPlatformPosition.z) / 2;
                rotationY = 0;
                break;

            case JumpDirection.Right:
                positionY = (lastPlatformPosition.x - preLastPlatformPosition.x) / 2;
                rotationY = 90;
                break;

            default:
                throw new ArgumentOutOfRangeException();
            }

            Instantiate(
                coinPrefab,
                new Vector3(positionX, positionY, positionZ),
                Quaternion.Euler(0, rotationY, 0)
                );
        }
示例#8
0
 public void jumpWithDirection(JumpDirection direction)
 {
     if (enabled && controlsActive)
     {
         jumpDirection = direction;
     }
 }
示例#9
0
        private void CalculateNewPosition(JumpDirection direction)
        {
            var     targetPosition = Target.position;
            Vector3 newPosition;

            switch (direction)
            {
            case JumpDirection.Left:
                newPosition = new Vector3(
                    targetPosition.x + offset.x / .75f,
                    offset.y,
                    targetPosition.z + offset.z / 1.5f);
                break;

            case JumpDirection.Right:
                newPosition = new Vector3(
                    targetPosition.x + offset.x,
                    offset.y,
                    targetPosition.z + offset.z);
                break;

            default:
                throw new ArgumentOutOfRangeException();
            }

            transform.DOMove(newPosition, CameraMovingDuration).SetEase(Ease.OutQuint);
        }
示例#10
0
        private GameObject CreatePlatform(JumpDirection direction, bool isMoving)
        {
            Vector3 position;
            Vector3 platformSize;

            if (_platforms.Count == 0)
            {
                position     = Vector3.zero;
                platformSize = Vector3.zero;
            }
            else
            {
                var lastPlatform = _platforms.Last();
                position     = lastPlatform.GetComponent <PlatformController>().InitialPosition;
                platformSize = Vector3.Scale(lastPlatform.transform.localScale,
                                             lastPlatform.GetComponent <BoxCollider>().bounds.size);
            }

            GameObject platform;
            var        a = (platformSize.x + platformSize.z) / 2;
            var        platformDistance    = Random.Range(a, a * 2) + a / 1.5f;
            var        platformsData       = _gameData.Platforms;
            var        activePlatformsData = platformsData.Where(p => p.IsActive).ToArray();
            var        platformData        = activePlatformsData[Random.Range(0, activePlatformsData.Length)];

            switch (direction)
            {
            case JumpDirection.Left:
                platform = Instantiate(
                    platformData.Prefab,
                    new Vector3(position.x, position.y, position.z + platformDistance),
                    Quaternion.identity
                    );
                break;

            case JumpDirection.Right:
                platform = Instantiate(
                    platformData.Prefab,
                    new Vector3(position.x + platformDistance, position.y, position.z),
                    Quaternion.identity
                    );
                break;

            default:
                throw new ArgumentOutOfRangeException();
            }

            var platformController = platform.GetComponent <PlatformController>();

            platformController.Direction = direction;
            platformController.IsMoving  = isMoving;

            return(platform);
        }
示例#11
0
 private void MoveRigidBody(JumpDirection jumpDirection)
 {
     if (jumpDirection == JumpDirection.left)
     {
         rb2D.AddForce(new Vector2(-widthForce, heightForce));
     }
     else // jump right
     {
         rb2D.AddForce(new Vector2(widthForce, heightForce));
     }
 }
示例#12
0
    public JumpEvent(string jumpDirection)
    {
        if (jumpDirection == "right")
        {
            this.jumpDirection = JumpDirection.right;
        }

        if (jumpDirection == "left")
        {
            this.jumpDirection = JumpDirection.left;
        }
    }
示例#13
0
        private void GeneratePlatformGenerate(JumpDirection direction, bool isMoving)
        {
            _platforms.Add(CreatePlatform(direction, isMoving));

            if (_platforms.Count > 4)
            {
                var firstPlatform = _platforms.First();
                firstPlatform.transform.DOKill();
                Destroy(firstPlatform);
                _platforms.Remove(firstPlatform);
            }
        }
示例#14
0
    public bool justDie3;     // die from timeout


    void Start()
    {
        justDie1         = false;
        justDie2         = false;
        justDie3         = false;
        justDead         = true;
        canMove          = true;
        lastJump         = JumpDirection.not_jump;
        nowJump          = JumpDirection.not_jump;
        perc             = 1f;
        endPosition      = gameObject.transform.position;
        environmentMaker = GameObject.Find("Environment").GetComponent <EnvironmentMaker>();
        cameraController = GameObject.Find("Level").GetComponent <CameraController> ();
        audioSource      = gameObject.GetComponent <AudioSource> ();
    }
示例#15
0
    public void SetMovementState(AlienMovementState state, JumpDirection direction)
    {
        if (state == AlienMovementState.Jump)
        {
            switch (direction)
            {
            case JumpDirection.LeftDown: alienParts.SetLeft(); alienParts.SetJumpDown(); break;

            case JumpDirection.RightDown: alienParts.SetRight(); alienParts.SetJumpDown(); break;

            case JumpDirection.LeftUp: alienParts.SetLeft(); alienParts.SetJumpUp(); break;

            case JumpDirection.RightUp: alienParts.SetRight(); alienParts.SetJumpUp(); break;
            }
        }
        SetMovementState(state);
    }
示例#16
0
        private Vector3 CalculateDirection()
        {
            var dir = _jumpDirection;

            if (_ball.position.y < _currentTransform.position.y)
            {
                if (_type == JumpDirection.DOWN)
                {
                    return(Vector3.zero);
                }
                else
                {
                    _type  = JumpDirection.DOWN;
                    dir.x *= _ball.position.x < _currentTransform.position.x ? -1 : 1;
                }
            }
            else
            {
                switch (_type)
                {
                case JumpDirection.LEFT:
                    _type = JumpDirection.RIGHT;
                    break;

                case JumpDirection.RIGHT:
                    _type  = JumpDirection.LEFT;
                    dir.x *= -1;
                    break;

                default:
                    if (_ball.position.x < _currentTransform.position.x)
                    {
                        _type = JumpDirection.RIGHT;
                    }
                    else
                    {
                        _type  = JumpDirection.LEFT;
                        dir.x *= -1;
                    }
                    break;
                }
            }
            return(dir);
        }
示例#17
0
        private void ExecuteJumpSelect(ITextControl textControl, JumpDirection direction, bool jumpOutsideEdge, bool skipClosestEdge)
        {
            // in the case of a disjoint selection we just wipe it all and start where the caret is, otherwise we add to
            // the active selection - maybe in future we'll support disjoint jumping...
            var startPos = textControl.Caret.Position.Value;

            if (textControl.Selection.HasSelection() && !textControl.Selection.IsDisjoint())
            {
                startPos = textControl.Selection.GetAnchorPoint();
            }

            ExecuteJump(textControl, direction, jumpOutsideEdge, skipClosestEdge);

            var endPos = textControl.Caret.Position.Value;

            if (textControl.Selection.IsDisjoint())
            {
                textControl.Selection.Collapse();
            }
            textControl.Selection.SetRange(new TextRange(startPos.ToDocOffset(), endPos.ToDocOffset()));
        }
        private void Turn(JumpDirection newJumpDirection)
        {
            if (_jumpDirection != newJumpDirection)
            {
                switch (newJumpDirection)
                {
                case JumpDirection.Left:
                    transform.DORotate(new Vector3(0, -90, 0), .33f).SetEase(Ease.Linear);
                    break;

                case JumpDirection.Right:
                    transform.DORotate(new Vector3(0, 0, 0), .33f).SetEase(Ease.Linear);
                    break;

                default:
                    throw new ArgumentOutOfRangeException();
                }
            }

            _jumpDirection = newJumpDirection;
        }
示例#19
0
 private void Jumping()
 {
     t += Time.deltaTime * speed;
     if (startCurve)
     {
         Vector3 center = (startPos + endPos) * 0.5f;
         center.y          += jumpHeight;
         transform.position = Util.Math.GetBezierCurve(startPos, center, endPos, t);
     }
     else
     {
         var p = Util.Math.GetLinearCurve(startPos, endPos, t);
         transform.position = p;
     }
     if (t >= 0.5f)
     {
         var a = (Input.GetKeyDown(KeyCode.A));
         var d = (Input.GetKeyDown(KeyCode.D));
         if (a || d)
         {
             isDJumping = true;
             startPos   = transform.position;
             j_dir      = (a) ? JumpDirection.LEFT : JumpDirection.RIGHT;
             t          = 0.0f;
         }
     }
     if (t > 1.0f)
     {
         t = 0.0f;
         if (startCurve == false)
         {
             playerRenderer.flipY = true;
             startCurve           = true;
         }
         isJumping = false;
         animControl.Play(PlayerAnim.Animation.Run_2);
         startPos = transform.position;
     }
 }
示例#20
0
        protected void ExecuteJumpSelect(IDataContext context, JumpDirection direction)
        {
            var solution = context.GetData(JetBrains.ProjectModel.DataContext.ProjectModelDataConstants.SOLUTION);

            if (solution == null)
            {
                return;
            }

            var textControl = context.GetData(JetBrains.TextControl.DataContext.TextControlDataConstants.TEXT_CONTROL);

            if (textControl == null)
            {
                return;
            }

            var settingsStore   = solution.GetSettingsStore();
            var jumpOutsideEdge = settingsStore.GetValue((RiderBlockJumperSettings x) => x.JumpOutsideEdge);
            var skipClosestEdge = settingsStore.GetValue((RiderBlockJumperSettings x) => x.SkipClosestEdge);

            ExecuteJumpSelect(textControl, direction, jumpOutsideEdge, skipClosestEdge);
        }
示例#21
0
 private float angleForDirection(JumpDirection direction)
 {
     float angle = 0;
     switch (direction)
     {
     case JumpDirection.Left:
         angle = 90 + jumpAngle;
         break;
     case JumpDirection.Right:
         angle = 90 - jumpAngle;
         break;
     case JumpDirection.Invalid:
         break;
     }
     return angle;
 }
示例#22
0
        // Update is called once per frame
        // Use this for initialization
        private void Start()
        {
            m_CharacterController = GetComponent<CharacterController>();
            m_Camera = Camera.main;
            m_OriginalCameraPosition = m_Camera.transform.localPosition;
            m_FovKick.Setup(m_Camera);
            m_HeadBob.Setup(m_Camera, m_StepInterval);
            m_StepCycle = 0f;
            m_NextStep = m_StepCycle/2f;
            m_Jumping = false;
            m_AudioSource = GetComponent<AudioSource>();
            m_MouseLook.Init(transform , m_Camera.transform);

            tempwalkspeed=m_WalkSpeed;
            jDir=new JumpDirection();
            anim=GetComponentInChildren<Animator>();
            currentFOV=cam.fieldOfView;
        }
示例#23
0
    private void applyForceWithDirection(JumpDirection direction)
    {
        float angle = angleForDirection(direction);
        Vector3 directionVector = Quaternion.AngleAxis(angle, Vector3.forward) * Vector3.right;

        playerRigidBody.AddForce(directionVector * jumpForce, ForceMode2D.Impulse);
    }
示例#24
0
 private void resetJumpDirection()
 {
     jumpDirection = JumpDirection.Invalid;
 }
示例#25
0
        // Update is called once per frame
        private void Update()
        {
            RotateView();
            // the jump state needs to read here to make sure it is not missed
            if (!m_Jump)
            {

                m_Jump = CrossPlatformInputManager.GetButtonDown("Jump");
                hAxis=CrossPlatformInputManager.GetAxis("Horizontal");
                vAxis=CrossPlatformInputManager.GetAxis("Vertical");
                //m_WalkSpeed=tempwalkspeed;

                //get direction
                if(hAxis>0)
                {
                    jDir=JumpDirection.Right;
                }
                else if (hAxis<0)
                {
                    jDir=JumpDirection.Left;
                }
                else if(vAxis>0)
                {
                    jDir=JumpDirection.Forward;
                }
                else if(vAxis<0)
                {
                    jDir=JumpDirection.Backward;
                }
                dodging=false;
            }

            if (!m_PreviouslyGrounded && m_CharacterController.isGrounded)
            {
                StartCoroutine(m_JumpBob.DoBobCycle());
                PlayLandingSound();
                m_MoveDir.y = 0f;
                jDir=JumpDirection.Forward;
                m_Jumping = false;
            }
            if (!m_CharacterController.isGrounded && !m_Jumping && m_PreviouslyGrounded)
            {
                m_MoveDir.y = 0f;
            }

            m_PreviouslyGrounded = m_CharacterController.isGrounded;
        }
示例#26
0
        private void FixedUpdate()
        {
            float speed;
            GetInput(out speed);
            // always move along the camera forward as it is the direction that it being aimed at
            Vector3 desiredMove = transform.forward*m_Input.y + transform.right*m_Input.x;

            // get a normal for the surface that is being touched to move along it
            RaycastHit hitInfo;
            Physics.SphereCast(transform.position, m_CharacterController.radius, Vector3.down, out hitInfo,
                               m_CharacterController.height/2f);
            desiredMove = Vector3.ProjectOnPlane(desiredMove, hitInfo.normal).normalized;

            //m_MoveDir.x = desiredMove.x*speed;
            //m_MoveDir.z = desiredMove.z*speed;

            if (m_CharacterController.isGrounded)
            {
                m_MoveDir.y = -m_StickToGroundForce;
                jumpCount=0;
                if(!dodging)
                {
                m_WalkSpeed=tempwalkspeed;
                }
                if (m_Jump)
                {
                    //new code::::DODGE
                    jumpCount++;
                    switch (jDir) {
                    case JumpDirection.Forward:
                        m_MoveDir.y = m_JumpSpeed;
                    break;
                    case JumpDirection.Backward:
                        dodging=true;
                        m_WalkSpeed=m_DodgeSpeed;
                        m_MoveDir.y =2f;
                        m_MoveDir.z = -m_DodgeSpeed;
                        break;
                    case JumpDirection.Left:
                        dodging=true;
                        m_WalkSpeed=m_DodgeSpeed;
                        m_MoveDir.y =2f;
                        m_MoveDir.x = -m_DodgeSpeed;
                        break;
                    case JumpDirection.Right:
                        dodging=true;
                        m_WalkSpeed=m_DodgeSpeed;
                        m_MoveDir.y =2f;
                        m_MoveDir.x = m_DodgeSpeed;
                        break;
                    }

                    jDir=JumpDirection.Forward;

                    //new code end
                    PlayJumpSound();
                    m_Jump = false;
                    m_Jumping = true;

                }

            }
            else
            {
                m_MoveDir += Physics.gravity*m_GravityMultiplier*Time.fixedDeltaTime;
                if(m_Jump && Input.GetAxis("Vertical")>0 && jumpCount <2)
                {
                    //jetpack

                    jumpCount++;
                    m_MoveDir.y=15f;
                    m_MoveDir.z++;
                }
                m_Jump=false;
            }

            m_MoveDir.x = desiredMove.x*speed;
            m_MoveDir.z = desiredMove.z*speed;

            m_CollisionFlags = m_CharacterController.Move(m_MoveDir*Time.fixedDeltaTime);

            ProgressStepCycle(speed);
            UpdateCameraPosition(speed);
        }
示例#27
0
 public void GeneratePlatform(JumpDirection jumpDirection, bool isMoving)
 {
     OnPlatformGenerate?.Invoke(jumpDirection, isMoving);
 }
示例#28
0
 public void ResetPosition()
 {
     _currentTransform.position = _startPosition;
     _type = JumpDirection.DOWN;
 }
示例#29
0
 void JumpRight()
 {
     print("Jumping right");
     jumpDirection = JumpDirection.Right;
     timePassed    = 0.0f;
 }
示例#30
0
        private IEnumerator Start()
        {
            _currentJumpDirection = JumpDirection.Right;
            _isAvailableMoving    = true;

            SpawnPlayer();
            SetCameraTarget();

            yield return(null);

            PlatformEventSystem.Instance.OnVisited += centered =>
            {
                var isMoving          = false;
                var nextJumpDirection = (JumpDirection)Random.Range(0, 2);

                if (_isAvailableMoving && _currentJumpDirection == nextJumpDirection)
                {
                    isMoving           = Random.value <= ChanceToMovingPlatform;
                    _isAvailableMoving = !isMoving;
                }
                else if (!_isAvailableMoving)
                {
                    nextJumpDirection  = _currentJumpDirection;
                    _isAvailableMoving = true;
                }

                GameEventSystem.Instance.MoveCamera(nextJumpDirection);
                GameEventSystem.Instance.GeneratePlatform(nextJumpDirection, isMoving);
                GameEventSystem.Instance.ChangeDirection(nextJumpDirection);

                var scorePopup = Instantiate(scorePopupPrefab, _player.transform).GetComponent <ScorePopup>();
                int earnedScore;

                if (centered)
                {
                    earnedScore   = 5;
                    _score       += earnedScore;
                    _centerSteps += 1;
                    Instantiate(centeredStepPrefab, _player.transform.parent);
                }
                else
                {
                    earnedScore  = 1;
                    _score      += earnedScore;
                    _centerSteps = 0;
                }
                _steps += 1;

                scorePopup.SetText("+" + earnedScore);
                GameEventSystem.Instance.UpdateScore(_score);

                if (_steps % StepsToCoin == 0 || _centerSteps == CenterStepsToCoin)
                {
                    GameEventSystem.Instance.GenerateCoin(nextJumpDirection);
                    _centerSteps = 0;
                }

                _currentJumpDirection = nextJumpDirection;
            };

            GameEventSystem.Instance.OnCoinPickuped += () =>
            {
                GameEventSystem.Instance.UpdateCoins(++_coins);
            };
        }
示例#31
0
    public bool IsJumpPossible(JumpDirection direction)
    {
        if (direction == JumpDirection.Up || direction == JumpDirection.LastChance)
        {
            //Assign the Raycast Points.
            Vector2 jumpPoint1a;
            Vector2 jumpPoint1b;
            Vector2 jumpPoint1c;
            Vector2 jumpPoint1d;
            Vector2 jumpPoint1e;

            Vector2 jumpPoint2a;
            Vector2 jumpPoint2b;
            Vector2 jumpPoint2c;
            Vector2 jumpPoint2d;
            Vector2 jumpPoint2e;
            Vector2 jumpPoint2f;

            Vector2 jumpPoint3a;
            Vector2 jumpPoint3b;

            if (controller.collisions.faceDir == 1)
            {
                jumpPoint1a = new Vector2(enemyCollider.bounds.max.x, enemyCollider.bounds.min.y);
                jumpPoint1b = new Vector2(jumpPoint1.bounds.max.x, jumpPoint1.bounds.min.y);
                jumpPoint1c = new Vector2(jumpPoint2.transform.position.x, jumpPoint2.bounds.min.y);
                jumpPoint1d = new Vector2(jumpPoint3.bounds.min.x, jumpPoint3.bounds.min.y);
                jumpPoint1e = new Vector2(jumpPoint4.bounds.min.x, jumpPoint4.bounds.min.y);

                jumpPoint2a = new Vector2(enemyCollider.bounds.min.x, enemyCollider.bounds.max.y);
                jumpPoint2b = new Vector2(jumpPoint1.bounds.min.x, jumpPoint1.bounds.max.y);
                jumpPoint2c = new Vector2(jumpPoint2.bounds.min.x, jumpPoint2.bounds.max.y);
                jumpPoint2d = new Vector2(jumpPoint2.bounds.max.x, jumpPoint2.bounds.max.y);
                jumpPoint2e = new Vector2(jumpPoint3.bounds.max.x, jumpPoint3.bounds.max.y);
                jumpPoint2f = new Vector2(jumpPoint4.bounds.max.x, jumpPoint4.bounds.max.y);

                jumpPoint3a = new Vector2(jumpPoint3.bounds.max.x, jumpPoint3.bounds.min.y);
                jumpPoint3b = new Vector2(jumpPoint4.bounds.max.x, jumpPoint4.bounds.min.y);
            }
            else
            {
                jumpPoint1a = new Vector2(enemyCollider.bounds.min.x, enemyCollider.bounds.min.y);
                jumpPoint1b = new Vector2(jumpPoint1.bounds.min.x, jumpPoint1.bounds.min.y);
                jumpPoint1c = new Vector2(jumpPoint2.transform.position.x, jumpPoint2.bounds.min.y);
                jumpPoint1d = new Vector2(jumpPoint3.bounds.max.x, jumpPoint3.bounds.min.y);
                jumpPoint1e = new Vector2(jumpPoint4.bounds.max.x, jumpPoint4.bounds.min.y);

                jumpPoint2a = new Vector2(enemyCollider.bounds.max.x, enemyCollider.bounds.max.y);
                jumpPoint2b = new Vector2(jumpPoint1.bounds.max.x, jumpPoint1.bounds.max.y);
                jumpPoint2c = new Vector2(jumpPoint2.bounds.max.x, jumpPoint2.bounds.max.y);
                jumpPoint2d = new Vector2(jumpPoint2.bounds.min.x, jumpPoint2.bounds.max.y);
                jumpPoint2e = new Vector2(jumpPoint3.bounds.min.x, jumpPoint3.bounds.max.y);
                jumpPoint2f = new Vector2(jumpPoint4.bounds.min.x, jumpPoint4.bounds.max.y);

                jumpPoint3a = new Vector2(jumpPoint3.bounds.min.x, jumpPoint3.bounds.min.y);
                jumpPoint3b = new Vector2(jumpPoint4.bounds.min.x, jumpPoint4.bounds.min.y);
            }

            RaycastHit2D segment1a = Physics2D.Linecast(jumpPoint1a, jumpPoint1b, patrolMask);
            RaycastHit2D segment1b = Physics2D.Linecast(jumpPoint1b, jumpPoint1c, patrolMask);
            RaycastHit2D segment1c = Physics2D.Linecast(jumpPoint1c, jumpPoint1d, patrolMask);
            RaycastHit2D segment1d = Physics2D.Linecast(jumpPoint1d, jumpPoint1e, patrolMask);

            RaycastHit2D segment2a = Physics2D.Linecast(jumpPoint2a, jumpPoint2b, patrolMask);
            RaycastHit2D segment2b = Physics2D.Linecast(jumpPoint2b, jumpPoint2c, patrolMask);
            RaycastHit2D segment2c = Physics2D.Linecast(jumpPoint2c, jumpPoint2d, patrolMask);
            RaycastHit2D segment2d = Physics2D.Linecast(jumpPoint2d, jumpPoint2e, patrolMask);
            RaycastHit2D segment2e = Physics2D.Linecast(jumpPoint2e, jumpPoint2f, patrolMask);

            RaycastHit2D segment3a = Physics2D.Linecast(jumpPoint1c, jumpPoint3a, patrolMask);
            RaycastHit2D segment3b = Physics2D.Linecast(jumpPoint3a, jumpPoint3b, patrolMask);

            //check the jump raycasts.

            //Always reject hits on 2a and 2d.
            if (segment2a || segment2d)
            {
                return false;
            }

            if (segment1a)
            {
                if (segment1a.collider.gameObject != targetPlatform.gameObject)
                {
                    return false;
                }
            }

            //1b.
            if (segment1b)
            {
                //If hit we can check if below the hit is a platform
                Vector2 hitOrigin = new Vector2(segment1b.point.x - (1 * controller.collisions.faceDir), segment1b.collider.bounds.min.y - .5f);
                RaycastHit2D hit = Physics2D.Raycast(hitOrigin, Vector2.down, 200, patrolMask);
                if (hit)
                {
                    //If the platform below is not the patrol platform and is higher than the patrol platform.
                    if (hit.collider.gameObject != patrolPlatform.gameObject && hit.collider.bounds.max.y > patrolPlatform.GetComponent<Collider2D>().bounds.max.y)
                    {
                        return true;
                    }
                }
                return false;
            }

            //2b.
            if (segment2b)
            {
                //If hit we can check if below the hit is a platform
                Vector2 hitOrigin = new Vector2(segment2b.point.x - (1 * controller.collisions.faceDir), segment2b.collider.bounds.min.y - .5f);
                RaycastHit2D hit = Physics2D.Raycast(hitOrigin, Vector2.down, 200, patrolMask);
                if (hit)
                {
                    //If the platform below is not the patrol platform and is higher than the patrol platform.
                    if (hit.collider.gameObject != patrolPlatform.gameObject && hit.collider.bounds.max.y > patrolPlatform.GetComponent<Collider2D>().bounds.max.y)
                    {
                        return true;
                    }
                }
                return false;
            }

            //2c.
            if (segment2c)
            {
                //If hit we can check if below the hit is a platform
                Vector2 hitOrigin = new Vector2(segment2c.point.x - (1 * controller.collisions.faceDir), segment2c.collider.bounds.min.y - .5f);
                RaycastHit2D hit = Physics2D.Raycast(hitOrigin, Vector2.down, 200, patrolMask);
                if (hit)
                {
                    //If the platform below is not the patrol platform and is higher than the patrol platform.
                    if (hit.collider.gameObject != patrolPlatform.gameObject && hit.collider.bounds.max.y > patrolPlatform.GetComponent<Collider2D>().bounds.max.y)
                    {
                        return true;
                    }
                }
                return false;
            }

            //1c.
            if (segment1c)
            {
                if (direction == JumpDirection.Up)
                {
                    //If the platform hit is higher than the patrol platform.
                    if (segment1c.collider.bounds.max.y > patrolPlatform.GetComponent<Collider2D>().bounds.max.y)
                    {
                        //If we hit the top of a platform.
                        if (segment1c.point.y >= segment1c.collider.bounds.max.y - .25f && segment1c.point.y <= segment1c.collider.bounds.max.y + .25f)
                        {
                            return true;
                        }

                        else {
                            //If they hit we can check if below the hit is a platform
                            Vector2 hitOrigin = new Vector2(segment1c.point.x - (1 * controller.collisions.faceDir), segment1c.point.y);
                            RaycastHit2D hit = Physics2D.Raycast(hitOrigin, Vector2.down, 200, patrolMask);
                            if (hit)
                            {
                                //If the platform below is not the patrol platform.
                                if (hit.collider.gameObject != patrolPlatform.gameObject)
                                {
                                    return true;
                                }
                            }
                        }
                    }
                }

                //Last chance ignores if the platform is higher than the patrol platform.
                else
                {
                    //If we hit the top of a platform.
                    if (segment1c.point.y >= segment1c.collider.bounds.max.y - .25f && segment1c.point.y <= segment1c.collider.bounds.max.y + .25f)
                    {
                        return true;
                    }

                    else {
                        //If they hit we can check if below the hit is a platform
                        Vector2 hitOrigin = new Vector2(segment1c.point.x - (1 * controller.collisions.faceDir), segment1c.point.y);
                        RaycastHit2D hit = Physics2D.Raycast(hitOrigin, Vector2.down, 200, patrolMask);
                        if (hit)
                        {
                            //If the platform below is not the patrol platform.
                            if (hit.collider.gameObject != patrolPlatform.gameObject)
                            {
                                return true;
                            }
                        }
                    }
                }
            }

            //1d.
            if (segment1d)
            {
                if (direction == JumpDirection.Up)
                {
                    //If the platform hit is higher than the patrol platform.
                    if (segment1d.collider.bounds.max.y > patrolPlatform.GetComponent<Collider2D>().bounds.max.y)
                    {
                        //If we hit the top of a platform.
                        if (segment1d.point.y >= segment1d.collider.bounds.max.y - .25f && segment1d.point.y <= segment1d.collider.bounds.max.y + .25f)
                        {
                            return true;
                        }

                        else {
                            //If they hit we can check if below the hit is a platform
                            Vector2 hitOrigin = new Vector2(segment1d.point.x - (1 * controller.collisions.faceDir), segment1d.point.y);
                            RaycastHit2D hit = Physics2D.Raycast(hitOrigin, Vector2.down, 200, patrolMask);
                            if (hit)
                            {
                                //If the platform below is not the patrol platform.
                                if (hit.collider.gameObject != patrolPlatform.gameObject)
                                {
                                    return true;
                                }
                            }
                        }
                    }
                }

                //Last chance ignores if the platform is higher than the patrol platform.
                else
                {
                    //If we hit the top of a platform.
                    if (segment1d.point.y >= segment1d.collider.bounds.max.y - .25f && segment1d.point.y <= segment1d.collider.bounds.max.y + .25f)
                    {
                        return true;
                    }

                    else {
                        //If they hit we can check if below the hit is a platform
                        Vector2 hitOrigin = new Vector2(segment1d.point.x - (1 * controller.collisions.faceDir), segment1d.point.y);
                        RaycastHit2D hit = Physics2D.Raycast(hitOrigin, Vector2.down, 200, patrolMask);
                        if (hit)
                        {
                            //If the platform below is not the patrol platform.
                            if (hit.collider.gameObject != patrolPlatform.gameObject)
                            {
                                return true;
                            }
                        }
                    }
                }
            }

            //2e.
            if (segment2e)
            {
                if (segment3b)
                {
                    if (segment2e.collider.gameObject != segment3b.collider.gameObject)
                    {
                        return false;
                    }
                }
                if (segment1d)
                {
                    if (segment2e.collider.gameObject != segment1d.collider.gameObject)
                    {
                        return false;
                    }
                }
            }

            //3a.
            if (segment3a)
            {
                if (direction == JumpDirection.Up)
                {
                    //If the platform hit is higher than the patrol platform.
                    if (segment3a.collider.bounds.max.y > patrolPlatform.GetComponent<Collider2D>().bounds.max.y)
                    {
                        //If we hit the top of a platform.
                        if (segment3a.point.y >= segment3a.collider.bounds.max.y - .25f && segment3a.point.y <= segment3a.collider.bounds.max.y + .25f)
                        {
                            return true;
                        }

                        else {
                            //If they hit we can check if below the hit is a platform
                            Vector2 hitOrigin = new Vector2(segment3a.point.x - (1 * controller.collisions.faceDir), segment3a.point.y);
                            RaycastHit2D hit = Physics2D.Raycast(hitOrigin, Vector2.down, 200, patrolMask);
                            if (hit)
                            {
                                //If the platform below is not the patrol platform.
                                if (hit.collider.gameObject != patrolPlatform.gameObject)
                                {
                                    return true;
                                }
                            }
                        }
                    }
                }

                //Last chance ignores if the platform is higher than the patrol platform.
                else
                {
                    //If we hit the top of a platform.
                    if (segment3a.point.y >= segment3a.collider.bounds.max.y - .25f && segment3a.point.y <= segment3a.collider.bounds.max.y + .25f)
                    {
                        return true;
                    }

                    else {
                        //If they hit we can check if below the hit is a platform
                        Vector2 hitOrigin = new Vector2(segment3a.point.x - (1 * controller.collisions.faceDir), segment3a.point.y);
                        RaycastHit2D hit = Physics2D.Raycast(hitOrigin, Vector2.down, 200, patrolMask);
                        if (hit)
                        {
                            //If the platform below is not the patrol platform.
                            if (hit.collider.gameObject != patrolPlatform.gameObject)
                            {
                                return true;
                            }
                        }
                    }
                }
            }

            //3b.
            if (segment3b)
            {
                if (direction == JumpDirection.Up)
                {
                    //If the platform hit is higher than the patrol platform.
                    if (segment3b.collider.bounds.max.y > patrolPlatform.GetComponent<Collider2D>().bounds.max.y)
                    {
                        //If we hit the top of a platform.
                        if (segment3b.point.y >= segment3b.collider.bounds.max.y - .25f && segment3b.point.y <= segment3b.collider.bounds.max.y + .25f)
                        {
                            return true;
                        }

                        else {
                            //If they hit we can check if below the hit is a platform
                            Vector2 hitOrigin = new Vector2(segment3b.point.x - (1 * controller.collisions.faceDir), segment3b.point.y);
                            RaycastHit2D hit = Physics2D.Raycast(hitOrigin, Vector2.down, 200, patrolMask);
                            if (hit)
                            {
                                //If the platform below is not the patrol platform.
                                if (hit.collider.gameObject != patrolPlatform.gameObject)
                                {
                                    return true;
                                }
                            }
                        }
                    }
                }

                //Last chance ignores if the platform is higher than the patrol platform.
                else
                {
                    //If we hit the top of a platform.
                    if (segment3b.point.y >= segment3b.collider.bounds.max.y - .25f && segment3b.point.y <= segment3b.collider.bounds.max.y + .25f)
                    {
                        return true;
                    }

                    else {
                        //If they hit we can check if below the hit is a platform
                        Vector2 hitOrigin = new Vector2(segment3b.point.x - (1 * controller.collisions.faceDir), segment3b.point.y);
                        RaycastHit2D hit = Physics2D.Raycast(hitOrigin, Vector2.down, 200, patrolMask);
                        if (hit)
                        {
                            //If the platform below is not the patrol platform.
                            if (hit.collider.gameObject != patrolPlatform.gameObject)
                            {
                                return true;
                            }
                        }
                    }
                }
            }

            return false;
        }

        else if (direction == JumpDirection.Down)
        {
            //check the free fall raycasts.
            //1 is the back corner.
            Vector2 fallPoint1a;
            Vector2 fallPoint1b;
            Vector2 fallPoint1c;

            //2 is the top corner.
            Vector2 fallPoint2a;
            Vector2 fallPoint2b;
            Vector2 fallPoint2c;

            //3 is the front corner.
            Vector2 fallPoint3a;
            Vector2 fallPoint3b;
            Vector2 fallPoint3c;

            if (controller.collisions.faceDir == 1)
            {
                fallPoint1a = new Vector2(fallPoint1.bounds.min.x, fallPoint1.bounds.min.y);
                fallPoint1b = new Vector2(fallPoint2.bounds.min.x, fallPoint2.bounds.min.y);
                fallPoint1c = new Vector2(fallPoint3.bounds.min.x, fallPoint3.bounds.min.y);

                fallPoint2a = new Vector2(fallPoint1.bounds.max.x, fallPoint1.bounds.max.y);
                fallPoint2b = new Vector2(fallPoint2.bounds.max.x, fallPoint2.bounds.max.y);
                fallPoint2c = new Vector2(fallPoint3.bounds.max.x, fallPoint3.bounds.max.y);
            }
            else
            {
                fallPoint1a = new Vector2(fallPoint1.bounds.max.x, fallPoint1.bounds.min.y);
                fallPoint1b = new Vector2(fallPoint2.bounds.max.x, fallPoint2.bounds.min.y);
                fallPoint1c = new Vector2(fallPoint3.bounds.max.x, fallPoint3.bounds.min.y);

                fallPoint2a = new Vector2(fallPoint1.bounds.min.x, fallPoint1.bounds.max.y);
                fallPoint2b = new Vector2(fallPoint2.bounds.min.x, fallPoint2.bounds.max.y);
                fallPoint2c = new Vector2(fallPoint3.bounds.min.x, fallPoint3.bounds.max.y);
            }

            fallPoint3a = new Vector2(fallPoint1.transform.position.x, fallPoint1.bounds.min.y);
            fallPoint3b = new Vector2(fallPoint2.transform.position.x, fallPoint2.bounds.min.y);
            fallPoint3c = new Vector2(fallPoint3.transform.position.x, fallPoint3.bounds.min.y);

            RaycastHit2D segment1a = Physics2D.Linecast(fallPoint1a, fallPoint1b, patrolMask);
            RaycastHit2D segment1b = Physics2D.Linecast(fallPoint1b, fallPoint1c, patrolMask);

            RaycastHit2D segment2a = Physics2D.Linecast(fallPoint2a, fallPoint2b, patrolMask);
            RaycastHit2D segment2b = Physics2D.Linecast(fallPoint2b, fallPoint2c, patrolMask);

            RaycastHit2D segment3a = Physics2D.Linecast(fallPoint3a, fallPoint3b, patrolMask);
            RaycastHit2D segment3b = Physics2D.Linecast(fallPoint3b, fallPoint3c, patrolMask);

            if (segment2a)
            {
                if (segment1b)
                {
                    if (segment2a.collider.gameObject != segment1b.collider.gameObject)
                    {
                        return false;
                    }
                }
                if (segment3b)
                {
                    if (segment2a.collider.gameObject != segment3b.collider.gameObject)
                    {
                        return false;
                    }
                }
            }

            if (segment2b)
            {
                if (segment1b)
                {
                    if (segment2b.collider.gameObject != segment1b.collider.gameObject)
                    {
                        return false;
                    }
                }
                if (segment3b)
                {
                    if (segment2b.collider.gameObject != segment3b.collider.gameObject)
                    {
                        return false;
                    }
                }
            }

            if (segment1a || segment1b || segment3a || segment3b)
            {
                if (segment1a)
                {
                    if (segment1a.point.y >= segment1a.collider.bounds.max.y - .25f && segment1a.point.y <= segment1a.collider.bounds.max.y + .25f)
                    {
                        return true;
                    }
                }
                if (segment1b)
                {
                    if (segment1b.point.y >= segment1b.collider.bounds.max.y - .25f && segment1b.point.y <= segment1b.collider.bounds.max.y + .25f)
                    {
                        return true;
                    }
                }
                if (segment3a)
                {
                    if (segment3a.point.y >= segment3a.collider.bounds.max.y - .25f && segment3a.point.y <= segment3a.collider.bounds.max.y + .25f)
                    {
                        return true;
                    }
                }
                if (segment3b)
                {
                    if (segment3b.point.y >= segment3b.collider.bounds.max.y - .25f && segment3b.point.y <= segment3b.collider.bounds.max.y + .25f)
                    {
                        return true;
                    }
                }
            }

            return false;
        }

        return false;
    }
示例#32
0
 public void GenerateCoin(JumpDirection jumpDirection)
 {
     OnCoinGenerated?.Invoke(jumpDirection);
 }
示例#33
0
 public void MoveCamera(JumpDirection jumpDirection)
 {
     OnCameraMove?.Invoke(jumpDirection);
 }
示例#34
0
 void Start()
 {
     jumpDirection = jumpDirectionForTouchInputSide(side);
 }
示例#35
0
        private void ExecuteJump(ITextControl textControl, JumpDirection direction, bool jumpOutsideEdge, bool skipClosestEdge)
        {
            var document         = textControl.Document;
            var caretPos         = textControl.Caret.Position.Value;
            var caretDocumentPos = caretPos.ToDocLineColumn();

            var lineCount           = document.GetLineCount();
            var lineInc             = direction == JumpDirection.Down ? Int32 <DocLine> .I : Int32 <DocLine> .O - Int32 <DocLine> .I;
            var targetLine          = Int32 <DocLine> .MinValue;
            var firstLine           = caretDocumentPos.Line + lineInc;
            var previousLine        = caretDocumentPos.Line;
            var previousLineIsBlank = string.IsNullOrWhiteSpace(document.GetLineText(previousLine));

            for (var line = firstLine; line >= Int32 <DocLine> .O && line < lineCount; line += lineInc)
            {
                if (!skipClosestEdge && previousLineIsBlank && line != firstLine)
                {
                    // found our text block, go to the blank line right before it
                    targetLine = (jumpOutsideEdge) ? previousLine : line;
                    break;
                }

                var lineText    = document.GetLineText(line);
                var lineIsBlank = string.IsNullOrWhiteSpace(lineText);
                if (lineIsBlank)
                {
                    if (!previousLineIsBlank && line != firstLine)
                    {
                        // found our next blank line beyond our text block
                        targetLine = (jumpOutsideEdge) ? line : previousLine;
                        break;
                    }
                }

                previousLine        = line;
                previousLineIsBlank = lineIsBlank;
            }

            int finalOffset = 0;

            if (targetLine >= Int32 <DocLine> .O)
            {
                if (jumpOutsideEdge)
                {
                    // move the caret to the blank line
                    finalOffset = document.GetLineEndOffsetNoLineBreak(targetLine);
                }
                else
                {
                    // move the caret to the first character on the non-blank line
                    string lineString  = document.GetLineText(targetLine);
                    int    spaceOffset = lineString.TakeWhile(char.IsWhiteSpace).Count();
                    finalOffset = document.GetLineStartOffset(targetLine) + spaceOffset;
                }
            }
            else
            {
                // we found no suitable position so just go to BOF or EOF depending on the direction
                if (direction == JumpDirection.Up)
                {
                    finalOffset = document.GetDocumentStartOffset().Offset;
                }
                else
                {
                    finalOffset = document.GetDocumentEndOffset().Offset;
                }
            }
            textControl.Caret.MoveTo(finalOffset, CaretVisualPlacement.DontScrollIfVisible);
        }
示例#36
0
 void JumpLeft()
 {
     print("Jumping left");
     jumpDirection = JumpDirection.Left;
     timePassed    = 0.0f;
 }
示例#37
0
    void Update()
    {
        if (isPlay)
        {
            if (!justDie1 && !justDie2 && !justDie3)
            {
                //read keyboard input
                if (Input.GetKeyDown(KeyCode.UpArrow) || Input.GetKeyDown(KeyCode.DownArrow) ||
                    Input.GetKeyDown(KeyCode.RightArrow) || Input.GetKeyDown(KeyCode.LeftArrow))
                {
                    audioSource.PlayOneShot(jumpSound, 0.2f);

                    if (perc == 1f || !canMove)
                    {
                        lerpTime        = 1f;
                        currentLerpTime = 0f;
                        firstInput      = true;
                        justJump        = true;

                        if (Input.GetKeyDown(KeyCode.UpArrow))                           //jump forward
                        {
                            if (canMove || (nowJump != lastJump))
                            {
                                endPosition.x += jumpDistance;
                                canMove        = true;
                            }
                            lastJump = nowJump;
                            environmentMaker.charRoadPos++;
                            gameObject.transform.GetChild(0).rotation = Quaternion.Euler(new Vector3(270f, 270f, 0f));
                        }
                        else if (Input.GetKeyDown(KeyCode.DownArrow))                             //jump backward
                        {
                            nowJump = JumpDirection.down;
                            if (canMove || (nowJump != lastJump))
                            {
                                canMove = true;
                                environmentMaker.collideFront = false;
                                endPosition.x -= jumpDistance;
                            }
                            lastJump = nowJump;
                            environmentMaker.charRoadPos--;
                            gameObject.transform.GetChild(0).rotation = Quaternion.Euler(new Vector3(270f, 90, 0f));
                        }
                        else if (Input.GetKeyDown(KeyCode.RightArrow))                             //jump to the right side
                        {
                            nowJump = JumpDirection.right;
                            if (canMove || (nowJump != lastJump))
                            {
                                if (gameObject.transform.position.z > (-roadSideBoundary * jumpDistance))
                                {
                                    endPosition.z -= jumpDistance;
                                }
                                canMove = true;
                                environmentMaker.collideFront = false;
                            }
                            lastJump = nowJump;
                            gameObject.transform.GetChild(0).rotation = Quaternion.Euler(new Vector3(270f, 0f, 0f));
                        }
                        else if (Input.GetKeyDown(KeyCode.LeftArrow))                             //jump to the leftside
                        {
                            nowJump = JumpDirection.left;
                            if (canMove || (nowJump != lastJump))
                            {
                                if (gameObject.transform.position.z < (roadSideBoundary * jumpDistance))
                                {
                                    endPosition.z += jumpDistance;
                                }
                                canMove = true;
                                environmentMaker.collideFront = false;
                            }
                            lastJump = nowJump;
                            gameObject.transform.GetChild(0).rotation = Quaternion.Euler(new Vector3(270f, 180f, 0f));
                        }
                    }
                }

                startPosition = gameObject.transform.position;

                if (firstInput)
                {
                    perc             = currentLerpTime / lerpTime;
                    currentLerpTime += Time.deltaTime * jumpSpeed;

                    gameObject.transform.position = Vector3.Lerp(startPosition, endPosition, perc);
                    if (perc > 0.8f)
                    {
                        perc = 1f;
                    }

                    if (Mathf.Round(perc) == 1f)
                    {
                        justJump = false;
                    }
                }
            }
            else                //player dies
            {
                if (justDead)
                {
                    if (justDie1)
                    {
                        audioSource.PlayOneShot(dieSound, 1f);
                        retryButton.SetActive(true);
                    }
                    else if (justDie2)
                    {
                        audioSource.PlayOneShot(dieSound2, 0.3f);
                        retryButton.SetActive(true);
                    }
                    else if (justDie3)
                    {
                        gameObject.transform.GetChild(1).gameObject.AddComponent <Rigidbody> ();
                        gameObject.transform.GetChild(1).gameObject.GetComponent <Rigidbody> ().mass = 5f;
                        audioSource.PlayOneShot(dieSound3, 0.3f);
                        //retryButton.SetActive (true);

                        /*if (gameObject.transform.GetChild (1).transform.position.y <= 1f) {
                         *      retryButton.SetActive (true);
                         * }*/
                    }
                    justDead = false;
                }

                Destroy(this.GetComponent <BoxCollider> ());
                if (justDie3)
                {
                    if (gameObject.transform.GetChild(1).transform.position.y <= 1f)
                    {
                        retryButton.SetActive(true);
                    }
                }
            }
        }
    }
示例#38
0
        private void Jump(JumpDirection direction)
        {
            // as with the standard caret moving operations (click, arrow keys, etc.)
            // we clear our current selection when we jump
            View.Selection.Clear();

            // rules:
            // if the line we begin on contains text, or the following line contains text,
            // navigate to the next blank line
            // if the line we begin on is blank, and the next line is also blank,
            // navigate to the line preceding the next line that contains text
            // if we find no suitable lines, we navigate to the last line
            CaretPosition startingPos     = View.Caret.Position;
            ITextBuffer   buffer          = View.TextBuffer;
            ITextSnapshot currentSnapshot = buffer.CurrentSnapshot;
            SnapshotPoint start           = startingPos.BufferPosition;

            ITextSnapshotLine previousLine = start.GetContainingLine();
            ITextSnapshotLine targetLine   = null;
            bool previousLineIsBlank       = string.IsNullOrWhiteSpace(previousLine.GetTextIncludingLineBreak());
            int  startLineNo = currentSnapshot.GetLineNumberFromPosition(start.Position);
            int  lineInc     = (int)direction;
            int  firstLine   = startLineNo + lineInc;

            for (int i = firstLine; i >= 0 && i < currentSnapshot.LineCount; i += lineInc)
            {
                ITextSnapshotLine line         = currentSnapshot.GetLineFromLineNumber(i);
                string            lineContents = line.GetTextIncludingLineBreak();
                bool lineIsBlank = string.IsNullOrWhiteSpace(lineContents);
                if (lineIsBlank)
                {
                    if (!previousLineIsBlank && i != firstLine)
                    {
                        // found our next blank line beyond our text block
                        targetLine = (JumpOutsideEdge) ? line : previousLine;
                        break;
                    }
                }
                else if (!SkipClosestEdge && previousLineIsBlank && i != firstLine)
                {
                    // found our text block, go to the blank line right before it
                    targetLine = (JumpOutsideEdge) ? previousLine : line;
                    break;
                }

                previousLine        = line;
                previousLineIsBlank = lineIsBlank;
            }

            if (targetLine != null)
            {
                VirtualSnapshotPoint finalPosition;
                if (JumpOutsideEdge)
                {
                    // move the caret to the blank line indented with the appropriate number of virtual spaces
                    int?virtualSpaces = SmartIndentation.GetDesiredIndentation(View, targetLine);
                    finalPosition = new VirtualSnapshotPoint(targetLine.Start, virtualSpaces.GetValueOrDefault());
                    if (!finalPosition.IsInVirtualSpace)
                    {
                        // our line has some 'meaningful' whitespace, go to end instead
                        finalPosition = new VirtualSnapshotPoint(targetLine.End);
                    }
                }
                else
                {
                    string lineString = targetLine.GetTextIncludingLineBreak();
                    int    offset     = lineString.TakeWhile(c => char.IsWhiteSpace(c)).Count();
                    finalPosition = new VirtualSnapshotPoint(targetLine, offset);
                }
                View.Caret.MoveTo(finalPosition);
            }
            else
            {
                // we found no suitable line so just choose BOF or EOF depending on the direction we were moving
                if (direction == JumpDirection.Up)
                {
                    View.Caret.MoveTo(previousLine.Start);
                }
                else
                {
                    View.Caret.MoveTo(previousLine.End);
                }
            }

            // scroll our view to the new caret position
            View.Caret.EnsureVisible();
        }
示例#39
0
 public void ChangeDirection(JumpDirection jumpDirection)
 {
     OnDirectionChanged?.Invoke(jumpDirection);
 }