Тёмный

Python Game Tutorial: Pong 

freeCodeCamp.org
Подписаться 10 млн
Просмотров 512 тыс.
50% 1

A Pong clone game tutorial for beginners using Python 3.
⭐️Course contents ⭐️
⌨️ (00:00) Part I: Introduction and the basic window setup
Code: christianthompson.com/sites/de...
⌨️ (03:32) Part II: Add game objects to the screen (Paddles and Ball)
Code: christianthompson.com/sites/de...
⌨️ (09:15) Part III: Moving the Paddles
Code: christianthompson.com/sites/de...
⌨️ (15:06) Part IV: Moving the ball
Code: christianthompson.com/sites/de...
⌨️ (24:10) Part V: Colliding with the Paddles
Code: christianthompson.com/sites/de...
⌨️ (30:47) Part VI: Scoring
Code: christianthompson.com/sites/de...
⌨️ (37:57) Part VII: Adding Sound
Code: christianthompson.com/sites/de...
🔈 Sound file: christianthompson.com/sites/de...
💻 Finished Code: christianthompson.com/sites/de...
Tutorial from Christian Thompson. Check out his RU-vid channel: / @tokyoedtech
--
Learn to code for free and get a developer job: www.freecodecamp.org
Read hundreds of articles on programming: medium.freecodecamp.org

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

 

8 авг 2024

Поделиться:

Ссылка:

Скачать:

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

Добавить в:

