Example #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()
Example #2
0
def render_all():
    libtcod.map_compute_fov(path_map, player.x, player.y, 0, True, libtcod.FOV_SHADOW)

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

    for y in range(MAP_HEIGHT):
        for x in range(MAP_WIDTH):
            if not libtcod.map_is_in_fov(path_map, x, y):
                if explore_map[x][y]:
                    libtcod.console_set_back(map_con, x, y, tile_map[x][y].hidden_color, libtcod.BKGND_SET)
            else:
                libtcod.console_set_background_color(map_con, tile_map[x][y].vis_color)
                libtcod.console_set_foreground_color(map_con, tile_map[x][y].char_color)
                libtcod.console_put_char(map_con, x, y, tile_map[x][y].char, libtcod.BKGND_SET)
                explore_map[x][y] = True

    entities = items + creatures
    for entity in entities:
        entity.sprite.render()

    render_panel()
    render_inventory()

    blit_consoles()
Example #3
0
    def _printStats(self, console):
        
        c = self.coords[self._selectedX][self._selectedY]
        
        messages = [
            (1, str(tcod.sys_get_fps()) + " FPS"),
            (2, "Coord: (" + str(self._selectedX)+","+str(self._selectedY)+")"),
            (3, "X-Offset: " + str(self._offsetX)),
            (4, "Y-Offset: " + str(self._offsetY)),
            (5, "Altitude: " + str(c.altitude)),
            (6, "Temp    : " + str(c.temp)),
            (7, "Rain    : " + str(c.rainfall)),
            (8, "Salinity: " + str(c.salinity)),
            (9, "Spring  : " + str(c.hasSpring)),
            (10, "Water   : " + str(c.depth)),
            (11, "Source  : " + str(c.source)),
            (12, "Biome   : " + str(c.biome.name))]
            
        tcod.console_set_foreground_color(console, tcod.Color(255,0,127));
        tcod.console_set_background_color(console, tcod.Color(0,0,0));
        for y, msg in messages:
            tcod.console_print_right(console, self._displayWidth-1, 
                                     y, tcod.BKGND_NONE, msg)
        tcod.console_set_foreground_color(console, tcod.Color(255,255,255));
        
        
        
###/////////////////////////////////////////////////////////////////////////////////////////////////
### EOF    
Example #4
0
    def _printStats(self, console):

        c = self.coords[self._selectedX][self._selectedY]

        messages = [(1, str(tcod.sys_get_fps()) + " FPS"),
                    (2, "Coord: (" + str(self._selectedX) + "," +
                     str(self._selectedY) + ")"),
                    (3, "X-Offset: " + str(self._offsetX)),
                    (4, "Y-Offset: " + str(self._offsetY)),
                    (5, "Altitude: " + str(c.altitude)),
                    (6, "Temp    : " + str(c.temp)),
                    (7, "Rain    : " + str(c.rainfall)),
                    (8, "Salinity: " + str(c.salinity)),
                    (9, "Spring  : " + str(c.hasSpring)),
                    (10, "Water   : " + str(c.depth)),
                    (11, "Source  : " + str(c.source)),
                    (12, "Biome   : " + str(c.biome.name))]

        tcod.console_set_foreground_color(console, tcod.Color(255, 0, 127))
        tcod.console_set_background_color(console, tcod.Color(0, 0, 0))
        for y, msg in messages:
            tcod.console_print_right(console, self._displayWidth - 1, y,
                                     tcod.BKGND_NONE, msg)
        tcod.console_set_foreground_color(console, tcod.Color(255, 255, 255))


###/////////////////////////////////////////////////////////////////////////////////////////////////
### EOF
Example #5
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)
Example #6
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)
Example #7
0
def draw_bar(x,y, width, current_val, max_val, full_color, empty_color):
    full_length = int(float(current_val)/max_val * width)

    libtcod.console_set_background_color(panel, empty_color)
    for i in range(width):
        libtcod.console_put_char(panel, x+i, y, ' ', libtcod.BKGND_SET)

    libtcod.console_set_background_color(panel, full_color)
    for i in range(full_length):
        libtcod.console_put_char(panel, x+i, y, ' ', libtcod.BKGND_SET)
Example #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)
Example #9
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) +'   ')
Example #10
0
def render_bar(x, y, total_width, name, value, maximum, bar_color, back_color):
	float_value = float(value)
	float_max = float(maximum)
	bar_width = int((float_value/float_max)*total_width)

	#bar_width = int((float(value)/maximum) * total_width)

	libtcod.console_set_background_color(panel, back_color)
	libtcod.console_rect(panel, x, y, total_width, 1, False)

	libtcod.console_set_background_color(panel, bar_color)
	if bar_width > 0:
		libtcod.console_rect(panel, x, y, bar_width, 1, False)

	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))
Example #11
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.black)
    libtcod.console_print_center(panel, x + total_width / 2, y, libtcod.BKGND_NONE,
        name + ': ' + str(value) + '/' + str(maximum))
