Пример #1
0
    //this function randomizes the typeOfFood and sprite that appears in the Fruitcell.
    private void randomFoodSelection(FoodCell myCell)
    {
        int whatTypeOfFood = Random.Range(0, foodSprites.Length);

        myCell.typeOfToken       = (FoodCell.TokenType)whatTypeOfFood;
        myCell.foodSprite.sprite = foodSprites[whatTypeOfFood];
    }
Пример #2
0
        private void AddFood()
        {
            Coordinate pos     = _gameArea.GetEmptyPosition();
            var        newFood = new FoodCell(pos);

            _gameArea.AddCell(newFood);
        }
Пример #3
0
 private void onMouseDown()
 {
     if (Time.timeScale != 0)
     {
         fruitCellDown = GetFruiteCellFromMousePos(Input.mousePosition);
     }
     //Debug.Log(fruitCellDown);
 }
Пример #4
0
 private void LevelLoader()
 {
     for (int i = 0; i < widthOfBoard; i++)
     {
         for (int j = 0; j < heightOfBoard; j++)
         {
             //(Vector2)transform.position casts transform.position as a vector2 instead of vector3.
             Vector2    position = (Vector2)transform.position + new Vector2(i * cellWidth, j * cellHight);
             GameObject tile     = Instantiate(myTile, position, Quaternion.identity) as GameObject;
             tile.transform.parent = this.transform;
             FoodCell fruit = tile.GetComponent <FoodCell>();
             tiles[i, j]   = fruit;
             fruit.gridPos = new Vector2(i, j);
             tile.name     = "(" + i + "," + j + ")";
             int whatTypeOfFood = Random.Range(0, foodSprites.Length);
             tiles[i, j].typeOfToken       = (FoodCell.TokenType)whatTypeOfFood;
             tiles[i, j].foodSprite.sprite = foodSprites[whatTypeOfFood];
         }
     }
 }
Пример #5
0
    private void TransferHeat(float value)
    {
        // Debug.DrawRay(transform.position, Vector2.up, Color.blue);

        RaycastHit2D hit = Physics2D.Raycast((Vector2)transform.position + new Vector2(0f, 0.125f), Vector2.up, 0.4f, mask);

        if (hit.collider != null)
        {
            //Debug.Log(hit.collider.gameObject.name + " was hit by a raycast");

            if (hit.collider.gameObject.tag != "MeatCell")
            {
                return;
            }

            //Debug.Log(hit.collider.gameObject.name + " was hit by a raycast");

            FoodCell cell = hit.collider.GetComponent <FoodCell>();

            cell.AddHeat(value);
        }
    }
Пример #6
0
    private void OnTriggerStay2D(Collider2D other)
    {
        //Debug.Log(other.gameObject.name + " is Staying within " + gameObject.name);

        if (other.gameObject.tag == "Ingredient")
        {
            float yForce = Random.Range(minSizzleForce.y, maxSizzleForce.y);
            float xForce = Random.Range(minSizzleForce.x, maxSizzleForce.x);

            other.GetComponent <Rigidbody2D>().AddForce(new Vector2(xForce, yForce));
        }



        if (other.gameObject.tag != "MeatCell")
        {
            return;
        }

        FoodCell cell = other.gameObject.GetComponent <FoodCell>();

        cell.AddHeat(heatAmount);
    }
