Exemplo n.º 1
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.º 2
0
    private void OnCollisionEnter2D(Collision2D collision)
    {
        if (collision.transform.CompareTag("Brick"))
        {
            BrickScript brickScript = collision.gameObject.GetComponent <BrickScript>();
            if (GetComponent <SpriteRenderer>().sprite == forms[1] || brickScript.hitsToBreak == 0)
            {
                int randomChance = Random.Range(1, 101);
                if (randomChance < 36)
                {
                    powerUp.GetComponent <PowerUpScript>().ChooseBuff();
                    Instantiate(powerUp, collision.transform.position, collision.transform.rotation);
                }
                Transform newExplosion = Instantiate(explosion, collision.transform.position, collision.transform.rotation);
                Destroy(newExplosion.gameObject, 1.5f);

                gm.UpdateScore(brickScript.points);
                gm.UpdateNumberOfBricks(-1);
                Destroy(collision.gameObject);
            }
            else
            {
                brickScript.ChangeSprite();
            }
        }
    }
Exemplo n.º 3
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.º 4
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();
     }
 }
 public void loseLife()
 {
     lives--;
     if (lives >= 0)
     {
         LifeBallScript lifeBallScript = lifeArr[lives].GetComponent <LifeBallScript>();
         lifeBallScript.Drop();
     }
     else
     {
         //explode all Bricks
         isGameOver = true;
         GameObject[] bricks = GameObject.FindGameObjectsWithTag("Brick");
         foreach (GameObject brick in bricks)
         {
             BrickScript brickScript = brick.GetComponent <BrickScript>();
             //brickScript.explode(false);
             brickScript.explode(true);
         }
         Destroy(paddle);
         //display game Over
         gameOverText.text = "GAME OVER";
         //Debug.Log("Game Over");
     }
 }
Exemplo n.º 6
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.º 7
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.º 8
0
 public void RemoveBrick(BrickScript brick)
 {
     bricks.Remove(brick.gameObject);
     if (bricks.Count == 0)
     {
         ResetLevel();
     }
 }
Exemplo n.º 9
0
    private void OnTriggerEnter2D(Collider2D target)
    {
        if (target.tag == "LargestBall" || target.tag == "LargeBall" || target.tag == "MediumBall" || target.tag == "SmallBall" || target.tag == "SmallestBall")
        {
            if (gameObject.tag == "FirstArrow" || gameObject.tag == "FirstStickyArrow")
            {
                PlayerScript.instance.PlayerShootOnce(true);
            }
            else if (gameObject.tag == "SecondArrow" || gameObject.tag == "SecondStickyArrow")
            {
                PlayerScript.instance.PlayerShootTwice(true);
            }
            gameObject.SetActive(false);
        }


        if (target.tag == "TopBrick" || target.tag == "UnbreakableBrickTop" || target.tag == "UnbreakableBrickBottom" || target.tag == "UnbreakableBrickLeft" || target.tag == "UnbreakableBrickRight" || target.tag == "UnbreakableBrickBottomVertical")
        {
            if (this.gameObject.tag == "FirstArrow")
            {
                PlayerScript.instance.PlayerShootOnce(true);
                this.gameObject.SetActive(false);
            }

            else if (this.gameObject.tag == "SecondArrow")
            {
                PlayerScript.instance.PlayerShootTwice(true);
                this.gameObject.SetActive(false);
            }

            if (this.gameObject.tag == "FirstStickyArrow")
            {
                SetTheStickyArrowPosition(this.gameObject);
            }

            else if (this.gameObject.tag == "SecondStickyArrow")
            {
                SetTheStickyArrowPosition(this.gameObject);
            }
        }


        if (target.tag == "BrokenBrickTop" || target.tag == "BrokenBrickBottom" || target.tag == "BrokenBrickLeft" || target.tag == "BrokenBrickRight")
        {
            BrickScript brick = target.gameObject.GetComponentInParent <BrickScript>();
            brick.StartCoroutine(brick.BreakTheBrick());
            if (gameObject.tag == "FirstArrow" || gameObject.tag == "FirstStickyArrow")
            {
                PlayerScript.instance.PlayerShootOnce(true);
            }
            else if (gameObject.tag == "SecondArrow" || gameObject.tag == "SecondStickyArrow")
            {
                PlayerScript.instance.PlayerShootTwice(true);
            }

            gameObject.SetActive(false);
        }
    }
