jabela

Whackamole with scoring and lives

Dec 17th, 2015
163
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.27 KB | None | 0 0
  1. #Python 3.4.3 with Pygame
  2. import pygame
  3. import random
  4. pygame.init()
  5. pygame.display.set_caption('Crash!')
  6. pygame.mixer.music.load('Slap.wav')
  7.  
  8. #variables
  9. window = pygame.display.set_mode((600, 600))
  10. rectplace = pygame.draw.rect(window, (0, 0, 0),(0, 0, 100, 100))
  11. counter = 200000
  12. randx = random.randrange(100, 500)
  13. randy = random.randrange(100, 500)
  14. score = 0
  15. life = 6
  16. running = True
  17.  
  18. #Main Loop
  19. while running:
  20.     pos = pygame.mouse.get_pos()
  21.     (pressed1,pressed2,pressed3) = pygame.mouse.get_pressed()
  22.     if rectplace.collidepoint(pos)& pressed1==1:
  23.         score=score+1
  24.         print("Score ",score)
  25.         pygame.mixer.music.play(0)
  26.         counter=200000
  27.         life=life+1
  28.     if counter == 200000:
  29.         rectplace = pygame.draw.rect(window, (0, 0, 0),(randx, randy, 100, 100))
  30.         pygame.display.update()
  31.         randx = random.randrange(100, 500)
  32.         randy = random.randrange(100, 500)
  33.         rectplace = pygame.draw.rect(window, (255, 0, 0),(randx, randy, 100, 100))
  34.         counter=0
  35.         pygame.display.update()
  36.         life=life-1
  37.         print ("lives: ",life)
  38.     counter=counter+1
  39.     if life == 0:
  40.         running = False
  41.     for event in pygame.event.get():
  42.         if event.type == pygame.QUIT:
  43.             running = False
Add Comment
Please, Sign In to add comment