Пример #1
0
 def __init__( self ):
     ## Initialize the superclass.
     GameMode.__init__( self )
     
     self.image, _ = load_image( 'pause.png' )
     self.quit_rect = pygame.Rect( 255, 340, 337, 250 )
     self.start_rect = pygame.Rect( 271, 100, 302, 250 )
     
     self.mouse_down_pos = (-1,-1)
Пример #2
0
 def __init__(self):
     GameMode.__init__(self)
     self.globals = json.load( open( os.path.join( kDataDir, kGlobals ) ) )
     self.roomName = 'PauseMenu'
     self.image, _ = load_image('PauseMenu.jpg')
     self.hotspots = []
     temp = self.globals['current_note']
     self.hotspots.append(Hotspot(pygame.Rect(20, 425, 200, 200), load_sound(temp), "current_note"))
     self.mouse_down_pos = (-1,-1)#need default position for mouse
Пример #3
0
 def __init__( self, movie, next_mode_name ):
     '''
     Given the file name of a movie, will play that movie until it is over
     and then transition to the next mode
     '''
     ## Initialize the superclass.
     GameMode.__init__( self )
     
     self.movieName = movie
     self.next_mode_name = next_mode_name
     self.movie = None
Пример #4
0
 def __init__( self, image, duration_in_milliseconds, next_mode_name ):
     '''
     Given a duration to show the splash screen 'duration_in_milliseconds',
     and the name of the next mode,
     displays 'image' until either a mouse click or 'duration_in_milliseconds'
     milliseconds have elapsed.
     '''
     ## Initialize the superclass.
     GameMode.__init__( self )
     
     self.image = image
     self.duration = duration_in_milliseconds
     self.next_mode_name = next_mode_name
Пример #5
0
 def __init__(self):
     GameMode.__init__(self)
     
     self.globals = json.load( open( os.path.join( kDataDir, kGlobals ) ) )
     
     
     ##Initialize to bedroom
     self.roomName = ''
     self.image = None
     self.exits = []
     self.hotspots = []
     
     self._changeRoom('Bedroom')
     
     self.mouse_down_pos = (-1,-1)
Пример #6
0
 def __init__(self):
     ## Initialize the superclass.
     GameMode.__init__(self)
     self.image, _ = load_image("MainMenu.jpg")
     ##load and play music
     try:
         backgroundMusic = os.path.join(kDataDir, "Eternal Memory.ogg")
         pygame.mixer.music.load(backgroundMusic)
         global splash_bool
         splash_bool = False
         global main_menu_bool
         main_menu_bool = True
     except pygame.error, message:
         print "Cannot load music:"
         raise SystemExit, message
Пример #7
0
 def __init__( self ):
     ## Initialize the superclass.
     GameMode.__init__( self )
     self.image, _ = load_image( 'MainMenu.jpg' )
     self.backgroundMusic = None
     ##load and play music
     try:
         self.backgroundMusic = os.path.join("data",'Eternal Memory.ogg')
         pygame.mixer.music.load( self.backgroundMusic )
         global splash_bool
         splash_bool = False
         global main_menu_bool
         main_menu_bool = True
     except pygame.error, message:
         print 'Cannot load music:'
         raise SystemExit, message
