-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathloader.py
47 lines (41 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
44
45
46
47
try:
import sys
import os
import pygame
import pygame.font
from pygame.locals import *
except ImportError as 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 as 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 as message:
print("Cannot load sound file: ", fullname)
raise SystemExit
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 as message:
print("Cannot load image: ", fullname)
raise SystemExit
return image, image.get_rect()