WP Tutorials

Pygame Tutorial for Beginners – Python Game Development Course

Pygame Tutorial for Beginners – Python Game Development Course

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: https://github.com/attreyabhatt/Space-Invaders-Pygame

🎥 Course created by buildwithpython. Check out his YouTube channel: https://www.youtube.com/channel/UCirPbvoHzD78Lnyll6YYUpg

⌨️ (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: https://www.freecodecamp.org

Read hundreds of articles on programming: https://www.freecodecamp.org/news

source

Comments (36)

  1. 47:00 i have everything correct but i can't get the spaceship to move 🙁 i even left de "print" statements to know if it was working and it does, it gives me the result, but it doesnt move 🙁

  2. Wayyy better

  3. code is correct but spaceShip is not moving

  4. can someone please tlel me how to get the autofill thing cuz they don't come up for me

  5. I watched it one sitting

  6. You come up with the idea of a game, teaching everything one needs to accomplish it. Much better than any book or tutorial I ever read!

  7. For some reason my bullet isnt appearing on the screen.

    import pygame

    import random

    pygame.init()

    running = True

    # Screen

    screen = pygame.display.set_mode((1200, 800))

    image = pygame.image.load('rocket.png')

    pygame.display.set_icon(image)

    # Background

    background = pygame.image.load('background.jpg')

    # player

    player_image = pygame.image.load('spaceship.png')

    playerX = 550

    playerY = 650

    playerchange = 50

    # Enemy

    enemy_image = pygame.image.load('enemies.png')

    enemyX = random.randint(0, 1200)

    enemyY = random.randint(50, 150)

    enemychangeX = 0.3

    enemychangeY = 30

    # Bullet

    bullet_image = pygame.image.load('bullet.png')

    bulletX = 0

    bulletY = 650

    bullet_state = False

    bulletchangeY = 10

    # Drawing spaceship on the surface

    def player(x, y):

    screen.blit(player_image, (x, y))

    def enemy(x, y):

    screen.blit(enemy_image, (x, y))

    def bullet_fire(x, y):

    global bullet_state

    bullet_state = True

    screen.blit(bullet_image, (x + 16, y + 10))

    # Game loop

    while running:

    for event in pygame.event.get():

    if event.type == pygame.QUIT:

    running = False

    if event.type == pygame.KEYDOWN:

    if event.key == pygame.K_LEFT:

    playerX = playerX – playerchange

    if event.key == pygame.K_RIGHT:

    playerX = playerX + playerchange

    if event.key == pygame.K_SPACE:

    bullet_fire(playerX, bulletY)

    if event.type == pygame.KEYUP:

    if event.key == pygame.K_LEFT or event.key == pygame.K_RIGHT:

    playerX = playerX

    if playerX <= 0:

    playerX = 0

    if playerX >= 1072:

    playerX = 1072

    enemyX += enemychangeX

    if enemyX <= 0:

    enemychangeX = 0.3

    enemyY += enemychangeY

    elif enemyX >= 1072:

    enemychangeX = -0.3

    enemyY += enemychangeY

    if bullet_state is True:

    bullet_fire(playerX, bulletY)

    bulletY -= bulletchangeY

    screen.fill((0, 0, 0))

    screen.blit(background, (0, 0))

    player(playerX, playerY)

    enemy(enemyX, enemyY)

    pygame.display.update()

    (Can anyone tell me whats the problem)

  8. This tutorial helped me in preparation of using Unreal engine and studying software engineering at university level

  9. For some reason it wont let me insert a image

  10. Anyone from 8std

  11. Showing many errors don't know why

  12. How to add the downloaded png to your poroject

  13. this is fucking terrible

  14. best tutorial about pygame❤‍🔥

  15. PNG file image is not loading in mine, the image does not get loaded, when I try to run the code, it shows "Unsupported Image Format" !! What should I do ??

  16. My player and enemy are glitching

  17. just finished this tutorial – it's great. Many thanks for making this and making it easy to follow.

  18. This tutorial is nothing short of amazing, I am working on a school project and using this video, I was taught how to use something I was considered a complex topic, so efficiently. Big thanks to you guys at freeCodeCamp. Cheers!

  19. i love this guy

  20. this video is good

  21. Everyone who just got learned properly because of this man and i learned this in just some minutes people who think that this man should get the best teacher award (Like)

  22. I've been searching for how to add the PNG images to the Pycharm Directory, or in other words, the sidebar list. That was skipped in the tutorial — the file was already there when that chapter started.

    I have the image I'd like to use for my player icon (spaceship). Any advice on how this is properly done?

    I'm using a Mac.

  23. How to atually add photos in vs code
    as png files

  24. amazing

  25. Really is wonderful journey for gaming

  26. Szkoda tylko że nie ma mechaniki FPS, a to podstawa nawet w najprostszych grach w pygame.

  27. some how I have to press alt and spacebar at the same time in order to shoot the bullet. strange….. :V

  28. Hey screen fill is not working

  29. Good course but you have a bad habit of using too much comments

  30. Tremendous, thanks for the tutorial!

  31. You should make something like this for teachers to teach certain chunks of knowledge and then the person can play if they get the answers right. Work, then play, then work, then play

  32. Freecodecamp, please try to post a video on the tutorial ursina python 3d game engine.

  33. <3

  34. Es una gran introducción a PyGame.
    ¡Felicitaciones!

    It is a great introduction to PyGame.

    Congratulations!

Leave your thought here

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

Enable Notifications OK No thanks