Learning Pygame by making Pong

Поділитися
Вставка
  • Опубліковано 4 січ 2025

КОМЕНТАРІ • 419

  • @essayprometheus
    @essayprometheus 4 роки тому +362

    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 4 роки тому +3

      i am with yo

    • @A6h4v
      @A6h4v 3 роки тому +1

      @@NavjotSingh-zx3we reply to a reply

    • @A6h4v
      @A6h4v 3 роки тому

      GELOMILF

    • @ifergff2280
      @ifergff2280 3 роки тому +1

      U are not alone, we all are here👍👍

    • @mimic_ed
      @mimic_ed 5 місяців тому

      It's not small anymore🎉

  • @Tila1
    @Tila1 4 роки тому +168

    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 роки тому +2

      Thanks

    • @TN3.1
      @TN3.1 Рік тому +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!

  • @michaelshuvalov9100
    @michaelshuvalov9100 4 роки тому +143

    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 роки тому +17

      Thank you!

    • @thepaulcraft957
      @thepaulcraft957 3 роки тому +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 роки тому +2

      @@thepaulcraft957 Thats because Einstien's German, Yeah..!!

    • @yuka8286
      @yuka8286 2 роки тому +1

      @@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 роки тому +1

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

  • @micahcarter1332
    @micahcarter1332 4 роки тому +76

    You’ve done better explaining PyGame than the 90% of PyGame tutorials I’ve watched.

    • @itsspratham802
      @itsspratham802 3 роки тому

      yes,tech with tim and other coding channels were tooooo hard and explained complicated,i almost felt like quitting game devolopment but luckily in time i found clear code

    • @pathikghugare9918
      @pathikghugare9918 3 роки тому +1

      Yeah man really

  • @quasarcore
    @quasarcore 4 роки тому +22

    One of the best programming videos I've seen, super clear and concise explanations

  • @Harry-ub2fv
    @Harry-ub2fv 4 роки тому +28

    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()

  • @shantanubindhani1622
    @shantanubindhani1622 4 роки тому +7

    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

  • @yusufnusrat
    @yusufnusrat 4 роки тому +4

    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

  • @akshhat97
    @akshhat97 4 роки тому +2

    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 4 роки тому +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.

  • @abrarmasumabir3809
    @abrarmasumabir3809 3 роки тому +3

    This guy is so clear...he definitely deserves million of subscribers

  • @lousimms4766
    @lousimms4766 4 роки тому +5

    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 роки тому +1

      Thank you, glad it helped :) check out my channel, I already made lots more pygame tutorials

  • @rebornreaper194
    @rebornreaper194 3 роки тому +2

    Your presentation style is incredibly intuitive, tysm :D

  • @shourya9998
    @shourya9998 4 роки тому +1

    Best tutorial video I've ever seen!
    Hats off to this guy

  • @knull8508
    @knull8508 4 роки тому +3

    your explanation is so clear this is amazing !

  • @bepositive271
    @bepositive271 Рік тому

    For you kind information this is the first video of The world greatest coding teacher
    like the editing , voice , and the way of explaining is just perfect even in his first video
    I just want to say that he is a "Legend"

  • @adrienlenud
    @adrienlenud 3 роки тому +2

    Thank you so much, you explain things so simply and intuitively compared to the other ressources I was trying to use

  • @elib7911
    @elib7911 4 роки тому +6

    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 роки тому +1

      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

  • @AC-he8ln
    @AC-he8ln 2 роки тому

    I think these Pong videos are the best starting Pygame starting series on UA-cam. The others are also good but too complex for a first project.

  • @paradoxicalinsomniac9950
    @paradoxicalinsomniac9950 4 роки тому +4

    this is the best python tutorial i've ever seen in my life

  • @alooooshm
    @alooooshm 4 роки тому +7

    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

  • @yassinezanned9837
    @yassinezanned9837 3 роки тому +1

    Astonishing simplicity and amazing content from your part, sir. Thanks really much.

  • @knightmare6249
    @knightmare6249 4 роки тому +1

    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

  • @synthoelectro
    @synthoelectro 3 роки тому +1

    This guy has a personality, that's a good thing.

  • @yashshreeaute8108
    @yashshreeaute8108 3 роки тому

    This is the best channel I ever seen for self learners. keep it up Man!

  • @todd3578
    @todd3578 4 роки тому +3

    This video is amazing, you really know how to explain the code!

  • @jivinhipcat
    @jivinhipcat 4 роки тому +1

    I wish all videos were this good. Thanks for it man.

  • @Schachlover
    @Schachlover 4 роки тому +1

    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 роки тому +1

      Thank you so much 🙂

    • @Schachlover
      @Schachlover 4 роки тому +1

      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.

  • @DailyFacts698
    @DailyFacts698 Рік тому +2

    I don't know what python was like 3 years ago, but now I was able to make player moving by this lines:
    keys = pygame.key.get_pressed()
    ''''if key[pygame.K_UP:
    ''''''''self.player.x += 7
    and this works even when you hold the button :)

  • @aidan5077
    @aidan5077 4 роки тому +1

    Just made this after watching your flappy bird video. These tutorials are incredible

  • @mier7239
    @mier7239 4 роки тому +1

    Thank you very much for the tutorial - its very well explained - just a pointer on a little twitch in the game: the ball can get behind the 'players' and move weirdly alongside it until it gets out.

    • @ClearCode
      @ClearCode  4 роки тому

      Yes, that's true. Although it is only really a problem as long as the ball can bounce on the left and right side of the screen. Once that is removed and the ball just gets reset there it should be fine.

    • @jivinhipcat
      @jivinhipcat 4 роки тому

      I noticed the same thing. I think the ball can collide with the top and bottom surfaces of the player/opponent rect. It then changes the x direction but not the y, so it is still colliding with the same surface during the next move. It keeps changing the x direction this way until it works it's way all the way up/down the player/opponent rect. I tried adding this if-else statement to the collision detection and I think it fixes it. It's such a small amount of movement that you don't notice it, and it makes the ball begin from the infacing side of the player/opponent so the problem collision no longer happens.
      if ball.colliderect(player) or ball.colliderect(opponent):
      ball_speed_x *= -1
      if ball_speed_x > 0:
      ball.x = 30
      else:
      ball.x = screen_width - (ball_width + 30)
      *I think I have adjust the player/opponent paddle sizes to make them a little wider. I don't remember just now what they were originally.

    • @ClearCode
      @ClearCode  4 роки тому +1

      @@jivinhipcat Now I get it, that is indeed a bit of a bug. And your solution is workable but I would say that it doesn't achieve the right goal. Basically, when the ball hits either the top or bottom of the paddle, the player (or opponent) shouldn't be able to recover the ball anymore.
      A really quick solution would be to change the parameters when ball_start is called from 0 and screen_width to 15 and screen_width - 15. That way the ball starts when it is even a pixel beyond the paddle; and that removes the issue quite drastically. Doesn't look very good though.
      Another way would be to modify your approach to move the ball to the opposite direction that you send it; and that would trigger the the ball_start function on the next cycle of the while loop. But I don't think it would look good either since the ball would just disappear mid-air (kinda like the approach above).
      I think the best way to fix this issue would be to properly code a collision for the top and bottom of the paddles, so that we get a proper movement for it. I am planning on making more pygame tutorials anyway, I'll make a video how to fix it next week :)

    • @ClearCode
      @ClearCode  4 роки тому +1

      @@jivinhipcat Here is a good stack overflow answer that explains how to get collisions for different sides: stackoverflow.com/questions/20180594/pygame-collision-by-sides-of-sprite

    • @jivinhipcat
      @jivinhipcat 4 роки тому

      Clear Code nice. I didn’t even think that top/bottom contact should be considered bad, and that makes total sense. I’m just starting with code, and I really like the style of your videos. I’m still playing with this Pong game turning it into an abomination with sounds and images. I plan on watching all your videos as I go. Thanks for making them.

  • @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.

  • @spaidory874
    @spaidory874 2 роки тому

    Thanks bro. Your vids are cool and rly well edited. U are underrated.

  • @chigstardan7285
    @chigstardan7285 4 роки тому

    This is one of the best tutorials ive ever seen and the clarity is.... Muah.
    Keep up the good work

  • @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

  • @structuralcraft
    @structuralcraft 2 роки тому

    Your teaching outline is good to begin with

  • @dolphinman9802
    @dolphinman9802 2 роки тому +1

    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

  • @didyouknowsciences
    @didyouknowsciences 5 років тому +1

    Thanks for the tutorial as well as the clear and detailled explanations.

    • @ClearCode
      @ClearCode  5 років тому

      Glad you liked it, let me know if you want me to cover another Pygame topic

  • @semajislove2353
    @semajislove2353 4 роки тому +2

    My first Python project, thank you very much, Good Sir!

    • @ClearCode
      @ClearCode  4 роки тому +2

      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!

  • @bearwater8747
    @bearwater8747 3 місяці тому

    Just finished this video thank you for helping me learn, I am still a little confused but I am using you to teach myself.

  • @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

  • @Zellaaaaaaaaaaa
    @Zellaaaaaaaaaaa 2 роки тому +1

    Very informative and instructive tutorial! Thank you

  • @AmateurStoryteller
    @AmateurStoryteller 4 роки тому

    Clean and CLEAR beginner tutorial... as the channel name

  • @davependrell6653
    @davependrell6653 4 роки тому

    Awesome tutorial video. Your transitions and animations are super nice as well.

  • @qashrina4402
    @qashrina4402 4 роки тому

    Your explanations are so clear!! Thank you so much.

  • @TypeZ3R0
    @TypeZ3R0 4 роки тому

    BEST EVER EXPLANATION FOR PROGRAMMING. PLZ MAKE VIDEOS ON PYTHON MACHINE LEARNING, DEEPLEARNING AND COMPUTER VISION WITH PYTHON🙏🏽🙏🏽

  • @sudiptobusiness1503
    @sudiptobusiness1503 3 роки тому

    Your explanation is so clear..

  • @imherovirat
    @imherovirat 3 роки тому

    Subscribed, awesome, perfect,wonderful and really understandable, Thank you Clear Code for this amazing Content.

  • @mitchellfolbe8729
    @mitchellfolbe8729 4 роки тому +1

    Good exercise with good explanation. Thank you.

  • @hürriyetpalestine
    @hürriyetpalestine 9 місяців тому

    great explanation...hate other tutorials that just try to have you copy their code without explanation

  • @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*

  • @muradpetrosyan5128
    @muradpetrosyan5128 4 роки тому

    The best tutorial for PyGame

  • @freadbear9645
    @freadbear9645 Рік тому

    This was the first game I learned to make from scratch

  • @0x656e
    @0x656e 4 роки тому +2

    That was a really great video thank you very much for making this great video.

  • @sultanrasul2794
    @sultanrasul2794 3 роки тому

    Why do you not have 1+ million subs, people get this man too 1mil

  • @ktzplayz2601
    @ktzplayz2601 4 роки тому +1

    Amazing graphics and a thorough and great tutorial = fast sub :)

  • @hariharanm6705
    @hariharanm6705 4 роки тому

    No words to appreciate Clear Code. Is this a teamwork or all are done by yourself?

    • @ClearCode
      @ClearCode  4 роки тому +1

      hey, yes I am making it by myself (looks much harder than it actually is tbh)

  • @christianschaub160
    @christianschaub160 2 роки тому

    Amazing tutorial. Thank u for all the explanation step by step guy 😃💪

  • @polyeder2000
    @polyeder2000 3 роки тому +2

    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.

  • @kogulansaravanabawan2034
    @kogulansaravanabawan2034 2 роки тому +1

    Very use full sir!
    And please tell me how to create this game for mobile phones!

  • @gdd9866
    @gdd9866 2 роки тому

    Amazing and well explained.

  • @thelife8836
    @thelife8836 2 роки тому

    You are the best brother❤

  • @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

  • @magoninhogamer
    @magoninhogamer 4 роки тому +2

    finally a good pygame tutorial

    • @ClearCode
      @ClearCode  4 роки тому +1

      Thanks, I actually made quite a few by now :)

    • @magoninhogamer
      @magoninhogamer 4 роки тому +2

      @@ClearCode awesome! you deserve more attention :D

  • @KeremDemirtas
    @KeremDemirtas 3 роки тому +4

    Thanks for the tutorial. I just don't get one simple part. Why don't we need to declare player_speed as a global inside the player_animation finction but we need to declare ball_speed_x and ball_speed_y variables as globals inside the ball_animation function?

  • @rezashir3873
    @rezashir3873 Рік тому

    actually im zero in programing. i like to become hero in programing, like you. thank you

  • @jurkokubik6383
    @jurkokubik6383 4 роки тому +1

    this was a really good tutorial!

  • @kaberanshutisamuel1856
    @kaberanshutisamuel1856 11 місяців тому

    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

  • @lu34z
    @lu34z Рік тому +1

    For anybody having an error with the keys at 23:20 getting the error "K_DOWN not defined". All you have to do is at the top say "from pygame import *" and it should fix it.

  • @stefanleustean4253
    @stefanleustean4253 4 роки тому +1

    Really good tutorial!!

  • @abhalera
    @abhalera 4 роки тому

    Very nicely explained. Thanks

  • @pcslowhand
    @pcslowhand 4 роки тому +1

    Thanks very much for this video. It was really helpful :)

  • @ChaosArtist
    @ChaosArtist 3 роки тому

    Thanks for this tutorial, very helpful.

  • @dungngoquang8354
    @dungngoquang8354 11 місяців тому

    very useful, thank you so much!!!!

  • @iohellemans3280
    @iohellemans3280 2 роки тому

    great tutorial, loved it

  • @BabyQuasarX
    @BabyQuasarX Рік тому +2

    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?

  • @joeyh2185
    @joeyh2185 3 роки тому

    very well made and helpful :) cheers mate

  • @rafy-ivanmorales3077
    @rafy-ivanmorales3077 3 роки тому

    Rafy-Ivan Morales
    0 seconds ago
    I'm a new student trying to learn, so I can become a programmer with python and I have a project on how to make a port scan.
    So far I already make a port scan with Python3, and it scans fine, give a date and everything working good so far.
    I see on your video tutorial, it is very good.
    I would like to ask for your advice if you can and guide me on how I will add this 3
    in a Python script, I have:
    2. System should look for all the ports between the range of 1 to 1025
    3. If the Ports is open, it should create a file and add an entry for port number
    4. In case of any exception for instance “host is not available”, “host name could not be resolved” or
    due to any other error, you need to write that exception into the same file.
    Thank you and Merry Christmas.

  • @lucasreingo
    @lucasreingo 4 роки тому +2

    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 3 роки тому +1

      thanks it really made the program better but you also need to replace ' opponent.bottom ' with 'opponent.centerx'

    • @lucasreingo
      @lucasreingo 3 роки тому

      @@IGOverkill yh, soz I forgot that. Good luck on your pygame journey

  • @akiha7611
    @akiha7611 4 роки тому

    thank you very much for the tutorial, you teach very well bro

  • @erremazo
    @erremazo 3 роки тому

    Excelent video, thanks a lot.

  • @vedantpandey4079
    @vedantpandey4079 2 роки тому

    Hey, awesome tutorial, keep up the good work!
    One very minor error, at 17:41 it says "Colissions" instead of "Collisions".

  • @janl5242
    @janl5242 2 роки тому

    Great stuff, thanks :)

  • @munjolla
    @munjolla 4 роки тому +1

    Great tutorial!

  • @MrFeivelinho
    @MrFeivelinho 4 роки тому +1

    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?

  • @lorendaoust4443
    @lorendaoust4443 Рік тому

    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.

  • @saadedi75
    @saadedi75 2 роки тому

    thanks for all video

  • @kodaditank173
    @kodaditank173 Рік тому

    thank you u saved my life

  • @conorhogan6111
    @conorhogan6111 3 роки тому +1

    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?

  • @swiftal8312
    @swiftal8312 4 роки тому

    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

  • @mr.blobfish5535
    @mr.blobfish5535 Рік тому

    sympathisch. Man kann sich unterhalten.

  • @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

  • @leobozkir5425
    @leobozkir5425 4 роки тому +1

    I>>> SIMPLY>>> LOVE>>> IT>>>

  • @testvb6417
    @testvb6417 4 роки тому

    Pls more ur the best

  • @edwardchen4447
    @edwardchen4447 4 роки тому +3

    How do you not have like a million subs? just a question, HOW!?

  • @riya6549
    @riya6549 Рік тому +1

    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

  • @silverseacow
    @silverseacow 2 роки тому

    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 роки тому

    thanks! this was my first project so i had a lot of bugs but it was really fun! i will do part 2 soon!

  • @YakyuBoy
    @YakyuBoy 2 роки тому +1

    Why does ball_speed_x and ball_speed_y need a global definition but not player_speed?

    • @YakyuBoy
      @YakyuBoy 2 роки тому +1

      Nevermind, I saw your reply in another comment. Thank you!
      Clear Code
      2 years ago
      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 :)

  • @zhankam7308
    @zhankam7308 2 роки тому

    thanks for the video, but I have an error in PowerShell at the beginning