예제 #1
0
 def show(self, state):
     """Show main menu"""
     if self.owner is None:
         raise SystemError("MainMenuStage is detached from render")
     main_menu(self.owner.con, self.main_menu_background_image,
               CONFIG.get('WIDTH'), CONFIG.get('HEIGHT'))
     if state.error:
         message_box(self.owner.con, 'No save game to load', 50,
                     CONFIG.get('WIDTH'), CONFIG.get('HEIGHT'))
     tcod.console_flush()
예제 #2
0
    def run(self):
        """ Main game loop """
        show_main_menu = True
        show_load_error_message = False

        main_menu_background_image = tcod.image_load('menu_background.png')

        key = tcod.Key()
        mouse = tcod.Mouse()

        while not tcod.console_is_window_closed():
            tcod.sys_check_for_event(tcod.EVENT_KEY_PRESS | tcod.EVENT_MOUSE,
                                     key, mouse)

            if show_main_menu:
                main_menu(self.main_console, main_menu_background_image,
                          self.constants['screen_width'],
                          self.constants['screen_height'])

                if show_load_error_message:
                    message_box(self.main_console, 'No save game to load', 50,
                                self.constants['screen_width'],
                                self.constants['screen_height'])

                tcod.console_flush()

                action = handle_main_menu(key)

                a_new_game = action.get('new_game')
                a_load_saved_game = action.get('load_game')
                a_exit_game = action.get('exit')

                if show_load_error_message and (a_new_game or a_load_saved_game
                                                or a_exit_game):
                    show_load_error_message = False
                elif a_new_game:
                    self.reset_game()
                    show_main_menu = False
                elif a_load_saved_game:
                    try:
                        self.load_saved_game()
                        show_main_menu = False
                    except FileNotFoundError:
                        show_load_error_message = True
                elif a_exit_game:
                    break

            else:
                tcod.console_clear(self.main_console)
                self.play_game()

                show_main_menu = True
예제 #3
0
def main():
    constants = get_constants()

    libtcod.console_set_custom_font(
        'arial10x10.png',
        libtcod.FONT_TYPE_GREYSCALE | libtcod.FONT_LAYOUT_TCOD)

    libtcod.console_init_root(constants['screen_width'],
                              constants['screen_height'],
                              constants['window_title'], False)

    con = libtcod.console_new(constants['screen_width'],
                              constants['screen_height'])
    panel = libtcod.console_new(constants['screen_width'],
                                constants['panel_height'])

    player = None
    entities = []
    game_map = None
    message_log = None
    game_state = None

    show_main_menu = True
    show_load_error_message = False

    main_menu_background_image = libtcod.image_load('menu_background1.png')

    key = libtcod.Key()
    mouse = libtcod.Mouse()

    while not libtcod.console_is_window_closed():
        libtcod.sys_check_for_event(
            libtcod.EVENT_KEY_PRESS | libtcod.EVENT_MOUSE, key, mouse)

        if show_main_menu:
            main_menu(con, main_menu_background_image,
                      constants['screen_width'], constants['screen_height'])

            if show_load_error_message:
                message_box(con, 'No save game to load', 50,
                            constants['screen_width'],
                            constants['screen_height'])

            libtcod.console_flush()

            action = handle_main_menu(key)

            new_game = action.get('new_game')
            load_saved_game = action.get('load_game')
            exit_game = action.get('exit')

            if show_load_error_message and (new_game or load_saved_game
                                            or exit_game):
                show_load_error_message = False
            elif new_game:
                player, entities, game_map, message_log, game_state = get_game_variables(
                    constants)
                game_state = GameStates.PLAYERS_TURN

                show_main_menu = False
            elif load_saved_game:
                try:
                    player, entities, game_map, message_log, game_state = load_game(
                    )
                    show_main_menu = False
                except FileNotFoundError:
                    show_load_error_message = True
            elif exit_game:
                break

        else:
            libtcod.console_clear(con)
            play_game(player, entities, game_map, message_log, game_state, con,
                      panel, constants)

            show_main_menu = True