Exemplo n.º 10
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.º 11
0
    void OnCollisionEnter2D(Collision2D other)
    {
        if (other.transform.CompareTag("Brick"))
        {
            BrickScript brickScript = other.gameObject.GetComponent <BrickScript>();



            brickScript.Break();
        }
    }
Exemplo n.º 12
0
    public void CreateBricks(int hp)
    {
        int layout = Random.Range(0, 10);

        Vector3[] positionVectors = new Vector3[8];
        if (layout == 0)
        {
            positionVectors = positionVectors1;
        }
        else if (layout == 1)
        {
            positionVectors = positionVectors2;
        }
        else if (layout == 2)
        {
            positionVectors = positionVectors3;
        }
        else if (layout == 3)
        {
            positionVectors = positionVectors4;
        }
        else if (layout == 4)
        {
            positionVectors = positionVectors5;
        }
        else if (layout == 5)
        {
            positionVectors = positionVectors6;
        }
        else if (layout == 6)
        {
            positionVectors = positionVectors7;
        }
        else if (layout == 7)
        {
            positionVectors = positionVectors8;
        }
        else if (layout == 8)
        {
            positionVectors = positionVectors9;
        }
        else
        {
            positionVectors = positionVectors10;
        }
        foreach (Vector3 v in positionVectors)
        {
            GameObject  brick       = Instantiate(brickPreFab, position + v, Quaternion.identity);
            BrickScript brickScript = brick.GetComponent <BrickScript>();
            brickScript.SetMaxHP(hp);
            numBricks++;
        }
    }
Exemplo n.º 13
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.º 14
0
    // Start is called before the first frame update
    void Start()
    {
        for (int y = 0; y < 8; y++)
        {
            for (int x = 0; x < 15; x++)
            {
                GameObject cube = GameObject.CreatePrimitive(PrimitiveType.Cube);
                cube.name = "Brick";
                cube.transform.position   = new Vector3(x * 2f - 14f, y - 1f, 0);
                cube.transform.localScale = new Vector3(1.7f, 0.7f, 1f);
                //Collider m_ObjectCollider = cube.GetComponent<Collider>();

                //
                //m_ObjectCollider = GetComponent<Collider>();
                //Here the GameObject's Collider is not a trigger
                //m_ObjectCollider.isTrigger = true;
                //m_ObjectCollider.enabled = true;
                //cube.tag="Brick";
                //cube.AddComponent<BrickScript>();
                BrickScript script = cube.AddComponent <BrickScript>() as BrickScript;
                cube.GetComponent <Collider>().isTrigger = true;
                //Output whether the Collider is a trigger type Collider or not
                //Debug.Log("Trigger On : " + cube.GetComponent<Collider>().isTrigger);
                if (y < 2)
                {
                    cube.GetComponent <Renderer>().material.color = Color.yellow;
                    script.brickStrength = 1;
                }
                else if (y < 4)
                {
                    cube.GetComponent <Renderer>().material.color = Color.cyan;
                    script.brickStrength = 2;
                }
                else if (y < 6)
                {
                    cube.GetComponent <Renderer>().material.color = Color.blue;
                    script.brickStrength = 3;
                }
                else
                {
                    cube.GetComponent <Renderer>().material.color = Color.red;
                    script.brickStrength = 4;
                }
                //cube.GetComponent<Renderer>().material.color = new Color(0.2f + y * 0.08f, 0.3f, 1.0f);

                //cube.renderer.material.color = new Color(0.2f + y * 0.08f, 0.3f, 1.0f);
            }
        }
    }
