2018-09-04homework
2018-09-05 本文已影响4人
Smilebest
一个球的动画
import pygame
from random import randint
if __name__ == '__main__':
# 初始化,创建窗口
pygame.init()
window = pygame.display.set_mode((400,600))
window.fill((255,255,255))
# c.展示内容(将纸贴在画框上)
pygame.display.flip()
# 圆心坐标
x = 100
y = 100
r = 50
add = 4
m = 2
n = 1
# 游戏循环
while True:
pygame.time.delay(5)
# 将之前window上的内容覆盖了
window.fill((255,255,255))
# 不断的画圆
pygame.draw.circle(window,(randint(0,255),randint(0,255),randint(0,255)),(x,y),r)
pygame.display.update()
# 改变y值让圆在垂直方向移动
y += m
x += n
# r += add
# if r >=600 or r <= 20 :
# add *= -1
if y >= 600 - r or y <= 50:
m *= -1
elif x >= 400-r or x <= 50:
n *= -1
# 事件检测
for event in pygame.event.get():
if event.type == pygame.QUIT:
exit()