public override void OnInspectorGUI()
    {
        DrawDefaultInspector();

        Cristal cristal = target as Cristal;

        if (GUILayout.Button("74"))
        {
            cristal.VidaCristal = 75;
        }

        if (GUILayout.Button("49"))
        {
            cristal.VidaCristal = 50;
        }

        if (GUILayout.Button("24"))
        {
            cristal.VidaCristal = 25;
        }

        if (GUILayout.Button("4"))
        {
            cristal.VidaCristal = 5;
        }
    }
Exemplo n.º 2
0
    void OnEnable()
    {
        cristal = target as Cristal;
        Vector2 reflectionDirections = cristal.reflectionDirections;

        right = reflectionDirections.x > 0.0f;
        up    = reflectionDirections.y > 0.0f;
    }
Exemplo n.º 3
0
    public GameObject audioSource;     // Referencia ao objeto audio source na cena

    private void OnTriggerEnter2D(Collider2D collision)
    {
        audioSource    = GameObject.Find("Audio Source");          // Localiza o objeto audio source
        enemyHitSource = audioSource.GetComponent <AudioSource>(); // liga o componente do objeto à fonte de audio
        if (collision is BoxCollider2D)
        {
            if (collision.gameObject.CompareTag("Inimigo"))
            {
                enemyHitSource.Play();   //toca o audio de atingir inimigo
                Inimigo inimigo = collision.gameObject.GetComponent <Inimigo>();
                StartCoroutine(inimigo.DanoCaractere(danoCausado, 0.0f));
                gameObject.SetActive(false);
            }

            if (collision.gameObject.CompareTag("Cristal"))
            {
                Cristal cristal = collision.gameObject.GetComponent <Cristal>();
                cristal.TrocarCor();
            }
        }
    }
Exemplo n.º 4
0
    private void FindTargetObject(bool horizontal, out Cristal outCristal)
    {
        Vector2      outputDirection = GetDirection(horizontal);
        RaycastHit2D hit;

        Vector2 raycastOrigin = this.firepoint;

        do
        {
            hit            = Physics2D.Raycast(raycastOrigin, outputDirection);
            raycastOrigin += outputDirection * 0.002f;
        } while(hit.transform == this.transform); // make sure the hit object is not us

        if (horizontal)
        {
            horizontalEndpoint = hit.point;
        }
        else
        {
            verticalEndpoint = hit.point;
        }

        outCristal = null;
        if (hit.collider != null)
        {
            // try to get a cristal component from the object that was hit
            // outCristal will be null if the hit object does not have a cristal component
            hit.transform.TryGetComponent <Cristal>(out outCristal);
        }

        if (horizontal)
        {
            horizontalLaserTrigger.CalculateTransform(raycastOrigin, hit.point);
        }
        else
        {
            verticalLaserTrigger.CalculateTransform(raycastOrigin, hit.point);
        }
    }
Exemplo n.º 5
0
    /// <param name="laserDirection">Normalized direction of the laser</param>
    public void GetLaserPoints(Vector2 laserDirection, ref List <Vector3> points, Laser laser)
    {
        laser.AddSubscriber(OnLaserStateChange);

        points.Add(this.firepoint);
        Vector2 horizontalDir = this.GetDirection(true);
        Vector2 verticalDir   = this.GetDirection(false);

        Vector2 redirectedDirection = Vector2.zero;
        Cristal nextCristal         = null;
        Vector2 nextPoint           = Vector2.zero;

        // if horizontal direction and laser direction are exactly opposite
        if (Vector2.Dot(horizontalDir, laserDirection) == -1.0f)
        {
            nextCristal         = nextVerticalCristal;
            redirectedDirection = verticalDir;
            nextPoint           = verticalEndpoint;
        }
        else if (Vector2.Dot(verticalDir, laserDirection) == -1.0f)
        {
            nextCristal         = nextHorizontalCristal;
            redirectedDirection = horizontalDir;
            nextPoint           = horizontalEndpoint;
        }

        if (nextCristal)
        {
            nextCristal.GetLaserPoints(redirectedDirection, ref points, laser);
        }
        // if sqrd mag > 0, it means it's not vector 0 anymore
        // which means at least one of the conditions above passed
        else if (nextPoint.sqrMagnitude > 0.0f)
        {
            points.Add(nextPoint);
        }
    }
