comparison pyntnclick/main.py @ 548:ded4324b236e pyntnclick

Moved stuff around, broke everything.
author Jeremy Thurgood <firxen@gmail.com>
date Sat, 11 Feb 2012 13:10:18 +0200
parents gamelib/main.py@02cf5537d74e
children 38fb04728ac5
comparison
equal deleted inserted replaced
547:33ce7ff757c3 548:ded4324b236e
1 '''Game main module.
2
3 Contains the entry point used by the run_game.py script.
4
5 '''
6
7 # Albow looks for stuff in os.path[0], which isn't always where it expects.
8 # The following horribleness fixes this.
9 import sys
10 import os.path
11 right_path = os.path.dirname(os.path.dirname(__file__))
12 sys.path.insert(0, right_path)
13 from optparse import OptionParser
14
15 import pygame
16 from pygame.locals import SWSURFACE
17 from albow.shell import Shell
18
19 from menu import MenuScreen
20 from gamescreen import GameScreen
21 from endscreen import EndScreen
22 from constants import (
23 SCREEN, FRAME_RATE, FREQ, BITSIZE, CHANNELS, BUFFER, DEBUG)
24 from sound import no_sound, disable_sound
25 import state
26 import data
27
28
29 def parse_args(args):
30 parser = OptionParser()
31 parser.add_option("--no-sound", action="store_false", default=True,
32 dest="sound", help="disable sound")
33 if DEBUG:
34 parser.add_option("--scene", type="str", default=None,
35 dest="scene", help="initial scene")
36 parser.add_option("--no-rects", action="store_false", default=True,
37 dest="rects", help="disable debugging rects")
38 opts, _ = parser.parse_args(args or [])
39 return opts
40
41
42 class MainShell(Shell):
43 def __init__(self, display):
44 Shell.__init__(self, display)
45 self.menu_screen = MenuScreen(self)
46 self.game_screen = GameScreen(self)
47 self.end_screen = EndScreen(self)
48 self.set_timer(FRAME_RATE)
49 self.show_screen(self.menu_screen)
50
51
52 def main():
53 opts = parse_args(sys.argv)
54 pygame.display.init()
55 pygame.font.init()
56 if opts.sound:
57 try:
58 pygame.mixer.init(FREQ, BITSIZE, CHANNELS, BUFFER)
59 except pygame.error, exc:
60 no_sound(exc)
61 else:
62 # Ensure get_sound returns nothing, so everything else just works
63 disable_sound()
64 if DEBUG:
65 if opts.scene is not None:
66 # debug the specified scene
67 state.DEBUG_SCENE = opts.scene
68 state.DEBUG_RECTS = opts.rects
69 display = pygame.display.set_mode(SCREEN, SWSURFACE)
70 pygame.display.set_icon(pygame.image.load(
71 data.filepath('icons/suspended_sentence24x24.png')))
72 pygame.display.set_caption("Suspended Sentence")
73 shell = MainShell(display)
74 try:
75 shell.run()
76 except KeyboardInterrupt:
77 pass