Exemple #1
0
 //--------------------------------------------
 // When colliding with something
 void OnCollisionEnter(Collision collision)
 {
     // If there's less balls than max balls
     if (Controller.spheresAmount < Controller.MAX_BALLS)
     {
         // Save point of contact to var
         ContactPoint contact = collision.contacts[0];
         // Save reference to collider's script
         Kulka script = collision.collider.GetComponent <Kulka>();
         // If script exists, either check if this object mass is bigger or if equal, check if this object is older
         if (script != null && (script.mass < mass) || (script.mass == mass && script.GetInstanceID() > GetInstanceID()))
         {
             // Get radius and mass of collider
             float otherRadius = script.radius;
             float otherMass   = script.mass;
             // Add +1 to "how many balls this ball is created from"
             howManyBalls++;
             // Destroy collider
             Destroy(collision.collider.gameObject);
             // Add mass of collider to object
             rigidBody.mass += otherMass;
             // Set mass variable to updated value
             mass = rigidBody.mass;
             // Set radius to sqrt of mass
             radius = Mathf.Sqrt(mass);
             // Resize ball
             ResizeSphere();
         }
     }
 }
Exemple #2
0
    public void SpawnBalls(int num)
    {
        int CurrentNumberOfBalls = GameObject.FindGameObjectsWithTag("Kulka").Length;

        num = Mathf.Clamp(num, 0, 81 - CurrentNumberOfBalls);
        int i = 0;

        while (num > 0)
        {
            int randomX = Random.Range(0, grid.GridSizeX);
            int randomY = -Random.Range(0, grid.GridSizeY);
            if (IsPositionFree(randomX, randomY))
            {
                num--;
                var kulka = Instantiate(PrefabKulki, new Vector2(randomX, randomY), Quaternion.identity);
                kulka.SetColor(BallColours[NextColors[i]], NextColors[i]);
                AllBalls.Add(kulka);
                lastBallAdded = kulka;
                i++;
            }
        }
        NextColors.Clear();
        NextColors.Add(Random.Range(0, ColoursAvailable));
        NextColors.Add(Random.Range(0, ColoursAvailable));
        NextColors.Add(Random.Range(0, ColoursAvailable));
        gui.UpdateNextColors();
        StartCoroutine(WaitForCheck());
    }
Exemple #3
0
    public bool CheckUppeningDiagnal()
    {
        //left side
        List <Kulka> Left  = new List <Kulka>();
        List <Kulka> Right = new List <Kulka>();
        int          MatchingColourBallsLeft  = 0;
        int          MatchingColourBallsRight = 0;


        ///LEWA STRONA W DOL
        int differenceY = 0;

        for (int i = (int)transform.position.x - 1; i >= 0; i--)
        {
            differenceY--;
            Kulka temp = CheckPosition(i, (int)transform.position.y + differenceY);
            if (temp != null)
            {
                MatchingColourBallsLeft++;
                Left.Add(temp);
            }
            else
            {
                break;
            }
        }
        ///LEWA STRONA W GORE
        differenceY = 0;
        for (int i = (int)(transform.position.x + 1); i < 9; i++)
        {
            differenceY++;
            Kulka temp = CheckPosition(i, (int)transform.position.y + differenceY);
            if (temp != null)
            {
                MatchingColourBallsRight++;
                Right.Add(temp);
            }
            else
            {
                break;
            }
        }
        if (MatchingColourBallsLeft + MatchingColourBallsRight + 1 >= 5)
        {
            GameController.instance.IncreaseScore(MatchingColourBallsLeft + MatchingColourBallsRight + 1);
            foreach (Kulka k in Left)
            {
                k.Dissolve();
            }
            foreach (Kulka k in Right)
            {
                k.Dissolve();
            }
            Dissolve();

            return(true);
        }
        return(false);
    }
Exemple #4
0
    static void Main(string[] args)
    {
        Kulka buf = new Kulka();
        Del   del = buf.Dlinna;

        del(2.71);
        del = buf.Plosha;
        del(2.71);
        del = buf.Amount;
        del(2.71);
    }
Exemple #5
0
    public bool CheckHorizontal()
    {
        //left side
        List <Kulka> Left  = new List <Kulka>();
        List <Kulka> Right = new List <Kulka>();
        int          MatchingColourBallsLeft  = 0;
        int          MatchingColourBallsRight = 0;

        for (int i = (int)transform.position.x - 1; i >= 0; i--)
        {
            Kulka temp = CheckPosition(i, (int)transform.position.y);
            if (temp != null)
            {
                MatchingColourBallsLeft++;
                Left.Add(temp);
            }
            else
            {
                break;
            }
        }
        for (int i = (int)(transform.position.x + 1); i < 9; i++)
        {
            Kulka temp = CheckPosition(i, (int)transform.position.y);
            if (temp != null)
            {
                MatchingColourBallsRight++;
                Right.Add(temp);
            }
            else
            {
                break;
            }
        }


        if (MatchingColourBallsLeft + MatchingColourBallsRight + 1 >= 5)
        {
            GameController.instance.IncreaseScore(MatchingColourBallsLeft + MatchingColourBallsRight + 1);
            foreach (Kulka k in Left)
            {
                k.Dissolve();
            }
            foreach (Kulka k in Right)
            {
                k.Dissolve();
            }
            Dissolve();

            return(true);
        }
        return(false);
    }
