Loading video player…

Make a 2D Side-Scroller Game With PyGame (Overview)

In this course, you’ll learn about creating games using Python and the library PyGame.

By the end of this course, you’ll be able to:

  • Draw items on your screen
  • Play sound effects and music
  • Handle user input
  • Implement event loops
  • Describe how game programming differs from standard procedural Python programming

This primer assumes you have a basic understanding of writing Python programs, including user-defined functions, imports, loops, and conditionals. You should also be familiar with how to open files on your platform. A basic understanding of object-oriented Python is helpful as well. pygame works with most versions of Python, but Python 3.6 is recommended and used throughout this article.

Download

Sample Code (.zip)

422.6 KB
Download

Course Slides (.pdf)

7.6 MB

00:00 Hi! I’m Chris Bailey from Real Python. I’m going to take you through a course on PyGame. So, let me show you what you’re going to build. You’re going to build this game.

00:08 It’s called Sky Dodge. As a player, you’re flying a jet and trying to avoid all these missiles that are coming at you. So, what will you learn how to do in PyGame?

00:19 You’ll learn how to draw items on your screen, how to play sound effects and add background music, how to handle user input, what an event loop is and how to implement it, and you’ll explore how game programming really differs from standard procedural Python programming. Now, there is a little bit of a suggested background for this course.

00:40 It’s not all required, but it would be helpful if you have some of this background. You will practice a lot of these techniques throughout, and hopefully raise your skills in these different areas.

00:50 You should understand what a user-defined function is, how to do basic imports, what loops are, how to set up conditionals, how to open files, and the basics of object-oriented Python. Again, all these concepts are going to be practiced in this course, but there’s not going to be a lot of time spent on the fundamentals of all these. You can kind of consider this a bit of an intermediate course.

01:12 There’ll be links below this video for more information on all of these topics if you need more background. Let me walk you through the table of contents.

01:20 It’s divided into four sections. The first section is all about starting with PyGame, in this introduction and overview lesson that you’re on right now. Then you’ll dive into the background on PyGame and how to set it up on your system.

01:34 After that, there’s a lesson on creating a basic PyGame program.

01:42 You’ll wrap up this section with some fundamental PyGame concepts. Then you’ll move into a section on basic game design. It starts with a lesson describing what you’re creating with this tutorial game.

02:00 Then you get to practice importing and initializing pygame.

02:08 The next lesson is what’s involved in setting up the display.

02:17 Then, a crucial lesson on setting up the game loop.

02:25 Then you get to practice techniques for drawing on the screen. In the next lesson, you’ll learn about the methods .blit() and .flip() and how they relate to the display.

02:41 That moves you into Section 3, where you’ll start working with sprites. The first lesson in that section is creating your first set of sprites. Then you’ll learn about handling user input.

02:57 How to keep the players sprites on the screen. Then you’ll have a lesson on creating enemies. And with that, in the next lesson, you’ll dive into sprite groups.

03:17 Then you’ll learn about creating custom events that you can trigger inside of the game loop. Next, most games wouldn’t be complete without some form of collision detection.

03:34 Then you’ll load artwork in as sprite images. And along with that, you’ll start adding background images. And now that you have that basic game started, how about enhancing it a bit?

03:51 Section 4 starts with a lesson on controlling the game speed and frame rate. Then you’ll have a lesson on adding music… and along with that, some additional audio with adding some sound effects.

04:14 Then, a discussion about where to find resources for your own game—artwork, sprites, music, and sound effects. And then you’ll wrap up with a conclusion and a course review. Okay.

04:28 That’s enough of an introduction. Let’s dive into PyGame’s background and setup in the next lesson.

Avatar image for Tomas Menito

Tomas Menito on April 9, 2020

Hi, I’m enjoying a lot the course!

I noticed that “Sample Code (.zip)” contains files from Arduino course, and not pygame course.

Avatar image for Dan Bader

Dan Bader RP Team on April 9, 2020

@Tomas: Thanks for the heads up. I just fixed the download, when you try again you’ll get the correct file :)

Avatar image for Andreas

Andreas on May 13, 2020

Just a quick heads up for my fellow Mac folks. I was not able to get anything to draw on the screen, when I found this post on slack overflow. Basically on Catalina you need to utilize: pip3 install pygame==2.0.0.dev4 to get things working. Hope that helps others!

Become a Member to join the conversation.