I am new to pygame, not python and I am trying to make a alien shooter game, and i want collision between the crosshairs and the sprite. I want to collide a circle with a alien image and a shape? I don't want rects, just pure 'click on sprite and disappear'. Is there any way to do this? Here is the code:
"""Alien_ShooterDescription: a game to shoot aliens"""import pygameimport tskimport randompygame.init()WIDTH = 1018HEIGHT = 573w = pygame.display.set_mode([WIDTH, HEIGHT])c = pygame.time.Clock()shooting= FalseinvaderImage = []invader_X = []invader_Y = []invader_Xchange = []invader_Ychange = []no_of_invaders = 8turn = Falsefor num in range(no_of_invaders): alien = pygame.image.load('SquidMan.png') alien = pygame.transform.scale(alien, (100,100)) alien_hb = pygame.Rect(200, 500, 50, 50) #collide = pygame.Rect.colliderect(player_rect, mouse) invaderImage.append(alien) invader_X.append(random.randint(64, 737)) invader_Y.append(random.randint(30, 180)) invader_Xchange.append(0) invader_Ychange.append(1)def invader(x, y, i): w.blit(invaderImage[i], (x, y))drawing = Truewhile drawing: for e in pygame.event.get(): if e.type == pygame.QUIT: drawing = False if e.type == pygame.MOUSEBUTTONDOWN: shooting = True else: shooting = False #collide = pygame.Rect.colliderect(alien_rect, center_rect) x, y = pygame.mouse.get_pos() #print(x,y) if shooting == True: # gives the flashing effect when shooting color = (0,0,0) else: color = (255,255,255) for i in range(no_of_invaders): invader_X[i] += invader_Xchange[i] # movement of the invader for i in range(no_of_invaders): invader_Y[i] += invader_Ychange[i] invader(invader_X[i], invader_Y[i], i) line1 = pygame.draw.line(w, color, (x,y), (350, 700), 3) line2 = pygame.draw.line(w, color, (x,y), (650, 700), 3) # crosshares center = pygame.draw.circle(w,color, (x, y), 10, 2) pygame.draw.line(w, color, (x,y), (x+20, y), 3) pygame.draw.line(w, color, (x,y), (x-20, y), 3) #################### # | # # --o-- # # | # #################### pygame.draw.line(w, color, (x,y), (x, y+20), 3) pygame.draw.line(w, color, (x,y), (x, y-20), 3) pygame.display.flip() c.tick(20) w.fill((0,0,0))
I tried to fix this but I am not sure how to do it without rects