Exemplo n.º 1
0
    private void OnCollisionEnter2D(Collision2D collision)
    {
        if (collision.transform.CompareTag("Brick"))
        {
            BrickScript brickScript = collision.gameObject.GetComponent <BrickScript>();

            if (brickScript.hitsToBreak > 1)
            {
                brickScript.BreakBrick();
            }
            else
            {
                int randChance = Random.Range(1, 100);

                if (randChance < 50)
                {
                    Instantiate(powerup, collision.transform.position, collision.transform.rotation);
                }


                Transform newExplosion = Instantiate(explosion, collision.transform.position, collision.transform.rotation); //Create an explosion

                Destroy(newExplosion.gameObject, 2.5f);                                                                      //Destroy the explosion effect

                gm.UpdateScore(brickScript.points);

                gm.UpdateNumberOfBricks();

                Destroy(collision.gameObject); // Destroy the brick
            }

            hitSound.Play();
        }
    }
Exemplo n.º 2
0
 private void OnCollisionEnter2D(Collision2D other)
 {
     if (other.transform.CompareTag("Brick"))
     {
         BrickScript brickScript = other.gameObject.GetComponent <BrickScript>();
         if (brickScript.hitsToBreak > 1)
         {
             brickScript.BreakBrick();
             var audioManager = FindObjectOfType <AudioManager>();
             audioManager.Play("Hit");
         }
         else
         {
             UpgradeLogic(other);
             gm.ChangeScore(brickScript.pointForBrick);
             brickScript.Explode();
             gm.ChangeNumberOfBricks();
             var audioManager = FindObjectOfType <AudioManager>();
             audioManager.Play("Blup");
         }
     }
     else if (!gm.StartPage.activeSelf)
     {
         var audioManager = FindObjectOfType <AudioManager>();
         audioManager.Play("Hit");
     }
 }
Exemplo n.º 3
0
 void OnCollisionEnter2D(Collision2D other)
 {
     if (other.transform.CompareTag("Brick"))
     {
         BrickScript brickScript = other.gameObject.GetComponent <BrickScript>();
         if (brickScript.hitsToBreak > 1)
         {
             brickScript.BreakBrick();
         }
         else
         {
             int randChance = Random.Range(1, 101);
             if (randChance < 50)
             {
                 Instantiate(powerup, other.transform.position, other.transform.rotation);
             }
             Transform newExplosion = Instantiate(explosion, other.transform.position, other.transform.rotation);
             Destroy(newExplosion.gameObject, 2.5f);
             gm.UpdateScore(brickScript.points);
             gm.UpdateNumberOfBricks();
             Destroy(other.gameObject);
         }
         audio.Play();
     }
 }
Exemplo n.º 4
0
 // Effects of the collision when the ball collide with the bricks
 void OnCollisionEnter2D(Collision2D other)
 {
     if (other.transform.CompareTag("brick"))
     {
         int randChance = Random.Range(1, 101);
         if (randChance < 50)
         {
             Instantiate(powerup, other.transform.position, other.transform.rotation);
         }
         BrickScript brickScript = other.gameObject.GetComponent <BrickScript>();
         if (brickScript.hittobreak > 1)
         {
             brickScript.BreakBrick();
         }
         else
         {
             // Effects
             Transform newExplosion = Instantiate(effect1, other.transform.position, other.transform.rotation);
             // Brick will be destroyed
             Destroy(newExplosion.gameObject, 2.5f);
             // tranfer the number of bricks that was destroyed into the point
             gm.UpdateScore(brickScript.point);
             gm.UpdateNumberOfBricks();
             Destroy(other.gameObject);
         }
     }
     // Play the music
     audio1.Play();
 }
Exemplo n.º 5
0
    void OnCollisionEnter2D(Collision2D other)
    {
        if (other.transform.CompareTag("brick"))
        {
            BrickScript brickScript = other.gameObject.GetComponent <BrickScript> ();
            if (brickScript.hitsBreak > 1)
            {
                brickScript.BreakBrick();
            }
            else
            {
                int randChance = Random.Range(1, 101);
                if (randChance < dropchancepowerup)
                {
                    Instantiate(powerup, other.transform.position, other.transform.rotation);
                }
                //Instancie l'explosion (effet) au niveau de la brique, puis detruit l'explosion au bout d'une seconde
                Transform newExplosion = Instantiate(explosion, other.transform.position, other.transform.rotation);
                Destroy(newExplosion.gameObject, 1f);

                gm.UpdateScore(brickScript.points);
                gm.UpdateBricks();
                // Detruit la brique après avoir update le score et le nombre de briques
                Destroy(other.gameObject);
            }

            audio.Play();
        }
    }