Пример #8
0
def main():
    """Main loop that runs the game. """

    # Reduce the audio sample rate to limit CPU burden
    # (Must be done before pygame.init()! )
    pygame.mixer.pre_init(44100, -16, 2, 1024)

    # Initialize all modules required for PyGame
    pygame.init()

    # Load config file
    settings_path = sys.path[0] + "/settings.ini"
    canonicalized_path = settings_path.replace('/',
                                               os.sep).replace('\\', os.sep)

    config = configparser.ConfigParser()
    config.optionxform = str
    #config.read('settings.ini')
    config.read(canonicalized_path)

    settings = {
        'Controls': {},
        'Screen': {},
        'Servos': {},
        'Audio': {},
        'LEDs': {}
    }

    for option in config['Controls']:
        settings['Controls'][option] = int(config['Controls'][option])
    for option in config['Screen']:
        settings['Screen'][option] = int(config['Screen'][option])
    for option in config['Servos']:
        settings['Servos'][option] = float(config['Servos'][option])
    for option in config['Audio']:
        settings['Audio'][option] = config['Audio'][option]
    for option in config['LEDs']:
        settings['LEDs'][option] = int(config['LEDs'][option])

    # Launch window of desired size
    screen = pygame.display.set_mode(
        [settings['Screen']['X'], settings['Screen']['Y']])

    # Set game window title
    pygame.display.set_caption('Ball balance game')

    # Hide the mouse cursor
    pygame.mouse.set_visible(False)

    assets = {
        'clock': pygame.time.Clock(),
        'rod': r.Rod(settings),
        'leds': l.LEDs(settings),
        'settings': settings,
        'screen': screen
    }

    # Add new game modes here
    c.ATTRACT_MODE = AttractMode.AttractMode(assets)
    c.GAME_MODE = GameMode.GameMode(assets)
    c.SERVICE_MENU_MODE = ServiceMenuMode.ServiceMenuMode(assets)

    active_mode = c.ATTRACT_MODE

    override_service_button = False

    while active_mode is not None:

        # Reset active mode to self so that it doesn't immediately flip to the
        # next mode
        active_mode.refresh(assets)

        pressed_keys = pygame.key.get_pressed()

        # Clear out the event queue into 'events'
        events = pygame.event.get()

        for event in events:

            # If user clicks the window close button...
            if event.type == pygame.QUIT:
                active_mode = None

            # If a button is pressed down...
            elif event.type == pygame.KEYDOWN:

                # Set to True if either Alt button is pressed
                alt_pressed = pressed_keys[pygame.K_LALT] or \
                          pressed_keys[pygame.K_RALT]

                # If Escape key is pressed...
                if event.key == pygame.K_ESCAPE:
                    active_mode = None

                # If Alt + F4 is pressed...
                elif event.key == pygame.K_F4 and alt_pressed:
                    active_mode = None

                # Limit switches activation
                elif event.key == settings['Controls']['LimitLeftTop']:
                    assets['rod'].limit_left_up = True
                elif event.key == settings['Controls']['LimitLeftBottom']:
                    assets['rod'].limit_left_down = True
                elif event.key == settings['Controls']['LimitRightTop']:
                    assets['rod'].limit_right_up = True
                elif event.key == settings['Controls']['LimitRightBottom']:
                    assets['rod'].limit_right_down = True

                # If Service Mode button is pressed...
                elif event.key == settings['Controls'][
                        'ServiceButton'] and not override_service_button:
                    active_mode.switch_to_mode(c.SERVICE_MENU_MODE)

            # If button is being released...
            elif event.type == pygame.KEYUP:

                # Limit switches deactivation
                if event.key == settings['Controls']['LimitLeftTop']:
                    assets['rod'].limit_left_up = False
                elif event.key == settings['Controls']['LimitLeftBottom']:
                    assets['rod'].limit_left_down = False
                elif event.key == settings['Controls']['LimitRightTop']:
                    assets['rod'].limit_right_up = False
                elif event.key == settings['Controls']['LimitRightBottom']:
                    assets['rod'].limit_right_down = False

        if active_mode is not None:
            # Send the events list to the active mode's process()
            active_mode.process(events, pressed_keys)

            # Use the active mode's render()
            active_mode.render(screen)

            # Change the active mode to the current active mode's next assigned
            active_mode = active_mode.next

            # Swap PyGame's buffers to update the graphics on the screen
            pygame.display.flip()

            # Delay the game to limit refresh rate to 60 FPS
            assets['clock'].tick(60)

    # Quit the game cleanly
    pygame.quit()
Пример #9
0
 def __init__( self, levels ):
     ## Initialize the superclass.
     GameMode.__init__( self )
     
     self.levels = [ Level( name ) for name in levels ]
     self.current_level_index = 0