コード例 #1
0
ファイル: BallsGun.cs プロジェクト: Crazy0wl/Magnet_Balls_2
        private void Shot(Vector3 touchPos, bool hasGravity)
        {
            if (CanShot())
            {
                //if (!Balls.EndlessMode)
                //{
                //    if (BallsCount > 0 && Balls.main.BallsLimit)
                //    {
                //        BallsCount--;
                //    }
                //    else
                //    {
                //        UIManager.GameOver.Show();
                //        return;
                //        // TODO: show no more balls
                //    }
                //}

                HideTutorial();
                Camera  cam     = GameManager.main.CamController.Cam;
                Vector3 heading = touchPos - cam.WorldToScreenPoint(GetShotPos());
                ballForShot.HasGravity = hasGravity;
                ballForShot.Shot(heading.normalized * ShotStretch);
                ballForShot.transform.parent = Balls.main.transform;
                Balls.AddBall(ballForShot);
                Balls.main.ComboNum = 1;
                Charge();
                PlaySound("shot", UnityEngine.Random.Range(0.9f, 1.1f), 1f);
            }
        }
コード例 #2
0
        private IEnumerator EmitRoutine(float delay)
        {
            yield return(new WaitForSeconds(delay));

            transform.position = ball.Pos;
            ForceBalls();
            PlaySound("lightning", Random.Range(0.9f, 1.1f), 0f, 1f);
            Ball b = null;

            while ((b = GetBallForDestroy()) && iterCounter++ < MAX_COUNT)
            {
                //  if (ball.WasJoin Joints.Count > 0)
                {
                    Stack <Ball> path = ball.GetPathTo(b);
                    if (path.Contains(ball))
                    {
                        Lightning lightning = Balls.EmitLightning();
                        b.Targeted = true;
                        Ball[] pathArray = path.ToArray();
                        lightning.Emit(b, pathArray);
                        yield return(new WaitForSeconds(0.15f));
                    }
                }
            }
            if (ball.BallType == BallType.Lightning)
            {
                ball.BallType = BallType.Simple;
                ball.Kill(0, Vector2.zero, 0.1f);
            }
        }
コード例 #3
0
 public override bool Show(float delay = 0f)
 {
     if (base.Show(delay))
     {
         if (Balls.EndlessMode)
         {
             UIManager.ShowMessage("Endless mode");
         }
         else
         {
             UIManager.ShowMessage("Adventure mode");
         }
         GameManager.main.Gameplay.SetActive(true);
         if (Balls.Restart())
         {
             UIManager.Info.Show();
             Balls.Score = 0;
             currScore   = 0;
         }
         else
         {
             currScore = Balls.Score;
         }
         AddScoreText.text  = "";
         ScoreText.text     = string.Format("{0}", currScore);
         BestScoreText.text = string.Format("{0}", GameData.OverallBest);
         return(true);
     }
     return(false);
 }
コード例 #4
0
ファイル: WaterWave.cs プロジェクト: Crazy0wl/Magnet_Balls_2
        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);
                    }
                }
            }
        }
コード例 #5
0
ファイル: BallsGun.cs プロジェクト: Crazy0wl/Magnet_Balls_2
        private IEnumerator GenerateGunBallsRoutine()
        {
            List <BallColor> colors = new List <BallColor>(Balls.EndlessMode ? Balls.Colors : Balls.GetColorSet());

            if (colors.Contains(BallColor.None))
            {
                colors.Remove(BallColor.None);
            }
            charging = true;
            Vector3 gunPos = transform.position;

            gunPos.x           = 0;
            gunPos.z           = -0.5f;
            transform.position = gunPos;

            for (int i = 0; i < ShotCount; i++)
            {
                BallColor color   = colors[UnityEngine.Random.Range(0, colors.Count)];
                Vector2   pos     = new Vector2(-(ShotCount + 1) / 2f + (i + 1), 0f);
                Ball      newBall = Balls.CreateGunBall(pos, color);
                balls.Add(newBall);
                yield return(new WaitForEndOfFrame());
            }
            charging = false;
            Charge();
        }
コード例 #6
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);
 }
コード例 #7
0
 public void OnRestartPressed()
 {
     if (Hide())
     {
         AdManager.ShowInterstitial();
         Balls.Restart();
     }
 }
コード例 #8
0
 public void RestartPressed()
 {
     if (Hide())
     {
         UIManager.Gameplay.Show();
         AdManager.ShowInterstitial();
         Balls.Restart();
     }
 }
コード例 #9
0
ファイル: BombBall.cs プロジェクト: Crazy0wl/Magnet_Balls_2
        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();
        }
コード例 #10
0
 public void OnBonusBallPressed(BonusButton btn)
 {
     if (Balls.Gun.BallForShotType == BallType.Simple)
     {
         GameData.Coins -= btn.Cost;
         Balls.Gun.SetGunBallType(btn.Bonus);
         BonusPanel.SetActive(false);
         Balls.Activate(0.1f);
     }
 }
コード例 #11
0
        private IEnumerator KillRoutine(int scoreToAdd, Vector2 force, float delay)
        {
            Balls.EmitBonus(this, force, delay);
            yield return(null);

            if (scoreToAdd != 0)
            {
                Balls.AddScore(scoreToAdd);
            }
        }
