Esempio n. 1
0
def render_all():
	global fov_map, color_dark_wall, color_light_wall
	global color_dark_ground, color_light_ground
	global fov_recompute

	if fov_recompute:
		fov_recompute = False
		libtcod.map_compute_fov(fov_map, player.x, player.y, TORCH_RADIUS, FOV_LIGHT_WALLS, FOV_ALGO)

	for y in range(MAP_HEIGHT):
		for x in range(MAP_WIDTH):
			visible = libtcod.map_is_in_fov(fov_map, x, y)
			tile = map[x][y].sort
			if not visible:
				if map[x][y].explored:
					if tile == 'wall':
						libtcod.console_set_back(con, x, y, color_dark_wall, libtcod.BKGND_SET)
					elif tile == 'metal1':
						libtcod.console_set_back(con, x, y, color_dark_metal1, libtcod.BKGND_SET)
					elif tile == 'metal2':
						libtcod.console_set_back(con, x, y, color_dark_metal2, libtcod.BKGND_SET)
					else:
						libtcod.console_set_back(con, x, y, color_dark_ground, libtcod.BKGND_SET)
			else:
				if tile == 'wall':
					libtcod.console_set_back(con, x, y, color_light_wall, libtcod.BKGND_SET)
				elif tile == 'metal1':
					libtcod.console_set_back(con, x, y, color_light_metal1, libtcod.BKGND_SET)
				elif tile == 'metal2':
					libtcod.console_set_back(con, x, y, color_light_metal2, libtcod.BKGND_SET)
				else:
					libtcod.console_set_back(con, x, y, color_light_ground, libtcod.BKGND_SET)
				map[x][y].explored = True

	for object in objects:
		if object != player:
			object.draw()
	player.draw()

	libtcod.console_blit(con, 0, 0, MAP_WIDTH, MAP_HEIGHT, 0, 0, 0)

	libtcod.console_set_background_color(panel, libtcod.black)
	libtcod.console_clear(panel)
	
	y = 1
	for (line, color) in game_msgs:
		libtcod.console_set_foreground_color(panel, color)
		libtcod.console_print_left(panel, MSG_X, y, libtcod.BKGND_NONE, line)
		y += 1

	render_bar(1, 1, BAR_WIDTH, 'John\'s Oxygen', player.spaceman.oxygen, player.spaceman.max_oxygen, libtcod.light_red, libtcod.darker_red)
	render_bar(1, 3, BAR_WIDTH, 'Adam\'s Oxygen', npc.spaceman.oxygen, npc.spaceman.max_oxygen, libtcod.light_magenta, libtcod.darker_magenta)

	libtcod.console_set_foreground_color(panel, libtcod.light_gray)
	libtcod.console_print_left(panel, 1, 0, libtcod.BKGND_NONE, get_names_under_mouse())

	libtcod.console_blit(panel, 0, 0, SCREEN_WIDTH, PANEL_HEIGHT, 0, 0, PANEL_Y)

	for object in objects:
		object.clear()
Esempio n. 2
0
File: game.py Progetto: scgs/tbfch
def menu(header, options, width, skip=None):
    maxoptions = 26
    if skip:
        maxoptions = 25

    if len(options) > maxoptions:
        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_height_left_rect(con, 0, 0, width, SCREEN_HEIGHT, header)
    if header == "":
        header_height = 0
    height = len(options) + header_height

    # create an off-screen console that represents the menu's window
    window = libtcod.console_new(width, height)

    # print the header, with auto-wrap
    libtcod.console_set_foreground_color(window, libtcod.white)
    libtcod.console_print_left_rect(window, 0, 0, width, height, libtcod.BKGND_NONE, header)

    # print all the options
    y = header_height
    letter_index = ord("a")
    for option_text in options:
        if skip and letter_index == ord(skip):
            letter_index += 1
        text = "(" + chr(letter_index) + ") " + option_text
        libtcod.console_print_left(window, 0, y, libtcod.BKGND_NONE, text)
        y += 1
        letter_index += 1

    # blit the contents of "window" to the root console
    x = SCREEN_WIDTH / 2 - width / 2
    y = SCREEN_HEIGHT / 2 - height / 2
    libtcod.console_blit(window, 0, 0, width, height, 0, x, y, 1.0, 0.7)

    # present the root console to the player and wait for a key-press
    libtcod.console_flush()
    key = libtcod.console_wait_for_keypress(True)

    if key.vk == libtcod.KEY_ENTER and key.lalt:  # (special case) Alt+Enter: toggle fullscreen
        libtcod.console_set_fullscreen(not libtcod.console_is_fullscreen())

    # convert the ASCII code to an index; if it corresponds to an option, return it
    index = key.c - ord("a")
    maxindex = len(options) - 1
    if skip and index > ord(skip) - ord("a"):
        maxindex = len(options)
    if index >= 0 and index <= maxindex:
        if skip:
            skippedindex = ord(skip) - ord("a")
            if index == skippedindex:
                return None
            if index > skippedindex:
                return index - 1
        return index
    return None
Esempio n. 3
0
def draw_messages(player, start_pos = 0):
	X, Y, W, H = 30, 40, 50, 10
	
	libtcod.console_set_background_color(0, libtcod.black)
	libtcod.console_rect(0, X, Y, W, H, True, libtcod.BKGND_SET)
	
	libtcod.console_set_foreground_color(0, libtcod.white)
	
	if start_pos > 0:
		offset = 1
		libtcod.console_print_left(0, X + 1, Y + 0, libtcod.BKGND_NONE, '? Too many messages; [any] to see more')
	
	else:
		offset = 0
	
	try:
		for m, message in enumerate(player.message_log[start_pos:]):
			color = message.has_seen and libtcod.grey or libtcod.white
			
			libtcod.console_set_foreground_color(0, color)
			
			wrapped = wrap_text(message.text, W - 3, subsequent_indent = ' ')
			
			for line, text in enumerate(wrapped):
				
				if line == 0:
					if message.symbol1:
						libtcod.console_put_char_ex( 0, X + ((message.symbol2 is None) and 1 or 0), Y + offset, message.symbol1[0], message.symbol1[1] * (message.has_seen and 0.5 or 1), message.symbol1[2] * (message.has_seen and 0.5 or 1))
					
					if message.symbol2:
						libtcod.console_put_char_ex( 0, X + 1, Y + offset, message.symbol2[0], message.symbol2[1] * (message.has_seen and 0.5 or 1), message.symbol2[2] * (message.has_seen and 0.5 or 1))
				
				parsed_text, parse_data = parse_colors(text)
				libtcod.console_print_left(0, X + 3, Y + offset, libtcod.BKGND_NONE, parsed_text%parse_data)
				offset += 1
				
				if offset >= H:
					if (not message.has_seen and line + 1 < len(wrapped)) or (m + 1 < len(player.message_log) and not player.message_log[start_pos+m+1].has_seen):
						raise TooManyMessages()
					
					else:
						raise LogIsFull()
				
	except LogIsFull:
		pass
	
	except TooManyMessages:
		draw_messages(player, start_pos + 1)
		return
	
	for message in player.message_log[start_pos:]:
		message.has_seen = True
	
	if start_pos > 0:
		libtcod.console_flush()
		key = libtcod.console_wait_for_keypress(True)
		draw_messages(player)
