Pygame in 90 Minutes - For Beginners
Why Stack Overflow recommends it
Stack Overflow users cite it as the tutorial they were following when they hit Pygame errors, since its spaceship game is a common first project for newcomers.
Recommended by 1 people across 1 different months, 2021 to 2022.
What it is
A 95-minute beginner tutorial by Tech With Tim that builds a simple two-player spaceship shooter in Python with Pygame. It covers installing Pygame, drawing images, handling sound effects, moving objects, bullets, collision and a basic game loop, with the finished code on GitHub.
What people said
Recommends MilkShake · 2022-05 · Stack Overflow · on “Module 'pygame' has no 'QUIT' memberPylint(E1101:no-member)”
I'm following along with this tutorial: [this video] My code is the same from the video but the pygame.QUIT isn't working. It was before but not sure what happened. Here's my code import pygame import os WIDTH, HEIGHT = 900, 500 #Y, X WIN = pygame.display.set_mode((WIDTH, HEIGHT)) pygame.display.set_caption("First Game!") #definding varibles# WHITE = (255, 255, 255) FPS = 60 SPACESHIP_WIDTH, SPACESHIP_HEIGHT = 55, 40 #inporting images these images in pygame are know as surfaces YELLOW_SPACESHIP_IMAGE = pygame.image.load(os.path.join('Assets', 'spaceship_yellow.png')) YELLOW_SPACESHIP = pygame.transform.scale(YELLOW_SPACESHIP_IMAGE, (SPACESHIP_WIDTH, SPACESHIP_HEIGHT)) RED_SPACESHIP_IMAGE = pygame
Cites Jumpae · 2021-06 · Stack Overflow · on “Bullets in pygame project not deleting when game restarts”
I'm new to Python and coding in general, so I'm following this beginner tutorial [this video] to make a two-player space invaders type game in pygame . All of the code for the mechanics in the game work correctly. However, whenever I try to restart the game by calling the main() function, everything resets except for the bullets (which means that bullets fired in the previous game will hit the players in the next game) Here is the main function: def main(): Player_One_Hitbox = pygame.Rect(WIDTH/4-SPACESHIP_WIDTH, HEIGHT/2-SPACESHIP_HEIGHT, SPACESHIP_WIDTH, SPACESHIP_HEIGHT) Player_Two_Hitbox = pygame.Rect(3*WIDTH/4-SPACESHIP_WIDTH, HEIGHT/2-SPACESHIP_HEIGHT, SPACESHIP_WIDTH, SPACESHIP_HEIGHT) Pla
Cites Nikolai · 2021-08 · Stack Overflow · on “pygame.error: File is not a Windows BMP file on m1 Mac running Mac os Monteray”
I've looked around but haven't found any solutions that work. I'm just learning pygame using the tutorial: [this video] but when I try to link the image I get the error: pygame.error: File is not a Windows BMP file. I've tried everything short of reinstalling pygame again (previous issue), or reinstalling python. Here is my code import pygame import os pygame.init() WIDTH, HEIGHT = 900, 500 WIN = pygame.display.set_mode((WIDTH, HEIGHT)) pygame.display.set_caption("First Game") WHITE = (255,255,255) RED = (255,0,0) FPS = 60 YELLOW_SPACESHIP_IMAGE = pygame.image.load( os.path.join('Assets', 'spaceship_yellow.png')).convert() RED_SPACESHIP_IMAGE = pygame.image.load( os.path.join('Assets', 'spaceship
Cites T122wd · 2021-12 · Stack Overflow · on “No file found in working directory , But the file is in the correct path”
i followed a tutorial to make a game using pygame but i had a problem that every time i run the code it gives this error enter image description here [LINK] i have checked the path of the file and its there enter image description here [LINK] i am not sure whats the problem here is the code : import pygame import os #opereting system WIDTH, HEIGHT = 900, 500 #this is to make the WINDOW WIN = pygame.display.set_mode((WIDTH, HEIGHT)) #your telling python that you want a window with this height and width pygame.display.set_caption("Maisa Ahmed") #it sets a name for the game DARK_GREEN = (00,64,00) FPS = 60 #to control how many times your game refresh per second SPACESHIP_WIDTH , SPACESHIP_HEIGH
Cites svasim · 2022-07 · Stack Overflow · on “Flip sprite when changing the direction of movement”
Today I started to learn pygame and python to eventually remake the simple game "Graphwar". As my first project I chose to make a really simple 2d car game while following a tutorial [this video] , now I want to try something on my own. That is to make my cars to visually change direction by using pygame.transform.flip() when pressing A or D. I've read multiple different tutorials on different sites but I can't get nothing to work. This is my code: #Imports from turtle import pos from xml.dom.pulldom import CHARACTERS import pygame import os pygame.init() #Colors WHITE = (255,255,255) BLACK = (0,0,0) GREEN = (54, 236, 189) GRAY = (64, 64, 64) #Images ICON = pygame.image.load(os.path.join("Assets"
Cites Konvas · 2022-08 · Stack Overflow · on “pygame instantly quits window”
Why is the window instantly closing? I am trying to follow this tutorial so far everything is a coppy but it doesnt work [this video] there is lines under pygame.QUIT(): run = False import pygame WIDTH, HEIGHT = 900, 500 WIN = pygame.display.set_mode((WIDTH, HEIGHT)) def main(): run = True while run: for event in pygame.event.get(): if event.type == pygame.QUIT(): run = False pygame.quit() if __name__ == "__main_": main()
Cites Aon_FPV · 2022-11 · Stack Overflow · on “Python : Pygame error : AttributeError: module 'pygame.image' has no attribute 'rotate' when trying to rotate image of an in game character”
import pygame import os WIDTH, HEIGHT = 900, 500 WIN = pygame.display.set_mode((WIDTH, HEIGHT)) pygame.display.set_caption("First Game!") WHITE = (255, 255, 255) FPS = 60 SPACESHIP_WIDTH, SPACESHIP_HEIGHT = 55, 40 YELLOW_SPACESHIP_IMAGE = pygame.image.load( os.path.join('Assets', 'spaceship_yellow.png')) YELLOW_SPACESHIP = pygame.image.rotate(pygame.transform.scale( YELLOW_SPACESHIP_IMAGE, (SPACESHIP_WIDTH, SPACESHIP_HEIGHT)), 90) RED_SPACESHIP_IMAGE = pygame.image.load( os.path.join('Assets', 'spaceship_red.png')) RED_SPACESHIP = pygame.transform.scale( RED_SPACESHIP_IMAGE, (SPACESHIP_WIDTH, SPACESHIP_HEIGHT)) def draw_window(): WIN.fill(WHITE) WIN.blit(YELLOW_SPACESHIP, (300, 100)) pygame.