Exemplo n.º 6
0
    public void Shoot(Vector2 direction)
    {
        notifyStateChangeToSubscribers?.Invoke(false);
        notifyStateChangeToSubscribers = null;

        List <Vector3> points = new List <Vector3>();

        points.Add(firepoint.position);

        RaycastHit2D hit = Physics2D.Raycast(firepoint.position, direction);

        if (hit.collider)
        {
            Cristal cristal = null;
            if (hit.collider.gameObject.tag == "hittable")
            {
                hit.collider.gameObject.SendMessage("HitByRay", direction);
            }
            else if (hit.transform.TryGetComponent <Cristal>(out cristal))
            {
                cristal.GetLaserPoints(direction, ref points, this);
            }
            else
            {
                points.Add(hit.point);
            }
        }
        else
        {
            points.Add(hit.point);
        }

        laserTrigger.CalculateTransform(firepoint.position, hit.point);
        lineRenderer.positionCount = points.Count;
        lineRenderer.SetPositions(points.ToArray());
    }
Exemplo n.º 7
0
 private void OnCristalSpawned(Cristal cristal)
 {
     cristal.onCollected += OnCristalCollected;
 }
Exemplo n.º 8
0
    private IEnumerator SwapTouchedCristals()
    {
        int firstX = Mathf.FloorToInt(_clickPointStart.x - _startPoint.x + 0.5f);
        int firstY = Mathf.FloorToInt(_clickPointStart.y - _startPoint.y + 0.5f);

        if (firstX < 0 || firstX >= _width || firstY < 0 || firstY >= _height)
        {
            yield break;
        }

        int secondX = firstX;
        int secondY = firstY;

        float angle = Mathf.Atan2(_clickPointFinal.y - _clickPointStart.y, _clickPointFinal.x - _clickPointStart.x) * 180 / Mathf.PI;

        if (angle > -45 && angle <= 45)
        {
            secondX++;
        }
        else if (angle > 45 && angle <= 135)
        {
            secondY++;
        }
        else if (angle > -135 && angle <= -45)
        {
            secondY--;
        }
        else
        {
            secondX--;
        }

        if (secondX < 0 || secondX >= _width || secondY < 0 || secondY >= _height)
        {
            yield break;
        }

        Cristal first  = _cristals[firstX, firstY];
        Cristal second = _cristals[secondX, secondY];

        if (first.Number() == second.Number())
        {
            yield break;
        }

        first.SwapMove(secondX - firstX, secondY - firstY);
        second.SwapMove(firstX - secondX, firstY - secondY);

        _canSwap = false;

        yield return(new WaitUntil(() => !first.IsMove()));

        SwapValue(ref _cristals[firstX, firstY], ref _cristals[secondX, secondY]);

        List <Cristal> matches = FindMatches();

        if (matches.Count == 0)
        {
            first.SwapMove(firstX - secondX, firstY - secondY);
            second.SwapMove(secondX - firstX, secondY - firstY);

            yield return(new WaitUntil(() => !first.IsMove()));

            SwapValue(ref _cristals[firstX, firstY], ref _cristals[secondX, secondY]);

            _canSwap = true;

            yield break;
        }

        StartCoroutine(RemoveMatches(matches));
    }
Exemplo n.º 9
0
    private void CreateCristal(Vector2 pos)
    {
        Cristal cristal = Instantiate(prefabCristal, pos, prefabCristal.transform.rotation);

        onCristalSpawned?.Invoke(cristal);
    }