My code won't run it says eror file not found

Can somone hellp me
Repl link:

code snippet
```# Import pygame module
import pygame

# Initialize pygame

# Create a screen with 800x600 pixels
screen = pygame.display.set_mode((800, 600))

# Set the title and icon of the window
pygame.display.set_caption("Schießerei Spiel")
icon = pygame.image.load("icon.png")

# Load the background image
background = pygame.image.load("background.jpg")

# Load the player image and set its initial position and speed
player = pygame.image.load("player.png")
player_x = 400
player_y = 500
player_speed = 5

# Load the enemy image and set its initial position and speed
enemy = pygame.image.load("enemy.png")
enemy_x = 400
enemy_y = 50
enemy_speed = 5

# Load the bullet image and set its initial state and speed
bullet = pygame.image.load("bullet.png")
bullet_x = 0
bullet_y = 500
bullet_speed = 10
bullet_state = "ready" # ready means the bullet is not fired, fire means the bullet is moving

# Define a function to draw the player on the screen
def draw_player(x, y):
    screen.blit(player, (x, y))

# Define a function to draw the enemy on the screen
def draw_enemy(x, y):
    screen.blit(enemy, (x, y))

# Define a function to fire the bullet from the player's position
def fire_bullet(x, y):
    global bullet_state
    bullet_state = "fire"
    screen.blit(bullet, (x + 16, y + 10))

# Define a variable to store the score
score = 0

# Define a font to render the score text
font = pygame.font.Font("freesansbold.ttf", 32)

# Define a function to show the score on the screen
def show_score():
    score_text = font.render("Score: " + str(score), True, (255, 255, 255))
    screen.blit(score_text, (10, 10))

# Create a loop to run the game until the user quits
running = True
while running:

    # Fill the screen with the background image
    screen.blit(background, (0, 0))

    # Check for any events (such as keyboard input or mouse clicks)
    for event in pygame.event.get():

        # If the user clicks the close button, exit the loop
        if event.type == pygame.QUIT:
            running = False

        # If the user presses a key, check which key it is
        if event.type == pygame.KEYDOWN:

            # If the user presses the left arrow key, move the player left
            if event.key == pygame.K_LEFT:
                player_x -= player_speed

            # If the user presses the right arrow key, move the player right
            if event.key == pygame.K_RIGHT:
                player_x += player_speed

            # If the user presses the space key, fire the bullet if it is ready
            if event.key == pygame.K_SPACE:
                if bullet_state == "ready":
                    bullet_x = player_x
                    fire_bullet(bullet_x, bullet_y)

    # Update the positions of the player, enemy and bullet
    player_x = min(max(player_x, 0), 736) # prevent the player from going out of bounds
    enemy_x += enemy_speed # move the enemy horizontally
    if enemy_x <= 0 or enemy_x >= 736: # if the enemy reaches the edge of the screen, reverse its direction and move it down
        enemy_speed = -enemy_speed
        enemy_y += 40
    if bullet_state == "fire": # if the bullet is fired, move it up
        fire_bullet(bullet_x, bullet_y)
        bullet_y -= bullet_speed
    if bullet_y <= 0: # if the bullet reaches the top of the screen, reset its state and position
        bullet_state = "ready"
        bullet_y = 500

    # Check for collision between the bullet and the enemy
    if abs(bullet_x - enemy_x) < 32 and abs(bullet_y - enemy_y) < 32:
        # If there is a collision, reset the bullet and enemy positions and increase the score
        bullet_state = "ready"
        bullet_y = 500
        enemy_x = pygame. randint(0, 736)
        enemy_y = pygame. randint(50, 150)
        score += 1

    # Draw the player, enemy and score on the screen
    draw_player(player_x, player_y)
    draw_enemy(enemy_x, enemy_y)

    # Update the display

Check to make sure the python file is named Otherwise replit cannot run it without a bunch of fancy stuff I do not know how to do.

Hello, the problem is that you are trying to load images that are not available in your repl.

There are many calls to pygame.image.load(...), and the string argument is a file path to the image. So, you should upload images to your repl with the same names as in the calls to pygame.image.load(...).

1 Like

You should mark the answer from @NuclearPasta0 as the solution. For you to load images with pygame, they need to be added to the actual replit files (you can just drag them in from your pc into the files)


it might be something like os

import os


even though “python” isn’t part of the file name, I still have to include it in the line

Or, this could be run in the Shell, so it doesn’t clutter the file.
But it is unclear as OP hasn’t followed up yet.