Mercurial > boomslang
diff gamelib/main.py @ 852:f95830b58336
Merge pyntnclick
author | Stefano Rivera <stefano@rivera.za.net> |
---|---|
date | Sat, 21 Jun 2014 22:04:35 +0200 |
parents | 02cf5537d74e bdaffaa8b6bf |
children |
line wrap: on
line diff
--- a/gamelib/main.py Sat Jun 21 17:38:39 2014 +0000 +++ b/gamelib/main.py Sat Jun 21 22:04:35 2014 +0200 @@ -1,77 +1,30 @@ -'''Game main module. - -Contains the entry point used by the run_game.py script. - -''' +import scenes -# Albow looks for stuff in os.path[0], which isn't always where it expects. -# The following horribleness fixes this. -import sys -import os.path -right_path = os.path.dirname(os.path.dirname(__file__)) -sys.path.insert(0, right_path) -from optparse import OptionParser +from constants import SSConstants +from menu import SSMenuScreen +from endscreen import EndScreen +from ss_state import SSState -import pygame -from pygame.locals import SWSURFACE -from albow.shell import Shell - -from menu import MenuScreen -from gamescreen import GameScreen -from endscreen import EndScreen -from constants import ( - SCREEN, FRAME_RATE, FREQ, BITSIZE, CHANNELS, BUFFER, DEBUG) -from sound import no_sound, disable_sound -import state -import data +from pyntnclick.main import GameDescription -def parse_args(args): - parser = OptionParser() - parser.add_option("--no-sound", action="store_false", default=True, - dest="sound", help="disable sound") - if DEBUG: - parser.add_option("--scene", type="str", default=None, - dest="scene", help="initial scene") - parser.add_option("--no-rects", action="store_false", default=True, - dest="rects", help="disable debugging rects") - opts, _ = parser.parse_args(args or []) - return opts +class SuspendedSentence(GameDescription): + INITIAL_SCENE = scenes.INITIAL_SCENE + SCENE_LIST = scenes.SCENE_LIST + SCREENS = { + 'menu': SSMenuScreen, + 'end': EndScreen, + } + START_SCREEN = 'menu' -class MainShell(Shell): - def __init__(self, display): - Shell.__init__(self, display) - self.menu_screen = MenuScreen(self) - self.game_screen = GameScreen(self) - self.end_screen = EndScreen(self) - self.set_timer(FRAME_RATE) - self.show_screen(self.menu_screen) + def game_state_class(self): + return SSState + + def game_constants(self): + return SSConstants() def main(): - opts = parse_args(sys.argv) - pygame.display.init() - pygame.font.init() - if opts.sound: - try: - pygame.mixer.init(FREQ, BITSIZE, CHANNELS, BUFFER) - except pygame.error, exc: - no_sound(exc) - else: - # Ensure get_sound returns nothing, so everything else just works - disable_sound() - if DEBUG: - if opts.scene is not None: - # debug the specified scene - state.DEBUG_SCENE = opts.scene - state.DEBUG_RECTS = opts.rects - display = pygame.display.set_mode(SCREEN, SWSURFACE) - pygame.display.set_icon(pygame.image.load( - data.filepath('icons/suspended_sentence24x24.png'))) - pygame.display.set_caption("Suspended Sentence") - shell = MainShell(display) - try: - shell.run() - except KeyboardInterrupt: - pass + ss = SuspendedSentence() + return ss.main()