Exemplo n.º 6
0
    void OnCollisionEnter2D(Collision2D other)
    {
        if (other.transform.CompareTag("Brick"))
        {
            SoundManagerScript.PlaySound("brickHitSound");
            BrickScript brickScript = other.gameObject.GetComponent <BrickScript>();

            if (brickScript.hitsToBreak > 1)
            {
                brickScript.BreakBrick();
            }

            else
            {
                int randChance = Random.Range(1, 101);
                if (randChance < 15)
                {
                    Instantiate(extraLifePowerup, other.transform.position, other.transform.rotation);
                }
                else if (randChance < 30)
                {
                    Instantiate(extendPowerup, other.transform.position, other.transform.rotation);
                }
                else if (randChance < 45)
                {
                    Instantiate(shrinkPowerup, other.transform.position, other.transform.rotation);
                }

                Transform newExplosion = Instantiate(explosion, other.transform.position, other.transform.rotation);
                Destroy(newExplosion.gameObject, 2.5f);

                gm.UpdateScore(brickScript.points);
                gm.UpdateNumberOfBricks();
                Destroy(other.gameObject);
            }
        }
        else if (other.transform.CompareTag("Paddle"))
        {
            SoundManagerScript.PlaySound("paddleHitSound");

            rb.velocity = Vector2.zero;
            float hitpoint     = other.contacts[0].point.x;
            float paddleCenter = other.gameObject.transform.position.x;
            float difference   = paddleCenter - hitpoint;
            if (hitpoint < paddleCenter)
            {
                rb.AddForce(new Vector2(-(Mathf.Abs(difference * 200)), speed));
            }
            else
            {
                rb.AddForce(new Vector2(Mathf.Abs(difference * 200), speed));
            }
        }
        else if (other.transform.CompareTag("Wall"))
        {
            SoundManagerScript.PlaySound("wallHitSound");
        }
    }
Exemplo n.º 7
0
    void OnCollisionEnter2D(Collision2D other)
    {
        if (other.gameObject.name == "Paddle")
        {
            SoundManager.Instance.PlayOneShot(SoundManager.Instance.paddleHit);
        }
        if ((other.gameObject.name == "leftPanel") || (other.gameObject.name == "rightPanel"))
        {
            SoundManager.Instance.PlayOneShot(SoundManager.Instance.wallHit);
        }
        if (other.transform.CompareTag("Brick"))
        {
            BrickScript brickScript = other.gameObject.GetComponent <BrickScript>();
            if (brickScript.ability > 1)
            {
                brickScript.BreakBrick();
            }
            else
            {
                int random = Random.Range(1, 501);
                if (random < 50 && random > 450)
                {
                    Instantiate(powerUp, other.transform.position, other.transform.rotation);
                }
                else if (random > 100 && random < 250)
                {
                    Instantiate(scoreUp50, other.transform.position, other.transform.rotation);
                }
                else if (random == 250)
                {
                    Instantiate(scoreUp250, other.transform.position, other.transform.rotation);
                }
                else if (random > 50 && random <= 100 && random >= 400 && random <= 450)
                {
                    Instantiate(powerDown, other.transform.position, other.transform.rotation);
                }
                else if (random > 250 && random < 350)
                {
                    Instantiate(scoreDown, other.transform.position, other.transform.rotation);
                }

                Transform newDestroy = Instantiate(destroy, other.transform.position, other.transform.rotation);
                Destroy(newDestroy.gameObject, 2);
                gm.UpdateScore(brickScript.points);
                gm.UpdateNumberOfBricks();
                Destroy(other.gameObject);
            }
            SoundManager.Instance.PlayOneShot(SoundManager.Instance.brickHit);
        }
    }
Exemplo n.º 8
0
    void OnCollisionEnter2D(Collision2D other)
    {
        if (other.transform.CompareTag("brick"))
        {
            BrickScript brickScript = other.gameObject.GetComponent <BrickScript>();

            if (brickScript.hitsToBreak > 1)
            {
                brickScript.BreakBrick();
            }
            else
            {
                whichpowerup = Random.Range(1, 6);

                if (whichpowerup == 1)
                {
                    Instantiate(extraLife, transform.position, extraLife.rotation);
                }

                else if (whichpowerup == 2)
                {
                    Instantiate(fasterSpeed, transform.position, fasterSpeed.rotation);
                }

                else if (whichpowerup == 3)
                {
                    Instantiate(lowerSpeed, transform.position, lowerSpeed.rotation);
                }

                else if (whichpowerup == 4)
                {
                    Instantiate(widePaddle, transform.position, widePaddle.rotation);
                }

                else if (whichpowerup == 5)
                {
                    Instantiate(thinPaddle, transform.position, thinPaddle.rotation);
                }
                Transform newExplosion = Instantiate(explosion, other.transform.position, other.transform.rotation);
                Destroy(newExplosion.gameObject, 2.5f);

                gm.UpdateScore(brickScript.points);
                gm.UpdateNumberOfBricks();
                Destroy(other.gameObject);
                speed = speed + 5;
            }
        }
    }
