Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import pygame
- import math
- # example of collision based on distance
- # fb.com/groups/pygame
- pygame.init()
- surface = pygame.display.set_mode((640, 480))
- black = [0, 0, 0]
- red = [255, 0, 0]
- blue = [0, 0, 255]
- x = 320
- y = 240
- dead = False
- # press ESCAPE to exit
- while True:
- e = pygame.event.get()
- if pygame.key.get_pressed()[pygame.K_ESCAPE]: break
- mx, my = pygame.mouse.get_pos()
- # calculate the distance between the centre of the surface and mouse location
- # if the distance is less than the combine radius (60) of the two circles then
- # a collision has occured.
- if math.sqrt((mx - x) ** 2 + (my - y) ** 2) < 60:
- dead = True
- surface.fill(black)
- if not dead: pygame.draw.circle(surface, red, (x, y), 30)
- pygame.draw.circle(surface, blue, (mx, my), 30)
- pygame.display.update()
- pygame.time.Clock().tick(60)
- pygame.quit()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement