import pygame,time pygame.init() screen = pygame.display.set_mode([900, 700]) pygame.display.est_caption(弹球) red = 255,0,0 black = 0,0,0 x = 10 y = 10 dx = 2 dy = 1 redius = 10 KeepGoing = True whil
时间: 2024-04-12 12:34:19 浏览: 115
pygame演示弹球示例
e KeepGoing:
for event in pygame.event.get():
if event.type == pygame.QUIT:
KeepGoing = False
screen.fill(black)
pygame.draw.circle(screen, red, (x, y), redius)
pygame.display.flip()
x += dx
y += dy
if x < 0 or x > 900:
dx = -dx
if y < 0 or y > 700:
dy = -dy
time.sleep(0.01)
pygame.quit()
这段代码使用pygame库创建了一个窗口,并在窗口中绘制了一个移动的红色球体。程序会不断更新球体的位置,并在窗口中显示。当点击窗口关闭按钮时,程序会退出。
阅读全文