Udemy
    •  
    •  
    •  
    •  
    •  
    •  
    •  
    •  
Turn what you know into an opportunity and reach millions around the world.
Learn More
Your cart is empty.
Keep shopping
Asteroids with Python PyGame
Rating: 4.3 out of 5(127 ratings)
30,178 students

Asteroids with Python PyGame

PyGame for total beginners
Created byFrank Anemaet
Last updated 9/2021
English
English [Auto],

What you'll learn

  • Basics of PyGame
  • Load and display images
  • Handle keyboard input
  • Game loop
  • How to make the Asteroids game

Course content

1 section16 lectures1h 1m total length
  • Introduction0:06
  • Download the code0:05
  • Game loop7:47

    learn to install pygame and set up a window, colors, and images for a game. build the endless game loop that updates the screen, handles input, and animates sprites.

  • Draw ship2:56

    Load a ship image in Pygame, blit it at the center using the window width and height, and offset by half the ship size (about 100 by 100).

  • Rotate image3:36

    Switch to ship X and Y for dynamic positioning, and rotate the ship image using an angle-based function, controlled by keyboard input.

  • Keyboard input 16:06

    Learn to implement keyboard input in PyGame to rotate the ship in an Asteroids-style game, using key down/up events, global variables, and continuous rotation via a rotating flag and direction.

  • Keyboard input 24:04

    Update the ship’s position from its angle using cosine and sine, converting degrees to radians to move forward as you hold the key for continuous motion and a defined speed.

  • Keyboard input 35:37

    Handle keyboard input to rotate and move the ship, implement gradual deceleration for released keys, and display a thrust image when the ship is accelerating.

  • Draw asteroids6:55

    Load and render multiple asteroids in pygame by using a single rock image, rotating it, and placing randomly distributed asteroids via a list of coordinates; control quantity with a variable.

  • Move asteroids4:06

    Implement asteroid motion by updating each asteroid's position in the game loop using a unique random angle and speed, so rocks move in varied directions across the screen.

  • Basic collision2:36

    Explore basic collision handling in a PyGame asteroids game by implementing ship-asteroid collisions that end the game or lose a life, and wrap around when asteroids reach the screen edges.

  • Collision detection2:48

    Detect collisions between the ship and asteroids with a coordinates-based collision detection function, and end the game on impact, while you can tweak that number to adjust detection.

  • Fire8:29

    Load and draw a bullet image, initialize bullet position and angle from the ship on spacebar press, and move bullets forward with their angle, enabling multiple bullets via a list.

  • Multiple fire2:57

    Implement multi-bullet firing in a PyGame asteroid game by managing bullets as a list, updating each bullet's position and angle, and spawning new bullets with the space bar.

  • Collision bullet1:29

    Implement collision detection between bullets and asteroids in PyGame by checking each bullet against each asteroid and repositioning hit asteroids; use a dynamic collision distance to tune strictness.

  • Whats next?1:46

    Extend your asteroid game with Pygame by adding sounds, music, and on-screen text like scores and game over messages; consider object oriented programming for cleaner code.

Requirements

  • Basic Python knowledge (no OOP required)

Description

When I was a kid, I used to play a lot of Asteroids, a simple arcade game where your space ship was orbiting around a bunch of asteroids. In the game you had to move your space ship around to avoid crashing into them or get onto them to destroy them with the lasers on the space ship. Whenever I played it I had fun.

In this course you will learn how to make the Asteroids game with the Python programming language. You don't need any advanced knowledge of Python nor any object orientated programming knowledge, it's a beginners course. Only basic Python knowledge is required like functions and loops.

The course will introduce you to PyGame, a game programming library. You will learn how to load and display images, how to create animations, how to create game play, how to add text and so on. By the end of this course, you will have a complete asteroids game made with the Python programming language.

The course includes all the code examples and graphics so you can follow along with each step. If you want to make games with Python, what are you waiting for? Enroll today and I'll see you inside the course.

Who this course is for:

  • Python beginners that want to learn PyGame