예제 #4
0
def render_all(root_console: tcod.console.Console,
               offscreen_console: tcod.console.Console,
               viewport_console: tcod.console.Console,
               status_console: tcod.console.Console,
               log_console: tcod.console.Console,
               entity_console: tcod.console.Console, player: Entity,
               game_map: GameMap, mouse_tx: int, mouse_ty: int,
               fov_recompute: bool, game_messages: MessageLog, box_text: str,
               game_state: GameState, camera: "Camera") -> None:

    screen_height = const.SCREEN_HEIGHT
    screen_width = const.SCREEN_WIDTH
    bar_width = const.BAR_WIDTH

    status_console.clear()
    log_console.clear()
    entity_console.clear()

    if fov_recompute:

        # Show nothing by default
        viewport_console.ch[:] = 0
        viewport_console.fg[:] = (0, 0, 0)
        viewport_console.bg[:] = (0, 0, 0)

        # Move camera to follow the player
        camera.move_camera(player.x, player.y, game_map.width, game_map.height)
        cam_x, cam_y = camera.x, camera.y
        cam_x2, cam_y2 = camera.x2, camera.y2

        # Translate map coordinates to camera coordinates
        cam_fov = game_map.fov_map.fov[cam_x:cam_x2 + 1, cam_y:cam_y2 + 1]
        cam_explored = game_map.explored[cam_x:cam_x2 + 1, cam_y:cam_y2 + 1]
        cam_glyph = game_map.tile_map.glyph[cam_x:cam_x2 + 1, cam_y:cam_y2 + 1]
        cam_fg = game_map.tile_map.fg[cam_x:cam_x2 + 1, cam_y:cam_y2 + 1]
        cam_bg = game_map.tile_map.bg[cam_x:cam_x2 + 1, cam_y:cam_y2 + 1]

        # If a tile is explored but not visible, render it in dark colors.
        viewport_console.fg[cam_explored == True] = np.multiply(
            cam_fg[cam_explored == True], 0.50).astype(np.int)
        viewport_console.bg[cam_explored == True] = np.multiply(
            cam_bg[cam_explored == True], 0.50).astype(np.int)
        viewport_console.ch[cam_explored == True] = cam_glyph[cam_explored ==
                                                              True]

        # If a tile is visible then render it in light colors.
        viewport_console.fg[cam_fov == True] = cam_fg[cam_fov == True]
        viewport_console.bg[cam_fov == True] = cam_bg[cam_fov == True]
        viewport_console.ch[cam_fov == True] = cam_glyph[cam_fov == True]
        # viewport_console.ch[cam_transparent == False] = 178

        # If a tile is visible, then it is now explored.
        game_map.explored[game_map.fov_map.fov == True] = True

    # Draw all entities in the list
    entities_in_render_order = sorted(game_map.entities,
                                      key=lambda x: x.entity_type.value)

    for entity in entities_in_render_order:
        draw_entity(viewport_console, entity, game_map, camera)

    render_bar(status_console, 1, 1, bar_width, 'HP', player.fighter.hp,
               player.fighter.max_hp, tcod.light_red, tcod.darker_red)
    status_console.print(1, 3, f"Dungeon Level: {game_map.dungeon_level}")

    status_console.print(1,
                         0,
                         get_names_under_mouse(mouse_tx, mouse_ty,
                                               game_map.entities, game_map),
                         fg=(128, 128, 128))

    y = 0
    for message in game_messages.messages:
        log_console.print(game_messages.x, y, message.text, fg=message.color)
        y += 1

    entity_console.print(5, 0, "Visible:", (128, 128, 128))

    visible_entities = [
        entity for entity in entities_in_render_order
        if tcod.map_is_in_fov(game_map.fov_map, entity.x, entity.y)
    ]

    for index, entity in enumerate(visible_entities, start=1):
        if entity.entity_type not in [EntityType.PLAYER, EntityType.CORPSE]:
            entity_str = f"{chr(entity.glyph)}: {entity.name.capitalize()}"
            entity_console.print(1, index, entity_str, entity.fg)

    draw_frames(offscreen_console)

    # offscreen_console.print(0, screen_height - 1, f"{mouse_tx}, {mouse_ty}")

    viewport_console.blit(offscreen_console, 1, 1)
    status_console.blit(offscreen_console, const.VIEWPORT_WIDTH + 2, 1)
    log_console.blit(offscreen_console, 1, const.VIEWPORT_HEIGHT + 2)
    entity_console.blit(offscreen_console, const.VIEWPORT_WIDTH + 2,
                        const.STATUS_HEIGHT + 2)
    offscreen_console.blit(root_console)

    if game_state in [GameState.SHOW_INVENTORY, GameState.DROP_INVENTORY]:
        if game_state == GameState.SHOW_INVENTORY:
            inventory_title = "Press the key next to an item to use it, ESC to cancel.\n"
        else:
            inventory_title = "Press the key next to an item to drop it, ESC to cancel.\n"

        inventory_menu(root_console, inventory_title, player, 50, screen_width,
                       screen_height)

    elif game_state == GameState.LEVEL_UP:
        level_up_menu(root_console, "Level up! Choose a stat to raise:",
                      player, 40, screen_width, screen_height)

    elif game_state == GameState.CHARACTER_SCREEN:
        character_screen(root_console, player, 30, 10, screen_width,
                         screen_height)

    elif game_state == GameState.MESSAGE_BOX:
        message_box(root_console, box_text, len(box_text),
                    const.VIEWPORT_WIDTH, const.VIEWPORT_HEIGHT)

    if SHOW_STATS:
        fps = tcod.sys_get_fps()
        if fps > 0:
            fps_str = f"FPS: {fps} ({1000 / fps:.2f} ms/frame)"
            root_console.print(0,
                               const.SCREEN_HEIGHT - 1,
                               fps_str,
                               fg=(255, 255, 255))

    tcod.console_flush()