Exemplo n.º 15
0
    public void DieForReal()
    {
        BrickScript bs = GameObject.Find("BrickController").GetComponent <BrickScript> ();

        bs.setAantalLives(-1);

        int aantalLives = bs.getAantalLives();

        if (aantalLives == 0)
        {
            awardStuff.awardSCurrency(Mathf.FloorToInt(bs.score / 10));
            awardStuff.awardSExperience(Mathf.FloorToInt(bs.score / 20));
            SceneManager.LoadScene("BricksGameOver");
        }
    }
Exemplo n.º 16
0
 public void SetBrickActive(bool active, BrickScript brick)
 {
     if (active)
     {
         m_inactiveBricks.Remove(brick);
         brick.InitBrick();
         m_activeBricks.Add(brick);
     }
     else
     {
         m_inactiveBricks.Add(brick);
         m_activeBricks.Remove(brick);
         _totalScore += brick.Score;
     }
 }
Exemplo n.º 17
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.º 18
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.º 19
0
    void OnCollisionEnter2D(Collision2D other)
    {
        if (other.transform.CompareTag("brick"))
        {
            BrickScript brickScript = other.gameObject.GetComponent <BrickScript>();

            if (brickScript.hitsToBreak > 1)
            {
                brickScript.BreackBrick();
            }
            else
            {
                Transform newExplosion = Instantiate(explosion, other.transform.position, other.transform.rotation);
                Destroy(newExplosion.gameObject, 2.5f);
                gm.UpdateScore(brickScript.points);
                gm.UpdateNumberOfBricks();
                Destroy(other.gameObject);
            }
        }
    }
Exemplo n.º 20
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.º 21
0
 void OnCollisionEnter2D(Collision2D other)
 {
     if (other.transform.CompareTag("brick"))
     {
         BrickScript bs = other.gameObject.GetComponent <BrickScript>();
         if (bs.GetHitsToBreak() > 1)
         {
             bs.BrickBreak();
         }
         else
         {
             gm.UpdateScore(bs.GetPoints());
             Destroy(other.gameObject);
         }
     }
     if (other.transform.CompareTag("player"))
     {
         Vector3 vec = transform.position - other.transform.position;
         rb.velocity = vec.normalized * speed;
     }
 }
Exemplo n.º 22
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();
        }
    }
Exemplo n.º 23
0
    // Use this for initialization
    void Start()
    {
        if (SceneManager.GetActiveScene().name.Contains("UNDERWORLD"))
        {
            GetComponent <Animator>().SetBool("Underworld", true);
        }
        else if (SceneManager.GetActiveScene().name.Contains("SEA"))
        {
            GetComponent <Animator>().SetBool("Sea", true);
        }
        else
        {
            GetComponent <Animator>().SetBool("Overworld", true);
        }


        if (transform.parent != null)
        {
            hasParent = true;
            script    = GetComponentInParent <BrickScript>();
        }
    }
Exemplo n.º 24
0
    private void OnCollisionEnter2D(Collision2D other)   // other is easy to define as something you/i just hit
    // on colision you cant just do compareTag only, you need transform
    {
        if (other.transform.CompareTag("Brick")) // so if what i just hit was a brick...

        {
            BrickScript brickScript = other.gameObject.GetComponent <BrickScript>();

            if (brickScript.hitsToBreak > 1)
            {
                brickScript.breakBrick();
                brickScript.changeColor();
            }
            else
            {
                // ---- Random.Range(x,y) explanation ----
                // lets say the parameter format is (x,y) with x is inclusive and y is exclusive, which mean x <= rand < y,
                // meaning the varible rand can be equal to x but can be to y, it can be equal to the value that is lower than y
                int rand = Random.Range(1, 101);
                if (rand >= 50)
                {
                    Instantiate(powerup, other.transform.position, other.transform.rotation);
                }


                gm.updateScore(brickScript.points);
                gm.reduceNumberOfBricks();

                Transform newExplosion = Instantiate(explosion, other.transform.position, other.transform.rotation); // this create the explosion effect with the position of the brick
                Destroy(newExplosion.gameObject, 2f);
                Destroy(other.gameObject);                                                                           //...then destroy it this other cause other is pointing at the brick
            }

            audio.Play();
        }
    }