Esempio n. 4
0
def start_menu():
    title.init_blood()
    libtcod.console_credits_reset()

    finished_libtcod_credits = False

    selection = 0
    while True:
        title.update()

        libtcod.console_clear(0)

        title.draw_blood()
        title.draw_title()

        libtcod.console_set_background_color(0, libtcod.dark_grey)
        libtcod.console_rect(0, 24, 14, 32, 7, False, libtcod.BKGND_MULTIPLY)

        libtcod.console_set_foreground_color(0, libtcod.red)
        libtcod.console_print_center(0, 40, 15, libtcod.BKGND_NONE, "Brutal RL: Slaves to Slaughter")

        libtcod.console_set_foreground_color(0, libtcod.white)
        libtcod.console_print_left(0, 35, 17, libtcod.BKGND_NONE, "New Game")
        libtcod.console_print_left(0, 35, 18, libtcod.BKGND_NONE, "Load Game")
        libtcod.console_print_left(0, 35, 19, libtcod.BKGND_NONE, "Quit")

        libtcod.console_print_left(0, 33, 17 + selection, libtcod.BKGND_NONE, ">")
        libtcod.console_print_left(0, 45, 17 + selection, libtcod.BKGND_NONE, "<")

        if not finished_libtcod_credits:
            finished_libtcod_credits = libtcod.console_credits_render(65, 43, True)

        libtcod.console_flush()

        key = libtcod.console_check_for_keypress(libtcod.KEY_PRESSED)

        if key.vk == libtcod.KEY_ESCAPE:
            if selection == 2:
                raise SetState("quit")

            else:
                selection = 2

        elif key.vk in DIRECTION_KEYS and DIRECTION_KEYS[key.vk][0] == 0:
            selection += DIRECTION_KEYS[key.vk][1]
            selection %= 3

        elif key.vk in [libtcod.KEY_ENTER, libtcod.KEY_KPENTER]:
            raise SetState([new_game, load_game, "quit"][selection])

        mouse = libtcod.mouse_get_status()
        if mouse.lbutton:
            title.set_full(mouse.cx, mouse.cy)

        elif mouse.rbutton:
            title.set_empty(mouse.cx, mouse.cy)
Esempio n. 5
0
def nextMessage():
    global messageBuffer, messageField
    if messageBuffer:
        message = messageBuffer.popleft()
        if messageBuffer:
            message = message + " --MORE--"
        libtcod.console_print_left(messageField, 0, 0, libtcod.BKGND_NONE, message)
        libtcod.console_blit(messageField, 0, 0, config.SCREEN_WIDTH, 1, 0, 0, config.SCREEN_HEIGHT - 4, 1, 1)
        libtcod.console_clear(messageField)
    else:
        libtcod.console_blit(messageField, 0, 0, config.SCREEN_WIDTH, 1, 0, 0, config.SCREEN_HEIGHT - 4, 1, 1)
Esempio n. 6
0
def Game():
	
	while not libtcod.console_is_window_closed():
		libtcod.console_set_foreground_color(0, libtcod.white)
		libtcod.console_print_left(0, Player.location_x, Player.location_y, libtcod.BKGND_NONE, Player.avatar)
		libtcod.console_flush()
	
		libtcod.console_print_left(0, Player.location_x, Player.location_y, libtcod.BKGND_NONE, ' ')
	
		exit = handle_keys()
		if exit:
			break
Esempio n. 7
0
def menu(header, options, width):
    if len(options) > MAX_OPTIONS:
        raise ValueError("Cannot have a meny with more than " +
                         str(MAX_OPTIONS) + "options.")

    #calculate the height for the menu, inclues 1 tile per line of header (after wrap)
    #and 1 line per option
    if header == "":
        headerHeight = 0
    else:
        headerHeight = libtcod.console_height_left_rect(
            con, 0, 0, width, SCREEN_HEIGHT, header)
    height = len(options) + headerHeight

    #make an off-screen console that is the menu window
    window = libtcod.console_new(width, height)

    #print header, with word wrap
    libtcod.console_set_foreground_color(window, libtcod.white)
    libtcod.console_print_left_rect(window, 0, 0, width, height,
                                    libtcod.BKGND_NONE, header)

    #prints the options to the menu
    y = headerHeight
    letterIndex = ord("a")
    for optionText in options:
        text = "(" + chr(letterIndex) + ")" + optionText
        libtcod.console_print_left(window, 0, y, libtcod.BKGND_NONE, text)
        y += 1
        letterIndex += 1

    #blit the contents of the window to the root console
    x = SCREEN_WIDTH / 2 - width / 2
    y = SCREEN_HEIGHT / 2 - height / 2
    libtcod.console_blit(window, 0, 0, width, height, 0, x, y, 1.0, 0.7)

    #present the root console to player and wait for a keypress
    libtcod.console_flush()
    keyPressed = libtcod.console_wait_for_keypress(True)

    #Allows for full-screening with Alt+Enter in menus
    if keyPressed.vk == libtcod.KEY_ENTER and (keyPressed.lalt
                                               or keyPressed.ralt):
        libtcod.console_set_fullscreen(not libtcod.console_is_fullscreen)

    #after they press a key, see which it was an do the appropriate thing
    index = keyPressed.c - ord("a")
    if index >= 0 and index < len(options):
        return index
    return None
