import pygame, sys, random class Crosshair(pygame.sprite.Sprite): def __init__(self,picture_path): super(). __init__() self.image = pygame.image.load (picture_path) self.rect = self.image.get_rect() self.gunshot = pygame.mixer.Sound("task 4/andrew-tate-breath-air.wav") def shoot(self): self.gunshot.play() pygame.sprite.spritecollide(crosshair,target_sprites,True) def update(self): self.rect.center = pygame.mouse.get_pos() class Target(pygame.sprite.Sprite): def __init__(self,picture_path,pos_x,pos_y): super().__init__() self.image = pygame.image.load(picture_path) self.rect = self.image.get_rect() self.rect.center = [pos_x,pos_y] class Gamestate(): def __init__(self): self.state = 'main_game' def intro(self): for event in pygame.event.get(): if event.type == pygame.QUIT: pygame.quit() sys.exit() if event.type == pygame.MOUSEBUTTONDOWN: self.state = 'main_game' pygame.display.flip() screen.blit(background, (0, 0)) screen.blit(ready_text, (screen_width // 2 -115, screen_height // 2 -43)) crosshair_group.draw(screen) crosshair_group.update() pygame.display.flip() def main_game(self): for event in pygame.event.get(): if event.type == pygame.QUIT: pygame.quit() sys.exit() if event.type == pygame.MOUSEBUTTONDOWN: crosshair.shoot() pygame.display.flip() screen.blit(background,(0,0)) target_sprites.draw(screen) crosshair_group.draw(screen) crosshair_group.update() def state_manager(self): if self.state == 'intro': self.intro() if self.state == 'main_game': self.main_game() #general setup pygame.init() clock = pygame.time.Clock() game_state = Gamestate() #game screen screen_width = 1920 screen_height = 1080 screen = pygame.display.set_mode((screen_width,screen_height)) background=pygame.image.load("task 4/tate.jpg") ready_text = pygame.image.load("task 4/logo.png") pygame.mouse.set_visible(False) #crosshair crosshair = Crosshair("task 4/tate-removebg-preview (2).png") crosshair_group = pygame.sprite.Group() crosshair_group.add(crosshair) #target target_sprites = pygame.sprite.Group() for target in range(50): new_target = Target("task 4/target.png",random.randrange(0,screen_width),random.randrange(0,screen_height)) target_sprites.add(new_target) while True: game_state.state_manager() clock.tick(60)