import pygame import sys class Crosshair(pygame.sprite.Sprite): def __init__(self, picture_path): super().__init__() self.image = pygame.image.load(picture_path).convert_alpha() # Use convert_alpha() for transparency self.rect = self.image.get_rect() def update(self): """ Update crosshair position to follow the mouse """ self.rect.center = pygame.mouse.get_pos() def shoot(self): """ Handle shooting action (currently just prints to console) """ print("Bang!") # General Setup pygame.init() clock = pygame.time.Clock() # Game Screen screen_width = 1920 screen_height = 1080 screen = pygame.display.set_mode((screen_width, screen_height)) # Load background image background = pygame.image.load(r"W:\11\jayden.harris\pygame\PNG\Stall\bg_wood.png").convert() # Hide default cursor pygame.mouse.set_visible(True) # Crosshair setup (fix: use Crosshair class) crosshair = Crosshair(r"W:\11\jayden.harris\pygame\PNG\HUD\crosshair_blue_large.png") crosshair_group = pygame.sprite.GroupSingle(crosshair) # Fix: Now a Sprite object # Calculate number of tiles needed to cover the screen num_tiles_x = (screen_width // background.get_width()) + 1 num_tiles_y = (screen_height // background.get_height()) + 1 # Game Loop while True: for event in pygame.event.get(): if event.type == pygame.QUIT: pygame.quit() sys.exit() if event.type == pygame.MOUSEBUTTONDOWN: crosshair.shoot() # Now it works because crosshair is a Sprite # Draw background tiles for y in range(num_tiles_y): for x in range(num_tiles_x): screen.blit(background, (x * background.get_width(), y * background.get_height())) # Update and draw crosshair crosshair_group.update() crosshair_group.draw(screen) pygame.display.flip() clock.tick(120)