Esempio n. 8
0
def draw_hud(player):
	libtcod.console_set_foreground_color(0, libtcod.white)
	
	X, Y, W, H = 0, 40, 30, 10
	
	libtcod.console_set_background_color(0, libtcod.black)
	libtcod.console_rect(0, X, Y, W, H, True, libtcod.BKGND_SET)
	
	libtcod.console_put_char_ex(0, X + 1, Y + 1, player.symbol, player.color, libtcod.black)
	
	libtcod.console_print_left(0, X + 3, Y + 1, libtcod.BKGND_NONE, player.name)
	libtcod.console_print_left(0, X + 1, Y + 8, libtcod.BKGND_NONE, 'In {:s}'.format(player.map.name))
	
	for i in range(10):
		if i * player.max_health > player.health * 10:
			libtcod.console_put_char_ex(0, X + 1 + i, Y + 3, ' ', libtcod.black, libtcod.darker_red)
		
		elif (i+1) * player.max_health > player.health * 10:
			libtcod.console_put_char_ex(0, X + 1 + i, Y + 3, ' ', libtcod.black, libtcod.color_lerp(libtcod.darker_red, libtcod.red, 10.*player.health/player.max_health - i))
		
		else:
			libtcod.console_put_char_ex(0, X + 1 + i, Y + 3, ' ', libtcod.black, libtcod.red)
	
	for i in range(10):
		if player.energy > i:
			libtcod.console_put_char_ex(0, X + 1 + i, Y + 4, 'O', libtcod.blue + libtcod.white * 0.2, libtcod.black)
		
		else:
			libtcod.console_put_char_ex(0, X + 1 + i, Y + 4, 'O', libtcod.desaturated_blue * 0.5, libtcod.black)
	
	libtcod.console_print_left(0, X + 12, Y + 3, libtcod.BKGND_NONE, 'MH: - {}'.format(player.mainhand and player.mainhand.name or '-'))
	
	if player.mainhand:
		libtcod.console_put_char_ex(0, X + 16, Y + 3, player.mainhand.symbol, player.mainhand.color, libtcod.black)
	
	libtcod.console_print_left(0, X + 12, Y + 4, libtcod.BKGND_NONE, 'OH: - {}'.format(player.offhand and player.offhand.name or player.mainhand and player.mainhand.wield_twohands and player.mainhand.name or '-'))
	
	if player.offhand:
		libtcod.console_put_char_ex(0, X + 16, Y + 4, player.offhand.symbol, player.offhand.color, libtcod.black)
	
	elif player.mainhand and player.mainhand.wield_twohands:
		libtcod.console_put_char_ex(0, X + 16, Y + 4, player.mainhand.symbol, player.mainhand.color, libtcod.black)
	
	libtcod.console_print_left(0, X + 12, Y + 5, libtcod.BKGND_NONE, 'AR: - {}'.format(player.wearing  and player.wearing.name or '-'))
	
	if player.wearing:
		libtcod.console_put_char_ex(0, X + 16, Y + 5, player.wearing.symbol, player.wearing.color, libtcod.black)
	
	draw_messages(player)
Esempio n. 9
0
def display_help():
	help_menu_console = libtcod.console_new(80, 50)
	
	while True:
		for line, text in enumerate(HELP_TEXT):
			parsed_text, parse_data = parse_colors(text)
			libtcod.console_print_left(help_menu_console, 0, line, libtcod.BKGND_NONE, parsed_text%parse_data)
		
		libtcod.console_blit(help_menu_console, 0, 0, 80, 50, 0, 0, 0)
		libtcod.console_flush()
		
		key = libtcod.console_wait_for_keypress(True)
		if key.vk == libtcod.KEY_ESCAPE or key.c == ord('?'):
			break
	
	libtcod.console_delete(help_menu_console)
Esempio n. 10
0
def render_bar(x, y, total_width, name, value, maximum, bar_color, back_color):  # render a bar (HP, experience, etc).
    # first calculate the width of the bar
    bar_width = int(float(value) / maximum * total_width)
    # render the background first
    libtcod.console_set_background_color(panel, back_color)
    libtcod.console_rect(panel, x, y, total_width, 1, False)
    # now render the bar on top
    libtcod.console_set_background_color(panel, bar_color)
    if bar_width > 0:
        libtcod.console_rect(panel, x, y, bar_width, 1, False)
     # finally, some centered text with the values
    libtcod.console_set_foreground_color(panel, libtcod.white)
    libtcod.console_print_center(panel, x + total_width / 2, y, libtcod.BKGND_NONE, name + ': ' + str(value) + '/' + str(maximum))
    # show the player's stats
    libtcod.console_set_foreground_color(con, libtcod.white)
    libtcod.console_print_left(con, 1, SCREEN_HEIGHT - 2, libtcod.BKGND_NONE, 'HP: ' + str(player.fighter.hp) + '/' + str(player.fighter.max_hp) +'   ')
Esempio n. 11
0
def menu(header, options, width):

    if len(options) > 26:
        raise ValueError('Cannot have a menu with more than 26 options')
    #calculate height for the header after auto-wrap and one line per option
    header_height = libtcod.console_height_left_rect(con, 0, 0, width,
                                                     SCREEN_HEIGHT, header)
    if header == '':
        header_height = 0
    height = len(options) + header_height

    #Create an off-screen console that represents the menu window
    window = libtcod.console_new(width, height)

    #Print the header with auto-wrap
    libtcod.console_set_foreground_color(window, libtcod.white)
    libtcod.console_print_left_rect(window, 0, 0, width, height,
                                    libtcod.BKGND_NONE, header)

    #Print all the options
    y = header_height
    letter_index = ord('a')
    for option_text in options:
        text = '(' + chr(letter_index) + ')' + option_text
        libtcod.console_print_left(window, 0, y, libtcod.BKGND_NONE, text)
        y += 1
        letter_index += 1

    #Blit the contents of "window" to the root console
    x = SCREEN_WIDTH / 2 - width / 2
    y = SCREEN_HEIGHT / 2 - height / 2
    libtcod.console_blit(window, 0, 0, width, height, 0, x, y, 1.0, 0.7)

    #Present the player with the root console and wait for a key-press
    libtcod.console_flush()
    key = libtcod.console_wait_for_keypress(True)

    #Convert the ASCII code to an index, and if it corresponds an option, return it
    index = key.c - ord('a')
    if index >= 0 and index < len(options):
        return index

    #alt-enter fullscreens
    if key.vk == libtcod.KEY_ENTER and key.lalt:
        libtcod.console_set_fullscreen(not libtcod.console_is_fullscreen())

    return None
Esempio n. 12
0
def render():
    for player in players:
        if not player.dead:
            tcod.console_put_char_ex(0, player.x, player.y,
                                     player_chars[(player.dx, player.dy)],
                                     tcod.black, player.color)
    if winner:
        tcod.console_set_foreground_color(0, winner.color)
        tcod.console_print_left(0, 0, map_size[1] - 1, tcod.BKGND_NONE,
                                'Player ' + str(players.index(winner) + 1) +
                                ' is the winner!')
    tcod.console_flush()

    # erase player arrows from their old positions
    for player in players:
        if not player.dead:
            tcod.console_put_char(0, player.x, player.y, ' ', tcod.BKGND_NONE)
Esempio n. 13
0
def menu(header, options, width):
    if len(options) > MAX_OPTIONS:
        raise ValueError("Cannot have a meny with more than " + str(MAX_OPTIONS) + "options.")

    #calculate the height for the menu, inclues 1 tile per line of header (after wrap)
    #and 1 line per option
    if header == "":
        headerHeight = 0
    else:
        headerHeight = libtcod.console_height_left_rect(con, 0, 0, width, SCREEN_HEIGHT, header)
    height = len(options) + headerHeight

    #make an off-screen console that is the menu window
    window = libtcod.console_new(width, height)

    #print header, with word wrap
    libtcod.console_set_foreground_color(window, libtcod.white)
    libtcod.console_print_left_rect(window, 0, 0, width, height, libtcod.BKGND_NONE, header)

    #prints the options to the menu
    y = headerHeight
    letterIndex = ord("a")
    for optionText in options:
        text = "(" + chr(letterIndex) + ")" + optionText
        libtcod.console_print_left(window, 0, y, libtcod.BKGND_NONE, text)
        y += 1
        letterIndex += 1

    #blit the contents of the window to the root console
    x = SCREEN_WIDTH/2 - width/2
    y = SCREEN_HEIGHT/2 - height/2
    libtcod.console_blit(window, 0, 0, width, height, 0, x, y, 1.0, 0.7)

    #present the root console to player and wait for a keypress
    libtcod.console_flush()
    keyPressed = libtcod.console_wait_for_keypress(True)

    #Allows for full-screening with Alt+Enter in menus
    if keyPressed.vk == libtcod.KEY_ENTER and (keyPressed.lalt or keyPressed.ralt):
        libtcod.console_set_fullscreen(not libtcod.console_is_fullscreen)

    #after they press a key, see which it was an do the appropriate thing
    index = keyPressed.c - ord("a")
    if index >= 0 and index < len(options):
        return index
    return None
