操作火箭小心翼翼地回家的小游戏。以下是部分代码预览:
"""请按上\左\右键操作火箭,让它平安着陆,着陆的时候速度不能太快哦,否则就会爆炸""" import os from turtle import * def init_audio(): """初始化音频""" try: import pygame pygame.mixer.init() pygame.mixer.music.load("audios\\495046_The-War-W.wav") pygame.mixer.music.play(-1,0) bumped_sound = pygame.mixer.Sound("audios\\中爆炸.wav") except: bumped_sound = None return bumped_sound def init_screen(): """初始化屏幕""" screen = Screen() screen.title("太空出租箭_作者:李兴球") screen.bgcolor("black") screen.bgpic(images_folder + "背景1.png") screen.setup(960,720) screen.delay(0) return screen def makelevel(): """生成关卡对象所需要的嵌套列表,以下代码可用关卡设计器生成。""" map1 = [(200,100),(-250,180),(-260,-200),(260,-200)] map2 = [(-200,-200),(200,180),(300,-180),(0,-90)] map3 = [(-100,-40),(120,160),(230,230),(-230,-230),(230,-230)] map4 = [(0,0),(-100,190),(230,230),(-180,-160),(130,-230),(-350,-210),(350,-0)] map5 = [(-100,0),(-100,190),(230,230),(-180,-160),(130,-230),(50,-210),(350,-100),(300,100)] maplist = [map1,map2,map3,map4,map5] return maplist def main(): """生成关卡对象,启动火箭""" screen.onkeypress(None,"Return") screen.bgpic(images_folder + "背景2.png") levels = Level(maplist,screen) # 根据每关卡的坐标点列表生成关卡对象 images = [images_folder + '箭造型1.gif',images_folder + '箭造型2.gif'] # 火箭造型 [screen.addshape(image) for image in images] # 注册到形状列表 explode_images = [images_folder + "爆炸" + str(i) + ".gif" for i in range(1,21)] [screen.addshape(image) for image in explode_images] # 注册爆炸造型到形状列表 ps = images,explode_images,levels,bumped_sound arrow = Firearrow(*ps) # 火箭实例化后自动下落 if __name__=="__main__": images_folder = os.getcwd() + os.sep + "images" + os.sep bumped_sound = init_audio() screen = init_screen() # 初始化屏幕 maplist = makelevel() # 每关卡的坐标点列表组成的列表。 screen.onkeypress(main,"Return") # 按回车键启动main函数 screen.listen() screen.mainloop()
下载完整源代码与素材,请
需要浏览更多吗?
成为会员后,登陆才能继续浏览!联系微信scratch8即可办理会员。
(会员专属:能浏览所有文章,下载所有带链接的Python资源。)