Exemple #6
0
    public bool CheckVertical()
    {
        //left side
        List <Kulka> Up   = new List <Kulka>();
        List <Kulka> Down = new List <Kulka>();
        int          MatchingColourBallsUp   = 0;
        int          MatchingColourBallsDown = 0;

        for (int i = (int)(transform.position.y - 1); i > -9; i--)
        {
            Kulka temp = CheckPosition((int)(transform.position.x), i);
            if (temp != null)
            {
                MatchingColourBallsDown++;
                Down.Add(temp);
            }
            else
            {
                break;
            }
        }
        for (int i = (int)(transform.position.y + 1); i < 9; i++)
        {
            Kulka temp = CheckPosition((int)(transform.position.x), i);
            if (temp != null)
            {
                MatchingColourBallsUp++;
                Up.Add(temp);
            }
            else
            {
                break;
            }
        }

        if (MatchingColourBallsUp + MatchingColourBallsDown + 1 >= 5)
        {
            GameController.instance.IncreaseScore(MatchingColourBallsUp + MatchingColourBallsDown + 1);
            foreach (Kulka k in Up)
            {
                k.Dissolve();
            }
            foreach (Kulka k in Down)
            {
                k.Dissolve();
            }
            Dissolve();
            return(true);
        }
        return(false);
    }
Exemple #7
0
    // Start is called before the first frame update
    public void SetSelectedBall(Kulka x)
    {
        ///When selecting a ball deselect old ball
        if (CurrentlySelectedBall != null)
        {
            CurrentlySelectedBall.Deselect();
        }


        //if you press on the same ball twice, you deselect it and current is null again;
        if (CurrentlySelectedBall == x)
        {
            CurrentlySelectedBall = null;
        }
        else // if you press on a different ball then the other one is selected
        {
            CurrentlySelectedBall = x;
        }
        BallReactionDelayTimer = BallReactionDelay;
    }
Exemple #8
0
    private void Start()
    {
        if (!GameSaveManager.instance.shouldBeLoadedFromFile)
        {
            if (PlayerPrefs.HasKey("Difficulty"))
            {
                difficulty = PlayerPrefs.GetInt("Difficulty");
                switch (difficulty)
                {
                case 0:
                    ColoursAvailable = 3;
                    break;

                case 1:
                    ColoursAvailable = 5;
                    break;

                case 2:
                    ColoursAvailable = 7;
                    break;

                case 3:
                    ColoursAvailable = 9;
                    break;
                }
                gui.SetDifficulty(difficulty);
            }

            List <Vector2> takenPositions = new List <Vector2>();
            while (BallsToSpawn > 0)
            {
                int randomX    = Random.Range(0, grid.GridSizeX);
                int randomY    = -Random.Range(0, grid.GridSizeY);
                int colorIndex = Random.Range(0, ColoursAvailable);
                if (!takenPositions.Contains(new Vector2(randomX, randomY)))
                {
                    BallsToSpawn--;
                    var kulka = Instantiate(PrefabKulki, new Vector2(randomX, randomY), Quaternion.identity);
                    kulka.SetColor(BallColours[colorIndex], colorIndex);
                    lastBallAdded = kulka;
                    AllBalls.Add(kulka);
                    takenPositions.Add(new Vector2(randomX, randomY));
                }
            }
            NextColors.Clear();
            NextColors.Add(Random.Range(0, ColoursAvailable));
            NextColors.Add(Random.Range(0, ColoursAvailable));
            NextColors.Add(Random.Range(0, ColoursAvailable));
            gui.UpdateNextColors();
            StartCoroutine(WaitForCheck());
        }
        else
        {
            GameSaveManager.instance.LoadGame();
            gui.UpdateScore();
            NextColors.Clear();
            NextColors.Add(Random.Range(0, ColoursAvailable));
            NextColors.Add(Random.Range(0, ColoursAvailable));
            NextColors.Add(Random.Range(0, ColoursAvailable));
            gui.UpdateNextColors();
        }
    }
Exemple #9
0
 public void DeselectCurrentBall()
 {
     CurrentlySelectedBall = null;
 }