Esempio n. 14
0
def render_all():
    global fov_recompute
    fov_recompute = True
    # go through all tiles, and set their background color according to the FOV
    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)
    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: # it's out of the player's FOV
                if map[x][y].explored:
                    libtcod.console_put_char_ex(con, x, y, *map[x][y].render_data(False))
            else: # it's visible
                libtcod.console_put_char_ex(con, x, y, *map[x][y].render_data(True))
                mouse = libtcod.mouse_get_status()
                if x == mouse.cx and y == mouse.cy:
                    libtcod.console_set_back(con, x, y, libtcod.yellow, libtcod.BKGND_SET)
                map[x][y].explored = True    
    for object in objects:
        if libtcod.map_is_in_fov(fov_map, object.x, object.y):
            object.draw()
    player.draw()
    # prepare to render the GUI panel
    libtcod.console_set_background_color(panel, libtcod.black)
    libtcod.console_clear(panel)
    # print the game messages, one line at a time
    y = 1
    for (line, color) in game_msgs:
        libtcod.console_set_foreground_color(panel, color)
        libtcod.console_print_left(panel, MSG_X, y, libtcod.BKGND_NONE, line)
        y += 1
    # show the player's stats
    render_bar(1, 1, BAR_WIDTH, 'HP', player.fighter.hp, player.fighter.max_hp,
        libtcod.dark_green, libtcod.red)

    # display names of objects under the mouse
    libtcod.console_set_foreground_color(panel, libtcod.light_gray)
    libtcod.console_print_left(panel, 1, 0, libtcod.BKGND_NONE, get_names_under_mouse())
    
    # Display on main console
    libtcod.console_blit(con, 0, 0, SCREEN_WIDTH, SCREEN_HEIGHT, 0, 0, 0)
    # blit the contents of "panel" to the root console
    libtcod.console_blit(panel, 0, 0, SCREEN_WIDTH, PANEL_HEIGHT, 0, 0, PANEL_Y)
Esempio n. 15
0
    def render(self, current_level, player):
        lines = []
        lines.append("Dlvl: %s" % current_level)
        lines.append("")
        lines.append("HP: %s/%s" % (player.health, player.max_health))
        lines.append("Wpn: %s" %
                     (player.weapon.describe() +
                      (" (" + str(player.get_ammo()) +
                       ")" if isinstance(player.weapon, RangedWeapon) else "")
                      if player.weapon else "None"))
        lines.append("Fear: %s" % player.fear)
        lines.append("Exp: %s" % player.exp)
        lines.append("Turns: %s" % player.turns)
        lines.append("")

        if player.panicked:
            lines.append("-- PANICKED --")

        T.console_print_left(self.con, 0, 0, T.BKGND_NONE, "\n".join(lines))
Esempio n. 16
0
def render_panel():
    libtcod.console_set_background_color(panel, libtcod.black)
    libtcod.console_clear(panel)
    #bar
    libtcod.console_set_foreground_color(panel, libtcod.white)
    for x in range(SCREEN_WIDTH):
        libtcod.console_put_char(panel, x, 0, '_', libtcod.BKGND_NONE)
    for y in range(PANEL_HEIGHT - 1):
        libtcod.console_put_char(panel, STATS_WIDTH, y+1, '|', libtcod.BKGND_NONE)

    #stats
    libtcod.console_print_left(panel, 1, 2, libtcod.BKGND_NONE, 'Level '+str(player.level))
    libtcod.console_print_left(panel, 1, 3, libtcod.BKGND_NONE, 'Health: '+str(player.health)+'/'+str(player.max_health))
    draw_bar(1, 4, STATS_WIDTH-2, player.health, player.max_health, libtcod.Color(255,0,0), libtcod.Color(128,0,0))
    libtcod.console_print_left(panel, 1, 6, libtcod.BKGND_NONE, 'Exp: '+str(experience)+'/'+str(player.level*10))
    draw_bar(1, 7, STATS_WIDTH-2, experience, player.level*10, libtcod.Color(0,255,255),libtcod.Color(0,64,64))
    libtcod.console_print_left(panel, 1, 9, libtcod.BKGND_NONE, 'Strength: '+str(player.strength)+' (x'+str(player.weapon.power)+')')
    libtcod.console_print_left(panel, 1, 10, libtcod.BKGND_NONE, 'Agility: '+str(player.agility))

    render_blotter()
Esempio n. 17
0
def render_inventory():
    libtcod.console_set_background_color(inv_con, libtcod.black)
    libtcod.console_clear(inv_con)
    libtcod.console_set_foreground_color(inv_con, libtcod.white)
    for y in range(MAP_HEIGHT):
        libtcod.console_put_char(inv_con, 0, y, '|', libtcod.BKGND_NONE)

    libtcod.console_print_left(inv_con, 2, 1, libtcod.BKGND_NONE, 'Inventory:')
    y = 3
    for item_index in range(len(inventory)):
        if inv_select == item_index:
            libtcod.console_set_foreground_color(inv_con, libtcod.white)
            libtcod.console_put_char(inv_con, 2, y, '>', libtcod.BKGND_NONE)
        else:
            libtcod.console_set_foreground_color(inv_con, libtcod.Color(128,128,128))
            libtcod.console_put_char(inv_con, 2, y, '-', libtcod.BKGND_NONE)
        name = inventory[item_index].name
        sprite = inventory[item_index].sprite
        libtcod.console_put_char(inv_con, 3, y, sprite.char, libtcod.BKGND_NONE)
        
        y += libtcod.console_print_left_rect(inv_con, 5, y, INVENTORY_WIDTH-4, 0, libtcod.BKGND_NONE, name)
Esempio n. 18
0
 def doMenu(self):
     
     tcod.console_set_foreground_color(0, tcod.white);
     
     selectedLine = 1
     
     while True:
         
         tcod.console_clear(0)
         
         index = 1
         
         for mode, name in self.options:
             tcod.console_print_left(
                     0, self.MENU_LEFT+2, self.MENU_TOP+index, 
                     tcod.BKGND_NONE, name)
             if (selectedLine == index):
                 self._selection = mode
                 tcod.console_put_char(0, self.MENU_LEFT+1, 
                                       self.MENU_TOP+index, '>')
             index += 1
         
         tcod.console_flush();
         
         # Get Input
         key = tcod.console_wait_for_keypress(True);
         
         if (key.vk == tcod.KEY_DOWN):
             selectedLine += 1
             if (selectedLine > len(self.options)):
                 selectedLine = 1
             
         elif (key.vk == tcod.KEY_UP):
             selectedLine -= 1
             if (selectedLine <= 0):
                 selectedLine = len(self.options)
         
         if (key.vk == tcod.KEY_ENTER):
             return self._selection
