I hope you took away lots from this video. Let me know below! PS: I created a course named "Object Oriented Programming Made Easy"! Sign up at bit.ly/3NaMfg4. I think you will enjoy it!
What do you do when you have all the functions and the blocks are not responding to it? It is not rotating, moving left or right. In fact not responding to keyboard strokes in general?
There is still have a chance that the newly spawned block overlap others just before game over. I have modify this line on game.py-> draws function if self.block_fits() == True: self.current_block.draw(screen, 11, 11) to prevent it drawing on the screen. Anyway, this is still the best Python Tetris Tutorial I 've ever seen, Great job!
This was really easy to follow and fun to program! One thing I did after is adding a storage function like in modern Tetris games. You have a window on the right for which block you are storing (you can store e.g by pressing shift) and can replace your current block with that block. You can't replace a current block that you have stored though.
I love this tutorial sm. It's not one of those python tutorials where the guy just writes code and doesn't explain it, it's great that u taught us how the code and logic works 😁
Added a function to update the speed after reaching 2000 points and also level. Still have to work on the logic behind it because if the value modules is not equal 0 it doesn't update but if I search other it increases automatically. I moved the GAME_UPDATE to the game.py and added the code below to the update_score section if self.score % 2000 == 0: self.newSpeed = Game.update_speed(self.newSpeed) self.level += 1 if self.newSpeed > 50: pygame.time.set_timer(self.GAME_UPDATE, self.newSpeed) else: self.newSpeed = 50
Nick, your tutorials are quite unique and quite detailed, I love your videos man, I think it is much better than other similar projects on youtube, and I have a request : could you please make more of such python game or other python projects, it would be very fun to learn from you. 💯
This was honestly really fun to code, I'm currently trying to get in more practice for coding in Python and this was a nice side project to work on, hopefully you make more tutorials like this.
thank you so much for explaining the game logic with readable code, I was trying to code tetris in both C++ and python by myself, and I was struggling at the move rows down logic and clearing the rows logic, I felt like I was going insane, and most of the solutions on google searches are mostly magic values and unreadable code, witch it does not help at all, but your solution by far is the cleanest tetris code I've seen, it might take more code lines, but I do appreciate to be able to read all those class methods.
this was insanely helpful and helped me grasp a lot of concepts in python. Along with that, it also taught me how to approach different problems and how to implement them inside of python. Thank you so much!
Hello guys! I hope you enjoyed the video! There is an error in the code as it appears in the video. In the block.py file the undo_rotation method should be like this: def undo_rotation(self): self.rotation_state -= 1 if self.rotation_state == -1: self.rotation_state = len(self.cells) - 1 The error is fixed in the github repository. Sorry for this.
I was stuck in this error lol. I thought it had something to do with me writing it in JavaScript lol. I was panicking. Then I asked chat GPT and it solved it for me, but here was the answer all the time 🤣
i have found a new solution for undo method. for example, when rotating at the edge, it should rotate and move the block inside the screen. my code is: def rotate_block(self): self.current_block.rotate_block() while self.block_in_screen() == False: self.current_block.move(0,1) seems unnecessary but hope it helps
Excellent tutorial, these videos will serve as a bible for me to consult how to make many types of games. Thank you very much for sharing all this material.
Where using Visual Studio, in main.py game_grid = Grid() I wrote game_grid.print_grid(), and 'print_grid' appeared in the 'Grid' object. What should I do?
Hi, I found an error. If a block is in it's last rotation state and you try to rotate it when it's not possible then first the rotate function will set the rotation_state to 0 and next the undo_rotation function will decrease the rotation_state by 1, so the index of the dictionary will be -1 which will crash the game. The line in undo_rotation "self.rotation_state -= 1" should be after the if statement in else statement , not before. Besides that, the video is great! Much appreciated!
Good catch! You are absolutely right! I totaly missed it. I played the game for hours and never crashed. I looked over this piece of code of hours and never occured to me that the value can become negative. Thanks for sharing!
Now, that I recall me, programming this piece of code, I wanted the method to look like this: def undo_rotation(self): self.rotation_state -= 1 if self.rotation_state == -1: self.rotation_state = len(self.cells) - 1 which works. I messed up the if statement.
To avoid tis you could also use the mod4-methode: def rotate(self): self.rotation_state = (self.rotation_state+1)%4 def undo_rotate(self): self.rotation_state = (self.rotation_state-1)%4
Thank you Tim. Yes, it is a quite long video but it will definately help you understand the game mechanics of this ingenius game and a few more advanced programming practices.
Hello Nick big fan i am having some trouble with 29:33 with line 22 givingme an error which says -> AttributeError: 'Grid' object has no attribute 'draw' ive looked over atleast 100 times and all of my code is exact as it is on screen at this current time in the video i even completely rewrote all of main.py and grid.py any reason why this is? i am using sublime as well
Hi Great video, But i facing an error When move the blocks to left the boundary check is done correctly but when try to move it to the right it goes out of bound .Any reson why it might have occured
Thank you Nick. It is very helpful. I have a request to you, I do not want to start the game directly. First it gives the option to "Play Now" and when we enter , the game starts and at the end of the end , it should show a messege "Play Again". How do i do it? Please help in this Nick.
Hello Nick! When I tried running the code by the end of step 5 (moving the blocks) if press any of the 3 keys (move_left, move_right, move down) the program ends with an error saying that the " object 'Game' does not have an attribute "move_left" for example if i press the left key. I have already defined it in the game class same as your code. I don't know what to do I can't progress to step 6 as it cannot properly run and I cannot move the blocks. Thank you
FileNotFoundError: No file 'Sounds/rotate.ogg' found in working directory 'C:\Users\Packard bell\Desktop\Python Örneklerim'. Unfortunately, I received another error and my game is not working.
Hi, great tutorial... I´m doing this... however I´ve a problem... when I move the block to right, this one is left out by a rectangle. I print positions into the for of the get_cell_positions method and for LBlock in the initil position after moving evrything to the right the position are: (0,16)(1,16)(1,17)(1,18)...plopppp... Why the column are greater than 10?
continuosly showing this error to me -> in grid.py file under the def draw method pygame.draw.rect(screen , self.colors[cell_value] , cell_value) TypeError: rect argument is invalid also game screen is disappearing immediately but before making grid.py it was staying on the window unless i click the red cross... can you help me out real quick please!!!!
I keep running into this error This is for the grid.py return [dark_grey, green, red, orange, yellow, purple, cyan, blue] ^ IndentationError: unindent does not match any outer indentation level [Finished in 106ms]
sir, i have an error, when i tried to run, this appeared File "c:\Users\asus\Desktop\mencoba game2\main.py", line 29, in game.draw(screen) File "c:\Users\asus\Desktop\mencoba game2\game.py", line 43, in draw self.current_block.draw(screen) File "c:\Users\asus\Desktop\mencoba game2\block.py", line 29, in draw for tile in tiles: TypeError: 'method' object is not iterable do u have any suggestion?
if self.grid[row][column] == 0: ~~~~~~~~~^^^^^ IndexError: list index out of range First of all, it's a great example, I'm almost at the end of the game, but I can't get rid of this mistake, please help
Hello, thank you for this detailed tutorial for beginners. I just want to point out one thing, I have an error in 56:45: AttributeError: 'Tblock' object has no attribute 'column_offset' Can anyone please provide me with a solution because I have been stuck on this error for the past 15 minutes. Thank you dearly.
Hi. Just finnished the "Checking for Collisons" part of your video. Everything went great until I realized that if the user moves a piece into another piece from either left or right, it intertwines and locks in place. Do you have a fix for this? I'll continue on in the video in hope that maybe you also get this error. If not, hopefully you can get back to me. Thanks in advance!
Traceback (most recent call last): File "/Users/mac/PycharmProjects/gamee/r2.py", line 19, in blockk = LBlock() ^^^^^^^^ File "/Users/mac/PycharmProjects/gamee/blocks.py", line 7, in __init__ super().__init__(1) TypeError: Block.__init__() takes 1 positional argument but 2 were given I keep getting this error and i dont know how to fix it even though i wrote every single line as the video
I hope you took away lots from this video. Let me know below!
PS: I created a course named "Object Oriented Programming Made Easy"! Sign up at bit.ly/3NaMfg4. I think you will enjoy it!
What do you do when you have all the functions and the blocks are not responding to it? It is not rotating, moving left or right. In fact not responding to keyboard strokes in general?
I used print statements and noticed that the keystrokes were working but not changing the movement of the blocks.
There is still have a chance that the newly spawned block overlap others just before game over. I have modify this line on game.py-> draws function
if self.block_fits() == True:
self.current_block.draw(screen, 11, 11)
to prevent it drawing on the screen.
Anyway, this is still the best Python Tetris Tutorial I 've ever seen, Great job!
This was really easy to follow and fun to program! One thing I did after is adding a storage function like in modern Tetris games. You have a window on the right for which block you are storing (you can store e.g by pressing shift) and can replace your current block with that block. You can't replace a current block that you have stored though.
I love this tutorial sm. It's not one of those python tutorials where the guy just writes code and doesn't explain it, it's great that u taught us how the code and logic works 😁
Added a function to update the speed after reaching 2000 points and also level. Still have to work on the logic behind it because if the value modules is not equal 0 it doesn't update but if I search other it increases automatically. I moved the GAME_UPDATE to the game.py and added the code below to the update_score section
if self.score % 2000 == 0:
self.newSpeed = Game.update_speed(self.newSpeed)
self.level += 1
if self.newSpeed > 50:
pygame.time.set_timer(self.GAME_UPDATE, self.newSpeed)
else:
self.newSpeed = 50
def update_speed(current_speed):
current_speed -= 10
return current_speed
One of the best tutorials I have ever seen. A simple, to-the-point explanation ...................
Thank you for such a wonderful course
🙌🙌🙌
By far the best tutorial on OOP in Python, Pygame. Well done Nick, and thank you very much for all your work!
By far the best tutorial on OOP in Python, Pygame. Well done Nick, and thank you very much for all your work!
Wow, thanks!
I love how you go into detail with this video about the code, I just started python yesterday and I'm doing well because of you! Thank you!
Nick, your tutorials are quite unique and quite detailed, I love your videos man, I think it is much better than other similar projects on youtube, and I have a request : could you please make more of such python game or other python projects, it would be very fun to learn from you.
💯
This was honestly really fun to code, I'm currently trying to get in more practice for coding in Python and this was a nice side project to work on, hopefully you make more tutorials like this.
thank you so much for explaining the game logic with readable code, I was trying to code tetris in both C++ and python by myself, and I was struggling at the move rows down logic and clearing the rows logic, I felt like I was going insane, and most of the solutions on google searches are mostly magic values and unreadable code, witch it does not help at all, but your solution by far is the cleanest tetris code I've seen, it might take more code lines, but I do appreciate to be able to read all those class methods.
Thank you very much for your feedback!
Finally understood how object oriented programming works, thanks a lot!!
this was insanely helpful and helped me grasp a lot of concepts in python. Along with that, it also taught me how to approach different problems and how to implement them inside of python. Thank you so much!
Thank you, I learnt a lot and succeeded in making snake by myself after this video without any help
I really enjoyed working on this project alonside. Thank you! :D
Hello guys! I hope you enjoyed the video! There is an error in the code as it appears in the video. In the block.py file the undo_rotation method should be like this:
def undo_rotation(self):
self.rotation_state -= 1
if self.rotation_state == -1:
self.rotation_state = len(self.cells) - 1
The error is fixed in the github repository. Sorry for this.
I was stuck in the error but, then I decided to check on comments and here is the answer. kkk Tks
I'm now at the automatic droping part.
I was stuck in this error lol. I thought it had something to do with me writing it in JavaScript lol. I was panicking. Then I asked chat GPT and it solved it for me, but here was the answer all the time 🤣
Thanks for the fix! I suggest you pin this comment so it's easier to find. Loved the explanation and the attention to every detail.
I was just thinking this wasn't quite right and read down the comments :)
Great tutorial. Was able to do it and really happy with how it came out! Thanks
This tutorial was a really good starting point for my Tetris project. Thanks so much for the help!
You're very welcome!
i have found a new solution for undo method. for example, when rotating at the edge, it should rotate and move the block inside the screen.
my code is:
def rotate_block(self):
self.current_block.rotate_block()
while self.block_in_screen() == False:
self.current_block.move(0,1)
seems unnecessary but hope it helps
A very clear and complete tutorial. Thank you
In chapter "Rotate the blocks" , method rotate(self), second line - I think it should be: if self.rotation_state == len(self.cells) - 1.
you are the reason i passed my OPP assessment in com sci
I am very happy to hear that! Well done!
@@programmingwithnick thank you!!
Excellent tutorial, these videos will serve as a bible for me to consult how to make many types of games. Thank you very much for sharing all this material.
okay , i subbed and liked , i like this side of youtube
nice work dude!, now i can finish my college final tasks :)))
Glad I could help!
Great demo and fantastic code for this Tetris game. Thanks so much !
Thank you por making this amazing video. I've enjoyed it a lot.
Nice tutorial! Is there a way to make it so you can hold the down button and have the block move down continuously?
Cool tutorial but i can’t seem to make a python file. Its just not an option for some reason😢
Where using Visual Studio, in main.py game_grid = Grid()
I wrote game_grid.print_grid(), and 'print_grid' appeared in the 'Grid' object. What should I do?
Hi, I found an error. If a block is in it's last rotation state and you try to rotate it when it's not possible then first the rotate function will set the rotation_state to 0 and next the undo_rotation function will decrease the rotation_state by 1, so the index of the dictionary will be -1 which will crash the game. The line in undo_rotation "self.rotation_state -= 1" should be after the if statement in else statement , not before. Besides that, the video is great! Much appreciated!
Good catch! You are absolutely right! I totaly missed it. I played the game for hours and never crashed. I looked over this piece of code of hours and never occured to me that the value can become negative. Thanks for sharing!
Now, that I recall me, programming this piece of code, I wanted the method to look like this:
def undo_rotation(self):
self.rotation_state -= 1
if self.rotation_state == -1:
self.rotation_state = len(self.cells) - 1
which works. I messed up the if statement.
To avoid tis you could also use the mod4-methode:
def rotate(self):
self.rotation_state = (self.rotation_state+1)%4
def undo_rotate(self):
self.rotation_state = (self.rotation_state-1)%4
nice@@olssonolov
Much better, go from 3 lines to ONLY 1 line@@olssonolov
Great work Nick, it's quite detailed, I will have to watch it in small intervals to take it all in.👍😁👍
Thank you Tim. Yes, it is a quite long video but it will definately help you understand the game mechanics of this ingenius game and a few more advanced programming practices.
This is a fantastic tutorial. Thank you!
Hello Nick big fan i am having some trouble with 29:33 with line 22 givingme an error which says -> AttributeError: 'Grid' object has no attribute 'draw' ive looked over atleast 100 times and all of my code is exact as it is on screen at this current time in the video i even completely rewrote all of main.py and grid.py any reason why this is?
i am using sublime as well
Thank you for the video sir :)
Hi Great video, But i facing an error When move the blocks to left the boundary check is done correctly but when try to move it to the right it goes out of bound .Any reson why it might have occured
Amazing job!! Thank you very much. Could I use this code with my students, with the credit to your work and channel?
Yes, of course. This is why I make these videos. To help as many people as possible to learn programming.
@@programmingwithnick Thank you!!! Your teaching is fantastic and the code is very organized..
👏👏
Thank you Nick. It is very helpful. I have a request to you, I do not want to start the game directly. First it gives the option to "Play Now" and when we enter , the game starts and at the end of the end , it should show a messege "Play Again". How do i do it? Please help in this Nick.
Hi nick I have a problem whit the creating blocks
Can you help me?
Great video,we learn so much from this channel!
23:01 the color of the back ground which is dark blue doesn’t appear
and also the list of lists of zeros
i wrot the same code but nothing appears
Hello Nick! When I tried running the code by the end of step 5 (moving the blocks) if press any of the 3 keys (move_left, move_right, move down) the program ends with an error saying that the " object 'Game' does not have an attribute "move_left" for example if i press the left key. I have already defined it in the game class same as your code. I don't know what to do I can't progress to step 6 as it cannot properly run and I cannot move the blocks. Thank you
FileNotFoundError: No file 'Sounds/rotate.ogg' found in working directory 'C:\Users\Packard bell\Desktop\Python Örneklerim'.
Unfortunately, I received another error and my game is not working.
estas en el directorio incorrecto, ubicate en la carpeta en donde se encuentre el archio correspondiente
Great video, I really learned a lot! But I was wondering how I would implement a block holding feature?
I don't know why my blocks keep going (partially) out of the grid whenever I move them left or right.
I had the same issue. In game .py in function block_inside, unindent 'return True' once so it lines up with the for loop instead of the if statement
@@nicholasflint9480 thanks man, I was having the same problem. Thanks for the solution
Nice, love Tetris
WOWWY BOWWY WOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOW.
Your tutorial so perfecto.
😎Can you use images instead of colors? I partially managed it myself, but it doesn't work with current_block and next_block.
Please could someone show me how to do the Grid file import, I use pycharm, so the ctrl n and ctrl s thing didn't work. Thanks
Somehow there is an error for the sound code although I created a file called Sounds with the music you implemented in.
Hi, great tutorial... I´m doing this... however I´ve a problem... when I move the block to right, this one is left out by a rectangle. I print positions into the for of the get_cell_positions method and for LBlock in the initil position after moving evrything to the right the position are: (0,16)(1,16)(1,17)(1,18)...plopppp... Why the column are greater than 10?
solved...
continuosly showing this error to me ->
in grid.py file under the def draw method
pygame.draw.rect(screen , self.colors[cell_value] , cell_value)
TypeError: rect argument is invalid
also game screen is disappearing immediately but before making grid.py it was staying on the window unless i click the red cross...
can you help me out real quick please!!!!
I keep running into this error
This is for the grid.py
return [dark_grey, green, red, orange, yellow, purple, cyan, blue]
^
IndentationError: unindent does not match any outer indentation level
[Finished in 106ms]
cannot import name Grid form grid help please
heeeeeeeelp someone help me writing the codes in vs code and in line 13 it says "sys" not defined Pylance, is it normal?what should i do?
sir, i have an error, when i tried to run, this appeared
File "c:\Users\asus\Desktop\mencoba game2\main.py", line 29, in
game.draw(screen)
File "c:\Users\asus\Desktop\mencoba game2\game.py", line 43, in draw
self.current_block.draw(screen)
File "c:\Users\asus\Desktop\mencoba game2\block.py", line 29, in draw
for tile in tiles:
TypeError: 'method' object is not iterable
do u have any suggestion?
IN the block.py file you have an error. Check if you have place some () where it not needed. Check your code again very carefully.
Nick I wrote the same codes you wrote but nothing appears on the screen if the game ,even the screan cames quickly and dissappears ,what should i do
Make sure you have your lines of code lined up
Mine has a problem where after 7 blocks have landed another block doesn't spawn. Any idea what might be wrong?
Maybe you have forgotten to recreate the blocks list. Give it a check.
Thank you!!!!
if self.grid[row][column] == 0:
~~~~~~~~~^^^^^
IndexError: list index out of range
First of all, it's a great example, I'm almost at the end of the game, but I can't get rid of this mistake, please help
I am a newb to coding. How do I add a hard drop if the space bar is hit in this code? If anyone is able to help I would appreciate it
What software did you use to code?
Sublime text
Hello, thank you for this detailed tutorial for beginners. I just want to point out one thing, I have an error in 56:45:
AttributeError: 'Tblock' object has no attribute 'column_offset'
Can anyone please provide me with a solution because I have been stuck on this error for the past 15 minutes.
Thank you dearly.
(btw I am using VScode which may differ, thank you.)
absolutely amazing
Thank you!
Array are used?
thanksyou
Hi. Just finnished the "Checking for Collisons" part of your video. Everything went great until I realized that if the user moves a piece into another piece from either left or right, it intertwines and locks in place. Do you have a fix for this? I'll continue on in the video in hope that maybe you also get this error. If not, hopefully you can get back to me. Thanks in advance!
I fix this problem in the video in the Checking for Collisons chapter. Are you sure you finished watching it?
@@programmingwithnick Hi, you are correct. Seems I ran into the problem and stopped paying attention to you explaining the fix. Thanks for the help.
Traceback (most recent call last):
File "/Users/mac/PycharmProjects/gamee/r2.py", line 19, in
blockk = LBlock()
^^^^^^^^
File "/Users/mac/PycharmProjects/gamee/blocks.py", line 7, in __init__
super().__init__(1)
TypeError: Block.__init__() takes 1 positional argument but 2 were given
I keep getting this error and i dont know how to fix it even though i wrote every single line as the video
It says sys is not defined
when I try to import grid from Grid it gives me import error
check for spelling mistakes
same
watch with 1.25x speed, thank me later
I am watching in 1.5x 😂
😎
Please share the Source code of this game
Please check the video description.
he tell me the attribute print_grid isnt exist
very hard tutorial
Thank you @DaCom3AK
by the time i got to 49:37 i got an error at blocks.py
Block.__init__() got an unexpected keyword argument 'id'
heres the code:
from block import Block
from position import Position
class LBlock(Block):
def __init__(self):
super().__init__(id = 1)
self.cells = {
0: [Position(0, 2), Position(1, 0), Position(1, 1), Position(1, 2)],
1: [Position(0, 1), Position(1, 1), Position(2, 1), Position(2, 2)],
2: [Position(1, 0), Position(1, 1), Position(1, 2), Position(2, 0)],
3: [Position(0, 0), Position(0, 1), Position(1, 1), Position(2, 1)]
}
can anyone help?
Have you solved the problem yet?
here i am learning python after making a tetris game in c
Nice.....i would like to know how you handled the rotation of the shapes....i want to design same using C++....
Thanks in advance