Пример #1
0
def enter():

    global game_play, game_clear
    game_play = True
    game_clear = False

    global background_music, game_clear_music 
    background_music = load_music('Resources/Musics/GameState.ogg')
    background_music.set_volume(64)
    background_music.repeat_play()

    game_clear_music = load_music('Resources/Musics/GameClear.ogg')
    game_clear_music.set_volume(64)

    global background_image
    background_image = load_image('Resources/States/Background_01.png')

    global background_gameclear
    background_gameclear = load_image('Resources/States/GameClearState.png')

    global back_image
    back_image = load_image('Resources/Images/Back.png')

    global next_image
    next_image = load_image('Resources/Images/Next.png')

    global map
    map = map_loader.load_map('Resources/Maps/Tutorial.json')
    
    global finn
    finn = finn_character.Finn()
    start = map.to_trigger('Start')
    finn.x, finn.y = start.x, map.mapoffsety + map.mapheight - start.y

    global effects
    effects = effect_handler.EffectHandler()

    global cubchooes, cubchoo_respone_time, cubchoo_respone_start
    cubchooes = []
    cubchoo_respone_time = 0.0
    cubchoo_respone_start = False

    global terrorlights, terrorlight_respone_time_A, terrorlight_respone_time_B, terrorlight_respone_start
    terrorlights = []
    terrorlight_respone_time_A = 0.0
    terrorlight_respone_time_B = 0.0
    terrorlight_respone_start = False

    global maples
    maples = [maple_particle.Maple() for i in range(30)]
    '''
    global snows
    snows = [snow_particle.Snow() for i in range(50)]
    '''
    global clouds
    clouds = [cloud_particle.Cloud() for i in range(10)]

    global tutorial_font, tutorial_str
    tutorial_font = load_font('Resources/Fonts/NanumBarunGothicBold.TTF', 12)
    tutorial_str = ''
 def prepare(self, map_file, script):
     text = open(script).read()
     python_ast = ast.parse(text)
     gcc_program = convert_python_to_gcc_module(python_ast)
     builder = GccTextBuilder()
     gcc_program.emit(builder)
     self.machine = GccMachine(parse_gcc(builder.text))
     self.wrapper = GCCWrapper(self.machine)
     self.map = load_map(map_file)
     self.world_state = self.wrapper.marshall_world_state(self.map)
Пример #3
0
def play(result):
    result = copy.copy(result)
    'Take partially filled result, fill in game outcome.'
    map = map_loader.load_map(result.map)
    map.set_ai_specs(result.lm_spec, result.ghost_specs)

    assert not result.lm_spec.startswith('interactive:')

    logger.info('match between {} and {} on {}'.format(
        result.lm_spec, result.ghost_specs, result.map))
    while not map.game_over():
        map.step()

    result.score = map.get_final_score()
    result.ticks = map.current_tick
    result.fruits_eaten = map.fruits_eaten
    result.power_pills_eaten = map.power_pills_eaten
    result.ghosts_eaten = map.ghosts_eaten
    result.gcc_stats = map.lman_vm_statistics()
    logger.info('score: {}, ticks: {}'.format(result.score, result.ticks))
    return result
Пример #4
0
def enter():
    global background_music 
    background_music = load_music('Resources/Musics/TitleState.ogg')
    background_music.set_volume(64)
    background_music.repeat_play()

    global background_image
    background_image = load_image('Resources/States/Background_01.png')

    global game_start_image
    game_start_image = load_image('Resources/Images/GameStart.png')

    global tutorial_image
    tutorial_image = load_image('Resources/Images/Tutorial.png')

    global exit_image
    exit_image = load_image('Resources/Images/Exit.png')

    global map
    map = map_loader.load_map('Resources/Maps/Title.json')

    global effects
    effects = effect_handler.EffectHandler()

    global cubchooes
    cubchooes = [cubchoo_character.Cubchoo() for i in range(10)]

    global terrorlights
    terrorlights = [terrorlight_character.Terrorlight() for i in range(5)]

    global maples
    maples = [maple_particle.Maple() for i in range(30)]
    '''
    global snows
    snows = [snow_particle.Snow() for i in range(50)]
    '''
    global clouds
    clouds = [cloud_particle.Cloud() for i in range(10)]