Esempio n. 19
0
def menu(header, options, width):
    if len(options) > 16:
        raise ValueError('Cannot have a menu with more than 26 options.')

    header_height = libtcod.console_height_left_rect(con, 0, 0, width,
                                                     SCREEN_HEIGHT, header)
    if header == '':
        header_height = 0

    height = len(options) + header_height

    window = libtcod.console_new(width, height)

    libtcod.console_set_foreground_color(window, libtcod.white)
    libtcod.console_print_left_rect(window, 0, 0, width, height,
                                    libtcod.BKGND_NONE, header)

    y = header_height
    letter_index = ord('a')
    for option_text in options:
        text = '(' + chr(letter_index) + ') ' + option_text
        libtcod.console_print_left(window, 0, y, libtcod.BKGND_NONE, text)
        y += 1
        letter_index += 1

    x = SCREEN_WIDTH / 2 - width / 2
    y = SCREEN_HEIGHT / 2 - height / 2

    libtcod.console_blit(window, 0, 0, width, height, 0, x, y, 1.0, 0.7)

    libtcod.console_flush()
    key = libtcod.console_wait_for_keypress(True)

    if key.vk == libtcod.KEY_ENTER and key.lalt:
        libtcod.console_set_fullscreen(not libtcod.console_is_fullscreen())

    index = key.c - ord('a')
    if index >= 0 and index < len(options): return index
    return None
Esempio n. 20
0
    def doMenu(self):

        tcod.console_set_foreground_color(0, tcod.white)

        selectedLine = 1

        while True:

            tcod.console_clear(0)

            index = 1

            for mode, name in self.options:
                tcod.console_print_left(0, self.MENU_LEFT + 2,
                                        self.MENU_TOP + index, tcod.BKGND_NONE,
                                        name)
                if (selectedLine == index):
                    self._selection = mode
                    tcod.console_put_char(0, self.MENU_LEFT + 1,
                                          self.MENU_TOP + index, '>')
                index += 1

            tcod.console_flush()

            # Get Input
            key = tcod.console_wait_for_keypress(True)

            if (key.vk == tcod.KEY_DOWN):
                selectedLine += 1
                if (selectedLine > len(self.options)):
                    selectedLine = 1

            elif (key.vk == tcod.KEY_UP):
                selectedLine -= 1
                if (selectedLine <= 0):
                    selectedLine = len(self.options)

            if (key.vk == tcod.KEY_ENTER):
                return self._selection
Esempio n. 21
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_height_left_rect(con, 0, 0, width, SCREEN_HEIGHT, header)
    if header == '':
        header_height = 0
    height = len(options) + header_height
    # create an off-screen console that represents the menu's window
    window = libtcod.console_new(width, height)

    #print the header, with auto-wrap
    libtcod.console_set_foreground_color(window, libtcod.white)
    libtcod.console_print_left_rect(window, 0, 0, width, height, libtcod.BKGND_NONE, header)

    # print all the options
    y = header_height
    letter_index = ord('a')
    for option_text in options:
        text = '(' + chr(letter_index) + ') ' + option_text
        libtcod.console_print_left(window, 0, y, libtcod.BKGND_NONE, text)
        y += 1
        letter_index += 1

     # blit the contents of "window" to the root console
    x, y = SCREEN_WIDTH / 2 - width / 2, SCREEN_HEIGHT / 2 - height / 2
    libtcod.console_blit(window, 0, 0, width, height, 0, x, y, 1.0, 0.7)

    # present the root console to the player and wait for a key-press
    libtcod.console_flush()
    key = libtcod.console_wait_for_keypress(True)

    # convert the ASCII code to an index; if it corresponds to an option, return it
    index = key.c - ord('a')
    if index >= 0 and index < len(options): return index

    if key.vk == libtcod.KEY_ENTER and key.lalt:  # (special case) Alt+Enter: toggle fullscreen
        libtcod.console_set_fullscreen(not libtcod.console_is_fullscreen())
    return None
Esempio n. 22
0
    def render(self, current_level, player):
        lines = []
        lines.append("Dlvl: %s" % current_level)
        lines.append("")
        lines.append("HP: %s/%s" % (player.health, player.max_health))
        lines.append(
            "Wpn: %s"
            % (
                player.weapon.describe()
                + (" (" + str(player.get_ammo()) + ")" if isinstance(player.weapon, RangedWeapon) else "")
                if player.weapon
                else "None"
            )
        )
        lines.append("Fear: %s" % player.fear)
        lines.append("Exp: %s" % player.exp)
        lines.append("Turns: %s" % player.turns)
        lines.append("")

        if player.panicked:
            lines.append("-- PANICKED --")

        T.console_print_left(self.con, 0, 0, T.BKGND_NONE, "\n".join(lines))
Esempio n. 23
0
def menu(header, options, width):
	if len(options) > 16: raise ValueError('Cannot have a menu with more than 26 options.')

	header_height = libtcod.console_height_left_rect(con, 0, 0, width, SCREEN_HEIGHT, header)
	if header == '':
		header_height = 0

	height = len(options) + header_height

	window = libtcod.console_new(width, height)

	libtcod.console_set_foreground_color(window, libtcod.white)
	libtcod.console_print_left_rect(window, 0, 0, width, height, libtcod.BKGND_NONE, header)

	y = header_height
	letter_index = ord('a')
	for option_text in options:
		text = '(' + chr(letter_index) + ') ' + option_text
		libtcod.console_print_left(window, 0, y, libtcod.BKGND_NONE, text)
		y += 1
		letter_index += 1

	x = SCREEN_WIDTH/2 - width/2
	y = SCREEN_HEIGHT/2 - height/2

	libtcod.console_blit(window, 0, 0, width, height, 0, x, y, 1.0, 0.7)

	libtcod.console_flush()
	key = libtcod.console_wait_for_keypress(True)

	if key.vk == libtcod.KEY_ENTER and key.lalt:
		libtcod.console_set_fullscreen(not libtcod.console_is_fullscreen())

	index = key.c - ord('a')
	if index >= 0 and index < len(options): return index
	return None
Esempio n. 24
0
 def draw_objects(self):
     fov_map = self.state.fov_map
     for obj in self.state.objects:
         if libtcod.map_is_in_fov(fov_map, obj.x, obj.y):
             libtcod.console_set_foreground_color(self.console, obj.color)
             libtcod.console_print_left(self.console, obj.x, obj.y, obj.color, obj.character)
