Тёмный

Make Pong With Python! 

Tech With Tim
Подписаться 1,5 млн
Просмотров 113 тыс.
50% 1

Welcome back to another video! In todays video I am going to be showing you how to make the famous game of Pong in Python! This is a great project for beginner or intermediate programmers. A lot of what we need to code out is the logic led to moving the ball around and having it bounce off the different paddles and implementing the score. If you are not, say an expert Python programmer already, you're going to learn a lot from this project!
💻 Thanks to BackTrace for sponsoring this video! Build better games with less bugs today for FREE by signing up for a developer account: hubs.la/Q012hTT00
💻 ProgrammingExpert is the best platform to learn how to code and become a software engineer as fast as possible! Check it out here: programmingexpert.io/tim and use code "tim" for a discount!
Code In This Video: github.com/techwithtim/Pong-P...
Fix Pip (Windows): • How to Install Pygame ...
Fix Pip (Mac): • How to Install Pygame ...
⭐️ Timestamps ⭐️
00:00:00 | Overview
00:00:48 | Pong Demo
00:01:40 | Sponsor
00:02:38 | Pygame Install
00:04:16 | Pygame Setup
00:12:57 | Creating The Paddles
00:21:28 | Moving The Paddles
00:32:14 | Creating The Ball
00:35:52 | Moving The Ball
00:39:07 | Handling Collision
00:58:54 | Implementing Score
01:06:33 | Winning The Game
01:11:38 | Conclusion
◼️◼️◼️◼️◼️◼️◼️◼️◼️◼️◼️◼️◼️◼️
👕 Merchandise: teespring.com/stores/tech-wit...
📸 Instagram: / tech_with_tim
📱 Twitter: / techwithtimm
⭐ Discord: / discord
📝 LinkedIn: / tim-ruscica-82631b179
🌎 Website: techwithtim.net
📂 GitHub: github.com/techwithtim
🔊 Podcast: anchor.fm/tech-with-tim
🎬 My RU-vid Gear: www.techwithtim.net/gear/
💵 One-Time Donations: www.paypal.com/donate?hosted_...
💰 Patreon: / techwithtim
◼️◼️◼️◼️◼️◼️◼️◼️◼️◼️◼️◼️◼️◼️
⭐️ Tags ⭐️
-Tech With Tim
-Pong With Python
-How to Make Pong
-Programming Pong
-Coding Pong in Python
⭐️ Hashtags ⭐️
#TechWithTim #Python #Pong

Опубликовано:

 

29 июн 2024

Поделиться:

Ссылка:

Скачать:

Готовим ссылку...

Добавить в:

