Advertisement
jabela

Collision detection with sound

Dec 17th, 2015
314
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.67 KB | None | 0 0
  1. #Python 3.4.3 with Pygame
  2. import pygame
  3.  
  4. pygame.init()
  5. pygame.display.set_caption('Crash!')
  6. pygame.mixer.music.load('Slap.wav')
  7. window = pygame.display.set_mode((300, 300))
  8. running = True
  9.  
  10. #Draw Once
  11. rectplace = pygame.draw.rect(window, (255, 0, 0),(100, 100, 100, 100))
  12. pygame.display.update()
  13. #Main Loop
  14. while running:
  15.     pos = pygame.mouse.get_pos()
  16.     (pressed1,pressed2,pressed3) = pygame.mouse.get_pressed()
  17.     if rectplace.collidepoint(pos)& pressed1==1:
  18.         print("Don't slap me!")
  19.         pygame.mixer.music.play(0)
  20.         pygame.time.wait(500)
  21.     for event in pygame.event.get():
  22.         if event.type == pygame.QUIT:
  23.             running = False
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement