예제 #1
0
        private void OnTriggerEnter2D(Collider2D collision)
        {
            if (collision.tag == TagForDestroy && !collision.attachedRigidbody.isKinematic)
            {
                Ball ballForDestroy = collision.GetComponent <Ball>();
                if (ballForDestroy && ballForDestroy.WasJoin)
                {
                    Balls.EmitEffect("BallCollision", ballForDestroy.Pos, -ballForDestroy.Vel);
                    baseBall = ballForDestroy.GetBaseBall();
                    if (baseBall)
                    {
                        Balls.EmitEffect("GameOverCollision", ballForDestroy.Pos, -ballForDestroy.Vel);
                        //Balls.WasGameOver = true;
                        UIManager.GameOver.Show();
                    }
                    else
                    {
                        float splashSpeed = ballForDestroy.Vel.y * 10f;
                        Splash(ballForDestroy.Pos.x, Mathf.Max(splashSpeed, 0.2f));
                        Vector3 force = new Vector3(0f, -ballForDestroy.Vel.y, -ballForDestroy.Vel.magnitude * 0.1f);

                        Balls.EmitCoin(ballForDestroy);
                        //   GameData.Coins++;
                        SoundManager.Play("gemAdded", Random.Range(0.9f, 1.1f), 1f);
                        Balls.EmitEffect("BallCollision", ballForDestroy.Pos, -ballForDestroy.Vel);
                        if (ballForDestroy.BallType == BallType.Lightning)
                        {
                            ballForDestroy.BallType = BallType.Simple;
                        }
                        ballForDestroy.Kill(Balls.main.BallScore, Vector3.zero, 0f);
                    }
                }
            }
        }
예제 #2
0
 public void SetBonusIcon(Sprite sprite)
 {
     bonusRenderer.gameObject.SetActive(true);
     bonusRenderer.sprite = sprite;
     bonusRenderer.color  = Color.white;
     bonusRenderer.gameObject.ScaleFrom(Vector3.zero, 0.5f, 0f, EaseType.spring);
     Balls.EmitEffect("BallCollision", Pos, Vector2.zero);
 }
예제 #3
0
        private IEnumerator EmitRoutine(float delay)
        {
            yield return(new WaitForSeconds(delay));

            SetVelocity(MainParticles, ball.Vel);
            PlaySound("bomb", Random.Range(0.9f, 1.1f), 0f, 1f);
            Vector2 pos        = transform.position = ball.Pos;
            bool    wasExplode = false;

            ball.Destroy();
            float minRadius      = Radius;
            float maxRadius      = Radius * 2f;
            int   collidersCount = Physics2D.OverlapCircleNonAlloc(pos, maxRadius, bombHitColliders, LayerMask.GetMask(CollisionMask));

            for (int i = 0; i < collidersCount; i++)
            {
                Collider2D hit = bombHitColliders[i];
                if (hit.attachedRigidbody != null && !hit.attachedRigidbody.isKinematic)
                {
                    Vector2 direction = hit.attachedRigidbody.position - pos;
                    int     count     = Physics2D.LinecastNonAlloc(pos, hit.attachedRigidbody.position, bombRayCastHits, LayerMask.GetMask(CollisionMask));
                    if (count > 0)
                    {
                        RaycastHit2D raycastHit = bombRayCastHits[0];
                        if (raycastHit.rigidbody != null && raycastHit.rigidbody == hit.attachedRigidbody)
                        {
                            Debug.DrawLine(pos, hit.attachedRigidbody.position, Color.red, 1f);
                            Ball b = hit.GetComponent <Ball>();
                            if (b && !b.Destroying)
                            {
                                float   distance = Vector2.Distance(pos, b.Pos);
                                Vector2 force    = direction.normalized * Power;
                                b.BallBody2D.AddForceAtPosition(force, pos, ForceMode2D.Impulse);
                                yield return(null);

                                //if (b.BallType != BallType.Frozen && b.BallType != BallType.Bubble && b.BallType != BallType.Bomb && distance < minRadius)
                                if (distance < minRadius)
                                {
                                    if (b.BallType != BallType.Frozen && b.BallType != BallType.Bubble)
                                    {
                                        b.BallType = BallType.Crashed;
                                    }
                                    b.Kill(Balls.main.BallScore, force / distance, distance * 0.05f * Time.timeScale);
                                    Balls.EmitEffect("BallCollision", raycastHit.point, force / 10f);
                                    wasExplode = true;
                                }
                            }
                        }
                    }
                }
            }
            if (wasExplode)
            {
                SoundManager.Play("ballsCrack", pos, Random.Range(1.4f, 1.6f), 1f, 0.05f);
            }
            Balls.Shake();
        }
