Login

Lost your password?
Don't have an account? Sign Up

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:

https://www.educational.guru

39 comments

  1. Souvik Saha

    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

  2. David Margis

    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.

  3. WatOnson

    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

    1. Old Guy From Octopus Game

      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

  4. Steve Kellogg

    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!

  5. Justin McCoy

    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.

  6. Programming With Raahim

    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.

    1. Vlad

      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.

  7. Andreea Diana Chiriac

    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!

  8. Marlon Solleske

    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.

    1. Lyonic

      @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 ❤️

  9. TreBros

    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!

  10. mateoingouville

    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.

Leave a Comment

Your email address will not be published. Required fields are marked *

*
*