help="rendered output file to generate") parser.add_option("-n", "--render-name", dest="rendername", type="string", default="main", help="renderer to use") parser.add_option("-l", "--log", dest="log", default=40, type="int", help="logging level") parser.add_option("-s", "--seed", dest="seed", default=0, type="int", help="seed for random number") parser.add_option("-p", "--profile", dest="profile", default=False, action="store_true", help="profile the application") if __name__ == '__main__': options, args = parser.parse_args() loggable.logger.setLevel(options.log) log = loggable.getLogger("Terrain") log.info('Terrain is starting') if options.seed: log.debug('Using random seed %d' % options.seed) random.seed(options.seed) def J(filename): """Return path joined to the base""" return os.path.join(options.base, filename) gen = generator.Generator() if options.profile: import cProfile, pstats cProfile.run(
dest="seed", default=0, type="int", help="seed for random number") parser.add_option("-p", "--profile", dest="profile", default=False, action="store_true", help="profile the application") if __name__ == '__main__': options, args = parser.parse_args() loggable.logger.setLevel(options.log) log = loggable.getLogger("Terrain") log.info('Terrain is starting') if options.seed: log.debug('Using random seed %d' % options.seed) random.seed(options.seed) def J(filename): """Return path joined to the base""" return os.path.join(options.base, filename) gen = generator.Generator() if options.profile: import cProfile, pstats cProfile.run(
"""Some common utils""" import re import loggable log = loggable.getLogger('evolution') class ParsingFailed(Exception): """Parsing the input file failed""" class BuilderError(Exception): """An error occurred while building""" def getResult(root, tag, result_type, default=None): """Return an integer from a tag""" try: return result_type(root.find(tag).text) except Exception, err: if default is None: raise ParsingFailed("Failed parsing input for a '%s' tag: %s" % (tag, err)) else: return default def getInt(root, tag, default=None): """Return an integer from a tag""" return getResult(root, tag, int, default)
def main(options, args): """Main loop""" # # Set options loggable.logger.setLevel(options.log) sound.MUTED = options.mute # log = loggable.getLogger('engine') log.info('Starting engine (v%s' % common.__version__) # running = True # screen = initPygame() # # Control when out of the game other_screens = outofgamestate.OutOfGame(options.speed) sound.Sounds.playMusic(S.Music.start_music) # # Setup game state game = gamestate.GameState(other_screens, options.speed) app = other_screens # log.info('Initialisation complete') screenshot_id = 1 # # Main loop of the engine while running: clicked_on = None for event in pygame.event.get(): if event.type == pygame.QUIT: running = False break elif event.type == pygame.KEYUP: if app.processKey(event.key) == pygame.QUIT: running = False elif event.key == pygame.K_s: pygame.image.save(screen, os.path.join('screenshots', 'screenshot-%d.png' % screenshot_id)) screenshot_id += 1 elif event.type == pygame.MOUSEBUTTONUP and event.button == 1: clicked_on = app.processClick(event.type, event.pos) # # Switch between game and other screen if other_screens.state == outofgamestate.S_GAME_SCREEN: app = game elif other_screens.state == outofgamestate.S_NEW_GAME: game = gamestate.GameState(other_screens, options.speed) app = game other_screens.state = outofgamestate.S_GAME_SCREEN else: app = other_screens # # Update and render app.updateState(clicked_on) screen.fill(S.Screen.background_colour) app.renderTo(screen) # pygame.display.flip() # if other_screens.state == outofgamestate.S_QUIT: break # log.info('Engine quiting')