Exemplo n.º 1
0
    //========================================================
    //
    //========================================================

    private void OnRockCollisionEvent()
    {
        if (_isDragging)
        {
            _draggedExtremity.IsMoving = false;
            _draggedExtremity          = null;

            _isDragging = false;
        }

        foreach (ExtremityScript extremity in _extremitiesList)
        {
            extremity.UnanchorExtremity();
        }
    }
Exemplo n.º 2
0
    //========================================================
    //
    //========================================================

    void Update()
    {
        if (_isDead)
        {
            return;
        }

        // DEATH, updating score and altitude

        bool  isDead   = true;
        float deathPos = Camera.main.transform.position.y - Camera.main.orthographicSize;

        _numOfAnchoredExtremities = 0;

        foreach (ExtremityScript extremity in _extremitiesList)
        {
            if (extremity.transform.position.y >= deathPos)
            {
                isDead = false;
            }

            if (extremity.IsAnchored)
            {
                _numOfAnchoredExtremities++;
            }
        }

        //******************************************
        if (isDead)
        {
            Debug.Log("Player Died!");
            GetComponent <AudioSource>().Play();
            _isDead = true;

            Invoke("ReloadScene", 0.5f);
            return;
        }

        //******************************************
        if (_numOfAnchoredExtremities == 0)
        {
            _levitationTimer += Time.fixedDeltaTime;
        }

        if (_levitationTimer > 1f)
        {
            if (_isDragging)
            {
                _draggedExtremity.IsMoving = false;
                _draggedExtremity          = null;

                _isDragging = false;
            }

            _anchoringAllowed = false;

            Invoke("AllowAnchoring", 0.5f);
        }

        //******************************************
        UIManager.Instance.UpdateCombo(_numOfAnchoredExtremities);

        _altitude = _body.position.y - _originalYpos;
        UIManager.Instance.UpdateAltitude(_altitude);

        if (_altitude > _highestAltitude)
        {
            _highestAltitude = _altitude;
        }
    }
Exemplo n.º 3
0
    // The code for moving the extremities is in the fixedUpdate method because the unity manual recommends using for moving rigidbodies
    void FixedUpdate()
    {
        if (_isDead)
        {
            return;
        }

        //******************************************************
        // DRAG AND DROP MOVEMENT

        if (Input.GetMouseButton(0))
        {
            //**********************
            // mouse down AND dragging
            if (_isDragging /*&& _anchoringAllowed*/)
            {
                Vector3 mousePos = Camera.main.ScreenToWorldPoint(Input.mousePosition);
                mousePos.z = 0;

                Vector3 force = mousePos - _draggedExtremity.transform.position;

                if (force.magnitude > 1)
                {
                    force.Normalize();
                }

                _draggedExtremity.GetComponent <Rigidbody2D>().AddForce(force * _draggingMultiplyer);
            }
            //**********************
            // mouse down AND NOT dragging
            else
            {
                //Collider2D[] colliders = Physics2D.OverlapPointAll(Camera.main.ScreenToWorldPoint(Input.mousePosition));
                Collider2D[] colliders = Physics2D.OverlapCircleAll(Camera.main.ScreenToWorldPoint(Input.mousePosition), 0.2f);

                if (colliders != null)
                {
                    foreach (Collider2D collider in colliders)
                    {
                        if (collider.CompareTag("Extremity"))
                        {
                            ExtremityScript extremityScript = collider.GetComponent <ExtremityScript>();

                            _draggedExtremity = extremityScript;

                            _draggedExtremity.UnanchorExtremity();
                            _draggedExtremity.IsMoving = true;

                            _isDragging       = true;
                            _anchoringAllowed = false;

                            Invoke("AllowAnchoring", 0.1f);

                            break;
                        }
                    }
                }
            }
        }
        //**********************
        // mouse NOT down
        else
        {
            if (_isDragging && _anchoringAllowed)
            {
                Collider2D[] colliders = Physics2D.OverlapBoxAll(_draggedExtremity.transform.position, _draggedExtremity.GetComponent <BoxCollider2D>().size, _draggedExtremity.transform.rotation.z);

                if (colliders != null)
                {
                    foreach (Collider2D collider in colliders)
                    {
                        AbstractAnchorScript anchorScript = collider.GetComponent <AbstractAnchorScript>();

                        if (collider.CompareTag("Anchor") && anchorScript.IsInUse == false)
                        {
                            //Debug.Log("end of drag, anchored extremity");

                            _currentChunkName = anchorScript.transform.parent.parent.name;

                            _draggedExtremity.AnchorExtremity(anchorScript, _anchorBreakForce);
                            GameObject fx = Instantiate(_grabFxPrefab);
                            fx.transform.position = anchorScript.transform.position;

                            if (!anchorScript.usedOnce)
                            {
                                anchorScript.usedOnce = true;
                                UIManager.Instance.AddScore(_grabScoreBonus);
                            }

                            _levitationTimer = 0;

                            EventManager.Instance.SendOnAnchorGrabbedEvent();

                            break;
                        }
                    }
                }
            }

            if (_isDragging)
            {
                _draggedExtremity.IsMoving = false;
                _draggedExtremity          = null;

                _isDragging = false;
            }
        }
    }