Esempio n. 25
0
def render_all():
    global color_dark_wall, color_light_wall
    global color_dark_ground, color_light_ground
    global fov_recompute

    if fov_recompute:
        #recompute FOV if needed (such as player movement or spellcasting or light or something)
        fov_recompute = True
        libtcod.map_compute_fov(fov_map, player.x, player.y, TORCH_RADIUS,
                                FOV_LIGHT_WALLS, FOV_ALGO)

        #Go through tiles, set BG color
        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:
                    #Even if it isn't visible it should be "remembered"
                    if map[x][y].explored:
                        #out of player FOV
                        if wall:
                            libtcod.console_set_back(con, x, y,
                                                     color_dark_wall,
                                                     libtcod.BKGND_SET)
                        else:
                            libtcod.console_set_back(con, x, y,
                                                     color_dark_ground,
                                                     libtcod.BKGND_SET)
                else:
                    #it is visible
                    if wall:
                        libtcod.console_set_back(con, x, y, color_light_wall,
                                                 libtcod.BKGND_SET)
                    else:
                        libtcod.console_set_back(con, x, y, color_light_ground,
                                                 libtcod.BKGND_SET)
                    map[x][y].explored = True

        #Draw all objects in the object list
        for object in objects:
            if object != player:
                object.draw()
        player.draw()

        #Blit the contents of the "con" console to the root console
        libtcod.console_blit(con, 0, 0, SCREEN_WIDTH, SCREEN_HEIGHT, 0, 0, 0)

        #prepare to render GUI panels
        libtcod.console_set_background_color(panel, libtcod.black)
        libtcod.console_clear(panel)

        #print the game messages one line at a time
        y = 1
        for (line, color) in game_msgs:
            libtcod.console_set_foreground_color(panel, color)
            libtcod.console_print_left(panel, MSG_X, y, libtcod.BKGND_NONE,
                                       line)
            y += 1

        #show player's stats
        render_bar(1, 1, BAR_WIDTH, 'HP', player.combat.hp,
                   player.combat.max_hp, libtcod.light_red, libtcod.darker_red)
        libtcod.console_print_left(panel, 1, 3, libtcod.BKGND_NONE,
                                   'Dungeon level ' + str(dungeon_level))

        #Display names of things under mouse
        libtcod.console_set_foreground_color(panel, libtcod.light_gray)
        libtcod.console_print_left(panel, 1, 0, libtcod.BKGND_NONE,
                                   get_names_under_mouse())

        #blit the contents of the 'panel' to the root console
        libtcod.console_blit(panel, 0, 0, SCREEN_WIDTH, PANEL_HEIGHT, 0, 0,
                             PANEL_Y)
Esempio n. 26
0
 def render(self):
     T.console_print_left(self.con, 0, 0, T.BKGND_NONE,
                          "\n".join(self.messages[-self.height:]))
Esempio n. 27
0
 def render(self, text):
     T.console_print_left(self.con, 0, 0, T.BKGND_NONE, text)
Esempio n. 28
0
 def render(self, map, items, npcs, player):
     T.console_print_left(self.con, 0, 0, T.BKGND_NONE, map.get_string())
     self.render_objects(items, map, player)
     self.render_objects(npcs, map, player)
     self.render_objects([player], map, player)
Esempio n. 29
0
 def render(self, prompt, options):
     T.console_print_left(self.con, 0, 0, T.BKGND_NONE, prompt)
Esempio n. 30
0
 def render(self, text):
     T.console_print_left(self.con, 0, 0, T.BKGND_NONE, text)
Esempio n. 31
0
def render_all():
    global fov_map, color_dark_wall, color_light_wall
    global color_dark_ground, color_light_ground
    global fov_recompute

    if fov_recompute:
        fov_recompute = False
        libtcod.map_compute_fov(fov_map, player.x, player.y, TORCH_RADIUS,
                                FOV_LIGHT_WALLS, FOV_ALGO)

    for y in range(MAP_HEIGHT):
        for x in range(MAP_WIDTH):
            visible = libtcod.map_is_in_fov(fov_map, x, y)
            tile = map[x][y].sort
            if not visible:
                if map[x][y].explored:
                    if tile == 'wall':
                        libtcod.console_set_back(con, x, y, color_dark_wall,
                                                 libtcod.BKGND_SET)
                    elif tile == 'metal1':
                        libtcod.console_set_back(con, x, y, color_dark_metal1,
                                                 libtcod.BKGND_SET)
                    elif tile == 'metal2':
                        libtcod.console_set_back(con, x, y, color_dark_metal2,
                                                 libtcod.BKGND_SET)
                    else:
                        libtcod.console_set_back(con, x, y, color_dark_ground,
                                                 libtcod.BKGND_SET)
            else:
                if tile == 'wall':
                    libtcod.console_set_back(con, x, y, color_light_wall,
                                             libtcod.BKGND_SET)
                elif tile == 'metal1':
                    libtcod.console_set_back(con, x, y, color_light_metal1,
                                             libtcod.BKGND_SET)
                elif tile == 'metal2':
                    libtcod.console_set_back(con, x, y, color_light_metal2,
                                             libtcod.BKGND_SET)
                else:
                    libtcod.console_set_back(con, x, y, color_light_ground,
                                             libtcod.BKGND_SET)
                map[x][y].explored = True

    for object in objects:
        if object != player:
            object.draw()
    player.draw()

    libtcod.console_blit(con, 0, 0, MAP_WIDTH, MAP_HEIGHT, 0, 0, 0)

    libtcod.console_set_background_color(panel, libtcod.black)
    libtcod.console_clear(panel)

    y = 1
    for (line, color) in game_msgs:
        libtcod.console_set_foreground_color(panel, color)
        libtcod.console_print_left(panel, MSG_X, y, libtcod.BKGND_NONE, line)
        y += 1

    render_bar(1, 1, BAR_WIDTH, 'John\'s Oxygen', player.spaceman.oxygen,
               player.spaceman.max_oxygen, libtcod.light_red,
               libtcod.darker_red)
    render_bar(1, 3, BAR_WIDTH, 'Adam\'s Oxygen', npc.spaceman.oxygen,
               npc.spaceman.max_oxygen, libtcod.light_magenta,
               libtcod.darker_magenta)

    libtcod.console_set_foreground_color(panel, libtcod.light_gray)
    libtcod.console_print_left(panel, 1, 0, libtcod.BKGND_NONE,
                               get_names_under_mouse())

    libtcod.console_blit(panel, 0, 0, SCREEN_WIDTH, PANEL_HEIGHT, 0, 0,
                         PANEL_Y)

    for object in objects:
        object.clear()
Esempio n. 32
0
 def render(self):
     T.console_print_left(self.con, 0, 0, T.BKGND_NONE, self.info)
