示例#1
0
 protected virtual void OnRunStart()
 {
     if (OnRunStartEvent != null)
     {
         OnRunStartEvent.Invoke();
     }
 }
示例#2
0
    private void HandleStateUpdate(bool wasRunningLastFrame)
    {
        //Register Wall Slide
        if (!_mover.IsGrounded)
        {
            if ((_mover.CollidedLeft && _goingLeft) || (_mover.CollidedRight && _goingRight))
            {
                if (!state.isSliding)
                {
                    _velocity.y = (_velocity.y > maxGravity * slideGravityDamping) ? _velocity.y : maxGravity * slideGravityDamping;
                }
                state.isSliding = true;
            }

            else if (!_mover.HasCollidedHorizontal && state.isSliding)
            {
                state.isSliding = false;
            }
        }
        else if (state.isSliding)
        {
            state.isSliding = false;
        }

        if (state.isReeling && _mover.HasCollidedHorizontal)
        {
            state.isReeling       = false;
            state.gravityDisabled = false;
        }

        if (_mover.HasLanded)
        {
            state.ResetAbilityUsage();
            state.isSliding = false;

            OnLandEvent?.Invoke();
        }

        //run-event should be called in the frame that movement goes from 0 to not-zero, as well as any frame where the player lands while moving.
        //TODO: rework sound system.
        if ((!wasRunningLastFrame || _mover.HasLanded) && horizontalMove != 0 && _mover.IsGrounded && !_mover.HasCollidedHorizontal)
        {
            OnRunStartEvent?.Invoke();
        }
        else if ((wasRunningLastFrame && horizontalMove == 0 && _mover.IsGrounded) || _mover.HasLeftGround || _mover.IsGrounded && _mover.HasCollidedHorizontal)
        {
            OnRunEndEvent?.Invoke();
        }
    }
示例#3
0
    public void GameUpdate()
    {
        if (IsRun == false)
        {
            if (preDistance >= PreDistance)
            {
                IsRun = true;
                OnRunStartEvent?.Invoke();
            }

            preDistance           += RunSpeed * Time.deltaTime;
            PlayerSprite.position -= new Vector3(0, RunSpeed * Time.deltaTime, 0);
        }
        else
        {
            var input = Input.GetKey(KeyCode.Mouse0);

            if (Input.GetKeyUp(KeyCode.Mouse0))
            {
                direction   *= (-1);
                acceleration = 2;
            }

            // Самый первый клик
            if (direction == 0 && input == true)
            {
                var x = Input.mousePosition;
                x.x /= Screen.width;

                direction = x.x <= 0.5f ? -1 : 1;
            }

            // Перемещение спрайта
            if (input == true)
            {
                print("input == true");
                PlayerSprite.position += new Vector3(acceleration * Time.deltaTime * direction, 0, 0);
                var posx = Mathf.Clamp(PlayerSprite.position.x, transform.position.x - HorizontalRange, transform.position.x + HorizontalRange);
                PlayerSprite.position = new Vector3(posx, PlayerSprite.position.y, PlayerSprite.position.z);


                acceleration += AccelerationFactor * Time.deltaTime;
                if (acceleration > HorizontalSpeed)
                {
                    acceleration = HorizontalSpeed;
                }
            }
            else // Игрок отпустил input
            {
                acceleration -= AccelerationDownFactor * Time.deltaTime;

                if (acceleration < 2)
                {
                    acceleration = 2;
                }

                Clamp2Quads();
            }
        }

        var cols = Physics2D.OverlapCircleAll(PlayerSprite.position, 0.2f);

        for (int i = 0; i < cols.Length; i++)
        {
            print("Work");
            if (cols[i].tag == "Obs")
            {
                GameManager.instance.StopGame();

                OnRunStopEvent?.Invoke();
            }
        }
    }