Example #1
0
def blit_dialogues():
    """
        Draw dialogues onto the screen.
    """
    if len(player.dialogues) > 0:
        libtcod.console_clear(0)
        dlg = player.dialogues[-1]
        if dlg.npc_picture:
            icon = libtcod.image_load(os.path.join('data', 'images', dlg.npc_picture))
        else:
            icon = libtcod.image_load(os.path.join('data', 'images', 'icon-%s.png' % (dlg.npc_name)))
        frame = libtcod.image_load(os.path.join('data', 'images', 'dialogue-frame.png'))
        libtcod.image_blit_rect(frame, 0, 0, 0, -1, -1, libtcod.BKGND_SET)
        libtcod.image_blit_rect(icon, 0, C.MAP_LEFT, C.MAP_TOP, -1, -1, libtcod.BKGND_SET)
        # title
        libtcod.console_print_ex(0, 2 + (C.MAP_WIDTH / 2), 2,
                            libtcod.BKGND_NONE, libtcod.CENTER, 
                            "%c%s says:%c" % (C.COL4, dlg.npc_name, C.COLS))
#        # the message
#        libtcod.console_print_ex(0, 2 + (C.MAP_WIDTH / 2), C.MAP_TOP + 4,
#                            libtcod.BKGND_NONE, libtcod.CENTER, 
#                            "\"%c%s%c\"" % (C.COL5, dlg.dialogue, C.COLS))
        try:
            libtcod.console_print_rect(
                    0, 4, 6, C.MAP_WIDTH - 4, C.MAP_HEIGHT - 2,
                    "%s" % (dlg.dialogue))
        except e:
            print('dialogue string format error: %s' % (e))

        # press space
        libtcod.console_print_ex(0, 2 + (C.MAP_WIDTH / 2), 
                            C.SCREEN_HEIGHT - 1, 
                            libtcod.BKGND_NONE, libtcod.CENTER, 
                            "(spacebar or enter...)")
Example #2
0
def blit_lost():
    libtcod.console_clear(0)
    frame = libtcod.image_load(os.path.join('data', 'images', 'dialogue-frame.png'))
    libtcod.image_blit_rect(frame, 0, 0, 0, -1, -1, libtcod.BKGND_SET)
    icon = libtcod.image_load(os.path.join('data', 'images', 'icon-paw.png'))
    libtcod.image_blit_rect(icon, 0, C.MAP_LEFT, C.MAP_TOP, -1, -1, libtcod.BKGND_SET)
    libtcod.console_print_ex(0, C.SCREEN_WIDTH / 2, 4,
                        libtcod.BKGND_NONE, libtcod.CENTER, \
                        "Ouch! You lost all your health.\n\n" \
                        "You rest to retry this level.\n\n" \
                        "(press space to try again)")
def main_menu():
    img = libtcod.image_load('menu_background.png')

    while not libtcod.console_is_window_closed():
        # show the background image, at twice the regular console
        # resolution
        libtcod.image_blit_2x(img, 0, 0, 0)

        # show the game's title, and some credits!
        libtcod.console_set_default_foreground(0, libtcod.light_yellow)
        libtcod.console_print_ex(0, SCREEN_WIDTH / 2, SCREEN_HEIGHT / 2 - 4,
                                 libtcod.BKGND_NONE, libtcod.CENTER,
                                 'TOMBS OF THE ANCIENT KINGS')
        libtcod.console_print_ex(0, SCREEN_WIDTH / 2, SCREEN_HEIGHT - 2,
                                 libtcod.BKGND_NONE, libtcod.CENTER,
                                 'By Jotaf')

        # show options and wait for the player's choice
        choice = menu('', ['Play a new game', 'Continue last game', 'Quit'],
                      24)

        if choice == 0:  # new game
            new_game()
            play_game()
        if choice == 1:  # load last game
            try:
                load_game()
            except:
                msgbox('\n No saved game to load.\n', 24)
                continue
            play_game()
        elif choice == 2:  # quit
            break
Example #4
0
def blit_about():
    libtcod.console_clear(0)
    icon = libtcod.image_load(os.path.join('data', 'images', 'about-frame.png'))
    libtcod.image_blit_rect(icon, 0, 0, 0, -1, -1, libtcod.BKGND_SET)
    try:
        readme = file('README', 'r')
    except IOError, e:
        libtcod.console_print_ex(0, 2, 2,
                        libtcod.BKGND_NONE, libtcod.LEFT, 
                        "Error: about file not found :'(")
        return None
