コード例 #1
0
    public void ProcessControlTouch(TouchCover touch)
    {
        if (!gameStarted)
        {
            return;
        }
        if (touch == null)
        {
            return;
        }

        //Touch Press
        if (touch.phase == TouchPhase.Began)
        {
            Vector2 rayOrigin = noteCamera.ScreenToWorldPoint(touch.position);

            //check if mouse hit any object?
            RaycastHit2D hit = Physics2D.Raycast(rayOrigin, Vector2.zero, 100, ProjectConstants.Layers.MainGameMask);
            if (hit && hit.transform != null)
            {
                string hitObjName = hit.transform.name.ToLower();

                //start object?
                if (gameplay.CurrentGameStage != TileMasterGamePlay.GameState.Playing)
                {
                    if (hitObjName.Contains("start"))
                    {
                        //game start
                        NoteStart noteStart = hit.transform.gameObject.GetComponent <NoteStart>();
                        if (noteStart != null)
                        {
                            noteStart.Press(touch);
                        }
                    }
                }

                //tiles?
                if (gameplay.CurrentGameStage == TileMasterGamePlay.GameState.Playing ||
                    gameplay.CurrentGameStage == TileMasterGamePlay.GameState.Continue ||
                    gameplay.CurrentGameStage == TileMasterGamePlay.GameState.AutoPlay)
                {
                    if (gameplay.CurrentGameStage == TileMasterGamePlay.GameState.Continue)
                    {
                        gameplay.StartGame();
                    }

                    if (hitObjName.Contains("simple_"))
                    {
                        NoteSimple simple = hit.transform.gameObject.GetComponent <NoteSimple>();
                        if (simple != null && CanTouchNote(simple))
                        {
                            simple.Press(touch);
                        }
                    }
                    else if (hitObjName.Contains("multi_"))
                    {
                        NoteMulti multi = hit.transform.gameObject.GetComponent <NoteMulti>();
                        if (multi != null && CanTouchNote(multi))
                        {
                            multi.Press(touch);
                            multi.OnShowUIWhenPress(GetRootPositionHit(touch));
                        }
                    }
                    else if (hitObjName.Contains("bonus"))
                    {
                        NoteBonus bonus = hit.transform.gameObject.GetComponent <NoteBonus>();
                        if (bonus != null)
                        {
                            bonus.Press(null);
                        }
                    }
                }
            }
            else
            {
                //if the touch didn't hit any note, check for hit on background
                RaycastHit2D bgCheck = Physics2D.Raycast(rayOrigin, Vector2.zero, 100, ProjectConstants.Layers.BackgroundMask);
                if (bgCheck.transform != null)
                {
                    if (gameplay.CurrentGameStage == TileMasterGamePlay.GameState.Playing ||
                        gameplay.CurrentGameStage == TileMasterGamePlay.GameState.AutoPlay)
                    {
                        if (CheckGameOver(touch))
                        {
                            GameOverByPressWrong(touch);
                        }
                    }
                    else if (gameplay.CurrentGameStage == TileMasterGamePlay.GameState.Continue)
                    {
                        gameplay.StartGame();
                    }
                }
            }
        }

        // Touch Hold
        else if (touch.phase == TouchPhase.Stationary || touch.phase == TouchPhase.Moved)
        {
            OnHoldTouch(touch);
        }
        else
        {
            ResetTouch(touch);
        }
    }
コード例 #2
0
    public void ProcessUpdate(float speed)
    {
        Vector3 translate = Vector3.up * speed * Time.smoothDeltaTime;

        oldPos = noteCamera.transform.localPosition;
        noteCamera.transform.Translate(translate);
        newPos         = noteCamera.transform.localPosition;
        cacheDeltaMove = newPos - oldPos;

        Vector3 vecBottom = GetBottomPosition();

        //return;
        // check game over
        for (int i = 0; i < listNoteActive.Count; i++)
        {
            if (!listNoteActive[i].GetFinish())
            {
                //check if a tile has gone pass the designated point or not
                float topPassY = listNoteActive[i].GetTopHeightForPass();
                //if yes, continue checking
                if (vecBottom.y > topPassY)
                {
                    //if the game is not on auto play mode, proceed to game over state
                    if (!GameConsts.isPlayAuto && !gameplay.isListenThisSong)
                    {
                        //Debug.Log("GameOver " + listNoteActive[i].gameObject.name);
                        gameplay.ChangeStatusToGameOver();

                        StartCoroutine(RoutineGameOverByMissing(listNoteActive[i]));
                        return;
                    }
                    else
                    {
                        if (dicTouchCover.ContainsKey(0))
                        {
                            listNoteActive[i].Press(dicTouchCover[0]);
                        }
                        else
                        {
                            listNoteActive[i].Press(null);
                        }

                        if (listNoteActive[i].isLongNote)
                        {
                            NoteMulti multi = (NoteMulti)listNoteActive[i];
                            multi.OnShowUIWhenPress(Vector3.zero);
                        }
                    }
                }
                else
                {
                    break;
                }
            }
        }

        //find used tiles
        List <NoteSimple> listCanReset = new List <NoteSimple>();

        for (int i = 0; i < listNoteActive.Count; i++)
        {
            if (listNoteActive[i].GetFinish())
            {
                float topPassY = listNoteActive[i].GetTopHeightForReset();

                if (vecBottom.y > topPassY)
                {
                    listCanReset.Add(listNoteActive[i]);
                }
                else
                {
                    break;
                }
            }
        }

        //recover used tile
        for (int i = 0; i < listCanReset.Count; i++)
        {
            listNoteActive.Remove(listCanReset[i]);
            listCanReset[i].Reset();
            PushToPool(listCanReset[i]);

            //generate new tiles for each used one
            gameplay.GenerateNextTile();
        }
    }