---------原创,引用请注明出处liurm.mypm.net-----------------
1 pyfunction.py 这个实现一些通用的方法,为便于重用,单独放到一个py中
# my common functions here
"""
functions list:
loadImage(name,colorkey)
loadSound(name)
"""
#imports
import os,pygame
from pygame.locals import *
def loadImage(name,colorkey=None):
fullname = os.path.join('img',name)
try:
image = pygame.image.load(fullname)
except pygame.error, message:
print 'Cannot load image:', fullname
raise SystemExit, message
image = image.convert()
if colorkey is not None:
if colorkey is -1:
colorkey = image.get_at((0,0))
image.set_colorkey(colorkey,RLEACCEL)
return image, image.get_rect()
def loadSound(name):
class NoneSound:
def play(self): pass
if not pygame.mixer or not pygame.mixer.get_init():
return NoneSound()
fullname = os.path.join('snd',name)
try:
sound = pygame.mixer.Sound(fullname)
except pygame.error, message:
print 'Cannot load sound:', fullname
raise SystemExit, message
return sound