comparison 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
comparison
equal deleted inserted replaced
546:ad4d6ffd25d7 852:f95830b58336
1 '''Game main module. 1 import scenes
2 2
3 Contains the entry point used by the run_game.py script. 3 from constants import SSConstants
4 from menu import SSMenuScreen
5 from endscreen import EndScreen
6 from ss_state import SSState
4 7
5 ''' 8 from pyntnclick.main import GameDescription
6
7 # Albow looks for stuff in os.path[0], which isn't always where it expects.
8 # The following horribleness fixes this.
9 import sys
10 import os.path
11 right_path = os.path.dirname(os.path.dirname(__file__))
12 sys.path.insert(0, right_path)
13 from optparse import OptionParser
14
15 import pygame
16 from pygame.locals import SWSURFACE
17 from albow.shell import Shell
18
19 from menu import MenuScreen
20 from gamescreen import GameScreen
21 from endscreen import EndScreen
22 from constants import (
23 SCREEN, FRAME_RATE, FREQ, BITSIZE, CHANNELS, BUFFER, DEBUG)
24 from sound import no_sound, disable_sound
25 import state
26 import data
27 9
28 10
29 def parse_args(args): 11 class SuspendedSentence(GameDescription):
30 parser = OptionParser()
31 parser.add_option("--no-sound", action="store_false", default=True,
32 dest="sound", help="disable sound")
33 if DEBUG:
34 parser.add_option("--scene", type="str", default=None,
35 dest="scene", help="initial scene")
36 parser.add_option("--no-rects", action="store_false", default=True,
37 dest="rects", help="disable debugging rects")
38 opts, _ = parser.parse_args(args or [])
39 return opts
40 12
13 INITIAL_SCENE = scenes.INITIAL_SCENE
14 SCENE_LIST = scenes.SCENE_LIST
15 SCREENS = {
16 'menu': SSMenuScreen,
17 'end': EndScreen,
18 }
19 START_SCREEN = 'menu'
41 20
42 class MainShell(Shell): 21 def game_state_class(self):
43 def __init__(self, display): 22 return SSState
44 Shell.__init__(self, display) 23
45 self.menu_screen = MenuScreen(self) 24 def game_constants(self):
46 self.game_screen = GameScreen(self) 25 return SSConstants()
47 self.end_screen = EndScreen(self)
48 self.set_timer(FRAME_RATE)
49 self.show_screen(self.menu_screen)
50 26
51 27
52 def main(): 28 def main():
53 opts = parse_args(sys.argv) 29 ss = SuspendedSentence()
54 pygame.display.init() 30 return ss.main()
55 pygame.font.init()
56 if opts.sound:
57 try:
58 pygame.mixer.init(FREQ, BITSIZE, CHANNELS, BUFFER)
59 except pygame.error, exc:
60 no_sound(exc)
61 else:
62 # Ensure get_sound returns nothing, so everything else just works
63 disable_sound()
64 if DEBUG:
65 if opts.scene is not None:
66 # debug the specified scene
67 state.DEBUG_SCENE = opts.scene
68 state.DEBUG_RECTS = opts.rects
69 display = pygame.display.set_mode(SCREEN, SWSURFACE)
70 pygame.display.set_icon(pygame.image.load(
71 data.filepath('icons/suspended_sentence24x24.png')))
72 pygame.display.set_caption("Suspended Sentence")
73 shell = MainShell(display)
74 try:
75 shell.run()
76 except KeyboardInterrupt:
77 pass