Pygame in 90 Minutes - For Beginners

แชร์
ฝัง
  • เผยแพร่เมื่อ 31 พ.ค. 2024
  • In this Pygame for beginners video, we'll be making a game in about 90 minutes. I'm going to cover a lot of stuff about Pygame in this video, including sound effects, images, moving objects, collision, most of the fundamental things you need to make a basic game. We'll be making a simple 2 player game to showcase how everything works in Pygame in python.
    💻 AlgoExpert is the coding interview prep platform that I used to ace my Microsoft and Shopify interviews. Check it out and get a discount on the platform using the code "techwithtim" algoexpert.io/techwithtim
    ⭐️ Timestamps ⭐️
    0:00 | Intro to Pygame
    2:39 | Installing Pygame
    4:09 | Working with Pygame
    📺 How to Install Pygame on Windows: • How to Install Pygame ...
    📺 How to Install Pygame on Mac: • How to Install Pygame ...
    📝 GitHub (Code Download): github.com/techwithtim/Pygame...
    ◼️◼️◼️◼️◼️◼️◼️◼️◼️◼️◼️◼️◼️◼️
    💰 Courses & Merch 💰
    💻 The Fundamentals of Programming w/ Python: tech-with-tim.teachable.com/p...
    👕 Merchandise: teespring.com/stores/tech-wit...
    🔗 Social Medias 🔗
    📸 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 TH-cam Gear 🎬
    🎥 Main Camera (EOS Canon 90D): amzn.to/3cY23y9
    🎥 Secondary Camera (Panasonic Lumix G7): amzn.to/3fl2iEV
    📹 Main Lens (EFS 24mm f/2.8): amzn.to/2Yuol5r
    🕹 Tripod: amzn.to/3hpSprv
    🎤 Main Microphone (Rode NT1): amzn.to/2HrZxXc
    🎤 Secondary Microphone (Synco Wireless Lapel System): amzn.to/3e07Swl
    🎤 Third Microphone (Rode NTG4+): amzn.to/3oi0v8Z
    ☀️ Lights: amzn.to/2ApeiXr
    ⌨ Keyboard (Daskeyboard 4Q): amzn.to/2YpN5vm
    🖱 Mouse (Logitech MX Master): amzn.to/2HsmRDN
    📸 Webcam (Logitech 1080p Pro): amzn.to/2B2IXcQ
    📢 Speaker (Beats Pill): amzn.to/2XYc5ef
    🎧 Headphones (Bose Quiet Comfort 35): amzn.to/2MWbl3e
    🌞 Lamp (BenQ E-reading Lamp): amzn.to/3e0UCr8
    🌞 Secondary Lamp (BenQ Screenbar Plus): amzn.to/30Dtafi
    💻 Monitor (BenQ EX2780Q): amzn.to/2HsmUPZ
    💻 Monitor (LG Ultrawide 34WN750): amzn.to/3dSD7tS
    🎙 Mic Boom Arm (Rode PSA 1): amzn.to/30EZw9m
    🎚 Audio Interface (Focusrite Scarlet 4i4): amzn.to/2TjXsih
    💸 Donations 💸
    💵 One-Time Donations: www.paypal.com/donate?hosted_...
    💰 Patreon: / techwithtim
    ◼️◼️◼️◼️◼️◼️◼️◼️◼️◼️◼️◼️◼️◼️
    ⭐️ Hashtags ⭐️
    #Pygame #Python #PythonPygame

