Mercurial > boomslang
comparison pyntnclick/main.py @ 608:a25cd1c6335a pyntnclick
Pass screens through engine by name
author | Neil Muller <neil@dip.sun.ac.za> |
---|---|
date | Sat, 11 Feb 2012 20:57:28 +0200 |
parents | 3ce19d33b51f |
children | cfc16ded7b34 |
comparison
equal
deleted
inserted
replaced
607:f2b1ddcc4986 | 608:a25cd1c6335a |
---|---|
38 | 38 |
39 # list of game scenes | 39 # list of game scenes |
40 SCENE_LIST = None | 40 SCENE_LIST = None |
41 | 41 |
42 # starting menu | 42 # starting menu |
43 MENU_SCREEN = DefMenuScreen | 43 SPECIAL_SCREENS = { |
44 'menu': DefMenuScreen, | |
45 'end': DefEndScreen, | |
46 } | |
44 | 47 |
45 # game over screen | 48 START_SCREEN = 'menu' |
46 END_SCREEN = DefEndScreen | |
47 | |
48 | 49 |
49 # resource module | 50 # resource module |
50 RESOURCE_MODULE = "Resources" | 51 RESOURCE_MODULE = "Resources" |
51 | 52 |
52 def __init__(self): | 53 def __init__(self): |
67 def initial_state(self): | 68 def initial_state(self): |
68 """Create a copy of the initial game state.""" | 69 """Create a copy of the initial game state.""" |
69 initial_state = state.Game(self) | 70 initial_state = state.Game(self) |
70 initial_state.set_debug_rects(self._debug_rects) | 71 initial_state.set_debug_rects(self._debug_rects) |
71 for scene in self._scene_list: | 72 for scene in self._scene_list: |
72 initial_state.load_scenes(scene) | 73 initial_state.load_scenes(scene, self.engine) |
73 initial_state.set_current_scene(self._initial_scene) | 74 initial_state.set_current_scene(self._initial_scene) |
74 initial_state.set_do_enter_leave() | 75 initial_state.set_do_enter_leave() |
75 return initial_state | 76 return initial_state |
76 | 77 |
77 def game_constants(self): | 78 def game_constants(self): |
135 if self.constants.debug and opts.rect_drawer: | 136 if self.constants.debug and opts.rect_drawer: |
136 if opts.scene is None: | 137 if opts.scene is None: |
137 print 'Need to supply a scene to use the rect drawer' | 138 print 'Need to supply a scene to use the rect drawer' |
138 sys.exit(1) | 139 sys.exit(1) |
139 display = make_rect_display() | 140 display = make_rect_display() |
141 # FIXME: Remove Albow from here | |
140 try: | 142 try: |
141 engine = RectApp(display, self.initial_state, opts.scene, | 143 self.engine = RectApp(display, self.initial_state, opts.scene, |
142 opts.detail) | 144 opts.detail) |
143 except KeyError: | 145 except KeyError: |
144 print 'Invalid scene: %s' % opts.scene | 146 print 'Invalid scene: %s' % opts.scene |
145 sys.exit(1) | 147 sys.exit(1) |
146 else: | 148 else: |
147 pygame.display.set_mode(self.constants.screen, SWSURFACE) | 149 pygame.display.set_mode(self.constants.screen, SWSURFACE) |
148 pygame.display.set_icon(self.resource.get_image( | 150 pygame.display.set_icon(self.resource.get_image( |
149 'suspended_sentence24x24.png', basedir='icons')) | 151 'suspended_sentence24x24.png', basedir='icons')) |
150 pygame.display.set_caption("Suspended Sentence") | 152 pygame.display.set_caption("Suspended Sentence") |
151 | 153 |
152 engine = Engine(self) | 154 self.engine = Engine(self) |
155 # Initialize the special screens in the engine | |
156 for name, cls in self.SPECIAL_SCENES.iteritems(): | |
157 screen = cls(self) | |
158 self.engine.add_screen(name, screen) | |
153 # Should we allow the menu not to be the opening screen? | 159 # Should we allow the menu not to be the opening screen? |
154 engine.set_screen(self.MENU_SCREEN(self)) | 160 self.engine.set_screen(self.START_SCREEN) |
155 try: | 161 try: |
156 engine.run() | 162 self.engine.run() |
157 except KeyboardInterrupt: | 163 except KeyboardInterrupt: |
158 pass | 164 pass |