是时候再来一个小游戏制作啦~
23.try:
24.surface =pygame.image.load(file)
25.except pygame.error:
26.raise SystemExit('Could not load image "%s"%s'%(file,
pygame.get_error()))
27.return surface.convert()
28.
29.def load_images(*files):
30.imgs =[]
31.for file in files:
32.imgs.append(load_image(file))
33.return imgs
34.
35.
36.class dummysound:
37.def play(self):pass
38.
39.def load_sound(file):
40.if not pygame.mixer:return dummysound()
41.file =os.path.join(main_dir,'data',file)
42.try:
43.sound =pygame.mixer.Sound(file)
44.return sound
45.except pygame.error:
46.print ('Warning,unable to load,%s'%file)
47.return dummysound()
#!/usr/bin/env python 目的是在运行python 脚本的时候告诉操作系统我们要用python 解释器去运行py 脚本。
所以我们在第一句往往会写如下两句中的其中一句:#!/usr/bin/python 或#!/usr/bin/env python。
就是说在没有在执行程序时指出用什么程序运行py 脚本时,系统会去调用python 程序来执行。