ความคิดเห็น • 1.4K

  • @TechWithTim
    @TechWithTim  3 ปีที่แล้ว +356

    Start a high paying tech career making $60k+/year with NO DEBT: coursecareers.com/a/techwithtim

    • @Romirazer
      @Romirazer 3 ปีที่แล้ว +13

      @@jiaqiwang3793 Those mp3's work fine for me though

    • @uprola
      @uprola 3 ปีที่แล้ว +9

      pygame.mixer works only with raw files, like WAV. For mp3 you should use pygame.muic

    • @dimitriosdesmos4699
      @dimitriosdesmos4699 3 ปีที่แล้ว

      thank you for this so much

    • @py_tok5589
      @py_tok5589 3 ปีที่แล้ว +5

      It DID WORK, I think you forgot to place double brackets

    • @py_tok5589
      @py_tok5589 3 ปีที่แล้ว +3

      this way works the sound for me, mp3 files are NOT CORRUPTED

  • @TitaniumTronic
    @TitaniumTronic 2 ปีที่แล้ว +71

    How tf this dude can code for almost 2 hours and not open stack overflow and like 30 tabs? Wizard. Wizard I say.

    • @Wojtek_1777
      @Wojtek_1777 24 วันที่ผ่านมา +2

      No he is the chosen one ALL HAIL TECH WITH TIM

    • @theanonymoustechie
      @theanonymoustechie 14 วันที่ผ่านมา

      Techfuckery

    • @dlv5652
      @dlv5652 12 วันที่ผ่านมา

      Ha has the code on the side

  • @arcei5726
    @arcei5726 2 ปีที่แล้ว +181

    16:25 fps implementation
    17:44 creating and defining the spaceships
    32:39 movement keys

    • @RailwayPenguin
      @RailwayPenguin ปีที่แล้ว +1

      @@prodbyosp i think TH-cam automatically made those chapters

    • @jaredcortes366
      @jaredcortes366 ปีที่แล้ว +3

      @@RailwayPenguin i'm pretty sure they're made by the user

    • @ashters4204
      @ashters4204 ปีที่แล้ว +3

      @@RailwayPenguin all timestamps are made by the creator

    • @secretr5024
      @secretr5024 ปีที่แล้ว

      You are chad

  • @Fr4nk4000
    @Fr4nk4000 ปีที่แล้ว +81

    I just wanna tell you how much this helped me. I started out knowing nothing about pygame and when you went along with the video i actually did a lot of the things you did later myself, starting to understand how this all works. Now i'm adding things like powerups and i'm having a blast. Can't wait to show this to my buddies when summer vacation ends and we can play this together. I never thought i could make ANYTHING like this

    • @forzeferrari2668
      @forzeferrari2668 ปีที่แล้ว +10

      This attitude ^

    • @blackbeast8571
      @blackbeast8571 5 หลายเดือนก่อน +1

      This💫

    • @connie4587
      @connie4587 2 หลายเดือนก่อน

      Just starting this now. I hope to have some sort of game finished by the end of the summer so my friends and I can play!

  • @tholver5895
    @tholver5895 3 ปีที่แล้ว +9

    Thank you so much for the tutorial. I had a project in school where I had to pick a skill, learn it for a month, and make an end project and this video has made all the difference. I understood the parts of Python you were using, what they were doing, and how to modify them to fit my needs which is great. Very rarely do I find a tutorial that helps me learn rather than copy but I'm glad I found one today.

  • @kathleen_lalala
    @kathleen_lalala 2 ปีที่แล้ว +4

    Thank you Tim for this AMAZING tutorial! This is the first time I am able to follow through a coding video because I am a beginner and it was hard finding a tutorial that explain codes and train of thoughts in this much detail. I felt much more confident in coding now with this tutorial and am very motivated to learn more! Thanks a lot really :)

  • @siebedeerenberg8766
    @siebedeerenberg8766 3 ปีที่แล้ว +59

    Great tutorial! One small comment:
    When rotating the images, the height and width change as well. That is what caused the problems with border and that is why the bullets don't shoot out from the middle of the spaceship. And why the bullets start in front of the spaceship.(That's why Tim added + 15, which is the difference between height and weight, 55-40 = 15).
    To correct the border you can change yellow.height to yellow.width in the yellow_handle_movement.
    To correct the bullets, you can change yellow.width to yellow.height in the Main function at the bullet movement.(bullet = pygame.Rect(yellow.x + yellow.height, yellow.y + yellow.width//2 - 2, 10, 5))

  • @benhardsim8629
    @benhardsim8629 2 ปีที่แล้ว +2

    The way you always try to make the code a little bit more dynamic, really make this tutorial hundred times better. Thank you some much 😀

  • @mariusmuller3886
    @mariusmuller3886 2 ปีที่แล้ว +15

    I think the reason why can go further down than the button at 48:25 is that you've rotated the spaceship. So now height is technically width and width is height. If you change the variables in the if-statement it should work fine.

    • @SuperMarioGalaxySMG
      @SuperMarioGalaxySMG 5 หลายเดือนก่อน

      this and you guys should also change your movement if statements to take into account if red/yellow.x/y ± SPEED goes over your border so the if statements look like this
      if keys[pygame.K_w]:
      if yellow.y - SPEED >= 0:
      yellow.y -= SPEED
      else:
      yellow.y = 0
      if keys[pygame.K_a]:
      if yellow.x - SPEED >= 0:
      yellow.x -= SPEED
      else:
      yellow.x = 0
      if keys[pygame.K_s]:
      if yellow.y + SPEED + yellow.height

    • @shalevforfor5550
      @shalevforfor5550 5 หลายเดือนก่อน

      The width and hight is not only x and y

  • @JayeshSarvaiya
    @JayeshSarvaiya 3 ปีที่แล้ว +5

    Thank you so much Tim, such a wonderful tutorial ! You really made it look all very easy, glad that I found your channel on TH-cam ! 😀

  • @asolutezero1304
    @asolutezero1304 2 ปีที่แล้ว +11

    He is a great explainer.
    The way that he explains concepts is so cool.

  • @jakubskorski4473
    @jakubskorski4473 3 ปีที่แล้ว +1

    Great tutorial! I could say even the best out there. I was trying to follow many pygame tutorials but your one was the only one that explained everything well! Thanks!

  • @codeklaudia9696
    @codeklaudia9696 2 ปีที่แล้ว +1

    You are awesome. I did a 1,5 year program in information technologies, and have been working in C# since the last year. Your explanation about CPU frequency and frames per second is awesome. I really enjoyed your video

  • @thoserandomshredders
    @thoserandomshredders ปีที่แล้ว +5

    As a beginner python coder: your tutorials help me so much. Keep making them!

  • @agent-33
    @agent-33 3 ปีที่แล้ว +121

    You're a very good tutor, definitely an educator level. You explain what you write, the purpose and how a code or line of code is used. Readability is also important, the highlight effect, the zoom-in. Unlike most tutorial videos, they only say what they type which we (the viewers) are already looking at, or what is worse is they don't bother zooming in their codes, they are like texts from mini bible.
    Thank you so much.

    • @u2b842
      @u2b842 ปีที่แล้ว +1

      Hey thanks, but why not just changing SPACEHEIGHT to a higher number ?

    • @ldelamat1
      @ldelamat1 ปีที่แล้ว

      no he didnt help me

    • @BallisticGamer101
      @BallisticGamer101 5 หลายเดือนก่อน

      @@ldelamat1 Yep the first I watched this vid it was very confusing compared to other tutorials that I watched simply as I was a beginner but as I learnt more from other sources I came back to give this video a chance and it helped me a ton!

  • @galaxfire8591
    @galaxfire8591 3 ปีที่แล้ว +1

    Thank You So Much For This! I wanted to learn pygame and was looking for a great starter tutorial and without a doubt in my mind this was it! This and other tutorials made by you are always so high-quality. Again Thank You!

  • @johannesperez9548
    @johannesperez9548 2 ปีที่แล้ว +2

    I replaced the sound effects to wav format. Now works great. Thanks Tim for this awesome tutorial!

  • @xjud3
    @xjud3 2 ปีที่แล้ว +5

    I love your tutorials Tim, and something funny i found in the video:
    Tim: 'im gonna write some code and go abit faster now, but we gonna go through it after'
    Tim: going exactly the same nice and calm speed and explaining everything as he goes
    xD

  • @bloocifer
    @bloocifer 3 ปีที่แล้ว +4

    Im at 45:00 in your video, and granted i have taken everything very slowly and wrote special notes in my own code so i can come back and refer here, this is SOOO helpful. i was getting bored doing tutorials and this is making me have fun now. So far i have two working spaceships with the border in the middle and im sittin here so happy that i made it. Even if i was following ur code. Im gonna finish these and continue to do projects cuz im learning a lot of applications of the code as well as growing a little project base of my own that i can always come back to and refer to and look at my own notes about why the code is written the way it is, and its like my own little cheatsheet of code with applications that i KNOW work. Great vid! vscode makes this soooo much better too. i was still using IDLE before i switched to vsc lol

  • @rgblogic448
    @rgblogic448 3 ปีที่แล้ว +1

    Nice work! Had fun going through this an learning the basics of game dev with pygame. As simple as this program may be I will save it forever as my very first game project. Thanks Tim!

  • @donbedner6482
    @donbedner6482 2 ปีที่แล้ว

    A rare experience: Everything worked! Even the sound. I learned a lot. Thanks!

  • @pablolongobardi7240
    @pablolongobardi7240 2 ปีที่แล้ว +3

    Im at minute 15 and I already love this! I am an experienced developer, andf I appreciate a lot the detail and the easy explanations

  • @ayze_khla1783
    @ayze_khla1783 3 ปีที่แล้ว +40

    From the 6 hours full python tutorial to here....
    Thank u Tim~

    • @themathforyou
      @themathforyou 2 ปีที่แล้ว

      Are you talking about Mosh?

    • @harikishan1881
      @harikishan1881 2 ปีที่แล้ว +1

      @@themathforyou ofcourse

  • @gvigary1
    @gvigary1 ปีที่แล้ว

    I've done a bit of commercial Python (many years ago) but never used Pygame. I'm now trying to teach a friend's son how to program, and this tutorial was so clear and well structured that it'll make that job a lot easier. Great job!

  • @nickg1828
    @nickg1828 2 ปีที่แล้ว +2

    Thanks for the clear explanation on how pygame works. My final project for Python II is due in 2 weeks and you just saved my life.

  • @hemaanthsivakumar2118
    @hemaanthsivakumar2118 2 ปีที่แล้ว +56

    Loved the tutorial! The three hours I spent carefully going over each piece of the tutorial and taking notes really paid off - finally made my first pygame powered python game 😀. Hope you keep making amazing videos 🔥🔥🔥 ❤

  • @Arjunsiva
    @Arjunsiva 3 ปีที่แล้ว +5

    I can't even begin to describe how much grateful I'm for this video. Thanks a lot

  • @chrismat3417
    @chrismat3417 3 ปีที่แล้ว

    thank you so much, you dont know how much this means to me, i tried so many videos but none of them actually explained what they where typing and i had a problem installing pygame but after your tutorial in the description, i got it downloaded. So thank you so much and keep it up:)

  • @flioink
    @flioink 3 ปีที่แล้ว

    Nice tutorial, I like how the whole game loop timing is automated so you don't have to do the ting where
    you check if the time passed is less than FPS and if it is you wait.

  • @youmuq
    @youmuq 2 ปีที่แล้ว +4

    Thanks Tim for the great tutorial!
    The problem with sound likely is the file path. The filename has ‘+’, I removed that and works fine here.

  • @pbprimeplay
    @pbprimeplay 3 ปีที่แล้ว +106

    The perfect guide for pefecting the art of perfection in Pygame

    • @sailajaraman7067
      @sailajaraman7067 3 ปีที่แล้ว +4

      And that's perfectly true

    • @Kouka2005
      @Kouka2005 3 ปีที่แล้ว +1

      *PERFECTION*

    • @naveen5126
      @naveen5126 3 ปีที่แล้ว +2

      And I just found the perfect comment

    • @g3itnal
      @g3itnal 3 ปีที่แล้ว +2

      by the perfect person

    • @mysterry2000
      @mysterry2000 3 ปีที่แล้ว +2

      I love how he perfectly teaches and follows programming conventions, so perfect

  • @dip8
    @dip8 ปีที่แล้ว +1

    I enjoyed following this tutorial. Along the way i noticed some of your not syntax related mistakes which was cool, and i made my own sounds w sfxr. I love how simple and understandable are your explenations. Even tho the music didnt work i still this was great, thank you for posting this tutorial for free

  • @ND-ns2zu
    @ND-ns2zu 3 ปีที่แล้ว +1

    Dude thank you so much! this video is amazing and it is great to find someone who covers all the issues that might happen. you helped me a lot!

  • @artistpw
    @artistpw 2 ปีที่แล้ว +10

    This is a truly great tutorial! You could have just made little “pew, pew, pew” noises for the firing and “blam” for the collisions. That would have sounded cute!

  • @sanuk9650
    @sanuk9650 3 ปีที่แล้ว +168

    Hey Tim, Could you please make tutorials on Data Structures & Algorithms with Python..🤞 It would be very helpful.. Hope you would make tutorials on DS soon..😊😊

  • @Lighthammer18
    @Lighthammer18 2 ปีที่แล้ว +2

    Really nice that you kept the bugfixing in there because that's like 90% of the work. Showing how to fix code is almost as valuable as showing how to write new code.

  • @bluejay432
    @bluejay432 2 ปีที่แล้ว

    You just indirectly gave me a genius idea to handle window blits WAY more efficiently in my project THANK YOU SO MUCH!

  • @MattiHolden
    @MattiHolden 2 ปีที่แล้ว +3

    Hi Tim, Thanks for the great tutorial, the code and the assets. I think the problem with the ships going off the bottom and being way of the border etc,. is because the images were rotated but the ship's rectangles weren't. I just switched the width and heights where red and yellow were created and it removed the need for the adjustments. I apologise if you were already aware of this by now 😁

  • @MusicWizards
    @MusicWizards 2 ปีที่แล้ว +4

    I don't comment lot of videos, but this one was great.
    1) There was not only code from a to z, but every step was explained.
    2) Code that was made is obtainable for example.
    Thx DUDE! Two thumbs up!

  • @programminglifeio
    @programminglifeio 3 ปีที่แล้ว

    Really cool video, Tim! I come from a web / security background and I found this video super interesting. Keep it going!

  • @ZeynepC3
    @ZeynepC3 6 หลายเดือนก่อน +1

    I am grateful that you are zooming in on the code part.

  • @josecostarosa2526
    @josecostarosa2526 2 ปีที่แล้ว +11

    I've started learning python this week, coming for 2 months of learning C++, this has got me so excited,.
    I'm still a newbie programmer but these things just leave a person wanting more and more, it's very exciting and encouraging that someone starting with 0 programming skills can use these videos and other sources to learn and become a better progammer in my case as a great suplement for my ciber-security degree.
    Great video and all the best.

    • @nutsberserk1
      @nutsberserk1 2 ปีที่แล้ว +2

      Python is my first and only known language (not counting Scratch), I've been learning from high school classes, and making games has always seemed like an interesting idea!

    • @toso1038
      @toso1038 11 หลายเดือนก่อน

      @@nutsberserk1 is good to start with JS its just the easiest language. Not that useful but you will undersand programming very well

  • @rapdo7359
    @rapdo7359 2 ปีที่แล้ว +3

    This is pure gold! Thank you so much Tim, its really useful to learn new topics developing a project, even more so if you have such a great instructor like you. ❤

  • @Killermonkey5465
    @Killermonkey5465 ปีที่แล้ว +1

    So cool! I'm a first-time pygame user and this was such a cool experiance to walk through and take notes and expand on the process!!!

  • @laurablue7893
    @laurablue7893 2 ปีที่แล้ว +1

    I really appreciate the way you explain why things are the way they are!

  • @sharmakartikeya
    @sharmakartikeya 3 ปีที่แล้ว +3

    1:16:04 Just saving for now. Thanks Tim, super excited for 2D game-dev !!

  • @ParleysWoodedJourney
    @ParleysWoodedJourney ปีที่แล้ว +3

    You covered so much in just one video. Thank you.

  • @pedroramires8928
    @pedroramires8928 3 ปีที่แล้ว

    The thing that you explaining where to get stuff and how to download it and installing it is VERY HELPFUL !!!!!

  • @learningpythonaccount3909
    @learningpythonaccount3909 3 ปีที่แล้ว

    Thanks just finished making it! Feel like im learning a lot about pygame with u tim

  • @Fr4nk4000
    @Fr4nk4000 ปีที่แล้ว +14

    For anyone who followed the tutorial and want to practice more of what you learned, here's some things you could do to make the game better.
    -Add a collision check to the bullets so if they collide, they destroy each other
    -Add poer ups that you can pick up and will increase the amount of bullets you can fire, increase bullet speed etc...
    -Add a healt system so you can get hit more times before you die
    -You could also add a healtbar if you're adding a healt system
    -You can also add different firing modes, like holding down a different key will shoot 2 bullets next to each other etc...
    -You could also add a border that slowly shrinks the space you can move around to prevent stalemates
    -You could add a score system
    That's just some ideas that came to mind and i'm implementing some of them already myself

    • @sanjanam5833
      @sanjanam5833 ปีที่แล้ว

      Do you have complete code ?

    • @Fr4nk4000
      @Fr4nk4000 ปีที่แล้ว

      @@sanjanam5833 I do have the code for the game. I didn't follow it 100%. Theres not a devider in the middle and isntead of the space ship sprites i just use suqares. Also I didn't watch the entire tutorial i kinda finished it myself, but i works. Do you want the code?

    • @sanjanam5833
      @sanjanam5833 ปีที่แล้ว

      @@Fr4nk4000 yes please do send

  • @poisonfoxxy
    @poisonfoxxy 3 ปีที่แล้ว +12

    For your problem at 48:20 its actually a pretty easy fix the rectangles you drew for the spaceship to be blit in are rotated incorrect just change the height and width in the main
    Yours:
    red = pygame.Rect(100, 450, SPACESHIP_WIDTH, SPACESHIP_HEIGTH)
    Fixed:
    red = pygame.Rect(100, 450, SPACESHIP_HEIGHT, SPACESHIP_WIDTH)
    Change that for both and it should be fine :)
    This also fixes the greater distance to the middle border.
    But great tutorial!!!

  • @stephenwilliams5092
    @stephenwilliams5092 ปีที่แล้ว +2

    Thanks Tim, this was a great tutorial and I was able to get it working with a few hours of practice.

  • @ianfarquharson2933
    @ianfarquharson2933 ปีที่แล้ว

    Thanks a lot for making this, I really wanted to make a game in python for a long time, and you finally allowed me to do what I wanted!

  • @GL-ETC
    @GL-ETC 3 ปีที่แล้ว +29

    Thank you so much Tech With Tim, I am only 10 - though I've done some python before, and I can nearly completely understand everything!

  • @CHITUS
    @CHITUS 2 ปีที่แล้ว +3

    Thank you so much Tim, such a wonderful tutorial ! You really made it look all very easy, glad that I found your channel on TH-cam !

    • @arcei5726
      @arcei5726 2 ปีที่แล้ว

      found you again, for the third time!

    • @intelchip_x86
      @intelchip_x86 ปีที่แล้ว

      @@arcei5726 i feel like this channel is actually a bot channel

  • @vvs.on.laptop
    @vvs.on.laptop ปีที่แล้ว +1

    Thanks for this amazing tutorial! I forgot all about pygame and this kept me back up to date.

  • @omarhammoud2383
    @omarhammoud2383 3 ปีที่แล้ว +2

    Sound effets worked fine! Great work, keep going, thank you!

  • @koppany3678
    @koppany3678 2 ปีที่แล้ว +5

    The problem you had with the spaceship going off the border is because of mixing up height and width when you rotated the spaceship. Here is a correct version:
    def red_movement(keys_pressed, red):
    if keys_pressed[pygame.K_LEFT]: # if left key is pressed
    if (red.x - VEL - 5) < (WIDTH/2):
    pass
    else:
    red.x -= VEL
    if keys_pressed[pygame.K_RIGHT]:
    if (red.x + VEL + SPACESHIP_HEIGHT) > WIDTH:
    pass
    else:
    red.x += VEL
    if keys_pressed[pygame.K_DOWN]:
    if (red.y + 4 + SPACESHIP_WIDTH) > HEIGHT:
    pass
    else:
    red.y += VEL
    if keys_pressed[pygame.K_UP]:
    if (red.y - 4) < (HEIGHT -HEIGHT):
    pass
    else:
    red.y -= VELdef red_movement(keys_pressed, red):
    if keys_pressed[pygame.K_LEFT]: # if left key is pressed
    if (red.x - VEL - 5) < (WIDTH/2):
    pass
    else:
    red.x -= VEL
    if keys_pressed[pygame.K_RIGHT]:
    if (red.x + VEL + SPACESHIP_HEIGHT) > WIDTH:
    pass
    else:
    red.x += VEL
    if keys_pressed[pygame.K_DOWN]:
    if (red.y + 4 + SPACESHIP_WIDTH) > HEIGHT:
    pass
    else:
    red.y += VEL
    if keys_pressed[pygame.K_UP]:
    if (red.y - 4) < (HEIGHT -HEIGHT):
    pass
    else:
    red.y -= VEL

  • @SReaperz
    @SReaperz 3 ปีที่แล้ว +110

    For anyone else wondering why the bottom part of the ship was going through the bottom of the window and how to fix that without manually adding pixels to it
    the problem is that he set the width and height of the spaceship as constants... then he rotated the image by 90 degrees which made the height be the width and the width be the height so just switch the values around for the rects and that should make it so you don't have to manually adjust for not going through the top and bottom, and bullets properly hit the ship

    • @cc-to2jn
      @cc-to2jn 3 ปีที่แล้ว +1

      you genius

    • @johannesziaether3916
      @johannesziaether3916 3 ปีที่แล้ว +1

      Thank u !
      It's a tip that may serve in other projects too.

    • @demaxl732
      @demaxl732 3 ปีที่แล้ว +2

      i also figured it

    • @colederusha
      @colederusha 3 ปีที่แล้ว +1

      Thanks so much!

    • @Polygonepictures
      @Polygonepictures 3 ปีที่แล้ว +1

      I thaught of the same thing! Tricky one...

  • @noelatum8692
    @noelatum8692 ปีที่แล้ว +1

    I enjoyed every step of this tutorial. Thanks a lot. For the sound, I used (.wav) audio files instead of (.mp3) and it worked!

  • @beez1th636
    @beez1th636 2 ปีที่แล้ว

    Tim I got to tell you every time I look up something for coding your always there thanks for the help

  • @krypticsilver1736
    @krypticsilver1736 3 ปีที่แล้ว +3

    Amazing tutorial tim! Keep it up.

  • @jamesbessant9290
    @jamesbessant9290 3 ปีที่แล้ว +27

    11:58 That was my first ever pygame window so I think you'll find it was actually very exciting!!

    • @nopens
      @nopens 3 ปีที่แล้ว

      Hawkeye, my man!

  • @eriswu3725
    @eriswu3725 2 ปีที่แล้ว +1

    Extremely clear and easy to understand! Thank you soooooo much! ❤️❤️

  • @OliverCaneteOfficial
    @OliverCaneteOfficial ปีที่แล้ว

    Thanks a lot dude. Very educational video. Really good and "hands-on" way to get started with pygame. Keep it up!

  • @data.artist
    @data.artist 2 ปีที่แล้ว +5

    Also find out is that it is best to move the if winner_text != "" section to after draw_window in the main(), this will allow the health to be properly displayed to 0, then the game will show who is the winner. Whereas original setup will declare the winner when the health is still showing 1. hopefully this helps anyone wanting to make the game even more polished.

    • @Cabarnacus
      @Cabarnacus 2 ปีที่แล้ว

      I second this one and I did the same.

  • @deanjordan6053
    @deanjordan6053 3 ปีที่แล้ว +290

    The fact that he kept going even when he spilled water on himself-

    • @josephstalin2647
      @josephstalin2647 3 ปีที่แล้ว +24

      yeah

    • @umanglunia2194
      @umanglunia2194 3 ปีที่แล้ว +33

      So nice seeing 2 of the greatest minds in the same comment :)

    • @imanoob128
      @imanoob128 3 ปีที่แล้ว +7

      @@umanglunia2194 lmao

    • @diarrheagaming6215
      @diarrheagaming6215 3 ปีที่แล้ว +3

      commie

    • @vamsi8569
      @vamsi8569 2 ปีที่แล้ว +5

      @@diarrheagaming6215 its dripping on your username :P

  • @hockeyandtacos5153
    @hockeyandtacos5153 2 ปีที่แล้ว +1

    Finally, a great tutorial for pygame, got this game working on my said in about 3 hours and it was so worth it!

  • @colederusha
    @colederusha 3 ปีที่แล้ว

    Thank you so much! This is the best Pygame tutorial I have found so far.

  • @tungarafrog2549
    @tungarafrog2549 3 ปีที่แล้ว +183

    Hi Tim, it is unlikely that you will see this but I just want to thank you for all of your Great tutorials. I would also like to ask if you could show a more advanced version of this tutorial or maybe how to make a platformer game with gravity and other stuff.

    • @richardreif3407
      @richardreif3407 3 ปีที่แล้ว +4

      I'm the same I really like it. Thank you very much. :)

    • @flaviomarcelo9044
      @flaviomarcelo9044 2 ปีที่แล้ว +3

      @Krishnansh Agarwal Identical Sublime Text Monokai theme

    • @mrgasmask7584
      @mrgasmask7584 2 ปีที่แล้ว

      You know its actually not that hard to imploment gravity

    • @dominicballinger6536
      @dominicballinger6536 2 ปีที่แล้ว

      Gravity should be simple, remember the example he used to show movement on screen before button presses? Do that, but down.

    • @tungarafrog2549
      @tungarafrog2549 2 ปีที่แล้ว

      @@dominicballinger6536 thanks, I realize how to do that, what I was having trouble doing was making it so that the player can stand on solid blocks and collide with them from all directions.

  • @jonathanferrer8623
    @jonathanferrer8623 ปีที่แล้ว

    I absolutely love this tutorial!! I was able to get the sound working by changing the names

  • @mr.shroom4280
    @mr.shroom4280 2 ปีที่แล้ว +1

    Thanks so much for the tutorial it really helps, I've mastered C# and I'm moving on to python and wanting to master it, you've helped me on my journey to master python. Thankyou so much for your quality tutorials!

  • @mythicshop1639
    @mythicshop1639 3 ปีที่แล้ว +17

    I'm new to coding and was struggling after the basics, this really helped me to get an insight and i watched a bunch of tutorials and was almost on the verge of loosing hope. Most of the videos out there are hard to understand with the logic maybe because they don't know or they just posting it for the views. but your contents are really different and you know what you talking about, Teaching or programming you will reach great heights bro. Thanks again , Love your content. wish that you had more followers so you can earn profit and we can get some proper intel. Guys other than watching toxic tik tok suggestion Give a thumbs up here.

  • @Frosty-dq2jw
    @Frosty-dq2jw 2 ปีที่แล้ว +27

    Hey the problem with ships not moving good around the border (going under the screen and cant touch the border on the right) is because we made our hitboxes/collision before they were rotated , so collision boxes are placed horizontal and not vertical , all you have to do is switch the SPACESHIP_WIDTH and SPACESHIP_HEIGHT values but then switch them while scaling the picture (YELLOW_SPACESHIP and RED_SPACESHIP), anyway thank you for getting me into python programming @Tech With Tim !

  • @__beginnerscode__3584
    @__beginnerscode__3584 3 ปีที่แล้ว

    Very helpful! Thanks for this guide, your video's make things seem so easy!

  • @ChaosArtist
    @ChaosArtist 2 ปีที่แล้ว

    Thanks for this tutorial. It's the first complete game I worked through using pygame. Thanks for the tutorial.

  • @tanmaygautam1348
    @tanmaygautam1348 3 ปีที่แล้ว +7

    Hey Tim, We need a video on some hashing algorithms python btw I also need this video.
    Thanks Tim.

  • @mantawhitest1895
    @mantawhitest1895 2 ปีที่แล้ว +7

    This guy is severely underrated.

  • @sprinter5901
    @sprinter5901 ปีที่แล้ว +1

    37:36 you have no idea how much happy I was when I reached till this point. Even the simplest thing can make a person soo happy

  • @mateuszstasiak6861
    @mateuszstasiak6861 3 ปีที่แล้ว +2

    48:20
    It is because in line 43 we put yellow.height instead of yellow.width. We rotated the spaceship image so now the vertical size is width and the horizontal size is height.

  • @Dracevui
    @Dracevui 3 ปีที่แล้ว +10

    for anyone getting a 'pygame.error: video system not initialized' error - just import the 'sys' module and add the 'sys.exit()' function underneath the pygame.quit() function
    learned that trick from the flappy bird tutorial lmao

    • @L0wPressure
      @L0wPressure 3 ปีที่แล้ว

      Thank you mate, and good day to you!

    • @xenonguard
      @xenonguard 3 ปีที่แล้ว

      Could not get 'sys.exit()' to work for me. However modifying the following at the end, worked:
      if running == True:
      main()
      else:
      pygame.quit()

    • @saadadchoudhury7163
      @saadadchoudhury7163 3 ปีที่แล้ว

      Thank you!

    • @xklepx
      @xklepx ปีที่แล้ว

      'sys.exit()' worked for me -- thx mate!!
      now I can close it w/o an error after passing through auto-py-to-exe lol

  • @allenliu9860
    @allenliu9860 3 ปีที่แล้ว +1

    Incredible tutorial, I really appreciate your effort! Thank you so much

  • @salmanalsaffar8040
    @salmanalsaffar8040 3 ปีที่แล้ว +1

    Thanks I've finished it all and the sound affects are working with me because I use my own sound affects.

  • @tdpencil2811
    @tdpencil2811 3 ปีที่แล้ว +35

    Thank you so much. After I watch this, I hope I'll be able to create fun games for some kids in my neighborhood!

  • @9Kino3
    @9Kino3 2 ปีที่แล้ว +6

    Instead of duplicating, you could use the same function to handle both red and yellow keypresses. Just use the player variable to decide which ship to move, less unnecessary code repetition

  • @notbob4271
    @notbob4271 2 ปีที่แล้ว

    This video was amazing, it really got me through my school project, thank you.

  • @rmccloud
    @rmccloud 2 ปีที่แล้ว

    Hey Tim, great tutorial!
    I enjoyed playing around and tweaking the code some and did manage to figure out the reason for the large space between the ship and the border (49:30). If incrementing yellow.x by the value for VEL put yellow.x past BORDER.x then yellow.x wouldn't update. I think your value for VEL was large enough to leave a sizeable gap.
    Instead of adding the and condition to the "if key_pressed[pygame.K_d]:" statement, I put another if inside that statement to check if it was past the border and then set yellow.x to the very edge instead of leaving it at its current position.
    if keys_pressed[pygame.K_d]: # RIGHT
    yellow.x += VEL
    if yellow.x > BORDER.x - yellow.height:
    yellow.x = BORDER.x - yellow.height
    Now the yellow ship can go all the way flush with the border with no gap!

  • @ianyourgod
    @ianyourgod 2 ปีที่แล้ว +5

    I tried to make my own simple game engine once, and the reason the coordinate system is like that is because it makes it easier to update the screen

  • @ayaanp
    @ayaanp 3 ปีที่แล้ว +4

    I was wanting to learn PyGame as I hadn't really done anything with it before, and this video just came out. You're actually amazing

  • @eazyaviation
    @eazyaviation 2 ปีที่แล้ว

    OMG thanks so much no other py game tutorials have worked for me! This is so helpful!

  • @sepehr6221
    @sepehr6221 ปีที่แล้ว

    Thank you so much for the tutorial, the sound effects actually worked fine for me, thank you again.

  • @Melvinn27
    @Melvinn27 2 ปีที่แล้ว +3

    This was such a good tutorial. As a beginner to pygame this gave me so many things to play around with. Thank you!

  • @freshness_of_air7909
    @freshness_of_air7909 3 ปีที่แล้ว +7

    i was genuinely shocked when i saw his face for the first time

  • @Shadowsdreamer123
    @Shadowsdreamer123 2 ปีที่แล้ว

    Thanks again. I was able to follow along to the end. Great explanation! ✌️

  • @shikhargupta6626
    @shikhargupta6626 ปีที่แล้ว +1

    Thank you for this amazing tutorial Tim!

  • @Unity_Particle_System
    @Unity_Particle_System 3 ปีที่แล้ว +3

    I will do this great tutorial as many times as possible until I can teach Pygame to others. As Tim said in another video, the best way to learn is to teach.

  • @petersteenkamp
    @petersteenkamp 3 ปีที่แล้ว +20

    One thing I'm worried about is when you finish a game round, you restart by calling the main() function from within the main() function. This means that the original call to the main() function never gets closed. Wouldn't this cause an increase in memory use after every game round? Given that this is a simple game, you'd probably need to play an insane number of rounds before your computer crashes with an "out of memory error" or similar, but if the game was much bigger, this may become a problem.
    How about not calling main() in line 177 and instead change line 180+ to:
    if __name__ == "__main__":
    while True:
    main()

    • @mbenz3145
      @mbenz3145 2 ปีที่แล้ว +1

      Or use continue instead of break statement....

    • @patlow
      @patlow 2 ปีที่แล้ว

      @@mbenz3145 that wouldn't work, continue cannot be used

  • @jamm9848
    @jamm9848 2 ปีที่แล้ว

    Hi Tim, i followed your tutorials from start to end and man your good i feel like a pro now , and thanks again i wise you all the best

  • @PodHighlights9
    @PodHighlights9 3 ปีที่แล้ว

    This was a great informative video. thanks Tim on helping me make my own game!

  • @jiaqiwang3793
    @jiaqiwang3793 3 ปีที่แล้ว +6

    Hey Tim, found the cause of your problem at 48:20 with the ship going outside the screen. Because you have rotated the image now the width and height have swapped thus your image does not match the rect anymore.
    Loved your video by the way!