[6c45ee]: helper_functions.py Maximize Restore History

Download this file

helper_functions.py    47 lines (36 with data), 1.2 kB

 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
# -*- coding: utf-8 -*-
'''
Created on 19 jul 2012
@author: Marco Baxemyr
'''
import os
import datetime
import pygame
def load_image(file_name):
"""inspired by http://www.linuxjournal.com/article/7694"""
full_name = os.path.join('images', file_name)
try:
image = pygame.image.load(full_name)
except pygame.error, message:
print "Couldn't load image:", full_name
raise SystemExit, message
image = image.convert_alpha()
return image
def load_sound(file_name):
"""inspired by http://www.linuxjournal.com/article/7694"""
class No_Sound:
def play(self):
pass
if not pygame.mixer or not pygame.mixer.get_init():
return No_Sound()
full_name = os.path.join('audio', file_name)
if os.path.exists(full_name):
sound = pygame.mixer.Sound(full_name)
return sound
else:
print 'File not found', full_name
return No_Sound()
def load_font(file_name, font_size):
full_name = os.path.join('fonts', file_name)
if os.path.exists(full_name):
return pygame.font.Font(full_name, font_size)