예제 #1
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, ' ')
예제 #2
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))
예제 #3
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
예제 #4
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)
예제 #5
0
def debug():
    terminal.put(10, 10, 133) #
    terminal.print_(11, 10, ': dark wall') # dark wall
    terminal.put(10, 11, 130) #
    terminal.print_(11, 11, ': light wall') # light wall
    terminal.put(10, 12, 136) #
    terminal.print_(11, 12, ': dark ground') # dark ground
    terminal.put(10, 13, 137) #
    terminal.print_(11, 13, ': light ground') # light ground
    #terminal.layer(2)
    terminal.put(10, 10, 389)
예제 #6
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
예제 #7
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())
예제 #8
0
 def render_viewport(self):
     self.set_offset()
     for r_idx, row in enumerate(self.current_world):
         for c_idx, tile in enumerate(row):
             terminal.put(r_idx, c_idx, tile.glyph)
     terminal.put(self.pc.x, self.pc.y, self.pc.glyph)
예제 #9
0
bl.open()
bl.refresh()
SCREEN_WIDTH = bl.state(bl.TK_WIDTH)
SCREEN_HEIGHT = bl.state(bl.TK_HEIGHT)

the_map = Map(SCREEN_WIDTH, SCREEN_HEIGHT, 3, 3, 9, 9)
at = AtMan(5, 5, the_map)
left_apostrophe = MapChild(0, 1, "'", the_map)
right_apostrophe = MapChild(2, 1, "'", the_map)
dud = MapChild(4, 4, "\u2193", the_map)
the_map.draw_view()
eventhandler.register(the_map, *ARROW_EVENTS + WASD_EVENTS)

menu = ui.Menu(60, 0, SCREEN_WIDTH - 1, SCREEN_HEIGHT - 1)

paint(gridtools.hollow_rectangle(2, 2, 10, 10))
paint(gridtools.rectangle(60, 0, SCREEN_WIDTH - 1, SCREEN_HEIGHT - 1))

while True:
    drawing_system.run()
    ui_drawing_system.run()
    event = bl.read()
    if event == bl.TK_CLOSE or event == bl.TK_ESCAPE:
        break

    eventhandler.fire(event)
    bl.put(1, 1, bl.state(bl.TK_WCHAR))
    bl.refresh()

bl.close()
예제 #10
0
def paint(positions):
    bl.bkcolor('darker red')
    for pos in positions:
        bl.put(pos[0], pos[1], ' ')
    bl.bkcolor('black')
예제 #11
0
def drawchar(xy, color, alpha=1):
    x, y = xy
    terminal.color(color.trans(alpha))
    #terminal.bkcolor('black')
    terminal.put(x, y, 'O')
예제 #12
0
def ui_draw(ui_elements):
    for ui_element in ui_elements:
        bl.put(ui_element.x, ui_element.y, CHAR_CORNER_TL)
        bl.put(ui_element.x2, ui_element.y, CHAR_CORNER_TR)
        bl.put(ui_element.x, ui_element.y2, CHAR_CORNER_BL)
        bl.put(ui_element.x2, ui_element.y2, CHAR_CORNER_BR)

        for x in range(ui_element.x + 1, ui_element.x2):
            bl.put(x, ui_element.y, CHAR_HORIZONTAL)
            bl.put(x, ui_element.y2, CHAR_HORIZONTAL)
        for y in range(ui_element.y + 1, ui_element.y2):
            bl.put(ui_element.x, y, CHAR_VERTICAL)
            bl.put(ui_element.x2, y, CHAR_VERTICAL)
예제 #13
0
def draw(drawables):
    for obj in drawables:
        bl.put(obj.screen_x, obj.screen_y, obj.char)
    bl.refresh()
예제 #14
0
def drawchar(xy, color, alpha=1):
    x, y = xy
    terminal.color(color.trans(alpha))
    #terminal.bkcolor('black')
    terminal.put(x, y, 'O')
예제 #15
0
import PyBearLibTerminal as terminal

terminal.open()
terminal.printf(2, 1, "β")
terminal.put(2, 2, "β")
terminal.refresh()
while True:
    if terminal.has_input():
        key = terminal.read()
        print(key)
        if key == terminal.TK_Q | terminal.TK_KEY_RELEASED:
            print("released")
            break
        elif key == terminal.TK_Q:
            break
terminal.close()