猫史档案馆


【Python作品分享】e【作业帖】

用户:wsz1881wsz1881查看:0 回复:0 评论:0 创建时间:2021-04-20T11:23:19


【作品展示】

center_image

 

【作品介绍】

et4

 

【作品源代码】

import pygame
#初始化窗体
pygame.init()

#绘制窗体
width=450
height=400
screen=pygame.display.set_mode((width,height))

#加载人物
hh=pygame.image.load('欢欢.png')
hh=pygame.transform.scale(hh,(100,100))#缩小图片
bg = pygame.image.load('广西.jfif')
pygame.display.set_caption('载歌载舞-象州县寺小-韦胜忠-13788771881')

#加载音乐
pygame.mixer.init()
pygame.mixer.music.set_volume(0.5)
pygame.mixer.music.load('刘三姐-云南山歌.mp3')
pygame.mixer.music.play()

speed = [0.1, 0.1]#移动速度
x1=0
y1=0
hh_pos=hh.get_rect()


while True:
    x1=x1+speed[0]
    y1=y1+speed[1]    
    screen.blit(bg, (0, 0))#加载背景
    screen.blit(hh, (x1,y1))#加载人物
    pygame.display.update()

    #让人物移动起来
    #hh_pos=hh_pos.move(speed)
    #碰到左或右边缘反弹
    if x1<0 or x1+hh.get_width()> width:
        hh = pygame.transform.flip(hh,True,False)
        speed[0]=-speed[0]
      
    #碰到上或下边缘反弹
    if y1<0 or y1+hh.get_height()>height:
      speed[1]=-speed[1]
    print(speed)

    #按下退出按钮
    for event in pygame.event.get():
        if event.type==pygame.QUIT:
            pygame.quit()
            exit()
      

 

【提示】

部分含有Python第三方库相关内容的作品,在海龟编辑器网页端无法运行哦!如遇到这种情况,可以打开下面的链接,下载海龟编辑器客户端:

https://python.codemao.cn


回复

上一页1 页 / 共 0下一页