Пример #5
0
def main():
    parser = argparse.ArgumentParser(description="Run a greatly castrated python script")
    parser.add_argument('-p', help='program to compile and run', dest='program')
    parser.add_argument('-m', help='map to use', dest='map', default='default_map.txt')
    parser.add_argument('-a', help='program arguments', dest='args', nargs='+', type=int, default=[])
    parser.add_argument('-o', help='code output file', dest='output_file', default=None)
    parser.add_argument('-c', help='compile only', dest='compile_only', action='store_const', const=True, default=False)
    parser.add_argument('--no-tco', help='disable TCO', dest='disable_tco', action='store_const', const=True, default=False)
    #parser.add_argument('-r', help='program arguments', dest='run', type=bool, default=False)
    args = parser.parse_args()
    if not args.program: return
    text = compile_to_text(args.program, disable_tco=args.disable_tco)
    if args.output_file is not None:
        with open(args.output_file, 'w') as f:
            f.write(text + '\n')
    else:
        print text
    if args.compile_only: return
    machine = GccMachine(parse_gcc(text))
    wrapper = GCCWrapper(machine)
    map = load_map(args.map)
    world_state = wrapper.marshal_world_state(map)
    pp = pprint.PrettyPrinter(indent=2)
    pp.pprint(machine.call(0, world_state, *(args.args)))
Пример #6
0
def run_search(cli_args=None, puzzle_path=None, search=None, search_name=None):
    board = load_map(get_map_str(puzzle_path))
    results, board = search(board, print_steps=args.steps)
    return results, board
Пример #7
0
def enter():

    global game_play, game_over, game_clear
    game_play = True
    game_over = False
    game_clear = False


    global background_music, game_clear_music, game_over_music 
    background_music = load_music('Resources/Musics/GameState.ogg')
    background_music.set_volume(64)
    background_music.repeat_play()

    game_clear_music = load_music('Resources/Musics/GameClear.ogg')
    game_clear_music.set_volume(64)

    game_over_music = load_music('Resources/Musics/GameOver.ogg')
    game_over_music.set_volume(64)

    global background_image
    background_image = load_image('Resources/States/Background_01.png')

    global background_gameover
    background_gameover = load_image('Resources/States/GameOverState.png')

    global background_gameclear
    background_gameclear = load_image('Resources/States/GameClearState.png')

    global pause_image
    pause_image = load_image('Resources/Images/Pause.png')

    global back_image
    back_image = load_image('Resources/Images/Back.png')

    global next_image
    next_image = load_image('Resources/Images/Next.png')

    global retry_image
    retry_image = load_image('Resources/Images/Retry.png')

    global map
    map = map_loader.load_map('Resources/Maps/Level_01.json')

    global finn
    finn = finn_character.Finn()
    start = map.to_trigger('Start')
    finn.x, finn.y = start.x, map.mapoffsety + map.mapheight - start.y

    global cubchooes, cubchoo_respone_time_A, cubchoo_respone_time_B
    cubchooes = []
    cubchoo_respone_time_A = 5.0
    cubchoo_respone_time_B = 5.0
    
    global terrorlights, terrorlight_respone_time
    terrorlights = []
    terrorlight_respone_time = 7.0

    global effects
    effects = effect_handler.EffectHandler()

    global maples
    maples = [maple_particle.Maple() for i in range(10)]

    '''
    global snows
    snows = [snow_particle.Snow() for i in range(50)]
    '''
    global clouds
    clouds = [cloud_particle.Cloud() for i in range(10)]
Пример #8
0
    def change_map(self, map_filename):
        self.map = map_loader.load_map(map_filename)

        for player in self.player_list:
            player.coords = random.choice(self.map["player_starts"])
Пример #9
0
    def change_map(self, map_filename):
        self.map = map_loader.load_map(map_filename)

        for player in self.player_list:
            player.coords = random.choice(self.map["player_starts"])