Example #12
0
def renderBar(x, y, total_width, name, value, maximum, barColor, backColor):
    #Renders a status bar, first we calculate the width of it
    bar_width = int(float(value) / maximum * total_width)

    #render the background
    libtcod.console_set_background_color(panel, backColor)
    libtcod.console_rect(panel, x, y, total_width, 1, False)

    #Now render the top of the bar
    libtcod.console_set_background_color(panel, barColor)
    if bar_width > 0:
        libtcod.console_rect(panel, x, y, bar_width, 1, False)

    #text to denote what the bar is of
    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))
Example #13
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)
Example #14
0
def render_bar(x, y, total_width, name, value, maximum, bar_color, back_color):
    #render a bar for tracking something. First comes width.
    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)

    #And some centered text with values for clarity
    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))
Example #15
0
def render_bar(x, y, total_width, name, value, maximum, bar_color, back_color):
    float_value = float(value)
    float_max = float(maximum)
    bar_width = int((float_value / float_max) * total_width)

    #bar_width = int((float(value)/maximum) * total_width)

    libtcod.console_set_background_color(panel, back_color)
    libtcod.console_rect(panel, x, y, total_width, 1, False)

    libtcod.console_set_background_color(panel, bar_color)
    if bar_width > 0:
        libtcod.console_rect(panel, x, y, bar_width, 1, False)

    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))
Example #16
0
def draw_blood():
	libtcod.console_set_background_color(0, libtcod.black)
	libtcod.console_clear(0)
	
	for (x, y), value in MAP.iteritems():
		if value != 0:
			right, left = MAP.get((x+1, y), 0) == 0, MAP.get((x-1,y), 0) == 0
			if right and not left:
				libtcod.console_set_back(0, x,  y, COLOR_LIGHTBLOOD, libtcod.BKGND_SET)
			
			elif left and not right:
				libtcod.console_set_back(0, x,  y, COLOR_SHADOWBLOOD, libtcod.BKGND_SET)
			
			else:
				libtcod.console_set_back(0, x,  y, COLOR_BLOOD, libtcod.BKGND_SET)

	libtcod.console_set_background_color(0, COLOR_BLOOD)
	libtcod.console_rect(0, 0, 0,  WIDTH, 5, False, libtcod.BKGND_SET)
Example #17
0
def renderBar(x, y, total_width, name, value, maximum, barColor, backColor):
    #Renders a status bar, first we calculate the width of it
    bar_width = int(float(value) / maximum * total_width)

    #render the background
    libtcod.console_set_background_color(panel, backColor)
    libtcod.console_rect(panel, x, y, total_width, 1, False)

    #Now render the top of the bar
    libtcod.console_set_background_color(panel, barColor)
    if bar_width > 0:
        libtcod.console_rect(panel, x, y, bar_width, 1, False)

    #text to denote what the bar is of
    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))
Example #18
0
def draw_map(player):
	libtcod.console_set_background_color(0, libtcod.black)
	libtcod.console_rect(0, 0, 0, 80, 40, True, libtcod.BKGND_SET)
	
	for x, y in player.fov.get_visible():
		player.memory.update(x, y)
	
	libtcod.console_blit(player.memory.console, 0, 0, 80, 40, 0, 0, 0)
	
	for feature in player.fov.get_visible_features():
		libtcod.console_put_char_ex(0, feature.x, feature.y, feature.symbol, feature.color_fore, feature.color_back)
	
	for item in player.fov.get_visible_items():
		libtcod.console_set_fore(0, item.x, item.y, item.color)
		libtcod.console_set_char(0, item.x, item.y, item.symbol)
	
	for actor in player.fov.get_visible_actors():
		libtcod.console_set_fore(0, actor.x, actor.y, actor.color)
		libtcod.console_set_char(0, actor.x, actor.y, actor.symbol)
Example #19
0
def render_bar(x, y, total_width, name, value, maximum, bar_color, back_color):
    global panel

    # 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))
Example #20
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()
Example #21
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)
Example #22
0
def set_full(x, y):
	if y > 5:
		MAP[x, y] = N_STATES - 1

def set_empty(x, y):
	if y > 5:
		MAP[x, y] = 0

if __name__ == '__main__':
	
	init_blood()
	
	libtcod.console_set_custom_font('courier12x12_aa_tc.png', libtcod.FONT_TYPE_GREYSCALE | libtcod.FONT_LAYOUT_TCOD)
	libtcod.console_init_root(WIDTH, HEIGHT, 'title screen sim', False)
	libtcod.sys_set_fps(60)
	libtcod.console_set_background_color(0, libtcod.black)
	
	while True:

		update()

		draw_blood()

		draw_title()

		libtcod.console_flush()

		key = libtcod.console_check_for_keypress()

		if key.vk == libtcod.KEY_ESCAPE:
			break
Example #23
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)
Example #24
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)
Example #25
0
 def put(self, x, y, ch, fg = 'white', bg = 'black'):
     libtcod.console_set_foreground_color( 0, self.colours[ fg ] )
     libtcod.console_set_background_color( 0, self.colours[ bg ] )
     libtcod.console_put_char( 0, x, y, ch, libtcod.BKGND_SET )
