comparison pyntnclick/main.py @ 553:ebb2efcb4ea7 pyntnclick

Create a re-usable main function.
author Simon Cross <hodgestar+bzr@gmail.com>
date Sat, 11 Feb 2012 13:40:51 +0200
parents 38fb04728ac5
children 99a1420097df
comparison
equal deleted inserted replaced
552:15713dfe555d 553:ebb2efcb4ea7
37 opts, _ = parser.parse_args(args or []) 37 opts, _ = parser.parse_args(args or [])
38 return opts 38 return opts
39 39
40 40
41 class MainShell(Shell): 41 class MainShell(Shell):
42 def __init__(self, display): 42 def __init__(self, display, initial_state):
43 Shell.__init__(self, display) 43 Shell.__init__(self, display)
44 self.menu_screen = MenuScreen(self) 44 self.menu_screen = MenuScreen(self)
45 self.game_screen = GameScreen(self) 45 self.game_screen = GameScreen(self, initial_state)
46 self.end_screen = EndScreen(self) 46 self.end_screen = EndScreen(self)
47 self.set_timer(FRAME_RATE) 47 self.set_timer(FRAME_RATE)
48 self.show_screen(self.menu_screen) 48 self.show_screen(self.menu_screen)
49 49
50 50
51 def main(): 51 def main(initial_scene, scene_list, debug_rects=False):
52 opts = parse_args(sys.argv) 52 opts = parse_args(sys.argv)
53 pygame.display.init() 53 pygame.display.init()
54 pygame.font.init() 54 pygame.font.init()
55 if opts.sound: 55 if opts.sound:
56 try: 56 try:
61 # Ensure get_sound returns nothing, so everything else just works 61 # Ensure get_sound returns nothing, so everything else just works
62 disable_sound() 62 disable_sound()
63 if DEBUG: 63 if DEBUG:
64 if opts.scene is not None: 64 if opts.scene is not None:
65 # debug the specified scene 65 # debug the specified scene
66 state.DEBUG_SCENE = opts.scene 66 initial_scene = opts.scene
67 state.DEBUG_RECTS = opts.rects 67 debug_rects = opts.rects
68 initial_state = state.initial_state_creator(initial_scene, scene_list,
69 debug_rects)
68 display = pygame.display.set_mode(SCREEN, SWSURFACE) 70 display = pygame.display.set_mode(SCREEN, SWSURFACE)
69 pygame.display.set_icon(pygame.image.load( 71 pygame.display.set_icon(pygame.image.load(
70 data.filepath('icons/suspended_sentence24x24.png'))) 72 data.filepath('icons/suspended_sentence24x24.png')))
71 pygame.display.set_caption("Suspended Sentence") 73 pygame.display.set_caption("Suspended Sentence")
72 shell = MainShell(display) 74 shell = MainShell(display, initial_state)
73 try: 75 try:
74 shell.run() 76 shell.run()
75 except KeyboardInterrupt: 77 except KeyboardInterrupt:
76 pass 78 pass