Beispiel #1
0
    public void CreateNewNote(TileData data, Vector3 spawnPos, int tileIndex, int column, int height, bool withBonusTile = false, BonusType bonusType = BonusType.Diamond)
    {
        if (data.type == TileType.LongNote)
        {
            NoteMulti multi = PopMulti("multi_buffer");
            multi.Setup(data, spawnPos, tileIndex, column, height);
            if (listNoteActive.Contains(multi))
            {
                listNoteActive.Remove(multi);
            }
            listNoteActive.Add(multi);
        }
        else
        {
            NoteSimple simple = PopSimple("simple_buffer");
            simple.Setup(data, spawnPos, tileIndex, column, height);
            if (listNoteActive.Contains(simple))
            {
                listNoteActive.Remove(simple);
            }
            listNoteActive.Add(simple);
        }

        if (withBonusTile)
        {
            NoteBonus bonus       = CreateBonusTile(bonusType);
            int       bonusColumn = (column - 2 >= 0) ? column - 2 : column + 2;
            bonus.Setup(data, spawnPos, tileIndex, bonusColumn, height);
            listBonusTiles.Add(bonus);
        }
    }
Beispiel #2
0
 public void ClearCacheTouchForNote(TouchCover touch, NoteMulti multi)
 {
     if (dicTouch.ContainsKey(touch.fingerId))
     {
         NoteMulti multiCache = dicTouch[touch.fingerId];
         if (multi == multiCache)
         {
             dicTouch.Remove(touch.fingerId);
         }
     }
 }
Beispiel #3
0
 public NoteMulti PopMulti(string name)
 {
     if (poolNoteMulti.Count < 1)
     {
         GameObject obj   = GameObject.Instantiate(prefabNoteMulti) as GameObject;
         NoteMulti  multi = obj.GetComponent <NoteMulti>();
         multi.isLongNote = true;
         multi.SetupInPool(poolRoot);
         obj.name = name; // "multi_buffer";
         poolNoteMulti.Enqueue(multi);
         multi.touchKeepEffect = noteTouchEffect;
     }
     return(poolNoteMulti.Dequeue());
 }
Beispiel #4
0
    public void OnHoldTouch(TouchCover touch)
    {
        if (dicTouch.ContainsKey(touch.fingerId))
        {
            NoteMulti multi = dicTouch[touch.fingerId];

            //clean up completed touch references
            if (multi.IsMoveCompleted())
            {
                ResetTouch(touch);
            }
            multi.OnKeepTouch();
            multi.IncreaseActiveHeight(cacheDeltaMove.y);
        }
    }
Beispiel #5
0
 public void PushToPool(NoteSimple objNote)
 {
     if (!objNote.isLongNote)
     {
         NoteSimple simple = (NoteSimple)objNote;
         simple.Reset();
         poolNoteSimple.Enqueue(simple);
     }
     else
     {
         NoteMulti multi = (NoteMulti)objNote;
         multi.Reset();
         poolNoteMulti.Enqueue(multi);
     }
 }
Beispiel #6
0
 public void CacheTouchForNote(TouchCover touch, NoteMulti multi)
 {
     dicTouch[touch.fingerId] = multi;
 }
Beispiel #7
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);
        }
    }
Beispiel #8
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();
        }
    }