Creating Tetris in Python with pygame - Beginner Tutorial (OOP)

preview_player
Показать описание
🎮💻 Build the classic game Tetris in less than two hours with Python and Pygame! 🔥 Follow along as we code and create colorful shapes that will challenge your skills. 🚀 With step-by-step instructions and engaging graphics, this tutorial is perfect for beginners and experienced coders alike. 🤓 Join me on this fun and exciting journey of game development! 💯

Become a member to this YouTube channel to enjoy perks:

Previous Tutorials (Watch in the following order)

#pygame #python #tetrisgame #gamedev #tutorial

00:00 Intro to Tetris tutorial
01:06 Why build Tetris?
04:30 Install pygame-ce
06:14 Setup the Game Loop
16:09 Creating the Grid
32:15 Create the Blocks
51:51 Move the Blocks
1:10:43 Rotate the Blocks
1:14:31 Checking for collisions
1:24:44 Check for completed rows
1:32:03 Game Over
1:35:48 Create the User Interface
1:45:54 Add Score
1:51:25 Add Next Block
1:54:19 Adding Sound
Рекомендации по теме
Комментарии
Автор

I hope you took away lots from this video. Let me know below!
PS: I'm creating an OOP course! Sign up at for early access and a 50% launch discount.

programmingwithnick
Автор

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.

programmingwithnick
Автор

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.

DandaMan
Автор

By far the best tutorial on OOP in Python, Pygame. Well done Nick, and thank you very much for all your work!

ericleboullenger
Автор

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!

andgelerieee
Автор

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.

paulotrano
Автор

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.
💯

shravanpanchal
Автор

Finally understood how object oriented programming works, thanks a lot!! <33
Also got to show this to my course teacher that asked us to make a little game

Flanx-ulhj
Автор

Thank you, I learnt a lot and succeeded in making snake by myself after this video without any help

antoinesadarnac
Автор

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!

neomatrix-
Автор

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.

commandprompt
Автор

watch with 1.25x speed, thank me later

DaComAK
Автор

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 =
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

Wayko
Автор

I really enjoyed working on this project alonside. Thank you! :D

thegrayfox
Автор

This tutorial was a really good starting point for my Tetris project. Thanks so much for the help!

claireoneill
Автор

okay, i subbed and liked, i like this side of youtube

freesoftwares
Автор

A very clear and complete tutorial. Thank you

gianmarcoferraro
Автор

Great demo and fantastic code for this Tetris game. Thanks so much !

paulthomas
Автор

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.

manuelgarciagarcia
Автор

Thank you por making this amazing video. I've enjoyed it a lot.

manoloexplaintome