用户:小河鱼查看:0 回复:0 评论:0 创建时间:2021-05-12T19:14:43
【作品展示】

【作品介绍】
看了课件和回放视频制作的,下次制作两个人物都出现。
【作品源代码】
import pygame
pygame.init()
#绘制窗口
width = 1200
height = 600
screen = pygame.display.set_mode((width, height))
#加载人物
xx = pygame.image.load('喜喜.png')
xx = pygame.transform.scale(xx, (100, 153))
bg = pygame.image.load('山歌背景图片.jpg')
# 初始化音乐模块
pygame.mixer.init()
pygame.mixer.music.set_volume(0.8) # 设置音量为0.8
pygame.mixer.music.load('刘三姐-云南山歌.mp3') # 加载歌曲
pygame.mixer.music.play() # 播放音乐
#设置运动
speed = [-1, 1]
#获取图像的位置
xx_pos = xx.get_rect()
while True:
#绘制背景和人物
screen.blit(bg, (0, 0))
screen.blit(xx, xx_pos)
pygame.display.update()
#人物移动起来
xx_pos = xx_pos.move(speed)
if xx_pos.left < 0 or xx_pos.right > width:
xx = pygame.transform.flip(xx, True, False)
speed[0] = -speed[0]
if xx_pos.top < 0 or xx_pos.bottom > height:
speed[1] = -speed[1]
#检测关闭窗口按钮
for event in pygame.event.get():
if event.type == pygame.QUIT:
pygame.quit()
exit()
【提示】
部分含有Python第三方库相关内容的作品,在海龟编辑器网页端无法运行哦!如遇到这种情况,可以打开下面的链接,下载海龟编辑器客户端:
https://python.codemao.cn