Мой плейлист
Посмотреть позже
Комментарии : 1,4 тыс.   
@47noodles
@47noodles 4 года назад
Me: *Gets a black box to appear on the screen* *Smiles Proudly*
@chriscreates7772
@chriscreates7772 4 года назад
me
@47noodles
@47noodles 4 года назад
Christian Thompson I done now, I even figured out how to get the ball to go faster at every bounce
@goku445
@goku445 4 года назад
I had to work to ge to that point. Linux python install versioning shitfest...
@seventyfox7442
@seventyfox7442 4 года назад
@@TokyoEdTech Wow! I think that it is really cool that you are still responding to these comments, even after about a year of this being up. I watched this video a while ago and it jump-started my passion for coding, so thank you!
@cal847
@cal847 4 года назад
ha, me too. that made my day.
@mikemindacodemy7279
@mikemindacodemy7279 5 лет назад
Build a game, no matter how simple, always makes learning a new language more fun and motivating. Thank you!
@goku445
@goku445 4 года назад
I always start with a pong whenever I want to learn a new language :D
@Jojo-cs4bl
@Jojo-cs4bl 4 года назад
Whan I wirt square it say error 😩
@samisha9145
@samisha9145 3 года назад
We made a pong game in Python using the Turtle and Freegames libraries. ru-vid.com/video/%D0%B2%D0%B8%D0%B4%D0%B5%D0%BE-QPKOBeNwRbk.html
@joebot001
@joebot001 5 лет назад
This is my first-ever (finally) attempt at coding something in Python. After dozens of "learn python in x-hours" videos, I finally realized I needed a specific goal, and pong was recommended. I had to pause at 32min to just play my pong game, with the biggest grin on my face. Thanks so much for this tutorial, it's EXACTLY what I needed to finally jump into coding.
@zachface.19
@zachface.19 4 года назад
It's been 5 months since you said this. How much more would you say your coding has improved?
@markuskorpijarvi5538
@markuskorpijarvi5538 4 года назад
@@zachface.19 Its 6 months
@markuskorpijarvi5538
@markuskorpijarvi5538 4 года назад
@@zachface.19 How much do You haves?
@user-xq2dz4rp9k
@user-xq2dz4rp9k 4 года назад
It's been 9 months since you said this. How much more would you say your coding has improved?
@bravosix8171
@bravosix8171 4 года назад
Have you learned? Plz tell
@crunchygs8771
@crunchygs8771 4 года назад
Me: copies everything he did but the color and size ratio's Also Me : i am programr
@TheComedyBlackGuy
@TheComedyBlackGuy 4 года назад
literally
@tankytitan1304
@tankytitan1304 4 года назад
The program is easy if you know math
@rayanking4773
@rayanking4773 4 года назад
i don't think is a good way that's a video for learning not for copy
@Zubs1507
@Zubs1507 4 года назад
lol
@Itz_me_JB
@Itz_me_JB 4 года назад
its fine to copy the code the point is to make sure to understand it
@TheWorldsStage
@TheWorldsStage 4 года назад
Do a beginners tutorial on how to program a game like "Fallout 4" using turtle in Python. It may need a few extra lines of code.
@cOnT3ST
@cOnT3ST 4 года назад
Or maybe he should just recode "Fallout 76"
@cOnT3ST
@cOnT3ST 4 года назад
@@linushallgren4156 Of course he wasn't. what made you think so???
@TheWorldsStage
@TheWorldsStage 4 года назад
@@linushallgren4156 So, maybe like, 20 extra lines of code?
@cooperbrahmsteadt5123
@cooperbrahmsteadt5123 4 года назад
Whitney 25 at most
@xdemoman3692
@xdemoman3692 4 года назад
@@cooperbrahmsteadt5123 Maybe 30, but that's only when worst comes to worst.
@protoactivenuclear7727
@protoactivenuclear7727 5 лет назад
richards from silicon valley was right, spaces are annoying just use tabs
@peesicle
@peesicle 4 года назад
Yeah he was also nice to see someone who actually watches something i watch
@sireopossom7860
@sireopossom7860 3 года назад
I watched the whole 44min and I was not bored a second. I loved it, thanks for the great tutorial, please make more!
@English.with.Mateusz
@English.with.Mateusz 2 года назад
did you continue your journey with Python?
@maayancole
@maayancole 4 года назад
Thank you so much for taking time aside to help people code, coding can be very hard without basic information, and what you do so helpful, please keep uploading. (Sorry for the grammar mistakes, English isn't my native language)
@LunaBellaRosa
@LunaBellaRosa 5 лет назад
Thanks so much for this. I am super new to coding and found this and decided to give it a try. I still have a long way to go, but I’m having fun. I hope to learn more with your videos and free code camp soon.
@harmannatsingh3933
@harmannatsingh3933 4 года назад
This is the best tutorial about a project in python. Thanks so so so much!
@chrispowell8121
@chrispowell8121 4 года назад
Finished. I never thought I could code a game until I watched this video. Thank you, Christian!
@TokyoEdTech
@TokyoEdTech 3 года назад
You're very welcome - keep on codin'!
@anonymoustechgeek
@anonymoustechgeek 4 года назад
Starting at 40:49, the sound comes after the ball hits the coordinates because that is where it is placed in the program. If you move the sound to right after the if statement, it will occur in the correct order hit-sound-rebound. I do not have Python and have never programmed in it but I used to be a Visual Basic programmer years ago (VB 6). Now I am a sys admin. I kind of miss programming. I followed the logic perfectly in this video despite that fact. I believe I will try it now that I have watched this. Thank you! This is awesome! It reminded me how much fun programming was!
@shalonemadre488
@shalonemadre488 4 года назад
That was very helpful with my school project, thank you very much for the help.
@publicstaticvoid3224
@publicstaticvoid3224 5 лет назад
Thank you very much for making this tutorial. I appreciate the hard work you put into this bro! Everything worked perfectly ;)
@ebentee
@ebentee 5 лет назад
It dies work for me
@josephshaw2747
@josephshaw2747 3 года назад
31:25 "I just call it a pen, but it's actually just a turtle" - Smart computer man, 2020
@TokyoEdTech
@TokyoEdTech 3 года назад
Thanks - I try.
@CarlC9898
@CarlC9898 5 лет назад
Thanks for this awesome tutorial! The game is working great for me (I just needed to change the ball.dx and ball.dy to 0.2 and -0.2 respectively). I'm going to try and make another game using the turtle module and the techniques I learned in this video.
@lannyboover229
@lannyboover229 5 лет назад
oh, thnx for your ball speed advice
@antonkarolik6993
@antonkarolik6993 4 года назад
instead of ball.shape("square"), do ball.shape("circle")
@user-ze3ui8ur9h
@user-ze3ui8ur9h 2 года назад
i believe this was inspired by the original version of pong.
@kiddo7562
@kiddo7562 2 года назад
thanks u made it look better and interesting :)
@ankeet4044
@ankeet4044 2 года назад
it looks more retro with square.
@TheBobstar89
@TheBobstar89 5 лет назад
24:35 why is there a 10px offset that causes the ball to go off the screen instead of stopping at the window corner?
@tinker7722
@tinker7722 2 года назад
Thank you! Great tutorial! Very good style. It is fun to watch! So professional, so inspiring!👍
@wesusaa
@wesusaa 4 года назад
Really good video! I was really happy with how it turned out! I made some adjustments so they paddles didn't go off screen, but the explanation was so well made!
@zackcordle4814
@zackcordle4814 2 года назад
How did you code them so they don't go off screen?
@samshanmukh
@samshanmukh 5 лет назад
I think adding the ampersand (&) at end of the file tells to run the command in the background for unix-based systems.
@EyiBillion
@EyiBillion 5 лет назад
Thank you for the tutorial. it was mind blowing.
@RotemEren
@RotemEren 2 года назад
Short and to the point. Well done.
@_HARAA_
@_HARAA_ 3 года назад
no one could have made it any easier and motivating, thank you
@annielouise1141
@annielouise1141 3 года назад
my ball is not moving..
@elbow3422
@elbow3422 5 лет назад
Hello, I followed through the whole tutorial and now at the end I'm trying to make a timer for the game. I successfully made the timer just how I wanted but it froze everything else in the game. I'm pretty sure the problem is that the loop is waiting for the timer to finish until it goes again, but I want the game and timer to run simultaneously. Any ideas?
@abhijeetkushwaha424
@abhijeetkushwaha424 5 лет назад
@ 23:50 instead of sending the ball to 0,0 when it collides with the x boundaries, i used: ball.goto(390,ball.ycor()) and ball.goto(-390,ball.ycor()) This is preserving continuity of the game, instead of directly sending the ball at center.
@dreggeth
@dreggeth Год назад
Thank you for this great tutorial! If someone wants to limit paddles movement in y direction you can do this: def paddle_a_up(): y = paddle_a.ycor() if y < 250: y += 20 paddle_a.sety(y) def paddle_a_down(): y = paddle_a.ycor() if y > -250: y -= 20 paddle_a.sety(y)
@greenbeanmanz
@greenbeanmanz 4 года назад
This was great!!I had to figure out how to show the turtle window and stuff on windows because the way visual studios was set up. I didn’t add sounds because I didn’t want to mess anything up and I didn’t want to spend any more time. Great tutorial!!!
@TokyoEdTech
@TokyoEdTech 3 года назад
Thanks!
@logandukes5984
@logandukes5984 4 года назад
this is probably the best coding tutorial i have watched so far. He explains everything super well for those who have never used turtle before. He simplifies everything and takes his time instead of speeding through it. I really want to see a snake game tutorial by this guy but I hope he teaches us how to make a grid instead of just a dark backround because a grid looks much better and makes it easier to play the game
@TokyoEdTech
@TokyoEdTech 3 года назад
Thanks! I have a snake tutorial, but no grid - sorry.
@sgeasley
@sgeasley 5 лет назад
Yo my dudes, loving this channels 'simple' yet effective tutorials, thank you so much! Having alot of fun here :) Edit: Helps that you guys dont rush things and like to recap before moving onto next!
@Moomoocowmeoww
@Moomoocowmeoww 5 лет назад
Thank you for this practical presentation. Explained alot for me man. Appreciated
@mdempse1
@mdempse1 5 лет назад
Great tutorial. Got the sound working in windows and now I just need to figure out how to make the paddles get continuous input from a held down key and make it faster/smoother. Learned a lot. Thanks!
@mdempse1
@mdempse1 5 лет назад
@@TokyoEdTech Nice, I will give it a try.
@RahulRoy-ct7ni
@RahulRoy-ct7ni Год назад
what is the command for window for the sound?
@thatwholesomeindian3305
@thatwholesomeindian3305 4 года назад
im having problems every time i try to run it, it says in the terminal invlid syntax
@SuperDavedm
@SuperDavedm 4 года назад
Great tutorial, I was wanting to make a more interesting version of pong and using this a base. How would you suggest dynamically updating the background as the game runs?
@harshitgupta5444
@harshitgupta5444 3 года назад
adding a controller control or mouse control maybe, simple yet good creativity
@Hilqy
@Hilqy 3 года назад
way more useful than my teacher, learned more here than I have this month
@TokyoEdTech
@TokyoEdTech 3 года назад
Thanks - glad you found it useful!
@peterkrogh1863
@peterkrogh1863 Год назад
Great tutorial, easy understandeble and good explaining on what does what, so oneself can improve a bit on the programming like not make the bat go off screen and whatever comes to mind :)
@marcfoster715
@marcfoster715 4 года назад
print("The only winning move is not to play.")
@hillybankok
@hillybankok 2 года назад
You've... Been.... Trolled! You've been trolled, Yes you've probably been told!, Don't reply to this guy, he's just trying to get a rise.. OUT OF YOU! Yes it's true! You respond, and that's his cue! To start trouble on the double, while he strokes his madly stubble!, You've been trolled, you've been trolled! You should probably just fold! When the only winning move is not to play! And yet, you keep on trying, mindlessly REPLYING! You've been trolled, you've been trolled! Have a nice daaaaaaaaaaay.!!
@gabrielchoimet6695
@gabrielchoimet6695 4 года назад
Thanks I love this without class and difficult code its perfect !
@TokyoEdTech
@TokyoEdTech 3 года назад
Glad you liked it!
@jackphillips497
@jackphillips497 5 лет назад
Great video for beginners in python (like me) to learn a simple yet interesting game! I did it on windows and followed this video step by step pretty much and everything works perfectly. I was using python 2 and had to take away a bracket and add a colon on the 'if ' function in 'paddle and ball collisions". Overall amazing Video. :)
@jackphillips497
@jackphillips497 5 лет назад
@@TokyoEdTech Your very welcome.
@julianwilliams2439
@julianwilliams2439 5 лет назад
how do i make it so paddle a is able to be hit by the ball its not working!!!!
@wasadasa1
@wasadasa1 5 лет назад
For paddle and ball collisions I used absolute value function for the distance between the core of the ball and paddle, it's easier and doesn't cause the ball to stuck behind the paddle.
@nowybopes
@nowybopes 4 года назад
I don't know why I was so happy when the black square appeared on my screen
@rayanking4773
@rayanking4773 4 года назад
me too xd
@latifasebti7913
@latifasebti7913 4 года назад
itz becuz u feel u did something great and u didn't do any falt and ur so proud of yourself
@thisthelongestnameonyoutub2190
@thisthelongestnameonyoutub2190 3 года назад
Me Too!
@hypersound1612
@hypersound1612 3 года назад
It’s not popping up on mine
@blue_is_cool16
@blue_is_cool16 3 года назад
@@hypersound1612 make sure to open the python IDLE program too.
@ursomrano542
@ursomrano542 2 года назад
A cool little thing you can add to the code as well is a direction randomizer every time the ball is in the center by importing "random" and then adding something like this: if ball.xcor() == 0 and ball.ycor() == 0: firstDirection = random.randint(0,3) if firstDirection == 1: ball.dx *= -1 ball.dy *= 1 elif firstDirection == 2: ball.dx *= 1 ball.dy *= -1 elif firstDirection == 3: ball.dx *= -1 ball.dy *= -1 in the "#Move the ball" section of the while loop :)
@danielmoreno968
@danielmoreno968 2 года назад
Thank you!
@kimacable
@kimacable 5 лет назад
Beautifully explained , step by step. Great tutorial. You sound so similar to Dr B Fraser who does You Tube tutorials on Android lists etc.
@AamirKhan-zy5yt
@AamirKhan-zy5yt 5 лет назад
Which text editor he is using?
@alyz2798
@alyz2798 5 лет назад
Microsoft visual studio code, free btw
@abdurrahman.maricar
@abdurrahman.maricar 4 года назад
Having issues with sound on Windows, Whenever it touches the wall or the paddle it gives a Windows error sound instead of the bounce sound that I had downloaded
@ogunkayodeoluwaseun9348
@ogunkayodeoluwaseun9348 4 года назад
Same here and my pad runs off the screen too
@sohitbagga712
@sohitbagga712 4 года назад
did you save your sound file in .vscode folder?
@ladzsn5314
@ladzsn5314 4 года назад
@@sohitbagga712 where is the folder
@u4tiwasdead
@u4tiwasdead 4 года назад
if you still want to know, if you just wrote the filename e.g. "bounce.wav" you need to write the full filepath instead e.g. "C:/Users/files/bounce.wav"
@abdurrahman.maricar
@abdurrahman.maricar 4 года назад
@@u4tiwasdead Thanks alot
@iudizm
@iudizm 5 лет назад
I made it... in 2 hours, but its awesome. Thx for all the wisdom hehe
@krishanujoarder2935
@krishanujoarder2935 5 лет назад
This one works fine. I have tried executing other game codes in RU-vid, it did not work. Awesome tutorial.
@nier-mage8669
@nier-mage8669 4 года назад
having issues with sound on windows and the ball is just to fast for the paddle or whatever to keep up, what can I do to fix this.
@beter1838
@beter1838 4 года назад
you can change the speed of the ball in 'ball.dx = ?' and 'ball.dy = ?' its in the code where you created the ball i`ve set it to 0.3 and its working fine for me.
@el4f310
@el4f310 4 года назад
@@beter1838 wow,thank very much man!
@el4f310
@el4f310 4 года назад
thank you *
@snatchbandicoot
@snatchbandicoot 5 лет назад
Just wondering... why do you like using 4 spaces instead of a tab? I have always used tab and the computer automatically puts a tab in certain situations, so why change it up?
@Set_Abominae
@Set_Abominae 5 лет назад
It's because of the PEP8 of Python. Read about it.
@nathansmith3608
@nathansmith3608 5 лет назад
maybe it's because Developers Who Use Spaces Make More Money Than Those Who Use Tabs stackoverflow.blog/2017/06/15/developers-use-spaces-make-money-use-tabs/ half kidding; Python style guide recommends indents using 4 space chars, & Python's hot among data scientists & at Google, which I suspect explains the correlation they found
@IamnotGW
@IamnotGW Год назад
9:37 I have never seen someone need more effort to write the word Function. Overall a great video for beginners
@dausband79
@dausband79 4 года назад
Building a Pong game This does put a smile on my face
@IDrive305
@IDrive305 5 лет назад
you should explain that if ball.dx is set too high at 2 use fractions your code should look like this : ball.dx = 1/5 ball.dy = 1/5 adjust bottom half of the fraction to your desired speed
@IDrive305
@IDrive305 5 лет назад
or decimal
@shivamjalotra7919
@shivamjalotra7919 5 лет назад
this thing is self-explanatory
@IDrive305
@IDrive305 5 лет назад
Christian Thompson I like your vids great work
@shivamjalotra7919
@shivamjalotra7919 5 лет назад
@@TokyoEdTech Great work from your side. Love it.
@uahatoxicboi9801
@uahatoxicboi9801 5 лет назад
C R thanks I appreciate
@luka8966
@luka8966 4 года назад
This is a very good tutorial and I very recommend it. It was easy to understand and I might actually stand a chance at creating games in the future. After it finished, I managed to: Make it slowly get faster, make it so both players can create there own names and make the game a best of 5 where your paddle gets smaller for every point you get and it even comes up with text at the end saying who won. Thank you!
@spekkio77
@spekkio77 4 года назад
nice going, I also made it slowly get faster and then reset when the ball goes out. I like the idea of the paddle getting smaller, I may try that. Another fun idea I might try is to change the angles (dx / dy) depending on where the ball hits the paddle
@mohammedirfan1739
@mohammedirfan1739 3 месяца назад
broooooo thank you soo much man i was scared that i would fail my test but you saved my 🥺
@tamassvecz571
@tamassvecz571 Год назад
Very useful tutorial! Thank you very much from Hungary! 😊
@nickw22689
@nickw22689 4 года назад
Anyone who's built and run this, does the "spin" of the ball change depending on the velocity and placement of the paddles when the ball hits?
@alexshao9916
@alexshao9916 4 года назад
This version of pong has no spin specifically coded in. In the original game and more complex versions, that would be a feature to add, but this is just a basic overview on the general ideas of the game itself.
@samuelmodig2816
@samuelmodig2816 3 года назад
Thank you for a great tutorial! So, how do I export this as a finished .exe game?
@alexyeomans1524
@alexyeomans1524 2 года назад
thank you so much. this has helped a lot and was very fun
@mishaan1791
@mishaan1791 4 года назад
was fun to do this thanks man
@Berzerker-
@Berzerker- 4 года назад
hey i got a problem where my ball speed isnt constant even though i have the same exact code as the tutorial, anyone know how to fix this ?
@TheBerkaay
@TheBerkaay 3 года назад
I have the same problem. Were you able to find a solution?
@kiwan7411
@kiwan7411 3 года назад
he litterly sedd how to fix it
@kiwan7411
@kiwan7411 3 года назад
@Waleed في الشلال well its kinda hard to explain just watch the video again or something
@vicfic_
@vicfic_ 3 года назад
@Waleed في الشلال , @Berksater in the # ball section there are two variables named ball.dx and ball.dy. Lower its values from 2 to 0.1 or something.
@kingannihilator8386
@kingannihilator8386 3 года назад
this is the most useless reply section i have ever seen
@rohanyadav8573
@rohanyadav8573 4 года назад
hey I'm facing a bug, do you mind helping me out on this, "whenever the ball bounces from the corners it's speed increases for a fraction of time, and gets shot in the direction it's following... "
@saun_sa
@saun_sa 4 года назад
Looks like turtle module got some weird physics bruh
@notanamehere8355
@notanamehere8355 4 года назад
Mine too but Ok
@tankytitan1304
@tankytitan1304 4 года назад
Check your move the ball function
@av465
@av465 4 года назад
It happened with me too but it was because i used + not * in the if cause
@xxjtoot8764
@xxjtoot8764 5 лет назад
im trying to get the ball to move but an error pops up saying the ball is not defined even though im following along exactly
@vampiriclion1176
@vampiriclion1176 4 года назад
I come from java and I'm shocked because of the simplicity of py. I began to study Python few days ago and I love it
@joost_schiphorst
@joost_schiphorst 4 года назад
my ball has different speeds, i dont know why, how do i solve it? the best speed on my computer is 0.13
@diegoolivera5261
@diegoolivera5261 4 года назад
did U find a solution to it, I'm having the same problem
@joost_schiphorst
@joost_schiphorst 4 года назад
@@diegoolivera5261 nope, I wish I had
@josephreed3287
@josephreed3287 4 года назад
Joost Schiphorst I’m having the same issue as well. And what I believe is happening is that your pc is using up less processing power at some points and in those moments, the ball moves faster because the ball is set to move based on how quickly your pc can update it. But I’m not 100% sore about that so take it at face value. Lol I do believe there is a way to fix it but it’s currently 2 am for me. I’ll look it up tomorrow and let you know if I’ve found a fix or not.
@ishank7239
@ishank7239 4 года назад
Has someone found the fix ?
@a.a8720
@a.a8720 4 года назад
1/2
@itstoufik8410
@itstoufik8410 3 года назад
thank you for the tutorial!
@TokyoEdTech
@TokyoEdTech 3 года назад
You're welcome!
@ayushshah9472
@ayushshah9472 Год назад
YOU ARE AMAZING AND YOUR EXPLANATION LEVEL IS TOP NOTCH!! VERY NICE VIDEO
@twodays8041
@twodays8041 4 года назад
I can't believe I just programed a game, thank you
@TokyoEdTech
@TokyoEdTech 3 года назад
You're welcome!
@punk199615
@punk199615 5 лет назад
So, I was having trouble with the paddles not showing up and I moved the following code, [while True wn.update] after the paddle codes and then it started working!
@aprameyakannan4291
@aprameyakannan4291 5 лет назад
same here
@jenaal-abbas330
@jenaal-abbas330 4 года назад
ohhhh so im gonna do that. thanks!
@TheBerkaay
@TheBerkaay 3 года назад
Thank you for the tutorial. I found it very useful. I have a question though, when I try to move both paddles at the same time (giving the program two inputs simultaneously) the program gives priority to first input given. Is there any way to fix this? Or this is because the turtle library? I am saying this because in some games, mario for instance, you can jump but you can also jump to left or right by pushing 2 buttons at the same time. Thanks in advance.
@TokyoEdTech
@TokyoEdTech 3 года назад
You're welcome. That is a limitation of the turtle module - try Pygame instead.
@annielouise1141
@annielouise1141 3 года назад
my ball is not moving....
@benaronson2410
@benaronson2410 5 лет назад
please help! in the main game loop, where we try to get the ball to move, i keep getting an error that says "instance of turtle has no 'dx' or 'dy' member." How do I fix this???
@kalyanbaidya7339
@kalyanbaidya7339 4 года назад
Thank you very much sir............that helped me to create my own pong game...☺☺
@dotcom4204
@dotcom4204 4 года назад
so i tried to do the sound part but instead of the bounce.wav playing, i just got a windows error sound, which is just as good so im happy
@alimz3134
@alimz3134 4 года назад
same i got that 2
@dominator1699
@dominator1699 5 лет назад
im pretty sure i copied the code correctly but the paddles can go off screen, did i do something wrong or did he not code that part?
@jrezzi1308
@jrezzi1308 5 лет назад
# Simple Pong in Python 3 for Beginners # By @TokyoEdTech import turtle import os wn = turtle.Screen() wn.title("Pong") wn.bgcolor("black") wn.setup(width=800, height=600) wn.tracer(0) # Score score_a = 0 score_b = 0 # Paddle A paddle_a = turtle.Turtle() paddle_a.speed(0) paddle_a.shape("square") paddle_a.color("white") paddle_a.shapesize(stretch_wid=5,stretch_len=1) paddle_a.penup() paddle_a.goto(-350, 0) # Paddle B paddle_b = turtle.Turtle() paddle_b.speed(0) paddle_b.shape("square") paddle_b.color("white") paddle_b.shapesize(stretch_wid=5,stretch_len=1) paddle_b.penup() paddle_b.goto(350, 0) # Ball ball = turtle.Turtle() ball.speed(0) ball.shape("square") ball.color("white") ball.penup() ball.goto(0, 0) ball.dx = 2 ball.dy = 2 # Pen pen = turtle.Turtle() pen.speed(0) pen.shape("square") pen.color("white") pen.penup() pen.hideturtle() pen.goto(0, 260) pen.write("Player A: 0 Player B: 0", align="center", font=("Courier", 24, "normal")) # Functions def paddle_a_up(): y = paddle_a.ycor() y += 20 paddle_a.sety(y) def paddle_a_down(): y = paddle_a.ycor() y -= 20 paddle_a.sety(y) def paddle_b_up(): y = paddle_b.ycor() y += 20 paddle_b.sety(y) def paddle_b_down(): y = paddle_b.ycor() y -= 20 paddle_b.sety(y) # Keyboard bindings wn.listen() wn.onkeypress(paddle_a_up, "w") wn.onkeypress(paddle_a_down, "s") wn.onkeypress(paddle_b_up, "Up") wn.onkeypress(paddle_b_down, "Down") # Main game loop while True: wn.update() # Move the ball ball.setx(ball.xcor() + ball.dx) ball.sety(ball.ycor() + ball.dy) # Border checking # Top and bottom if ball.ycor() > 290: ball.sety(290) ball.dy *= -1 os.system("afplay bounce.wav&") elif ball.ycor() < -290: ball.sety(-290) ball.dy *= -1 os.system("afplay bounce.wav&") # Left and right if ball.xcor() > 350: score_a += 1 pen.clear() pen.write("Player A: {} Player B: {}".format(score_a, score_b), align="center", font=("Courier", 24, "normal")) ball.goto(0, 0) ball.dx *= -1 elif ball.xcor() < -350: score_b += 1 pen.clear() pen.write("Player A: {} Player B: {}".format(score_a, score_b), align="center", font=("Courier", 24, "normal")) ball.goto(0, 0) ball.dx *= -1 # Paddle and ball collisions if ball.xcor() < -340 and ball.ycor() < paddle_a.ycor() + 50 and ball.ycor() > paddle_a.ycor() - 50: ball.dx *= -1 os.system("afplay bounce.wav&") elif ball.xcor() > 340 and ball.ycor() < paddle_b.ycor() + 50 and ball.ycor() > paddle_b.ycor() - 50: ball.dx *= -1 os.system("afplay bounce.wav&")
@akshatbajetha2483
@akshatbajetha2483 4 года назад
thank u so much... your video tutorials are the best on youtube!!!! Love your Hard work....
@TokyoEdTech
@TokyoEdTech 3 года назад
Thanks!
@ferax4598
@ferax4598 4 года назад
Ahh finally I'm done Christian: *AaAAaanDd*
@ferax4598
@ferax4598 4 года назад
@@TokyoEdTech lol
@derpdarko
@derpdarko 3 года назад
For windows you have to do winsound.Beep(800, 75) (you can change the numbers if you want you should end up with this import winsound winsound.Beep(800, 75) Edit: Only if the first method doesn't work
@jamesleibee890
@jamesleibee890 Год назад
i dont know if i missed it, but if you wanna end the game you can do something like this at the end of it all under the while True loop. # game over if score_a == 5: pen.clear() ball.dx = 0 ball.dy = 0 ball.goto(0, 0) pen.write("Player A wins!!!", align="center", font=("courier", 32, "normal")) if score_b == 5: pen.clear() ball.dx = 0 ball.dy = 0 ball.goto(0, 0) pen.write("Player B wins!!!", align="center", font=("courier", 32, "normal"))
@k.alipardhan6957
@k.alipardhan6957 5 лет назад
28:00 the giant if statement should be nested if statements, since they are a lot more readable and noob friendly
@Ledinos1
@Ledinos1 5 лет назад
Great tut. I've been trying to improve the game by adding ball speed-up after every paddle hit but i cannot figure it out :/ Can someone help ?
@simonmoberg8906
@simonmoberg8906 5 лет назад
Try playing around with where you have this (in the collision detection with paddles): Instead of: ball.dx() *= -1 do ball.dx() *= -2 This will invert the current direction and also double the speed. For me, I find the increase of 50% (1.5) be quite alright if you start quite slow. You'll need to reset the speed at the instant when you increase the score.
@josephreed3287
@josephreed3287 4 года назад
Simon Moberg yeah. I did the same thing but had to change it to *= 1.1 because it was a bit too fast to rally for long. Also make sure you reset the dx when you score. Or else it speeds up indefinitely. Lol
@Izui-
@Izui- 2 года назад
@@simonmoberg8906 hey, you look like a professional, I can't get python to recognise paddle_2_up/down so can you please helppp
@simonmoberg8906
@simonmoberg8906 2 года назад
@@Izui- I'm sorry but I have forgotten about this stuff :(
@jaytea23
@jaytea23 5 лет назад
Great tutorial! Only issue I'm having is with the 'w' key. I can't hold it down and continue to move up like I can with the other keys. Anyone else having this issue?
@Shikigami6
@Shikigami6 5 лет назад
same, but set the movement of the b paddle to o for up and p for down, and here i can only hold-move the up-movement. Have you solved the problem yet?
@a2kvarnstrom80
@a2kvarnstrom80 4 года назад
here is the code: def paddle_a_up(): y = paddle_a.ycor() y += 20 paddle_a.sety(y) wn.onkeypress(paddle_a_up, "w")
@maxtaylor12
@maxtaylor12 4 года назад
You are getting this issue because when you did not write your code right. Just copy it line for line. Dont forget to change each var for each function you change it for (a,b)
@vaibhavsharma985
@vaibhavsharma985 4 года назад
Here is the solution Take two Boolean variable s pressed_up and pressed_down initialised as false Then in game loop place following code If event.type==pygame.KEYFOWN: If event.key==pyame.K_W: pressed_up=True elif event.key==pygame.K_S:pressed_down=True elif event.type==pygame.KEYUP: if event.key==pygame.K_W: pressed_up=False elif event.key==pygame.K_S:pressed_down=False Then outside the event loop write If pressed_up: xcord-=1 elif pressed_down: xcord-+=1
@Nate-er1fb
@Nate-er1fb 3 года назад
You must have placed it under the "while true loop"
@Siddhesh1123
@Siddhesh1123 3 года назад
i was so happy when u said u werent using OOP, i cant get my head around it!
@parkie2582
@parkie2582 5 лет назад
Thanks so much this was so fun :D
@viljar_5339
@viljar_5339 5 лет назад
"raw_input" is not defined. Me: Well, that's because there is no "raw_input" in my code
@talhanawaz5486
@talhanawaz5486 4 года назад
U can use simple "input ( ) " either because raw_input is no longer supported in python 3
@EJStudios17
@EJStudios17 4 года назад
I noticed that false debug notices can appear if something isn’t completely true, say you said print(‘blah , text_q , blah blah’) And because you don’t put the ‘ after getting python to put input in.
@iamsatyam9689
@iamsatyam9689 4 года назад
@@TokyoEdTech thanks :)
@Glitch1125
@Glitch1125 4 года назад
I like my input cooked
@johnniegilkerson4724
@johnniegilkerson4724 5 лет назад
Im running this code in visual studio code on windows 10, everything works but the ball goes way too fast?
@leahr.529
@leahr.529 5 лет назад
johnnie gilkerson try using points like 0.2
@k01b01
@k01b01 5 лет назад
Mine also does not work. I tried every speed option and it goes the same fast speed.
@stolencinnamon6230
@stolencinnamon6230 5 лет назад
same here anyone knows why ?
@k01b01
@k01b01 5 лет назад
@@stolencinnamon6230 You still having the problem?
@sevcandincel
@sevcandincel 5 лет назад
First sorry for bad english. johnnie gilkerson its cause of it is performance based move. İ mean, if your computer fast execute the while loop, your ball will move fatser. You should use velocity based moving. For this, you can use time function from time module. This function give time as seconds. So you can calculate how many seconds a loop will last. Then you should multiple this time with ball.dx and ball.dy.
@icecreamcone8770
@icecreamcone8770 5 лет назад
for the sound part what is it on windows?
@gv6758
@gv6758 4 года назад
When I press and hold the keys that trigger the movement, they do the movement repeatedly as long as I'm holding the key, which is what I expect but, I don't know why, if I press and hold the key that triggers the down movement on the paddle b, it only does it one time. It's not a keyboard problem if anyone's wondering
@climbingcreeper1609
@climbingcreeper1609 4 года назад
The ball keeps changing speed... please help
@kindersmith8407
@kindersmith8407 4 года назад
yeah it happens to me too, but it doesnt impact preformance......... i'lll just deal with it
@gokulravi7133
@gokulravi7133 5 лет назад
Dude my ball speed at the game is really high.. After doing the same as u did.. How can i reduce it.. And keep it to a normal
@rafaelperezmederos6958
@rafaelperezmederos6958 5 лет назад
also have the same issue
@AdurxIsd
@AdurxIsd 5 лет назад
dunno if you still have the problem, but reducing ball.dx and ball.dy to something like 0.2 insetad of 2 should help.
@zervakisgiorgos91
@zervakisgiorgos91 5 лет назад
Amazing tutorial, thank you very much for your time.
@kemdncucuirnwnnwhcucjje166
@kemdncucuirnwnnwhcucjje166 5 лет назад
Γιωργος Ζερβακης Πος είσαι my fellow Greek brother
@zervakisgiorgos91
@zervakisgiorgos91 5 лет назад
@@kemdncucuirnwnnwhcucjje166 καλησπέρα :) I am very well my friend! I watched your videos, keep the hard work!
@kemdncucuirnwnnwhcucjje166
@kemdncucuirnwnnwhcucjje166 5 лет назад
Thanks dude! I recently got a concussion so I missed some tournaments I’ll be back in a month or so
@coltonwilliams3176
@coltonwilliams3176 4 года назад
Don’t use spaces. Set your visual studio code text editor to use tabs ( seen in the bottom right corner of screen “Spaces”)
@sliferslacker6763
@sliferslacker6763 4 года назад
Personal Time stamp, please ignore. 19:55
@wehavedonuts7767
@wehavedonuts7767 4 года назад
A. Human no
@goku445
@goku445 4 года назад
Which kind of browser you use? On Firefox if you quit (closing tab) a video half way and come back, your session is saved where you left it.
@Acidpop
@Acidpop 4 года назад
@@goku445 thats because of youtube not Firefox
@crunchygs8771
@crunchygs8771 4 года назад
@@Acidpop lmao ikr i legit hit facepalm when i read that thank you for protecting and serving *massive salute*.
@cesag1329
@cesag1329 4 года назад
28:49 my ball trespasses the paddle b :(
@ibrah1m
@ibrah1m 4 года назад
were u able to fix this?
@randmorf
@randmorf 4 года назад
If the top and bottom parts of your paddle seems not to work, it's because in the code for the ball colliding with the paddle uses +40 and -40 to delimit the paddle. The paddle is 100px tall, and the code above uses only the middle 80px. To make the full paddle workable, the code should use +50 and -50. This change will need to be made in two places (remember those two horribly long if statements? That's where.).
@WilliamMarsokov
@WilliamMarsokov 4 года назад
That helped me alot to understand more of python programming thank you very much
@TokyoEdTech
@TokyoEdTech 3 года назад
You're welcome.
@Galileo3k
@Galileo3k 5 лет назад
Wow! You are really crystallizing many concepts of my early studies of python. I will watch more.
@BAOOOOOOOOOOOOOOOOOOOOOOOOOOOO
love code first
@BAOOOOOOOOOOOOOOOOOOOOOOOOOOOO
I wan't to learn but i english very bad
@mikemindacodemy7279
@mikemindacodemy7279 5 лет назад
Not to worry, you just need a basic understanding of english since logic and algorithms are more important🙄
@anupamkrishna7811
@anupamkrishna7811 5 лет назад
how to make pads smooth as the ball Can anyone please give a suggestion
@simonmoberg8906
@simonmoberg8906 5 лет назад
You can lower the size of the step it makes when you press your up & down key. However, this will make them slower. I guess there is a totally different approach to it, but I'm just a nub :). below i changed y += and +-= to 2, this makes it quite smooth, but too slow for the game. def paddle_a_up(): y = paddle_a.ycor() y += 2 paddle_a.sety(y) def paddle_a_down(): y = paddle_a.ycor() y -= 2 paddle_a.sety(y)
@anupamkrishna7811
@anupamkrishna7811 5 лет назад
@@simonmoberg8906 this is the only way I too think.. but as you said it will make the ball too slow that it wouldn't be able to cover the distance
@simonmoberg8906
@simonmoberg8906 5 лет назад
@@anupamkrishna7811 yea. I'm thinking you'd need an entire different approach (not turtle?). I'm quite sure it isn't impossible, but perhaps not best focus on at this stage of knowledge :).
@anupamkrishna7811
@anupamkrishna7811 5 лет назад
@@simonmoberg8906 Pygame will be good for this have you ever tried that?
@simonmoberg8906
@simonmoberg8906 5 лет назад
@@anupamkrishna7811 Actually just installed it to check it out to see the difference. Have you tried it?
@alyz2798
@alyz2798 5 лет назад
this is awesome. thank you sir
@jcc-gamem3047
@jcc-gamem3047 4 года назад
Hello, enjoying the tutorial so far but came across a problem where I tested the paddles and ball after programming and they wouldn’t appear! I doubled checked all the code and no syntax errors. They were just invisible, please help me with this issue soon and I would love to make this game and learn how to program
Далее
Make Pong With Python!
1:12:42
Просмотров 114 тыс.
Learning pygame by creating Snake [python tutorial]
2:05:00
The lightweights ended Round One with a BANG 💪
00:10
Python Django Web Framework - Full Course for Beginners
3:45:41
Machine Learning for Everybody - Full Course
3:53:53
2 YEARS of PYTHON Game Development in 5 Minutes!
4:54
Просмотров 888 тыс.
Python Algorithms for Interviews
3:47:08
Просмотров 806 тыс.
The ultimate introduction to Pygame
3:47:58
Просмотров 2,5 млн
Making a Game in Python with No Experience
5:57
Просмотров 1,6 млн
👩‍💻 Python for Beginners Tutorial
1:03:21
Просмотров 3,1 млн