Exemplo n.º 9
0
    void OnCollisionEnter2D(Collision2D other)
    {
        if (other.transform.CompareTag("brick"))
        {
            BrickScript brickScript = other.gameObject.GetComponent <BrickScript>();
            if (brickScript.hitsToBreak > 1)
            {
                brickScript.BreakBrick();
            }
            else
            {
                gm.UpdateScore(other.gameObject.GetComponent <BrickScript>().points);
                gm.UpdateNumberOfBricks();

                Destroy(other.gameObject);
            }
        }
    }
Exemplo n.º 10
0
    // Fungsi jika menabrak collision (brick atau dll) brick pecah
    void OnCollisionEnter2D(Collision2D other)
    {
        // Bila menabrak brick
        if (other.transform.CompareTag("Brick"))                                     // Pada Collision2D tak bisa langsung ambil Comparetag
        {
            FindObjectOfType <AudioManager> ().Play("Brick");                        // Efek kena brick
            BrickScript brickScript = other.gameObject.GetComponent <BrickScript>(); // Ambil script nya brick
            // Cek jika hit point
            if (brickScript.hitPoint > 1)                                            // Brick belum hancur, kurangi hit point brick
            {
                brickScript.BreakBrick();
            }
            else               // Brick hancur
            {
                // Memunculkan extra live secara random saat brick hancur
                int rd = Random.Range(1, 101);                 // Menggambil nilai acak dari 1 sampai 100 (nilai maks pada int eksklusif)
                if (rd > 10 && rd < 20)
                {
                    Instantiate(extraLive, other.transform.position, other.transform.rotation);
                }

                Transform newExplosion = Instantiate(explosion, other.transform.position, other.transform.rotation);
                Destroy(newExplosion.gameObject, 2.5f);    // Instantiate efek pecah
                gm.UpdateScore(brickScript.points);        // Ambil nilai point brick dari BrickScript dan diupdate ke gm
                gm.UpdateNumberOfBrick();                  // Cek banyak brick yang tersisa
                Destroy(other.gameObject);
            }
        }

        // Bila menabrak paddle
        if (other.transform.CompareTag("Paddle"))
        {
            FindObjectOfType <AudioManager> ().Play("Paddle");
        }

        // Bila menabrak wall
        if (other.transform.CompareTag("Wall"))
        {
            FindObjectOfType <AudioManager> ().Play("Wall");
        }
    }
Exemplo n.º 11
0
    void OnCollisionEnter2D(Collision2D other)
    {
        if (other.transform.CompareTag("brick"))
        {
            BrickScript brickScripts = other.gameObject.GetComponent <BrickScript>();
            if (brickScripts.hitsToBreak > 1)
            {
                brickScripts.BreakBrick();
            }
            else
            {
                Transform newExplosion = Instantiate(explosion, other.transform.position, other.transform.rotation);
                Destroy(newExplosion.gameObject, 2.5f);
                gm.updateScore(brickScripts.points);
                gm.UpdateNumberOfBricks();
                Destroy(other.gameObject);

                audio.Play();
            }
        }
    }
Exemplo n.º 12
0
    void OnCollisionEnter2D(Collision2D other)
    {
        //is the item a brick?
        //if yes
        //destroy it
        //Play explosion particles
        if (other.transform.CompareTag("brick"))
        {
            // if brick has more than 1 hit to break
            // replace sprite with creacke bricked sprite
            BrickScript brickScript = other.gameObject.GetComponent <BrickScript> ();
            if (brickScript.hitsToBreak > 1)
            {
                brickScript.BreakBrick();
            }
            else
            {
                // extra life power up spawner
                // random chance
                // if number is less that 50
                // spawn extra life power up
                int randChance = Random.Range(1, 101);
                if (randChance > 50)
                {
                    Instantiate(powerup, other.transform.position, other.transform.rotation);
                }

                Transform newExplosion = Instantiate(explosion, other.transform.position, other.transform.rotation);
                //Destroy explosion particle from unity after 2.5f
                Destroy(newExplosion.gameObject, 2.5f);

                // check the worth of points the brick that the user hit and give points accordingly
                gm.UpdateScore(brickScript.points);
                gm.UpdateNumberOfBricks();
                Destroy(other.gameObject);
            }
            // play ball sound effect
            audio.Play();
        }
    }