用户:
码精查看:0 回复:2 评论:0 创建时间:2019-10-05T21:40:12
【作品展示】

【作品介绍】
打开后慢慢看,注意注释内容。
【作品源代码】
# SmileyBounceWithTrails.py
import pygame #申请pygame库,请自行下载
pygame.init()
screen = pygame.display.set_mode([800,600]) #申请pygame运行窗口
keep_going = True
pic = pygame.image.load("E:/编程资料/Python/CrazySmile.bmp")
#使用时把上行绿色字改成自己的文件放入的精确位置和文件名字,素材在网喵teachkids”获取
colorkey = pic.get_at((0, 0))
pic.set_colorkey(colorkey)
picx = 0
picy = 0
BLACK = (0,0,0)
timer = pygame.time.Clock()
speedx = 5
speedy = 5
while keep_going:
for event in pygame.event.get():
if event.type == pygame.QUIT:
keep_going = False
picx += speedx
picy += speedy
if picx <= 0 or picx + pic.get_width() >= 800:
speedx = -speedx
if picy <= 0 or picy + pic.get_height() >= 600:
speedy = -speedy
screen.fill(BLACK) #可以去试一试把这行代码注释掉
screen.blit(pic, (picx, picy))
pygame.display.update()
timer.tick(60)
pygame.quit() #游戏结束
【提示】
部分含有Python第三方库相关内容的作品,在海龟编辑器网页端无法运行哦!如遇到这种情况,可以打开下面的链接,下载海龟编辑器客户端:
https://python.codemao.cn