Pygame Tutorial for Beginners - Python Game Development Course
Why Stack Overflow recommends it
Stack Overflow users link it because many beginners follow this exact Space Invaders tutorial and then ask about bugs in their copy of its code, such as blitting, movement, bullets and multiple enemies.
Recommended by 3 people across 3 different months, 2020 to 2023.
What it is
A 2h15m freeCodeCamp.org course, created by buildwithpython, that teaches Pygame by building a Space Invaders clone in Python with PyCharm. It covers windows, images, keyboard input, enemies, bullets, collision detection, score text, sound and a game over screen.
What people said
Recommends spiral spark · 2020-03 · Stack Overflow · on “why wont the image blit?”
I have tried putting the fill color before blit but it won't work. im using python 3.8.2, windows 10, and pygame 1.9.6. please help btw im following this [this video] tutorial (im new to pygame) and here's my code import pygame #initialize pygame.init() #screen screen = pygame.display.set_mode((800, 600)) #things pygame.display.set_caption("space invaders 1.0") icon = pygame.image.load('ufo.png') pygame.display.set_icon(icon) #player settings playerimg = pygame.image.load('space-invaders.png') playerx = 370 playery = 430 #define player def player(): screen.blit(playerimg, (playerx, playery)) #loop running = True while running: #rgb screen.fill((10, 0, 0)) for event in pygame.event.get(): if event
Recommends AmanoSkullGZ · 2020-04 · Stack Overflow · on “The player character isn't moving”
So, I'm having some trouble developing the space ship movement on my game. I checked the code a couple of times and yet I still can't find nothing. The project is from this video [this video] and I got this bug on the minute 44:55, and I'm using Python 3.8. Here's the code. import pygame # Initiate pygame pygame.init() # Display the game window screen = pygame.display.set_mode((800,600)) # Title and Icon pygame.display.set_caption('Space Invaders') icon = pygame.image.load('icon.png') pygame.display.set_icon(icon) # Player playerSprite = pygame.image.load('player.png') playerX = 370 playerY = 480 playerX_change = 0 def player(x,y): screen.blit(playerSprite, (x, y)) # Game Loop running = True whil
Recommends Databas3 · 2020-12 · Stack Overflow · on “TypeError: unsupported operand type(s) for +=: 'int' and 'list' with Pygame”
Please help!! I'm trying to make Space Invaders with Python following this tutorial: [this video] I got suuper confused at the part when the guy starts to add for loops, as I'm horrible with them and I don't really understand them. There need to be multiple enemies, so I make a for loop that iterates through lists of variables and draws enemies. The tutorial went very quickly, and I have no idea what I'm supposed to put "[i]" next to, and what not. When I run my code (shown below) it says: Traceback (most recent call last): File "C:/Users/geema/PycharmProjects/pythonpractice/Scripts/myfirstpygame.py", line 139, in <module> enemyX[i] += enemyX_change[i] I could copy and paste the code, but the pur
Cites user12782536 · 2020-02 · Stack Overflow · on “I tried to make a player move in pygame but it didn't work and it's giving me this error:”
There's the error: File "C:/Users/jimos/PycharmProjects/ffg/app.py", line 40 if event.type==pygame.KEYUP: ^ IndentationError: unindent does not match any outer indentation level And I followed this tutorial: [this video] import pygame pygame.init() #create the screen screen=pygame.display.set_mode((800, 600)) #Title and Icon pygame.display.set_caption("Space Invaders") icon=pygame.image.load('ufo.png') pygame.display.set_icon(icon) #Player playerImg=pygame.image.load('player.png') playerX=370 playerY=480 playerX_change=0 def player(x,y): screen.blit(playerImg, (x, y)) #game loop running=True while running: screen.fill((255, 128, 0)) for event in pygame.event.get(): if event.type == pygame.QUIT: r
Cites Hydro · 2020-05 · Stack Overflow · on “I am trying to move my character but instead of that the player wont move”
I am trying to move my character. I wrote it just like in a tutorial( [this video] ). It doesn't work. My character just wont move. I do not see any errors neither! Did I forget to add something to my code - in the KEYDOWN section? So the whole Code is here but the problem probably is in the KEYDOWN section or the player coordinates. Here is the code: import pygame from pygame.locals import * pygame.init() WINDOW_WIDTH = 800 WINDOW_HEIGHT = 600 SURFACE = pygame.HWSURFACE|pygame.DOUBLEBUF|pygame.RESIZABLE win = pygame.display.set_mode((WINDOW_WIDTH, WINDOW_HEIGHT), SURFACE) win.fill((0, 180, 210)) pygame.display.set_caption("Baloon War!") icon = pygame.image.load("Baloon war icon.png") pygame.disp
Cites piddi24 · 2020-06 · Stack Overflow · on “Pygame error 'TypeError: argument 1 must be pygame.Surface, not list'”
I am creating a game using pygame and have run into an error, I am new to pygame. I am using python 3.8 and pycharm community edition 2020.1 Here is the video i am making the game with: [this video] here is the error: Traceback (most recent call last): File "C:/Users/user/PycharmProjects/Agam/Python/Pygame.py", line 131, in <module> enemy(enemyX, enemyY) File "C:/Users/user/PycharmProjects/Agam/Python/Pygame.py", line 28, in enemy screen.blit(enemyImg, (x, y)) TypeError: argument 1 must be pygame.Surface, not list Here is my code: import math import random import pygame pygame.init() # Screen (Pixels by Pixels (X and Y (X = right and left Y = up and down))) screen = pygame.display.set_mode((800,
Cites Oftox · 2020-12 · Stack Overflow · on “pygame "invalid destination position for blit"”
This has been asked by many others but i cant seem to get it to work for my code (Space invaders). Tutorial python version 1.9.6 and i am using 3.8.5 so it's very possibly outdated code or is there a mistake. How should i do this in 3.8.5? Tutorial: [this video] I am making it so it would spawn in 6 enemies and i added the [i] to the end almost every enemyX, enemyY or enemy_change as i was told in a tutorial. So i got this error for line 56: screen.blit(enemyImg[i], (x, y)) TypeError: invalid destination position for blit" and the Pygame window closes. Thanks for help Here is the error related code followed by the tutorial: import random import math pygame.init() pygame.init() enemyImg = [] enemy
Cites Oftox · 2020-12 · Stack Overflow · on “Python Pygame print keystroke spams the output”
I have been following a Pygame tutorial on made on 2019 so it might be outdated. It should detect the arrow keys and print it but it keeps spamming the print right or left arrow and the keystroke released when i press any arrow key. is the code outdated or is there a mistake on my code? And also before it start the spamming it says "ALSA lib pcm.c:8526:(snd_pcm_recover) underrun occurred" on the pycharm as an error. It works great for all the other parts. video link if you need ( [this video] ) im using pygame 2.0.0 on pycharm 3.8.5 if its the same on pycharm and python. Linux ubuntu 20.04.1 if event.type == pygame.KEYDOWN: if event.key == pygame.K_LEFT: print("Left arrow") if event.key == pygame
Cites SHREEJIT MISHRA · 2021-03 · Stack Overflow · on “how do i draw bullet in pygame”
i am experiencing problem trying to draw a bullet but it just plain isnt working ,this is the code i was watching this tutorial [this video] i cant find the answer anywhere the bullet isnt appearing i have tried to replicate tutorial, seach on youtube i have got the enemy and player moving [LINK] .... import pygame import random pygame.init() pygame.display.init() screen = pygame.display.set_mode((800, 600)) bacground = pygame.image.load("background.png") playerimg = pygame.image.load("spaceship.png") playerX_change = 0 playerX = 360 playerY = 480 def player(x, y): screen.blit(playerimg, (x, y)) enemyimg = pygame.image.load("enemy.png") enemyX = random.randint(0,736) enemyY = random.randint(50,15
Cites Codem · 2021-05 · Stack Overflow · on “How do I add a 32px png as a new file in Pycharm so that my script can find it?”
I was following a starter tutorial on Pygame but at some point of the video, we can see he has "ufo.png" as a Pycharm file on the left side of the screen and as a tab. Video link at the right timecode: [this video] He explains how to download the file from flaticon.com (32px) but not how to get it into Pycharm. I tried to to just slide into the tab bar to create a new tab with the file in it, and it works, but the script cannot find it. It might be because although the file is a new tab, it doesn't appear in the folder on the right side, unlike "main.py" or "ufo.png" in the video. Anyway, this is my script so far. import pygame # Initialize the pygame pygame.init() #create the screen screen = pyg