forked from mcgillij/pyDF
-
Notifications
You must be signed in to change notification settings - Fork 0
/
loader.py
43 lines (40 loc) · 1.29 KB
/
loader.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
try:
import pygame, random, sys
import pygame.font
from pygame.locals import *
import os
except ImportError, err:
print "couldn't load module. %s" % (err)
sys.exit(2)
def load_font(name, size):
"""Load up a font file, or try to use the default None(system font)"""
fullname = os.path.join('data', name)
try:
font = pygame.font.Font(fullname, size)
except pygame.error, message:
print "Cannot load font file: ", fullname
else:
font = pygame.font.SysFont(None, size)
return font
def load_sound(name):
""" Load the sound file from the data directory, return sound """
fullname = os.path.join('data', name)
try:
sound = pygame.mixer.Sound(fullname)
except pygame.error, message:
print "Cannot load sound file: ", fullname
raise SystemExit, message
return sound
def load_png(name):
""" Load image and return image object """
fullname = os.path.join('data', name)
try:
image = pygame.image.load(fullname)
if image.get_alpha() is None:
image = image.convert()
else:
image = image.convert_alpha()
except pygame.error, message:
print 'Cannot load image: ', fullname
raise SystemExit, message
return image, image.get_rect()