예제 #5
0
파일: engine.py 프로젝트: psizek/quaffquest
def main():

    rootDir = Path(__file__).parent.parent
    fontpath = rootDir / 'gfx' / 'arial10x10.png'
    tcod.console_set_custom_font(
        str(fontpath), tcod.FONT_TYPE_GREYSCALE | tcod.FONT_LAYOUT_TCOD)

    with tcod.console_init_root(c.SCREEN_WIDTH, c.SCREEN_HEIGHT,
                                c.WINDOW_TITLE, False,
                                tcod.RENDERER_SDL2) as root_con:

        con: tcod.console.Console = tcod.console.Console(
            c.SCREEN_WIDTH, c.SCREEN_HEIGHT)
        panel: tcod.console.Console = tcod.console.Console(
            c.SCREEN_WIDTH, c.PANEL_HEIGHT)

        player = None
        entities = []
        game_map = None
        message_log = None
        game_state = None

        show_main_menu: bool = True
        show_load_error_message: bool = False

        main_menu_img_background = tcod.image_load('menu_background.png')

        state = MainMenu_State()

        while True:
            for event in tcod.event.wait():
                state.dispatch(event)

                if show_main_menu:
                    main_menu(root_con, main_menu_img_background)

                    if show_load_error_message:
                        message_box(root_con, 'No save game to load', 50)

                    tcod.console_flush()

                    if state.action:
                        new_game = state.action.get('new_game')
                        load_saved_game = state.action.get('load_game')
                        exit_game = state.action.get('exit')

                        if show_load_error_message and (new_game
                                                        or load_saved_game
                                                        or exit_game):
                            show_load_error_message = False
                        elif new_game:
                            player, entities, game_map, message_log, game_state = get_game_variables(
                            )
                            game_state = GameStates.PLAYERS_TURN
                            show_main_menu = False
                        elif load_saved_game:
                            try:
                                player, entities, game_map, message_log, game_state = load_game(
                                )
                                show_main_menu = False
                            except FileNotFoundError:
                                show_load_error_message = True
                        elif exit_game:
                            return
                else:
                    root_con.clear()
                    play_game(player, entities, game_map, message_log,
                              game_state, root_con, con, panel)

                    return
예제 #6
0
def main():
    """ Main game loop

    Init console + wraps key events

    """

    constants = get_constants()

    tcod.console_set_custom_font(
        "arial10x10.png", tcod.FONT_TYPE_GREYSCALE | tcod.FONT_LAYOUT_TCOD)
    tcod.console_init_root(
        constants["screen_width"],
        constants["screen_height"],
        constants["window_title"],
        False,
        constants["sdl_renderer"],
    )

    console = tcod.console.Console(constants["screen_width"],
                                   constants["screen_height"])
    panel = tcod.console_new(constants["screen_width"],
                             constants["panel_height"])

    player = None
    entities = []
    game_map = None
    message_log = None
    game_state = None

    show_main_menu = True
    show_load_error_message = False

    main_menu_background_image = tcod.image_load('menu_background.png')

    key = tcod.Key()
    mouse = tcod.Mouse()

    while not tcod.console_is_window_closed():
        tcod.sys_check_for_event(tcod.EVENT_KEY_PRESS | tcod.EVENT_MOUSE, key,
                                 mouse)

        if show_main_menu:
            main_menu(console, main_menu_background_image,
                      constants['screen_width'], constants['screen_height'])

            if show_load_error_message:
                message_box(console, 'No save game to load', 50,
                            constants['screen_width'],
                            constants['screen_height'])

            tcod.console_flush()

            action = handle_main_menu(key)

            new_game = action.get('new_game')
            load_saved_game = action.get('load_game')
            exit_game = action.get('exit')

            if show_load_error_message and (new_game or load_saved_game
                                            or exit_game):
                show_load_error_message = False
            elif new_game:
                player, entities, game_map, message_log, game_state = get_game_variables(
                    constants)
                game_state = GameStates.PLAYERS_TURN
                show_main_menu = False
            elif load_saved_game:
                try:
                    player, entities, game_map, message_log, game_state = load_game(
                    )
                    show_main_menu = False
                except FileNotFoundError:
                    show_load_error_message = True
            elif exit_game:
                break
        else:
            tcod.console_clear(console)
            play_game(player, entities, game_map, message_log, game_state,
                      console, panel, constants)
            show_main_menu = True
