Пример #1
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
Пример #2
0
def main():
    global WINDOW_WIDTH, WINDOW_HEIGHT, CELLSIZE
    blt.open_()
    blt.set_("window: size={}x{}, cellsize={}, title='Grid Test';"
             "font: default".format(
                 str(WINDOW_WIDTH), str(WINDOW_HEIGHT), CELLSIZE))
    blt.clear()
    blt.refresh()
    blt.color("white")
    g = Quadrant()
    blt.clear()
    for x in range(30):
        for y in range(30):
            if [x, y] in g.all_nodes:
                blt.print_(x * 2, y * 2, 'O')
            elif [x, y] in g.roads:
                # if x != 0 and x != 10 and y != 0 and y != 10:
                    # blt.layer(1)
                # blt.print_(x * 2, y * 2, str(g.roads.index([x, y])))
                    # blt.layer(0)
                # else:
                blt.print_(x * 2, y * 2, '+')
    blt.refresh()

    proceed = True
    while proceed:
        key = 0
        while blt.has_input():
            key = blt.read()
            if key == blt.TK_CLOSE or key == blt.TK_Q:
                proceed = False
    blt.close()
Пример #3
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)
Пример #4
0
 def initialize_blt(self):
     terminal.open()
     terminal.set(
         "window: size={}x{}, cellsize={}, title='Roguelike';"
         "font: default;"
         "input: filter=[keyboard+];"
         "".format(str(self.window_width), str(self.window_height), self.cellsize)
     )
     terminal.clear()
     terminal.refresh()
     terminal.color("white")
Пример #5
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
Пример #6
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))
Пример #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 drawchar(xy, color, alpha=1):
    x, y = xy
    terminal.color(color.trans(alpha))
    #terminal.bkcolor('black')
    terminal.put(x, y, 'O')
Пример #9
0
def drawchar(xy, color, alpha=1):
    x, y = xy
    terminal.color(color.trans(alpha))
    #terminal.bkcolor('black')
    terminal.put(x, y, 'O')
Пример #10
0



terminal.open()

terminal.set("window: size=80x25, cellsize=auto, title='Omni: menu';"
            "font: default;"
            "input: filter={keyboard}")

terminal.composition(True)

alphas = [16, 32, 64,80, 96, 112, 128, 144, 160, 176, 192, 208, 224, 240, 255, 240, 224, 208, 192, 176, 160, 144, 128, 112, 96, 80, 64, 32]
_alphas = cycle(alphas)

terminal.color(terminal.color_from_argb(128, 255,30,30))
drawRect(5,5,10,10)

color10 = bltColor('blue')

terminal.color(terminal.color_from_argb(128, 30,30,255))
#terminal.color(color10.trans(255))
drawRect(10,10,10,10)


l1 = (40, 12)
l2 = (25, 5)
l3 = (60, 18)
l4 = (5, 5)
l5 = (5, 18)