0

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 i have checked the path of the file and its there enter image description herei 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_HEIGHT = 55,40

#importing images 

YELLOW_SPACESHIP_IMAGE = pygame.image.load(os.path.join('Assets, spaceship_yellow.png'))
 # assets to go in the that folder and which file

YELLOW_SPACESHIP = pygame.transform.scale(YELLOW_SPACESHIP_IMAGE, (SPACESHIP_WIDTH,SPACESHIP_HEIGHT))


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(): #the order in which you draw matters
    
    WIN.fill(DARK_GREEN) #to fill color to the WINDOW
    WIN.blit(YELLOW_SPACESHIP, ())# you use blit when you want draw a surface on the screen (basically used to put the images/texts on the screen)
    pygame.display.update() #you have to update the WINDOW to show any changes






def main():
    clock = pygame.time.Clock() # create a clock object which can be used to keep track of time
    run = True

    while run: #event loop
        clock.tick(FPS) #ensures that you will never go above the FPS you set the game on
        for event in pygame.event.get():
            if event.type == pygame.QUIT: #.QUIT to end pygame in the loop




                run = False

        draw_window()

    pygame.quit #.quit to end pygame in general


if __name__ == "__main__": #doesnt matter

    main()

please help me, thank you the link for the tutorial :https://www.youtube.com/watch?v=jO6qQDNa2UY&t=302s

Code-Apprentice
  • 81,660
  • 23
  • 145
  • 268
T122wd
  • 37
  • 3
  • Look closely at the error message. You do not have a file with the name that you are giving in your code. You have a typo in the line with `os.path.join()`. Double check the video to see the correct way to type it. I suggest that you learn more about folders and files. The comma in the output in the error message is a dead give away that something is wrong. – Code-Apprentice Dec 25 '21 at 08:40
  • The file path needs to be relative to the current working directory. The working directory may ne different from the project directory. Add `import os` `os.chdir(os.path.dirname(os.path.abspath(__file__)))` at the begin of your code. – Rabbid76 Dec 25 '21 at 08:56
  • Just add `os.chdir(os.path.dirname(os.path.abspath(__file__)))` – Rabbid76 Dec 25 '21 at 18:42

0 Answers0