Esempio n. 1
0
    // Use this for initialization
    void Start()
    {
        float x1 = transform.position.x;
        float y1 = transform.position.y;

        Collider2D[] hits = Physics2D.OverlapCircleAll(new Vector2(x1, y1), radius);
        foreach (Collider2D hit in hits)
        {
            Diggable dig = hit.GetComponent <Diggable>();
            if (dig)
            {
                dig.ApplyHit(damage);
            }
        }

        Destroy(gameObject, lifetime);
    }
Esempio n. 2
0
    void Update()
    {
        Debug.DrawRay(transform.position, lastDirection, Color.blue);

        bool digPressed = Input.GetButtonDown(digButtonName);

        if (digPressed)
        {
            float x1 = transform.position.x;
            float y1 = transform.position.y;

            RaycastHit2D[] hits = Physics2D.CircleCastAll(new Vector2(x1, y1), 0.3f, new Vector2(lastDirection.x, lastDirection.y), digDistance);

            foreach (RaycastHit2D hit in hits)
            {
                if (hit.collider)
                {
                    Diggable dig = hit.collider.GetComponent <Diggable>();
                    if (dig)
                    {
                        dig.ApplyHit(digStrength);
                        break;
                    }
                }
            }
        }

        if (Input.GetButtonDown(power0ButtonName))
        {
            if (activePowers[0] != null)
            {
                activePowers[0].OnButtonDown();
            }
        }
        if (Input.GetButtonUp(power0ButtonName))
        {
            if (activePowers[0] != null)
            {
                activePowers[0].OnButtonUp();
            }
        }

        if (Input.GetButtonDown(power1ButtonName))
        {
            if (activePowers[1] != null)
            {
                activePowers[1].OnButtonDown();
            }
        }
        if (Input.GetButtonUp(power1ButtonName))
        {
            if (activePowers[1] != null)
            {
                activePowers[1].OnButtonUp();
            }
        }

        bool gemsUpdated = false;

        for (int matrix_row = 0; matrix_row < 4; ++matrix_row)
        {
            for (int matrix_col = 0; matrix_col < 4; ++matrix_col)
            {
                if (Input.GetButtonDown(matrixButtonNames[matrix_row][matrix_col]))
                {
                    if (matrix_row == 3)
                    {
                        // Wild gems!
                        if (gemCount[4] > matrix_col)
                        {
                            if (ActivatePower(PowerColor.Wild, matrix_col))
                            {
                                gemCount[4]--;
                                gemsUpdated = true;
                            }
                        }
                    }
                    else if (matrix_col == 0)
                    {
                        // Blue gems
                        if (gemCount[0] > matrix_row)
                        {
                            if (ActivatePower(PowerColor.Blue, matrix_row))
                            {
                                gemCount[0]--;
                                gemsUpdated = true;
                            }
                        }
                    }
                    else if (matrix_col == 1)
                    {
                        // Red gems
                        if (gemCount[1] > matrix_row)
                        {
                            if (ActivatePower(PowerColor.Red, matrix_row))
                            {
                                gemCount[1]--;
                                gemsUpdated = true;
                            }
                        }
                    }
                    else if (matrix_col == 2)
                    {
                        // Yellow gems
                        if (gemCount[2] > matrix_row)
                        {
                            if (ActivatePower(PowerColor.Yellow, matrix_row))
                            {
                                gemCount[2]--;
                                gemsUpdated = true;
                            }
                        }
                    }
                    else if (matrix_col == 3)
                    {
                        // Green gems
                        if (gemCount[3] > matrix_row)
                        {
                            if (ActivatePower(PowerColor.Green, matrix_row))
                            {
                                gemCount[3]--;
                                gemsUpdated = true;
                            }
                        }
                    }
                }
            }
        }

        if (gemsUpdated)
        {
            UpdateGemLeds();
        }

        UpdateButtonColors();
    }