There's a fundamental bug in the latter half of this code that wasn't fixed: here's where it is, and how to resolve it. You'll need to edit your ClearLines() method in the GameLogic script. What's happening is that you're moving the lines down, incrementing Y without adjusting for the shifted blocks, and missing all cases where two lines of rows are completed adjacent to each other. This is my fixed method. I reversed the for loop, checking for completed blocks from the top down instead of the bottom up. public void ClearLines() { for (int y = height-1; y >= 0; y--) { if (IsLineComplete(y)) { DestroyLine(y); MoveLines(y); } } }
I didn't get the blocks to move down correctly after clearing a line with your code, I may have done some things different that have impacted it, but I made it work with this: private static void MoveLines(int y) { for (int i = y; i < gameHeight - 1; i++) // The array goes out of bounds if you don't set -1, // since you check for the grid above in the second for loop { for (int x = 0; x < gameWidth; x++) { if (grid[x, i + 1] != null) // In the tutors code, the code only checks for the row above, now it checks every row { grid[x, i] = grid[x, i + 1]; grid[x, i].gameObject.transform.position -= new Vector3(0, 1, 0); grid[x, i + 1] = null; } } } } private static void DestroyLine(int y) { for (int x = 0; x < gameWidth; x++) { Destroy(grid[x, y].gameObject); grid[x, y] = null; // Setting the cleared grid to null, then MoveLines will correct this if it got blocks above } }
I finished your Tutorial but there are two big bugs: 1. Blocks don't stop other blocks when they collide ob the right Side of the block. 2. I cannot clear a line but I think that's because of the first one. There ist a problem in your video as well...54:14. The blue Line is buggy.
// Function to check if the game is over public bool IsGameOver() { // Check the top row of the grid for any occupied cells for (int x = 0; x < gridWidth; x++) { if (grid[x, gridHeight - 1] != null) { return true; // If there's a block at the top, the game is over } } return false; // If the top row is empty, the game is not over } // ... (other TetrisManager code) // Call this function to check for game over conditions public void CheckGameOver() { if (IsGameOver()) { // Implement game over logic here, such as displaying a game over screen or resetting the game. Debug.Log("Game Over!"); } }
So the ClearLine function (or it's helper functions) don't work correctly. If I have multiple complete lines, only the bottom most is cleared, and only the line directly above the cleared line moves down. Additionally, new blocks stop spawning after a line has been cleared.
i am a beginner and have a question...can we use collider to prevent moving through other blocks and use gravity to make objects fall and also will it be too much computationally intensive than the other method?.. gr8 video btw
When I try to spawn blocks randomly and save the source code, it says error: "Mathf" does not contain a definition for "floorToInt". What is happening?
What about game like tetris but only clear not lines, but 3 blocks sequence, horizontal or vertical? Like game Puyo puyo ar columns or maybe match 3 games. How to recognize when 3 blocks are ready for destroy ? How to know that line complete in this case?
Some error with RegisterBlock method. And part of blocks destroy, but other parn will not. And in the left side i can't rotate. Something is wrong with the center of the blocks.
is your scale setting for your grid set to unity default of 1? i get an error where im alway -.5 off on the y axis although all of my sprite centering. sprite sizes are identical to what you’ve shown in the lesson.
17:17 Did you do something off camera again? I was able to keep up with the sudden changes until this point. The piece won't move if I run the test. EDIT: Somehow I was able to get the piece to move and didn't have the out of bound error you had, which is really weird.
@@ClipperDev ooo, Polish is a dialect of Russian, its my opinion.I can tell by your accent that you're not English man. But you have very good content, you cool ;)
Cześć Clipper! Dzięki za Twój tutorial :) Udało mi się w przyjemny sposób zrobić gierkę oraz poprawić kilka drobnych błędów, które wkradły się w Twój film (w podobny sposób co w komentarzach poniżej, więc nie będę powtarzała). Niestety wciąż mam ten błąd: Index was outside the bounds of the array. Prześledziłam kod i wydaje mi się (właściwie jestem pewna, że mam tak jak u Ciebie). Wklejam fragmenty kodu, w których wywala błąd. Może wiesz, co jest nie tak? bool CheckValid() { foreach (Transform subBlock in rig.transform) {
There's a fundamental bug in the latter half of this code that wasn't fixed: here's where it is, and how to resolve it. You'll need to edit your ClearLines() method in the GameLogic script. What's happening is that you're moving the lines down, incrementing Y without adjusting for the shifted blocks, and missing all cases where two lines of rows are completed adjacent to each other.
This is my fixed method. I reversed the for loop, checking for completed blocks from the top down instead of the bottom up.
public void ClearLines() {
for (int y = height-1; y >= 0; y--) {
if (IsLineComplete(y)) {
DestroyLine(y);
MoveLines(y);
}
}
}
Thank you!!!
I didn't get the blocks to move down correctly after clearing a line with your code, I may have done some things different that have impacted it, but I made it work with this:
private static void MoveLines(int y)
{
for (int i = y; i < gameHeight - 1; i++)
// The array goes out of bounds if you don't set -1,
// since you check for the grid above in the second for loop
{
for (int x = 0; x < gameWidth; x++)
{
if (grid[x, i + 1] != null)
// In the tutors code, the code only checks for the row above, now it checks every row
{
grid[x, i] = grid[x, i + 1];
grid[x, i].gameObject.transform.position -= new Vector3(0, 1, 0);
grid[x, i + 1] = null;
}
}
}
}
private static void DestroyLine(int y)
{
for (int x = 0; x < gameWidth; x++)
{
Destroy(grid[x, y].gameObject);
grid[x, y] = null;
// Setting the cleared grid to null, then MoveLines will correct this if it got blocks above
}
}
Thank you random citizen.
Yeah but it works only with one full line at once, if we have two full lines it doesnt work ... it works only for the first line ...
I finished your Tutorial but there are two big bugs:
1. Blocks don't stop other blocks when they collide ob the right Side of the block.
2. I cannot clear a line but I think that's because of the first one.
There ist a problem in your video as well...54:14. The blue Line is buggy.
Thank you very much, it is a very excellent explanation🎉
// Function to check if the game is over
public bool IsGameOver()
{
// Check the top row of the grid for any occupied cells
for (int x = 0; x < gridWidth; x++)
{
if (grid[x, gridHeight - 1] != null)
{
return true; // If there's a block at the top, the game is over
}
}
return false; // If the top row is empty, the game is not over
}
// ... (other TetrisManager code)
// Call this function to check for game over conditions
public void CheckGameOver()
{
if (IsGameOver())
{
// Implement game over logic here, such as displaying a game over screen or resetting the game.
Debug.Log("Game Over!");
}
}
So the ClearLine function (or it's helper functions) don't work correctly. If I have multiple complete lines, only the bottom most is cleared, and only the line directly above the cleared line moves down.
Additionally, new blocks stop spawning after a line has been cleared.
At the end of the video it still not working right...... when i had knew this before i went directly to other video from other guy
54:12 something wrong when the blue bar hits the floor. anyway I shall figure out how to make it work by my one.
i am a beginner and have a question...can we use collider to prevent moving through other blocks and use gravity to make objects fall and also will it be too much computationally intensive than the other method?.. gr8 video btw
The collider wouldn't be exact to the block and the script would need to work with every single block.
When I try to spawn blocks randomly and save the source code, it says error: "Mathf" does not contain a definition for "floorToInt". What is happening?
What about game like tetris but only clear not lines, but 3 blocks sequence, horizontal or vertical? Like game Puyo puyo ar columns or maybe match 3 games. How to recognize when 3 blocks are ready for destroy ? How to know that line complete in this case?
Where to get score counter and level up plug ins? any idea? thanks for sharing!
make them
Thank you so much for your tutorial, very clear one !
Its not working right......you see at the end of video still bucks...how do you fixed it?
Some error with RegisterBlock method. And part of blocks destroy, but other parn will not. And in the left side i can't rotate. Something is wrong with the center of the blocks.
is your scale setting for your grid set to unity default of 1? i get an error where im alway -.5 off on the y axis although all of my sprite centering. sprite sizes are identical to what you’ve shown in the lesson.
I'm getting errors with the timer. Console error says that the name Timer does not exist in the current context.
Are you finish ludum dare jam in 3 hours team? I've frankly gotten a bit lost in the tutorial a little. Halfway through before bugs bugged me
That intro sounds familiar ;3
very good!
can we have the source code ?
54:13 Баг с линией, она провалилась, в Т фигуру..
I tried the code but it doesn't work. I can't move the blocks.
I’m sorry to hear that. Maybe you can pass your code either here or on discord so we can try to fix the issue?
@@ClipperDev i sent an email to you
Could you please send again? Nothing received, checked spam as well. I’ll see tomorrow if anything changes
@@ClipperDev I sent you a Dropbox link to it, cause neither Gmail or Yahoo want me to send it.
@@ClipperDev I sent you an email with a link to my Tetris code
17:17 Did you do something off camera again? I was able to keep up with the sudden changes until this point. The piece won't move if I run the test.
EDIT: Somehow I was able to get the piece to move and didn't have the out of bound error you had, which is really weird.
You russian? =)
Niet, Polak
Pierogi
@@ClipperDev ooo, Polish is a dialect of Russian, its my opinion.I can tell by your accent that you're not English man. But you have very good content, you cool ;)
Cześć Clipper!
Dzięki za Twój tutorial :) Udało mi się w przyjemny sposób zrobić gierkę oraz poprawić kilka drobnych błędów, które wkradły się w Twój film (w podobny sposób co w komentarzach poniżej, więc nie będę powtarzała). Niestety wciąż mam ten błąd: Index was outside the bounds of the array.
Prześledziłam kod i wydaje mi się (właściwie jestem pewna, że mam tak jak u Ciebie). Wklejam fragmenty kodu, w których wywala błąd. Może wiesz, co jest nie tak?
bool CheckValid()
{
foreach (Transform subBlock in rig.transform)
{
if(subBlock.transform.position.x >= GameLogic.width ||
subBlock.transform.position.x