Exemplo n.º 25
0
	void OnTriggerEnter2D (Collider2D target) {
		if (target.tag == "LargestBall" || target.tag == "LargeBall" || target.tag == "MediumBall" || target.tag == "SmallBall" || target.tag == "SmallestBall") {
			if (gameObject.tag == "FirstArrow" || gameObject.tag == "FirstStickyArrow") {
				PlayerScript.instance.PlayerShootOnce (true);
			} else if (gameObject.tag == "SecondArrow" || gameObject.tag == "SecondStickyArrow") {
				PlayerScript.instance.PlayerShootTwice (true);
			}
			gameObject.SetActive (false);
		} // If the arrow hits a ball
			
		if (target.tag == "TopBrick" || target.tag == "UnbreakableBrickTop" || target.tag == "UnbreakableBrickBottom"
			|| target.tag == "UnbreakableBrickLeft" || target.tag == "UnbreakableBrickRight"
			|| target.tag == "UnbreakableBrickBottomVertical") {

			if (this.gameObject.tag == "FirstArrow") {
				PlayerScript.instance.PlayerShootOnce (true);
				this.gameObject.SetActive (false);
			} else if (this.gameObject.tag == "SecondArrow") {
				PlayerScript.instance.PlayerShootTwice (true);
				this.gameObject.SetActive (false);
			}

			if (this.gameObject.tag == "FirstStickyArrow") {
				canShootStickyArrow = false;
				Vector3 targetPos = target.transform.position;
				Vector3 temp = transform.position;

				if (target.tag == "TopBrick") {
					targetPos.y -= 0.989f;
				} else if (target.tag == "UnbreakableBrickTop" || target.tag == "UnbreakableBrickBottom" || target.tag == "UnbreakableBrickLeft" || target.tag == "UnbreakableBrickRight") {
					targetPos.y -= 0.75f;
				} else if (target.tag == "UnbreakableBrickBottomVertical") {
					targetPos.y -= 0.97f;
				}
					
				temp.y = targetPos.y;
				transform.position = temp;
				AudioSource.PlayClipAtPoint (clip, transform.position);
				StartCoroutine ("ResetStickyArrow");

			} else if (this.gameObject.tag == "SecondStickyArrow") {
				canShootStickyArrow = false;
				Vector3 targetPos = target.transform.position;
				Vector3 temp = transform.position;

				if (target.tag == "TopBrick") {
					targetPos.y -= 0.989f;
				} else if (target.tag == "UnbreakableBrickTop" || target.tag == "UnbreakableBrickBottom" || target.tag == "UnbreakableBrickLeft" || target.tag == "UnbreakableBrickRight") {
					targetPos.y -= 0.75f;
				} else if (target.tag == "UnbreakableBrickBottomVertical") {
					targetPos.y -= 0.97f;
				}

				temp.y = targetPos.y;
				transform.position = temp;
				AudioSource.PlayClipAtPoint (clip, transform.position);
				StartCoroutine ("ResetStickyArrow");
			}
		} // If the arrow hits the top brick or an unbreakable brick

		if (target.tag == "BrokenBrickTop" || target.tag == "BrokenBrickBottom" || target.tag == "BrokenBrickLeft" || target.tag == "BrokenBrickRight") {
			BrickScript brick = target.gameObject.GetComponentInParent<BrickScript> ();
			brick.StartCoroutine (brick.BreakTheBrick ());

			if (gameObject.tag == "FirstArrow" || gameObject.tag == "FirstStickyArrow") {
				PlayerScript.instance.PlayerShootOnce (true);
			} else if (gameObject.tag == "SecondArrow" || gameObject.tag == "SecondStickyArrow") {
				PlayerScript.instance.PlayerShootTwice (true);
			}

			gameObject.SetActive (false);
		} // If the arrow hits a broken brick
	} // OnTriggerEnter2D