Example #26
0
 def clear(self):
     libtcod.console_set_foreground_color( 0, self.colours[ 'black' ] )
     libtcod.console_set_background_color( 0, self.colours[ 'black' ] )
     libtcod.console_clear(0)
Example #27
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)
Example #28
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, dungeon_level, stairs

    # 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)

    # dungeon level
    libtcod.console_print_left(panel, 1, 3, libtcod.BKGND_NONE, 'Dungeon level ' + str(dungeon_level))

    # 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)
Example #29
0
libtcod.console_set_custom_font('terminal8x8_gs_as.png', libtcod.FONT_TYPE_GREYSCALE | libtcod.FONT_LAYOUT_ASCII_INCOL)
libtcod.console_init_root(SCREEN_WIDTH, SCREEN_HEIGHT, 'RogueQuestAdventure')

map_con = libtcod.console_new(MAP_WIDTH, MAP_HEIGHT)
panel = libtcod.console_new(SCREEN_WIDTH, PANEL_HEIGHT)
game_over = libtcod.console_new(MAP_WIDTH, MAP_HEIGHT)
inv_con = libtcod.console_new(INVENTORY_WIDTH, MAP_HEIGHT)

inv_open = False
inventory = []
inv_select = 0

took_turn = False

libtcod.console_set_background_color(game_over, libtcod.black)
libtcod.console_clear(game_over)
libtcod.console_set_foreground_color(game_over, libtcod.white)
libtcod.console_print_center(game_over, MAP_WIDTH/2, MAP_HEIGHT/2, libtcod.BKGND_NONE, 'Game Over')

experience = 0
dungeon_level = 1

blotter = [[('You awaken in a mysterious dungeon.',libtcod.white)]]

def descend():
    global blotter
    global creatures
    global items
    global dungeon_level
Example #30
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)
Example #31
0
def new_game():
    global player_obj, current_map  # , level_roster

    # libtcod.console_clear(memory_console)

    libtcod.console_set_background_color(0, libtcod.black)
    libtcod.console_set_foreground_color(0, libtcod.white)

    libtcod.console_clear(0)

    if config.QUICK_START:
        name = "Test Player"

    else:
        name = ""

        while True:
            libtcod.console_clear(0)

            libtcod.console_print_left(
                0, 1, 1, libtcod.BKGND_NONE, "Enter your name (1-{} char):".format(MAX_NAME_LENGTH)
            )

            libtcod.console_print_left(0, 1, 3, libtcod.BKGND_NONE, name)

            if len(name) < MAX_NAME_LENGTH:
                libtcod.console_put_char_ex(0, 1 + len(name), 3, libtcod.CHAR_BLOCK1, libtcod.white, libtcod.black)

            libtcod.console_flush()

            key = libtcod.console_wait_for_keypress(True)

            if key.vk == libtcod.KEY_ESCAPE:
                raise SetState(start_menu())

            elif key.vk in [libtcod.KEY_ENTER, libtcod.KEY_KPENTER] and name:
                break

            elif key.vk == libtcod.KEY_BACKSPACE and name:
                name = name[:-1]

            elif chr(key.c) in VALID_NAME_CHARS and len(name) < MAX_NAME_LENGTH:
                name += chr(key.c)

    player_obj = Player(name)

    if config.DEBUG_ITEMS:
        player_obj.inventory.add(items.PotionDebugHeal())
        player_obj.inventory.add(items.ScrollDebugScrying())
        player_obj.inventory.add(items.ScrollDebugTeleport())

    knife = items.WeaponKnife()
    player_obj.inventory.add(knife)
    player_obj.mainhand = knife

    messages.set_player(player_obj)

    messages.Basic("Behold, <c=libtcod.red>brutality</c>!", symbol1=player_obj)
    messages.Basic("[?] to see controls.", symbol1="?")

    current_map = maps.TestMap()
    current_map.place_actor_random(player_obj)

    player_obj.memory = Memory(player_obj)

    # level_roster = [maps.MazeOfMeat, maps.MeatCaves, maps.Meatnasium] # temporary solution

    raise SetState(playing)
Example #32
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)
Example #33
0
    libtcod.console_init_root(width, height, "level generation tests", False)

    for generator, has_doors in (
        (premade_maze, False),
        (premade_caves, False),
        (premade_caves, True),
        (premade_loops, False),
        (premade_rooms, False),
        (premade_rooms, True),
        (premade_rooms_hallways, False),
        (premade_rooms_hallways, True),
        (premade_rooms_caves, False),
        (premade_rooms_caves, True),
    ):

        libtcod.console_set_background_color(0, libtcod.black)
        map = generator(width, height)

        if has_doors:
            for (x, y) in get_door_locations(map):
                if random.random() > 0.5:
                    map[x, y] = DOOR

        libtcod.console_clear(0)

        for (x, y), value in map.iteritems():
            if value == FILLED and all(map.get((x + dx, y + dy), FILLED) == FILLED for (dx, dy) in ADJACENT):
                continue
            libtcod.console_put_char_ex(0, x, y, *feature_key[value])

        libtcod.console_set_background_color(0, libtcod.darker_grey)
Example #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:
        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()
Example #35
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)