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
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!
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
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!
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. ;)
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
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
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 !
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...
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!!
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 ;)
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.
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.
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
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
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.
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?
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.
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?
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.
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
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
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.
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!!
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
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
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.
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
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!
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
Great job
👌👌👌👌
Thanks bhaiya
Thanks!
thanks!!
Congrats to everyone who finished the tutorial and created the game! We made it and didn't give up!
didnt work for me fudge
Aditya ha ra
yeah!
Am 19 mins in
3 sleepless nights but i did it
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!
This is one of the best pygame tutorials online because he tells you what each step does
"Forgive me; I'm drawing with my mouse."
*draws a perfect square with the hand of god*
How did he do that
@@franciskurian9392 *first* *draw* *a* *circle*
@@usopphammergataling3910 that's the problem
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!
lol i installed python like a couple days ago, was hard, now its ez with tim
holy shit! what a coincidence, i just finished making a space invaders game from another tutorial, and my man posts a better one
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
I love how it covers many topics, classes & dictionaries especially! Super helpful for me
completed my first project ever! thanks for the vid.
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!
At 48:34, instead of using self.ship_img, use the variable for the yellow ship (YELLOW_SPACE_SHIP)
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. ;)
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
Top quality tutorial. Good job man!
dude you are literally expanding our knowledge. thanks a lot
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
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 !
Thank you for being specific and explaining what you were doing thoroughly. Keep it up!
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 !
Oh you're French too, I think I know you ! XOXO
@@ggbo4936 Love u brahhhh
I've been subbed to this channel since you guys had 100K subs! Amazing tutorial Tim!!
17:58 That awkward silence tho lol
Great vid man! It helped me so much Thank you!!!
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...
Is he better?
Thanks!
Thank you!!
@@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
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!!
Awesome, Tim! Kudos! Greetings from Brazil!
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 ;)
how did it go? still programing?
@@CorridorJ Kinda sorta. I'm a statistical programmer - so somewhat related!
thank you so much my brother Tech With Tim i'm using this for my final project
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.
Best of luck for your new podcast!
Thx Tim for this tutorial. Keep going with it because I need this one. Also stay safe
thanks for the tutorial. Tim. It saved me a lot of time to be familier with an interesting game module in Python. Great support !
Merci Tim
Très bien présenté. (Very well presented.)
BRAVO
Christophe from France
Moi aussi je suis francais.
Dude You are AWSOME! excellet tutorial I learned so much. Better then 4 weeks of school
23:01 He said he was drawing with the mouse, but that's the best square I've ever seen.
Lol this is a perfect square I think.
Hold shift while drawing to get a straight line.
Shift + mouse
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.
Exactly....very consoling
YES TIM WAS LITERALLY WAITING FOR THIS
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
pip is actually recursive acronym "Pip Install Packages"
pip pip hooray!! :-D
yo that's crazy, but ion remember askin my jibba
Smh my head
@@jackfishion5964 I see what you did there ...
i thought it was "Please instal packages"
One of the best game in my first computer, ZX Spectrum few decades ago. Thank you
Legends code in the default IDLE DARK MODE.
Uber legends code in total dark, remove the lightbulb, turn off keyboard backlighting and turn the monitor off. Hardcore darkmode.
@@tnetroP lol
@@tnetroP 😂
I use IDLE because my trashy laptop can't download pycharm nor sublime
@@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)
Cheers Tim mate, class at what you do sir
I was waiting for this, stay safe my friends 😷
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
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.
This was a really fun and educational little code-along project! Greetings from Finland!
chezard 1 1 1
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?
Same
Same
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.
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
Excellent Tutorial !! I was able to follow through the whole tutorial with so much ease ! Thank you Tim :)
Really neat tutorial. Had fun implementing this one.
Muito bom, estou começando no pygame e seu vídeo ajudou muito a entender melhor a iteração entre objetos.
French : merci mon gars , tu m'as beaucoup appris , merci de ta générosité
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?
Thank you so much for this tutorial. Your projects are really helping me practice skills and get more confident.
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.
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
I noticed that too. I think it was just a bug he didn't catch. But great tutorial nonetheless
Dude, keep this up. I love these videos
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
ok?
thanks I gues
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.
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!
Time out with Tim is an awesome name!
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!!
You are doing a really good job. Suddenly I found your channel and I became your fan
One Question: how did you create the art in the tutorial? I'd like to add more features and just wanted to know :)
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
Thanks Tim! Again a great tutorial with absolutely no necessity to watch it with increased speed ;-)
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!
i think the speed is due to your computer power, try increasing the player_velocity
I learnt lots of new ideas for python other than pygame, great tutorial .
if you guys find a problem with scaling the BG ur probably missing a coma lol i was stuck there for a whole hour
It is a dash( or minus sign), not a underscore.Tim tricked us haha.
Dude this is the video I was waiting for!
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
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.
I was stuck on this type of game and I'm sure this will be helpful. Thanks a lot for making this, really appreciated
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
Did you figure it out?
VRY GOOD TUTORIAL TIM...
VERY INDPIRATIONAL AND UNDERSTANDING THANKS ALOT
Web scraping tutorial!!!!
Ya
Maybe an RSS reader
For bug bounty or pentesting
with login and csrf code pls !
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.
How many days u spent...friend
His website is down, can someone upload the image assets somewhere else for us?
It isn't now, I just downloaded
You're such a cool guy Tim thanks so much !
Imagine doing this thing but using Unity instead so it'll take you 10 minutes...
yeah, in unity this will be a lot quicker xD
Best wishes for you ...From Iran
Tim: don't name the file pygame
Me: let me try 😈
Later....
Well you know what happened.
You have real good vids Tim, I just can't focus, help me! keep up the good work.
Finally completed , thanks for the game
Super helpful intro to pygame. Thanks a ton!
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!
great tutorial, just finished!
bro u deserve more subs.. thankyou so much for the tutorial
The Best program by telling others what to do.
Thanks for the tutorial i"m new to python. But with your help i got lot of gain. thanks for the video
Awesome tutorial man!
and to sum this up: ... You're the best of the best ♥
*appreciation* 👏👏
Very cool and interesting tutorial!!! Just finished it and I defenetly larnt a lot!
Thanks a lot!!!
Great content! I was wondering how can I add some sound effects as well!?
Thanks so much for this amazing tutorial!
You explain very well. Love ya man!
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!
Time out with Tim on spotify please :). Would like to listen to it too, love your channel btw
*The best Tutorial of 2020, thanks for this one Tim*
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 :)
Thanks Tim! You are the best!
Really fun tutorial, good job!
Very good video! Thank you so much! Keep up the good work!