예제 #1
0
 private void PeakJump()
 {
     nextPosition       = transform.position;
     nextPosition.y     = jumpHeight;
     transform.position = nextPosition;
     State = BounceState.Airborne;
 }
예제 #2
0
 private void Ground()
 {
     nextPosition       = transform.position;
     nextPosition.y     = 0f;
     transform.position = nextPosition;
     State = BounceState.Grounded;
 }
예제 #3
0
    private void Update()
    {
        if (Input.GetMouseButtonDown(0) && _bounceState != BounceState.Up)
        {
            if (isBusy == false)
            {
                _bounceState = BounceState.Up;
            }
        }


        if (_bounceState != BounceState.None && isOkToBounce)
        {
            if (coinCount > 0)
            {
                Bounce();
            }
            else
            {
                if (isFinishedBounce)
                {
                    _anim.enabled = false;
                    SetSprite(_emptyBlock);
                    isFinishedBounce = false;
                }
            }
        }
    }
예제 #4
0
    private void Bounce()
    {
        Vector3 currentPos = transform.position;

        if (_bounceState == BounceState.Up)
        {
            if (currentPos.y <= _posBeforeBounce.y + _bounceYDist)
            {
                transform.Translate(_bounceVelocity * Vector2.up * Time.fixedDeltaTime);
            }
            else
            {
                _bounceState = BounceState.Down;
            }
        }
        else if (_bounceState == BounceState.Down)
        {
            if (currentPos.y >= _posBeforeBounce.y)
            {
                transform.Translate(_bounceVelocity * Vector2.down * Time.fixedDeltaTime);
            }
            else
            {
                _bounceState       = BounceState.None;
                transform.position = _posBeforeBounce;

                GivePrize();
            }
        }
    }
예제 #5
0
 public void TriggerBounce()
 {
     if (isBusy == false)
     {
         _bounceState = BounceState.Up;
     }
 }
예제 #6
0
 public void Start()
 {
     State = BounceState.Grounded;
     GameState.Instance.OnGameEnd.AddListener(OnGameEnd);
     if (runOnStart)
     {
         Run();
     }
 }
예제 #7
0
    private void OnTriggerEnter2D(Collider2D other)
    {
        Debug.Log("Collision Detected....");

        if (other.transform.tag == "Player")
        {
            Debug.Log("Player");
            _bounceState = BounceState.Up;
        }
    }
예제 #8
0
    void OnInteraction(SMBPlayer player)
    {
        if (_bounceState == BounceState.None && !_isDestroyed)
        {
            DestroyBlock(player);

            _posBeforeBounce = transform.position;
            _bounceState     = BounceState.Up;
        }
    }
예제 #9
0
    private void Bounce()
    {
        isBusy          = true;
        currentPosition = transform.position;

        if (coinCount == 1)
        {
            _anim.enabled = false;
            SetSprite(_emptyBlock);
            isFinishedBounce = false;
        }

        if (_bounceState == BounceState.Up)
        {
            if (currentPosition.y <= _posBeforeBounce.y + _bounceYDist)
            {
                transform.Translate(_bounceVelocity * Vector2.up * Time.fixedDeltaTime);
            }
            else
            {
                _bounceState = BounceState.Down;
                PowerUpType(option);
            }
        }
        else if (_bounceState == BounceState.Down)
        {
            if (currentPosition.y >= _posBeforeBounce.y)
            {
                transform.Translate(_bounceVelocity * Vector2.down * Time.fixedDeltaTime);
            }
            else
            {
                if (coinCount == 1)
                {
                    isOkToBounce = false;
                }


                //Rigidbody2D r2d = GetComponent<Rigidbody2D>();
                //r2d.isKinematic = true;

                _bounceState       = BounceState.None;
                transform.position = _posBeforeBounce;
            }
        }
    }
