示例#1
0
def addAchievementsWorld(options, theme):
    """Add a world for the achievements"""
    G = theme.getProperty
    #
    # The behaviour manager
    engine = serge.engine.CurrentEngine()
    serge.blocks.utils.createWorldsForEngine(engine, ['achievements-screen'])
    world = engine.getWorld('achievements-screen')
    manager = serge.blocks.behaviours.BehaviourManager('behaviours',
                                                       'behaviours')
    world.addActor(manager)
    #
    # The screen actor
    s = AchievementsGrid(theme.getTheme('achievements').getProperty)
    s.options = options
    world.addActor(s)
    #
    # Snap shots
    if options.screenshot:
        manager.assignBehaviour(
            None,
            serge.blocks.behaviours.SnapshotOnKey(key=pygame.K_s,
                                                  size=G('screenshot-size'),
                                                  overwrite=False,
                                                  location='screenshots'),
            'screenshot')
def startEngine(options):
    """Start the main engine"""
    engine = serge.engine.Engine(width=G('screen-width'), height=G('screen-height'), 
        title=G('screen-title'), fullscreen=options.fullscreen)
    serge.blocks.utils.createVirtualLayersForEngine(engine, ['background', 'foreground', 'foam', 'main', 
        'ropes', 'smoke', 'actors', 'trees', 'light', 'ui-back', 'ui-highlight', 'ui', 'overlay'])
    serge.blocks.utils.createWorldsForEngine(engine, ['start-screen', 'name-screen', 
        'main-screen', 'credits-screen', 'help-screen', 'collection-screen'])
    #
    if options.engine_profile:
        engine.profilingOn()
    #
    # The layers which don't move with the camera
    for layer in ('ui', 'ui-back', 'ui-highlight'):
        engine.getRenderer().getLayer(layer).setStatic(True)
    #
    # For the start screen we want to isolate the rope from the cave since they move independently so
    # we create two zones. 
    world = engine.getWorld('start-screen')
    rope_zone = serge.zone.TagIncludeZone(['player', 'rope', 'rope-anchor', 'rope-link'])
    none_rope_zone = serge.zone.TagExcludeZone(['player', 'rope', 'rope-anchor', 'rope-link'])
    rope_zone.active = none_rope_zone.active = True
    rope_zone.physics_stepsize = 1.0
    world.clearZones()
    world.addZone(rope_zone)
    world.addZone(none_rope_zone)
    #
    engine.setCurrentWorldByName('start-screen' if not options.skip else 'main-screen')
    return engine
def addMuteButtonToWorlds(button, center_position, world_names=None):
    """Add a particular mute button to various worlds
    
    If worlds is not specified then add to all the worlds currently in the engine.
    
    """
    engine = serge.engine.CurrentEngine()
    if world_names is None:
        world_names = [world.name for world in engine.getWorlds()]
    for name in world_names:
        world = engine.getWorld(name)
        addActorToWorld(world, button, center_position=center_position)
示例#4
0
def addMuteButtonToWorlds(button, center_position, world_names=None):
    """Add a particular mute button to various worlds
    
    If worlds is not specified then add to all the worlds currently in the engine.
    
    """
    engine = serge.engine.CurrentEngine()
    if world_names is None:
        world_names = [world.name for world in engine.getWorlds()]
    for name in world_names:
        world = engine.getWorld(name)
        addActorToWorld(world, button, center_position=center_position)
def addAchievementsWorld(options, theme):
    """Add a world for the achievements"""
    G = theme.getProperty
    #
    # The behaviour manager
    engine = serge.engine.CurrentEngine()
    serge.blocks.utils.createWorldsForEngine(engine, ['achievements-screen'])
    world = engine.getWorld('achievements-screen')
    manager = serge.blocks.behaviours.BehaviourManager('behaviours', 'behaviours')
    world.addActor(manager)
    #
    # The screen actor
    s = AchievementsGrid(theme.getTheme('achievements').getProperty)
    s.options = options
    world.addActor(s)
    #
    # Snap shots
    if options.screenshot:
        manager.assignBehaviour(None,
                                serge.blocks.behaviours.SnapshotOnKey(key=pygame.K_s, size=G('screenshot-size')
                                    , overwrite=False, location='screenshots'), 'screenshot')
def main(options, args):
    """Start the engine and the game"""
    #
    # For ropes and things we typically need a higher number of iterations
    serge.zone.PHYSICS_ITERATIONS = 100
    #
    # Create the engine
    engine = startEngine(options)
    engine.linkEvent(serge.events.E_BEFORE_STOP, stoppingNow)
    #
    registerSounds()
    registerMusic()
    registerGraphics()
    registerEvents()
    #
    # Change theme settings
    if options.theme:
        theme.updateFromString(options.theme)
    #
    # Muting
    mute = serge.blocks.actors.MuteButton('mute-button', 'ui', alpha=G('mute-button-alpha'))
    serge.blocks.utils.addMuteButtonToWorlds(mute, center_position=G('mute-button-position'))
    #
    if options.musicoff:
        mute.toggleSound()
    #
    # Initialise the main logic
    globals = serge.blocks.singletons.Store.registerItem('globals')  
    globals.history = history.History('history', 'history')
    globals.last_cave_name = 'RANDOM-CAVE'
    #
    registerAchievements(options)
    if options.skip:
        mainscreen.main(options)
    else:
        startscreen.main(options)
        #
        # Force a rendering of the overlay - this puts
        # up the "loading ..." screen so the user has something
        # to see while we create the cave and trees etc
        w = engine.getWorld('start-screen')
        w.log.info('Rendering overlay')
        w.renderTo(engine.getRenderer(), 1000)
        engine.getRenderer().render()
        pygame.display.flip()
    #
    helpscreen.main(options)
    creditsscreen.main(options)
    namescreen.main(options)
    collectionscreen.main(options)
    #   
    #
    if options.movie:
        serge.blocks.utils.RecordDesktop(options.movie)
    if options.debug:
        serge.builder.builder.main(engine, options.framerate)
    else:
        try:
            engine.run(options.framerate)
        except:
            # Make sure this event is raised so that any workers can be killed
            engine.processEvent((serge.events.E_BEFORE_STOP, None))
            raise
    #
    # Display profile statistic if needed
    if options.engine_profile:
        prof = engine.getProfiler()
        data = [(prof.byTag(n).get('renderActor', (0,0))[1], n) for n in prof.getTags()]
        data.sort()
        data.reverse()
        print '\n\nEngine profiling\n\nTag\tTime(s)'
        for tme, tag in data:
            print '%s\t%s' % (tag, tme)
        print '\n\n'