Пример #10
0
def main():
    # clear old log
    with open('visualizer_debug.log', 'w'):
        pass
    logging.basicConfig(
        level=logging.INFO,
        format='%(levelname)8s:%(name)15s: %(message)s',
        filename='visualizer_debug.log')
    import ghc
    ghc.logger.setLevel(logging.WARNING)

    decorate_handlers()

    parser = argparse.ArgumentParser()
    parser.add_argument(
        '--map', default='default_map.txt',
        help='map file, relative to data/maps')
    parser.add_argument('--lm', default='interactive:', help='lm spec')
    parser.add_argument('ghost', nargs='*', help='ghost specs')

    args = parser.parse_args()
    if not args.ghost:
        args.ghost = [
            'py:GhostAI_Shortest',
            'ghc:fickle.ghc',
        ]
        print 'no ghosts specified, using', args.ghost

    map = map_loader.load_map(args.map)
    map.set_ai_specs(args.lm, args.ghost)

    stdscr = curses.initscr()

    curses.noecho()
    curses.cbreak()
    stdscr.keypad(1)

    curses.start_color()
    curses.init_pair(1, curses.COLOR_WHITE, curses.COLOR_BLACK)
    curses.init_pair(2, curses.COLOR_RED, curses.COLOR_BLACK)
    curses.init_pair(3, curses.COLOR_YELLOW, curses.COLOR_BLACK)
    curses.init_pair(4, curses.COLOR_GREEN, curses.COLOR_BLACK)
    curses.init_pair(5, curses.COLOR_BLUE, curses.COLOR_BLACK)

    ghost_colors = [curses.color_pair(i) for i in 2, 3, 4, 5]

    try:
        history = []
        while not map.game_over():
            history = history[-MAX_HISTORY_SIZE:]
            for y in range(map.height()):
                stdscr.addstr(y, 0, map.line_as_text(y))
            for i, ghost in enumerate(map.ghosts):
                idx = ghost.index % len(args.ghost)
                if ghost.vitality != game.INVISIBLE:
                    stdscr.addstr(ghost.y, ghost.x, '=', ghost_colors[idx])
                stdscr.addstr(
                    i, map.width() + 1,
                    '{} {}'.format(ghost.vitality, args.ghost[idx]), ghost_colors[idx])

            #for i, ghost in enumerate(args.ghost):

            stdscr.addstr(
                len(map.ghosts) + 1, map.width() + 1,
                'pill: {}    '.format(map.remaining_power_pill_ticks()),
                curses.color_pair(1))
            stdscr.addstr(
                len(map.ghosts) + 2, map.width() + 1,
                'lives: {}    '.format(map.lambdaman.lives),
                curses.color_pair(1))

            stdscr.addstr(map.height(), 0, "Tick {0} Score {1}   ".format(
                map.move_queue[0].next_move, map.lambdaman.score))
            stdscr.refresh()
            next_actor = map.move_queue[0]
            if isinstance(next_actor, LambdaMan):
                quit_game = False
                rewind = False
                if args.lm == 'interactive:':
                    while True:
                        c = stdscr.getch()
                        if c in (27, 113):  # ESC, q
                            quit_game = True
                            break
                        if c == ord('b'):
                            rewind = True
                            break
                        if c in DIRECTION_KEYS:
                            set_interactive_lambda_man_direction(
                                DIRECTION_KEYS.index(c))
                            break
                        stdscr.addstr(map.height()+1, 0, "Unknown key {}".format(c))
                        stdscr.refresh()
                else:
                    c = stdscr.getch()
                    if c in (27, 113):  # ESC, q
                        quit_game = True
                    elif c == ord('b'):
                        rewind = True
                if quit_game:
                    break
                if rewind:
                    if not history:
                        stdscr.addstr(map.height()+1, 0, 'no more history')
                        stdscr.refresh()
                    else:
                        map = history.pop()
                    continue
                history.append(copy.deepcopy(map))
            with log_context('step'):
                map.step()
    finally:
        curses.nocbreak()
        stdscr.keypad(0)
        curses.echo()
        curses.endwin()
        print "Tick {0} Score {1}".format(map.current_tick,
                                          map.lambdaman.score)
Пример #11
0
    for f in quads:
        index_list = [str(n.id) for n in f.nodes]
        oudata.append('f ' + ' '.join(index_list))

    with open(filename, mode='w') as f:
        f.write('\n'.join(data))


if __name__ == '__main__':

    for (i, j) in zip([nums[-1]] + nums[:-1], nums):

        print('%d, %d' % (i, j))

        cells_a = map_loader.load_map(
            '%s/%d/%d.csv' % (SOURCE_PATH, FRAME_NUM, i), max_value,
            SIDE_LENGTH)
        cells_b = map_loader.load_map(
            '%s/%d/%d.csv' % (SOURCE_PATH, FRAME_NUM, j), max_value,
            SIDE_LENGTH)

        # generate voxels
        set_a, _ = voxel_operation.create_3d_array(cells=cells_a,
                                                   side_length=SIDE_LENGTH,
                                                   z_range=z_range,
                                                   max_value=max_value,
                                                   is_positive=False)
        set_b, _ = voxel_operation.create_3d_array(cells=cells_b,
                                                   side_length=SIDE_LENGTH,
                                                   z_range=z_range,
                                                   max_value=max_value)