Example #5
0
def blit_victory():
    libtcod.console_clear(0)
    frame = libtcod.image_load(os.path.join('data', 'images', 'about-frame.png'))
    libtcod.image_blit_rect(frame, 0, 0, 0, -1, -1, libtcod.BKGND_SET)
    results = ["You won, Top Dog!"]
    results.append("You moved %s times." % (player.moves))
    results.append("You drank %s puddles." % (player.quenches))
    results.append("You took %s bites." % (player.bites_taken))
    results.append("You ate %s treats." % (player.treats_eaten))
    results.append("You piddled %s times." % (player.piddles_taken))
    results.append("Your score is %s!" % (player.score))
    results.append("Well Done ^_^")
    libtcod.console_print_ex(0, C.SCREEN_WIDTH / 2, 4,
                        libtcod.BKGND_NONE, libtcod.CENTER, "\n\n".join(results))
Example #6
0
def blit_menu():
    libtcod.console_clear(0)
    icon = libtcod.image_load(os.path.join('data', 'images', 'intro.png'))
    libtcod.image_blit_rect(icon, 0, 0, 0, -1, -1, libtcod.BKGND_SET)
    text = [
        "version %s" % (C.VERSION)
        ,"%cA%cbout" % (C.COL1, C.COLS)
        ,"%cspace%c to continue"  % (C.COL4, C.COLS)
        ]
    libtcod.console_print_ex(0, 2, 45,
                        libtcod.BKGND_NONE, libtcod.LEFT, 
                        "\n".join(text))
    libtcod.console_print_ex(0, C.SCREEN_WIDTH / 2, 24,
                        libtcod.BKGND_NONE, libtcod.CENTER, 
                        "in 'The Lost Puppy'")
Example #7
0
def blit_help():
    """
        Show help.
    """
    libtcod.console_clear(0)
    icon = libtcod.image_load(os.path.join('data', 'images', 'stats-frame.png'))
    libtcod.image_blit_rect(icon, 0, C.MAP_LEFT, C.MAP_TOP, -1, -1, libtcod.BKGND_SET)
    
    libtcod.console_print_ex(0, C.SCREEN_WIDTH / 2, 2,
                        libtcod.BKGND_NONE, libtcod.CENTER, 
                        "%cTop Dog%c\nv%s\n^_^" % (C.COL5, C.COLS, C.VERSION))
                            

#    helptext = ["%c%s%s" % (C.COL5, C.COLS, C.VERSION)]
    helptext = ["The %cPuppy%c has been kidnapped by the %cFat Cat Mafioso%c. You travel from yard to yard, searching for the crafty Cats!" % (C.COL4, C.COLS, C.COL1, C.COLS)]
    
    helptext.append("\nYou are the %c@%c sign. Walk into other animals to interact with them." % (C.COL3, C.COLS))
    helptext.append("\n%cKEYPAD%c" % (C.COL5, C.COLS))
    helptext.append("\nUse the %cKeypad%c to move, this is preferred as \
diagonals are the dog's bark. Keypad 5 shows your stats, as does [i]nfo. The %cARROW%c keys also move you." \
        % (C.COL4, C.COLS, C.COL4, C.COLS))

    helptext.append("\n%cACTIONS%c" % (C.COL5, C.COLS))
    helptext.append("\n[%cd%c]rink water" % (C.COL5, C.COLS))
    helptext.append("[%ce%c]at food" % (C.COL5, C.COLS))
    helptext.append("[%cp%c]piddle to relieve yourself" % (C.COL5, C.COLS))
    helptext.append("[%ci%c]nfo screen: stats and quests" % (C.COL5, C.COLS))

    helptext.append("\nThe keypad also map to actions, use this mnemonic to remember:")
    helptext.append("\n%cD%crink and %cD%civide\n%cE%cat and %cM%cultiply\n%cP%ciddling %cS%coothes ;)" % (C.COL1, C.COLS, C.COL1, C.COLS
                , C.COL2, C.COLS, C.COL2, C.COLS
                , C.COL3, C.COLS, C.COL3, C.COLS))

    helptext.append("\nNow go find that %cPuppy!%c" % (C.COL5, C.COLS))
    helptext.append("\nWOOF!")

    libtcod.console_print_rect(0, 4, 10, C.MAP_WIDTH - 4, C.MAP_HEIGHT - 2,
                        "\n".join(helptext))
