예제 #1
0
    public void CheckConnection(SinkPiece newPiece)
    {
        bool badConnection = true;

        if (newPiece.currentCell.cellDown == currentPiece.currentCell)
        {
            badConnection = false;
        }
        else if (newPiece.currentCell.cellUp == currentPiece.currentCell)
        {
            badConnection = false;
        }
        else if (newPiece.currentCell.cellLeft == currentPiece.currentCell)
        {
            badConnection = false;
        }
        else if (newPiece.currentCell.cellRight == currentPiece.currentCell)
        {
            badConnection = false;
        }
        if (badConnection)
        {
            ResetPieces();
        }
    }
예제 #2
0
    // Update is called once per frame
    void Update()
    {
        if (canPlay)
        {
            if (mySelectButton.buttonPressed)
            {
                lvlToLoad = mySelectButton.lvlToLoad;
                if (chngLvlTimer >= setupLvlWaitTime && curntLvl != lvlToLoad && maxLvl >= lvlToLoad)
                {
                    chngLvlTimer = 0f;
                    ChangeLevelSetup();
                }
                mySelectButton.buttonPressed = false;
            }

            if (chngLvlTimer < setupLvlWaitTime)
            {
                chngLvlTimer += Time.deltaTime;                                                /* Debug.Log("do I ever run? Or am I just lazy like that?"); */
            }

            if (myLvls[curntLvl - 1].levelComplete)
            {
                /* Debug.Log("ya win m8!"); */
                SilverEggsSetup();
            }

            if (mySelectButton.buttonsOff)
            {
                mySelectButton.buttonsOff = false; mySelectButton.InteractableThreeDots(maxLvl, curntLvl);
            }
            if (myInput.Tapped)
            {
                UpdateMousePos(myInput.TapPosition);
                hit = Physics2D.Raycast(mousePos2D, Vector3.forward, 50f);
                if (hit)
                {
                    Debug.Log(hit.collider.gameObject.name);
                    if (hit.collider.CompareTag("Puzzle"))
                    {
                        currentPiece = hit.collider.gameObject.GetComponent <SinkPiece>();
                        if (currentPiece.pieceType == SinkPiece.pieceTypes.bubble)
                        {
                            currentPiece.matched = true;
                            ResetPieces();
                        }
                        else
                        {
                            ResetPieces();
                        }
                    }
                }
            }
            else if (myInput.isDragging)
            {
                if (firstTouch)
                {
                    UpdateMousePos(myInput.startDragTouch);
                    firstTouch = false;
                }
                else
                {
                    UpdateMousePos(myInput.draggingPosition);
                }
                hit = Physics2D.Raycast(mousePos2D, Vector3.forward, 50f);
                if (hit)
                {
                    Debug.Log(hit.collider.gameObject.name);
                    if (hit.collider.CompareTag("Puzzle") && canSelect)
                    {
                        if (currentHashCode != hit.collider.gameObject.GetHashCode())
                        {
                            currentHashCode = hit.collider.gameObject.GetHashCode();
                            if (myPieces.Count > 0)
                            {
                                CheckConnection(hit.collider.gameObject.GetComponent <SinkPiece>());
                            }
                            currentPiece = hit.collider.gameObject.GetComponent <SinkPiece>();
                            if (currentPiece.pieceType == SinkPiece.pieceTypes.bubble)
                            {
                                currentPiece.matched = true;
                                ResetPieces();
                            }
                            currentCellPos = hit.collider.gameObject.transform.position;
                            myPieces.Add(hit.collider.gameObject.GetComponent <SinkPiece>());
                            if (myPieces.Count == 1)
                            {
                                currentPiece.selected = true;
                                if (currentPiece.pieceType == SinkPiece.pieceTypes.sponge || currentPiece.pieceType == SinkPiece.pieceTypes.soap)
                                {
                                    if (currentPiece.pieceType == SinkPiece.pieceTypes.soap)
                                    {
                                        soapSelected = true;
                                    }
                                }
                                else
                                {
                                    ResetPieces();
                                }
                            }
                            else if (myPieces.Count < 5)
                            {
                                if (currentPiece.pieceType == SinkPiece.pieceTypes.dish)
                                {
                                    currentPiece.selected = true;
                                }
                                else
                                {
                                    ResetPieces();
                                }
                            }
                            else if (myPieces.Count == 5)
                            {
                                if (currentPiece.pieceType == SinkPiece.pieceTypes.soap)
                                {
                                    if (soapSelected)
                                    {
                                        ResetPieces();
                                    }
                                    else
                                    {
                                        MatchPieces();
                                    }
                                }
                                else if (currentPiece.pieceType == SinkPiece.pieceTypes.sponge)
                                {
                                    if (soapSelected)
                                    {
                                        MatchPieces();
                                    }
                                    else
                                    {
                                        ResetPieces();
                                    }
                                }
                                else
                                {
                                    ResetPieces();
                                }
                            }
                        }
                    }
                }
                else
                {
                    //Debug.Log(Vector2.Distance(currentCellPos,Camera.main.ScreenToWorldPoint(myInput.draggingPosition)));
                    if (Vector2.Distance(currentCellPos, Camera.main.ScreenToWorldPoint(myInput.draggingPosition)) > cellRadius && myPieces.Count > 0)
                    {
                        ResetPieces();
                    }
                }
            }
            else
            {
                ResetPieces();
                canSelect  = true;
                firstTouch = true;
            }
            if (Input.GetKey("r"))
            {
                myLvls[curntLvl - 1].ResetLevel();
                myLvls[curntLvl - 1].SetUpLevel();
            }
        }
        else
        {
            // When this Scene is loaded.
            if (initialSetupOn)
            {
                InitialSetup();
            }

            // After the initial set up run the first sequence.
            if (iniSeqStart)
            {
                if (iniSeqDelay > 0)
                {
                    iniSeqDelay -= Time.deltaTime;
                }
                else
                {
                    seqTimer += Time.deltaTime;
                    if (seqTimer > itemSpawnF && !itemSpawnB)
                    {
                        itemSpawnB = true; /* lvlItemHolders[curntLvl - 1].SetActive(true); */ LvlStuffFadeIn();
                    }
                    if (seqTimer > dotsSpawnF && !dotsSpawnB)
                    {
                        dotsSpawnB = true; mySelectButton.EnabledThreeDots(maxLvl); mySelectButton.InteractableThreeDots(maxLvl, curntLvl);
                    }
                    if (seqTimer > iniCanPlayF)
                    {
                        if (tutorialDone)
                        {
                            canPlay = true;
                            mySelectButton.InteractableThreeDots(maxLvl, curntLvl);
                            sceneTapScript.canTapPauseBtn = true;
                        }
                        else
                        {
                            slideInHelpScript.MoveBirdUpDown();
                        }
                        iniSeqStart = false;
                    }
                }
            }

            if (itemsWait)
            {
                itemWaitTimer += Time.deltaTime;
                if (itemWaitTimer > itemWaitAmnt)
                {
                    itemHolder.SetActive(true);

                    //for (int i = 0; i < resetTilesScript.tiles.Count; i++) // CONSIDER SAVING THE ITEM SCRIPTS TO ANOTHER LIST TO AVOID LOOPING 7 to 12 GETCOMPONENTS AT A TIME
                    //{ resetTilesScript.tiles[i].GetComponent<FadeInOutSprite>().FadeIn(); }

                    LvlStuffFadeIn();

                    itemsWait     = false;
                    itemWaitTimer = 0f;
                    canPlay       = true;
                    mySelectButton.InteractableThreeDots(maxLvl, curntLvl);
                }
            }


            if (setupChsnLvl)
            {
                ChosenLevelSetup(lvlToLoad);
            }
            // Turn off interaction for all three level select dots.
            if (!mySelectButton.buttonsOff)
            {
                mySelectButton.buttonsOff = true; mySelectButton.UninteractableThreeDots();
            }

            // #region Click On SilverEggs
            // // Clicking on a silver egg.
            // if (myInput.Tapped) {
            //  UpdateMousePos();
            //  hit = Physics2D.Raycast(mousePos2D, Vector3.forward, 50f);
            //  if (hit) {
            //      if (hit.collider.CompareTag("Egg")) {
            //          SilverEggs silEggTappedScript = hit.collider.gameObject.GetComponent<SilverEggs>();
            //          silEggTappedScript.StartSilverEggAnim();
            //          hit.collider.enabled = false;

            //          if (!silEggTappedScript.hollow) { mySilverEggMan.silverEggsPickedUp++; }
            //          mySilverEggMan.SaveSilverEggsToCorrectFile();
            //          mySilverEggMan.SaveNewSilEggsFound(mySilverEggMan.allSilEggs.IndexOf(hit.collider.gameObject));
            //          mySilverEggMan.amntSilEggsTapped++;
            //          SilverEggsCheck(); // Check if the Silver Eggs have all been collected.
            //      }
            //  }
            // }
            // #endregion
        }
        if (waitMethod)
        {
            if (waitTimer > 0)
            {
                waitTimer -= Time.deltaTime;
            }
            else
            {
                RunAfter(voidDelegate); waitMethod = false;
            }
        }
    }