Pygame Tutorial for Beginners – Python Game Development Course
Learn how to use Pygame to code games with Python. In this full tutorial course, you will learn Pygame by building a space invaders game. The course will help you understand the main game development concepts like moving characters, shooting bullets, and more.
? Code:
? Course created by buildwithpython. Check out his YouTube channel:
⌨️ (0:00:00) Installing Python and Pycharm
⌨️ (0:04:12) Creating Our First Game Window
⌨️ (0:12:39) Changing the Title, Logo and Background Color
⌨️ (0:20:33) Adding Images into Our Space Invader Game
⌨️ (0:29:57) Movement Mechanics in Game Development
⌨️ (0:38:13) Keyboard Input Controls & Key Pressed Event
⌨️ (0:49:53) Adding Boundaries to Our Game
⌨️ (0:53:28) Creating the Enemy
⌨️ (0:59:14) Movement Mechanics of the Enemy Space Invader
⌨️ (1:06:51) Adding a Background Image
⌨️ (1:12:08) Creating Bullets for Shooting
⌨️ (1:26:21) Shooting Multiple Bullets at Space Invaders
⌨️ (1:34:24) Collision Detection
⌨️ (1:48:05) Creating Multiple Enemies
⌨️ (1:55:08) Adding Text and Displaying Score
⌨️ (2:03:17) Adding Sounds and Background Music
⌨️ (2:09:05) Game Over
—
Learn to code for free and get a developer job:
Read hundreds of articles on programming:
And subscribe for new videos on technology every day:
Thank you so much for such clear explanation … You guys are blessing !
1:06:00 these 2 conditions can be simplified as
if enemyX <= 0 or enemyX >= 736:
enemyDx = -enemyDx
enemyY += enemyDy
this way the enemy speed value can be modified in the global only instead of changing in 3 different places
Yeah.
Working with variables is much more comfortable than putting numbers.
This has to be the most useful learn-by-doing Pygame tutorial I’ve seen. You start with the basics, explain what you want to do and how Pygame allows you to do it, and work it in with concepts a learning programmer should be aware of, without jumping right into the more complex aspects.
1:35:00
For collision detection pygame actually has a method called ‘colliderect’ which detects collision between rectangles. So, if you want to check if the enemy rectangle has collided with the bullet rectangle, instead of checking the distance between the two for every frame, you just write:
if enemy_rectangle.colliderect(bullet_rectangle)
[whatever you want to do when the enemy collides with a bullet, or vice versa]
Hope this helps
this is good solution but he did not even introduce the topic of rectangles in this vid
dont work obly for rectangles
I personally believe that this way is better because it lets us know how the collision is actually detected
Thank you for the tip.
@Godly Trickshots THANX BRO
First guy who has made a proper tutorial glad to see that people like them exist in this world
i am viral lmao
You guys didn’t finish it, this is a outdated tutorial… otherwise python should have given an error about not defining playerX_change before saying in the loop to add it
@37. Vignesh Gopal im
indian
@NK Arena Tamil yeah they’re great 🙂
@Charlie Buckley I understand better here, but tech with tim also does a great job, i love his videos
I imagine you might not be monitoring the comments anymore by now, but I’m finding this really helpful! I have to try to help some students pick up some programming skills, and this tutorial is great! The detail that you go into about why things have to be the way they are is very helpful. Thanks!
This was a really good tutorial. He explained everything in detail. Highly recommend.
How do you add an image/icon to Pycharm? I had a lot of trouble trying to import a logo for the icon
This is one of the best tutorials i have ever seen so far. You explain every line of code without leaving room for confusion. Thanks you for everything!
see u around…. officer
You are so right
well this is one of the best tutorials that I’ve seen.
It’s so easy to understand and well-explained also those recaps after each lesson are so awesome
Thank you so much ??
Great tutorial bruh, really easy to follow along to without speed up or slow down on video play speed. Didn’t slow talk the basics like it’s somehow news that a String can be a variable value or something. Just gets right into a python library and explains how to build a game.
Fantastic tutorial! Thank you for taking the time to do this. Much appreciated.
You made it vey nicely and easy. Please keep making tutorials like this so we can learn more. Thank you for investing your time for us. Lots of love for you.
Thankyou again.
Brilliant Man, brilliant video. I like that this man is teaching python as well as telling us all the resources for the needy things. This is just awesome. Thank you for this tutorial of space invaders.
This tutorial was amazing, I’ve learned so many concepts in python game development.
Python wasn’t really designed for it.. it is really important, though, to apply Pygame knowledge to future computer vision projects (if you choose to do so). CV2 is super valuable in combination with pygame and blitting.
Great tutorial! After watching I made it so the enemies could fire bullets to make it a bit more interesting
Just to Clarify would you take the spaceships shooting speed and then put it on an enemy sorry for asking a stupid question I am New to Python
Thanks so much for this amazing tutorials. I found it confusig that the coordonates (x, y) are reversed (to the normal list/matrix coordonates in numpy, for example, like lst[0][1]). I found it very easy to understand and much more easy than I thought it will be. I assumed some bfs for each move, but it’s actually much, much more easy. Really thanks for this amazing tutorial. I wonder if you have other tutorials, because there are still some questions I have. For example, could you change this map to another one? Would it be possible? Or, would it be possible to re-center the map based on the character-position? Like, to go further, after the (0, 0) coordinates? Thanks a lot!
Really cool coding exercise covering the basics. Great fun while following throw it and playing with the functions here and there. Keep up the good work and kindly share more courses like this one. Also looking forward to a object-oriented approach for games involving lots of sprites. Thanks again.
It’s funny how he explains that adding negative numbers is subtracting but also assumes we know the distance between two points algebraic equation
if you have passed 10th grade geometry, you should know that formula.
@Aaron Carter I agree completely! And appreciate the well-thought out reply. Also, I respect the DirectX/C++ programming stuff, I focus more on Java and the Web Development tools (HTML, CSS, and Javascript), and always found that stuff to be a bit complicated for my understanding. Though, I will say, I actually worked in Unity with C# for a while too a good bit ago, which was relatively easy to migrate into language wise, since Java and C# are almost the exact same language in terms of Syntax. Though it did take a while for me to learn the ins and outs of Unity as a game engine, working with Rigidbodies and all the other various elements in a game. All that being said, love the input, and thanks for the reply ❤️
@Lyonic wowza
Awesome Tutorial! Thank you for the spread of your knowledge! Super grateful for people like you who take the time to explain how and why it works and why it does not! That is definitely good teaching practices! I wish my CS teachers were as good as you when it comes to explaining the internals of code! Much appreciated! Take care!
Thank you! I know less than jon snow about programming, but I followed your every step and I made my own game with my own cool graphics and story. And I think I understood most of it, even the collision part. Great teacher.