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); } }
public NoteSimple PopSimple(string name) { if (poolNoteSimple.Count < 1) { GameObject obj = GameObject.Instantiate(prefabNoteSimple) as GameObject; NoteSimple simple = obj.GetComponent <NoteSimple>(); simple.isLongNote = false; simple.SetupInPool(poolRoot); obj.name = name; // "simple_buffer"; poolNoteSimple.Enqueue(simple); } return(poolNoteSimple.Dequeue()); }
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); } }
private IEnumerator EffectDieByMissing(NoteSimple noteDie) { //flash 4 times for (int i = 0; i < 8; i++) { if (i % 2 == 0) { noteDie.gameObject.SetActive(true); } else { noteDie.gameObject.SetActive(false); } yield return(new WaitForSeconds(0.1f)); } noteDie.gameObject.SetActive(true); }
public bool CheckGameOver(TouchCover touch) { NoteSimple note = null; Vector3 vec = GetRootPositionHit(touch); //skip first note (which is a special start object) if (vec.y <= startObj.transform.localPosition.y + 480) { return(false); } //start checking from the end of the note list //check for a small bit of tiles only, not to go too far to save calculating time for (int i = 0; i < listNoteActive.Count && i < 6; i++) { float min = listNoteActive[i].transform.localPosition.y; float max = min + listNoteActive[i].height; //check if the touch on background has any tiles with the same Y? if (vec.y >= min && vec.y <= max) { //if yes, check if there is any tile at that exact location? float minX = listNoteActive[i].transform.localPosition.x; float maxX = minX + tileWidth; if (vec.x >= minX && vec.x <= maxX) { //if yes, then the touch is fine, because may be we touch on an used tile //Debug.Log("Touched on background, but saved by note " + note.gameObject.name); return(false); } else { //if not touch on any tiles, meaning the user has missed it note = listNoteActive[i]; break; } } } //if there are no tile next to current touch if (note == null) { //mean the touch is fine return(false); } return(true); }
public IEnumerator RoutineGameOverByMissing(NoteSimple noteDie) { MidiPlayer.Instance.PlayPianoNote(PIANO_NOTE_GAME_OVER); yield return(new WaitForSeconds(0.4f)); Vector3 vecStart = noteCamera.transform.localPosition; Vector3 vecEnd = vecStart; vecEnd.y -= noteDie.GetDistanceAcceptPass() * scale; noteCamera.transform.DOLocalMove(vecEnd, 0.5f).SetEase(Ease.OutQuad).Play(); yield return(new WaitForSeconds(0.4f)); StartCoroutine(EffectDieByMissing(noteDie)); yield return(new WaitForSeconds(0.5f)); noteDie.ResetClickable();// dung cho replay gameplay.ProcessGameOverEvent(); }
public void GenerateNoteDie(TouchCover touch) { Vector3 posGenererate = Vector3.zero; float heightGenerate = 480; NoteSimple note = null; Vector3 vec = GetRootPositionHit(touch); posGenererate = vec; for (int i = 0; i < listNoteActive.Count; i++) { float min = listNoteActive[i].transform.localPosition.y; float max = min + listNoteActive[i].height; if (vec.y >= min && vec.y <= max) { note = listNoteActive[i]; } } if (note != null) { int x = (int)(posGenererate.x / tileWidth); posGenererate = note.transform.localPosition; posGenererate.x = x * tileWidth; heightGenerate = note.height; } else { //Should never go to here int x = (int)(vec.x / tileWidth); posGenererate.x = x * tileWidth; heightGenerate = vec.y; } GameObject objDie = GameObject.Instantiate(prefabDie); objDie.transform.parent = lineRoot; objDie.transform.localScale = Vector3.one; objDie.transform.localPosition = posGenererate; objDie.GetComponent <NoteDie>().Setup(heightGenerate); GameObject.Destroy(objDie, 2f); }
/// <summary> /// Check if this note can register touch or not /// </summary> /// <param name="note">The note to check</param> /// <returns>Is the specified note eligible for touching</returns> private bool CanTouchNote(NoteSimple note) { for (int i = 0; i < listNoteActive.Count; i++) { //get the last clickable note if (listNoteActive[i].IsClickable()) { //if that is the same note as we are checking, return true if (listNoteActive[i] == note) { return(true); } else { //or else, continue to check //if the lowest note is a dual note if (listNoteActive[i].data.subType == TileType.Dual) { //special case, if i == 0 if (i == 0) { //only check for the next tile, since there are no tile before if (listNoteActive[1] == note) { return(true); } return(false); } //special case, if i is at the end of the list else if (i == listNoteActive.Count - 1) { //only check for the previous tile since there are no tile after if (listNoteActive[listNoteActive.Count - 2] == note) { return(true); } return(false); } else { //if the note right before or after this clickable note is the one we are checking, return true if (listNoteActive[i - 1] == note || listNoteActive[i + 1] == note) { return(true); } } //all else, false return(false); } else { return(false); } } } } return(false); }
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); } }
public void GenerateNextTile() { //Debug.LogError ("GenerateNextTile:"+listTilesData.Count+","+numTileGenerated+","+InGameUIController.Instance.GetCountNoteActive()); //this.Print("Generating next tile"); if (listTilesData.Count <= 0) { return; } if (numTileGenerated < 0) { numTileGenerated = 0; } //get suitable tile data int tileIndex = numTileGenerated % listTilesData.Count; if (tileIndex == 0 && numTileGenerated != 0) { zz_rest_distance = 1500; } else { zz_rest_distance = 0; } TileData tileData = listTilesData[tileIndex]; //calculate tile's position Vector3 spawnPos = new Vector3(0, 480 - 1140, 0);//tileStartPosition.localPosition; //random tile's location int tileColumIndex = 0; //if this is not the first tile to be spawn if (numTileGenerated > 0) { NoteSimple note = InGameUIController.Instance.GetLastNoteGenerate(); TileData lastTile = note.data; //print(string.Format("Num tile generated: {0}, last dual tile index {1}", numTileGenerated, lastDualTileIndex)); if (((lastTile.subType != TileType.Dual) || (tileData.subType != TileType.Dual)) || (numTileGenerated - lastDualTileIndex <= 1)) { //if the tile is a dual note or a note right after dual note, set it as next to the last generated tile if (tileData.subType == TileType.Dual || lastTile.subType == TileType.Dual) { tileColumIndex = (lastGeneratedTileColumn + 1) % TILE_COLUMN; } else { //if the tile is a normal one, random for a column index tileColumIndex = UnityEngine.Random.Range(0, TILE_COLUMN); //but the random column can not be the same as the last one if (tileColumIndex == lastGeneratedTileColumn) { //so we improvise here tileColumIndex = lastGeneratedTileColumn + UnityEngine.Random.Range(1, TILE_COLUMN - 1); tileColumIndex = tileColumIndex % TILE_COLUMN; } } //calculate time appear of this to-be-generated-tile float supposeAppearTime = lastTile.startTime + lastTile.duration; float appearTime = tileData.startTime; //if it's not too far from the last tile if (appearTime <= supposeAppearTime + MINIMUM_TIME_DIFFERENT) { //spawn it at normal position (without any empty area in between them) spawnPos.y = note.transform.localPosition.y + note.height - 1140 + zz_rest_distance; } else { spawnPos.y = note.transform.localPosition.y + note.height - 1140 + zz_rest_distance + (appearTime - supposeAppearTime) * baseLocalRunSpeed; } } else { //record current index as last dual tile created lastDualTileIndex = numTileGenerated; tileColumIndex = (lastGeneratedTileColumn + 2) % TILE_COLUMN; spawnPos.y = note.transform.localPosition.y - 1140 + zz_rest_distance; } } lastGeneratedTileColumn = tileColumIndex; //create a new tile int tileLength = 0; if (tileData.type == TileType.LongNote) { //print(string.Format("Duration in ticks: {0}, tick per tile: {1}", tileData.durationInTicks, ticksPerTile)); tileData.score = Mathf.RoundToInt(tileData.durationInTicks * 1.0f / ticksPerTile); tileLength = Mathf.RoundToInt(tileData.durationInTicks * 1.0f / ticksPerTile * tileRowHeight); } else { tileData.score = 1; tileLength = tileData.score * tileRowHeight; } bool withBonusTile = false; if (CurrentGameStage == GameState.Playing) { if (numTileGenerated > listTilesData.Count) { if (tileData.subType != TileType.Dual) { if (diamondDropped < GameManager.Instance.GameConfigs.maxDiamondPerGame) { if (currentRunSpeed >= GameManager.Instance.GameConfigs.speedToDropDiamond && Counter.GetQuantity(Counter.KeyScore) >= GameManager.Instance.GameConfigs.scoreToDropDiamond) { float chance = UnityEngine.Random.Range(0, 1.001f); if (chance <= GameManager.Instance.GameConfigs.diamondChance) { withBonusTile = true; ++diamondDropped; } } } } } } InGameUIController.Instance.CreateNewNote(tileData, spawnPos, numTileGenerated, tileColumIndex, tileLength, withBonusTile); numTileGenerated++; }