예제 #7
0
def main() -> None:

    tcod.console_set_custom_font(
        'potash_10x10.png',
        tcod.FONT_TYPE_GREYSCALE | tcod.FONT_LAYOUT_ASCII_INROW)

    root_console = tcod.console_init_root(w=const.SCREEN_WIDTH,
                                          h=const.SCREEN_HEIGHT,
                                          title=const.WINDOW_TITLE,
                                          fullscreen=False,
                                          order="F",
                                          vsync=False,
                                          renderer=tcod.RENDERER_OPENGL2)

    offscreen_console = tcod.console.Console(const.SCREEN_WIDTH,
                                             const.SCREEN_HEIGHT,
                                             order="F")

    viewport_console = tcod.console.Console(const.VIEWPORT_WIDTH,
                                            const.VIEWPORT_HEIGHT,
                                            order="F")

    status_console = tcod.console.Console(const.STATUS_WIDTH,
                                          const.STATUS_HEIGHT,
                                          order="F")

    entity_console = tcod.console.Console(const.ENTITY_WIDTH,
                                          const.ENTITY_HEIGHT,
                                          order="F")

    log_console = tcod.console.Console(const.LOG_WIDTH,
                                       const.LOG_HEIGHT,
                                       order="F")

    root_console.ch[:] = 0
    root_console.fg[:] = (255, 255, 255)
    root_console.bg[:] = (0, 0, 0)

    offscreen_console.ch[:] = 0
    offscreen_console.fg[:] = (255, 255, 255)
    offscreen_console.bg[:] = (0, 0, 0)

    viewport_console.ch[:] = 0
    viewport_console.fg[:] = (255, 255, 255)
    viewport_console.bg[:] = (0, 0, 0)

    status_console.ch[:] = 0
    status_console.fg[:] = (255, 255, 255)
    status_console.bg[:] = (0, 0, 0)

    entity_console.ch[:] = 0
    entity_console.fg[:] = (255, 255, 255)
    entity_console.bg[:] = (0, 0, 0)

    player = None
    dungeon = None
    message_log = None
    game_state = None
    camera = None

    show_main_menu = True
    show_load_error = False
    show_corrupt_error = False

    current_level = -1

    while True:

        if show_main_menu:
            main_menu(root_console, "heic1104a-edited.png", const.SCREEN_WIDTH,
                      const.SCREEN_HEIGHT)
            if show_load_error:
                message_text = "No save exists."
                message_box(root_console, message_text, len(message_text),
                            const.SCREEN_WIDTH, const.SCREEN_HEIGHT)
            if show_corrupt_error:
                message_text = "Corrupt save."
                message_box(root_console, message_text, len(message_text),
                            const.SCREEN_WIDTH, const.SCREEN_HEIGHT)

            tcod.console_flush()

            action = handle_main_menu(tcod.event.get())

            new_game = action.get("new_game")
            load_save = action.get("load_game")
            exit_game = action.get("exit")

            if show_load_error and (new_game or load_save or exit_game):
                show_load_error = False
            elif show_corrupt_error and (new_game or load_save or exit_game):
                show_corrupt_error = False
            elif new_game:
                player, dungeon, message_log, game_state, current_level, camera = get_game_variables(
                )
                game_state = GameState.PLAYER_TURN

                show_main_menu = False

            elif load_save:
                try:
                    camera = Camera(0, 0, const.VIEWPORT_WIDTH - 1,
                                    const.VIEWPORT_HEIGHT - 1)
                    player, dungeon, message_log, game_state, current_level = load_game(
                    )
                    show_main_menu = False
                except FileNotFoundError:
                    show_load_error = True
                except KeyError:
                    show_corrupt_error = True
            elif exit_game:
                break

        else:
            root_console.clear()
            assert current_level != -1
            play_game(player, dungeon, message_log, game_state, root_console,
                      offscreen_console, viewport_console, log_console,
                      status_console, entity_console, current_level, camera)

            show_main_menu = True
