Mercurial > pyntnclick
comparison gamelib/main.py @ 107:5213b45fcc7e
Initial event sound support
author | Neil Muller <neil@dip.sun.ac.za> |
---|---|
date | Tue, 24 Aug 2010 14:07:07 +0200 |
parents | 65976205fc2d |
children | 97322b78d1c1 |
comparison
equal
deleted
inserted
replaced
106:da547e148532 | 107:5213b45fcc7e |
---|---|
8 # The following horribleness fixes this. | 8 # The following horribleness fixes this. |
9 import sys | 9 import sys |
10 import os.path | 10 import os.path |
11 right_path = os.path.dirname(os.path.dirname(__file__)) | 11 right_path = os.path.dirname(os.path.dirname(__file__)) |
12 sys.path.insert(0, right_path) | 12 sys.path.insert(0, right_path) |
13 from optparse import OptionParser | |
13 | 14 |
14 import pygame | 15 import pygame |
15 from pygame.locals import SWSURFACE | 16 from pygame.locals import SWSURFACE |
16 from albow.dialogs import alert | 17 from albow.dialogs import alert |
17 from albow.shell import Shell | 18 from albow.shell import Shell |
18 | 19 |
19 from menu import MenuScreen | 20 from menu import MenuScreen |
20 from gamescreen import GameScreen | 21 from gamescreen import GameScreen |
21 from constants import SCREEN, FRAME_RATE | 22 from constants import SCREEN, FRAME_RATE, FREQ, BITSIZE, CHANNELS, BUFFER |
23 from sound import no_sound, disable_sound | |
24 | |
25 def parse_args(args): | |
26 parser = OptionParser() | |
27 parser.add_option("--no-sound", action="store_false", default=True, | |
28 dest="sound", help="disable sound") | |
29 opts, _ = parser.parse_args(args or []) | |
30 return opts | |
22 | 31 |
23 class MainShell(Shell): | 32 class MainShell(Shell): |
24 def __init__(self, display): | 33 def __init__(self, display): |
25 Shell.__init__(self, display) | 34 Shell.__init__(self, display) |
26 self.menu_screen = MenuScreen(self) | 35 self.menu_screen = MenuScreen(self) |
27 self.game_screen = GameScreen(self) | 36 self.game_screen = GameScreen(self) |
28 self.set_timer(FRAME_RATE) | 37 self.set_timer(FRAME_RATE) |
29 self.show_screen(self.menu_screen) | 38 self.show_screen(self.menu_screen) |
30 | 39 |
31 def main(): | 40 def main(): |
41 opts = parse_args(sys.argv) | |
32 pygame.display.init() | 42 pygame.display.init() |
33 pygame.font.init() | 43 pygame.font.init() |
44 if opts.sound: | |
45 try: | |
46 pygame.mixer.init(FREQ, BITSIZE, CHANNELS, BUFFER) | |
47 except pygame.error, exc: | |
48 no_sound(exc) | |
49 else: | |
50 # Ensure get_sound returns nothing, so everything else just works | |
51 disable_sound() | |
34 display = pygame.display.set_mode(SCREEN, SWSURFACE) | 52 display = pygame.display.set_mode(SCREEN, SWSURFACE) |
35 shell = MainShell(display) | 53 shell = MainShell(display) |
36 shell.run() | 54 shell.run() |
37 | 55 |