Мой плейлист
Посмотреть позже
Комментарии : 155   
@wearegeek
@wearegeek 2 года назад
Hey Tim. I just recently discovered your channel and I must say I'm very impressed with your hands on tutorials. I'm working for a non-profit organization that helps people with a psychiatric background to rehabilitate. A lot of the participants show an interest in programming and your content is very helpful to explore this. Well explained; bite sized; project based. Thanks man!
@ivanmironov599
@ivanmironov599 Год назад
*Hey, Tim. *Thanks, man!
@nextgodlevel4056
@nextgodlevel4056 2 года назад
I am following you since you just have 10k subs and I am very happy to see your growth and Keep doing this kind of work.
@user-do3pd1sk6c
@user-do3pd1sk6c 2 года назад
I've missed your pygame tutorials! I find your tutorials interesting and especially the pygame ones since I started programming by making simple games, and now I'm learning pygame, so good job
@jakemasters4361
@jakemasters4361 2 года назад
Hey man, I don't comment too often but I felt the need to express my gratitude for all the great content. I studied C# years ago, loved it but got pigeon holed doing helpdesk work for 7 years and pretty much forgetting everything I'd learned. Almost a decade later I'm picking back up where I left off, discovering my passion again, and trying to get my foot in the development door professionally. Your channel has been a godsend. You have a natural talent for teaching and presenting information in a way that's easy to grasp. I've never been the type who learns much from just watching lectures. The guided tutorial format has always been best for me, and you've got some of the best I've been able to find. All the best!
@Lahmeinthehouse
@Lahmeinthehouse 2 года назад
Hey Tim! Great video, just one tip: Did you know that you can place the mouse location at multiple places AND do the exact same commands? So if you want to change left_paddle , left_paddle and change that directly to right, you can hold CTRL, click at the end of the words in BOTH variables, backspace and then write Right. This makes you able to change and write the same thing multiple places.
@Alk0h0liX
@Alk0h0liX 2 года назад
Hey Tim - thanks a lot for your amazing videos! I just started coding/Python two months ago and you helped me so much already. Always thought, that coding is something I am not able to do, because during study it was just horribly boring, but you definetely helped to show me, that coding is a lot of fun, a lot of thinking and a lot of "sense of archievement", if everything works in the end. An AI-pong video would be great by the way! I am just now trying something similar with "Brick Breaker" and I am kind of stuck :D
@junealexissantos4341
@junealexissantos4341 2 года назад
Tim, you are the best. I'm just a python beginner and I understand everything you taught here. Keep these kind of content going man. You're a legend.
@olesmor72
@olesmor72 2 года назад
Thank you very much for this super tutorial! You are a very good teacher and I managed to learn a lot of useful things . Now I feel confident enough to try making something on my own.
@jamesstone8988
@jamesstone8988 2 года назад
Awesome tutorial and clear explanations! Especially appreciated how to "solve for" with the equation :) Thanks!
@karpagambaskar6608
@karpagambaskar6608 2 года назад
Love your videos tim. Congrats on 900k. Just 100k more and you'll reach the glorious 1000000. Your videos are great tim keep It up
@tntredstone
@tntredstone 2 года назад
golden programming play button
@MeLoveCH3DDER
@MeLoveCH3DDER 11 месяцев назад
Thank you very much Tim for this tutorial for just this pong game. I am a beginner in pygame coding so this really helped me a lot and I appreciate it. Keep it up Tim
@salimmohammed1016
@salimmohammed1016 7 месяцев назад
Hey Tim. I dont have programming background except for seeing a few videos on python. I had visual studio code on my pc. I saw the first few minutes of the video and I installed pygame using the code given and then copy-pasted the code you attached and now I am playing ping on my pc. I am done within 10 minutes. Thanks a lot.
@myhatmygandhi6217
@myhatmygandhi6217 2 года назад
I did this as a complete beginner, literally know nothing about programming/coding. Just followed the video and did it using Pythons IDLE. Had to make 4 or 5 corrections along the way but is was pretty straight forward. Great video! Looking forward to learning actual fundamentals of coding online now, preferably in Python. Edit: Being able to programme AI in this game would be great too for a future video.
@TechWithTim
@TechWithTim 2 года назад
I have a video on AI!
@HcmfWice
@HcmfWice Год назад
You could save yourself a lot of typing by using the object-oriented features of Python. E.g. you could add some methods to the Paddle class like left_x(), right_x(), top_y(), bottom_y() that calculate and return the relevant edge values of the paddle. Same with the ball. It would also make the code much cleaner.
@asharhabib4742
@asharhabib4742 Год назад
Awesome work! Keep up the great videos :)
@tiagovieira5080
@tiagovieira5080 2 года назад
Tim, please do a video implementing AI for Pong.
@davebostain8588
@davebostain8588 6 месяцев назад
Great Video! I have a program to train the Gym Pong in Pythorch. The training appears to go well, but the AI cannot play the game well. I am hoping these videos will provide some insight into why this is occurring. I like the way you didn't make a bunch of classes just to make classes, but made classes when it made sense to make classes. Looking forward to the Pong AI training video!
@ozgur8946
@ozgur8946 2 года назад
Thanks for guide , really nice for both pygame and oop.I was wondering how to refresh text like scores without blinking text!
@Aditya_777
@Aditya_777 2 года назад
Thank you very much!!! Did it finally 🙏
@guipe7712
@guipe7712 2 года назад
Hello Tim, Great video and interesting material. Im practice with this pygame is really cool. Thanks friend
@lukaszb3233
@lukaszb3233 3 месяца назад
Brilliant work Tim 😁 I absolutely love your content and it's very helpful for the beginner programmer to understand. The only thing I could add to this is to avoid repeatable code in your handle_paddle_movement function you could alter the move function of the Paddle class. That's what I did in the sample below: def move(self, up): if up == True and self.y >= 0: self.y -= self.VELOCITY elif up == False and self.y < HEIGHT - PADDLE_HEIGHT: self.y += self.VELOCITY Keep up the great work you do :)
@piotrczerechowicz9352
@piotrczerechowicz9352 2 года назад
Tim, great tutorial. You should definitely make video about implementing AI to opponent pong :D
@kiish8571
@kiish8571 2 года назад
thank you, watching this is like therapy for me
@wrb5682
@wrb5682 5 месяцев назад
Thank you Tim! It really helped in enhancing my knowledge.
@TechWithTim
@TechWithTim 5 месяцев назад
Very welcome!
@Child0ne
@Child0ne 2 года назад
Yyeeeessssssssssssss I know what I’m doing today ! Thanks timbo
@user-on3bg3pe7f
@user-on3bg3pe7f 2 года назад
thanks a lot helped now i will know python better :)
@codesaif8075
@codesaif8075 2 года назад
Just started learning pygame today and you uploaded another game tutorial, Thanks Tim!
@Lokakoskt
@Lokakoskt 2 года назад
First of all congrats for the video! And let me ask a question how you learned all this stuffs?
@UnemployedMacintosh
@UnemployedMacintosh 2 года назад
He posted a video a while back I think it’s called something like his programming journey. Shouldn’t be too hard to find on his channel
@tntredstone
@tntredstone 2 года назад
I was the 7,825 viewer watched the entire video and loved it👍
@Heraclius.Maps1121
@Heraclius.Maps1121 Год назад
biggest thanks from me! I had a project and You saved me
@Clipaholick
@Clipaholick 2 года назад
omg this is awesome!!
@ranselaar
@ranselaar 2 года назад
Just started programming with Python, the fun is immense. Altough sometimes I get lost in my code spaghetti. Do you also have a video about clean code perhaps?
@puturavindrawiguna3025
@puturavindrawiguna3025 2 года назад
hey Tim, i have a question about the reason you are passing the left paddle and right paddle into a list, is there any reason why you choose list instead of other array like type like say tuple? or is it completely free to choose and doesn't have an impact on the peformance
@alexbartles
@alexbartles 2 года назад
Here goes 1 hour of my day!
@sp1nk1ck53
@sp1nk1ck53 2 года назад
I have a question: In the handle collision function, is it really necessary to check if the ball is in between the corners of the paddle it's about to hit if in it's nested "if" statement, you're going to check if the ball hits the paddle anyways?
@justmyfavs5796
@justmyfavs5796 2 года назад
you can just add this instead of left_paddle movement to make an AI " if ball.y
@diogenesthecynic1334
@diogenesthecynic1334 Год назад
where to add?
@SneakySnakesStudio
@SneakySnakesStudio 2 года назад
Much thanks bro ;-)
@Mangohawk124
@Mangohawk124 10 месяцев назад
This is smooth thats what i need ❤❤❤
@softwhere07
@softwhere07 2 года назад
Looks interesting, but I will have to check it out if I can ever get more time. I suppose I could watch 10 or 20 minutes if this a day until I finish it.
@36aryansharma83
@36aryansharma83 2 года назад
Pretty cool man! never thought you could make games with python lol
@WatchItWithFuture
@WatchItWithFuture 2 года назад
I'm waiting on the planet simulation tutorial 😁
@caleb7327
@caleb7327 10 месяцев назад
Great Video
@JastaCon
@JastaCon Год назад
it would help if you could show your keyboard inputs too. sometimes i cant see the difference between __ and _
@GreenScreenKid284
@GreenScreenKid284 2 года назад
Can you make something related like creating Jarvis irl or how iron man codes his Armor and other gadgets
@lawson1310
@lawson1310 2 года назад
Bro, you are just the best!, am gonna make an AI beat this game😎
@THEMATT222
@THEMATT222 2 года назад
Very Noice 👍
@Schmacksz
@Schmacksz 2 года назад
If I’m not using pygame… what should I use for the import?
@pushkarajsavji729
@pushkarajsavji729 2 года назад
where is the paddles defined ? it says undefined and two arguments in draw function
@sirgb7
@sirgb7 2 года назад
Great tutorial, thank you Tim
@adimac9346
@adimac9346 2 года назад
AI for pong is a great idea Tim!
@anuvabchakraborty4900
@anuvabchakraborty4900 2 года назад
You are really consistent
@enomskenneth3125
@enomskenneth3125 2 года назад
Mr may i conquire your help i was trying to download pygame but then an error occurec saying "no mudule named 'pygame'"
@bigbro1815
@bigbro1815 8 месяцев назад
Great game
@Gunsi-kb2xq
@Gunsi-kb2xq 2 года назад
Question... if you do not reset the ball (around 1:04) it keeps counting up the score (understood) but if you just wait the balls comes back from somewhere....why is that?
@ninja411-zl9yl
@ninja411-zl9yl 3 месяца назад
same
@aumpauskar4653
@aumpauskar4653 2 года назад
This video couldn't come at a much better time, I tried pygame juat last week and was halfway through making my *cursed pong* game.
@alexanderwierzbicki7988
@alexanderwierzbicki7988 2 года назад
quick question Tim. I have downloaded pygame successfully but when i run my module it just doesn't work. do you know why?
@dw5197
@dw5197 2 года назад
Do you have the right pycharm?
@ghengushahn2852
@ghengushahn2852 2 года назад
I’m having issues with collision, implementing what you have here my ball still only travels on the x axis I have no y travel at all I wonder what could be happening?
@MonTech0451
@MonTech0451 2 года назад
I have the same thing and dont know whats wrong
@MonTech0451
@MonTech0451 2 года назад
yo check your move function in the ball class i wrote self.x += self.y_vel and it sould be self.y+= self.y_vel
@ghengushahn2852
@ghengushahn2852 2 года назад
@@MonTech0451 yea I had the same thing good catch!
@Schmacksz
@Schmacksz 2 года назад
I’m on pythonista right now.
@zulfiqar7967
@zulfiqar7967 2 года назад
I completed ur Blockchain beginning course.. do you have any other plans to do another playlist on Blockchain development?
@Sniper1903
@Sniper1903 2 года назад
20:11 how can I make this bracket on the keyboard like here I mean this -> ( in straight form
@MonTech0451
@MonTech0451 2 года назад
Hey Tim my program is just changing the speed of the ball when it collides with different sides of the paddle instead of changing angles. Do you know what might be wrong or anyone in the comments know?
@MonTech0451
@MonTech0451 2 года назад
ok i figure it out it was in the ball call move function and i wrote self.x += self.y_vel so my y movement was not working on the ball lol. I wonder why this caused my ball to change speeds instead of angle most be the collision equation was only appling on the x coordinates of the ball
@kushalop_2
@kushalop_2 2 года назад
Hi bro, nice tutorial. I got an error called NameError: name 'paddles' is not defined. I am a beginner so pls help me with this 😂😅😅
@shiamjuniorchuttoocode
@shiamjuniorchuttoocode Год назад
Awesome video, really great, you did a great job.
@bxr4231
@bxr4231 2 года назад
Such a cool video
@peterbregnbk8119
@peterbregnbk8119 2 года назад
what does size must be 2 numbers mean
@MathewBey13
@MathewBey13 Год назад
When I do the first test run, my window appears for a second then disappears. How do I fix this issue?
@kshutt6242
@kshutt6242 Год назад
How can I do this with IDLE? I have installed Pygame via the command prompt, but IDLE doesn't recognize pygame with import. Thanks in advance.
@jamieharper5665
@jamieharper5665 Год назад
I learned so damn much in this video! On to the AI using NEAT video that I've been eyeing up lol :P
@Tinker250
@Tinker250 Год назад
I am getting an error that reads AttributeError: partially initialized module 'pygame' has no attribute 'init' (most likely due to a circular import) pls help me
@markadyash
@markadyash 2 года назад
yeah we all need AI playing pingpoing
@Billman07
@Billman07 2 года назад
U are my fav teacher
@TechWithTim
@TechWithTim 2 года назад
You're my fav commenter ;)
@Billman07
@Billman07 2 года назад
@@TechWithTim damm i first time commented-
@BackyardFusion
@BackyardFusion Год назад
where was paddles defined(minute20:26) it tells me that it isnt defined and also: TypeError: draw() takes 1 positional argument but 2 were given
@ryanali156
@ryanali156 Год назад
for some reason when i put the second set of parenthases in the pygame.display.set_mode((WIDTH, HIEGHT)) it says thats its invalid syntax pls help
@jagzey
@jagzey 10 месяцев назад
u spelt height wrong
@0Clappy
@0Clappy 2 года назад
Can you give a quick tid bit about the left_paddle.y - left_paddle.VEL >= 0 ? Is this like a vector thats updated per frame?
@tipsminecraftchannel4348
@tipsminecraftchannel4348 6 месяцев назад
Tim the code isnt working it wont let my paddles go up can you help me with this
@mdjackhan
@mdjackhan 10 месяцев назад
hey um the code didnt work because every time u run it it just opens for 1 second and then closes, I even tried running your github code (it had same result)
@masterm987
@masterm987 Месяц назад
You need to make sure your using the pygame.display.update() to keep the window open.
@davidisfrench6560
@davidisfrench6560 Год назад
why dies it say that the module "pygame" is not found?
@dant872
@dant872 2 года назад
I would like to see the AI piece of this
@kulandaigeorgemariasingara5089
I 'm your number one fan!
@granpajestaz292
@granpajestaz292 9 месяцев назад
Followed to a T but getting error paddle object has no attribute draw any ideas?
@theatfshotmydog8224
@theatfshotmydog8224 5 месяцев назад
did you add a draw(): function within the paddle class?
@OHIOHUBPS99
@OHIOHUBPS99 Год назад
i got trouble at excuting it it always fail and the pong is not responding
@alfredgomez7701
@alfredgomez7701 10 месяцев назад
Hi sir how to out a game over message and please restart and start the game.
@cYuber356
@cYuber356 2 года назад
Ai for pong!
@sarhabernalumana4206
@sarhabernalumana4206 6 месяцев назад
9:14 uhhh my window opens for a second and than closes by itself ....
@ownser1
@ownser1 2 года назад
Can anyone explain to me why you would prefer to use something like pygame that takes much more time and knowledge, over a game engine like godot that will do a lot of the tedious work for you? This is a real question and I'm asking purely out of ignorance. Thanks to anyone who answers!
@malindrome9055
@malindrome9055 2 года назад
the reason why is pygame isnt about learning game dev per se, but its more about learning how to code and learning how to do other projects, like if you wanted to do gamedev, then pygame is not for you, then you can use godot, but pygame teaches you how to make other software, hope this helps!
@PaiganBeast
@PaiganBeast Год назад
Can someone help me? I'm getting a name error, saying '_name_' is not defined, and I'm not getting the black screen popping up at 9:14 :(
@brucemozart3665
@brucemozart3665 Год назад
I had the same error. Make sure that there are two '_' on each side of "name" and "main". This is easy to mess up :D
@PaiganBeast
@PaiganBeast Год назад
@@brucemozart3665 I double checked, and ive two underscores on each side 🥺
@Adam-gk9or
@Adam-gk9or 10 месяцев назад
I rewrote your code but my display shows only for a second? do you guys know why is that?
@zdiddy4112
@zdiddy4112 7 месяцев назад
I had the same issue for a moment, for me it was an indentation error, my if __name__ == '__main__': main() was indented as if it was part of the main() function. I just had to de-dent that one part. Try selecting (click and drag) the if name ==main: main() part and press shift + tab it should pop it back into place at the start of the line
@pravachanpatra4012
@pravachanpatra4012 2 года назад
Tim now can you make an AI that plays Pong using the NEAT algorithm.
@pravachanpatra4012
@pravachanpatra4012 2 года назад
I understand the basic concept of the NEAT algorithm, but I want learn how it actually mutates/breeds the neural networks.
@pravachanpatra4012
@pravachanpatra4012 2 года назад
Yo Tim why aren’t you replying to my comment? 😤
@pravachanpatra4012
@pravachanpatra4012 2 года назад
I guess Tim just doesn’t like my ideas 🤷‍♂️
@FRAMEDSKATEKREW69
@FRAMEDSKATEKREW69 Год назад
Idk if you'll see this but how do I display 10 at the end of the match? Its kind of bothering me that it shows 9 when it ends. Hopefully I figure it out soon, Nice tutorial btw!
@kangmashdy
@kangmashdy 2 года назад
waw, ini keren
@user-pt4eo1cc8b
@user-pt4eo1cc8b 3 дня назад
I'm using python 3.12.3
@hudsonmcknight4221
@hudsonmcknight4221 Год назад
the screen wouldnt show up
@rochoe4575
@rochoe4575 2 года назад
Tfw i was working on a pong clone last night using what I've learned with pygame so far. This is convenient.. too convenient
@TechWithTim
@TechWithTim 2 года назад
I'm watching you...
@Ur.Podcast_Buddy
@Ur.Podcast_Buddy 2 года назад
@@TechWithTim watch me also😏
@rochoe4575
@rochoe4575 2 года назад
@@TechWithTim would this be hard to make into an online game using sockets?
@srinivas-pt3kb
@srinivas-pt3kb Год назад
How to stop the game after out
@stonedape3804
@stonedape3804 3 месяца назад
Hey guys.. im just learning python, and have a very low understanding, i have got as far as drawing on the paddles left and right, my issue is, when i run the program my paddles are sitting horizontally instead of vertically, can anyone help me with this?? They seem to be perfect dimensions, just drawn at the wrong angle. Any help be Much appreciated.
@Fr-wx8zj
@Fr-wx8zj Месяц назад
I think you may be getting your paddle width and height placed wrong. There's two possibilities, 1. While calling your function, you put the variable for the width and height in the wrong order ( being paddle_height, paddle_width)(instead of paddle_width, paddle_height). 2. You got the variable sequence right, but the value is swapped with one another ( like paddle_width, paddle_height = 100, 20)(instead of paddle_width, paddle_height = 20, 100) I'm not sure if this is what you're asking , but hope it helps
@stonedape3804
@stonedape3804 Месяц назад
Thanks i posted this a while ago, so i got the issue fixed, much appreciated all the same 🙏🏻
@ali-bibon--
@ali-bibon-- 2 года назад
Tim
@JastaCon
@JastaCon Год назад
there is no window opening. it just says "no module named pygame"
@HDMentor
@HDMentor 10 месяцев назад
Can You make the game easy with codes
@jasiriwa-kyendo8043
@jasiriwa-kyendo8043 2 года назад
Pythong
@neiladriangomez
@neiladriangomez 2 года назад
I think you are one of those ppl who work two or three full time jobs, in your case with a company and in youtube🤭🤔😁
Далее
Pygame in 90 Minutes - For Beginners
1:35:22
Просмотров 1 млн
Python Pong AI Tutorial - Using NEAT
1:18:13
Просмотров 99 тыс.
I Built a SECRET McDonald’s In My Room!
36:00
Просмотров 17 млн
When You Get Ran Over By A Car...
00:15
Просмотров 3 млн
2 YEARS of PYTHON Game Development in 5 Minutes!
4:54
Просмотров 851 тыс.
Pygame Tutorial - Creating Space Invaders
1:56:03
Просмотров 806 тыс.
Data Analysis with Python for Excel Users - Full Course
3:57:46
Making a Game in Python with No Experience
5:57
Просмотров 1,6 млн
5 Mini Python Projects - For Beginners
1:41:08
Просмотров 2,8 млн
How to Make a Game in Python
43:01
Просмотров 383 тыс.
HOW TO MAKE PONG IN PYTHON AND PYGAME! (15 Min)
17:29
Automate with Python - Full Course for Beginners
2:42:55
Learn Python With This ONE Project!
55:04
Просмотров 1,6 млн
I Built a SECRET McDonald’s In My Room!
36:00
Просмотров 17 млн