예제 #8
0
def main():
    constants = get_constants()

    tdl.set_font('arial10x10.png', greyscale=True, altLayout=True)

    root_console = tdl.init(constants['screen_width'],
                            constants['screen_height'],
                            constants['window_title'])
    con = tdl.Console(constants['screen_width'], constants['screen_height'])
    panel = tdl.Console(constants['screen_width'], constants['panel_height'])

    player = None
    entities = []
    game_map = None
    message_log = None
    game_state = None

    show_main_menu = True
    show_load_error_message = False

    main_menu_background_image = image_load('menu_background.png')

    while not tdl.event.is_window_closed():
        for event in tdl.event.get():
            if event.type == 'KEYDOWN':
                user_input = event
                break
        else:
            user_input = None

        if show_main_menu:
            main_menu(con, root_console, main_menu_background_image,
                      constants['screen_width'], constants['screen_height'],
                      constants['colors'])

            if show_load_error_message:
                message_box(con, root_console, 'No save game to load', 50,
                            constants['screen_width'],
                            constants['screen_height'])

            tdl.flush()

            action = handle_main_menu(user_input)

            new_game = action.get('new_game')
            load_saved_game = action.get('load_game')
            exit_game = action.get('exit')

            if show_load_error_message and (new_game or load_saved_game
                                            or exit_game):
                show_load_error_message = False
            elif new_game:
                player, entities, game_map, message_log, game_state = get_game_variables(
                    constants)
                game_state = GameStates.PLAYER_TURN

                show_main_menu = False
            elif load_saved_game:
                try:
                    player, entities, game_map, message_log, game_state = load_game(
                    )
                    show_main_menu = False
                except FileNotFoundError:
                    show_load_error_message = True
            elif exit_game:
                break

        else:
            root_console.clear()
            con.clear()
            panel.clear()
            play_game(player, entities, game_map, message_log, game_state,
                      root_console, con, panel, constants)

            show_main_menu = True
예제 #9
0
def main():
    constants = get_constants()

    tc.console_set_custom_font('terminal10x10_gs_tc2.png',
                               tc.FONT_TYPE_GREYSCALE | tc.FONT_LAYOUT_TCOD)

    con = tc.console.Console(constants['screen_width'],
                             constants['screen_height'])
    panel = tc.console.Console(constants['screen_width'],
                               constants['panel_height'])

    player = None
    entities = []
    game_map = None
    message_log = None
    game_state = None

    show_main_menu = True
    show_load_error_message = False

    main_menu_background_image = tc.image_load('menu_background.png')

    key = tc.Key()
    mouse = tc.Mouse()

    with tc.console_init_root(constants['screen_width'],
                              constants['screen_height'],
                              constants['window_title'],
                              False) as root_console:
        while not tc.console_is_window_closed():
            tc.sys_check_for_event(tc.EVENT_KEY_PRESS | tc.EVENT_MOUSE, key,
                                   mouse)

            if show_main_menu:
                main_menu(con, main_menu_background_image,
                          constants['screen_width'],
                          constants['screen_height'])

                if show_load_error_message:
                    message_box(con, 'No save game to load', 50,
                                constants['screen_width'],
                                constants['screen_height'])

                tc.console_flush()

                action = handle_main_menu(key)

                new_game = action.get('new_game')
                load_saved_game = action.get('load_saved_game')
                exit_game = action.get('exit')

                if show_load_error_message and (new_game or load_saved_game
                                                or exit_game):
                    show_load_error_message = False
                elif new_game:
                    player, entities, game_map, message_log, game_state = get_game_variables(
                        constants)
                    game_state = GameState.PLAYER_TURN

                    show_main_menu = False
                elif load_saved_game:
                    try:
                        player, entities, game_map, message_log, game_state = load_game(
                        )
                        show_main_menu = False
                    except FileNotFoundError:
                        show_load_error_message = True
                elif exit_game:
                    break

            else:
                con.clear(fg=(63, 127, 63))
                play_game(player, entities, game_map, message_log, game_state,
                          con, panel, constants)
                return True