Example #8
0
def blit_player_stats():
    """
        Draw player stats and quests screen.
    """
    libtcod.console_clear(0)
    icon = libtcod.image_load(os.path.join('data', 'images', 'stats-frame.png'))
    libtcod.image_blit_rect(icon, 0, C.MAP_LEFT, C.MAP_TOP, -1, -1, libtcod.BKGND_SET)
    
    if player.carrying:
        if player.carrying.quest_id:
            inv_item = "%c%s%c\n%c*quest item*%c" % \
                (C.COL3, player.carrying.name, C.COLS, C.COL4, C.COLS)
        else:
            inv_item = "%c%s%c" % (C.COL3, player.carrying.name, C.COLS)
    else:
        inv_item = ""
    
    labels = (
        ""
        ,""
        ,"%clevel%c:" % (C.COL5, C.COLS)
        ,"%cscore%c:" % (C.COL5, C.COLS)
        ,"%cmoves%c:" % (C.COL5, C.COLS)
        ,"%cinventory%c:" % (C.COL5, C.COLS)
        )
    values = [
        "%cTop Dog%c" % (C.COL5, C.COLS)
        ,""
        ,str(player.level)
        ,str(player.score)
        ,str(player.moves)
        ,inv_item
    ]
    
    # name, score, inventory
    libtcod.console_print_ex(0, C.STATS_SCREEN_LEFT, C.STATS_SCREEN_TOP,
                        libtcod.BKGND_NONE, libtcod.RIGHT, 
                        "\n".join(labels))

    libtcod.console_print_ex(0, C.STATS_SCREEN_LEFT + 2, C.STATS_SCREEN_TOP,
                        libtcod.BKGND_NONE, libtcod.LEFT, 
                        "\n".join(values))
    
    # quests
    values = []
    if len(player.quests) > 0:
        values = ["%cQUESTS%c\n" % (C.COL5, C.COLS)]
    for q in player.quests:
        values.append("+ %s" % (q.title))
    
    # hungry, thirsty, piddle, inventory
    if player.weak:
        values.append("+ %cweak%c, [e]at food" % (C.COL1, C.COLS))
    if player.hungry:
        values.append("+ %chungry%c, [e]at *food*" % (C.COL2, C.COLS))
    if player.thirsty:
        values.append("+ %cthirsty%c, [d]rink water" % (C.COL2, C.COLS))
    libtcod.console_print_ex(0, 4, C.SCREEN_HEIGHT / 2,
                        libtcod.BKGND_NONE, libtcod.LEFT, 
                        "\n".join(values))

    
    
    # player hearts
    if player.weak:
        heart_colors = [libtcod.red]* 10
    else:
        heart_colors = (libtcod.red, libtcod.red, libtcod.orange, libtcod.orange
                        , libtcod.amber, libtcod.amber, libtcod.lime, libtcod.lime
                        , libtcod.chartreuse, libtcod.chartreuse)
    for heart in range(player.get_hearts()):
        libtcod.console_put_char_ex(
                        0, heart + C.STAT_HEART_LEFT, C.STAT_HEART_TOP
                        ,chr(3), heart_colors[heart], None)
Example #9
0
        factory.spawn_level_storyline(game_map, game_objects, player)

        # compute field of vision
        libtcod.map_compute_fov(fov_map, player.x, player.y
                                ,player.fov_radius, C.FOV_LIGHT_WALLS, C.FOV_ALGO)
        # carry our inventory item into this new level
        if player.carrying:
            game_objects.append(player.carrying)


if __name__ == "__main__":
    """
        Entry point.
    """
    canvas = factory.init_libtcod()
    mullions = libtcod.image_load(os.path.join('data', 'images','background.png'))
    kb_handler = setup_keyhandler()
    gamestate = cls.GameState()
    maps_avail = factory.count_available_maps()
    game_map = None
    path_map = None
    fov_map = None
    game_objects = None
    player = None
    save_screenshot = False
    
    while not libtcod.console_is_window_closed():
        state = gamestate.peek()
        if state == C.STATE_MENU:
            blit_menu()
        elif state == C.STATE_ABOUT: