title: Mouse clicked on random image in python
body: <p>I am beginner in python. Recently i am doing a pygame poject. I want to make a game where the screen will show an image in a random position, and after 0.3 seconds, the image will move to another random position again. The player will repeatedly click on the position-changed image with the mouse and the score will increase. Even if I do everything, clicking with the mouse does not increase the score.</p>
  
  <p>Here is my code: </p>
  
  <pre class="lang-py prettyprint-override"><code>pygame.init()
  width = 500
  height = 500
  score = 0
  display = pygame.display.set_mode((width, height))
  pygame.display.set_caption("Tapping")
  image = pygame.image.load('spaceship.png').convert()
  sides = ['Top', 'Botom', 'left', 'Right']
  weights = [width, width, height, height]
  posx = random.randint(50, 450)
  posy = random.randint(20, 460)
  tsp = 1.2
  Mousex = 0
  Mousey = 0
  
  def image_view(x, y):
      display.blit(image, (x, y))
  
  run = True
  while run:
      display.fill((153, 255, 187))
      for event in pygame.event.get():
          if event.type == pygame.QUIT:
              run = False
          if event.type == pygame.MOUSEBUTTONDOWN:
              Mousex, Mousey = event.pos
              if image.get_rect().collidepoint(posx, posy):
                  score += 1
  
      side = random.choices(sides, weights)[0]
  
      if side == 'Top':
          posx = random.randrange(100, 300)
          posy = random.randrange(20, 100)
          time.sleep(tsp)
      elif side == 'Botom':
          posx = random.randrange(350, 430)
          posy = random.randrange(250, 450)
          time.sleep(tsp)
      elif side == 'left':
          posx = random.randrange(20, 250)
          posy = random.randrange(20, 250)
          time.sleep(tsp)
      elif side == 'Right':
          posx = random.randrange(280, 450)
          posy = random.randrange(280, 450)
          time.sleep(tsp)
  
      print(score)
      image_view(posx, posy)
      pygame.display.update()
  </code></pre>