用户:
申浩南查看:0 回复:0 评论:0 创建时间:2021-05-23T17:38:09
【作品展示】

【作品介绍】
这个作品共有三个环节:第一是显示选自《人民日报》中的文字;
第二是九张明信片,按照中国航天的发展历程来编排;
第三是一个清理太空垃圾的小游戏。
gif有1分钟长,压缩后画质不好,大家可以自己根据链接下载体验(一定要把shequ.codemao.cn/删掉)。
【作品源代码】
#下载喵o.cn/pan.喵/s/1F3RqA-1RtaIayRHKz5ixTg(复制后把“shequ.codemao.cn/”删掉)
#提取码:9999
import pygame
from random import*
pygame.init()
pygame.mixer.init()
screen = pygame.display.set_mode([960, 720])
loadimg = pygame.image.load
pygame.display.set_caption('给航天人的一张“明星片”')
timer=pygame.time.Clock()
fm=loadimg('封面.png')
fmtext=loadimg('封面文字.png')
start=loadimg('查看详情.png')
fm2=loadimg('封面2.png')
fm2t=loadimg('文字.png')
_next=loadimg('继续.png')
lx = loadimg('流星.png')
gamebg = loadimg('gamebg.png')
gs=loadimg('gamestart.png')
player=loadimg('player.png')
zidan=loadimg('zidan.png')
fmh=loadimg('fmh.png')
black = 0, 0, 0
white = 255, 255, 255
darkblue = 37, 67, 82
def event_loop():
# 游戏事件循环
for event in pygame.event.get():
if event.type == pygame.QUIT:
pygame.quit()# 结束窗口
def drawwords(word, font, size, x, y, color):#绘制文字
font = pygame.font.SysFont(font, size)
text = font.render(word, True, color)
screen.blit(text, (x, y))
def mousehide(real):
if real:
pygame.mouse.set_visible(False)#隐藏鼠标指针
else:
pygame.mouse.set_visible(True)#显示鼠标指针
level = 0
fmtY=-100
lxX=randint(100,960)
lxY=-200
music=pygame.mixer.music.load('Victory.wav')
pygame.mixer.music.play()
while True:
event_loop()
if level==0:
event_loop()
screen.blit(fm,(0,0))
screen.blit(fmtext,(280,fmtY))
for y in range (50):
fmtY+=(50-y)/4
event_loop()
screen.blit(fm,(0,0))
screen.blit(fmtext,(280,fmtY))
pygame.display.update()
screen.blit(start,(370,600))
pygame.display.update()
_start=True
while _start:
event_loop()
screen.blit(fm, (0, 0))
screen.blit(fmtext, (280, fmtY))
screen.blit(start, (370, 600))
screen.blit(lx,(lxX,lxY))
pygame.display.update()
lxX -= 8
lxY += 8
if lxX<=-200:
lxX = randint(100, 960)
lxY = -200
for event in pygame.event.get():
if event.type==pygame.MOUSEBUTTONDOWN:
if pygame.mouse.get_pos()[0] >= 370 and pygame.mouse.get_pos()[0] <= 370+start.get_width() and \
pygame.mouse.get_pos()[1] >= 600 and pygame.mouse.get_pos()[1] <= 600+start.get_height():
_start=False
level=1
if level==1:
mousehide(True)
for y in range (1280):
event_loop()
screen.blit(fm2,(0,0))
screen.blit(fm2t,(40,680-y/2))
pygame.display.update()
_1_2=True
screen.blit(_next,(830,670))
pygame.display.update()
mousehide(False)
while _1_2:
event_loop()
for event in pygame.event.get():
if event.type == pygame.MOUSEBUTTONDOWN:
if pygame.mouse.get_pos()[0] >= 830 and pygame.mouse.get_pos()[0] <= 830+_next.get_width() and \
pygame.mouse.get_pos()[1] >= 670 and pygame.mouse.get_pos()[1] <= 670+_next.get_height():
_1_2=False
level=2
if level==2:
for i in range(1,10):#9张明信片
if pygame.mixer.music.get_busy() == False:
pygame.mixer.music.play()
mxpX = 960
for x in range (17):
screen.blit(fm,(0,00))
mxp=loadimg('%d.png'%i)
screen.blit(mxp,(mxpX,90))
pygame.display.update()
mxpX -= 55
drawwords('单击鼠标以继续>>', 'SimHei', 25, 730, 680, white)
pygame.display.update()
w = True
while w:
event_loop()
for event in pygame.event.get():
if event.type == pygame.MOUSEBUTTONDOWN:
w = False
for x in range (17):
screen.blit(fm,(0,00))
mxp=loadimg('%d.png'%i)
screen.blit(mxp,(mxpX,90))
pygame.display.update()
mxpX -= 55
level=3
if level==3:
screen.blit(fmh,(0,0))
for i in range(80):
event_loop()
screen.blit(fmh, (0, 0))
drawwords('怎么样?', 'SimHei', 50, 960-i*12, 0, white)
pygame.display.update()
for i in range(80):
event_loop()
screen.blit(fmh, (0, 0))
drawwords('怎么样?', 'SimHei', 50, 0, 0, white)
drawwords('欣赏完这些明信片后,', 'SimHei', 50, 960-i*12, 50, white)
pygame.display.update()
for i in range(80):
event_loop()
screen.blit(fmh, (0, 0))
drawwords('怎么样?', 'SimHei', 50, 0, 0, white)
drawwords('欣赏完这些明信片后,', 'SimHei', 50, 0, 50, white)
drawwords('您是否对航空航天充满向往?', 'SimHei', 50, 960-i*12, 100, white)
pygame.display.update()
for i in range(80):
event_loop()
screen.blit(fmh, (0, 0))
drawwords('怎么样?', 'SimHei', 50, 0, 0, white)
drawwords('欣赏完这些明信片后,', 'SimHei', 50, 0, 50, white)
drawwords('您是否对航空航天充满向往?', 'SimHei', 50, 0, 100, white)
drawwords('现在,', 'SimHei', 50, 960-i*12, 150, white)
pygame.display.update()
for i in range(80):
event_loop()
screen.blit(fmh, (0, 0))
drawwords('怎么样?', 'SimHei', 50, 0, 0, white)
drawwords('欣赏完这些明信片后,', 'SimHei', 50, 0, 50, white)
drawwords('您是否对航空航天充满向往?', 'SimHei', 50, 0, 100, white)
drawwords('现在,', 'SimHei', 50, 0, 150, white)
drawwords('您可以通过此游戏,', 'SimHei', 50, 960-i*12, 200, white)
pygame.display.update()
for i in range(80):
event_loop()
screen.blit(fmh, (0, 0))
drawwords('怎么样?', 'SimHei', 50, 0, 0, white)
drawwords('欣赏完这些明信片后,', 'SimHei', 50, 0, 50, white)
drawwords('您是否对航空航天充满向往?', 'SimHei', 50, 0, 100, white)
drawwords('现在,', 'SimHei', 50, 0, 150, white)
drawwords('您可以通过此游戏,', 'SimHei', 50, 0, 200, white)
drawwords('来当一次宇宙飞船驾驶员,', 'SimHei', 50, 960-i*12, 250, white)
pygame.display.update()
for i in range(80):
event_loop()
screen.blit(fmh, (0, 0))
drawwords('怎么样?', 'SimHei', 50, 0, 0, white)
drawwords('欣赏完这些明信片后,', 'SimHei', 50, 0, 50, white)
drawwords('您是否对航空航天充满向往?', 'SimHei', 50, 0, 100, white)
drawwords('现在,', 'SimHei', 50, 0, 150, white)
drawwords('您可以通过此游戏,', 'SimHei', 50, 0, 200, white)
drawwords('来当一次宇宙飞船驾驶员,', 'SimHei',50, 0, 250, white)
drawwords('使用特制药剂,', 'SimHei', 50, 960-i*12, 300, white)
pygame.display.update()
for i in range(80):
event_loop()
screen.blit(fmh, (0, 0))
drawwords('怎么样?', 'SimHei', 50, 0, 0, white)
drawwords('欣赏完这些明信片后,', 'SimHei', 50, 0, 50, white)
drawwords('您是否对航空航天充满向往?', 'SimHei', 50, 0, 100, white)
drawwords('现在,', 'SimHei', 50, 0, 150, white)
drawwords('您可以通过此游戏,', 'SimHei', 50, 0, 200, white)
drawwords('来当一次宇宙飞船驾驶员,', 'SimHei',50, 0, 250, white)
drawwords('使用特制药剂,', 'SimHei', 50, 0, 300, white)
drawwords('来清理太空垃圾吧!', 'SimHei', 50, 960-i*12, 350, white)
pygame.display.update()
drawwords('单击鼠标以继续>>', 'SimHei', 25, 730, 680, white)
pygame.display.update()
w = True
while w:
event_loop()
for event in pygame.event.get():
if event.type == pygame.MOUSEBUTTONDOWN:
w = False
level=4
if level==4:
pygame.mixer.music.stop()
music=pygame.mixer.Sound('Victory.wav')
music.play()
screen.blit(gamebg,(0,0))
screen.blit(gs,(100,500))
pygame.display.update()
w=True
while w:
for event in pygame.event.get():
if event.type == pygame.MOUSEBUTTONDOWN:
if pygame.mouse.get_pos()[0] >= 100 and pygame.mouse.get_pos()[0] <= 100+gs.get_width() and \
pygame.mouse.get_pos()[1] >= 500 and pygame.mouse.get_pos()[1] <= 500+gs.get_height():
w=False
w=True
zidanX=[]
zidanY=[]
rubbish=loadimg('r%d.png'%randint(1,4))
rubbishX=randint(0,850)
rubbishY=-200
score=0
mousehide(True)
while w:
event_loop()
screen.fill(darkblue)
pY = pygame.mouse.get_pos()[0]-player.get_width()/2
screen.blit(player, (pY, 600))
screen.blit(rubbish,(rubbishX,rubbishY))
if randint(1,8)==1:
zidanX.append(pY+player.get_width()/2)
zidanY.append(620)
for i in range (len(zidanX)):
screen.blit(zidan,(zidanX[i],zidanY[i]))
for i in range(len(zidanX)):
zidanY[i]=zidanY[i]-20
for i in range(len(zidanX)):
if zidanY[i] - rubbishY<50 and rubbishY>-100 and \
abs(rubbishX-zidanX[i])<120 and zidanY[i] - rubbishY>-100:
rubbish = loadimg('r%d.png' % randint(1, 4))
rubbishX = randint(0, 850)
rubbishY = -200
score+=1
drawwords('已清理%d个太空垃圾'%score, 'SimHei', 15, 0, 0, white)
if rubbishY>720:
level=5
w=False
rubbishY+=3
pygame.display.update()
timer.tick(100)
mousehide(False)
if level==5:
screen.blit(fm,(0,0))
drawwords('游戏结束', 'SimHei', 30, 0, 0, white)
drawwords('共清理%d个太空垃圾'%score, 'SimHei', 30, 0, 30, white)
drawwords('单击右上角“X”退出', 'SimHei', 30, 0, 60, white)
pygame.display.update()
event_loop()
pygame.display.update()
【提示】
部分含有Python第三方库相关内容的作品,在海龟编辑器网页端无法运行哦!如遇到这种情况,可以打开下面的链接,下载海龟编辑器客户端:
https://python.codemao.cn