예제 #4
0
 private void OnCollisionEnter(Collision collision)
 {
     if (collision.transform.tag == CollisionTag)
     {
         float vel = collision.rigidbody.velocity.sqrMagnitude;
         if (vel > MinVel)
         {
             float volume = Mathf.Clamp(vel / 100f, 0f, 1f);
             float pitch  = Random.Range(1.5f, 2f);
             SoundManager.Play(SoundName, pitch, volume);
             Balls.EmitEffect("BallCollision", collision.contacts[0].point, collision.rigidbody.velocity / 2f);
         }
     }
 }
예제 #5
0
        private void OnCollisionEnter2D(Collision2D col)
        {
            if (killAfterJoint)
            {
                Kill(Balls.main.BallScore, Vel, 0f);
                return;
            }

            if (col.transform.tag == "wall")
            {
                if (Vel.sqrMagnitude > 10f)
                {
                    Balls.EmitEffect("BallCollision", col.contacts[0].point, Vel / 2f);
                    float volume = Mathf.Clamp(Vel.sqrMagnitude / 100f, 0.2f, 1f);
                    float pich   = Random.Range(1.25f, 1.5f);
                    PlaySound("wallCollision", pich, volume);
                }
                WasJoin = true;
            }
            else if (col.transform.tag == tag && !gunBall)
            {
                Ball ball = col.gameObject.GetComponent <Ball>();
                if (ball)
                {
                    if (BallType == BallType.Hammer)// ball.BallType == BallType.Hammer)
                    {
                        if (ball.BallType == BallType.Simple)
                        {
                            ball.BallType = BallType.Crashed;
                        }
                        Vector2 force = Vel;
                        ball.BallBody2D.AddForceAtPosition(force, Pos, ForceMode2D.Impulse);
                        ball.Kill(Balls.main.BallScore, force, 0.01f);
                        return;
                    }
                    if (Join(ball))
                    {
                    }
                }
            }
        }
예제 #6
0
 private bool Join(Ball ball)
 {
     if (!joints.ContainsKey(ball) && !ball.joints.ContainsKey(this))
     {
         if (ball.gunBall)
         {
             Ball baseBall = GetBaseBall();
             if (baseBall)
             {
                 Vector2 pos = (Pos + ball.Pos) / 2f;
                 Balls.EmitEffect("GameOverCollision", pos, Vel);
                 UIManager.GameOver.Show();
             }
             else if (!IsKinematic && WasJoin)
             {
                 BallType = BallType.Crashed;
                 Kill(Balls.main.BallScore, Vel * -1f, 0.01f);
                 return(false);
             }
         }
         else
         {
             SpringJoint2D joint = GetJoint(ball);
             ProcessJoinWith(ball, joint);
             ball.ProcessJoinWith(this, joint);
             if (!Destroying && BallColor == ball.BallColor)
             {
                 Balls.EmitEffect("BallCollision", (Pos + ball.Pos) / 2f, Vel);
                 StartCoroutine(CheckChainRoutine(0.25f));
             }
             float volume = Mathf.Clamp(Vel.sqrMagnitude / 10f, 0.1f, 1f);
             float pich   = Mathf.Clamp(Vel.sqrMagnitude / 10f, 1f, 1.2f);
             PlaySound("ballCollision", pich, volume);
             ball.WasJoin = WasJoin = true;
             return(true);
         }
     }
     return(false);
 }