예제 #1
0
    private void AIThink()
    {
        int randIndex = Random.Range(0, 5);

        if (enemyDoll[randIndex].dead)
        {
            for (int i = 0; i < 5; ++i)
            {
                if (!enemyDoll[i].dead)
                {
                    randIndex = i;
                    break;
                }
            }
        }
        float         randPower = Random.Range(5.5f, 10f);
        CharacterDoll ed        = enemyDoll[randIndex];

        randIndex = Random.Range(0, 5);
        if (playerDoll[randIndex].dead)
        {
            for (int i = 0; i < 5; ++i)
            {
                if (!playerDoll[i].dead)
                {
                    randIndex = i;
                    break;
                }
            }
        }
        CharacterDoll tar = playerDoll[randIndex];

        float       randAngle = Random.Range(0f, 360f) * Mathf.Deg2Rad;
        Rigidbody2D rb        = ed.GetComponent <Rigidbody2D>();

        ed.transform.rotation = CalculateLookRotation(ed, tar);

        rb.AddForce(ed.transform.up * (randPower * 1280f));
        attacker = ed;
        NextTurn();
    }
예제 #2
0
    private void ShotDoll()
    {
        touchStarted = false;
        attacking    = false;
        // CancleControl
        // u.CloseCancelControl();
        u.SetDollControlAimActive(false);
        if (cancelAct)
        {
            g.DeselectDoll();
            return;
        }
        CharacterDoll selectedDoll = g.selectedDoll;
        Rigidbody2D   rb           = selectedDoll.GetComponent <Rigidbody2D>();

        selectedDoll.defMode        = false;
        selectedDoll.rb.isKinematic = false;
        rb.AddForce(selectedDoll.transform.up * (powerScale * ONE_GRID_FORCE));
        g.attacker = selectedDoll;
        g.NextTurn();
    }
예제 #3
0
    private void UpdatePreview(float _touchDis)
    {
        CharacterDoll selectedDoll = g.selectedDoll;

        if (cancelAct)
        {
            lineRenderer[PREVIEW_INCOMING].gameObject.SetActive(false);
            lineRenderer[PREVIEW_REFLECT].gameObject.SetActive(false);
            lineRenderer[PREVIEW_TARGETGO].gameObject.SetActive(false);
            lineRenderer[PREVIEW_CIRCLE].gameObject.SetActive(false);
            return;
        }

        float bw    = Board.BOARD_WIDTH;
        float power = _touchDis * 2f;

        powerScale = power / bw;

        Transform        trans     = selectedDoll.transform;
        int              layerMask = -1 - (1 << LayerMask.NameToLayer("Background")) - (1 << LayerMask.NameToLayer("SelectedDoll"));
        CircleCollider2D col       = selectedDoll.GetComponent <CircleCollider2D>();
        RaycastHit2D     hit       = Physics2D.CircleCast(trans.position, col.radius - 0.01f, trans.up, power, layerMask);

        if (hit.collider != null)
        {
            Vector3 hpos = hit.point;
            Vector3 spos = selectedDoll.transform.position;
            hpos.z = PREVIEW_Z;
            spos.z = PREVIEW_Z;

            Vector3   i     = hpos - spos;                      // Incoming Vector.
            Vector3   n     = hit.normal;                       // Hit Vector Normalize.
            Vector3   tc    = hit.normal * col.radius;          // To Center Vector.
            Vector3   c     = hpos + tc;                        // Center Position.
            Vector3[] vecs1 = { spos, c };

            if (hit.collider.gameObject.layer == LayerMask.NameToLayer("Doll"))
            {
                Vector3 tar = hit.collider.gameObject.transform.TransformPoint(hit.collider.offset);
                Vector3 res = tar + -n * 1f;
                res.z = PREVIEW_Z;

                Vector3[] vecs2 = { tar, res };
                lineRenderer[PREVIEW_INCOMING].SetPositions(vecs1);
                lineRenderer[PREVIEW_TARGETGO].SetPositions(vecs2);
                lineRenderer[PREVIEW_INCOMING].gameObject.SetActive(true);
                lineRenderer[PREVIEW_TARGETGO].gameObject.SetActive(true);
                lineRenderer[PREVIEW_REFLECT].gameObject.SetActive(false);
            }
            else
            {
                Vector3 r   = Vector3.Reflect(-i, n).normalized;
                Vector3 res = c + -r * 1f;
                res.z = PREVIEW_Z;

                Vector3[] vecs2 = { c, res };
                lineRenderer[PREVIEW_INCOMING].SetPositions(vecs1);
                lineRenderer[PREVIEW_REFLECT].SetPositions(vecs2);
                lineRenderer[PREVIEW_INCOMING].gameObject.SetActive(true);
                lineRenderer[PREVIEW_REFLECT].gameObject.SetActive(true);
                lineRenderer[PREVIEW_TARGETGO].gameObject.SetActive(false);
            }

            DrawPreviewCircle(c, col.radius);
        }
        else
        {
            Vector3 spos = selectedDoll.transform.position;
            Vector3 dpos = spos + selectedDoll.transform.up * power;
            spos.z = PREVIEW_Z;
            dpos.z = PREVIEW_Z;

            Vector3[] vecs = { spos, dpos };
            lineRenderer[PREVIEW_INCOMING].SetPositions(vecs);
            lineRenderer[PREVIEW_INCOMING].gameObject.SetActive(true);
            lineRenderer[PREVIEW_REFLECT].gameObject.SetActive(false);
            lineRenderer[PREVIEW_TARGETGO].gameObject.SetActive(false);

            DrawPreviewCircle(dpos, col.radius);
        }
        Vector2 offset = lineRenderer[PREVIEW_INCOMING].material.mainTextureOffset;

        offset.x -= (64f * Time.deltaTime * previewMaterialSpeed) % 64f;
        lineRenderer[PREVIEW_INCOMING].material.mainTextureOffset = offset;
        lineRenderer[PREVIEW_REFLECT].material.mainTextureOffset  = offset;
        attacking = true;
    }