Pygame Tutorial for Beginners – Python Game Development Course
September 2, 2024 2024-09-02 13:19Pygame 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)
@nicoz1407
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 🙁
@sleekzee6044
1:24:20
@Disci_Code_pline
Wayyy better
@prabudhanasekar3786
code is correct but spaceShip is not moving
@CaptainL3v1
can someone please tlel me how to get the autofill thing cuz they don't come up for me
@Mechadori
I watched it one sitting
@stephimalzkorn
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!
@muhammadhuzaima6026
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)
@t.kaystkays6514
This tutorial helped me in preparation of using Unreal engine and studying software engineering at university level
@user-zh1ou6bn7w
For some reason it wont let me insert a image
@UnknownGamer-lw7zp
20:33
@VinodKhutekar-dq2ko
Anyone from 8std
@dileepkm3940
Showing many errors don't know why
@dileepkm3940
How to add the downloaded png to your poroject
@NElectronicSoul
this is fucking terrible
@bountyhunter-makkar
best tutorial about pygame❤🔥
@debokikantalahirichowdhury4986
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 ??
@jitteshwaransaktivel1414
My player and enemy are glitching
@abominablemusic
just finished this tutorial – it's great. Many thanks for making this and making it easy to follow.
@nadirikram5612
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!
@abeloiscauchy8009
i love this guy
@user-th8hs2gb2i
this video is good
@poojaingole2536
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)
@HausYT
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.
@sidratulmuntaha4050
How to atually add photos in vs code
as png files
@user-iz8gw2vi3u
amazing
@sakthivelmaribe8120
Really is wonderful journey for gaming
@godfryddolbinczykunical1571
Szkoda tylko że nie ma mechaniki FPS, a to podstawa nawet w najprostszych grach w pygame.
@greeng448
some how I have to press alt and spacebar at the same time in order to shoot the bullet. strange….. :V
@bloodystargaming
Hey screen fill is not working
@brain-370
Good course but you have a bad habit of using too much comments
@eduardorocha2767
Tremendous, thanks for the tutorial!
@GetRealwithMike
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
@LeraxTheChilledLonelyBoy
Freecodecamp, please try to post a video on the tutorial ursina python 3d game engine.
@Zkauba24
<3
@NPRojas
Es una gran introducción a PyGame.
¡Felicitaciones!
It is a great introduction to PyGame.
Congratulations!