void AllBlocksStatic() { b_RunAgain = false; #region Set Left & Right Walls to 'Empty' (Done BEFORE scoring) for (int y_ = 0; y_ < i_ArrayHeight; ++y_) { // Tell the board model to destroy the block if (GetBlock(0, y_) != Enum_BlockType.Empty) { GameObject.Find("BoardDisplay").GetComponent<Cs_BoardDisplay>().DestroyBlockAt(new IntVector2(0, y_)); } // Set Left Wall to be 'Empty' SetBlock(0, y_, Enum_BlockType.Empty); // Tell the board model to destroy the block if (GetBlock(i_ArrayWidth - 1, y_) != Enum_BlockType.Empty) { GameObject.Find("BoardDisplay").GetComponent<Cs_BoardDisplay>().DestroyBlockAt(new IntVector2(i_ArrayWidth - 1, y_)); } // Set Right Wall to be 'Empty' SetBlock(i_ArrayWidth - 1, y_, Enum_BlockType.Empty); } #endregion #region Convert All to Static // Run through the array and convert all blocks into their static counterpart. Run bottom to top, left to right. for (int x_ = 0; x_ < i_ArrayWidth; ++x_) { for (int y_ = 0; y_ < i_ArrayHeight; ++y_) { Enum_BlockType tempBlock = GetBlock(x_, y_); if (tempBlock == Enum_BlockType.Block_1_Active) { SetBlock(x_, y_, Enum_BlockType.Block_1_Static); } else if (tempBlock == Enum_BlockType.Block_2_Active) { SetBlock(x_, y_, Enum_BlockType.Block_2_Static); } else if (tempBlock == Enum_BlockType.Block_3_Active) { SetBlock(x_, y_, Enum_BlockType.Block_3_Static); } } } #endregion #region Pull Blocks Down PullBlocksDown(); #endregion // TODO: RUN SCORE CODE HERE FIRST if (Load_ScoreLine()) { #region Print Scoreline to console string s_ScoreLine = "LINE REACHED: (" + iv2_ScoreLine.Count + "):"; for (int i_ = 0; i_ < iv2_ScoreLine.Count; ++i_) { if (i_ != iv2_ScoreLine.Count - 1) { s_ScoreLine += iv2_ScoreLine[i_] + ", "; } else { s_ScoreLine += iv2_ScoreLine[i_] + ""; } } print(s_ScoreLine); #endregion CheckScoreLineLeftWall(); // Destroy all Black Blocks if (b_ThreeBlockColors) { DestroyBlackBlocks(); } b_RunAgain = true; e_PauseEffect = Enum_PauseEffect.ScoreLine; GameObject.Find("BoardDisplay").GetComponent<Cs_BoardDisplay>().Set_ScoreTextIncrease(iv2_ScoreLine.Count); i_ScoreLine_Counter = 0; return; } #region Set 'Mid Empty' row to empty (Done AFTER scoring) //for (int y_ = 0; y_ < i_ArrayHeight; ++y_) //{ // if (b_MidRowBlank) // { // if (i_ExtraBlankRow > 0 && // i_ExtraBlankRow < i_ArrayWidth) // { // // Destroy the block model on screen // if (GetBlock(0, y_) != Enum_BlockType.Empty) // { // GameObject.Find("BoardDisplay").GetComponent<Cs_BoardDisplay>().DestroyBlockAt(new IntVector2(i_ExtraBlankRow, y_)); // } // SetBlock(i_ExtraBlankRow, y_, Enum_BlockType.Empty); // } // } //} #endregion // Set the next block size to be whatever we found e_BlockSize = e_NextBlockSize; // Clear all backdrops now. Creating new blocks will reset the new backdrop colors // GameObject.Find("BoardDisplay").GetComponent<Cs_BoardDisplay>().Set_ClearBackdrops(); if(b_RunAgain) { AllBlocksStatic(); // GameObject.Find("BoardDisplay").GetComponent<Cs_BoardDisplay>().Set_ClearBackdrops(); } else { // GameObject.Find("BoardDisplay").GetComponent<Cs_BoardDisplay>().Set_ClearBackdrops(); Load_ScoreLine(); CheckScoreLineLeftWall(); CreateNewBlock(); // Reset time for new block to be created f_TimeToDrop = -1f; } }
void CreateNewBlock() { // Manually create a set of new blocks in the proper location int i_NumToShift = 0; // Find the 'X' location to set the block location (2 wide) if(e_BlockSize == Enum_BlockSize.size_2w_2h || e_BlockSize == Enum_BlockSize.size_2w_3h) { // Finds the center of the List width v2_ActiveBlockLocation.x = (int)((i_ArrayWidth - 1) / 2); } else // (3 high) { // Finds the center of the List width, and shifts to the left one space v2_ActiveBlockLocation.x = (int)((i_ArrayWidth - 1) / 2) - 1; } // Find the 'Y' location to set the block location (2 high) if (e_BlockSize == Enum_BlockSize.size_2w_2h || e_BlockSize == Enum_BlockSize.size_3w_2h) { v2_ActiveBlockLocation.y = i_ArrayHeight - 2; } // (3 high) else v2_ActiveBlockLocation.y = i_ArrayHeight - 3; // Check for GameOver based on new ActiveBlockLocation information. Returns true if the game's over. if (GameOverCheck()) { // PauseState is set to Game Over e_PauseEffect = Enum_PauseEffect.GameOver; return; } // Set the number of blocks to shift afterward if (e_BlockSize == Enum_BlockSize.size_2w_2h) i_NumToShift = 4; else if (e_BlockSize == Enum_BlockSize.size_2w_3h || e_BlockSize == Enum_BlockSize.size_3w_2h) i_NumToShift = 6; else if (e_BlockSize == Enum_BlockSize.size_3w_3h) i_NumToShift = 9; // Create temp block list int i_NewBlocks_Width = 2; int i_NewBlocks_Height = 2; if (e_BlockSize == Enum_BlockSize.size_3w_2h || e_BlockSize == Enum_BlockSize.size_3w_3h) i_NewBlocks_Width = 3; if (e_BlockSize == Enum_BlockSize.size_2w_3h || e_BlockSize == Enum_BlockSize.size_3w_3h) i_NewBlocks_Height = 3; // print("BLOCK SIZE: " + e_BlockSize); Enum_BlockType[,] e_SmallList = new Enum_BlockType[i_NewBlocks_Height, i_NewBlocks_Width]; // No matter what, set the initial 2x2 SetBlock(v2_ActiveBlockLocation, e_NextBlockList[0]); e_SmallList[0, 0] = e_NextBlockList[0]; SetBlock(new Vector2(v2_ActiveBlockLocation.x + 1, v2_ActiveBlockLocation.y + 0), e_NextBlockList[1]); e_SmallList[0, 1] = e_NextBlockList[1]; SetBlock(new Vector2(v2_ActiveBlockLocation.x + 0, v2_ActiveBlockLocation.y + 1), e_NextBlockList[2]); e_SmallList[1, 0] = e_NextBlockList[2]; SetBlock(new Vector2(v2_ActiveBlockLocation.x + 1, v2_ActiveBlockLocation.y + 1), e_NextBlockList[3]); e_SmallList[1, 1] = e_NextBlockList[3]; // If we're specifically 3x2, set those positions if ( e_BlockSize == Enum_BlockSize.size_3w_2h ) { SetBlock(new Vector2(v2_ActiveBlockLocation.x + 2, v2_ActiveBlockLocation.y + 1), e_NextBlockList[4]); e_SmallList[1, 2] = e_NextBlockList[4]; SetBlock(new Vector2(v2_ActiveBlockLocation.x + 2, v2_ActiveBlockLocation.y + 0), e_NextBlockList[5]); e_SmallList[0, 2] = e_NextBlockList[5]; } // If we're specifically 2x3, set those positions else if( e_BlockSize == Enum_BlockSize.size_2w_3h) { SetBlock(new Vector2(v2_ActiveBlockLocation.x + 0, v2_ActiveBlockLocation.y + 2), e_NextBlockList[4]); e_SmallList[2, 0] = e_NextBlockList[4]; SetBlock(new Vector2(v2_ActiveBlockLocation.x + 1, v2_ActiveBlockLocation.y + 2), e_NextBlockList[5]); e_SmallList[2, 1] = e_NextBlockList[5]; } else if( e_BlockSize == Enum_BlockSize.size_3w_3h ) { SetBlock(new Vector2(v2_ActiveBlockLocation.x + 2, v2_ActiveBlockLocation.y + 1), e_NextBlockList[4]); e_SmallList[1, 2] = e_NextBlockList[4]; SetBlock(new Vector2(v2_ActiveBlockLocation.x + 2, v2_ActiveBlockLocation.y + 0), e_NextBlockList[5]); e_SmallList[0, 2] = e_NextBlockList[5]; SetBlock(new Vector2(v2_ActiveBlockLocation.x + 0, v2_ActiveBlockLocation.y + 2), e_NextBlockList[6]); e_SmallList[2, 0] = e_NextBlockList[6]; SetBlock(new Vector2(v2_ActiveBlockLocation.x + 1, v2_ActiveBlockLocation.y + 2), e_NextBlockList[7]); e_SmallList[2, 1] = e_NextBlockList[7]; SetBlock(new Vector2(v2_ActiveBlockLocation.x + 2, v2_ActiveBlockLocation.y + 2), e_NextBlockList[8]); e_SmallList[2, 2] = e_NextBlockList[8]; } #region Send e_SmallList to Board Display GameObject.Find("BoardDisplay").GetComponent<Cs_BoardDisplay>().Set_NewBlocks(e_SmallList, e_BlockSize, new IntVector2((int)v2_ActiveBlockLocation.x, (int)v2_ActiveBlockLocation.y)); #endregion #region Send Set_ShowPotentialBlockVisual Information PotentialBlockVisual(); #endregion ShiftNewBlockList( i_NumToShift ); }
void Update() { if(Input.GetKeyDown(KeyCode.P)) { Cheat_SetDoubleLine(); } if(e_PauseEffect == Enum_PauseEffect.Unpause) { if(b_DemoGame_InputReceived) { #region Drop Block timer // Decrement timer for next time to move blocks down if (i_TimeToDrop_Max > 0) { f_TimeToDrop += Time.deltaTime; if(f_TimeToDrop > i_TimeToDrop_Max) { // Reset timer f_TimeToDrop = 0; // Drop blocks down manually MoveActiveBlocks_Down(v2_ActiveBlockLocation, e_BlockSize); } } #endregion } } else if(e_PauseEffect == Enum_PauseEffect.ScoreLine) { #region Scoreline Pause // Run through the Scoreline array and have them destroy themselves f_ScoreLine_Timer += Time.deltaTime; if(f_ScoreLine_Timer > f_ScoreLine_Timer_Max) { if(i_ScoreLine_Counter < iv2_ScoreLine.Count) { // Set the block in BlockArray to empty SetBlock(iv2_ScoreLine[i_ScoreLine_Counter].x, iv2_ScoreLine[i_ScoreLine_Counter].y, Enum_BlockType.Empty); // Score the block model on the screen GameObject.Find("BoardDisplay").GetComponent<Cs_BoardDisplay>().ScoreBlockAt(iv2_ScoreLine[i_ScoreLine_Counter]); #region Play sound effect // Store previous pitch float f_Pitch_Prev = go_SFX.GetComponent<AudioSource>().pitch; // Find pitch float f_Pitch = 0.4f + ((iv2_ScoreLine[i_ScoreLine_Counter].x / 3f) * 0.2f) + ((iv2_ScoreLine[i_ScoreLine_Counter].y / 3f) * 0.05f); print("Setting pitch: " + f_Pitch); go_SFX.GetComponent<AudioSource>().clip = sfx_ScoreEffect; go_SFX.GetComponent<AudioSource>().pitch = f_Pitch; go_SFX.GetComponent<AudioSource>().time = 0.09f; go_SFX.GetComponent<AudioSource>().Play(); // Set previous pitch // go_SFX.GetComponent<AudioSource>().pitch = f_Pitch_Prev; #endregion // Increment i_ScoreLine_Counter ++i_ScoreLine_Counter; } // Scoreline is finished, reset and move on else { // f_ScoreLine_Timer_Max gets added here cause I'm lazy. This line doesn't hit until the above timer breaches f_ScoreLine_Timer_Max. f_ScoreLine_Timer_Conclusion += Time.deltaTime + f_ScoreLine_Timer_Max; if(f_ScoreLine_Timer_Conclusion > f_ScoreLine_Timer_Conclusion_Max) { if (Load_ScoreLine()) { CheckScoreLineLeftWall(); b_RunAgain = true; e_PauseEffect = Enum_PauseEffect.ScoreLine; GameObject.Find("BoardDisplay").GetComponent<Cs_BoardDisplay>().Set_ScoreTextIncrease(iv2_ScoreLine.Count); i_ScoreLine_Counter = 0; f_ScoreLine_Timer_Conclusion = 0.0f; return; } else { f_ScoreLine_Timer_Conclusion = 0.0f; // Reset the counter for the next cycle i_ScoreLine_Counter = 0; b_RunAgain = true; // Clear the ScoreLine list iv2_ScoreLine = new List<IntVector2>(); // 'PullBlocksDown' to update the board PullBlocksDown(); if(Load_ScoreLine()) { CheckScoreLineLeftWall(); b_RunAgain = true; e_PauseEffect = Enum_PauseEffect.ScoreLine; GameObject.Find("BoardDisplay").GetComponent<Cs_BoardDisplay>().Set_ScoreTextIncrease(iv2_ScoreLine.Count); i_ScoreLine_Counter = 0; f_ScoreLine_Timer_Conclusion = 0.0f; return; } // Make a new block CreateNewBlock(); // Gameplay resumes e_PauseEffect = Enum_PauseEffect.Unpause; } // Reset the ScoreLine timer } } // Reset the float timer f_ScoreLine_Timer = 0.0f; } #endregion } else if(e_PauseEffect == Enum_PauseEffect.StartGame) { #region Start Game // Creates a new block after a couple seconds at the beginning of the game if (f_StartGameTimer > 0) { f_StartGameTimer -= Time.deltaTime; if (f_StartGameTimer < 0) { // GameObject.Find("BoardDisplay").GetComponent<Cs_BoardDisplay>().Set_ClearBackdrops(); CreateNewBlock(); e_PauseEffect = Enum_PauseEffect.Unpause; } } #endregion } else if(e_PauseEffect == Enum_PauseEffect.GameOver) { #region End Game f_GameOver_Timer += Time.deltaTime; if(f_GameOver_Timer > f_GameOver_Timer_Max) { // Set block position if( i_GameOver_X < i_ArrayWidth - 1 && i_GameOver_Y < i_ArrayHeight ) { // Destroy the old. Set the new. All visual, no board array manipulation. GameObject.Find("BoardDisplay").GetComponent<Cs_BoardDisplay>().DestroyBlockAt(new IntVector2(i_GameOver_X, i_GameOver_Y)); GameObject.Find("BoardDisplay").GetComponent<Cs_BoardDisplay>().Set_GameOverBlock( i_GameOver_X, i_GameOver_Y, e_GameOverBlock ); } // Set next block type #region Next Block Type // Ensure that we're an odd number. Forces a checkerboard pattern. if(i_GameOver_X < i_ArrayWidth - 1) { if (e_GameOverBlock == Enum_BlockType.Block_1_Active) { e_GameOverBlock = Enum_BlockType.Block_2_Active; } else if (e_GameOverBlock == Enum_BlockType.Block_2_Active) { if (b_ThreeBlockColors) { e_GameOverBlock = Enum_BlockType.Block_3_Active; } else { e_GameOverBlock = Enum_BlockType.Block_1_Active; } } else // Block 3 { e_GameOverBlock = Enum_BlockType.Block_1_Active; } } else { if (i_ArrayWidth % 2 == 0) { if (e_GameOverBlock == Enum_BlockType.Block_1_Active) { e_GameOverBlock = Enum_BlockType.Block_2_Active; } else if (e_GameOverBlock == Enum_BlockType.Block_2_Active) { if (b_ThreeBlockColors) { e_GameOverBlock = Enum_BlockType.Block_3_Active; } else { e_GameOverBlock = Enum_BlockType.Block_1_Active; } } else { e_GameOverBlock = Enum_BlockType.Block_1_Active; } } } #endregion // Reset timer f_GameOver_Timer = 0f; // Increment X/Y ++i_GameOver_X; // When the GameOver_X position is greater than the inner walls... if(i_GameOver_X > i_ArrayWidth - 1) { // Reset the X position i_GameOver_X = 1; // Increments the Y. ++i_GameOver_Y; } } else { if (i_GameOver_X >= i_ArrayWidth - 1 && i_GameOver_Y >= i_ArrayHeight - 1) { f_GameOver_FadeOut_Timer += Time.deltaTime; } } #endregion if(f_GameOver_FadeOut_Timer > 0f) { // Fade to black & return to main menu f_GameOver_FadeOut_Timer += Time.deltaTime; print(f_GameOver_FadeOut_Timer); if (f_GameOver_FadeOut_Timer > 5.0f) { // Fade out the screen slowly Color clr_CurrAlpha = go_FadeOut.GetComponent<Image>().color; clr_CurrAlpha.a += Time.deltaTime / 3f; float f_Perc = 1f - clr_CurrAlpha.a; go_FadeOut.GetComponent<Image>().color = clr_CurrAlpha; // Reduce volume to match GameObject.Find("AudioSource_Music").GetComponent<AudioSource>().volume = f_Perc / 2.0f; } if (f_GameOver_FadeOut_Timer > 10f) { SceneManager.LoadScene(2); } } } }