Mercurial > boomslang
comparison pyntnclick/main.py @ 576:1b1ab71535bd pyntnclick
Classify constants, which involves a whole bunch of XXX comments
author | Stefano Rivera <stefano@rivera.za.net> |
---|---|
date | Sat, 11 Feb 2012 16:02:06 +0200 |
parents | 9c3528c2cbe5 |
children | 27809609eeca |
comparison
equal
deleted
inserted
replaced
575:970cdc219e15 | 576:1b1ab71535bd |
---|---|
17 from albow.shell import Shell | 17 from albow.shell import Shell |
18 | 18 |
19 from pyntnclick.menu import MenuScreen | 19 from pyntnclick.menu import MenuScreen |
20 from pyntnclick.gamescreen import GameScreen | 20 from pyntnclick.gamescreen import GameScreen |
21 from pyntnclick.endscreen import EndScreen | 21 from pyntnclick.endscreen import EndScreen |
22 from pyntnclick.constants import ( | 22 from pyntnclick.constants import GameConstants |
23 SCREEN, FRAME_RATE, DEBUG) | |
24 from pyntnclick.resources import Resources | 23 from pyntnclick.resources import Resources |
25 from pyntnclick.sound import Sound | 24 from pyntnclick.sound import Sound |
26 from pyntnclick import state | 25 from pyntnclick import state |
27 | 26 |
28 | 27 |
29 class MainShell(Shell): | 28 class MainShell(Shell): |
30 def __init__(self, display, initial_state): | 29 def __init__(self, display, initial_state, frame_rate): |
31 Shell.__init__(self, display) | 30 Shell.__init__(self, display) |
32 self.menu_screen = MenuScreen(self) | 31 self.menu_screen = MenuScreen(self) |
33 self.game_screen = GameScreen(self, initial_state) | 32 self.game_screen = GameScreen(self, initial_state) |
34 self.end_screen = EndScreen(self) | 33 self.end_screen = EndScreen(self) |
35 self.set_timer(FRAME_RATE) | 34 self.set_timer(frame_rate) |
36 self.show_screen(self.menu_screen) | 35 self.show_screen(self.menu_screen) |
37 | 36 |
38 | 37 |
39 class GameDescriptionError(Exception): | 38 class GameDescriptionError(Exception): |
40 """Raised when an GameDescription is invalid.""" | 39 """Raised when an GameDescription is invalid.""" |
61 self._scene_list = self.SCENE_LIST | 60 self._scene_list = self.SCENE_LIST |
62 self._resource_module = self.RESOURCE_MODULE | 61 self._resource_module = self.RESOURCE_MODULE |
63 self._debug_rects = False | 62 self._debug_rects = False |
64 self.resource = Resources(self._resource_module) | 63 self.resource = Resources(self._resource_module) |
65 self.sound = Sound(self.resource) | 64 self.sound = Sound(self.resource) |
65 self.constants = self.game_constants() | |
66 | 66 |
67 def initial_state(self): | 67 def initial_state(self): |
68 """Create a copy of the initial game state.""" | 68 """Create a copy of the initial game state.""" |
69 initial_state = state.GameState(self) | 69 initial_state = state.GameState(self) |
70 initial_state.set_debug_rects(self._debug_rects) | 70 initial_state.set_debug_rects(self._debug_rects) |
72 initial_state.load_scenes(scene) | 72 initial_state.load_scenes(scene) |
73 initial_state.set_current_scene(self._initial_scene) | 73 initial_state.set_current_scene(self._initial_scene) |
74 initial_state.set_do_enter_leave() | 74 initial_state.set_do_enter_leave() |
75 return initial_state | 75 return initial_state |
76 | 76 |
77 def game_constants(self): | |
78 return GameConstants() | |
79 | |
77 def option_parser(self): | 80 def option_parser(self): |
78 parser = OptionParser() | 81 parser = OptionParser() |
79 parser.add_option("--no-sound", action="store_false", default=True, | 82 parser.add_option("--no-sound", action="store_false", default=True, |
80 dest="sound", help="disable sound") | 83 dest="sound", help="disable sound") |
81 if DEBUG: | 84 if self.constants.debug: |
82 parser.add_option("--scene", type="str", default=None, | 85 parser.add_option("--scene", type="str", default=None, |
83 dest="scene", help="initial scene") | 86 dest="scene", help="initial scene") |
84 parser.add_option("--no-rects", action="store_false", default=True, | 87 parser.add_option("--no-rects", action="store_false", default=True, |
85 dest="rects", help="disable debugging rects") | 88 dest="rects", help="disable debugging rects") |
86 return parser | 89 return parser |
89 parser = self.option_parser() | 92 parser = self.option_parser() |
90 opts, _ = parser.parse_args(sys.argv) | 93 opts, _ = parser.parse_args(sys.argv) |
91 pygame.display.init() | 94 pygame.display.init() |
92 pygame.font.init() | 95 pygame.font.init() |
93 if opts.sound: | 96 if opts.sound: |
94 self.sound.enable_sound() | 97 self.sound.enable_sound(self.constants) |
95 else: | 98 else: |
96 self.sound.disable_sound() | 99 self.sound.disable_sound() |
97 if DEBUG: | 100 if self.constants.debug: |
98 if opts.scene is not None: | 101 if opts.scene is not None: |
99 # debug the specified scene | 102 # debug the specified scene |
100 self._initial_scene = opts.scene | 103 self._initial_scene = opts.scene |
101 self._debug_rects = opts.rects | 104 self._debug_rects = opts.rects |
102 display = pygame.display.set_mode(SCREEN, SWSURFACE) | 105 display = pygame.display.set_mode(self.constants.screen, |
106 SWSURFACE) | |
103 pygame.display.set_icon(pygame.image.load( | 107 pygame.display.set_icon(pygame.image.load( |
104 self.resource.get_resource_path('icons/suspended_sentence24x24' | 108 self.resource.get_resource_path('icons/suspended_sentence24x24' |
105 '.png'))) | 109 '.png'))) |
106 pygame.display.set_caption("Suspended Sentence") | 110 pygame.display.set_caption("Suspended Sentence") |
107 shell = MainShell(display, self.initial_state) | 111 shell = MainShell(display, self.initial_state, |
112 self.constants.frame_rate) | |
108 try: | 113 try: |
109 shell.run() | 114 shell.run() |
110 except KeyboardInterrupt: | 115 except KeyboardInterrupt: |
111 pass | 116 pass |