Ejemplo n.º 1
0
    // Use this for initialization
    void Start()
    {
        spriteRenderer = GetComponent <SpriteRenderer> ();
        animator       = GetComponent <Animator> ();
        gameController = GameObject.FindGameObjectWithTag("GameController").GetComponent <GameController> ();
        piece          = gameObject.GetComponentInParent <piece_script> ();
        //no need for these if there are no spells
        if (gameController.gameType == "Wit" || gameController.gameType == "Quick")
        {
            Destroy(gameObject);
        }
        else
        {
            spellHandler = GameObject.Find("Spell Handler").GetComponent <SpellHandler> ();
        }

        whiteActive  = false;
        cyanActive   = false;
        purpleActive = false;
        purpleEnd    = false;

        spriteRenderer.sprite = null;
        greenBlueActive       = false;

        orangeActive = false;
    }
Ejemplo n.º 2
0
    //puts the pieces in the grid after they've settled into their place
    public void placePiece(GameObject piece)
    {
        piece_script pieceStats = piece.GetComponent <piece_script> ();
        int          thisX      = (int)pieceStats.gridPos.x;
        int          thisY      = (int)pieceStats.gridPos.y;

        //check to make sure the piece is in the grid
        if (pieceStats.gridPos.x >= 0 && pieceStats.gridPos.x < 8 && pieceStats.gridPos.y >= 0 && pieceStats.gridPos.x < 16)
        {
            //uncomment this to show what the grid position of the newly placed piece is
            //Debug.Log ("Grid Position is" +(int)pieceStats.gridPos.x +" " + (int)pieceStats.gridPos.y);
            colorGrid [(int)pieceStats.gridPos.x, (int)pieceStats.gridPos.y] = pieceStats.pieceColor;
            grid [(int)pieceStats.gridPos.x, (int)pieceStats.gridPos.y]      = piece;
            //uncomment this to show what the color of the newly placed piece is
            //if(colorGrid[(int)pieceStats.gridPos.x, (int)pieceStats.gridPos.y] != null)
            //	Debug.Log ("inserted " +grid [(int)pieceStats.gridPos.x, (int)pieceStats.gridPos.y].GetComponent<piece_script>().pieceColor + " piece into colorgrid position " +(int)pieceStats.gridPos.x +" " + (int)pieceStats.gridPos.y);
            //This if statement will check if a check board is necessary, for optimization.
            //Debug.Log ("Beginning check");
            if (((thisX + 1 < 8) && (grid [thisX + 1, thisY] != null && colorGrid[thisX + 1, thisY] == pieceStats.pieceColor)) ||       //right
                ((thisY + 1 < 16) && (grid [thisX, thisY + 1] != null && colorGrid[thisX, thisY + 1] == pieceStats.pieceColor)) ||      //up
                ((thisX - 1 >= 0) && (grid [thisX - 1, thisY] != null && colorGrid[thisX - 1, thisY] == pieceStats.pieceColor)) ||      //left
                ((thisY - 1 >= 0) && (grid [thisX, thisY - 1] != null && colorGrid[thisX, thisY - 1] == pieceStats.pieceColor)))        //below
            {
                checkFlag = true;
                //Debug.Log ("Matching adjacent piece detected");
            }
            piecesPlaced++;
        }
        // if it isn't in the grid, throw an error up and delete the offending piece.
        else
        {
            Debug.LogError("Error in placing piece with position" + (int)pieceStats.gridPos.x + " " + (int)pieceStats.gridPos.y);
            Destroy(piece);
        }
    }
Ejemplo n.º 3
0
    //use this to double check to make sure the arrays are accurate;
    public void recalculateBoard()
    {
        grid      = new GameObject[8, 16];
        colorGrid = new string[8, 16];
        GameObject[]      allPieces       = GameObject.FindGameObjectsWithTag("Piece");
        List <GameObject> offendingPieces = new List <GameObject>();

        foreach (GameObject piece in allPieces)
        {
            piece_script temp = piece.GetComponent <piece_script>();
            //if it's on the grid, add it to the grid
            if (temp != null && !temp.inHolder && !temp.inSplitter && !temp.inSideHolder)
            {
                //it's just been shot, ignore it for now
                if (!(temp.gridPos.x < 0))
                {
                    if (grid [(int)temp.gridPos.x, (int)temp.gridPos.y] == null)
                    {
                        grid [(int)temp.gridPos.x, (int)temp.gridPos.y]      = piece;
                        colorGrid [(int)temp.gridPos.x, (int)temp.gridPos.y] = temp.pieceColor;
                    }
                    else
                    {
                        offendingPieces.Add(piece);
                    }
                }
            }
        }
        foreach (GameObject piece in offendingPieces)
        {
            Destroy(piece);
        }
        collapse();
    }
