-
Notifications
You must be signed in to change notification settings - Fork 0
/
gutils.py
36 lines (27 loc) · 919 Bytes
/
gutils.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
import pygame, os
from pygame.locals import *
IMAGES_DIR = "images"
SOUND_DIR = "sound"
def load_image(name, colorkey = False):
fullname = os.path.join(IMAGES_DIR, name)
try: image = pygame.image.load(fullname)
except pygame.error, message:
print 'No se puede cargar la imagen: ', fullname
raise SystemExit, message
image = image.convert()
if(colorkey):
colorkey = image.get_at((0,0))
image.set_colorkey(colorkey, RLEACCEL)
return image, image.get_rect()
def load_sound_file(name):
class NoneSound:
def play(self): pass
if not pygame.mixer or not pygame.mixer.get_init():
return NoneSound()
fullname = os.path.join(SOUND_DIR, name)
try:
sound = pygame.mixer.Sound(fullname)
except pygame.error, message:
print "No se pudo cargar el sonido:", fullname
raise SystemExit, message
return sound