Esempio n. 33
0
def render_all():
    global color_light_wall, color_light_ground
    global color_dark_wall, color_dark_ground
    global fov_map, fov_recompute
    global player, map

    # draw the map
    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)

        # 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:
                    # it's out of the player's FOV
                    # if it's not visible right now, the player can only see it if it's explored
                    if map[x][y].explored:
                        if wall:
                            libtcod.console_set_back(con, x, y,
                                                     color_dark_wall,
                                                     libtcod.BKGND_SET)
                        else:
                            libtcod.console_set_back(con, x, y,
                                                     color_dark_ground,
                                                     libtcod.BKGND_SET)
                else:
                    # it's visible
                    # explore the tile since it is visible right now
                    map[x][y].explored = True
                    if wall:
                        libtcod.console_set_back(con, x, y, color_light_wall,
                                                 libtcod.BKGND_SET)
                    else:
                        libtcod.console_set_back(con, x, y, color_light_ground,
                                                 libtcod.BKGND_SET)

    # draw all objects in the list, except the player, we want it to
    # always appear over all the other objects! so it's drawn later.
    for object in objects:
        if object != player:
            object.draw()
    player.draw()

    # blit off-screen console to root one
    libtcod.console_blit(con, 0, 0, MAP_WIDTH, MAP_HEIGHT, 0, 0, 0)

    # prepare to render the GUI panel
    libtcod.console_set_background_color(panel, libtcod.black)
    libtcod.console_clear(panel)

    # print the game messages, one line at a time
    y = 1
    for (line, color) in game_msgs:
        libtcod.console_set_foreground_color(panel, color)
        libtcod.console_print_left(panel, MSG_X, y, libtcod.BKGND_NONE, line)
        y += 1

    # show the player's stats
    render_bar(1, 1, BAR_WIDTH, 'HP', player.fighter.hp, player.fighter.max_hp,
               libtcod.light_red, libtcod.dark_red)

    # mouse look command
    libtcod.console_set_foreground_color(panel, libtcod.light_gray)
    libtcod.console_print_left(panel, 1, 0, libtcod.BKGND_NONE,
                               get_names_under_mouse())

    # blit the contents of "panel" to the root console
    libtcod.console_blit(panel, 0, 0, SCREEN_WIDTH, PANEL_HEIGHT, 0, 0,
                         PANEL_Y)
Esempio n. 34
0
def render_all():
	global fov_map, color_dark_wall, color_light_wall
	global color_dark_ground, color_light_ground
	global fov_recompute
	
	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)
	
		#go through all tiles, and set their background color
		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
				
				# #find doorways
				# for object in objects:
					# if object.x == x and object.y == y and object.door:
						# doorway = True
					# else:
						# doorway = False
			
				if not visible:
					#if it's not visible right now, the player can only see it if it's explored
					if map[x][y].explored:
						#it's out of the player's FOV
						if wall:
							libtcod.console_put_char_ex(con, x, y, '#', libtcod.white, libtcod.darker_grey)
						else:
							libtcod.console_put_char_ex(con, x, y, '.', libtcod.white, libtcod.darker_grey)
				else:
					#it's visible
					if wall:
						libtcod.console_put_char_ex(con, x, y, '#', libtcod.white, libtcod.desaturated_yellow)
					else:
						libtcod.console_put_char_ex(con, x, y, '.', libtcod.white, libtcod.desaturated_yellow)
					#since it's visible, explore it
					map[x][y].explored = True
	
	#draw all objects
	for object in objects:
		if object != player:
			if (object.stairs or object.door) and map[object.x][object.y].explored:
				libtcod.console_set_foreground_color(con, object.color)
				libtcod.console_put_char(con, object.x, object.y, object.char, libtcod.BKGND_NONE)
			else:
				object.draw()
	player.draw()
	
	#blit 'con' to '0'
	libtcod.console_blit(con, 0, 0, MAP_WIDTH, MAP_HEIGHT, 0, 0, 0)
	
	#prepare to render the GUI panel
	libtcod.console_set_background_color(panel, libtcod.black)
	libtcod.console_clear(panel)
	
	#print the game messages, one line at a time
	y = 1
	for (line, color) in game_msgs:
		libtcod.console_set_foreground_color(panel, color)
		libtcod.console_print_left(panel, MSG_X, y, libtcod.BKGND_NONE, line)
		y += 1

	#show the player's stats
	render_bar(1, 1, BAR_WIDTH, 'HP', player.fighter.hp, player.fighter.max_hp, libtcod.light_red, libtcod.darker_red)
	libtcod.console_print_left(panel, 1, 0, libtcod.BKGND_NONE, get_names_under_mouse())
	
	#display names of objects under the mouse
	libtcod.console_set_foreground_color(panel, libtcod.light_gray)
	libtcod.console_print_left(panel, 1, 2, libtcod.BKGND_NONE, 'Current floor: ' + str(current_floor))

	#blit the contents of "panel" to the root console
	libtcod.console_blit(panel, 0, 0, SCREEN_WIDTH, PANEL_HEIGHT, 0, 0, PANEL_Y)
Esempio n. 35
0
 def render(self, prompt, options):
     T.console_print_left(self.con, 0, 0, T.BKGND_NONE, prompt)
Esempio n. 36
0
 def render(self, map, items, npcs, player):
     T.console_print_left(self.con, 0, 0, T.BKGND_NONE, map.get_string())
     self.render_objects(items, map, player)
     self.render_objects(npcs, map, player)
     self.render_objects([player], map, player)
Esempio n. 37
0
 def draw_stats(self):
     fighter = self.state.player.fighter
     hp_string = 'HP: %d/%d' % (fighter.hp, fighter.max_hp)
     libtcod.console_set_foreground_color(self.console, libtcod.white)
     libtcod.console_print_left(self.console, 1, self.screen_height - 2, libtcod.BKGND_NONE, hp_string)
Esempio n. 38
0
 def render(self):
     T.console_print_left(self.con, 0, 0, T.BKGND_NONE, self.info)
Esempio n. 39
0
 def clear_objects(self):
     for obj in self.state.objects:
         libtcod.console_print_left(self.console, obj.x, obj.y, libtcod.BKGND_NONE, ' ')
