Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import pygame
- pygame.init()
- WIDTH = 970
- HEIGHT = 600
- window = pygame.display.set_mode((WIDTH, HEIGHT))
- red = (255, 0, 0)
- green = (0, 255, 0)
- run = True
- speed = 2
- x, y = 100, 200
- dx, dy = speed, speed
- count = 0
- clock = pygame.time.Clock()
- color = red
- while run:
- clock.tick(60)
- window.fill((0,0,0))
- for event in pygame.event.get():
- if event.type == pygame.QUIT:
- run = False
- x += dx
- y += dy
- circle = pygame.draw.circle(window, color, (x, y), 40)
- m = pygame.mouse.get_pos()
- r = pygame.Rect(m[0], m[1], 10,10)
- pygame.mouse.set_visible(False)
- rec = pygame.draw.rect(window, (0, 255, 0), r)
- if not circle.colliderect(rec):
- # print(count)
- count += 0.1
- color = red
- else:
- color = green
- if circle.left <= 0:
- speed += 0.5
- dx = speed
- elif circle.right >= WIDTH:
- speed += 0.5
- dx = -speed
- elif circle.top <= 0:
- speed += 0.5
- dy = speed
- elif circle.bottom >= HEIGHT:
- speed += 0.5
- dy = -speed
- print(speed)
- pygame.display.update()
- pygame.quit()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement