Pygame Tutorial - Creating Space Invaders

Поделиться
HTML-код
  • Опубликовано: 2 дек 2024

Комментарии • 959

  • @akuamtau
    @akuamtau 4 года назад +585

    Tutorial timestamps:
    0:9:00 import assets
    0:15:00 main function
    0:32:30 ship class
    0:39:00 setup player keys
    0:46:30 player class
    0:53:30 enemy class
    1:13:00 laser class
    1:37:39 enemy shooting
    1:42:00 health bar
    1:49:20 main menu

  • @lamedev1342
    @lamedev1342 4 года назад +495

    Congrats to everyone who finished the tutorial and created the game! We made it and didn't give up!

  • @ziiiizy
    @ziiiizy 4 года назад +54

    Thank you so much, Tim! I was present for all 2 hours and learned a lot. This is my first official Pygame game! Keep the good work up!

  • @ajiazhou
    @ajiazhou 23 дня назад

    This is one of the best pygame tutorials online because he tells you what each step does

  • @baphnie
    @baphnie 3 года назад +56

    "Forgive me; I'm drawing with my mouse."
    *draws a perfect square with the hand of god*

  • @bwip2033
    @bwip2033 4 года назад +23

    A week ago I was barely scraping the surface of Python, following this tutorial made it much easier to see where syntax belongs and how everything communicates. This was a lot of fun - Thanks!

    • @ikben3983
      @ikben3983 3 года назад +1

      lol i installed python like a couple days ago, was hard, now its ez with tim

  • @eshanbahuguna8088
    @eshanbahuguna8088 4 года назад +31

    holy shit! what a coincidence, i just finished making a space invaders game from another tutorial, and my man posts a better one

  • @codysmith1915
    @codysmith1915 3 года назад +6

    I super appreciate this man, I was a c++ student in college but wanted to swap over to python. Stuff likes this make awesome little projects to practice the language

  • @trevorribbans2256
    @trevorribbans2256 3 года назад +4

    I love how it covers many topics, classes & dictionaries especially! Super helpful for me

  • @katchem5666
    @katchem5666 2 года назад

    completed my first project ever! thanks for the vid.

  • @elenkorkmaz4075
    @elenkorkmaz4075 4 года назад +17

    Thank you so much it worked perfectly despite the loads mistakes I made... It had for me 4 days in a row, a few mental breakdowns and struggles, but I managed to solve everything and follow your path and I"m very thankful because I just finished my first python project with you :)! Btw I have an advice for people who watch this; create a checkpoint save and save it everytime when you ran the project without any error, so you wouldn`t have to restart the project everytime you have an error. Thanks again!

  • @neelbiswas5992
    @neelbiswas5992 4 года назад +7

    At 48:34, instead of using self.ship_img, use the variable for the yellow ship (YELLOW_SPACE_SHIP)

  • @tonyfremont
    @tonyfremont 4 года назад +4

    Been programming, for well over 40 years, in BASIC, various assembler languages, FORTRAN, COBOL, C, Perl, php, and several scripting thingys. After much resistance, I finally broke down and decided I should spend some time learning more about python. Watched the 4.5 hour tutorial from Mike, pygame demo of Connect 4 (part 1), and then watched this. Best use of a cold Saturday in a long time. In about 8 hours, I've a decent handle on the basics, along with graphics use. I can't thank this channel enough. I might actually learn some JavaScript now. ;)

  • @mattmovesmountains1443
    @mattmovesmountains1443 4 года назад +1

    About halfway through this code-along, my program would force-close as soon as I hit the shoot button. I couldn't for the life of me figure out what was different between my code and Tim's, so I made a file comparison program that printed each line of both of our codes, one line at a time. Got to the issue, fixed it, and it works! Noob for the win

  • @federicogemin1715
    @federicogemin1715 4 года назад +10

    Top quality tutorial. Good job man!

  • @msa3533
    @msa3533 4 года назад +4

    dude you are literally expanding our knowledge. thanks a lot

  • @harrisoncrettol
    @harrisoncrettol 4 года назад +12

    I appreciate the hard work that goes into these videos. I noticed a small bug in the program where everything on the screen had almost like a ghosting effect. Fixed it by adding "WIN.fill((0,0,0))" directly after the redraw_window function. Hopefully this helps

  • @ggbo4936
    @ggbo4936 4 года назад +6

    Thank you to be so great, I can go to holidays now, you save my last year project. So nice ! Keep going love on you from France !

  • @ArpanNeupaneProductions
    @ArpanNeupaneProductions 4 года назад +4

    Thank you for being specific and explaining what you were doing thoroughly. Keep it up!

  • @paulbagnis781
    @paulbagnis781 4 года назад +2

    Thank you for being such a great guy, love what you do, it's been two weeks working on your videos, just got me a top class last year project ! If you wan't to give courses in Paris, can get a word to my school ! Love from France !

    • @ggbo4936
      @ggbo4936 4 года назад

      Oh you're French too, I think I know you ! XOXO

    • @paulbagnis781
      @paulbagnis781 4 года назад +1

      @@ggbo4936 Love u brahhhh

  • @Ashersminicartoons
    @Ashersminicartoons 4 года назад +6

    I've been subbed to this channel since you guys had 100K subs! Amazing tutorial Tim!!

  • @riot_dingo
    @riot_dingo 2 года назад

    17:58 That awkward silence tho lol
    Great vid man! It helped me so much Thank you!!!

  • @roshanican504
    @roshanican504 3 года назад +12

    With this tutorial it's been my second pygame but i know everything's waste if we really won't understand the code itself and and be able to built Everything from scratch and add some features so hopefully,
    I'll do it, please pray for my grandpa guys it's like he is really sick but what i am hoping is to work hard and get a job to support his treatment...
    But i really believe prayers or dua change things... So thanks to Tim again
    It's really amazing for people like me who can get this content for free literally...

  • @swamphonkey
    @swamphonkey Год назад

    Thanks!

    • @TechWithTim
      @TechWithTim  Год назад

      Thank you!!

    • @SuperFilmFan11
      @SuperFilmFan11 Год назад

      ​@@TechWithTim my lesers are shooting only once and then it is not shooting at all please help me and the you lost sine is showing only for 1 second

  • @williamneck7897
    @williamneck7897 4 года назад +8

    Thanks for being so specific explaining every single line of the code, learning python this way becomes much easier and dynamic than reading books full of theory (I'm not saying these are useless but for me learning hands on is proving to improve the learning curve and the interest in programming in a beginner level) Thanks again Tim keep it up!!

  •  7 месяцев назад

    Awesome, Tim! Kudos! Greetings from Brazil!

  • @SilentEagle2029
    @SilentEagle2029 4 года назад +30

    Really appreciate these videos! I have given programming a second go around and am really sticking with it this time. Following tutorials such as yours expand my knowledge and teach by doing at the same time. You got yourself a new sub! P.S. I'll check out that podcast too ;)

    • @CorridorJ
      @CorridorJ Год назад

      how did it go? still programing?

    • @SilentEagle2029
      @SilentEagle2029 Год назад

      @@CorridorJ Kinda sorta. I'm a statistical programmer - so somewhat related!

  • @mountainlion9002
    @mountainlion9002 Год назад

    thank you so much my brother Tech With Tim i'm using this for my final project

  • @probabilityfilter
    @probabilityfilter 3 года назад +3

    If anyone of you are getting the "FileNotFoundError: No such file or directory" error (at around the 10min mark) then one of the reasons could be that you are not running your Python from the folder that you are working from. Meaning, many IDEs work from the root or base folder like ".../Documents/Python Scripts" and if you created a folder for this project like ".../Documents/Python Scripts/Space Invaders" then you need to change your IDE's working folder to ".../Space Invaders". Also remember to use the correct slash \ vs / , whenever you need to use it for paths etc. Also space between words of a folder name need to be handled appropriately.

  • @neelbiswas5992
    @neelbiswas5992 4 года назад +2

    Best of luck for your new podcast!

  • @devguyahnaf
    @devguyahnaf 4 года назад +3

    Thx Tim for this tutorial. Keep going with it because I need this one. Also stay safe

  • @caijason9486
    @caijason9486 4 года назад

    thanks for the tutorial. Tim. It saved me a lot of time to be familier with an interesting game module in Python. Great support !

  • @CSonneck
    @CSonneck 4 года назад +3

    Merci Tim
    Très bien présenté. (Very well presented.)
    BRAVO
    Christophe from France

    • @arnosk8703
      @arnosk8703 4 года назад

      Moi aussi je suis francais.

  • @zLowe
    @zLowe 3 года назад +1

    Dude You are AWSOME! excellet tutorial I learned so much. Better then 4 weeks of school

  • @angel-ig
    @angel-ig 4 года назад +9

    23:01 He said he was drawing with the mouse, but that's the best square I've ever seen.

    • @ekrem_dincel
      @ekrem_dincel 4 года назад

      Lol this is a perfect square I think.

    • @sreeramoffcl
      @sreeramoffcl 4 года назад

      Hold shift while drawing to get a straight line.

    • @__someone8938
      @__someone8938 3 года назад

      Shift + mouse

  • @suguruchhaya3194
    @suguruchhaya3194 4 года назад +1

    Love this tutorial!! One thing to mention is that you have to have mastered beginner python concepts and also know how to use classes to understand what the heck is going on.

  • @gloryness
    @gloryness 4 года назад +16

    YES TIM WAS LITERALLY WAITING FOR THIS

  • @eddiemeekin9180
    @eddiemeekin9180 Год назад

    Just finished your beginners oygame tutorial. Was so badly hoping you would have a tutorial for this (I feel this is the next step to that video) and obviously you pulled through! Dunno how I would have felt following a tutorial from somebody else. You are an Amazing tutor

  • @hemanta212
    @hemanta212 4 года назад +71

    pip is actually recursive acronym "Pip Install Packages"

    • @diliupg
      @diliupg 4 года назад +20

      pip pip hooray!! :-D

    • @Tomo-uj8qy
      @Tomo-uj8qy 4 года назад +6

      yo that's crazy, but ion remember askin my jibba

    • @jackfishion5964
      @jackfishion5964 4 года назад +8

      Smh my head

    • @kavinbharathirm9478
      @kavinbharathirm9478 4 года назад

      @@jackfishion5964 I see what you did there ...

    • @baddreams0919
      @baddreams0919 3 года назад +5

      i thought it was "Please instal packages"

  • @anurasenarathna1703
    @anurasenarathna1703 2 года назад

    One of the best game in my first computer, ZX Spectrum few decades ago. Thank you

  • @l4m5
    @l4m5 4 года назад +146

    Legends code in the default IDLE DARK MODE.

    • @tnetroP
      @tnetroP 4 года назад +41

      Uber legends code in total dark, remove the lightbulb, turn off keyboard backlighting and turn the monitor off. Hardcore darkmode.

    • @Vielmont
      @Vielmont 4 года назад +2

      @@tnetroP lol

    • @gokulbeats6932
      @gokulbeats6932 4 года назад

      @@tnetroP 😂

    • @projectvibe1226
      @projectvibe1226 4 года назад +2

      I use IDLE because my trashy laptop can't download pycharm nor sublime

    • @nemanjastefanovic9215
      @nemanjastefanovic9215 4 года назад +1

      @@projectvibe1226 You can use repl.it. It is a browser based IDE, there is no downloads and even my laptop can use it. (It is very old)

  • @jibster148
    @jibster148 3 года назад +1

    Cheers Tim mate, class at what you do sir

  • @aaeuj
    @aaeuj 4 года назад +5

    I was waiting for this, stay safe my friends 😷

  • @robinnutbeam750
    @robinnutbeam750 3 года назад +1

    Hi Tim. Great tutorial, it has helped me to better understand what code in Python/ Pygame can create. I managed to add background music to this game, which I learnt from one of your other Pygame videos I had an error with the def collide (obj1, obj2): section. When I ran the program it said that the argument result expected was an int value but returned a float value. I managed to get the code running by using the int function before the offset_x and offset_y. like this:
    def collide(obj1, obj2):
    offset_x = obj2.x - obj1.x
    offset_y = obj2.y - obj1.y
    return obj1.mask.overlap(obj2.mask, (int(offset_x), int(offset_y))) != None
    If anyone else had the same problem I hope this helps. All other code works great :) thanks Tim

  • @elosopodast
    @elosopodast 3 года назад +5

    At one point, when you REPLACE, in python it also replaces the file name from ship to player and then it throw an error, so I had to go back an manually replace player back to ship so it could find the right asset.

  • @karelsalminen2671
    @karelsalminen2671 4 года назад +1

    This was a really fun and educational little code-along project! Greetings from Finland!

  • @GamingBrasilTuto
    @GamingBrasilTuto 4 года назад +4

    at 50:00 i'm getting this error: TypeError: argument 1 must be pygame.Surface, not None. I change in class Ship, self.ship_img = None to self.ship_img = YELLOW_SPACE_SHIP and works but just for yellow color. What i can do?

  • @thepaperbowser
    @thepaperbowser 2 года назад +2

    For the issue of enemy lasers shooting off center from the enemy ships, I used a different solution that doesn't involve overriding the inherited shoot method:
    Use an image editing program (Photoshop, Paint 3D, etc.) to edit the size of each laser image asset (red, green, and blue) to be the same width as its corresponding ship image asset (red, green, and blue). NOTE: Make sure to keep the transparent background!
    Thank you for the tutorial! This is really helping me learn Python and is giving me good practical practice for how to work with classes.

    • @styk3000
      @styk3000 2 года назад +4

      def shoot(self):
      if self.cool_down_counter == 0:
      laser = Laser(
      *self.x - ((self.laser_img.get_width() - self.ship_img.get_width()) / 2),*
      self.y,
      self.laser_img,
      )
      self.lasers.append(laser)
      self.cool_down_counter = 1

  • @v.smourya8005
    @v.smourya8005 4 года назад +3

    Excellent Tutorial !! I was able to follow through the whole tutorial with so much ease ! Thank you Tim :)

  • @LuisPereira-bn8jq
    @LuisPereira-bn8jq 4 года назад +2

    Really neat tutorial. Had fun implementing this one.

  • @franciscomenezes2055
    @franciscomenezes2055 4 года назад +6

    Muito bom, estou começando no pygame e seu vídeo ajudou muito a entender melhor a iteração entre objetos.

  • @christophejan5587
    @christophejan5587 2 года назад

    French : merci mon gars , tu m'as beaucoup appris , merci de ta générosité

  • @curtis9701
    @curtis9701 3 года назад +17

    Hey man, I just want to say I appreciate the living hell out of you. How have I only just discovered you. I guess perhaps its because this is the first time I have dabbled in pygame and you came up. But good god. I have not found a better teacher for coding related topics. Seriously, you teach better than my profs do.
    If your someone who has never touched pygame, following along, you go over all the built in functions and what they actually do. I love that when you're using an unfamiliar library. I even downloaded Sublime text to try out. Was curious as to how you got the intelligence going and to get the parameters to pop up for the built in functions?

  • @alexmckinley79
    @alexmckinley79 Год назад

    Thank you so much for this tutorial. Your projects are really helping me practice skills and get more confident.

  • @dejavukun
    @dejavukun 4 года назад +8

    Thanks a lot for your videos Tim. I had a question. How do you start with building such projects? Do you use references? Do you use other people's code initially? Like supposed you are starting out with PyGame module(I know that now you are pretty experienced with it and you can build up stuff on own), how would you approach building a game like let's say PONG.
    Could you explain your approach.
    Could you make a video on this topic? Like how we can approach things while making a project which can minimize copying stuff. One thing that I do is that if I learn something from a blog or a video, i try to understand it. Then, mostly I will make a variant of it. That way, I am practicing also and using the concepts I learnt without copying much.

  • @varivalentinuzzi3602
    @varivalentinuzzi3602 4 года назад +1

    Great lesson. I changed to just lose a life instead of game over when health comes to zero. I also want to introduce a points counter each time shoot down an enemy ship. To test my self

    • @philipeby5418
      @philipeby5418 2 года назад +1

      I noticed that too. I think it was just a bug he didn't catch. But great tutorial nonetheless

  • @jadenwirhol3260
    @jadenwirhol3260 3 года назад +1

    Dude, keep this up. I love these videos

  • @glaceondev4149
    @glaceondev4149 4 года назад +10

    Hey there,if you got any errors like: " int got float"
    then the error is in the instance of player and if you have tried to divide the WIDTH/HEIGHT with some values so it will spawn at the center or somewhere of your screen if so...then the problem is when you try to divide that numbers that returns a floating number so what you can do is:
    import decimal
    decimal.Decilam(Now just do your math stuffs)
    i faced this error and saw the entire video 3 times..but after all i found this problem..its hard to find this type of error...HOPE THIS HELPS

  • @hossumquat
    @hossumquat 3 года назад

    If anyone is wondering why the Y coordinate increases going down instead of up, like it does in mathematics, I believe the reason is because that is how screen rasterization on the old CRTs were done. It would draw from the top-left corner and go to the right first, then back and down a line to draw the next row, etc. Why did that do it that way? Probably because that was the way people read books here in the west, left to right and top to bottom in the same way. So maybe that will help you remember how the coordinate systems work in graphics programming.

  • @Tom-kg6qe
    @Tom-kg6qe 4 года назад +13

    Yo dawg, we heard you liked functions, so we put a function IN YO FUNCTION! So you can run a function while you run a function!

  • @johannesvartdal624
    @johannesvartdal624 2 года назад

    Time out with Tim is an awesome name!

  • @bryanromo7138
    @bryanromo7138 4 года назад +3

    Hey Tim, great video as always! I'm a begginer and your videos help me a lot :)
    I wanted to make a video about: "I made a videogame watching a tutorial" (this tutorial) obviusly referencing you and your channel. Can you give me permission?
    Anyways thanks as always!!

  • @ritikvishvakarma7152
    @ritikvishvakarma7152 4 года назад

    You are doing a really good job. Suddenly I found your channel and I became your fan

  • @hermesbonilla4775
    @hermesbonilla4775 4 года назад +10

    One Question: how did you create the art in the tutorial? I'd like to add more features and just wanted to know :)

    • @revanthgsr
      @revanthgsr 3 года назад

      Me too. I already added healthpacks with a bitmap image from paint.
      i tried making hearts for the lives to increase but i am getting a white background

  • @uli9001
    @uli9001 4 года назад

    Thanks Tim! Again a great tutorial with absolutely no necessity to watch it with increased speed ;-)

  • @jcsmith9518
    @jcsmith9518 4 года назад +4

    Hey Tim, trying to learn Python and trying the game. Q: How to increase screen speed? Tried modification of FPS but don't work. Thanks for tutorial!

    • @jhonmekonnen6465
      @jhonmekonnen6465 4 года назад

      i think the speed is due to your computer power, try increasing the player_velocity

  • @rakeshkulkarni5552
    @rakeshkulkarni5552 4 года назад

    I learnt lots of new ideas for python other than pygame, great tutorial .

  • @mehdibekri9586
    @mehdibekri9586 3 года назад +5

    if you guys find a problem with scaling the BG ur probably missing a coma lol i was stuck there for a whole hour

    • @brainy3429
      @brainy3429 3 года назад

      It is a dash( or minus sign), not a underscore.Tim tricked us haha.

  • @noone-gr4is
    @noone-gr4is 4 года назад +1

    Dude this is the video I was waiting for!

  • @skilz8098
    @skilz8098 4 года назад +4

    Nice python tutorial. Just a couple of caveats...
    I made a small modification to the game logic, in the run loop where you were checking to see if lives were

    • @krishnaraj3989
      @krishnaraj3989 4 года назад

      am not even that experienced in game programming except for working with cpp and sfml, but i do agree that game programming is one of the best ways to learn any language.

  • @TopBagon
    @TopBagon 4 года назад +1

    I was stuck on this type of game and I'm sure this will be helpful. Thanks a lot for making this, really appreciated

  • @vladijunior20
    @vladijunior20 4 года назад +3

    Hey Tim. Amazing tutorial !! I managed to make the game and I really enjoyed your way of teaching. Quick question, I am trying to make my version of the game by adding "lives" which could be an enemy ship but instead of removing 10 points of life and collide, it will add 10 points to my player. I tried a few ways by myself but without luck. My way of thinking was to define that when the enemy ship from when randomly was selected, if it is green for example to add points. I guess the error was mostly that I havent defined ship."green" anywhere. Any help or comments will be highly appreciated. Thanks again for the video

  • @drax3801
    @drax3801 3 года назад

    VRY GOOD TUTORIAL TIM...
    VERY INDPIRATIONAL AND UNDERSTANDING THANKS ALOT

  • @georgiivanov8631
    @georgiivanov8631 4 года назад +30

    Web scraping tutorial!!!!

  • @sashamuller9743
    @sashamuller9743 4 года назад

    took me days to work through this lol. Thank you Tim for all your hard work, i honestly don't know how you do it.

  • @hamod1452000
    @hamod1452000 4 года назад +5

    His website is down, can someone upload the image assets somewhere else for us?

    • @SmellyNutz
      @SmellyNutz 4 года назад

      It isn't now, I just downloaded

  • @edos3783
    @edos3783 3 года назад

    You're such a cool guy Tim thanks so much !

  • @acropolise2945
    @acropolise2945 4 года назад +3

    Imagine doing this thing but using Unity instead so it'll take you 10 minutes...

    • @hbros6811
      @hbros6811 4 года назад

      yeah, in unity this will be a lot quicker xD

  • @rootamin
    @rootamin 3 года назад +1

    Best wishes for you ...From Iran

  • @emojiguy6374
    @emojiguy6374 4 года назад +3

    Tim: don't name the file pygame
    Me: let me try 😈
    Later....
    Well you know what happened.

  • @Kicsa
    @Kicsa 2 года назад

    You have real good vids Tim, I just can't focus, help me! keep up the good work.

  • @niteshbagla6045
    @niteshbagla6045 4 года назад +1

    Finally completed , thanks for the game

  • @arnaldogonzalez1
    @arnaldogonzalez1 3 года назад

    Super helpful intro to pygame. Thanks a ton!

  • @noxzeuz
    @noxzeuz Год назад

    this was great, i actullay understand most of this :D, maybe you go a little fast for me, but i just have to slow down the speed of the vid! Great job!

  • @brianm2572
    @brianm2572 4 года назад +1

    great tutorial, just finished!

  • @Ali-vu6eo
    @Ali-vu6eo 4 года назад

    bro u deserve more subs.. thankyou so much for the tutorial

  • @mrmartinwatson1
    @mrmartinwatson1 4 года назад

    The Best program by telling others what to do.

  • @deshansalitha2477
    @deshansalitha2477 3 года назад

    Thanks for the tutorial i"m new to python. But with your help i got lot of gain. thanks for the video

  • @lucanotti2246
    @lucanotti2246 Год назад

    Awesome tutorial man!

  • @zeinan.1655
    @zeinan.1655 3 года назад

    and to sum this up: ... You're the best of the best ♥
    *appreciation* 👏👏

  • @fabu324
    @fabu324 4 года назад

    Very cool and interesting tutorial!!! Just finished it and I defenetly larnt a lot!
    Thanks a lot!!!

  • @rakoahmed5439
    @rakoahmed5439 Год назад +1

    Great content! I was wondering how can I add some sound effects as well!?
    Thanks so much for this amazing tutorial!

  • @jasongrace6274
    @jasongrace6274 3 года назад

    You explain very well. Love ya man!

    • @jasongrace6274
      @jasongrace6274 3 года назад

      OOO KAY! Well a little too much, I got impressed in the first 20 mins, but now it feels like it's never gonna end. Puff!

  • @greenbone9556
    @greenbone9556 3 года назад +1

    Time out with Tim on spotify please :). Would like to listen to it too, love your channel btw

  • @rafasantos23
    @rafasantos23 4 года назад +1

    *The best Tutorial of 2020, thanks for this one Tim*

  • @doughaskins160
    @doughaskins160 3 года назад

    Thank you so much. Just started learning and this was a challenge AND it fired my imagination

  • @เเอลลิกซานเดอะริชมอนด์

    Very good explanations! Learnt a lot from this video. Thanks so much :)

  • @P.L.D.
    @P.L.D. 4 года назад

    Thanks Tim! You are the best!

  • @x-r-s
    @x-r-s 4 года назад

    Really fun tutorial, good job!

  • @kaelwang1251
    @kaelwang1251 4 года назад

    Very good video! Thank you so much! Keep up the good work!