// perform calculation and spawn private void PerformCalAndSpawn(Transform t) { Game2P.PerformOperations(t, Game2P.grid2, 2); // Clean the full rows Game2P.DeleteFullRows(2); // Spawn next shape //FindObjectOfType<Spawner>().SpawnNext(); spawner.SpawnNext(); // Disable the script of the obj, since it needs to be stop from controlling // enabled = false; }
// update all grids that belongs to a certain shape. void UpdateGrid() { if (Data.mode == 1) { // Remove old children from grid for (int x = 0; x < Game.width; ++x) { for (int y = 0; y < Game.height; ++y) { if (Game.grid[x, y] != null) // if has a grid { if (Game.grid[x, y].parent == transform) // if the parent is the shape { Game.grid[x, y] = null; } } } } // put new block in the position foreach (Transform child in transform) { Vector2 pos = Game.RoundPosition(child.position); Game.grid[(int)pos.x, (int)pos.y] = child; } } else { for (int x = 0; x < Game2P.width; ++x) { for (int y = 0; y < Game2P.height; ++y) { if (Game2P.grid1[x, y] != null) // if has a grid { if (Game2P.grid1[x, y].parent == transform) // if the parent is the shape { Game2P.grid1[x, y] = null; } } } } // put new block in the position foreach (Transform child in transform) { Vector2 pos = Game2P.RoundPosition(child.position); Game2P.grid1[(int)pos.x, (int)pos.y] = child; } } }
public bool isValidGridPos() { if (Data.mode == 1) { foreach (Transform child in transform) { Vector2 pos = Game.RoundPosition(child.position); // detect if the block is inside border or not if (!Game.InsideBorder(pos)) { return(false); } // Used in rotation: find the block that is in the position already. // If there is a block that at the position, return false. if (Game.grid[(int)pos.x, (int)pos.y] != null && Game.grid[(int)pos.x, (int)pos.y].parent != transform) { return(false); } } return(true); } else { foreach (Transform child in transform) { Vector2 pos = Game2P.RoundPosition(child.position); // detect if the block is inside border or not if (!Game2P.InsideGridOneBorder(pos)) { return(false); } // Used in rotation: find the block that is in the position already. // If there is a block that at the position, return false. if (Game2P.grid1[(int)pos.x, (int)pos.y] != null && Game2P.grid1[(int)pos.x, (int)pos.y].parent != transform) { return(false); } } return(true); } return(true); }
// Use this for initialization void Start() { GameObject finalScore = GameObject.Find("FinalScore"); GameObject cod = GameObject.Find("COD"); GameObject winner = GameObject.Find("Winner"); GameObject p1 = GameObject.Find("P1"); GameObject p2 = GameObject.Find("P2"); GameObject mainSound = GameObject.Find("Tetris"); if (finalScore) { finalScore.GetComponent <Text>().text = "Score: " + Data.score.ToString("0.00"); } if (cod) { if (Data.mode == 1) { cod.GetComponent <Text>().text = "Cause of Death: " + Data.cod; } else { cod.GetComponent <Text>().text = Data.cod; } } if (winner) { string w = Game2P.winner == 1 ? "Player 1" : "Player 2"; winner.GetComponent <Text>().text = w + " wins!"; } if (p1 && p2) { p1.GetComponent <Text>().text = "Player 1: " + Game2P.score1; p2.GetComponent <Text>().text = "Player 2: " + Game2P.score2; } if (mainSound) { string scene = SceneManager.GetActiveScene().name; if (scene == "Over" || scene == "Over2P") { mainSound.GetComponent <AudioSource>().Stop(); } } Game2P.Reset(); }
// perform calculation and spawn private void PerformCalAndSpawn(Transform t) { if (Data.mode == 1) { Game.PerformOperations(t); // Clean the full rows Game.DeleteFullRows(); // Spawn next shape spawner.SpawnNext(); // Disable the script of the obj, since it needs to be stop from controlling // enabled = false; } else { Game2P.PerformOperations(t, Game2P.grid1, 1); Game2P.DeleteFullRows(1); spawner2P.SpawnNext(); } }
public bool isValidGridPos() { foreach (Transform child in transform) { Vector2 pos = Game2P.RoundPosition(child.position); // detect if the block is inside border or not if (!Game2P.InsideGridTwoBorder(pos)) { return(false); } // Used in rotation: find the block that is in the position already. // If there is a block that at the position, return false. if (Game2P.grid2[(int)(pos.x - 14), (int)pos.y] != null && Game2P.grid2[(int)(pos.x - 14), (int)pos.y].parent != transform) { return(false); } } //Debug.Log("Exiting isValidGridPos"); return(true); }