コード例 #12
0
 public void MainMenuPressed()
 {
     if (Hide())
     {
         Balls.Active = false;
         Balls.DestroyBalls();
         GameManager.main.Gameplay.SetActive(false);
         UIManager.Gameplay.Hide();
         UIManager.Main.Show();
     }
 }
コード例 #13
0
 private void SetBallColor(BallColor ballColor)
 {
     RealColor = Balls.GetBallColor(ballColor);
     if (Colored)
     {
         if (style != BallStyle.Normal && BallType != BallType.Frozen && BallType != BallType.Rust)
         {
             ballRenderer.sprite = Balls.GetColorFigureSprite(ballColor);
         }
         this.ballColor = ballColor;
     }
 }
コード例 #14
0
 public bool Show(Level levelProfile)
 {
     base.Show();
     GameManager.main.Gameplay.SetActive(true);
     currScore          = 0;
     AddScoreText.text  = "";
     Balls.Score        = 0;
     ScoreText.text     = string.Format("{0}", currScore);
     BestScoreText.text = string.Format("{0}", GameData.GetLevelBestScore(levelProfile.Num));
     Balls.LoadLevel(levelProfile);
     return(true);
 }
コード例 #15
0
        private IEnumerator CheckChainRoutine(float delay)
        {
            yield return(new WaitForSeconds(delay));

            if (!Destroying && gameObject.activeSelf)
            {
                Queue <Ball> chain = GetBallsChain();
                if (chain.Count > 2)
                {
                    Balls.DestroyChain(chain, BallColor);
                }
            }
        }
コード例 #16
0
ファイル: Wall.cs プロジェクト: Crazy0wl/Magnet_Balls_2
 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);
         }
     }
 }
コード例 #17
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))
                    {
                    }
                }
            }
        }
コード例 #18
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);
 }
コード例 #19
0
ファイル: BallsGun.cs プロジェクト: Crazy0wl/Magnet_Balls_2
        private IEnumerator MoveUpRoutine(float speed)
        {
            moving = true;
            Vector3 fromPos = gameObject.transform.position;

            toPos = gameObject.transform.position;
            float dY = Mathf.Sqrt(3f) / 2f;

            toPos.y += dY;
            for (float f = 0f; f <= 1f; f += speed * Time.deltaTime)
            {
                transform.position = Vector3.Lerp(fromPos, toPos, f);
                yield return(null);
            }
            transform.position = toPos;
            yield return(null);

            if (transform.position.y > maxPosY)
            {
                Balls.CreateNewLine();
                maxPosY = transform.position.y;
            }
            moving = false;
        }
コード例 #20
0
        private void SetBallType(BallType ballType)
        {
            Destroying          = false;
            ballRenderer.sprite = Balls.main.Simple;
            this.ballType       = ballType;
            Sprite sprite = Balls.GetBallTypeSprite(ballType);

            bonusRenderer.gameObject.SetActive(false);

            BallBody2D.constraints  = RigidbodyConstraints2D.FreezeRotation;
            BallBody2D.gravityScale = 1f;
            switch (ballType)
            {
            case BallType.Crashed:
                ballRenderer.sprite = sprite;
                killAfterJoint      = true;
                break;

            case BallType.Simple:
                break;

            case BallType.Chameleon:
                SetBonusIcon(sprite);
                StartCoroutine(ChangeColorCycleRoutine());
                break;

            case BallType.Anchored:
                SetBonusIcon(sprite);
                BallBody2D.constraints = RigidbodyConstraints2D.FreezeAll;
                break;

            case BallType.Freeze:
                SetBonusIcon(sprite);
                reactAfterJoint = true;
                break;

            case BallType.Brush:
                SetBonusIcon(sprite);
                reactAfterJoint = true;
                break;

            case BallType.Hammer:

                break;

            case BallType.Bomb:
                SetBonusIcon(sprite);
                reactAfterJoint = true;
                break;

            case BallType.Lightning:
                SetBonusIcon(sprite);
                reactAfterJoint = true;
                break;

            case BallType.Aim:
                SetBonusIcon(sprite);
                reactAfterJoint = false;
                break;

            case BallType.Frozen:
                Colored              = false;
                ballRenderer.sprite  = sprite;
                bonusRenderer.sprite = null;
                killAfterJoint       = true;
                break;

            case BallType.Anchor:
                Colored              = false;
                ballRenderer.sprite  = sprite;
                bonusRenderer.sprite = null;
                IsKinematic          = true;
                break;

            case BallType.Bubble:
                Colored                 = false;
                ballRenderer.sprite     = sprite;
                bonusRenderer.sprite    = null;
                BallBody2D.gravityScale = -1f;
                killAfterJoint          = true;
                break;

            case BallType.Rust:
                Colored              = false;
                ballRenderer.sprite  = sprite;
                bonusRenderer.sprite = null;
                break;
            }
        }
コード例 #21
0
 public void Destroy()
 {
     ClearJoints();
     Balls.DestroyBall(this);
 }