0

basically the title, i am making a game where you avoid objects (the circles), I tried looking up solutions and the problem appears to be in the event handling, but none of the solutions worked for me.what can I do to fix this?

run = True
    
while run:

    pygame.time.delay(10)
    
    for event in pygame.event.get(): ##cycles through event list
            
        if event.type == pygame.MOUSEBUTTONDOWN:
            if pygame.mouse.get_pos()[0] >= 500 and pygame.mouse.get_pos()[1] >= 500:
                if pygame.mouse.get_pos()[0] <= 530 and pygame.mouse.get_pos()[1] <= 560:
                        pygame.quit()
                        sys.exit(0)
            if pygame.mouse.get_pos()[0] >= 500 and pygame.mouse.get_pos()[1] >= 350:
                if pygame.mouse.get_pos()[0] <= 530 and pygame.mouse.get_pos()[1] <= 410:
                        key = pygame.key.get_pressed()
        
                        if key[pygame.K_a] and character_x>0: ##move left when A is pressed
                            character_x -= character_vel
                        if key[pygame.K_d] and character_x<1000 - character_width: ##move righ when D is pressed
                            character_x += character_vel
                        if key[pygame.K_w] and character_y>0: ##move up when W is pressed
                            character_y -= character_vel
                        if key[pygame.K_s] and character_y<700 - character_height - 10: ##move down when S is pressed
                            character_y += character_vel
                        
                        character_rect = pygame.Rect((character_x, character_y, 30, 30))

                        win.fill((0, 0, 0))
                        win.blit(bg, (0, 0))
                        pygame.draw.rect(win, (255, 0, 0), character_rect) ##draws characters
                        win.blit(Character_image, (character_x, character_y))
                        
                        for count in range(numEnemies):
                            pygame.draw.circle(win, EnemiesColorList[count], EnemiesPosList[count], EnemiesSizeList[count])
                        
                        for count in range(numEnemies): ##asteroid movement
                            EnemiesPosList[count][0] -= 10
                            
                        if EnemiesPosList[count][0] < 0 - EnemiesSizeList[count]: ##makes sure the enemies reset when reaching the end of the screen
                            EnemiesPosList = []
                            for count in range(numEnemies):
                                EnemiesPosList.append( [screen_width,random.randint(0,480)] )
                                pygame.draw.circle(win, EnemiesColorList[count], EnemiesPosList[count], EnemiesSizeList[count])      
                        

                        
                        label = myfont.render(str(lives), 1, (255,255,0)) ##displays score and lives on screen
                        label_2 = myfont.render(str(score), 1, (255,255,0))
                        win.blit(label, (20, 20))
                        win.blit(label_2, (screen_width - 20, 20))
    
        if event.type == pygame.quit:
            pygame.quit()
            sys.exit()
    
    pygame.display.flip()
    pygame.display.update()
        
pygame.quit()

everything works fine for the menu screen, the quit button does what it should and the begin button takes me to the gameplay screen, but as soon as i get there everythinng freezes, my character wont respnd to the controls and the enemies won't actually move.

0 Answers0