Learning Pygame by making Pong

  Рет қаралды 206,656

Clear Code

Clear Code

Күн бұрын

A fairly simple Pong game to help you learn the basics of Pygame. We will talk about the fundamentals of Pygame and then incrementally add more elements.
Files can be found at:
github.com/cle...

Пікірлер: 416
@essayprometheus
@essayprometheus 4 жыл бұрын
honestly, its these small coding channels that provide the most useful information, especially to self learning coders like me. Props to u!
@NavjotSingh-zx3we
@NavjotSingh-zx3we 3 жыл бұрын
i am with yo
@A6h4v
@A6h4v 3 жыл бұрын
@@NavjotSingh-zx3we reply to a reply
@A6h4v
@A6h4v 3 жыл бұрын
GELOMILF
@ifergff2280
@ifergff2280 3 жыл бұрын
U are not alone, we all are here👍👍
@mimic_ed
@mimic_ed 2 ай бұрын
It's not small anymore🎉
@Tila1
@Tila1 4 жыл бұрын
0:18 Installing Pygame 0:51 How Pygame works 5:37 Drawing 13:26 Animations 20:24 Input 24:27 Opponent 'AI' 25:47 Basic Scoring
@muhammadanas7698
@muhammadanas7698 3 жыл бұрын
Thanks
@TN3.1
@TN3.1 Жыл бұрын
That was really helpful. I knew how to make basics but i mainly needed to learn animation and opponent AI. Thank you very much!
@Harry-ub2fv
@Harry-ub2fv 4 жыл бұрын
To be honest, I've read the book 'Beginning Game Development with Python and Pygame (2007)', but this man accurately and more clearly explained all of that in just 4 videos that too in a concise manner. Thanks a lot. You are awesome.man()
@enderman-minecraftmonsters8249
@enderman-minecraftmonsters8249 Жыл бұрын
the function at the end really completed it lol
@yusufnusrat
@yusufnusrat 3 жыл бұрын
i am just 2 mins in and so many information that nobody would say that. thanks a lot this really helped me. never know why small channels are always most helpful
@shantanubindhani1622
@shantanubindhani1622 4 жыл бұрын
Your Chanel deserves to grow!.... You content is so awesome to understand, it has good clarity, you make the learning seems easy.. Greatly looking forward for new uploads
@akshhat97
@akshhat97 4 жыл бұрын
This was so crisp and clear. I've seen other tutorials where they just guide you through the code without explaining the underlying concepts but this was definitely what I needed. Thanks!
@diegocruz8187
@diegocruz8187 3 жыл бұрын
I've been watching your tutorials for a while and you are simply amazing!! Really, you can't imagine how helpful your channel has been for me.
@lousimms4766
@lousimms4766 4 жыл бұрын
I hope you make more videos, was struggling with pygame trying stuff on my own just reading the documentation but was sooo off with rect collisions, this explained it perfectly!
@ClearCode
@ClearCode 4 жыл бұрын
Thank you, glad it helped :) check out my channel, I already made lots more pygame tutorials
@abrarmasumabir3809
@abrarmasumabir3809 3 жыл бұрын
This guy is so clear...he definitely deserves million of subscribers
@elib7911
@elib7911 4 жыл бұрын
Thanks so much man, I'm a 3rd-year student in college learning computer science. I am very interested in game development/coding and this helped a lot. Hope you make more :)
@rajab4187
@rajab4187 4 жыл бұрын
I'm in 2nd year I'm into web development (front. End) N PyGame too Hope will go any of these twos route Before I mess up in ma mind
@alooooshm
@alooooshm 4 жыл бұрын
you truly live up to your channel name. clear coding indeed! honestly, if I could give you more than one like I would. please keep it up and if you could cover some AI topics and applications that would be amazing
@rebornreaper194
@rebornreaper194 3 жыл бұрын
Your presentation style is incredibly intuitive, tysm :D
@dolphinman9802
@dolphinman9802 2 жыл бұрын
Awesome video! You walked through it all really well and it was easy to follow along to. One change i made to the code though, that made the AI smarter, is i changed the opponent_ai function to compare the opponent center y with the ball instead of opponent bottom and opponent top respectively. This made it so the opponent tried to align its middle with the ball instead of its bottom/top. def opponent_ai(): if opponent.centery < ball.y: opponent.centery += opponent_speed if opponent.centery > ball.y: opponent.centery -= opponent_speed if opponent.top = screen_height: opponent.bottom = screen_height
@AC-he8ln
@AC-he8ln Жыл бұрын
I think these Pong videos are the best starting Pygame starting series on KZbin. The others are also good but too complex for a first project.
@knightmare6249
@knightmare6249 4 жыл бұрын
Actually an amazing tutorial, I'm amazed by how you were able to explain the code line by line. Thank you.
@knightmare6249
@knightmare6249 4 жыл бұрын
btw who are the six people that disliked this lol
@yassinezanned9837
@yassinezanned9837 3 жыл бұрын
Astonishing simplicity and amazing content from your part, sir. Thanks really much.
@shourya9998
@shourya9998 4 жыл бұрын
Best tutorial video I've ever seen! Hats off to this guy
@knull8508
@knull8508 3 жыл бұрын
your explanation is so clear this is amazing !
@paradoxicalinsomniac9950
@paradoxicalinsomniac9950 4 жыл бұрын
this is the best python tutorial i've ever seen in my life
@rajab4187
@rajab4187 4 жыл бұрын
It's PyGame
@aidan5077
@aidan5077 4 жыл бұрын
Just made this after watching your flappy bird video. These tutorials are incredible
@Schachlover
@Schachlover 4 жыл бұрын
Best explained tutorial ever. U R really a gifted teacher. Wish I had found something similar when I started. Please keep up the good work. Best wishes from D. R.
@ClearCode
@ClearCode 4 жыл бұрын
Thank you so much 🙂
@Schachlover
@Schachlover 4 жыл бұрын
Could you please make a tutorial on string manipulation ; let's say, moving text on the screen using Python or better pygame? Thanks in advance.
@todd3578
@todd3578 4 жыл бұрын
This video is amazing, you really know how to explain the code!
@ismailaminu9826
@ismailaminu9826 4 жыл бұрын
Do you know what software he was using?
@xadas5230
@xadas5230 4 жыл бұрын
I just had the urge to write this comment, and compliment you for doing those type of videos, as a beginner/intermediate programmer this really helps me to understand pygame better. Thanks for your work, looking forward to more videos of yours.
@jivinhipcat
@jivinhipcat 4 жыл бұрын
I wish all videos were this good. Thanks for it man.
@michaelshuvalov9100
@michaelshuvalov9100 4 жыл бұрын
Amazing clarity, someone who clearly not only knows how to execute the code, but has a thorough understanding in it. "If you can't explain it simply, you don't understand it well enough." - Mr Einstein
@ClearCode
@ClearCode 4 жыл бұрын
Thank you!
@thepaulcraft957
@thepaulcraft957 3 жыл бұрын
Mr Einstein's words in German "Wenn du es nicht simpel erklären kannst, hast du es nicht gut genug verstanden."
@kaneki_ken_07
@kaneki_ken_07 3 жыл бұрын
@@thepaulcraft957 Thats because Einstien's German, Yeah..!!
@yuka8286
@yuka8286 2 жыл бұрын
@@kaneki_ken_07 Einstein's dying wish was to be referred to as "A rock", other than "The rock" as we all know as Dwayne "The Rock" Johnson, "A rock" in German is "Ein Stein". A singular rock can make a difference, we should respect that.
@kaneki_ken_07
@kaneki_ken_07 2 жыл бұрын
@@yuka8286 Well, there was some other conversation going on and I see some comments are deleted. So, I think you didn't understand the topic because of deleted comments.
@gamedog123games
@gamedog123games Жыл бұрын
I've been trying to make a game without an engine (yet my brain stops working when I open VSCode) and this was a lifesaver and helped me start out with a small project
@chigstardan7285
@chigstardan7285 3 жыл бұрын
This is one of the best tutorials ive ever seen and the clarity is.... Muah. Keep up the good work
@semajislove2353
@semajislove2353 4 жыл бұрын
My first Python project, thank you very much, Good Sir!
@ClearCode
@ClearCode 4 жыл бұрын
You're welcome and glad you liked it :) I made lots more pygame tutorials and I will make a video on a much better pong game in about a week!
@TypeZ3R0
@TypeZ3R0 3 жыл бұрын
BEST EVER EXPLANATION FOR PROGRAMMING. PLZ MAKE VIDEOS ON PYTHON MACHINE LEARNING, DEEPLEARNING AND COMPUTER VISION WITH PYTHON🙏🏽🙏🏽
@David-fq5un
@David-fq5un 6 ай бұрын
great explanation...hate other tutorials that just try to have you copy their code without explanation
@Oxim1nus
@Oxim1nus 2 жыл бұрын
Really helpful and very well explained, i did this and some of your other tutorial-projects and it's a great way to learn, please keep going with the great job
@structuralcraft
@structuralcraft 2 жыл бұрын
Your teaching outline is good to begin with
@synthoelectro
@synthoelectro 3 жыл бұрын
This guy has a personality, that's a good thing.
@polyeder2000
@polyeder2000 3 жыл бұрын
To solve the problem with keydown: Use keys = pygame.key.get_pressed() if keys[pygame.K_w]: This way the player will move as long as the key (w in this case) is held down. Do this after checking for events (and don't check the movement keys in the events section.)
@jefhamish
@jefhamish 2 жыл бұрын
With this method, my player's speed seems inconsistent and/or slower than it should be as if for some frames it's missing that the button is held down.
@davependrell6653
@davependrell6653 4 жыл бұрын
Awesome tutorial video. Your transitions and animations are super nice as well.
@parthgupta4850
@parthgupta4850 4 жыл бұрын
you are greAt ! a wonderful experience thanks a lot a different from all the other videos (a straight to the point video with clear concepts) really thanku *now I got to know what power does coding has*
@AbhishekKumar-dq1dr
@AbhishekKumar-dq1dr 3 жыл бұрын
I am having python 3.7.0 version on my mac. So will it work after installing pi game using terminal to make the pong game? Please reply fast
@atirekmanidiggal5140
@atirekmanidiggal5140 3 жыл бұрын
Yes please tell
@kaberanshutisamuel1856
@kaberanshutisamuel1856 8 ай бұрын
how I learned this is hilarious, I first followed along tutorial and then the nextday i tried to do it without tutorial and comeback for where I am stuck, the funny thing I am very understanding it for the second time
@imherovirat
@imherovirat 3 жыл бұрын
Subscribed, awesome, perfect,wonderful and really understandable, Thank you Clear Code for this amazing Content.
@mitchellfolbe8729
@mitchellfolbe8729 4 жыл бұрын
Good exercise with good explanation. Thank you.
@rezashir3873
@rezashir3873 Жыл бұрын
actually im zero in programing. i like to become hero in programing, like you. thank you
@qashrina4402
@qashrina4402 4 жыл бұрын
Your explanations are so clear!! Thank you so much.
@0x656e
@0x656e 4 жыл бұрын
That was a really great video thank you very much for making this great video.
@hariharanm6705
@hariharanm6705 4 жыл бұрын
No words to appreciate Clear Code. Is this a teamwork or all are done by yourself?
@ClearCode
@ClearCode 4 жыл бұрын
hey, yes I am making it by myself (looks much harder than it actually is tbh)
@lucasreingo
@lucasreingo 3 жыл бұрын
Thanks so much for this pog tutorial. Also if you want to make the AI a bit better in the opponent_ai function instead of opponent.top < ball.y:, you can use opponent.centery. This is more efficient as it checks if the ball is lower or higher than the center of the opponent Rect.
@IGOverkill
@IGOverkill 2 жыл бұрын
thanks it really made the program better but you also need to replace ' opponent.bottom ' with 'opponent.centerx'
@lucasreingo
@lucasreingo 2 жыл бұрын
@@IGOverkill yh, soz I forgot that. Good luck on your pygame journey
@kogulansaravanabawan2034
@kogulansaravanabawan2034 2 жыл бұрын
Very use full sir! And please tell me how to create this game for mobile phones!
@sudiptobusiness1503
@sudiptobusiness1503 2 жыл бұрын
Your explanation is so clear..
@freadbear9645
@freadbear9645 Жыл бұрын
This was the first game I learned to make from scratch
@mohammedsaad3801
@mohammedsaad3801 3 жыл бұрын
yup dude u explaain well which is why I also bought ur udemy classes I saw u on it and thanks for the great content
@thelife8836
@thelife8836 Жыл бұрын
You are the best brother❤
@MrFeivelinho
@MrFeivelinho 4 жыл бұрын
Easily one of the best tutorials on coding i have seen so far. Does anybody know how difficult it would be to add multiplayer (via internet) to the game?
@rajab4187
@rajab4187 4 жыл бұрын
APIs
@gdd9866
@gdd9866 Жыл бұрын
Amazing and well explained.
@dungngoquang8354
@dungngoquang8354 7 ай бұрын
very useful, thank you so much!!!!
@pcslowhand
@pcslowhand 4 жыл бұрын
Thanks very much for this video. It was really helpful :)
@muradpetrosyan5128
@muradpetrosyan5128 4 жыл бұрын
The best tutorial for PyGame
@ScoobyYTP
@ScoobyYTP Жыл бұрын
The ball_animations function does not allow the player and opponent variables to operate correctly. As far as the computer is concerned, those variables only exist outside of this function. How do you go about solving this issue?
@saadedi75
@saadedi75 2 жыл бұрын
thanks for all video
@lorendaoust4443
@lorendaoust4443 10 ай бұрын
Thanks for this tutorial. Having absolutely no code experience, I was able to follow along and get a game working with some small changes so I have two players. I used ai to add a score game ender and mouse control - like I said, no code experience. I am hoping to use this for a setup using two bicycles mounted on a frame that control the paddle movement. I have a working prototype now. The only thing I'd like to add is changing the ball graphic to a small pixel graphic of the grinch's face. Is this a possibility? Could you point me in the right direction to look if it is? Thanks for this again.
@latviesupidari2103
@latviesupidari2103 2 жыл бұрын
For player movement, I found it easier to put this code inside the While loop instead of For loop: keys = pygame.key.get_pressed() if keys[pygame.K_UP]: player.y -= 7 if keys[pygame.K_DOWN]: player.y += 7
@edwardchen4447
@edwardchen4447 4 жыл бұрын
How do you not have like a million subs? just a question, HOW!?
@hariharanm6705
@hariharanm6705 4 жыл бұрын
I think it is a new channel
@magoninhogamer
@magoninhogamer 4 жыл бұрын
finally a good pygame tutorial
@ClearCode
@ClearCode 4 жыл бұрын
Thanks, I actually made quite a few by now :)
@magoninhogamer
@magoninhogamer 4 жыл бұрын
@@ClearCode awesome! you deserve more attention :D
@swiftal8312
@swiftal8312 3 жыл бұрын
Your the best, i watched someone else and he made my pygame so it looked blocky and 30 fps. But with your vid its smooooooooth
@zhankam7308
@zhankam7308 2 жыл бұрын
thanks for the video, but I have an error in PowerShell at the beginning
@janl5242
@janl5242 Жыл бұрын
Great stuff, thanks :)
@vedantpandey4079
@vedantpandey4079 2 жыл бұрын
Hey, awesome tutorial, keep up the good work! One very minor error, at 17:41 it says "Colissions" instead of "Collisions".
@jurkokubik6383
@jurkokubik6383 4 жыл бұрын
this was a really good tutorial!
@abhalera
@abhalera 4 жыл бұрын
Very nicely explained. Thanks
@madhavkrishna4579
@madhavkrishna4579 3 жыл бұрын
where do i get this code as i wanted to work on this
@abdelrahmanabbas4414
@abdelrahmanabbas4414 4 жыл бұрын
Module 'pygame' has no 'init' member Can you help me with this, please?
@ekimosos281
@ekimosos281 4 жыл бұрын
can i see full error
@conorhogan6111
@conorhogan6111 3 жыл бұрын
Why does ball_speed_x and ball_speed_y have to be included as global variables in ball_animation, but player_speed not have to be included in player_movement?
@MikaelL
@MikaelL 2 жыл бұрын
Good tutorial
@joeyh2185
@joeyh2185 2 жыл бұрын
very well made and helpful :) cheers mate
@Sharky_0456
@Sharky_0456 3 жыл бұрын
thanks! this was my first project so i had a lot of bugs but it was really fun! i will do part 2 soon!
@seamusstinson62
@seamusstinson62 4 жыл бұрын
Hey, Thanks for the video. I have a question about the code though. Why does ball_speed_x and ball_speed_y need to be global but player_speed doesnt need to be global?
@ClearCode
@ClearCode 4 жыл бұрын
When using the player_speed variable it is only used by the player_animation function, the function does not change the value (so if you wanted to change the speed of the player from the function you would need to declare it a global variable. Both the ball_speed variables change the variable from within the function; i.e. you are trying to change a global variable from a local scope. Hope that makes sense :)
@seamusstinson62
@seamusstinson62 4 жыл бұрын
@@ClearCode Yeah that makes sense. Thanks very much
@riya6549
@riya6549 Жыл бұрын
can someone explain to me why we needed to increment player _speed at every loop when the key is pressed down instead of directly incrementing the y coordinates of player when the same happens?
@heysiri_official
@heysiri_official Жыл бұрын
He explain it at 21:25
@riya6549
@riya6549 Жыл бұрын
@@heysiri_official yeah, i know he mentioned it...but i still couldn't get why exactly. A little expansion would help
@alsoalpha9162
@alsoalpha9162 4 жыл бұрын
should this work in repl.it? cause im trying to do it on there (my computer just doesnt want to recognize that pygame is downloaded so i have to use something online) and i am only getting like the top left quadrant of the screen.
@ClearCode
@ClearCode 4 жыл бұрын
So repl does support pygame but I am not sure how large of a window it supports. Maybe try different window sizes and see what fits. Are you getting an error message for pygame on your computer?
@alsoalpha9162
@alsoalpha9162 4 жыл бұрын
@@ClearCode i am getting an error message saying that no setup file exists (i have a screenshot of the whole error message) and also i have not thought about if replit only supports a certain size window, thanks!
@erremazo
@erremazo 3 жыл бұрын
Excelent video, thanks a lot.
@iohellemans3280
@iohellemans3280 2 жыл бұрын
great tutorial, loved it
@kostaskoukos3932
@kostaskoukos3932 3 жыл бұрын
for some reason I have written the code properly but when i press the arrow keys it doesn't always register it and I thought it was a matter of multiplying with deltatime but it still doesn't work. Can someone help?
@roandejager8534
@roandejager8534 Жыл бұрын
Very good
@mr.blobfish5535
@mr.blobfish5535 Жыл бұрын
sympathisch. Man kann sich unterhalten.
@A6h4v
@A6h4v 3 жыл бұрын
If you u want a big nice screen in a laptop use - 1000 width and use 700 height
@mr__aathithya
@mr__aathithya 2 жыл бұрын
For me arrow keys is not moving it. I am using a laptop do I have to change something?
@stolimoli
@stolimoli 2 ай бұрын
Why didn't you have to declare global variables for the player movement like you had to for the ball movement?
@toxxicdutchie232
@toxxicdutchie232 4 жыл бұрын
When I started code I was told don't use python its slow so I used python because honestly it looked straight forward and I had messed with some more complicated languages that I ddin't really understand and now I just love python. Then I was looking at things and I was told tkinter really wasnt great but it was something but under no circumstance should I use PyGame but here we are.
@sooriyashankar2776
@sooriyashankar2776 4 жыл бұрын
Hey! I really gained a lots of information. CAN YOU PL GUIDE ME HOW TO ADD SOUND EFFECTS AND TIMER???
@ClearCode
@ClearCode 4 жыл бұрын
Glad you like it! and check out my channel, I made a couple of sequels for this game and timers and sound effects are covered there.
@iumair_mehmood
@iumair_mehmood 3 жыл бұрын
which IDE is used in this video ?
@fernandoalmer3312
@fernandoalmer3312 9 ай бұрын
Yo i set the ball speed to 1, but it's still too fast when i run it, but when i set it to 0.5 or .5, it doesn't move, any solution? Edit: and also when i grouped the ball animation, it doesnt even open the game
@silverseacow
@silverseacow Жыл бұрын
18:46 Like cant we also add arguments, ballxspeed and ballyspeed for the function ball_animation() instead of global variables
@Sharky_0456
@Sharky_0456 3 жыл бұрын
what are you using? raw python doesnt have those suggestions.
@snxphy
@snxphy 3 жыл бұрын
the code is word for word yet my paddle just drops to the ground and i dont understand why, any help?
@seyd
@seyd 3 жыл бұрын
Help! it says error: File "F:\PythonSachen\Scripts\PongPy\Pongpy.py", line 28, in opponent_ai if opponent.top < ball.y: UnboundLocalError: local variable 'opponent' referenced before assignment
@srininja
@srininja 2 жыл бұрын
This tutorial is so good, and I'm so exited i haven't played the game yet, but i have a question. The height is too big that the window goes out of my computer screen. I've changed the width and height to make it smaller, but i have a feeling it won't work. Can you give me a better solution if you have one? Thank you for the tutorial
@leobozkir5425
@leobozkir5425 4 жыл бұрын
I>>> SIMPLY>>> LOVE>>> IT>>>
@jarkk0896
@jarkk0896 2 жыл бұрын
can i do to opponent as 2player like he can control anotehr pad with like wasd
@scfs2.0
@scfs2.0 3 жыл бұрын
When i run the code I don’t get any window pops up
@duckperson5533
@duckperson5533 2 жыл бұрын
0:49 For me it says: No module named pygame, even after installing it again.
@adarshkhatri993
@adarshkhatri993 3 жыл бұрын
Rather your channel name(Clear Code) specifies your coding skills 😊
@demonlord3375
@demonlord3375 3 жыл бұрын
My restart command is not working any suggestions
@georgeperson8917
@georgeperson8917 Жыл бұрын
the tutorial is great and i followed it, but when i finished the colors for everything and i ran it,it just shown a black screen,i am on linux so if anyone could help me i would be very thankfull
I made Games with Python for 10 Years...
28:52
DaFluffyPotato
Рет қаралды 337 М.
ПРИКОЛЫ НАД БРАТОМ #shorts
00:23
Паша Осадчий
Рет қаралды 6 МЛН
Incredible: Teacher builds airplane to teach kids behavior! #shorts
00:32
Fabiosa Stories
Рет қаралды 10 МЛН
Шок. Никокадо Авокадо похудел на 110 кг
00:44
C++ Developer Learns Python
9:26
PolyMars
Рет қаралды 2,7 МЛН
Should you learn C++?? | Prime Reacts
20:29
ThePrimeTime
Рет қаралды 366 М.
Running "Hello World!" in 10 FORBIDDEN Programming Languages
18:07
Can Dangerous Saw Blades Cut Wood?
25:34
Waterjet Channel
Рет қаралды 8 М.
Making a Game in Python with No Experience
5:57
Goodgis
Рет қаралды 1,7 МЛН
CONCURRENCY IS NOT WHAT YOU THINK
16:59
Core Dumped
Рет қаралды 100 М.
I Built the Pyramids in LEGO!
16:08
Brick Science
Рет қаралды 28 М.
Cameras in Pygame
1:13:21
Clear Code
Рет қаралды 120 М.
What if a glass of water were LITERALLY half empty?
4:20
xkcd's What If?
Рет қаралды 893 М.
ПРИКОЛЫ НАД БРАТОМ #shorts
00:23
Паша Осадчий
Рет қаралды 6 МЛН