I'm making a simple "Find the objects" game in pygame. It increases the score by 1 whenever an element is clicked. I am using the coordinates of an element to check if it has been clicked or not. Here's the code:
import pygame
pygame.init()
pygame.mixer.init()
screen_width = 905
screen_height = 390
screen = pygame.display.set_mode([screen_width, screen_height])
pygame.display.set_caption("Game")
clock = pygame.time.Clock()
done = False
score = 0
first = pygame.image.load("1st.png").convert()
current_level_no = 1
if current_level_no ==1:
screen.blit(first, [0, 0])
while not done:
for event in pygame.event.get():
if event.type == pygame.QUIT:
done = True
if event.type == pygame.MOUSEBUTTONDOWN:
x = event.pos[0]
y = event.pos[1]
if current_level_no == 1:
if x > 766 and x < 787:
if y > 311 and y < 339:
pygame.draw.ellipse (screen, LIME, [766, 311, 21, 28], 3)
score +=1
if x > 60 and x < 135:
if y > 365 and y < 380:
pygame.draw.ellipse (screen, LIME, [60, 365, 71, 15], 3)
score +=1
if x > 798 and x < 843:
if y > 150 and y < 171:
pygame.draw.ellipse (screen, LIME, [798, 150, 45, 25], 3)
score +=1
if x > 61 and x < 102:
if y > 115 and y < 141:
pygame.draw.ellipse (screen, LIME, [61, 115, 44, 36], 3)
score +=1
if x > 357 and x < 394:
if y > 151 and y < 170:
pygame.draw.ellipse (screen, LIME, [357, 151, 44, 22], 3)
score +=1
if x > 256 and x < 288:
if y > 209 and y < 230:
pygame.draw.ellipse (screen, LIME, [256, 209, 37, 25], 3)
score +=1
clock.tick(60)
pygame.display.flip()
pygame.quit()
I want to know how to detect if the element has already been clicked by the user. Thanks.