Pygame Car Racing Tutorial #1 - Moving The Car

Sdílet
Vložit
  • čas přidán 8. 07. 2024
  • Welcome back to a new tutorial series! In this series, we'll go over making a car racing game in Python. We'll be using one of my favorite modules, Pygame.
    💻 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
    📄 Resources 📄
    Download Image Assets: dev-cms.us-east-1.linodeobjec...
    Code In This Video: github.com/techwithtim/Pygame...
    Learn Python OOP: • Python Object Oriented...
    Fix Pip (Mac): • How to Install Pygame ...
    Fix Pip (Windows): • How to Install Pygame ...
    📚 Playlist: • Pygame Car Racing Tuto...
    ⭐️ Timestamps ⭐️
    00:00 | Game Information and Demo
    03:02 | Setup and Pygame Installation
    06:00 | Loading Images/Assets
    08:01 | Creating the Pygame Windows
    10:19 | Displaying Images
    15:45 | Resizing Images
    21:20 | Rotating The Car
    34:35 | Key Presses and Turning
    36:28 | Acceleration and Velocity
    40:21 | Moving The Car By An Angle
    47:28 | Slowing Down The Car
    ◼️◼️◼️◼️◼️◼️◼️◼️◼️◼️◼️◼️◼️◼️
    💰 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 CZcams 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
    ◼️◼️◼️◼️◼️◼️◼️◼️◼️◼️◼️◼️◼️◼️
    ⭐️ Tags ⭐️
    - Tech With Tim
    - Pygame
    - Displaying Images
    - Acceleration
    - Velocity
    - Algoexpert
    ⭐️ Hashtags ⭐️
    #TechWithTim #PythonGame