Пример #7
0
    //this function solves the grid but looping using for loops to cheak every cell and cheak weather the cells beside or on the bottom or top of the cell match the cell.
    private void SolveGrid()
    {
        gridSolvedTimesInARow += 1;
        FoodCell.TokenType TokenTypeForPowerUpDrop;
        //Debug.Log("solveGrid");
        //two for loops used to cheak through every grid cell
        for (int i = 0; i < widthOfBoard; i++)
        {
            for (int j = 0; j < heightOfBoard; j++)
            {
                //Debug.Log("cheaking cell " + i + "," + j);
                FoodCell.TokenType tempFood                = tiles[i, j].typeOfToken;
                FoodCell           currentFruitCell        = tiles[i, j];
                List <FoodCell>    matchingCellsToTheRight = new List <FoodCell>();
                List <FoodCell>    matchingCellsUp         = new List <FoodCell>();
                FoodCell           neiborFruitCell         = currentFruitCell.getNeiborRight(tiles);
                //uses a while loop to cheak keep cheaking for matches as long as their is a neiboring Cell to the one being cheaked.
                while (neiborFruitCell != null)
                {
                    //if statment used to cheak if cell being cheaked has a match with a horizontal cell.
                    if (currentFruitCell.typeOfToken == neiborFruitCell.typeOfToken)
                    {
                        //Debug.Log("H-match- " + neiborFruitCell.gridPos);
                        matchingCellsToTheRight.Add(neiborFruitCell);
                        neiborFruitCell = neiborFruitCell.getNeiborRight(tiles);
                    }
                    //breaks out of the stament if their is no match.
                    else
                    {
                        break;
                    }
                }
                neiborFruitCell = currentFruitCell.getNeiborUp(tiles);
                while (neiborFruitCell != null)
                {
                    if (currentFruitCell.typeOfToken == neiborFruitCell.typeOfToken)
                    {
                        //if statment used to cheak if cell being cheaked has a match with a vertical cell.
                        //Debug.Log("V-match- " + neiborFruitCell.gridPos);
                        matchingCellsUp.Add(neiborFruitCell);
                        neiborFruitCell = neiborFruitCell.getNeiborUp(tiles);
                    }
                    else
                    {
                        break;
                    }
                }
                //uses bools to tell game if the food in a cell needs to be replaced by another food when a match is found
                bool horizontalSolved = false;
                bool verticalSolved   = false;
                if (matchingCellsToTheRight.Count >= 2)
                {
                    horizontalSolved = true;
                    //iterate over this list and replace the food type with a new food type.
                    for (int b = 0; b < matchingCellsToTheRight.Count; b++)
                    {
                        FoodCell fruitCellToSolve = matchingCellsToTheRight[b];
                        //Debug.Log("cells to the right match");
                        StartCoroutine(fruitCellToSolve.DoSolveFruit(this));
                    }
                }
                if (matchingCellsUp.Count >= 2)
                {
                    verticalSolved = true;
                    //iterate over this list and replace the food type with a new food type.
                    for (int b = 0; b < matchingCellsUp.Count; b++)
                    {
                        FoodCell fruitCellToSolve = matchingCellsUp[b];
                        //Debug.Log("cells up match");
                        StartCoroutine(fruitCellToSolve.DoSolveFruit(this));
                    }
                }
                //if we solved any fruit cells above or to the right thne break out of this
                if (horizontalSolved || verticalSolved)
                {
                    thereWasSomethingToSolveInTheGrid = true;
                    //randomFoodSelection called to change food that matches.
                    //this uses a coroutine from FruitCell.
                    StartCoroutine(currentFruitCell.DoSolveFruit(this));
                    //uses myScoreValue from ScoreScript to change the score when grid is solved
                    //ScoreScript.myScoreValue++;
                    //restarts the solving prosses.
                    StartCoroutine(WaitAndSolveGrid());
                    TokenTypeForPowerUpDrop = currentFruitCell.typeOfToken;
                    int probabilityOfPowerUpDrop = Random.Range(0, 2);
                    if (probabilityOfPowerUpDrop == 1 && FirstSolveGridHasPassed)
                    {
                        switch (TokenTypeForPowerUpDrop)
                        {
                        case FoodCell.TokenType.Undefined:
                            break;

                        case FoodCell.TokenType.Armour:
                            Instantiate(armour, powerUpSpawnPos, powerUpRotation);
                            break;

                        case FoodCell.TokenType.Sword:
                            Instantiate(swordWeapon, powerUpSpawnPos, powerUpRotation);
                            break;

                        case FoodCell.TokenType.Cherry:
                            Instantiate(cherryPowerUp, powerUpSpawnPos, powerUpRotation);
                            break;

                        case FoodCell.TokenType.Apple:
                            Instantiate(applePowerUp, powerUpSpawnPos, powerUpRotation);
                            break;

                        case FoodCell.TokenType.InvisibilityPotion:
                            Instantiate(invisablePotion, powerUpSpawnPos, powerUpRotation);
                            break;
                        }
                    }
                    break;
                }
                else
                {
                    thereWasSomethingToSolveInTheGrid = false;
                }
            }
        }
    }
