# Required Libraries import pygame import random # Initialize Pygame pygame.init() # Set the screen size screen_width = 800 screen_height = 600 screen = pygame.display.set_mode((screen_width, screen_height)) # Set the game title pygame.display.set_caption("FNAF Game") # Set the background image background = pygame.image.load("background.png") # Set the player image player_image = pygame.image.load("player.png") player_width = player_image.get_width() player_height = player_image.get_height() # Set the enemy image enemy_image = pygame.image.load("enemy.png") enemy_width = enemy_image.get_width() enemy_height = enemy_image.get_height() # Set the clock clock = pygame.time.Clock() # Set the font font = pygame.font.Font(None, 36) def game(): """ This function runs the FNAF game. """ # Set the player position player_x = (screen_width - player_width) / 2 player_y = screen_height - player_height - 10 # Set the enemy position enemy_x = random.randint(0, screen_width - enemy_width) enemy_y = -enemy_height # Set the score score = 0 # Set the game over flag game_over = False # Game loop while not game_over: # Event loop for event in pygame.event.get(): if event.type == pygame.QUIT: game_over = True # Move the player keys = pygame.key.get_pressed() if keys[pygame.K_LEFT] and player_x > 0: player_x -= 5 if keys[pygame.K_RIGHT] and player_x < screen_width - player_width: player_x += 5 # Move the enemy enemy_y += 3 if enemy_y > screen_height: enemy_x = random.randint(0, screen_width - enemy_width) enemy_y = -enemy_height score += 1 # Check for collision if player_x < enemy_x + enemy_width and player_x + player_width > enemy_x and player_y < enemy_y + enemy_height and player_y + player_height > enemy_y: game_over = True # Draw the screen screen.blit(background, (0, 0)) screen.blit(player_image, (player_x, player_y)) screen.blit(enemy_image, (enemy_x, enemy_y)) score_text = font.render("Score: " + str(score), True, (255, 255, 255)) screen.blit(score_text, (10, 10)) pygame.display.update() # Set the game speed clock.tick(60) # Quit Pygame pygame.quit() # Run the game game()
Please fill in all the options in the message template.
Hey, @SamanthaMonroy, welcome to Replit Ask.
For future reference, giving details and a link to your repl is generally more helpful and better than just giving code without details at all.
Welcome @SamanthaMonroy to ask
Please give us an idea if the problem you’re facing and a link to your Replit so that we can help you.
Add the missing video libraries. Run in Shell:
sed -i '/ ];/s/;/ ++ (with pkgs.xorg; [ libX11 libXext libXinerama libXcursor libXrandr libXi libXxf86vm ]);/' replit.nix
We don’t know what you want help with. You need to specify what you mean by “Game help” If you meant that you wanted to collaborate with someone or have them do it, then post it as a bounty with specific details. Otherwise, it is better to ask specific questions as you go along instead of asking someone to make it for you.
I disagree with this, as there’s a #general:collaborations category made just for collaborations.