예제 #10
0
        // bounce up and down and rotate on z axis
        public void Shake(ShakeArgument argument)
        {
            if (_bounceState == BounceState.Static || _bounceState == BounceState.ToStatic)
            {
                _shakeEndTime = Time.time;
            }

            // time related calculations
            _shakeArgument = argument;
            _shakeEndTime  = Time.time + Random.Range(
                argument.minDuration,
                argument.maxDuration);
            _bounceState = BounceState.ToBouncing; // race condition vs Update solution
            _rotateState = RotateState.ToRotating;

            // position calculations
            _bounceOffset   = new Vector3(0, argument.bounceMax / 4); // todo: improve offset
            _sqrBounceSpeed = argument.bounceSpeed * argument.bounceSpeed;

            // rotation calculations
            _sqrRotationSpeed = argument.rotationSpeed * argument.rotationSpeed;
            halfAngleOffset   = argument.rotationMax / 2;
        }
예제 #11
0
 public void Fall()
 {
     step  = 0f;
     State = BounceState.Falling;
 }
예제 #12
0
 public void Jump()
 {
     step  = 0f;
     State = BounceState.Jumping;
 }
예제 #13
0
        void Update()
        {
            // optimizable
            float   sampleY                      = _shakeArgument.bounceMax * Mathf.PerlinNoise(0, Time.time * _shakeArgument.bounceSpeed);
            Vector3 bounceOffset                 = (sampleY * Vector3.up) - _bounceOffset;
            Vector3 cameraRestingPosition        = target.position + cameraOffset;
            Vector3 cameraRelativeTargetPosition = cameraRestingPosition + bounceOffset;

            switch (_bounceState)
            {
            case BounceState.Static:
                localTransform.position = cameraRestingPosition;
                break;

            case BounceState.ToBouncing:
                localTransform.position = Vector3.MoveTowards(
                    localTransform.position,
                    cameraRelativeTargetPosition, transitionSpeed);

                if (_sqrBounceSpeed > Vector3.SqrMagnitude(localTransform.position - cameraRelativeTargetPosition))
                {
                    _bounceState = BounceState.Bouncing;
                }
                break;

            case BounceState.Bouncing:
                localTransform.position = cameraRelativeTargetPosition;
                if (Time.time > _shakeEndTime)
                {
                    _bounceState = BounceState.ToStatic;
                }
                break;

            case BounceState.ToStatic:
                localTransform.position = Vector3.MoveTowards(localTransform.position, cameraRestingPosition, transitionSpeed);

                if (_sqrBounceSpeed > Vector3.SqrMagnitude(localTransform.position - cameraRestingPosition))
                {
                    _bounceState = BounceState.Static;
                }
                break;

            default:
                throw new ArgumentOutOfRangeException();
            }

            float sampleAngle = _shakeArgument.rotationMax
                                * Mathf.PerlinNoise(Time.time * _shakeArgument.rotationSpeed, 0)
                                - halfAngleOffset;
            Quaternion targetRotation = Quaternion.AngleAxis(sampleAngle, localTransform.forward);

            switch (_rotateState)
            {
            case RotateState.Static:
                break;

            case RotateState.ToRotating:
                localTransform.rotation = Quaternion.RotateTowards(
                    localTransform.rotation,
                    targetRotation,
                    _shakeArgument.rotationSpeed);

                if (_sqrRotationSpeed > Mathf.Abs(
                        localTransform.rotation.eulerAngles.z
                        - targetRotation.eulerAngles.z))
                {
                    _rotateState = RotateState.Rotating;
                }
                break;

            case RotateState.Rotating:
                localTransform.rotation = targetRotation;
                if (Time.time > _shakeEndTime)
                {
                    _rotateState = RotateState.ToStatic;
                }
                break;

            case RotateState.ToStatic:
                localTransform.rotation = Quaternion.RotateTowards(
                    localTransform.rotation,
                    targetRotation,
                    _shakeArgument.rotationSpeed);

                if (_sqrRotationSpeed >
                    Mathf.Abs(localTransform.rotation.eulerAngles.z))
                {
                    localTransform.rotation = Quaternion.identity;
                    _rotateState            = RotateState.Static;
                }
                break;

            default:
                throw new ArgumentOutOfRangeException();
            }
        }
예제 #14
0
 void Start()
 {
     _posBeforeBounce = transform.position;
     _bounceState     = BounceState.Up;
 }