Exemple #1
0
 private RowBehavior.RowType MakeEndRow()
 {
     cO.GetComponent <SpriteRenderer>().sprite   = endSprite;
     cO.AddComponent <RowBehavior>().myRowType   = RowBehavior.RowType.end;
     cO.GetComponent <BoxCollider2D>().isTrigger = true;
     cO.layer = 15;
     cO.tag   = "End Row";
     lastRow  = RowBehavior.RowType.end;
     cO.GetComponent <SpriteRenderer>().color = new Color(0, 0, 0, 0);
     return(lastRow);
 }
Exemple #2
0
 private RowBehavior.RowType MakeSafeRow()
 {
     oneCameBefore = true;
     cO.GetComponent <SpriteRenderer>().sprite   = safeSprite;
     cO.AddComponent <RowBehavior>().myRowType   = RowBehavior.RowType.safe;
     cO.GetComponent <BoxCollider2D>().isTrigger = true;
     cO.layer = 11;
     cO.tag   = "Safe Row";
     lastRow  = RowBehavior.RowType.safe;
     return(lastRow);
 }
Exemple #3
0
 private RowBehavior.RowType MakeHomeRow()
 {
     oneCameBefore = true;
     cO.GetComponent <SpriteRenderer>().sprite   = homeSprite;
     cO.AddComponent <RowBehavior>().myRowType   = RowBehavior.RowType.home;
     cO.GetComponent <BoxCollider2D>().isTrigger = true;
     cO.layer = 18;
     cO.tag   = "Home Row";
     lastRow  = RowBehavior.RowType.home;
     cO.GetComponent <SpriteRenderer>().color = new Color(0, 0, 0, 0);
     return(lastRow);
 }
Exemple #4
0
    //jellies or no jellies decided here
    //progressive dificulty is handled here
    private RowBehavior.RowType MakeDangerRow(int row)
    {
        cO.GetComponent <SpriteRenderer>().sprite = dangerSprite;
        cO.AddComponent <RowBehavior>().myRowType = RowBehavior.RowType.danger;


        if (thisLevel == 1)
        {
            //blowfish every other row
            if (!oneCameBefore)
            {
                cO.GetComponent <RowBehavior>().freeRow = true;
                oneCameBefore = true;
            }
            else
            {
                cO.GetComponent <RowBehavior>().freeRow = false;
                oneCameBefore = false;
            }
        }

        //int chance = FindObjectOfType<GameManager>().freeRowChance;
        //int pickle = Random.Range(1, 101);
        //if (pickle > chance)
        //{
        //	cO.GetComponent<RowBehavior>().freeRow = true;
        //}

        if (chosenRows[row - 1] == GenRow.dangerWithJelly && thisLevel >= 5)
        {
            cO.GetComponent <RowBehavior>().jellies = true;
        }

        cO.layer = 8;
        cO.GetComponent <SpriteRenderer>().color = new Color(0, 0, 0, 0);
        lastRow = RowBehavior.RowType.danger;
        return(lastRow);
    }
Exemple #5
0
    void InitCells()
    {
        //creates an empty object and adds a sprite renderer component -> set the sprite to cellSprite
        GameObject cellObject = new GameObject("Row");

        cellObject.AddComponent <SpriteRenderer>().sprite = cellSprite;

        //cache the size of the sprite
        cellSize = cellSprite.bounds.size;

        //get the new cell size -> adjust the size of the cells to fit the size of the grid
        Vector2 newTileSize = new Vector2(gridSize.x, gridSize.y / (float)rows);

        //Get the scales so you can scale the cells and change their size to fit the grid
        cellScale.x = newTileSize.x / cellSize.x;
        cellScale.y = newTileSize.y / cellSize.y;

        //replace the size with the newly calculated size
        cellSize = newTileSize;
        cellObject.transform.localScale = new Vector2(cellScale.x, cellScale.y);

        //fix the cells to the grid by getting the half of the grid and cells add and minus experiment
        gridOffset.x = -(gridSize.x / 2) + cellSize.x / 2;
        gridOffset.y = -(gridSize.y / 2) + cellSize.y / 2;

        //fill the grid with cells by using Instantiate
        //TODO: clean this up!
        for (int row = 0; row < rows; row++)
        {
            lastRow = RowBehavior.RowType.unknown;

            //add the cell size so that no two cells will have the same x and y position
            Vector2 pos = new Vector2(gridOffset.x + transform.position.x, row * cellSize.y + gridOffset.y + transform.position.y);

            ////because quaternions...
            //Quaternion myQuat = Quaternion.identity;
            //Quaternion quatRotation = Quaternion.Euler(myQuat.eulerAngles.x - 25f, myQuat.eulerAngles.y, myQuat.eulerAngles.z);

            cO = Instantiate(cellObject, pos, Quaternion.identity) as GameObject;
            cO.AddComponent <BoxCollider2D>();

            if (row == 0) //first row
            {
                //always home row for odd levels
                if ((manager.levelsGenerated + 1) % 2 != 0)
                {
                    lastRow = MakeHomeRow();
                }
                else //or end row for even levels
                {
                    lastRow = MakeEndRow();
                }
            }

            else if (row == (rows - 1)) //last row
            {
                //always end row for odd levels
                if ((manager.levelsGenerated + 1) % 2 != 0)
                {
                    lastRow = MakeEndRow();
                }
                else //or home row for even levels
                {
                    lastRow = MakeHomeRow();
                }
            }

            else //all the rows in between home and end
            {
                if (chosenRows[row - 1] == GenRow.safe)
                {
                    lastRow = MakeSafeRow();
                }
                else if (chosenRows[row - 1] == GenRow.danger || chosenRows[row - 1] == GenRow.dangerWithJelly)
                {
                    lastRow = MakeDangerRow(row);
                    cO.tag  = "Row";
                }
            }

            //set the parent of the cell to GRID so you can move the cells together with the grid;
            cO.transform.parent = transform;

            cO.GetComponent <RowBehavior>().myLevel = manager.levelsGenerated + 1;
            //cO.GetComponent<SpriteRenderer>().sprite = null;
        }

        //destroy the object used to instantiate the cells
        Destroy(cellObject);

        manager.levelsGenerated++;
        manager.generatedLevels.Add(this);
    }