Exemplo n.º 26
0
    void OnCollisionEnter(Collision other)
    {
        Vector3 right = Vector3.Cross(-1 * this.transform.forward, this.transform.up);
        Vector3 down  = Vector3.Cross(-1 * this.transform.forward, this.transform.right);
        Vector3 left  = Vector3.Cross(-1 * this.transform.forward, -1 * this.transform.up);
        Vector3 up    = Vector3.Cross(-1 * this.transform.forward, -1 * this.transform.right);

        Vector3 center = this.collider.bounds.center;

        float distance = .1f;


        Vector3 topRight = center;

        topRight.y += this.collider.bounds.size.y / 2 - distance / 2;
        topRight.x += this.collider.bounds.size.x / 2 - distance / 2;

        Vector3 topCenter = center;

        topCenter.y += this.collider.bounds.size.y / 2 - distance / 2;

        Vector3 topLeft = center;

        topLeft.y += this.collider.bounds.size.y / 2 - distance / 2;
        topLeft.x -= this.collider.bounds.size.x / 2 - distance / 2;

        Vector3 botRight = center;

        botRight.y -= this.collider.bounds.size.y / 2 - distance / 2;
        botRight.x += this.collider.bounds.size.x / 2 - distance / 2;

        Vector3 botLeft = center;

        botLeft.y -= this.collider.bounds.size.y / 2 - distance / 2;
        botLeft.x -= this.collider.bounds.size.x / 2 - distance / 2;

        RaycastHit edgeInfo1;
        RaycastHit edgeInfo2;
        RaycastHit centerInfo;

        //top
        bool hitTopRight  = Physics.Raycast(topRight, up, out edgeInfo1, distance);
        bool hitTopLeft   = Physics.Raycast(topLeft, up, out edgeInfo2, distance);
        bool hitTopCenter = Physics.Raycast(topCenter, up, out centerInfo, distance);

        bool hitTop = hitTopLeft || hitTopRight || hitTopCenter;

        if (hitTop)
        {
            if (hitTopCenter && centerInfo.collider.gameObject.tag == "Brick")
            {
                BrickScript brick = centerInfo.collider.gameObject.GetComponent <BrickScript>();
                brick.marioHit();
            }
        }
        //left

        //bot
        bool hitBotRight = Physics.Raycast(botRight, down, out edgeInfo1, distance);
        bool hitBotLeft  = Physics.Raycast(botLeft, down, out edgeInfo2, distance);
        bool hitBot      = hitBotRight || hitBotLeft;

        if (hitBot)
        {
            Vector3 vel  = rigidbody.velocity;
            string  tag1 = "none";
            string  tag2 = "none";

            if (hitBotLeft)
            {
                tag2 = edgeInfo2.collider.tag;
            }
            if (hitBotRight)
            {
                tag1 = edgeInfo1.collider.tag;
            }

            if (tag1 == "Enemy")
            {
                vel.y += 5;
                Destroy(edgeInfo1.collider.gameObject);
            }
            else if (tag2 == "Enemy")
            {
                vel.y += 5;
                Destroy(edgeInfo2.collider.gameObject);
            }
            else if (tag1 == "Shell" || tag2 == "Shell")
            {
                vel.y += 5;
            }
            else
            {
                grounded = true;
                jumping  = false;
            }
            rigidbody.velocity = vel;
        }


        //right
        //Debug.DrawLine(topRight, topRight + (rRay.direction * distance), Color.red);
        //Debug.DrawLine(botRight, botRight + (rRay.direction * distance), Color.red);


        //grounded = true;
        //jumping = false;
    }
