コード例 #1
0
def render_bar(x, y, total_width, name, value, maximum, bar_color, back_color):
    #adjust: move panel to desired location (bottom of console)
    y = y + PANEL_Y
    #set console to GUI layer
    terminal.layer(5)
    #render a bar (HP, experience, etc). first calculate the width of the bar
    bar_width = int(float(value) / maximum * total_width)
    #set total-width back bar color
    terminal.color(back_color)
    #terminal: draw a row of given length
    a = 0
    for b in range(total_width):
        terminal.put(x + a, y, BAR_CHAR)
        a += 1
    #now render the bar on top
    #set bar itself color
    terminal.color(bar_color)
    #libtcod.console_set_default_background(panel, bar_color)
    if bar_width > 0:
        a = 0
        for b in range(bar_width):
            terminal.put(x + a, y, BAR_CHAR)
            a += 1
    #finally, some centered text with the values
    #first clear previous text, then draw new text, centred.
    terminal.color("#FFFFFF")
    terminal.layer(6)
    terminal.clear_area(x, y, total_width, 1)
    bar_center = len(name + ': ' + str(value) + '/' + str(maximum))/2
    terminal.print_(x + total_width/2 - bar_center, y, name + ': ' + str(value) + '/' + str(maximum))
コード例 #2
0
def check_level_up():
    #see if the player's experience is enough to level up
    level_up_xp = LEVEL_UP_BASE + player.level * LEVEL_UP_FACTOR
    if player.fighter.xp >= level_up_xp:
        #it is! level up
        player.level += 1
        player.fighter.xp -= level_up_xp
        message('Your battle skills have improved! You reached level ' + str(player.level) + '!', 4294967040)
        choice = None
        while choice == None:
            choice = menu('Level up! Choose a stat to raise:\n',
                          ['Constitution (+20 HP, from ' + str(player.fighter.max_hp) + ')',
                'Strength (+1 attack, from ' + str(player.fighter.power) + ')',
                'Agility (+1 defense, from ' + str(player.fighter.defense) + ')'], LEVEL_SCREEN_WIDTH)
        if choice == 0:
            player.fighter.base_max_hp += 20
            player.fighter.hp += 20

        elif choice == 1:
            player.fighter.base_power += 1

        elif choice == 2:
            player.fighter.base_defense += 1

        #clear level menu before refresh
        terminal.layer(6)
        terminal.clear_area(0, 0, MAP_WIDTH, MAP_HEIGHT)
コード例 #3
0
 def clear(self):
     #erase the character that represents this object
     if self.fighter:
         terminal.layer(4)
     else:
         terminal.layer(3)
     terminal.put(self.x, self.y, ' ')
コード例 #4
0
def main_menu():

    while True:
        terminal.clear()
        for y in range(50):
            for x in range(80):
                terminal.color(1678238975 - x)
                terminal.put(x, y, 20)

        terminal.refresh()

        #show the game's title and some credits
        terminal.layer(6)
        terminal.color(4294967103)
        terminal.print_(SCREEN_WIDTH/2 - 10, SCREEN_HEIGHT/2-4, 'CAVES OF THE SNAILMEN')
        terminal.print_(SCREEN_WIDTH/2, SCREEN_HEIGHT-2, 'By Tommy Z')

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

        if choice == 0:  #new game
            terminal.clear()
            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

            terminal.close()
            break
コード例 #5
0
 def draw(self):
     #set the color and then draw the character that represents this object at its position
     if (libtcod.map_is_in_fov(fov_map, self.x, self.y) or
         (self.always_visible and map[self.x][self.y].explored)):
         #set color and then draw character at location
         if self.fighter:
             terminal.layer(4)
         else:
             terminal.layer(3)
         terminal.color("#FFFFFF")
         terminal.put(self.x, self.y, self.char)
コード例 #6
0
def monster_death(monster):
    #transform it into a nasty corpse! it doesn't block, can't be
    #attacked and doesn't move
    message(monster.name.capitalize() + ' is dead! You again ' + str(monster.fighter.xp) + 'xp.', 4294901760)
    monster.char = 22
    monster.blocks = False
    monster.fighter = None
    monster.ai = None
    monster.name = 'remains of ' + monster.name
    monster.send_to_back()
    #clearing monster sprite from its layer, since corpse is not 'fighter' type
    terminal.layer(4)
    terminal.clear_area(monster.x, monster.y, 1, 1)