Пример #8
0
 private void onMouseDown()
 {
     fruitCellDown = GetFruiteCellFromMousePos(Input.mousePosition);
     //Debug.Log(fruitCellDown);
 }
Пример #9
0
 //this function solves the grid but looping using for loops to cheak every cell and cheak weather the cells beside or on the bottom or top of the cell match the cell.
 private void SolveGrid()
 {
     gridSolvedTimesInARow += 1;
     //Debug.Log("solveGrid");
     //two for loops used to cheak through every grid cell
     for (int i = 0; i < widthOfBoard; i++)
     {
         for (int j = 0; j < heightOfBoard; j++)
         {
             //Debug.Log("cheaking cell " + i + "," + j);
             FoodCell.TokenType tempFood                = tiles[i, j].typeOfToken;
             FoodCell           currentFruitCell        = tiles[i, j];
             List <FoodCell>    matchingCellsToTheRight = new List <FoodCell>();
             List <FoodCell>    matchingCellsUp         = new List <FoodCell>();
             FoodCell           neiborFruitCell         = currentFruitCell.getNeiborRight(tiles);
             //uses a while loop to cheak keep cheaking for matches as long as their is a neiboring Cell to the one being cheaked.
             while (neiborFruitCell != null)
             {
                 //if statment used to cheak if cell being cheaked has a match with a horizontal cell.
                 if (currentFruitCell.typeOfToken == neiborFruitCell.typeOfToken)
                 {
                     //Debug.Log("H-match- " + neiborFruitCell.gridPos);
                     matchingCellsToTheRight.Add(neiborFruitCell);
                     neiborFruitCell = neiborFruitCell.getNeiborRight(tiles);
                 }
                 //breaks out of the stament if their is no match.
                 else
                 {
                     break;
                 }
             }
             neiborFruitCell = currentFruitCell.getNeiborUp(tiles);
             while (neiborFruitCell != null)
             {
                 if (currentFruitCell.typeOfToken == neiborFruitCell.typeOfToken)
                 {
                     //if statment used to cheak if cell being cheaked has a match with a vertical cell.
                     //Debug.Log("V-match- " + neiborFruitCell.gridPos);
                     matchingCellsUp.Add(neiborFruitCell);
                     neiborFruitCell = neiborFruitCell.getNeiborUp(tiles);
                 }
                 else
                 {
                     break;
                 }
             }
             //uses bools to tell game if the food in a cell needs to be replaced by another food when a match is found
             bool horizontalSolved = false;
             bool verticalSolved   = false;
             if (matchingCellsToTheRight.Count >= 2)
             {
                 horizontalSolved = true;
                 //iterate over this list and replace the food type with a new food type.
                 for (int b = 0; b < matchingCellsToTheRight.Count; b++)
                 {
                     FoodCell fruitCellToSolve = matchingCellsToTheRight[b];
                     //Debug.Log("cells to the right match");
                     StartCoroutine(fruitCellToSolve.doSolveFruitTwo(this));
                 }
             }
             if (matchingCellsUp.Count >= 2)
             {
                 verticalSolved = true;
                 //iterate over this list and replace the food type with a new food type.
                 for (int b = 0; b < matchingCellsUp.Count; b++)
                 {
                     FoodCell fruitCellToSolve = matchingCellsUp[b];
                     //Debug.Log("cells up match");
                     StartCoroutine(fruitCellToSolve.doSolveFruitTwo(this));
                 }
             }
             //if we solved any fruit cells above or to the right thne break out of this
             if (horizontalSolved || verticalSolved)
             {
                 thereWasSomethingToSolveInTheGrid = true;
                 //randomFoodSelection called to change food that matches.
                 //this uses a coroutine from FruitCell.
                 StartCoroutine(currentFruitCell.doSolveFruitTwo(this));
                 //restarts the solving prosses.
                 myShipFuel.FuelAmount += 0.2f;
                 StartCoroutine(WaitAndSolveGrid());
             }
             else
             {
                 thereWasSomethingToSolveInTheGrid = false;
             }
         }
     }
 }