Esempio n. 40
0
def renderAll():
    global fovMap, color_dark_wall, color_light_wall
    global color_dark_ground, color_light_ground
    global fovRecompute

    if fovRecompute:
        #message("Recomputing the FOV", libtcod.orange)
        fovRecompute = False
        libtcod.map_compute_fov(fovMap, player.x, player.y, TORCH_RADIUS,
                                FOV_LIGHT_WALLS, FOV_ALGO)

        for y in range(MAP_HEIGHT):
            for x in range(MAP_WIDTH):
                visible = libtcod.map_is_in_fov(fovMap, x, y)
                wall = map[x][y].block_sight
                visited = map[x][y].explored
                if not visible:
                    if visited:
                        #if a tile is not visible but it was visited, we still display it
                        if wall:
                            #message("Not visible and a wall", libtcod.orange)
                            libtcod.console_set_back(con, x, y,
                                                     color_dark_wall,
                                                     libtcod.BKGND_SET)
                        else:
                            libtcod.console_set_back(con, x, y,
                                                     color_dark_ground,
                                                     libtcod.BKGND_SET)
                else:
                    #Once we see a tile it is considered explored
                    map[x][y].explored = True

                    #currently visible to the player
                    if wall:
                        #message("Visible and a wall", libtcod.orange)
                        libtcod.console_set_back(con, x, y, color_light_wall,
                                                 libtcod.BKGND_SET)
                    else:
                        #message("Visible and ground", libtcod.orange)
                        libtcod.console_set_back(con, x, y, color_light_ground,
                                                 libtcod.BKGND_SET)

    #draw all objects in the list
    for object in objects:
        if object != player:
            object.draw()
    #draw player last so it is always on top
    player.draw()

    #blit the contents of "con" to the root console
    libtcod.console_blit(con, 0, 0, SCREEN_WIDTH, SCREEN_HEIGHT, 0, 0, 0)

    #prepares the GUI panel
    libtcod.console_set_background_color(panel, libtcod.black)
    libtcod.console_clear(panel)

    #shows the players stats
    renderBar(1, 1, BAR_WIDTH, "HP", player.fighter.hp, player.fighter.max_hp,
              libtcod.light_red, libtcod.darker_red)

    #message(the game messages, one line at a time, libtcod.orange)
    y = 1
    for (line, color) in gameMessages:
        libtcod.console_set_foreground_color(panel, color)
        libtcod.console_print_left(panel, MSG_X, y, libtcod.BKGND_NONE, line)
        y += 1

    #display names under the mouse
    libtcod.console_set_foreground_color(panel, libtcod.light_gray)
    libtcod.console_print_left(panel, 1, 0, libtcod.BKGND_NONE,
                               getNamesUnderMouse())

    #blit the panel to the root console
    libtcod.console_blit(panel, 0, 0, SCREEN_WIDTH, PANEL_HEIGHT, 0, 0,
                         PANEL_Y)
Esempio n. 41
0
def render_all():
    global fov_map, color_dark_wall, color_light_wall
    global color_dark_ground, color_light_ground
    global fov_recompute, make_map
     
    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)
 
        #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
                    if map[x][y].explored:
                        if wall:
                            libtcod.console_set_back(con, x, y, color_dark_wall, libtcod.BKGND_SET)
                        else:
                            libtcod.console_set_back(con, x, y, color_dark_ground, libtcod.BKGND_SET)
                else:
                    #it's visible
                    if wall:
                        libtcod.console_set_back(con, x, y, color_light_wall, libtcod.BKGND_SET )
                    else:
                        libtcod.console_set_back(con, x, y, color_light_ground, libtcod.BKGND_SET )
                    #since it's visible, explore it
                    map[x][y].explored = True
 
    #draw all objects in the list, except the player. we want it to
    #always appear over all other objects! so it's drawn later.
    for object in objects:
        if object != player:
            object.draw()
    player.draw()
 
    #blit the contents of "con" to the root console
    libtcod.console_blit(con, 0, 0, MAP_WIDTH, MAP_HEIGHT, 0, 0, 0)
 
 
    #prepare to render the GUI panel
    libtcod.console_set_background_color(panel, libtcod.black)
    libtcod.console_clear(panel)
 
    #print the game messages, one line at a time
    y = 0
    for (line, color) in game_msgs:
        libtcod.console_set_foreground_color(panel, color)
        libtcod.console_print_left(panel, MSG_X, y, libtcod.BKGND_NONE, line)
        y += 1
 
    #show the player's stats
    render_bar(1, 0, BAR_WIDTH, 'HP', player.fighter.hp, player.fighter.max_hp,
        libtcod.light_red, libtcod.darker_red)
    #render_bar(2, 0, BAR_WIDTH, 'MP', player.fighter.mp, player.fighter.mp,
    #    libtcod.light_blue, libtcod.darker_blue)
 
    #blit the contents of "panel" to the root console
    libtcod.console_blit(panel, 0, 0, MAP_WIDTH, PANEL_HEIGHT, 0, 0, SCREEN_HEIGHT-PANEL_HEIGHT)
Esempio n. 42
0
def updateDisplay(player):
    libtcod.console_set_color_control(libtcod.COLCTRL_1, libtcod.red, libtcod.black)
    statusString = player.name + " HP:" + str(player.hp) + "/" + str(player.hpmax) + " Level " + str(player.level)
    libtcod.console_clear(statusCon)
    libtcod.console_print_left(statusCon, 0, 0, libtcod.BKGND_NONE, statusString)
    libtcod.console_blit(statusCon, 0, 0, config.SCREEN_WIDTH, 2, 0, 0, config.SCREEN_HEIGHT - 2, 1, 1)
Esempio n. 43
0
 def render(self):
     T.console_print_left(self.con, 0, 0, T.BKGND_NONE, "\n".join(self.messages[-self.height :]))
Esempio n. 44
0
def player_card():
	#create an off-screen console that represents the card's window
	window = libtcod.console_new(30, 20)
	
	#print player stats
	libtcod.console_set_foreground_color(window, libtcod.white)
	libtcod.console_print_left(window, 1, 1, libtcod.BKGND_NONE, 'Player')
	libtcod.console_print_left(window, 1, 2, libtcod.BKGND_NONE, 'Class: ' + player.stats.plclass)
	libtcod.console_print_left(window, 1, 3, libtcod.BKGND_NONE, 'STR:' + str(player.stats.str))
	libtcod.console_print_left(window, 1, 4, libtcod.BKGND_NONE, 'DEX:' + str(player.stats.dex))
	libtcod.console_print_left(window, 1, 5, libtcod.BKGND_NONE, 'CON:' + str(player.stats.con))
	libtcod.console_print_left(window, 1, 6, libtcod.BKGND_NONE, 'INT:' + str(player.stats.int))
	libtcod.console_print_left(window, 1, 7, libtcod.BKGND_NONE, 'FTH:' + str(player.stats.fth))
	libtcod.console_print_left(window, 1, 8, libtcod.BKGND_NONE, 'PER:' + str(player.stats.per))
	
	libtcod.console_print_left(window, 1, 10, libtcod.BKGND_NONE, 'AC: ' + str(player.stats.ac))
	libtcod.console_print_left(window, 1, 11, libtcod.BKGND_NONE, 'Encumbrance: ')
	
	libtcod.console_print_left(window, 1, 13, libtcod.BKGND_NONE, 'Hit %: ' + str((20-player.stats.hitdie)*5))
	libtcod.console_print_left(window, 1, 14, libtcod.BKGND_NONE, 'Damage: ' + str(player.stats.mindmg) + ' - ' + str(player.stats.maxdmg))
	
	#blit the contents of "window" to the root console
	libtcod.console_blit(window, 0, 0, 30, 20, 0, 1, 1, 1.0, 0.7)
	
	#present the root console to the player and wait for a key-press
	libtcod.console_flush()
	key = libtcod.console_wait_for_keypress(True)
	
	if key.vk == libtcod.KEY_ENTER and key.lalt:  #(special case) Alt+Enter: toggle fullscreen
		libtcod.console_set_fullscreen(not libtcod.console_is_fullscreen())
	
	return None