-
Notifications
You must be signed in to change notification settings - Fork 0
/
helpers.py
37 lines (34 loc) · 1.11 KB
/
helpers.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
#Written by Ian Donovan
#Some functionality from Chimp tutorial
#see http://www.pygame.org/docs/tut/chimp/ChimpLineByLine.html
#Helper file; loads images and sounds.
import os, sys
import pygame
from pygame.locals import *
#This function loads an image and adjusts its background
def load_image(name, colorkey=None):
#'data' is the folder in which the image is saved
fullname = os.path.join('data', name)
try:
image = pygame.image.load(fullname)
except pygame.error, message:
print 'Cannot load image:', name
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, pygame.RLEACCEL)
return image, image.get_rect()
def load_sound(name):
class NoneSound:
def play(self): pass
if not pygame.mixer:
return NoneSound()
fullname = os.path.join('data', name)
try:
sound = pygame.mixer.Sound(fullname)
except pygame.error, message:
print 'Cannot load sound:', wav
raise SystemExit, message
return sound