import pygame
if __name__ == '__main__':
pygame.init()
window = pygame.display.set_mode((400, 600))
window.fill((255, 255, 255))
pygame.display.flip()
x = 100
y = 100
r = 50
y_speed = 2
x_speed = 2
while True:
pygame.time.delay(10)
window.fill((255, 255, 255))
pygame.draw.circle(window, (255, 0, 0), (x, y), r)
pygame.display.update()
y += y_speed
x += x_speed
if y > 600 - r:
y = 600 - r
y_speed = -4
elif y<50:
y = 50
y_speed = 2
elif x > 400 - r:
x = 400 - r
x_speed = -4
elif x < 50:
x = 50
x_speed = 2
for event in pygame.event.get():
if event.type == pygame.QUIT:
exit()
网友评论