Komentáře • 193

  • @TechWithTim
    @TechWithTim  Před 2 lety +27

    If you’re having trouble downloading the assets please try getting them from GitHub! Both links are in the description. :)

    • @sweetkalibur
      @sweetkalibur Před 2 lety

      hey, im trying to make it such that you can collide with the bot car but the bot cars direction doesnt change. can you make a video on that?

    • @shauryaplayz1076
      @shauryaplayz1076 Před rokem

      I still can't download it on mac. Can you help : )

  • @ookii5795
    @ookii5795 Před 2 lety +68

    My man Tim always keeps coming back to Pygame ❤️ It's so addictive

  • @henryash413
    @henryash413 Před 2 lety +22

    This is your best Python series yet!!!
    I've been waiting for a more advanced Pygame tutorial with OOP and all this angle stuff is great!

  • @XenkoVence
    @XenkoVence Před 2 lety +24

    Finally, a pygame tutorial that teaches you how to realistically use it. I can't tell you how long I've been looking for one of these. So many of the pygame tutorials out there just show you what you CAN do but never expand on HOW to actually use it, especially not in a real world environment.

  • @austinjeng2780
    @austinjeng2780 Před 2 lety +11

    Tim is literally the best python youtuber out here saving us from bad professors.

  • @just_for_funarts9905
    @just_for_funarts9905 Před 2 lety +1

    I have learned so much with the previous courses done by Tim for pygame. Through his tutorial, I am now able to create my first game and I have been able to progress my programming skill so much by following his tutorials. Really a Big Thanks to Tim for taking the time to create another awesome tutorial on for this great module.

  • @Lord_Arkham
    @Lord_Arkham Před 2 lety +1

    Wonderful tutorial Tim! This is a very inspiring tutorial! Keep them coming :D!

  • @ankitaburman5406
    @ankitaburman5406 Před 2 lety +1

    Loving this series Tim

  • @TheOrigamiKnight
    @TheOrigamiKnight Před rokem +1

    Thank you for this tutorial. I was looking for movement in a direction and you are the only one who has helped me.

  • @noah_ishappy
    @noah_ishappy Před 2 lety +10

    Im proud to be early in this new series

  • @danielros7798
    @danielros7798 Před 2 lety +1

    Great video, I'm looking forward to the next one

  • @NaJoeLibre
    @NaJoeLibre Před 23 dny

    Love this. I can't believe I'm understanding what you're talking about and I'm not even following along with python. Crazy I've come this far! Also my wife's a math teacher and I told her to show the trig piece to see how math is used in real life.

  • @rr-qj9fz
    @rr-qj9fz Před 2 lety +1

    Thank you Tim for making such great vid.

  • @rconr007
    @rconr007 Před 2 lety +1

    This is awesome. I think you have explained it quite right.

  • @fovu959
    @fovu959 Před 2 lety +1

    Best programming channel ever, u really helped me!

  • @Myrslokstok
    @Myrslokstok Před 2 lety

    Very easy to listen to this guy, no nonsen, free fluent and good tempo.

  • @rochakadhikari9264
    @rochakadhikari9264 Před 2 lety +5

    Love from Nepal, keep inspiring us with these project ideas❤

  • @promisesheggs8863
    @promisesheggs8863 Před 2 lety +4

    Thanks, Tim, your tutorials are always inspiring, they make me push my limits. I am having some challenges using pygame's Joystick module and the hat-keys on the gamepad for rotating and moving a sprite, I would be glad if you could help me out with that. Thanks once more Tim.

  • @aassemsehsah3825
    @aassemsehsah3825 Před 2 lety +1

    Keep up the good work. I love your videos.

  • @Flashxyz123
    @Flashxyz123 Před 2 lety

    Love it Tim your the best coder on youtube thanks for doing it really appreciate it

  • @shoppasshoppas611
    @shoppasshoppas611 Před 2 lety +1

    Keep up the great work!

  • @david100awesome
    @david100awesome Před 2 lety +1

    reliable tim. Been following u since 2018!

  • @Kumek01
    @Kumek01 Před 2 lety +13

    I have a game idea. Started with gamemaker a year and a half ago. But they kept changing/upgrading the engine which is good for the people who use it, but is hell for someone who doesnt know how to program. Then, my licence expired after a year, and everything stopped for me. Recently they changed the licencing terms, and got to think about continuing on my game. But, even tho i did learn some programing with GM, i felt something was wrong. So i started to learn python.
    Now, i am still grasping the basics, but i have better understanding how code works. How things are structured. Im learning how to program, not how game engine works, and what are its features.... Even tho i finally understand why some things in GM are the way it is.
    This tutorials are still over my grasp, but still i like to check them out, look at the concepts, how you structure things, how you use something.
    One day i will make my masterpiece :D

  • @MahmudShuaib
    @MahmudShuaib Před 2 lety +1

    damn it tim! your killing us! keep it coming!!!!!!

  • @lukeBalmar
    @lukeBalmar Před 2 lety +4

    Love from Ethiopia, Thanks for the video Tim !

  • @ExCenterProductions
    @ExCenterProductions Před 2 lety

    Thank you very much for posting this!

  • @boolean0_046
    @boolean0_046 Před 2 lety

    Congrats on one mil subscribers

  • @etteo6979
    @etteo6979 Před 2 lety +1

    Great tutorial. Took a while to understand that rotated image center. Got it! Thanks

    • @tushaljain5726
      @tushaljain5726 Před rokem

      hey ET TEO i need your help in my car racing porject game please send me your emial id or something wos that i can contact you i really need an urgent hel of yours please provide me your contact please reply to the comment urgently need your help please help in image rotation please help me it would great ehlp from your side i m from INDIA please help me please

  • @thepetiteotaku
    @thepetiteotaku Před 2 lety

    love ur channel!

  • @ilikeyoursmile6215
    @ilikeyoursmile6215 Před 2 lety

    Idk how to Thank you back? I guess Thank you is the only thing I can do. Thanks Tim

  • @khizrshaikh9902
    @khizrshaikh9902 Před 2 lety

    We really want like this type of awesome projects

  • @talhaajraou9886
    @talhaajraou9886 Před 2 lety +1

    So cool tutorial thanks a lot keep going

  • @IcyJack248
    @IcyJack248 Před 2 lety

    Respect boy. You‘re a boy with talent

  • @mrbeastjr7968
    @mrbeastjr7968 Před 2 lety +1

    Bro thanks for this lesson... trying to make mine now ❤️❤️❤️

  • @talhaajraou9886
    @talhaajraou9886 Před 2 lety

    I really like your python videos
    theire the best

  • @j2frostygaming870
    @j2frostygaming870 Před 2 lety

    very nice and clear turorial!

    • @tushaljain5726
      @tushaljain5726 Před rokem

      hey J2frosty i need your help in my car racing porject game please send me your emial id or something wos that i can contact you i really need an urgent hel of yours please provide me your contact please reply to the comment urgently need your help

  • @tuhinbhowmick8424
    @tuhinbhowmick8424 Před 2 lety

    Just thought yesterday let's make a pygame project . I earlier make a pygame ball game but due to some reason I lost that..😓 .So I thought to recreate the game . But I forgot the pygame syntax. Now I got a tutorial to brush up my memory. Tim you are a mind reader.....

  • @justins7796
    @justins7796 Před 2 lety

    this little car project kicked my butt lol

  • @pic01
    @pic01 Před 2 lety +1

    I'll try to get along as Tim is good at instructing

  • @Jcmacielh
    @Jcmacielh Před 2 lety

    Nice job!!

  • @CandelGaming
    @CandelGaming Před 2 lety +1

    so hardworking boy😨❤️❤️❤️❤️

  • @PersiusKane
    @PersiusKane Před 2 lety +1

    It's fun to watch when he talks about trigonometry "A NERDS CANDY" banner sneaks in to the frames. :-)

  • @PP-tc1zp
    @PP-tc1zp Před 2 lety +1

    Thank You! Now I have to play Dirt rally 2 and Car Racing pygame 😉

  • @pseudounknow5559
    @pseudounknow5559 Před 2 lety +1

    Niiice ! We like more advanced stuff in Python

    • @tushaljain5726
      @tushaljain5726 Před rokem

      hey tim i need your help in my car racing project game please send me your emial id or something wos that i can contact you i really need an urgent hel of yours please provide me your contact please reply to the comment urgently need your help

  • @ash_2279
    @ash_2279 Před 2 lety

    Glad Tim's back with a pygame tutorial, but it is any one else having problems with the assets link?

  • @vishallazrus7353
    @vishallazrus7353 Před 2 lety +7

    Love from India ❤️, thank you for ameging video 😀.

  • @paulubakanma0
    @paulubakanma0 Před 2 lety

    I FOUND IT INTERSTING, THANKS FOR YOUR UPLOAD AND LECTURING, GOD BLESS

    • @paulubakanma0
      @paulubakanma0 Před rokem

      I forgot to appreciate you for making the codes available. God bless you in His Will. Thank you

  • @b4xin802
    @b4xin802 Před 2 lety

    thanks tim 🤍🔥

  • @melissaleigh3013
    @melissaleigh3013 Před 2 lety

    New Tim album drop lets goooooo

  • @braidencrow7534
    @braidencrow7534 Před rokem

    "dont worry abt inheritance" continues to give a basic description of inheritance lol

  • @esdeath1236
    @esdeath1236 Před 2 lety +1

    Hey, Tim can you tell me what game engine did you use for your "12 hour coding Livestream" about a year ago

  • @tahirahmed96
    @tahirahmed96 Před 2 lety +1

    Damn that is some heavy maths right there, I should've focused more on my maths class damn.

  • @Life-zx5wp
    @Life-zx5wp Před 2 lety

    my fan :)

  • @omkarpatil9707
    @omkarpatil9707 Před 2 lety +1

    Hey Tim Tim🔥🔥

  • @davidcalebpaterson7101
    @davidcalebpaterson7101 Před 2 lety +1

    This is nice series. I would like to do this but only using tkinter, time and math I guess.

  • @murphygreen8484
    @murphygreen8484 Před 2 lety +1

    Didn't realize I was going to get a good Kahn Academy math less in trig with my awesome PyGame tutorial! Thanks Tim! (what was up with the nerds photo-bombing your paint window though?)

  • @thestickbuster1852
    @thestickbuster1852 Před rokem

    thx tim

  • @varunshrivastava2706
    @varunshrivastava2706 Před 2 lety +1

    Hey can some one tell me that in my screen the window that we create is really big. How can I make it small? I have given its height and width equal to that of track.

  • @programmingwithraahim
    @programmingwithraahim Před 2 lety +6

    In the starting of video, Tim : I will try my best to explain everything.
    In the middle of video, Tim : I don't know I just copied the code from stackoverflow.
    by the way great series as always Tim.

  • @Poylman
    @Poylman Před 2 lety +1

    Goat

  • @shohanurrahman5932
    @shohanurrahman5932 Před 2 lety

    Waiting for more

  • @xhjb4ever
    @xhjb4ever Před 2 lety

    thank you

  • @Iamhnd
    @Iamhnd Před 6 měsíci

    How we can extract border of the track from image???

  • @humzahnouman3760
    @humzahnouman3760 Před 2 lety

    Hey Tim,
    I am using a chromebook and when I try clicking on the same img link it isn't loading.
    I tryed copy and pating in new browser but it's just plain white.
    Is it because I am using Chrom OS?

  • @doyill5928
    @doyill5928 Před 2 lety +1

    how do i make it so the top of my window is orange like at 18:45

  • @hometvfirestick
    @hometvfirestick Před 2 lety

    Thanks

  • @fermienrico
    @fermienrico Před 2 lety

    Tim What is that thing came into the screen when you explaining angles on paint?
    And also we are waiting for the next video...

  • @Wraient
    @Wraient Před 2 lety +2

    This series is awesome and i am looking forward for you tutorial on chess in pygame i made a bit of it but got stuck.

    • @Myrslokstok
      @Myrslokstok Před 2 lety +1

      Wow chess and pygame, amazing 🤩

  • @elliasmwangi32
    @elliasmwangi32 Před 2 lety +2

    Hey Tim, do you have the tutorial on your website?

  • @marcusaureliusregulus2833

    Would that car movement work with camera movements in something like THREEjs?

  • @Queso791
    @Queso791 Před 2 lety

    I like how he explain the video

  • @MercyFromOverwatch2
    @MercyFromOverwatch2 Před 2 lety

    My man

  • @binyameenpehlari7419
    @binyameenpehlari7419 Před rokem

    anyoneknows why the class was created in the way it was. I mean why specific variables were defined as class attributes and specific variables were taken in innit. Is there any reason in particular for that, is there something we should keep in mind while defining class attributes and innit arguments ??

  • @mdmohidulhasan588
    @mdmohidulhasan588 Před 2 lety

    Hello Tim,
    Are you planning on applying Reinforcement learning or Genetic Algorithm like Neat on this game later when you finish coding the game?

  • @alkhiljohn7640
    @alkhiljohn7640 Před 2 lety +1

    I still need more work with the trigonometry; do you have a trig tutorial?

  • @abdul0mar
    @abdul0mar Před 2 lety +3

    can you make more of the opencv series?

  • @user-rk3yq8rt3g
    @user-rk3yq8rt3g Před 3 měsíci

    where did you download the images from? the antivirus says they have something malicious

  • @atharvbindal2058
    @atharvbindal2058 Před 2 lety +1

    Congratulations on being early, claim your before 100k views 🍪 here

  • @diemekalombo2949
    @diemekalombo2949 Před 2 lety

    On the line of code that says:
    blit_rotate_center(win, self.img, (self.x, self.y), self.angle)
    There was an error that said:
    blit_rotate_center() takes 3 positional arguments but 4 were given.
    Can someone help me out?

  • @turcopole.
    @turcopole. Před 2 lety +4

    Pygame is love pygame is life.

  • @cluelessProgrammer1
    @cluelessProgrammer1 Před rokem

    So i have a problem in this part 31:21 ,I always get the Unresolved attribute reference 'IMG' for class 'AbstractCar also for the START_POS. Also in the def draw(win, images), I got this Shadows name 'images' from outer scope . I tried using chatgpt to find whats wrong, it give me a code where i put super. in class PlayerCar, and after that, it doesnt show anything. Please help me, I'm stuck here and I still don't know what to change.

  • @johnniegilkerson4724
    @johnniegilkerson4724 Před 2 lety

    Hi Tim, can't do pygame in vscode:
    "pygame" is not accessedPylance
    Import "pygame" could not be resolvedPylancereportMissingImports
    Do you have any suggestions?
    thanks

  • @imperialmuffin
    @imperialmuffin Před 2 lety

    No way he is actually doing this!!!

  • @aarjavjain2675
    @aarjavjain2675 Před 2 lety

    Hey Tim what’s your color scheme it looks amazing!

  • @21ninpo
    @21ninpo Před 2 lety

    i wanna download python and i noticed that your version is not the latest. which should i download and how?

  • @alexany4619
    @alexany4619 Před 4 měsíci

    Hi, you didn't mention which version of Python and Pygame you are using here?

  • @JimboMazza669
    @JimboMazza669 Před 11 měsíci

    how would you implement another car thats the exact same?

  • @anubhavsharma1761
    @anubhavsharma1761 Před 2 lety +1

    45:34 Can someone tell me why we have to use cosine for the vertical component?? Aren't we supposed to use sine as sinA = p/h

    • @balquist8080
      @balquist8080 Před 2 lety +1

      me too i was so confused when i saw it

    • @balquist8080
      @balquist8080 Před 2 lety +1

      actually now that i think about it, maybe it's because the car starts in an upright position on 0 degrees. let's say we want to move the car ONLY forward, on speed v. then y = v, but sin of 0 is undefined. if we calculate using sin (0) the equation would be wrong. instead we have to calculate using sin (90 + 0) * v so that y = v . so in all of our equations we have to add 90 to that angle. and with trig, we know that sin(90 + a) = cos a, and cos (90+a) = - sin a. hope that helps!

  • @ripperr2476
    @ripperr2476 Před 2 lety

    Tim’s cute
    Keep it going

  • @skyfrezeeminecraft6310
    @skyfrezeeminecraft6310 Před 2 lety +1

    can you teach me how to code a game from start to finish, because I'm still a beginner and just learning code

  • @jrc1248
    @jrc1248 Před rokem

    Hi .. i am new to python .. can you help me by some solution .. from your code
    i need position value of car how can i get this

  • @genilsonmelo8372
    @genilsonmelo8372 Před 2 lety

    hello from Brazil

  • @Derpy999
    @Derpy999 Před 2 lety +1

    why not use sprite classes?

  • @DREW.Tech0
    @DREW.Tech0 Před 2 lety

    Hi tim
    I have an error that says: No file 'imgs/grass.jpg' found in working directory.
    What can I do?

    • @DREW.Tech0
      @DREW.Tech0 Před 2 lety

      @Tech With Tim. please respond

  • @rishavmitra5732
    @rishavmitra5732 Před 2 lety

    Aren't the sin and cos flipped in the code?

  • @ZANES-YT
    @ZANES-YT Před 2 lety

    Haha remeber where I learned this

  • @basicallybrand
    @basicallybrand Před 2 lety

    do I have to learn trig for this????

  • @aattreyakrishnakumarsubram2902

    When I tried accessing your website for the track border and track it just keeps crashing how do i fix this?? Or is you site down ??
    Thanks Bro Love the vids

  • @einat_naor1703
    @einat_naor1703 Před 6 měsíci

    Can the game be converted to multiplayer?

  • @RealAmay
    @RealAmay Před 2 lety

    it is showing error in line 15 but i have written the same code that you have written