-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathgame_utility.py
50 lines (44 loc) · 1.04 KB
/
game_utility.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
48
49
50
import os, sys
import pygame
from pygame.locals import *
#global constants
I_MINO = 1
O_MINO = 2
T_MINO = 3
J_MINO = 4
L_MINO = 5
S_MINO = 6
Z_MINO = 7
GHOST = 8
DOWN = 10
RIGHT = 11
LEFT = 12
CLOCK = 20
COUNTERCLOCK = 21
BOARD_X = 50
BOARD_Y = 250
def load_image(name, colorkey=None):
fullname = os.path.join('tetrisdata', 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, RLEACCEL)
return image, image.get_rect()
def load_sound(name):
class NoSound:
def play(self) : pass
if not pygame.mixer:
return NoSound()
fullname = os.path.join('tetrisdata', name)
try:
sound = pygame.mixer.Sound(fullname)
except pygame.error, message:
print 'Cannot load sound:', name
raise SystemExit, message
return sound