comparison pyntnclick/main.py @ 599:2d2ea51b73ad pyntnclick

Move menu.py and endscreen.py to gamelib. Add default versions for new games
author Neil Muller <neil@dip.sun.ac.za>
date Sat, 11 Feb 2012 18:46:19 +0200
parents c1b5e982809b
children fabce47e542f
comparison
equal deleted inserted replaced
598:c1b5e982809b 599:2d2ea51b73ad
14 14
15 import pygame 15 import pygame
16 from pygame.locals import SWSURFACE 16 from pygame.locals import SWSURFACE
17 from albow.shell import Shell 17 from albow.shell import Shell
18 18
19 from pyntnclick.menu import MenuScreen 19 from pyntnclick.gamescreen import GameScreen, DefMenuScreen, DefEndScreen
20 from pyntnclick.gamescreen import GameScreen
21 from pyntnclick.endscreen import EndScreen
22 from pyntnclick.constants import GameConstants, DEBUG_ENVVAR 20 from pyntnclick.constants import GameConstants, DEBUG_ENVVAR
23 from pyntnclick.resources import Resources 21 from pyntnclick.resources import Resources
24 from pyntnclick.sound import Sound 22 from pyntnclick.sound import Sound
25 from pyntnclick import state 23 from pyntnclick import state
26 24
27 from pyntnclick.tools.rect_drawer import RectApp, make_rect_display 25 from pyntnclick.tools.rect_drawer import RectApp, make_rect_display
28 from pyntnclick.tools.utils import list_scenes 26 from pyntnclick.tools.utils import list_scenes
29 27
30 28
31 class MainShell(Shell): 29 class MainShell(Shell):
32 def __init__(self, display, game_description): 30 # Should we allow the menu not to be the opening screen?
31 def __init__(self, display, game_description, menu_screen, end_screen):
33 Shell.__init__(self, display) 32 Shell.__init__(self, display)
34 self.menu_screen = MenuScreen(self, game_description) 33 if menu_screen:
34 self.menu_screen = menu_screen(self, game_description)
35 else:
36 self.menu_screen = DefMenuScreen(self, game_description)
35 self.game_screen = GameScreen(self, game_description) 37 self.game_screen = GameScreen(self, game_description)
36 self.end_screen = EndScreen(self, game_description) 38 if end_screen:
39 self.end_screen = end_screen(self, game_description)
40 else:
41 self.end_screen = DefEndScreen(self, game_description)
37 self.set_timer(game_description.constants.frame_rate) 42 self.set_timer(game_description.constants.frame_rate)
38 self.show_screen(self.menu_screen) 43 self.show_screen(self.menu_screen)
39 44
40 45
41 class GameDescriptionError(Exception): 46 class GameDescriptionError(Exception):
47 # initial scene for start of game (unless overridden by debug) 52 # initial scene for start of game (unless overridden by debug)
48 INITIAL_SCENE = None 53 INITIAL_SCENE = None
49 54
50 # list of game scenes 55 # list of game scenes
51 SCENE_LIST = None 56 SCENE_LIST = None
57
58 # starting menu
59 MENU_SCREEN = None
60
61 # game over screen
62 END_SCREEN = None
63
52 64
53 # resource module 65 # resource module
54 RESOURCE_MODULE = "Resources" 66 RESOURCE_MODULE = "Resources"
55 67
56 def __init__(self): 68 def __init__(self):
152 SWSURFACE) 164 SWSURFACE)
153 pygame.display.set_icon(self.resource.get_image( 165 pygame.display.set_icon(self.resource.get_image(
154 'suspended_sentence24x24.png', basedir='icons')) 166 'suspended_sentence24x24.png', basedir='icons'))
155 pygame.display.set_caption("Suspended Sentence") 167 pygame.display.set_caption("Suspended Sentence")
156 168
157 shell = MainShell(display, self) 169 shell = MainShell(display, self, self.MENU_SCREEN,
170 self.END_SCREEN)
158 try: 171 try:
159 shell.run() 172 shell.run()
160 except KeyboardInterrupt: 173 except KeyboardInterrupt:
161 pass 174 pass