Exemplo n.º 1
0
def main_menu():
    img = tcod.ImageFile("menu_background1.png")
    con = tcod.root_console

    while not tcod.is_window_closed():
        img.blit_2x(con)
        con.set_default_foreground(tcod.COLOR_LIGHT_YELLOW)
        con.print_ex(const.SCREEN_WIDTH/2, const.SCREEN_HEIGHT/2 - 4, align=tcod.ALIGN_CENTER,
                     text="Random Life")
        con.print_ex(const.SCREEN_WIDTH/2, const.SCREEN_HEIGHT-2, align=tcod.ALIGN_CENTER,
                     text="A tutorial roguelike using libtcod")

        key = utils.menu('', ['Start a new game', 'Resume last game', 'Quit'], width=24)

        if key.c == ord('a'): # New game
            game_loop(new_game())
        elif key.c == ord('b'): # Load game
            try:
                player = load_game()
                game_loop(player)
            except:
                utils.msgbox('Loading the game failed: are you sure one exists?')
                continue
        elif key.c == ord('c') or key.c == ord('q'): # Quit
            break;
Exemplo n.º 2
0
def game_loop(player):
    while not tcod.is_window_closed():
        utils.render_all(player)

        action = handle_events(player)
        if action == const.ACTION_EXIT:
            save_game(player.map)
            break
        elif action == const.ACTION_DESCEND_STAIRS:
            next_level(player)
        elif action != const.ACTION_NONE:
            for e in player.map.entities:
                if e.ai is not None:
                    e.ai.think()
Exemplo n.º 3
0
def main_loop(top, dialog=False):
    while True:
        top.render()
        tcod.flush()

        # Get the input...
        get_input()
        if tcod.is_window_closed():
            events.post(events.QUIT)

        # ...and handle it:
        for event in events.generator():
            if event.type is events.QUIT:
                # Repost the quit event to break out of all the loops.
                events.post(events.QUIT)
                return
            elif dialog and event.type in {events.OK, events.CANCEL}:
                return event.data
            elif event.type is events.LAUNCH:
                event.data()
            else:
                top.handle_event(event)
Exemplo n.º 4
0
def main_loop(top, dialog=False):
    while True:
        top.render()
        tcod.flush()

        # Get the input...
        get_input()
        if tcod.is_window_closed():
            events.post(events.QUIT)

        # ...and handle it:
        for event in events.generator():
            if event.type is events.QUIT:
                # Repost the quit event to break out of all the loops.
                events.post(events.QUIT)
                return
            elif dialog and event.type in {events.OK, events.CANCEL}:
                return event.data
            elif event.type is events.LAUNCH:
                event.data()
            else:
                top.handle_event(event)