Exemplo n.º 27
0
    void OnCollisionEnter2D(Collision2D other)
    {
        int randomNumber = Random.Range(1, 101);

        // Handle collisions with bricks
        if (other.transform.CompareTag(GameManager.BRICK))
        {
            BrickScript brickScript =
                other.gameObject.GetComponent <BrickScript>();

            // Instantiate LifeAdder randomally - chanceToLifeAdder chance to get a LifeAdder.
            if (randomNumber <= chanceToLifeAdder)
            {
                Instantiate(lifeAdderObject,
                            other.transform.position,
                            other.transform.rotation);
            }

            // Explosion effect when breaking a brick
            Transform newExplosion =
                Instantiate(explosion,
                            other.transform.position,
                            other.transform.rotation);
            Destroy(newExplosion.gameObject, 2.5f);

            gameManager.UpdateScore(brickScript.points);
            gameManager.BricksUpdate();
            Destroy(other.gameObject);
        }

        // Handle collisions with harder bricks
        if (other.transform.CompareTag(GameManager.HARDER_BRICK))
        {
            HarderBrickScript harderBrickScript =
                other.gameObject.GetComponent <HarderBrickScript>();

            if (harderBrickScript.brickLives > 1)
            {
                harderBrickScript.BreakBrick();
            }
            else
            {
                if (randomNumber <= chanceToLifeAdder)
                {
                    Instantiate(lifeAdderObject,
                                other.transform.position,
                                other.transform.rotation);
                }

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

                gameManager.UpdateScore(harderBrickScript.points);
                gameManager.BricksUpdate();
                Destroy(other.gameObject);
            }
        }
    }
Exemplo n.º 28
0
    private void Update()
    {                                 //timer
        if (Grabby.startGame == true) //ballscript, grabby, manager
        {
            if (paused == false)
            {
                if (lose == false)
                {
                    //Debug.Log("lose is false");
                    timeLeft     -= Time.deltaTime * Time.timeScale;
                    TimeText.text = "Time: " + timeLeft;
                    if (timeLeft < 0)
                    {
                        Debug.Log("lose");
                        Lost();
                        lose = true;
                    }
                }
                else
                {
                    TimeText.text = "Time: 0"; //bc it would end on a negative number
                }
            }
        }

        //start menu
        if (Grabby.startGame == true)
        {
            StartMenu.gameObject.SetActive(false);
        }

        //Pausing
        if ((lose == false && Grabby.startGame == true) || PAUSE_GAME)
        {
            if (Input.GetButtonDown("Fire1"))
            {
                if (PauseMenu.gameObject.activeSelf == false)
                {
                    PauseMenu.gameObject.SetActive(true);

                    pausedGOver.gameObject.SetActive(false);
                    pause.gameObject.SetActive(true);

                    Time.timeScale = 0.0f;
                    PAUSE_GAME     = true;
                }
                else// if (PauseMenu.gameObject.activeSelf == true)
                {
                    PauseMenu.gameObject.SetActive(false);
                    PAUSE_GAME = false;

                    Time.timeScale = runTimeScale;
                }
            }
        }

        if (PauseMenu.gameObject.activeSelf == true)
        {
            paused = true;
        }
        else
        {
            paused = false;
        }

        if (!lose && !PAUSE_GAME)
        {
            Time.timeScale = runTimeScale;
        }

        //updating score
        if (lose == false)
        {
            ScoreText.text = "Score: " + BrickScript.score;
        }

        //updating highscore
        if (BrickScript.score > PlayerPrefs.GetInt("Highscore", 0))
        {
            PlayerPrefs.GetInt("Highscore", BrickScript.score);
        }

        //restart script
        if (lose == true)
        {
            if (ScoreManager.HighScore < BrickScript.score)
            {
                ScoreManager.HighScore = BrickScript.score;
                ScoreManager.SaveScore();
            }
            if (doRestart)
            {
                runTimeScale   = 1.0f;
                Time.timeScale = runTimeScale;
                BrickScript.ResetBrickCount();
                SceneManager.LoadScene("NewGameScene");
            }
        }
    }