1,小球随机运动
import pygame
from random import randint
''' '''
def draw_cirtle(x,y):
pygame.draw.circle(window, ( 255,0,255),(x,y),20)
pygame.display.update()
''' '''
pygame.init()
window = pygame.display.set_mode((400, 600))
window.fill((255, 255, 255))
x=randint(20,580)
y=randint(20,580)
print(x,y)
a=randint(-3,3)
b=randint(-3,3)
add_x=a
add_y=b
# 游戏循环
while True:
print(add_x,add_y)
pygame.time.delay(10)
# 将之前纸上的内容给覆盖
window.fill((255, 255, 255))
# 不断的画圆
draw_cirtle(x,y)
if (x+20)>=400:
x=380
add_x *= -1
elif (x-20)<=0:
x = 20
add_x *= -1
elif (y+20)==600:
y=580
add_y *= -1
elif (y-20)<=0:
y = 20
add_y *= -1
y+=add_y
x+=add_x
# 事件检测
for event in pygame.event.get():
if event.type == pygame.QUIT:
exit()
网友评论