コード例 #7
0
def menu(header, options, width):
    if len(options) > 26: raise ValueError('Cannot have a menu with more than 26 options.')
    #calculate total height for the header (after auto-wrap) and one line per option
    #header_height = libtcod.console_get_height_rect(con, 0, 0, width, SCREEN_HEIGHT, header)!!!

    header_height = len(textwrap.wrap(header, width))
    height = len(options) + header_height
    #set co-ords of menu
    menu_x = SCREEN_WIDTH/2 - width/2
    menu_y = SCREEN_HEIGHT/2 - height/2

    #paint menu background
    terminal.layer(5)
    terminal.color(MENU_BACKGROUND_COLOR) #menu
    for y_bg in range(height):
        for x_bg in range(width):
            terminal.put(menu_x + x_bg, menu_y + y_bg, 20)


    #print the header, with auto-wrap
    terminal.layer(6)
    terminal.color('#FFFFFF')
    y = 0
    for line in textwrap.wrap(header, width):
        terminal.print_(menu_x, menu_y + y, line)
        y += 1

    #position of options, below header (y)
    y = menu_y + header_height
    letter_index = ord('a')

    #print all the options
    for option_text in options:
        text = '(' + chr(letter_index) + ') ' + option_text
        #libtcod.console_print_ex(window, 0, y, libtcod.BKGND_NONE, libtcod.LEFT, text)
        terminal.print_(menu_x, y, text)
        y += 1
        letter_index += 1
    #present the root console to the player and wait for a key-press

    terminal.refresh()
    key = terminal.read() #temporary halt of operation, wait for keypress/click

    #clear the menu from screen
    terminal.layer(5)
    terminal.clear_area(menu_x, menu_y, width, height)

    if terminal.state(terminal.TK_CHAR): #!! maybe no if statement here?
        #convert the ASCII code to an index; if it corresponds to an option, return it
        index = terminal.state(terminal.TK_CHAR) - ord('a')
        if index >= 0 and index < len(options): return index
        return None
コード例 #8
0
def render_all():
    global fov_map, color_dark_wall, color_light_wall
    global color_dark_ground, color_light_ground
    global fov_recompute, game_msgs

    if fov_recompute:
        #recompute FOV if needed (the player moved or something)
        fov_recompute = False
        libtcod.map_compute_fov(fov_map, player.x, player.y, TORCH_RADIUS, FOV_LIGHT_WALLS, FOV_ALGO)
        terminal.color("#FFFFFF")
        #go through all tiles, and set their background color according to the FOV
        for y in range(MAP_HEIGHT):
            for x in range(MAP_WIDTH):
                visible = libtcod.map_is_in_fov(fov_map, x, y)
                wall = map[x][y].block_sight
                if not visible:
                    #if it's not visible right now, the player can only see it if it's explored
                    terminal.layer(2)
                    if map[x][y].explored:
                        if wall:
                            terminal.put(x, y, tile_dark_wall)
                        else:
                            terminal.put(x, y, tile_dark_ground)
                else:
                    #it's visible
                    if wall:
                        terminal.put(x, y, tile_light_wall)
                    else:
                        terminal.put(x, y, tile_light_ground)
                    #since it's visible, explore it
                    map[x][y].explored = True

    #draw all objects in the list, except the player. we want it to
    for object in objects:
        object.draw()

    #prepare to render the GUI text
    terminal.layer(6)
    terminal.clear_area(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT)
    #print the game messages, one line at a time
    y = 1
    for (line, color) in game_msgs:
        terminal.color(color)
        terminal.print_(MSG_X, y+PANEL_Y, line)
        y += 1

    #show the player's hp
    render_bar(1, 3, BAR_WIDTH, 'HP', player.fighter.hp, player.fighter.max_hp, 4294917951, 4286513152)

    #show xp
    level_up_xp = LEVEL_UP_BASE + player.level * LEVEL_UP_FACTOR
    render_bar( 1, 4, BAR_WIDTH, 'XP', player.fighter.xp, level_up_xp, 4282384191, 4278222592)

    #print dungeon level
    terminal.layer(6)
    terminal.color(4282335231)
    terminal.print_(1,PANEL_Y +1,'  S N A I L M A N ')
    terminal.color(4294967295)
    terminal.print_(1,PANEL_Y + 5, 'Dungeon level ' + str(dungeon_level))

    #display names of objects under the mouse
    #still on layer 6 ***** (text layer)
    terminal.print_(1, PANEL_Y, get_names_under_mouse())