Ejemplo n.º 4
0
 //2D collision detection
 void OnTriggerEnter2D(Collider2D col)
 {
     //ignore score bits
     if (col.gameObject.tag == "Score Bit" || col.gameObject.tag == "Spell Tab")
     {
         return;
     }
     //if the piece hasn't already been assigned a position, begin to assign it
     if (!isMoving && !locked && !inSplitter && !inSideHolder)
     {
         piece_script colPiece = col.gameObject.GetComponent <piece_script> ();
         //if it collided with the side of a grid, place it in the grid
         if (colPiece == null)
         {
             transform.GetComponent <Rigidbody2D>().velocity = new Vector2(0, 0);
             GetComponent <Rigidbody2D>().isKinematic        = false;
             locked             = true;
             lockPos            = new Vector2(Mathf.Round(transform.position.x), Mathf.Round(transform.position.y));
             transform.position = lockPos;
             gridPos            = new Vector2((int)lockPos.y, (int)lockPos.x + 8);
             gameController.placePiece(gameObject);
             clacker.BroadcastMessage("PlaySound");
         }
         //if it collided with another piece, determine where that piece is and place it relative to that piece
         else if (colPiece.locked == true && !colPiece.inSplitter)
         {
             //check if it was fired left
             if (transform.GetComponent <Rigidbody2D>().velocity.x < 0 && !colPiece.inSplitter && !inSplitter)
             {
                 transform.GetComponent <Rigidbody2D>().velocity = new Vector2(0, 0);
                 GetComponent <Rigidbody2D>().isKinematic        = false;
                 locked             = true;
                 lockPos            = new Vector2(Mathf.Round(col.transform.position.x + 1), Mathf.Round(col.transform.position.y));
                 transform.position = lockPos;
                 gridPos            = new Vector2((int)lockPos.y, (int)lockPos.x + 8);
             }
             //check if it was fired right
             else if (transform.GetComponent <Rigidbody2D>().velocity.x > 0 && !colPiece.inSplitter && !inSplitter)
             {
                 transform.GetComponent <Rigidbody2D>().velocity = new Vector2(0, 0);
                 GetComponent <Rigidbody2D>().isKinematic        = false;
                 locked             = true;
                 lockPos            = new Vector2(Mathf.Round(col.transform.position.x - 1), Mathf.Round(col.transform.position.y));
                 transform.position = lockPos;
                 gridPos            = new Vector2((int)lockPos.y, (int)lockPos.x + 8);
             }
             //places the piece in the grid upkept by the game controller
             gameController.placePiece(gameObject);
             clacker.BroadcastMessage("PlaySound");
         }
         if (isBomb)
         {
             gameObject.BroadcastMessage("Activate_Cyan", null, SendMessageOptions.DontRequireReceiver);
         }
     }
 }
Ejemplo n.º 5
0
 //refills the splitter with two new pieces
 public void refill()
 {
     holder.getNextPiece();
     piece_script[] slots = new piece_script[2] {
         leftSlot.GetComponent <piece_script> (), rightSlot.GetComponent <piece_script> ()
     };
     for (int i = 0; i < 2; i++)
     {
         slots[i].locked     = false;
         slots[i].inHolder   = false;
         slots[i].inSplitter = true;
     }
 }
Ejemplo n.º 6
0
 // Use this for initialization
 void Start()
 {
     spriteRenderer        = GetComponent <SpriteRenderer> ();
     parentPiece           = transform.GetComponentInParent <piece_script> ();
     spriteRenderer.sprite = parentPiece.GetComponent <SpriteRenderer> ().sprite;
     dangerColor           = new Color(0, 0, 0, 0.25f);
     activeColor           = new Color(spriteRenderer.color.r, spriteRenderer.color.g, spriteRenderer.color.b, 0.5f);
     inActiveColor         = new Color(spriteRenderer.color.r, spriteRenderer.color.g, spriteRenderer.color.b, 0);
     spriteRenderer.color  = inActiveColor;
     isPulsing             = false;
     //move slightly in front of the so as to make it obvious when it's active
     transform.Translate(new Vector3(0, 0, -0.1f));
     //gameController = parentPiece.gameController;
 }