Ejemplo n.º 1
0
def render_all(con, panel, entities, player, game_map, fov_map, fov_recompute, message_log, screen_width, screen_height,
               bar_width, panel_height, panel_y, mouse, colors, game_state):

    if fov_recompute:
        for y in range(game_map.height):
            for x in range(game_map.width):
                visible = libtcod.map_is_in_fov(fov_map, x, y)
                wall = game_map.tiles[x][y].block_sight

                if visible:
                    if wall:
                        libtcod.console_put_char_ex(con, x, y, '#', colors.lgray(), colors.black())
                    else:
                        libtcod.console_put_char_ex(con, x, y, '+', colors.dgray(), colors.black())
                    game_map.tiles[x][y].explored = True

                elif game_map.tiles[x][y].explored:
                    if wall:
                        libtcod.console_put_char_ex(con, x, y, '#', colors.dgray(), colors.black())
                    else:
                        libtcod.console_put_char_ex(con, x, y, '+', colors.black(), colors.black())

    entities_in_render_order = sorted(entities, key=lambda x: x.render_order.value)

    for entity in entities_in_render_order:
        draw_entity(con, entity, fov_map, game_map)

    libtcod.console_blit(con, 0, 0, screen_width, screen_height, 0, 0, 0)

    libtcod.console_set_default_background(panel, colors.black())
    libtcod.console_clear(panel)

    y = 1
    for message in message_log.messages:
        libtcod.console_set_default_foreground(panel, message.color)
        libtcod.console_print_ex(panel, message_log.x, y, libtcod.BKGND_NONE, libtcod.LEFT, message.text)
        y += 1

    render_bar(panel, 1, 1, bar_width, 'HP', player.fighter.hp, player.fighter.max_hp,
               colors.red(), colors.dred(), colors.white())
    libtcod.console_print_ex(panel, 1, 3, libtcod.BKGND_NONE, libtcod.LEFT,
                             'Dungeon level: {0}'.format(game_map.dungeon_level))

    libtcod.console_set_default_foreground(panel, colors.lgray())
    libtcod.console_print_ex(panel, 1, 0, libtcod.BKGND_NONE, libtcod.LEFT,
                             get_names_under_mouse(mouse, entities, fov_map))

    libtcod.console_blit(panel, 0, 0, screen_width, panel_height, 0, 0, panel_y)
    
    if game_state in (GameStates.SHOW_INVENTORY, GameStates.DROP_INVENTORY):
        if game_state == GameStates.SHOW_INVENTORY:
            inventory_title = 'Press the key next to an item to use it, or Esc to cancel.\n'
        else:
            inventory_title = 'Press the key next to an item to drop it, or Esc to cancel.\n'

        inventory_menu(con, inventory_title, player, 50, screen_width, screen_height)
    elif game_state == GameStates.LEVEL_UP:
        level_up_menu(con, 'Level up! Choose a stat to raise:', player, 40, screen_width, screen_height)
    elif game_state == GameStates.CHARACTER_SCREEN:
        character_screen(player, 30, 18, screen_width, screen_height)
Ejemplo n.º 2
0
    def render_menus(self, player, game_state, world_map=None):
        if game_state in (GameStates.SHOW_INVENTORY,
                          GameStates.DROP_INVENTORY):
            if game_state == GameStates.SHOW_INVENTORY:
                inventory_title = menu_vars.inventory_show_title
            else:
                inventory_title = menu_vars.inventory_drop_title

            inventory_menu(inventory_title, menu_vars.inventory_width, player,
                           self)
        elif game_state == GameStates.LEVEL_UP:
            level_up_menu(menu_vars.level_up_title, menu_vars.level_up_width,
                          player, self)
        elif game_state == GameStates.CHARACTER_SCREEN:
            character_screen(player, menu_vars.character_screen_width,
                             menu_vars.character_screen_height, self)
        elif game_state == GameStates.SHOW_LOCATIONS:
            tile = world_map.tiles[player.x][player.y]
            locations_menu(menu_vars.location_list_title,
                           menu_vars.location_list_width, tile.locations, self)
        elif game_state == GameStates.EXPLORATION_SCREEN:
            tile = world_map.tiles[player.x][player.y]
            dx, dy = world_map.potential_move
            exploration_screen(player, menu_vars.exploration_screen_width,
                               menu_vars.exploration_screen_height, world_map,
                               (player.x + dx, player.y + dy), self)
Ejemplo n.º 3
0
def render_all(con, panel, entities, player, game_map, fov_map, fov_recompute, message_log, screen_width, screen_height, bar_width, panel_height, panel_y, mouse, colors, game_state):
	# Draw all the tiles in the game map
	if fov_recompute:
		for y in range(game_map.height):
			for x in range(game_map.width):
				visible = libtcod.map_is_in_fov(fov_map, x, y)
				wall = game_map.tiles[x][y].block_sight

				if visible:
					if wall:
						libtcod.console_set_char_background(con, x, y, colors.get('light_wall'), libtcod.BKGND_SET)
					else:
						libtcod.console_set_char_background(con, x, y, colors.get('light_ground'), libtcod.BKGND_SET)

					game_map.tiles[x][y].explored = True

				elif game_map.tiles[x][y].explored:
					if wall:
						libtcod.console_set_char_background(con, x, y, colors.get('dark_wall'), libtcod.BKGND_SET)
					else:
						libtcod.console_set_char_background(con, x, y, colors.get('dark_ground'), libtcod.BKGND_SET)   
	
	entities_in_render_order = sorted(entities, key=lambda x: x.render_order.value)
	# Draw all entities in the list
	for entity in entities_in_render_order:
		draw_entity(con, entity, fov_map, game_map)

	libtcod.console_blit(con, 0, 0, screen_width, screen_height, 0, 0, 0)

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

	#Print the game messages, one line at a time
	y = 1
	for message in message_log.messages:
		libtcod.console_set_default_foreground(panel, message.color)
		libtcod.console_print_ex(panel, message_log.x, y, libtcod.BKGND_NONE, libtcod.LEFT, message.text)
		y += 1

	render_bar(panel, 1, 1, bar_width, 'HP', player.fighter.hp, player.fighter.max_hp, libtcod.light_red, libtcod.darker_red)

	libtcod.console_print_ex(panel, 1, 3, libtcod.BKGND_NONE, libtcod.LEFT, 'Dungeon level: {0}'.format(game_map.dungeon_level))

	libtcod.console_set_default_foreground(panel, libtcod.light_gray)
	libtcod.console_print_ex(panel, 1, 0, libtcod.BKGND_NONE, libtcod.LEFT, get_names_under_mouse(mouse, entities, fov_map))
	libtcod.console_blit(panel, 0, 0, screen_width, panel_height, 0, 0, panel_y)

	if game_state in (GameStates.SHOW_INVENTORY, GameStates.DROP_INVENTORY):
		if game_state == GameStates.SHOW_INVENTORY:
			inventory_title = 'Press the key next to the item to use it, or Esc to cancel.\n'
		else:
			inventory_title = 'Press the key next to an item to drop it, or Esc to cancel.\n'

		inventory_menu(con, inventory_title, player.inventory, 50, screen_width, screen_height)

	elif game_state == GameStates.LEVEL_UP:
		level_up_menu(con, 'Level up! Choose a stat to raise:', player, 40, screen_width, screen_height)

	elif game_state == GameStates.CHARACTER_SCREEN:
		character_screen(player, 30, 10, screen_width, screen_height)
def render_all(con, panel, entities, player, game_map, fov_map, fov_recompute, message_log, screen_width, screen_height,  bar_width, panel_height, panel_y, mouse, colors, game_state):
	if fov_recompute:
		#Draw all tiles in the game map
		for x in range(game_map.width):
			for y in range(game_map.height):
				visible = libtcod.map_is_in_fov(fov_map, x, y)
				isWall = game_map.tiles[x][y].block_sight
				
				if visible:
					if isWall:
						libtcod.console_set_char_background(con, x, y, colors.get('light_wall'), libtcod.BKGND_SET)
					else:
						libtcod.console_set_char_background(con, x, y, colors.get('light_ground'), libtcod.BKGND_SET)
					game_map.tiles[x][y].explored = True
				elif game_map.tiles[x][y].explored:
					if isWall:
						libtcod.console_set_char_background(con, x, y, colors.get('dark_wall'), libtcod.BKGND_SET)
					else:
						libtcod.console_set_char_background(con, x, y, colors.get('dark_ground'), libtcod.BKGND_SET)
	
	entities_in_render_order = sorted(entities, key=lambda x: x.render_order.value)
	
	#Draws all entities in the list
	for entity in entities_in_render_order:
		draw_entity(con, entity, fov_map, game_map)
	
	libtcod.console_blit(con, 0, 0, screen_width, screen_height, 0, 0, 0)
	
	#Draw the information panel		
	libtcod.console_set_default_background(panel, libtcod.black)
	libtcod.console_clear(panel)
	
	y = 1
	for message in message_log.messages:
		libtcod.console_set_default_foreground(panel, message.color)
		libtcod.console_print_ex(panel, message_log.x, y, libtcod.BKGND_NONE, libtcod.LEFT, message.text)
		y += 1
		
	render_bar(panel, 1, 1, bar_width, 'HP', player.fighter.hp, player.fighter.max_hp, libtcod.light_red, libtcod.darker_red)
	
	libtcod.console_print_ex(panel, 1, 3, libtcod.BKGND_NONE, libtcod.LEFT, 'Dungeon Level: {0}'.format(game_map.dungeon_level)) 
	
	libtcod.console_set_default_foreground(panel, libtcod.light_gray)
	libtcod.console_print_ex(panel, 1, 0, libtcod.BKGND_NONE, libtcod.LEFT, get_names_under_mouse(mouse, entities, fov_map))
	
	libtcod.console_blit(panel, 0, 0, screen_width, panel_height, 0, 0, panel_y)
	
	if game_state in (GameStates.SHOW_INVENTORY, GameStates.DROP_INVENTORY):
		if game_state == GameStates.SHOW_INVENTORY:
			inventory_title = 'Press the key next to the item to use it, or esc to cancel\n'
		else:
			inventory_title = 'Press the key next to the item to drop it, or esc to cancel\n'
		inventory_menu(con, inventory_title, player, 50, screen_width, screen_height)
	
	elif game_state == GameStates.LEVEL_UP:
		level_up_menu(con, 'Level Up! Choose a state to raise:', player, 40, screen_width, screen_height)
		
	elif game_state == GameStates.CHARACTER_SCREEN:
		character_screen(player, 30, 10, screen_width, screen_height)
Ejemplo n.º 5
0
def render_all(con, panel, entities, player, game_map, fov_map, fov_recompute,
               message_log, screen_width, screen_height, bar_width, panel_y,
               colors, root, game_state):
    if fov_recompute:
        for y in range(game_map.height):
            for x in range(game_map.width):
                visible = tcod.map_is_in_fov(fov_map, x, y)
                wall = game_map.tiles[x][y].block_sight
                if visible:
                    if wall:
                        tcod.console_set_char_background(
                            con, x, y, colors.get('light_wall'),
                            tcod.BKGND_SET)
                    else:
                        tcod.console_set_char_background(
                            con, x, y, colors.get('light_ground'),
                            tcod.BKGND_SET)
                    game_map.tiles[x][y].explored = True
                elif game_map.tiles[x][y].explored:
                    if wall:
                        tcod.console_set_char_background(
                            con, x, y, colors.get('dark_wall'), tcod.BKGND_SET)
                    else:
                        tcod.console_set_char_background(
                            con, x, y, colors.get('dark_ground'),
                            tcod.BKGND_SET)
    entities_in_render_order = sorted(entities,
                                      key=lambda _: _.render_order.value)
    for entity in entities_in_render_order:
        draw_entity(con, entity, fov_map, game_map)
    con.blit(root, 0, 0, 0, 0, screen_width, screen_height)
    panel.default_bg = tcod.black
    panel.clear()
    # Print the game messages, one line at a time
    y = 1
    for message in message_log.messages:
        panel.default_fg = message.color
        tcod.console_print_ex(panel, message_log.x, y, tcod.BKGND_NONE,
                              tcod.LEFT, message.text)
        y += 1
    render_bar(panel, 1, 1, bar_width, 'HP', player.fighter.hp,
               player.fighter.max_hp, tcod.darker_red, tcod.darker_gray)
    tcod.console_print_ex(panel, 1, 3, tcod.BKGND_NONE, tcod.LEFT,
                          'Dungeon level: {0}'.format(game_map.dungeon_level))
    panel.blit(root, 0, panel_y, 0, 0, screen_width, screen_height)
    if game_state in (GameStates.SHOW_INVENTORY, GameStates.DROP_INVENTORY):
        if game_state == GameStates.SHOW_INVENTORY:
            inventory_title = 'Press the key next to an item to use it, or Esc to cancel.\n'
        else:
            inventory_title = 'Press the key next to an item to drop it, or Esc to cancel.\n'
        inventory_menu(con, inventory_title, player.inventory, 50,
                       screen_width, screen_height, root)
    elif game_state == GameStates.CHARACTER_SCREEN:
        character_screen(player, 30, 10, screen_width, screen_height)
Ejemplo n.º 6
0
def render_menu_console(game_state, player, quest_request=None, exclude=[]):
    if game_state == GameStates.GAME_PAUSED:
        return game_paused()
    elif game_state == GameStates.GAME_OVER:
        return game_over()
    elif game_state == GameStates.GAME_COMPLETE:
        return game_completed()
    elif game_state == GameStates.CHARACTER_SCREEN:
        return character_screen(player)
    elif game_state in INVENTORY_STATES:
        if game_state == GameStates.INVENTORY_USE:
            inventory_title = 'Press the key next to an item to use it, or Esc to cancel.\n'
        elif game_state == GameStates.INVENTORY_EXAMINE:
            inventory_title = 'Press the key next to an item to examine it, or Esc to cancel.\n'
        elif game_state == GameStates.INVENTORY_DROP:
            inventory_title = 'Press the key next to an item to drop it, or Esc to cancel.\n'
        elif game_state == GameStates.INVENTORY_SELECT:
            inventory_title = 'Press the key next to an item to identify it, or Esc to cancel.\n'
        else:
            inventory_title = 'Esc to cancel.\n'

        return inventory_menu(inventory_title, player, exclude)
    elif game_state == GameStates.QUEST_ONBOARDING:
        return quest_menu(quest_request)
    elif game_state == GameStates.QUEST_LIST:
        return quest_list_menu(player)
    elif game_state == GameStates.LEVEL_UP:
        return level_up_menu(player)
Ejemplo n.º 7
0
def render_all(con, panel, entities, players, active_player, game_map, fov_recompute, message_log, screen_width, screen_height, bar_width,
					panel_height, panel_y, mouse, colors, game_state):
	if fov_recompute:
		render_map(con, players, game_map, screen_width, screen_height)
						
	# Draw all entities in the list
	render_entities(con, entities, players, game_map, screen_width, screen_height)

	# Render bars
	libtcod.console_set_default_background(panel, libtcod.black)
	libtcod.console_clear(panel)

	# Print the game messages, one line at a time
	y = 1
	for message in message_log.messages:
		libtcod.console_set_default_foreground(panel, message.color)
		libtcod.console_print_ex(panel, message_log.x, y, libtcod.BKGND_NONE, libtcod.LEFT, message.text)
		y +=1

	# Render HP and dungeon level
	for i in range(len(players)):
		render_bar(panel, 2, i+2, bar_width-1, 'HP', players[i].fighter.hp, players[i].fighter.max_hp,
				libtcod.red, libtcod.darker_red)
	# Print > next to active player
	libtcod.console_print_ex(panel, 1, active_player + 2, libtcod.BKGND_NONE, libtcod.LEFT, '>')
	libtcod.console_print_ex(panel, 1, 1, libtcod.BKGND_NONE, libtcod.LEFT,
							'Dungeon level: {0}'.format(game_map.dungeon_level))

	libtcod.console_set_default_foreground(panel, libtcod.light_gray)
	libtcod.console_print_ex(panel, 1, 0, libtcod.BKGND_NONE, libtcod.LEFT,
							get_names_under_mouse(mouse, entities, game_map, players))

	libtcod.console_blit(panel, 0, 0, screen_width, panel_height, 0, 0, panel_y)

	if game_state in (GameStates.SHOW_INVENTORY, GameStates.DROP_INVENTORY):
		if game_state == GameStates.SHOW_INVENTORY:
			inventory_title = 'Press the key next to an item to use it, or Esc to cancel.\n'
		else:
			inventory_title = 'Press the key next to an item to drop it, or Esc to cancel.\n'
		
		inventory_menu(con, inventory_title, players[active_player], 50, screen_width, screen_height)

	elif game_state == GameStates.LEVEL_UP:
		level_up_menu(con, 'Level up! Choose a stat to raise:', players[active_player], 40, screen_width, screen_height)

	elif game_state == GameStates.CHARACTER_SCREEN:
		character_screen(players[active_player], 30, 10, screen_width, screen_height)
def render_all(con, panel, entities, player, game_map, fov_map, fov_recompute,
               message_log, screen_width, screen_height, bar_width,
               panel_height, panel_y, mouse, colors, game_state):
    wall_tile = 256
    floor_tile = 257
    player_tile = 258
    orc_tile = 259
    troll_tile = 260
    scroll_tile = 261
    healingpotion_tile = 262
    sword_tile = 263
    shield_tile = 264
    stairsdown_tile = 265
    dagger_tile = 266

    if fov_recompute:
        # Draw all the tiles in the game map
        for y in range(game_map.height):
            for x in range(game_map.width):
                visible = libtcod.map_is_in_fov(fov_map, x, y)
                wall = game_map.tiles[x][y].block_sight

                if visible:
                    if wall:
                        libtcod.console_put_char_ex(con, x, y, wall_tile,
                                                    libtcod.white,
                                                    libtcod.black)
                    else:
                        libtcod.console_put_char_ex(con, x, y, floor_tile,
                                                    libtcod.white,
                                                    libtcod.black)

                    game_map.tiles[x][y].explored = True
                elif game_map.tiles[x][y].explored:
                    if wall:
                        libtcod.console_put_char_ex(con, x, y, wall_tile,
                                                    libtcod.grey,
                                                    libtcod.black)
                    else:
                        libtcod.console_put_char_ex(con, x, y, floor_tile,
                                                    libtcod.grey,
                                                    libtcod.black)

    entities_in_render_order = sorted(entities,
                                      key=lambda x: x.render_order.value)

    # Draw all entities in the list
    for entity in entities_in_render_order:
        draw_entity(con, entity, fov_map, game_map)

    libtcod.console_blit(con, 0, 0, screen_width, screen_height, 0, 0, 0)

    if game_state in (GameStates.SHOW_INVENTORY, GameStates.DROP_INVENTORY):
        if game_state == GameStates.SHOW_INVENTORY:
            inventory_title = 'Press the key next to an item to use it, or Esc to cancel.\n'
        else:
            inventory_title = 'Press the key next to an item to drop it, or Esc to cancel.\n'

        inventory_menu(con, inventory_title, player, 50, screen_width,
                       screen_height)

    elif game_state == GameStates.LEVEL_UP:
        level_up_menu(con, 'Level up! Choose a stat to raise:', player, 40,
                      screen_width, screen_height)

    elif game_state == GameStates.CHARACTER_SCREEN:
        character_screen(player, 30, 10, screen_width, screen_height)

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

    # Print the game messages, one line at a time
    y = 1
    for message in message_log.messages:
        libtcod.console_set_default_foreground(panel, message.color)
        libtcod.console_print_ex(panel, message_log.x, y, libtcod.BKGND_NONE,
                                 libtcod.LEFT, message.text)
        y += 1

    render_bar(panel, 1, 1, bar_width, 'HP', player.fighter.hp,
               player.fighter.max_hp, libtcod.light_red, libtcod.darker_red)
    libtcod.console_print_ex(
        panel, 1, 3, libtcod.BKGND_NONE, libtcod.LEFT,
        'Dungeon level: {0}'.format(game_map.dungeon_level))

    libtcod.console_set_default_foreground(panel, libtcod.light_gray)
    libtcod.console_print_ex(panel, 1, 0, libtcod.BKGND_NONE, libtcod.LEFT,
                             get_names_under_mouse(mouse, entities, fov_map))

    libtcod.console_blit(panel, 0, 0, screen_width, panel_height, 0, 0,
                         panel_y)
Ejemplo n.º 9
0
def render_all(con, panel, entities, player, game_map, fov_map, fov_recompute,
               message_log, screen_width, screen_height, bar_width,
               panel_height, panel_y, mouse, colors, game_state, camera):
    if fov_recompute:
        libtcod.console_clear(con)
        # Draw all the tiles in the game map
        for y in range(game_map.height):
            for x in range(game_map.width):
                #camera code
                x_in_camera, y_in_camera = x + camera.x, y + camera.y  #camera.apply(x, y)

                visible = libtcod.map_is_in_fov(fov_map, x, y)
                wall = game_map.tiles[x][y].block_sight

                #시야에 따른 벽과 바닥 색깔/캐릭터 렌더링
                if visible:
                    game_map.tiles[x][y].explored = True
                    if wall:  #피 묻었는지 안 묻었는지 체크
                        if game_map.tiles[x][y].bloodied:
                            #libtcod.console_put_char_ex(con, x, y,'▒',libtcod.red, colors.get('dark_wall'))
                            libtcod.console_put_char_ex(
                                con, x_in_camera, y_in_camera, '▒',
                                libtcod.red, colors.get('dark_wall'))

                        else:
                            libtcod.console_put_char_ex(
                                con, x_in_camera, y_in_camera, '▒',
                                libtcod.white, colors.get('dark_wall'))

                    else:
                        if game_map.tiles[x][y].bloodied:
                            libtcod.console_put_char_ex(
                                con, x_in_camera, y_in_camera, '.',
                                libtcod.red, colors.get('light_ground'))
                        else:
                            libtcod.console_put_char_ex(
                                con, x_in_camera, y_in_camera, '.',
                                libtcod.white, colors.get('light_ground'))
                            #libtcod.console_set_char_background(con, x, y, colors.get('light_ground'), libtcod.BKGND_SET)

                elif game_map.tiles[x][y].explored:
                    if wall:
                        libtcod.console_put_char_ex(con, x_in_camera,
                                                    y_in_camera, '▒',
                                                    libtcod.dark_grey,
                                                    colors.get('dark_ground'))
                        #libtcod.console_put_char_ex(con, x, y, 176, colors.get('light_wall'), colors.get('dark_wall'))
                    else:
                        libtcod.console_put_char_ex(con, x_in_camera,
                                                    y_in_camera, ' ',
                                                    libtcod.dark_grey,
                                                    colors.get('dark_ground'))
                        #libtcod.console_set_char_background(con, x, y, colors.get('dark_ground'), libtcod.BKGND_SET)
                else:
                    libtcod.console_set_char_background(
                        con, x_in_camera, y_in_camera, libtcod.Color(0, 0, 0),
                        libtcod.BKGND_SET)
    entities_in_render_order = sorted(entities,
                                      key=lambda x: x.render_order.value)
    #game_map.tiles[x][y].explored |= self.fov

    # Draw all entities in the list
    for entity in entities_in_render_order:
        draw_entity(con, entity, fov_map, game_map, camera)

    #draw hp?
    libtcod.console_set_default_foreground(panel, libtcod.white)
    #libtcod.console_set_default_background(con, libtcod.Color(0, 63, 0))
    libtcod.console_print_ex(
        panel, 1, screen_height - 2, libtcod.BKGND_NONE, libtcod.LEFT,
        'HP: {0:02}/{1:02}'.format(player.fighter.hp, player.fighter.max_hp))

    libtcod.console_blit(con, 0, 0, screen_width, screen_height, 0, 0, 0)

    if game_state in (GameStates.SHOW_INVENTORY, GameStates.DROP_INVENTORY):
        if game_state == GameStates.SHOW_INVENTORY:
            inventory_title = 'Press the key next to an item to use it, or Esc to cancel.\n'
        else:
            inventory_title = 'Press the key next to an item to drop it, or Esc to cancel.\n'

        inventory_menu(con, inventory_title, player, 50, screen_width,
                       screen_height)

    elif game_state == GameStates.LEVEL_UP:
        level_up_menu(con, 'Level up! Choose a stat to raise:', player, 40,
                      screen_width, screen_height)

    elif game_state == GameStates.CHARACTER_SCREEN:
        character_screen(player, 30, 10, screen_width, screen_height)

    #libtcod.console_set_default_background(panel, libtcod.black)
    libtcod.console_set_default_background(panel, libtcod.Color(0, 20, 30))
    libtcod.console_clear(panel)

    # Print the game messages, one line at a time
    y = 1
    for message in message_log.messages:
        libtcod.console_set_default_foreground(panel, message.color)
        libtcod.console_print_ex(panel, message_log.x, y, libtcod.BKGND_NONE,
                                 libtcod.LEFT, message.text)
        y += 1

    render_bar(panel, 1, 1, bar_width, 'HP', player.fighter.hp,
               player.fighter.max_hp, libtcod.light_red, libtcod.darker_red)

    libtcod.console_print_ex(
        panel, 1, 3, libtcod.BKGND_NONE, libtcod.LEFT,
        'Dungeon level: {0}'.format(game_map.dungeon_level))

    #libtcod.console_clear(animation_con)

    libtcod.console_set_default_foreground(panel, libtcod.light_gray)

    libtcod.console_print_ex(
        panel, 1, 0, libtcod.BKGND_NONE, libtcod.LEFT,
        get_names_under_mouse(con, mouse, camera, entities, fov_map))
    #libtcod.console_print_rect(con, mouse.cx, mouse.cy,20,1,get_names_under_mouse(con, mouse, camera, entities, fov_map))

    libtcod.console_blit(panel, 0, 0, screen_width, panel_height, 0, 0,
                         panel_y)
Ejemplo n.º 10
0
def render_all(con, panel, entities, player, game_map, fov_map, fov_recompute,
               message_log, screen_width, screen_height, bar_width,
               panel_height, panel_y, mouse, colors, game_state, camera):
    # Draw the tiles in the given map
    if fov_recompute:
        libtcod.console_clear(
            con
        )  # This was required to get screen scrolling working. There may be a more efficient way to update the screen but I can't think of one.
        for y in range(game_map.height):
            for x in range(game_map.width):
                visible = libtcod.map_is_in_fov(fov_map, x, y)
                wall = game_map.tiles[x][y].block_sight
                x_in_camera, y_in_camera = camera.apply(x, y)

                if visible:
                    if wall:
                        libtcod.console_set_char_background(
                            con, x_in_camera, y_in_camera,
                            colors.get('light_wall'), libtcod.BKGND_SET)
                    else:
                        libtcod.console_set_char_background(
                            con, x_in_camera, y_in_camera,
                            colors.get('light_ground'), libtcod.BKGND_SET)

                    game_map.tiles[x][y].explored = True
                elif game_map.tiles[x][y].explored:
                    if wall:
                        libtcod.console_set_char_background(
                            con, x_in_camera, y_in_camera,
                            colors.get('dark_wall'), libtcod.BKGND_SET)
                    else:
                        libtcod.console_set_char_background(
                            con, x_in_camera, y_in_camera,
                            colors.get('dark_ground'), libtcod.BKGND_SET)

    entities_in_render_order = sorted(entities,
                                      key=lambda x: x.render_order.value)

    for entity in entities_in_render_order:
        draw_entity(con, entity, fov_map, game_map, camera)

    libtcod.console_blit(con, 0, 0, screen_width, screen_height, 0, 0, 0)

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

    y = 1
    for message in message_log.visible:
        libtcod.console_set_default_foreground(panel, message.color)
        libtcod.console_print_ex(panel, message_log.x, y, libtcod.BKGND_NONE,
                                 libtcod.LEFT, message.text)
        y += 1

    render_bar(panel, 1, 1, bar_width, 'HP', player.fighter.hp,
               player.fighter.max_hp, libtcod.light_red, libtcod.darker_red)
    libtcod.console_print_ex(
        panel, 1, 3, libtcod.BKGND_NONE, libtcod.LEFT,
        'Dungeon level: {0}'.format(game_map.dungeon_level))

    libtcod.console_set_default_foreground(panel, libtcod.light_gray)
    libtcod.console_print_ex(panel, 1, 0, libtcod.BKGND_NONE, libtcod.LEFT,
                             get_names_under_mouse(mouse, entities, fov_map))

    libtcod.console_blit(panel, 0, 0, screen_width, panel_height, 0, 0,
                         panel_y)

    if game_state in (GameStates.SHOW_INVENTORY, GameStates.DROP_INVENTORY):
        if game_state == GameStates.SHOW_INVENTORY:
            inventory_title = 'Press the key next to an item to use it. Press Esc to cancel.\n'
        else:
            inventory_title = 'Press the key next to an item to drop it. Press Esc to cancel.\n'

        inventory_menu(con, inventory_title, player, 50, screen_width,
                       screen_height)

    elif game_state == GameStates.LEVEL_UP:
        level_up_menu(con, 'Level up! Choose a stat to increase:', player, 40,
                      screen_width, screen_height)

    elif game_state == GameStates.CHARACTER_SCREEN:
        character_screen(
            player, 30, 10, screen_width,
            screen_height)  # TODO: More constants all over the place here

    elif game_state == GameStates.FULLSCREEN_CONSOLE:
        window = libtcod.console_new(screen_width, screen_height)

        z = 1
        for message in message_log.fullscreen_visible:
            libtcod.console_set_default_foreground(window, message.color)
            libtcod.console_print_ex(window, 0, z, libtcod.BKGND_NONE,
                                     libtcod.LEFT, message.text)
            z += 1

        libtcod.console_blit(window, 0, 0, screen_width, screen_height, 0, 0,
                             0)
Ejemplo n.º 11
0
def render_all(con, panel, entities, player, game_map, fov_map, fov_recompute,
               message_log, screen_width, screen_height, bar_width,
               panel_height, panel_y, mouse, colors, game_state):
    if fov_recompute:
        # Draw all the tiles in the game map
        for y in range(game_map.height):
            for x in range(game_map.width):
                visible = libtcod.map_is_in_fov(fov_map, x, y)
                wall = game_map.tiles[x][y].block_sight

                if visible:
                    if wall:
                        libtcod.console_set_char_background(
                            con, x, y, colors['light_wall'], libtcod.BKGND_SET)
                    else:
                        libtcod.console_set_char_background(
                            con, x, y, colors['light_ground'],
                            libtcod.BKGND_SET)

                    game_map.tiles[x][y].explored = True

                elif game_map.tiles[x][y].explored:
                    if wall:
                        libtcod.console_set_char_background(
                            con, x, y, colors['dark_wall'], libtcod.BKGND_SET)
                    else:
                        libtcod.console_set_char_background(
                            con, x, y, colors['dark_ground'],
                            libtcod.BKGND_SET)

    entities_in_render_order = sorted(entities,
                                      key=lambda x: x.render_order.value)

    # Draw all entities in the list
    for entity in entities_in_render_order:
        draw_entity(con, entity, fov_map, game_map)

    libtcod.console_blit(con, 0, 0, screen_width, screen_height, 0, 0, 0)

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

    # Print the game messages, one line at a time
    y = 1
    for message in message_log.messages:
        libtcod.console_set_default_foreground(panel, message.color)
        libtcod.console_print_ex(panel, message_log.x, y, libtcod.BKGND_NONE,
                                 libtcod.LEFT, message.text)
        y += 1

    render_bar(panel, 1, 1, bar_width, 'HP', player.fighter.hp,
               player.fighter.max_hp, libtcod.light_red, libtcod.darker_red)
    libtcod.console_print_ex(
        panel, 1, 3, libtcod.BKGND_NONE, libtcod.LEFT,
        'Dungeon level: {0}'.format(game_map.dungeon_level))

    libtcod.console_set_default_foreground(panel, libtcod.light_gray)
    libtcod.console_print_ex(panel, 1, 0, libtcod.BKGND_NONE, libtcod.LEFT,
                             get_names_under_mouse(mouse, entities, fov_map))

    libtcod.console_blit(panel, 0, 0, screen_width, panel_height, 0, 0,
                         panel_y)

    if game_state in (GameStates.SHOW_INVENTORY, GameStates.DROP_INVENTORY):
        if game_state == GameStates.SHOW_INVENTORY:
            inventory_title = 'Press the key next to an item to use it, or Esc to cancel.\n'
        else:
            inventory_title = 'Press the key next to an item to drop it, or Esc to cancel.\n'

        inventory_menu(con, inventory_title, player, 50, screen_width,
                       screen_height)

    elif game_state == GameStates.LEVEL_UP:
        level_up_menu(con, 'Level up! Choose a stat to raise:', player, 40,
                      screen_width, screen_height)

    elif game_state == GameStates.CHARACTER_SCREEN:
        character_screen(player, 30, 10, screen_width, screen_height)

    elif game_state == GameStates.CHARACTER_CREATION:
        character_creation_menu(con, 'Brave peasant! What is your race!:',
                                player, 40, screen_width, screen_height)

    elif game_state == GameStates.GENDER_SELECTION:
        gender_selection_menu(con, 'Brave peasant! What is your gender!:',
                              player, 40, screen_width, screen_height)

    elif game_state == GameStates.JOB_SELECTION:
        job_selection_menu(
            con, 'Congratulations! You have gained a level! Pick a job!:',
            player, 40, screen_width, screen_height)

    elif game_state == GameStates.SKILL_SELECTION:
        job_selection_menu(
            con, 'You have gained a skill! Which button should it go in?:',
            player, 40, screen_width, screen_height)
Ejemplo n.º 12
0
def render_all(
    entities: List[Entity],
    player: Entity,
    game_map: GameMap,
    fov_map: tcod.map.Map,
    camera: Camera,
    message_log: MessageLog,
    ui_panel: Rect,
    bar_width: int,
    mouse_position: Point,
    game_state: GameStates,
):

    # Draw the map
    blt.clear()
    # blt.clear_area(x=0, y=0, w=camera.width, h=camera.height)
    blt.layer(0)
    game_map.render(fov_map=fov_map, camera=camera)

    # Draw all entities in the list
    # entities_in_render_order = sorted(entities, key=lambda x: x.render_order.value)
    for entity in entities:
        if camera.in_bounds(entity.position):
            if fov_map.fov[entity.x, entity.y] or (
                    entity.stairs and game_map.is_explored(entity.position)):
                point = entity.position - camera.top_left
                entity.draw(point)

    blt.layer(0)
    render_bar(
        x=ui_panel.x,
        y=ui_panel.y,
        total_width=bar_width,
        name="HP",
        value=player.fighter.hp,
        maximum=player.fighter.max_hp,
        bar_color=Colors.RED,
        back_color=Colors.DARK_RED,
    )

    blt.printf(ui_panel.x,
               ui_panel.y + 2,
               s=f"Dungeon level: {game_map.dungeon_level}")

    names = get_names_under_mouse(mouse_position=mouse_position,
                                  entities=entities,
                                  fov_map=fov_map,
                                  camera=camera)
    color = blt.color_from_argb(*Colors.LIGHT_GRAY.argb)
    blt.printf(ui_panel.x, ui_panel.y + 4, s=f"[color={color}]{names}")

    for i, message in enumerate(message_log.messages, 0):
        color = blt.color_from_argb(*message.color.argb)
        blt.printf(
            x=message_log.x,
            y=ui_panel.y + (i * 2),
            s=f"[color={color}]{message.text}",
        )

    fg_color = blt.color_from_argb(*Colors.RED.argb)
    bk_color = blt.color_from_argb(*Colors.YELLOW.argb)
    blt.printf(
        camera.width * 2 + 2, 4,
        f"[color={fg_color}]A[/color][+][color={bk_color}][U+2588][/color]")
    # map_point = Point(x=abs(mouse_position.x - camera.center.x), y=abs(mouse_position.y - camera.center.y))
    # blt.printf(camera.width * 2 + 2, 6, f"Map point: {map_point}")
    # blt.printf((camera.width + 1) * 2, 8, f"Player position: {player.position}")

    # blt.printf(ui_panel.x + 1, ui_panel.y + 6, "This is a test!", blt.TK_ALIGN_CENTER)

    if game_state in (GameStates.SHOW_INVENTORY, GameStates.DROP_INVENTORY):
        if game_state == GameStates.SHOW_INVENTORY:
            inventory_title = (
                "Press the key next to an item to use it, or Esc to cancel. \n"
            )
        else:
            inventory_title = (
                "Press the key next to an item to drop it, or Esc to cancel. \n"
            )
        inventory_menu(
            camera=camera,
            header=inventory_title,
            player=player,
            inventory_width=50,
        )

    elif game_state == GameStates.LEVEL_UP:
        level_up_menu(header="Level up! Choose a stat to raise:",
                      player=player,
                      menu_width=camera.width,
                      screen_width=camera.width,
                      screen_height=camera.height)

    elif game_state == GameStates.CHARACTER_SCREEN:
        character_screen(player,
                         30,
                         10,
                         screen_width=camera.width,
                         screen_height=camera.height)

    blt.refresh()
Ejemplo n.º 13
0
def render_all(con, panel, entities, player, game_map, fov_map, fov_recompute,
               screen_width, screen_height, message_log, bar_width,
               panel_height, panel_y, mouse, colors, game_state):
    """Renders the map according to the FOV map, then draws all passed entities"""
    if fov_recompute:
        for y in range(game_map.height):
            for x in range(game_map.width):
                visible = libtcod.map_is_in_fov(fov_map, x, y)
                wall = game_map.tiles[x][y].block_sight

                if visible:
                    if wall:
                        libtcod.console_set_char_background(
                            con, x, y, colors.get('light_wall'),
                            libtcod.BKGND_SET)
                    else:
                        libtcod.console_set_char_background(
                            con, x, y, colors.get('light_ground'),
                            libtcod.BKGND_SET)

                    game_map.tiles[x][y].explored = True

                elif game_map.tiles[x][
                        y].explored:  # Draws the map for the player (doesn't keep entities lit)
                    if wall:
                        libtcod.console_set_char_background(
                            con, x, y, colors.get('dark_wall'),
                            libtcod.BKGND_SET)
                    else:
                        libtcod.console_set_char_background(
                            con, x, y, colors.get('dark_ground'),
                            libtcod.BKGND_SET)

    # Draw all entity objects in the 'entities' list, in render order
    entities_in_render_order = sorted(entities,
                                      key=lambda x: x.render_order.value)
    for entity in entities_in_render_order:
        draw_entity(con, entity, fov_map, game_map)

    libtcod.console_blit(con, 0, 0, screen_width, screen_height, 0, 0, 0)

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

    # Print the game messages, line by line
    y = 1
    for message in message_log.messages:
        libtcod.console_set_default_foreground(panel, message.color)
        libtcod.console_print_ex(panel, message_log.x, y, libtcod.BKGND_NONE,
                                 libtcod.LEFT, message.text)
        y += 1

    # Health Bar and Dungeon Level
    render_bar(panel, 1, 1, bar_width, 'HP', player.fighter.hp,
               player.fighter.max_hp, libtcod.light_red, libtcod.darker_red)
    libtcod.console_print_ex(
        panel, 1, 3, libtcod.BKGND_NONE, libtcod.LEFT,
        'Dungeon level: {}'.format(game_map.dungeon_level))

    # Information about an entity under the mouse cursor
    libtcod.console_set_default_foreground(panel, libtcod.light_gray)
    libtcod.console_print_ex(panel, 1, 0, libtcod.BKGND_NONE, libtcod.LEFT,
                             get_names_under_mouse(mouse, entities, fov_map))

    libtcod.console_blit(panel, 0, 0, screen_width, panel_height, 0, 0,
                         panel_y)

    # Inventory Menu
    if game_state in (GameStates.SHOW_INVENTORY, GameStates.DROP_INVENTORY):
        if game_state == GameStates.SHOW_INVENTORY:
            inventory_title = "Press the key next to an item to use it, or ESC to close.\n"
        else:
            inventory_title = "Press the key next to an item to drop it, or ESC to close.\n"

        inventory_menu(con, inventory_title, player, 50, screen_width,
                       screen_height)

    # Level Up Menu
    elif game_state == GameStates.LEVEL_UP:
        level_up_menu(con, "Level up! Choose a stat to raise:", player, 40,
                      screen_width, screen_height)

    # Character Screen
    elif game_state == GameStates.CHARACTER_SCREEN:
        character_screen(player, 30, 10, screen_width, screen_height)
Ejemplo n.º 14
0
def render_all(con, panel, entities, player, game_map, fov_map, fov_recompute,
               message_log, screen_width, screen_height, bar_width,
               panel_height, panel_y, mouse, colors, game_state, graphics):
    """
    Affiche les pièces, les entites, les menus, et tous les éléments du jeu

    Parametres:
    ----------
    con : tcod.console

    panel : tcod.console

    entities : list

    player : Entity

    game_map : GameMap

    fov_map : tcod.map

    fov_recompute : bool

    message_log : MessageLog

    screen_width : int

    screen_height : int

    bar_width : int

    panel_heidght : int

    panel_y : int

    mouse : tcod.mouse

    colors : tcod.colors
        Désormais non utilisé

    game_state : int

    graphics : dict


    Renvoi:
    -------
    Aucun

    """
    if fov_recompute:
        for y in range(game_map.height):
            for x in range(game_map.width):
                visible = libtcod.map_is_in_fov(fov_map, x, y)
                wall = game_map.tiles[x][y].block_sight
                if visible:
                    if wall:
                        libtcod.console_put_char_ex(con, x, y,
                                                    graphics.get('wall'),
                                                    libtcod.white,
                                                    libtcod.black)
                    else:
                        libtcod.console_put_char_ex(con, x, y,
                                                    graphics.get('floor'),
                                                    libtcod.white,
                                                    libtcod.black)
                    game_map.tiles[x][y].explored = True
                elif game_map.tiles[x][y].explored:
                    if wall:
                        libtcod.console_put_char_ex(con, x, y,
                                                    graphics.get('wall'),
                                                    libtcod.light_grey,
                                                    libtcod.black)
                    else:
                        libtcod.console_put_char_ex(con, x, y,
                                                    graphics.get('floor'),
                                                    libtcod.light_grey,
                                                    libtcod.black)
    entities_in_render_order = sorted(entities,
                                      key=lambda x: x.render_order.value)

    for entity in entities_in_render_order:
        draw_entity(con, entity, fov_map, game_map)
        if entity.ai:
            if entity.ai.ai_name == 'Boss':
                if entity.ai.aoeing:
                    if entity.ai.turn % 10 == 0:
                        color = libtcod.lightest_red
                    elif entity.ai.turn % 10 == 1:
                        color = libtcod.lighter_red
                    elif entity.ai.turn % 10 == 2:
                        color = libtcod.light_red
                    elif entity.ai.turn % 10 == 3:
                        color = libtcod.red
                    radius = entity.ai.radius
                    for x in range(entity.x - radius, entity.x + radius + 1):
                        for y in range(entity.y - radius,
                                       entity.y + radius + 1):
                            if ((x - entity.x)**2 +
                                (y - entity.y)**2)**0.5 <= radius:
                                libtcod.console_set_char_foreground(
                                    con, x, y, color)

    libtcod.console_blit(con, 0, 0, screen_width, screen_height, 0, 0, 0)
    libtcod.console_set_default_background(panel, libtcod.black)
    libtcod.console_clear(panel)

    y = 1
    for message in message_log.messages:
        libtcod.console_set_default_foreground(panel, message.color)
        libtcod.console_print_ex(panel, message_log.x, y, libtcod.BKGND_NONE,
                                 libtcod.LEFT, message.text)
        y += 1

    render_bar(panel, 1, 1, bar_width, 'HP', player.fighter.hp,
               player.fighter.max_hp, libtcod.light_red, libtcod.darker_red)
    libtcod.console_print_ex(
        panel, 1, 2, libtcod.BKGND_NONE, libtcod.LEFT,
        'Salle : {0} - LVL : {1}'.format(game_map.dungeon_level,
                                         player.level.current_level))
    boss_bar = False
    for entity in entities:
        if entity.name == 'Boss':
            boss_bar = True
            boss = entity.fighter
    if boss_bar:
        render_bar(panel, 1, 3, bar_width, 'Boss HP', boss.hp, boss.max_hp,
                   libtcod.orange, libtcod.darker_orange)
    else:
        render_bar(panel, 1, 3, bar_width, 'XP', player.level.current_xp,
                   player.level.experience_to_next_level, libtcod.light_purple,
                   libtcod.darker_purple)
    libtcod.console_print_ex(
        panel, 1, 4, libtcod.BKGND_NONE, libtcod.LEFT,
        'ATQ : {0} - DEF : {1}'.format(player.fighter.power,
                                       player.fighter.defense))

    libtcod.console_set_default_foreground(panel, libtcod.light_gray)
    libtcod.console_print_ex(panel, 1, 0, libtcod.BKGND_NONE, libtcod.LEFT,
                             get_names_under_mouse(mouse, entities, fov_map))
    libtcod.console_blit(panel, 0, 0, screen_width, panel_height, 0, 0,
                         panel_y)
    if game_state in (GameStates.SHOW_INVENTORY, GameStates.DROP_INVENTORY):
        if game_state == GameStates.SHOW_INVENTORY:
            inventory_title = 'Echap pour quitter, A/B/C... pour utiliser.\n'
        else:
            inventory_title = 'Echap pour quitter, A/B/C... pour lacher\n'
        inventory_menu(con, inventory_title, player, 50, screen_width,
                       screen_height)
    elif game_state == GameStates.LEVEL_UP:
        level_up_menu(con, 'Level up, choisis une amelioration :', player, 40,
                      screen_width, screen_height)
    elif game_state == GameStates.CHARACTER_SCREEN:
        character_screen(player, 30, 10, screen_width, screen_height)
Ejemplo n.º 15
0
def render_all(con, panel, entities, player, game_map, fov_map, fov_recompute,
               message_log, screen_width, screen_height, bar_width,
               panel_height, panel_y, mouse, colors, game_state):
    # Recompute Field of View if necessary
    if fov_recompute:
        for y in range(game_map.height):
            for x in range(game_map.width):
                visible = libtcod.map_is_in_fov(fov_map, x, y)
                wall = game_map.tiles[x][y].block_sight

                if visible:
                    if wall:
                        libtcod.console_set_char_background(
                            con, x, y, colors.get("light_wall"),
                            libtcod.BKGND_SET)
                    else:
                        libtcod.console_set_char_background(
                            con, x, y, colors.get("light_ground"),
                            libtcod.BKGND_SET)
                    game_map.tiles[x][y].explored = True

                elif game_map.tiles[x][y].explored:
                    if wall:
                        libtcod.console_set_char_background(
                            con, x, y, colors.get("dark_wall"),
                            libtcod.BKGND_SET)
                    else:
                        libtcod.console_set_char_background(
                            con, x, y, colors.get("dark_ground"),
                            libtcod.BKGND_SET)

    # Sort and render Entities
    entities_in_render_order = sorted(entities,
                                      key=lambda x: x.render_order.value)
    for entity in entities_in_render_order:
        draw_entity(con, entity, fov_map, game_map)

    libtcod.console_blit(con, 0, 0, screen_width, screen_height, 0, 0, 0)

    if game_state in (GameStates.SHOW_INVENTORY, GameStates.DROP_INVENTORY):
        if game_state == GameStates.SHOW_INVENTORY:
            inventory_title = 'Press the key next to an item to use it, or Esc to cancel.\n'
        else:
            inventory_title = 'Press the key next to an item to drop it, or Esc to cancel.\n'
        inventory_menu(con, inventory_title, player, 50, screen_width,
                       screen_height)
    elif game_state == GameStates.LEVEL_UP:
        level_up_menu(con, 'Level up! Choose a stat to raise:', player, 40,
                      screen_width, screen_height)
    elif game_state == GameStates.CHARACTER_SCREEN:
        character_screen(player, 30, 15, screen_width, screen_height)
    libtcod.console_set_default_background(panel, libtcod.black)
    libtcod.console_clear(panel)

    y = 1
    for message in message_log.messages:
        libtcod.console_set_default_foreground(panel, message.color)
        libtcod.console_print_ex(panel, message_log.x, y, libtcod.BKGND_NONE,
                                 libtcod.LEFT, message.text)
        y += 1
    render_bar(panel, 1, 1, bar_width, 'HP', player.fighter.hp,
               player.fighter.max_hp, libtcod.light_red, libtcod.darker_red)
    stamina_label = "Stam" if not "exhausted" in player.fighter.effects else "Stam (E)"
    render_bar(panel, 1, 2, bar_width, stamina_label, player.fighter.stamina,
               player.fighter.max_stamina, libtcod.dark_green, libtcod.grey)
    libtcod.console_print_ex(
        panel, 1, 3, libtcod.BKGND_NONE, libtcod.LEFT,
        'Dungeon level: {0}'.format(game_map.dungeon_level))
    libtcod.console_print_ex(
        panel, 1, 4, libtcod.BKGND_NONE, libtcod.LEFT,
        'Atk: {0} / Def: {1}'.format(player.fighter.total_attack,
                                     player.fighter.defense))
    libtcod.console_set_default_foreground(panel, libtcod.light_gray)
    libtcod.console_print_ex(panel, 1, 0, libtcod.BKGND_NONE, libtcod.LEFT,
                             get_names_under_mouse(mouse, entities, fov_map))

    libtcod.console_blit(panel, 0, 0, screen_width, panel_height, 0, 0,
                         panel_y)
Ejemplo n.º 16
0
def render_all(con, panel, entities, player, game_map, fov_recompute,
               root_console, message_log, screen_width, screen_height,
               bar_width, panel_height, panel_y, mouse_coordinates, colors,
               game_state):

    # draw all tiles in the map
    if fov_recompute:
        for x, y in game_map:
            wall = not game_map.transparent[x, y]

            if game_map.fov[x, y]:
                if wall:
                    con.draw_char(x,
                                  y,
                                  None,
                                  fg=None,
                                  bg=colors.get("light_wall"))
                else:
                    con.draw_char(x,
                                  y,
                                  None,
                                  fg=None,
                                  bg=colors.get("light_ground"))

                game_map.explored[x][y] = True
            elif game_map.explored[x][y]:
                if wall:
                    con.draw_char(x,
                                  y,
                                  None,
                                  fg=None,
                                  bg=colors.get("dark_wall"))
                else:
                    con.draw_char(x,
                                  y,
                                  None,
                                  fg=None,
                                  bg=colors.get("dark_ground"))

    # draw all entities in the list
    entities_in_render_order = sorted(entities,
                                      key=lambda x: x.render_order.value)

    for entity in entities_in_render_order:
        draw_entity(con, entity, game_map)

    root_console.blit(con, 0, 0, screen_width, screen_height, 0, 0)

    panel.clear(fg=colors.get("white"), bg=colors.get("black"))

    # print game messages, one line at a time
    y = 1
    for message in message_log.messages:
        panel.draw_str(message_log.x,
                       y,
                       message.text,
                       bg=None,
                       fg=message.color)
        y += 1

    render_bar(panel, 1, 1, bar_width, "HP", player.fighter.hp,
               player.fighter.max_hp, colors.get("light_red"),
               colors.get("darker_red"), colors.get("white"))
    panel.draw_str(1,
                   3,
                   "Depth: {0}".format(game_map.dungeon_level),
                   fg=colors.get("white"),
                   bg=None)

    panel.draw_str(
        1, 0, get_names_under_mouse(mouse_coordinates, entities, game_map))

    root_console.blit(panel, 0, panel_y, screen_width, panel_height, 0, 0)

    if game_state in (GameStates.SHOW_INVENTORY, GameStates.DROP_INVENTORY):
        if game_state == GameStates.SHOW_INVENTORY:
            inventory_title = "Press the key next to an item to use it, or Esc to close.\n"
        else:
            inventory_title = "Press the key next to an item to drop it, or Esc to close.\n"

        inventory_menu(con, root_console, inventory_title, player, 50,
                       screen_width, screen_height)

    elif game_state == GameStates.LEVEL_UP:
        level_up_menu(con, root_console,
                      "You've grown stronger! Choose a stat to raise:", player,
                      40, screen_width, screen_height)

    elif game_state == GameStates.CHARACTER_SCREEN:
        character_screen(root_console, player, 30, 10, screen_width,
                         screen_height)
Ejemplo n.º 17
0
def render_all(con, panel, entities, player, game_map, fov_map, fov_recompute, message_log, screen_width, screen_height,
               bar_width, panel_height, panel_y, mouse, colors, game_state):

    ########## RENDERS TILES ##########

    # Only renders walls if the fov has changed or game just started.
    if fov_recompute:
        # Draw all tiles in the game map.
        for y in range(game_map.height):
            for x in range(game_map.width):
                # Stores whether the tile is in the fov (field of view).
                visible = libtcod.map_is_in_fov(fov_map, x, y)
                # Stores whether the wall is blocked or not.
                wall_block = game_map.tiles[x][y].block_sight

                # Colours the visible tiles.
                if visible:
                    if wall_block:
                        libtcod.console_set_char_background(con, x, y, colors.get("light_wall"), libtcod.BKGND_SET)
                    else:
                        libtcod.console_set_char_background(con, x , y, colors.get("light_ground"), libtcod.BKGND_SET)
                    # Sets the visible tile as 'explored'.
                    game_map.tiles[x][y].explored = True
                # Colours the tiles outside the fov if they have been explored.
                elif game_map.tiles[x][y].explored:
                    if wall_block:
                        libtcod.console_set_char_background(con, x, y, colors.get("dark_wall"), libtcod.BKGND_SET)
                    else:
                        libtcod.console_set_char_background(con, x, y, colors.get("dark_ground"), libtcod.BKGND_SET)

    entities_in_render_order = sorted(entities, key=lambda x: x.render_order.value)

    ########## RENDERS ENTITIES ##########

    # Draw all entities in the list.
    for entity in entities_in_render_order:
        draw_entity(con, entity, fov_map, game_map)

    ########## BLITS MAIN CONSOLE ##########

    # Blits the main off-screen console onto the root console.
    libtcod.console_blit(con, 0, 0, screen_width, screen_height, 0, 0, 0)

    # Clears the HP panel.
    libtcod.console_set_default_background(panel, libtcod.black)
    libtcod.console_clear(panel)

    ########## RENDERS MESSAGE LOG ##########

    # Prints the game messages, one line at a time.
    y = 1
    for message in message_log.messages:
        libtcod.console_set_default_foreground(panel, message.color)
        libtcod.console_print_ex(panel, message_log.x, y, libtcod.BKGND_NONE, libtcod.LEFT, message.text)
        y += 1

    ########## RENDERS HP BAR ##########

    render_bar(panel, 1, 1, bar_width, "HP", player.fighter.hp, player.fighter.max_hp,
               libtcod.light_red, libtcod.darker_red)

    ########## DEPTH LEVEL / FLOOR COUNTER ##########

    libtcod.console_print_ex(panel, 1, 3, libtcod.BKGND_NONE, libtcod.LEFT,
                             "Dungeon level: {0}".format(game_map.dungeon_level))

    ########## RENDERS entities-under-mouse message ##########

    libtcod.console_set_default_foreground(panel, libtcod.light_gray)
    libtcod.console_print_ex(panel, 1, 0, libtcod.BKGND_NONE, libtcod.LEFT,
                             get_names_under_mouse(mouse, entities, fov_map))

    ########## BLITS BOTTOM PANEL ##########

    # Blits the bottom panel to the screen.
    libtcod.console_blit(panel, 0, 0, screen_width, panel_height, 0, 0, panel_y)

    ########## BLITS THE INVENTORY MENU IF APPLICABLE ##########

    if game_state in (GameStates.SHOW_INVENTORY, GameStates.DROP_INVENTORY):
        if game_state == GameStates.SHOW_INVENTORY:
            inventory_title = "Press the key next to an item to use it, or Esc to cancel.\n"
        else: # Else the inventory must be the drop inventory...
            inventory_title = "Press the key next to an item to drop it, or Esc to cancel.\n"

        # Creates the inventory menu and blits it to the screen.
        inventory_menu(con, inventory_title,
                       player, 50, screen_width, screen_height)

    elif game_state == GameStates.LEVEL_UP:
        level_up_menu(con, "Level up! Choose a state to raise:", player, 40, screen_width, screen_height)

    elif game_state == GameStates.CHARACTER_SCREEN:
        character_screen(player, 30, 10, screen_width, screen_height)
def render_all(con, panel, cursor, entities, player, game_map, fov_map,
               fov_recompute, message_log, screen_width, screen_height,
               bar_width, panel_width, panel_x, mouse, colors, game_state,
               targeting_item, key):
    """
    Draw all tiles on the game (FOV) map and all entities in the list (con).
    Render panel and targeting (cursor) consoles.
    """
    # === Game map ===
    if fov_recompute:
        for y in range(game_map.height):
            for x in range(game_map.width):
                # Checks if tiles are in FOV
                visible = libtcod.map_is_in_fov(fov_map, x, y)
                tile = game_map.tiles[x][y]

                if visible:
                    tile_fg = libtcod.Color(*tile.colors_lit.get("fg"))
                    tile_bg = libtcod.Color(*tile.colors_lit.get("bg"))
                    libtcod.console_put_char_ex(con, x, y, tile.character,
                                                tile_fg, tile_bg)

                    game_map.tiles[x][y].explored = True

                elif game_map.tiles[x][y].explored:
                    tile_fg = libtcod.Color(*tile.colors_dark.get("fg"))
                    tile_bg = libtcod.Color(*tile.colors_dark.get("bg"))
                    libtcod.console_put_char_ex(con, x, y, tile.character,
                                                tile_fg, tile_bg)

    # === Entities ===
    entities_in_render_order = sorted(entities,
                                      key=lambda x: x.render_order.value)

    for entity in entities_in_render_order:
        draw_entity(con, entity, fov_map, game_map)

    # offset console by panel_width
    libtcod.console_blit(con, 0, 0, screen_width, screen_height, 0,
                         panel_width, 0)

    libtcod.console_set_default_background(con, colors['background_default'])

    # === Panel console ===
    libtcod.console_set_default_background(panel, colors['background_panel'])
    libtcod.console_clear(panel)

    # Print the message, one line at a time
    y = 32
    for message in message_log.messages:
        # if y % 2 == 0 and message.color == libtcod.lightest_grey:
        #     libtcod.console_set_default_foreground(panel, libtcod.grey)
        # else:
        libtcod.console_set_default_foreground(panel, message.color)
        libtcod.console_print_ex(panel, message_log.x, y, libtcod.BKGND_NONE,
                                 libtcod.LEFT, message.text)
        y += 1

    render_info(panel, 1, 1, player.name.upper(), colors['text_info_alt'],
                None)
    render_info(panel, 1, 2, 'Dungeon Level', colors['text_emphasize'],
                game_map.dungeon_level)

    render_bar(panel, 1, 4, bar_width, 'HP', player.fighter.hp,
               player.fighter.max_hp, colors['text_default'],
               colors['render_bar_fg'], colors['render_bar_bg'])
    render_bar(panel, 1, 5, bar_width, 'XP', player.level.current_xp,
               player.level.experience_to_next_level, colors['text_default'],
               libtcod.orange, libtcod.dark_orange)

    render_info(panel, 1, 7, 'Attack', colors['text_default'],
                player.fighter.power, player.equipment.power_bonus)
    render_info(panel, 1, 8, 'Defense', colors['text_default'],
                player.fighter.defense, player.equipment.defense_bonus)

    libtcod.console_set_default_foreground(panel, colors['text_desaturate'])
    libtcod.console_print_ex(panel, 1, 0, libtcod.BKGND_NONE, libtcod.LEFT,
                             get_names_under_mouse(mouse, entities, fov_map))
    description_box(
        con, get_entity_information_under_mouse(mouse, entities, fov_map), 10,
        screen_width, screen_height, mouse.cx, mouse.cy, colors)

    libtcod.console_blit(panel, 0, 0, panel_width, screen_height, 0, panel_x,
                         0)

    if game_state in {
            GameStates.SHOW_INVENTORY, GameStates.SHOW_EQUIPMENT,
            GameStates.DROP_INVENTORY
    }:
        if game_state == GameStates.SHOW_INVENTORY:
            inventory_title = 'Press the key next to an item to use it, or Esc to cancel.\n'
            inventory_menu(con, inventory_title, player, 30, screen_width,
                           screen_height, colors)
        elif game_state == GameStates.DROP_INVENTORY:
            inventory_title = 'Press the key next to an item to drop it, or Esc to cancel.\n'
            inventory_menu(con, inventory_title, player, 30, screen_width,
                           screen_height, colors)
        else:
            inventory_title = 'Press the key next to an item to unequip it, or Esc to cancel.\n'
            equipment_menu(con, inventory_title, player, 30, screen_width,
                           screen_height, colors)

    elif game_state == GameStates.LEVEL_UP:
        level_up_menu(con, 'Level up! Choose at stat to raise:', player, 30,
                      screen_width, screen_height, colors)

    elif game_state == GameStates.CHARACTER_SCREEN:
        character_screen(player, 30, 10, screen_width, screen_height, colors)

    elif game_state == GameStates.TARGETING:
        show_target(cursor, mouse, key, game_map.width, game_map.height,
                    targeting_item)
def render_all(con, panel, entities, player, game_map, fov_recompute,
               root_console, message_log, screen_width, screen_height,
               bar_width, panel_height, panel_y, mouse_coordinates, colors,
               game_state):
    # Draw all the tiles in the game map
    if fov_recompute:
        for x, y in game_map:
            wall = not game_map.transparent[x, y]

            if game_map.fov[x, y]:
                if wall:
                    con.draw_char(x,
                                  y,
                                  177,
                                  fg=colors.get('blue_3'),
                                  bg=colors.get('brown_2'))
                else:
                    con.draw_char(x,
                                  y,
                                  None,
                                  fg=colors.get('brown_2'),
                                  bg=colors.get('brown_1'))
                    #print(floor_var())

                game_map.explored[x][y] = True
            elif game_map.explored[x][y]:
                if wall:
                    con.draw_char(x,
                                  y,
                                  None,
                                  fg=None,
                                  bg=colors.get('brown_3'))
                else:
                    con.draw_char(x,
                                  y,
                                  None,
                                  fg=None,
                                  bg=colors.get('brown_4'))

    # Draw all entities in the list
    entities_in_render_order = sorted(entities,
                                      key=lambda x: x.render_order.value)

    for entity in entities_in_render_order:
        draw_entity(con, entity, game_map)

    con.draw_str(
        1, screen_height - 2,
        'HP: {0:02}/{1:02}'.format(player.fighter.hp, player.fighter.max_hp))

    root_console.blit(con, 0, 0, screen_width, screen_height, 0, 0)

    panel.clear(fg=colors.get('green_0'), bg=colors.get('blue_4'))

    # Print the game messages, one line at a time
    y = 1
    for message in message_log.messages:
        panel.draw_str(message_log.x,
                       y,
                       message.text,
                       bg=None,
                       fg=message.color)
        y += 1

    render_bar(panel, 1, 1, bar_width, 'HP', player.fighter.hp,
               player.fighter.max_hp, colors.get('red_3'), colors.get('red_4'),
               colors.get('red_1'))

    panel.draw_str(
        1, 0, get_names_under_mouse(mouse_coordinates, entities, game_map))
    panel.draw_str(1,
                   3,
                   'Dungeon Level: {0}'.format(game_map.dungeon_level),
                   fg=colors.get('red_1'),
                   bg=None)

    root_console.blit(panel, 0, panel_y, screen_width, panel_height, 0, 0)

    if game_state in (GameStates.SHOW_INVENTORY, GameStates.DROP_INVENTORY):
        if game_state == GameStates.SHOW_INVENTORY:
            inventory_title = 'Press the key next to an item to use it, or Esc to cancel.\n'
        else:
            inventory_title = 'Press the key next to an item to drop it, or Esc to cancel.\n'

        inventory_menu(con, root_console, inventory_title, player, 50,
                       screen_width, screen_height)

    elif game_state == GameStates.LEVEL_UP:
        level_up_menu(con, root_console, 'Level up! Choose a stat to raise:',
                      player, 40, screen_width, screen_height)

    elif game_state == GameStates.CHARACTER_SCREEN:
        character_screen(root_console, player, 30, 10, screen_width,
                         screen_height)
Ejemplo n.º 20
0
def render_all(con, panel, entities, player, game_map, fov_map, fov_recompute, message_log, screen_width, screen_height,
               bar_width, panel_height, panel_y, mouse, colors, game_state):

    if fov_recompute:
        # Draw all the tiles
        for y in range(game_map.height):
            for x in range(game_map.width):
                #todo change map_is_in_fov
                visible = libtcod.map_is_in_fov(fov_map, x, y)
                wall = game_map.tiles[x][y].block_sight

                if visible:
                    if wall:
                        #todo change the console char setting
                        libtcod.console_set_char_foreground(con, x, y, colors.get('light_ground'))
                        libtcod.console_set_char(con, x, y, '=')
                        libtcod.console_set_char_background(con, x, y, colors.get('light_wall'), libtcod.BKGND_SET)
                    else:
                        #todo change the console char setting
                        libtcod.console_set_char_foreground(con, x, y, colors.get('light_wall'))
                        libtcod.console_set_char(con, x, y, '.')
                        libtcod.console_set_char_background(con, x, y, colors.get('light_ground'), libtcod.BKGND_SET)
                    game_map.tiles[x][y].explored = True
                elif game_map.tiles[x][y].explored:
                    if wall:
                        #todo change the console char setting
                        libtcod.console_set_char_foreground(con, x, y, colors.get('dark_ground'))
                        libtcod.console_set_char(con, x, y, '=')
                        libtcod.console_set_char_background(con, x, y, colors.get('dark_wall'), libtcod.BKGND_SET)
                    else:
                        #todo change the console char setting
                        libtcod.console_set_char_foreground(con, x, y, colors.get('dark_wall'))
                        libtcod.console_set_char(con, x, y, '.')
                        libtcod.console_set_char_background(con, x, y, colors.get('dark_ground'), libtcod.BKGND_SET)

    entities_in_render_order = sorted(entities, key=lambda x: x.render_order.value)

    # draw all entities in the list
    for entity in entities_in_render_order:
        draw_entity(con, entity, fov_map, game_map)

    #todo update to new tcod commands
    libtcod.console_blit(con, 0, 0, screen_width, screen_height, 0, 0, 0)
    libtcod.console_set_default_background(panel, libtcod.black)
    libtcod.console_clear(panel)

    # Print the game messages, one line at a time
    y = 1
    for message in message_log.messages:
        #todo change the console char setting
        libtcod.console_set_default_foreground(panel, message.color)
        libtcod.console_print_ex(panel, message_log.x, y, libtcod.BKGND_NONE, libtcod.LEFT, message.text)
        y += 1

    # HP Bar
    render_bar(panel, 1, 1, bar_width, 'HP', player.fighter.hp, player.fighter.max_hp, libtcod.light_red, libtcod.darker_red)
    #todo change the console char setting
    libtcod.console_print_ex(panel, 1, 3, libtcod.BKGND_NONE, libtcod.LEFT, 'Dungeon Depth: {0}'.format(game_map.dungeon_depth))

    # print output from entities under mouse
    #todo change the console char setting
    libtcod.console_set_default_foreground(panel, libtcod.white)
    libtcod.console_print_ex(panel, 1, 0, libtcod.BKGND_NONE, libtcod.LEFT,
                             get_names_under_mouse(mouse, entities, fov_map))

    libtcod.console_blit(panel, 0, 0, screen_width, panel_height, 0, 0, panel_y)

    # Inventory call
    if game_state in (GameStates.SHOW_INVENTORY, GameStates.DROP_INVENTORY):
        if game_state == GameStates.SHOW_INVENTORY:
            inventory_title = 'Select from Menu or Esc to cancel.\n'
        else:
            inventory_title = 'Select from Menu or Esc to cancel.\n'

        inventory_menu(con, inventory_title, player, 50, screen_width, screen_height)

    elif game_state == GameStates.LEVEL_UP:
        level_up_menu(con, 'Level Up! Choose a stat to raise:', player, 40, screen_width, screen_width)

    elif game_state == GameStates.CHARACTER_SCREEN:
        character_screen(player, 30, 10, screen_width, screen_height)
def render_all(con, panel, tooltip, messages_pane, inventory_pane, entities,
               player, game_map, fov_map, fov_recompute, message_log,
               screen_width, screen_height, map_width, map_height, panel_width,
               panel_height, panel_x, mouse, colors, cam_x, cam_y, anim_frame,
               game_state, targeting_item, log_scroll, log_height, inv_scroll,
               inv_height, inv_selected):

    libtcod.console_clear(0)

    if fov_recompute or game_state == GameStates.TARGETING:
        # Draw all the tiles in the game map
        libtcod.console_set_default_foreground(con, libtcod.white)
        for y in range(game_map.height):
            for x in range(game_map.width):
                visible = libtcod.map_is_in_fov(fov_map, x, y)
                wall = game_map.tiles[x][y].block_sight
                if visible:
                    if game_state == GameStates.TARGETING and distanceBetween(
                            math.floor((mouse.cx + cam_x) / 3),
                            math.ceil((mouse.cy + cam_y) / 2), x,
                            y) <= targeting_item.item.targeting_radius:
                        backcolor = colors.get('red')
                    else:
                        backcolor = colors.get('light')
                    game_map.tiles[x][y].explored = True
                else:
                    backcolor = colors.get('dark')

                libtcod.console_set_char_background(con, x * 3, y * 2,
                                                    backcolor,
                                                    libtcod.BKGND_SET)
                libtcod.console_set_char_background(con, x * 3 + 1, y * 2,
                                                    backcolor,
                                                    libtcod.BKGND_SET)
                libtcod.console_set_char_background(con, x * 3 + 2, y * 2,
                                                    backcolor,
                                                    libtcod.BKGND_SET)
                libtcod.console_set_char_background(con, x * 3, y * 2 + 1,
                                                    backcolor,
                                                    libtcod.BKGND_SET)
                libtcod.console_set_char_background(con, x * 3 + 1, y * 2 + 1,
                                                    backcolor,
                                                    libtcod.BKGND_SET)
                libtcod.console_set_char_background(con, x * 3 + 2, y * 2 + 1,
                                                    backcolor,
                                                    libtcod.BKGND_SET)

                if (game_map.tiles[x][y].explored or visible) and wall:
                    libtcod.console_put_char(con, x * 3, y * 2,
                                             tiles.get('wall_tile'),
                                             libtcod.BKGND_NONE)
                    libtcod.console_put_char(con, x * 3 + 1, y * 2,
                                             tiles.get('wall_tile') + 1,
                                             libtcod.BKGND_NONE)
                    libtcod.console_put_char(con, x * 3 + 2, y * 2,
                                             tiles.get('wall_tile') + 2,
                                             libtcod.BKGND_NONE)
                    libtcod.console_put_char(con, x * 3, y * 2 + 1,
                                             tiles.get('wall_tile') + 32,
                                             libtcod.BKGND_NONE)
                    libtcod.console_put_char(con, x * 3 + 1, y * 2 + 1,
                                             tiles.get('wall_tile') + 33,
                                             libtcod.BKGND_NONE)
                    libtcod.console_put_char(con, x * 3 + 2, y * 2 + 1,
                                             tiles.get('wall_tile') + 34,
                                             libtcod.BKGND_NONE)

    # Draw all entities in the list

    entities_in_render_order = sorted(entities,
                                      key=lambda x: x.render_order.value)

    for entity in entities_in_render_order:
        draw_entity(con, entity, fov_map, anim_frame, game_map, game_state)

    libtcod.console_blit(con, 0, 0, map_width * 3, map_height * 2, 0, -cam_x,
                         -cam_y)

    libtcod.console_set_default_background(panel, colors.get('light'))
    libtcod.console_set_default_foreground(panel, colors.get('dark'))
    libtcod.console_clear(panel)

    # Print the game messages, one line at a time
    libtcod.console_print_ex(panel, int(panel_width / 2), 3, libtcod.BKGND_SET,
                             libtcod.CENTER, "-------- Messages --------")

    libtcod.console_set_default_background(messages_pane, colors.get('light'))
    libtcod.console_clear(messages_pane)
    y = 1
    for message in message_log.messages:
        libtcod.console_set_default_foreground(messages_pane, message.color)
        libtcod.console_print_ex(messages_pane, message_log.x, y,
                                 libtcod.BKGND_NONE, libtcod.LEFT,
                                 message.text)
        y += 1


#    if log_scroll > y - log_height:
#        log_scroll = y - log_height
    libtcod.console_blit(messages_pane, 0, y - log_height - log_scroll,
                         panel_width - 3, log_height, panel, 2, 4)

    #    libtcod.console_set_default_background(panel, colors.get('dark'))
    #    libtcod.console_set_default_foreground(panel, colors.get('light'))
    #    libtcod.console_put_char(panel, panel_width-1, 5, " ", libtcod.BKGND_SET)
    libtcod.console_put_char(panel, panel_width - 2, 4, tiles.get('up_tile'),
                             libtcod.BKGND_SET)
    #    libtcod.console_put_char(panel, panel_width-3, 5, " ", libtcod.BKGND_SET)
    #    libtcod.console_put_char(panel, panel_width-1, 5+log_height, " ", libtcod.BKGND_SET)
    libtcod.console_put_char(panel, panel_width - 2, 4 + log_height,
                             tiles.get('down_tile'), libtcod.BKGND_SET)
    #    libtcod.console_put_char(panel, panel_width-3, 5+log_height, " ", libtcod.BKGND_SET)

    # Print the inventory items
    #    libtcod.console_set_default_background(panel, colors.get('light'))
    #    libtcod.console_set_default_foreground(panel, colors.get('dark'))
    libtcod.console_print_ex(panel, int(panel_width / 2), 5 + log_height,
                             libtcod.BKGND_SET, libtcod.CENTER,
                             "-------- Backpack --------")
    libtcod.console_set_default_foreground(panel, colors.get('green'))
    libtcod.console_print_ex(panel, int(panel_width / 2), 6 + log_height,
                             libtcod.BKGND_SET, libtcod.CENTER,
                             "<> select | [u]se | [d]rop")

    libtcod.console_set_default_background(inventory_pane, colors.get('light'))
    libtcod.console_clear(inventory_pane)
    y = 1
    for item in player.inventory.items:
        if y == inv_selected + 1:
            libtcod.console_set_default_background(inventory_pane,
                                                   colors.get('dark'))
            libtcod.console_set_default_foreground(inventory_pane,
                                                   colors.get('light'))
        else:
            libtcod.console_set_default_background(inventory_pane,
                                                   colors.get('light'))
            libtcod.console_set_default_foreground(inventory_pane,
                                                   colors.get('dark'))
        if player.equipment.main_hand == item:
            libtcod.console_print_ex(
                inventory_pane, 0, y, libtcod.BKGND_SET, libtcod.LEFT,
                '{0} ({1}) (main)'.format(item.name, item.number))
        elif player.equipment.off_hand == item:
            libtcod.console_print_ex(
                inventory_pane, 0, y, libtcod.BKGND_SET, libtcod.LEFT,
                '{0} ({1}) (off)'.format(item.name, item.number))
        else:
            libtcod.console_print_ex(
                inventory_pane, 0, y, libtcod.BKGND_SET, libtcod.LEFT,
                '{0} ({1})'.format(item.name, item.number))
        y += 1
    libtcod.console_blit(inventory_pane, 0, y - inv_height, panel_width - 3,
                         inv_height, panel, 2, 7 + log_height)

    render_bar(panel, 2, 1, panel_width - 4, 'Health', player.fighter.hp,
               player.fighter.max_hp, colors.get('green'), colors.get('dark'),
               colors.get('light'))
    libtcod.console_set_default_foreground(panel, colors.get('dark'))
    #    libtcod.console_print_ex(panel, 1, 3, libtcod.BKGND_NONE, libtcod.LEFT, 'Dungeon level: {0}'.format(game_map.dungeon_level))

    libtcod.console_set_default_background(panel, colors.get('light'))
    libtcod.console_set_default_foreground(panel, colors.get('dark'))
    for y in range(0, screen_height):
        libtcod.console_put_char(panel, 0, y, tiles.get('gradient_tile'),
                                 libtcod.BKGND_SET)

    libtcod.console_set_default_foreground(panel, colors.get('dark'))
    libtcod.console_set_default_background(panel, colors.get('light'))

    libtcod.console_blit(panel, 0, 0, panel_width, panel_height, 0, panel_x, 0)

    tooltip_text = get_names_under_mouse(cam_x, cam_y, mouse, entities,
                                         fov_map)
    tooltip_len = len(tooltip_text)
    libtcod.console_set_default_background(tooltip, libtcod.black)
    libtcod.console_clear(tooltip)
    libtcod.console_set_default_foreground(tooltip, colors.get('light'))
    libtcod.console_set_default_background(tooltip, colors.get('dark'))
    libtcod.console_print_ex(tooltip, 0, 0, libtcod.BKGND_SET, libtcod.LEFT,
                             tooltip_text)

    libtcod.console_set_key_color(tooltip, libtcod.black)
    libtcod.console_blit(tooltip, 0, 0, tooltip_len, 1, 0, mouse.cx + 2,
                         mouse.cy + 1)

    if game_state in (GameStates.SHOW_INVENTORY, GameStates.DROP_INVENTORY):
        if game_state == GameStates.SHOW_INVENTORY:
            inventory_title = 'Use or equip item.\n'
        else:
            inventory_title = 'Drop an item.\n'

        inventory_menu(con, inventory_title, player, 50, screen_width,
                       screen_height)

    elif game_state == GameStates.LEVEL_UP:
        level_up_menu(con, 'Level up! Choose a stat to raise:', player, 40,
                      screen_width, screen_height)

    elif game_state == GameStates.CHARACTER_SCREEN:
        character_screen(player, 30, 10, screen_width, screen_height)
Ejemplo n.º 22
0
def render_all(con, panel, entities, player, game_map, fov_map, fov_recompute,
               message_log, screen_width, screen_height, bar_width,
               panel_height, panel_y, mouse, colors, game_state):
    if fov_recompute:
        for y in range(game_map.height):
            for x in range(game_map.width):
                visible = fov_map.fov[y][x]
                wall = game_map.tiles[x][y].block_sight
                if visible:
                    if wall:
                        libtcod.console_set_char_background(
                            con, x, y, colors.get("light_wall"),
                            libtcod.BKGND_SET)
                    else:
                        libtcod.console_set_char_background(
                            con, x, y, colors.get("light_ground"),
                            libtcod.BKGND_SET)
                    game_map.tiles[x][y].explored = True
                elif game_map.tiles[x][y].explored:
                    if wall:
                        libtcod.console_set_char_background(
                            con, x, y, colors.get("dark_wall"),
                            libtcod.BKGND_SET)
                    else:
                        libtcod.console_set_char_background(
                            con, x, y, colors.get("dark_ground"),
                            libtcod.BKGND_SET)

    entities_in_render_order = sorted(entities,
                                      key=lambda x: x.render_order.value)

    for entity in entities_in_render_order:
        if fov_map.fov[entity.y][entity.x] or (
                entity.stairs and game_map.tiles[entity.x][entity.y].explored):
            draw_entity(con, entity)

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

    render_bar(panel, 1, 1, bar_width, "HP", player.fighter.hp,
               player.fighter.max_hp, libtcod.light_red, libtcod.darker_red)

    libtcod.console_print_ex(
        panel, 1, 3, libtcod.BKGND_NONE, libtcod.LEFT,
        "Dungeon level: {}".format(game_map.dungeon_level))

    libtcod.console_set_default_foreground(panel, libtcod.light_gray)
    libtcod.console_print_ex(panel, 1, 0, libtcod.BKGND_NONE, libtcod.LEFT,
                             get_names_under_mouse(mouse, entities, fov_map))

    y = 1
    for message in message_log.messages:
        libtcod.console_set_default_foreground(panel, message.color)
        libtcod.console_print_ex(panel, message_log.x, y, libtcod.BKGND_NONE,
                                 libtcod.LEFT, message.text)
        y += 1

    libtcod.console_blit(con, 0, 0, screen_width, screen_height, 0, 0, 0)
    libtcod.console_blit(panel, 0, 0, screen_width, panel_height, 0, 0,
                         panel_y)

    inventory_title = None
    if game_state == GameStates.SHOW_INVENTORY:
        inventory_title = "Press the key next to an item to use it, or Esc to cancel.\n"
    elif game_state == GameStates.DROP_INVENTORY:
        inventory_title = "Press the key next to an item to drop it, or Esc to cancel.\n"

    if inventory_title != None:
        inventory_menu(con, inventory_title, player, player.inventory, 50,
                       screen_width, screen_height)

    if game_state == GameStates.LEVEL_UP:
        level_up_menu(con, "Level up! Choose a stat to raise:", player, 40,
                      screen_width, screen_height)

    if game_state == GameStates.CHARACTER_SCREEN:
        character_screen(player, 30, 10, screen_width, screen_height)
Ejemplo n.º 23
0
def render_all(con, panel, entities, player, game_map, fov_recompute,
               root_console, message_log, screen_width, screen_height,
               bar_width, panel_height, panel_y, mouse_coordinates, colors,
               game_state):
    # Draw all the tiles in the game map.
    if fov_recompute:
        for x, y in game_map:
            wall = not game_map.transparent[x, y]

            if game_map.fov[x, y]:
                if wall:
                    con.draw_char(x,
                                  y,
                                  None,
                                  fg=None,
                                  bg=colors.get('light_wall'))
                else:
                    con.draw_char(x,
                                  y,
                                  None,
                                  fg=None,
                                  bg=colors.get('light_ground'))

                game_map.explored[x][y] = True

            elif game_map.explored[x][y]:
                if wall:
                    con.draw_char(x,
                                  y,
                                  None,
                                  fg=None,
                                  bg=colors.get('dark_wall'))
                else:
                    con.draw_char(x,
                                  y,
                                  None,
                                  fg=None,
                                  bg=colors.get('dark_ground'))

    entities_in_render_order = sorted(entities,
                                      key=lambda x: x.render_order.value)

    # Draw all entities in the list
    for entity in entities_in_render_order:
        draw_entity(con, entity, game_map)

    root_console.blit(con, 0, 0, screen_width, screen_height, 0, 0)

    if game_state in (GameStates.SHOW_INVENTORY, GameStates.DROP_INVENTORY):
        if game_state == GameStates.SHOW_INVENTORY:
            inventory_title = 'Press the key next to an item to use it, or ESC to cancel.\n'
        else:
            inventory_title = 'Press the key next to an item to drop it, or ESC to cancel.\n'

        inventory_menu(con, root_console, inventory_title, player, 50,
                       screen_width, screen_height)

    elif game_state == GameStates.LEVEL_UP:
        level_up_menu(con, root_console, 'Level Up! Choose a stat to raise:',
                      player, 40, screen_width, screen_height)

    elif game_state == GameStates.CHARACTER_SCREEN:
        character_screen(root_console, player, 30, 10, screen_width,
                         screen_height)

    elif game_state == GameStates.SHOW_STORE:
        store_menu(con, root_console, 'Store', player, 40, screen_width,
                   screen_height)

    elif game_state == GameStates.CONTROL_SCREEN:
        control_screen(root_console, 40, 20, screen_width, screen_height)

    panel.clear(fg=colors.get('white'), bg=colors.get('black'))

    #Print the game messages, one line at a time
    y = 1
    for message in message_log.messages:
        panel.draw_str(message_log.x,
                       y,
                       message.text,
                       bg=None,
                       fg=message.color)
        y += 1

    render_bar(panel, 1, 1, bar_width, 'HP', player.fighter.hp,
               player.fighter.max_hp, colors.get('light_red'),
               colors.get('darker_red'), colors.get('white'))
    render_bar(panel, 1, 2, bar_width, 'XP', player.level.current_xp,
               player.level.experience_to_next_level, colors.get('gold'),
               colors.get('black'), colors.get('white'))

    panel.draw_str(1,
                   3,
                   'Gold: {0}'.format(player.gold.current_gold),
                   fg=colors.get('white'),
                   bg=None)
    panel.draw_str(1,
                   4,
                   'Dungeon Level: {0}'.format(game_map.dungeon_level),
                   fg=colors.get('white'),
                   bg=None)

    panel.draw_str(
        1, 0, get_names_under_mouse(mouse_coordinates, entities, game_map))

    root_console.blit(panel, 0, panel_y, screen_width, panel_height, 0, 0)
Ejemplo n.º 24
0
def render_all(con, panel, entities, player, game_map, fov_map, fov_recompute, message_log, screen_width, screen_height,
               bar_width, panel_height, panel_y, mouse, colors,game_state):
    if fov_recompute:
    # Draw all the tiles in the game map
        for y in range(game_map.height):
            for x in range(game_map.width):
                visible = libtcod.map_is_in_fov(fov_map, x, y)
                wall = game_map.tiles[x][y].block_sight

                if visible:
                    if wall:
                        #libtcod.console_set_char_background(con, x, y, colors.get('light_wall'), libtcod.BKGND_SET)
                        libtcod.console_set_default_foreground(con, libtcod.white)
                        libtcod.console_put_char(con, x, y, const.Grass_Light_tile, libtcod.BKGND_NONE)
                    else:
                        #libtcod.console_set_char_background(con, x, y, colors.get('light_ground'), libtcod.BKGND_SET)
                        libtcod.console_set_default_foreground(con,libtcod.white)
                        libtcod.console_put_char(con,x,y, const.Court_tile , libtcod.BKGND_NONE)

                    game_map.tiles[x][y].explored = True
                elif game_map.tiles[x][y].explored:
                    if wall:
                        #libtcod.console_set_char_background(con, x, y, colors.get('dark_wall'), libtcod.BKGND_SET)
                        libtcod.console_set_default_foreground(con, libtcod.white)
                        libtcod.console_put_char(con, x, y, const.Grass_Dark_tile , libtcod.BKGND_NONE)
                    else:
                        #libtcod.console_set_char_background(con, x, y, colors.get('dark_ground'), libtcod.BKGND_SET)
                        libtcod.console_set_default_foreground(con, libtcod.white)
                        libtcod.console_put_char(con, x, y, const.Court_tile , libtcod.BKGND_NONE)

    entities_in_render_order = sorted(entities, key=lambda x: x.render_order.value)

    # Draw all entities in the list
    for entity in entities_in_render_order:
        draw_entity(con, entity, fov_map,game_map)

    libtcod.console_blit(con, 0, 0, screen_width, screen_height, 0, 0, 0)

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

    # Print the game messages, one line at a time
    y = 1
    for message in message_log.messages:
        libtcod.console_set_default_foreground(panel, message.color)
        libtcod.console_print_ex(panel, message_log.x, y, libtcod.BKGND_NONE, libtcod.LEFT, message.text)
        y += 1

    render_bar(panel, 1, 1, bar_width, 'HP', player.fighter.hp, player.fighter.max_hp,
               libtcod.light_red, libtcod.darker_red)

    libtcod.console_print_ex(panel, 1, 3, libtcod.BKGND_NONE, libtcod.LEFT,
                             'Dungeon level: {0}'.format(game_map.dungeon_level))

    libtcod.console_set_default_foreground(panel, libtcod.light_gray)
    libtcod.console_print_ex(panel, 1, 0, libtcod.BKGND_NONE, libtcod.LEFT,
                             get_names_under_mouse(mouse, entities, fov_map))

    libtcod.console_blit(panel, 0, 0, screen_width, panel_height, 0, 0, panel_y)

    if game_state in (GameStates.SHOW_INVENTORY, GameStates.DROP_INVENTORY):
        if game_state == GameStates.SHOW_INVENTORY:
            inventory_title = 'Press the key next to an item to use it, or Esc to cancel.\n'
        else:
            inventory_title = 'Press the key next to an item to drop it, or Esc to cancel.\n'

        inventory_menu(con, inventory_title, player, 50, screen_width, screen_height)

    elif game_state == GameStates.LEVEL_UP:
        level_up_menu(con, 'Level up! Choose a stat to raise:', player, 40, screen_width, screen_height)
    elif game_state == GameStates.EVOLVE:
        evolve_menu(con,'Your player is evolved!',player,40,screen_width,screen_height)
    elif game_state == GameStates.CHARACTER_SCREEN:
        character_screen(player, 30, 10, screen_width, screen_height)
    elif game_state == GameStates.COMMAND_MENU:
        commandMenu(screen_width, screen_height, screen_width, screen_height)
    elif game_state == GameStates.WIN_MENU:
        WinMenu(con, screen_width, screen_height)
    elif game_state == GameStates.PLAYER_DEAD:
        DiedMenu(con, screen_width, screen_height)
Ejemplo n.º 25
0
def render_all(con, panel, game_map, entities, player, fov_map, fov_recompute,
               message_log, screen_width, screen_height, bar_width,
               panel_height, panel_y, mouse, tile_data, game_state):

    entities_in_render_order = sorted(entities,
                                      key=lambda x: x.render_order.value)
    for entity in entities_in_render_order:
        draw_entity(con, entity, fov_map, game_map)

    if fov_recompute:
        stairs_x, stairs_y = stairs_location(entities)

        for y in range(game_map.height):
            for x in range(game_map.width):

                visible = lc.map_is_in_fov(fov_map, x, y)

                if visible:
                    lc.console_set_char_background(
                        con, x, y,
                        tile_data.get(game_map.tiles[x][y].terrain)['light'],
                        lc.BKGND_SET)
                    if not (y == stairs_y and x == stairs_x):
                        lc.console_set_char_foreground(
                            con, x, y,
                            tile_data.get(
                                game_map.tiles[x][y].terrain)['dark'])
                        lc.console_set_char(con, x, y,
                                            chr(game_map.tiles[x][y].texture))
                    game_map.tiles[x][y].explored = True
                elif game_map.tiles[x][y].explored:
                    # lc.console_put_char(con,x,y,chr(game_map.tiles[x][y].texture),lc.BKGND_NONE)

                    lc.console_set_char_background(
                        con, x, y,
                        tile_data.get(game_map.tiles[x][y].terrain)['dark'],
                        lc.BKGND_SET)
                    if not (y == stairs_y and x == stairs_x):
                        lc.console_set_char_foreground(con, x, y, lc.black)
                        lc.console_set_char(con, x, y,
                                            chr(game_map.tiles[x][y].texture))

    lc.console_blit(con, 0, 0, screen_width, screen_height, 0, 0, 0)

    lc.console_set_default_background(panel, lc.black)
    lc.console_clear(panel)

    y = 1
    for message in message_log.messages:
        lc.console_set_default_foreground(panel, message.colour)
        lc.console_print_ex(panel, message_log.x, y, lc.BKGND_NONE, lc.LEFT,
                            message.text)
        y += 1

    render_bar(panel, 1, 1, bar_width, 'HP', player.fighter.health,
               player.fighter.max_health, lc.red, lc.darker_red)
    lc.console_print_ex(panel, 1, 3, lc.BKGND_NONE, lc.LEFT,
                        'Dungeon Level: {0}'.format(game_map.floor))

    lc.console_set_default_background(panel, lc.light_gray)
    lc.console_print_ex(panel, 1, 0, lc.BKGND_NONE, lc.LEFT,
                        get_names_under_mouse(mouse, entities, fov_map))

    lc.console_blit(panel, 0, 0, screen_width, panel_height, 0, 0, panel_y)

    if game_state in (GameStates.SHOW_INVENTORY, GameStates.DROP_INVENTORY):
        if game_state == GameStates.SHOW_INVENTORY:
            inventory_title = 'Press the key next to an item to use it or Esc to cancel.\n'
        else:
            inventory_title = 'Press the key next to an item to drop it or Esc to cancel. \n'

        inventory_menu(con, inventory_title, player, 50, screen_width,
                       screen_height)
    elif game_state == GameStates.LEVEL_UP:
        level_up_menu(con, 'Level up! Choose a stat to raise:', player, 40,
                      screen_width, screen_height)
    elif game_state == GameStates.CHARACTER_SCREEN:
        character_screen(player, 30, 10, screen_width, screen_height)
def render_all(con, panel, entities, player, game_map, fov_map, fov_recompute,
               message_log, screen_width, screen_height, bar_width,
               panel_height, panel_y, mouse, colors, kill_count, game_state):
    if fov_recompute:
        for y in range(game_map.height):
            for x in range(game_map.width):
                visible = libtcod.map_is_in_fov(fov_map, x, y)
                wall = game_map.tiles[x][y].block_sight

                if visible:
                    if wall:
                        libtcod.console_set_char_background(
                            con, x, y, colors.get('light_wall'),
                            libtcod.BKGND_SET)
                    else:
                        libtcod.console_set_char_background(
                            con, x, y, colors.get('light_ground'),
                            libtcod.BKGND_SET)

                    game_map.tiles[x][y].explored = True
                elif game_map.tiles[x][y].explored:
                    if wall:
                        libtcod.console_set_char_background(
                            con, x, y, colors.get('dark_wall'),
                            libtcod.BKGND_SET)
                    else:
                        libtcod.console_set_char_background(
                            con, x, y, colors.get('dark_ground'),
                            libtcod.BKGND_SET)

    entities_in_render_order = sorted(entities,
                                      key=lambda x: x.render_order.value)

    for entity in entities_in_render_order:
        draw_entity(con, entity, fov_map, game_map)

    libtcod.console_set_default_foreground(con, libtcod.white)
    libtcod.console_print_ex(
        con, 1, screen_height - 2, libtcod.BKGND_NONE, libtcod.LEFT,
        "HP: {0:02}/{1:02}".format(player.fighter.hp, player.fighter.max_hp))
    ''' Danny code to center player and have window scroll
    r = 20
    libtcod.console_blit(con, player.x - r, player.y - r, 2*r+1, 2*r+1, 0, int(screen_width/2) - r, int(screen_height/2) - r)
    '''
    libtcod.console_blit(con, 0, 0, screen_width, screen_height, 0, 0, 0)

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

    y = 1
    for message in message_log.messages:
        libtcod.console_set_default_foreground(panel, message.color)
        libtcod.console_print_ex(panel, message_log.x, y, libtcod.BKGND_NONE,
                                 libtcod.LEFT, message.text)
        y += 1

    render_bar(panel, 1, 1, bar_width, "HP", player.fighter.hp,
               player.fighter.max_hp, libtcod.light_red, libtcod.darker_red)

    render_bar(panel, 1, 2, bar_width, "EXP", player.level.current_xp,
               player.level.experience_to_next_level, libtcod.light_blue,
               libtcod.darker_blue)

    libtcod.console_print_ex(panel, 1, 4, libtcod.BKGND_NONE, libtcod.LEFT,
                             "Gold: {0}".format(player.fighter.gold))

    if player.inventory.search("Health Talisman") is not None:
        render_bar(panel, 1, 3, bar_width, "Talisman HP",
                   player.fighter.talismanhp, player.fighter.max_hp,
                   libtcod.light_purple, libtcod.darker_purple)

    libtcod.console_print_ex(
        panel, 1, 5, libtcod.BKGND_NONE, libtcod.LEFT,
        "Dungeon Level: {0}".format(game_map.dungeon_level))

    libtcod.console_set_default_foreground(panel, libtcod.light_gray)
    libtcod.console_print_ex(panel, 1, 0, libtcod.BKGND_NONE, libtcod.LEFT,
                             get_names_under_mouse(mouse, entities, fov_map))

    libtcod.console_blit(panel, 0, 0, screen_width, panel_height, 0, 0,
                         panel_y)

    if game_state in (GameStates.SHOW_INVENTORY, GameStates.DROP_INVENTORY):
        if game_state == GameStates.SHOW_INVENTORY:
            inventory_title = "Press the key next to an item to use it, or ESC to cancel.\n"
        elif game_state == GameStates.DROP_INVENTORY:
            inventory_title = "Press the key next to an item to drop it, or ESC to cancel.\n"

        inventory_menu(con, inventory_title, player, 50, screen_width,
                       screen_height)

    elif game_state in (GameStates.SHOW_EQUIPMENT_INVENTORY,
                        GameStates.DROP_EQUIPMENT):
        if game_state == GameStates.SHOW_EQUIPMENT_INVENTORY:
            inventory_title = "Press the key next to an item to equip it, or ESC to cancel.\n"
        else:
            inventory_title = "Press the key next to the equipment to drop it, or ESC to cancel.\n"

        equipment_inventory_menu(con, inventory_title, player, 50,
                                 screen_width, screen_height)

    elif game_state == GameStates.LEVEL_UP:
        level_up_menu(con, "Level up! Choose a stat to raise:\n", player, 46,
                      screen_width, screen_height)

    elif game_state == GameStates.CHARACTER_SCREEN:
        character_screen(player, 30, 10, screen_width, screen_height,
                         kill_count)

    elif game_state == GameStates.SHOW_BAG:
        bag_title = "Press the key next to the option to open the bag.\n"

        bag_menu(con, bag_title, player, 50, screen_width, screen_height)

    elif game_state == GameStates.HELP_MENU:
        help_menu(player, 30, 10, screen_width, screen_height)

    elif game_state == GameStates.QUIT_MENU:
        quit_title = "ARE YOU SURE YOU WANT\n  TO QUIT THE GAME?\n"

        quit_menu(con, quit_title, player, 21, screen_width, screen_height)

    elif game_state == GameStates.DROP_MENU:
        drop_title = "Which inventory would you like to drop items from?"

        drop_menu(con, drop_title, player, 50, screen_width, screen_height)

    elif game_state == GameStates.SELL_MENU:
        shop_title = "Welcome to the Shop!\nWhat would you like to sell?\n"

        sell_menu(con, shop_title, player, 50, screen_width, screen_height)

    elif game_state == GameStates.BUY_MENU:
        shop_title = "Welcome to the Shop!\nWhat would you like to buy?\n"

        buy_menu(con, shop_title, player, 50, screen_width, screen_height)

    elif game_state == GameStates.SHOP_MENU:
        shop_title = "Welcome to the Shop!\nWhat would you like to do?\n"

        shop_menu(con, shop_title, player, 50, screen_width, screen_height)
Ejemplo n.º 27
0
def render_all(con, panel, entities, player, game_map, fov_map, fov_recompute,
               message_log, screen_width, screen_height, bar_width,
               panel_height, panel_y, mouse, colors, game_state):
    # draw all tiles in the game map
    # loop through each tile in the game map and check if it blocks sight or not
    if fov_recompute:
        for y in range(game_map.height):
            for x in range(game_map.width):
                visible = libtcod.map_is_in_fov(fov_map, x, y)
                wall = game_map.tiles[x][y].block_sight

                if visible:  # if tile is visible, it will be drawn in the "light" colors
                    # if blocks sight, draw as a wall
                    if wall:
                        libtcod.console_set_char_background(
                            con, x, y, colors.get('light_wall'),
                            libtcod.BKGND_SET)
                    # if does not block sight, draw as a floor
                    else:
                        libtcod.console_set_char_background(
                            con, x, y, colors.get('light_ground'),
                            libtcod.BKGND_SET)

                    # mark tiles within the player's field of view as explored
                    game_map.tiles[x][y].explored = True
                elif game_map.tiles[x][
                        y].explored:  # tile is not within FOV - however, if the tile has already been explored, draw it as a "dark" tile
                    # if blocks sight, draw as a wall
                    if wall:
                        libtcod.console_set_char_background(
                            con, x, y, colors.get('dark_wall'),
                            libtcod.BKGND_SET)
                    # if does not block sight, draw as a floor
                    else:
                        libtcod.console_set_char_background(
                            con, x, y, colors.get('dark_ground'),
                            libtcod.BKGND_SET)

    entities_in_render_order = sorted(entities,
                                      key=lambda x: x.render_order.value)

    # draw all entities in the list
    for entity in entities_in_render_order:
        draw_entity(con, entity, fov_map, game_map)

    libtcod.console_blit(con, 0, 0, screen_width, screen_height, 0, 0, 0)

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

    # print the game messages, one line at a time
    y = 1
    for message in message_log.messages:
        libtcod.console_set_default_foreground(panel, message.color)
        libtcod.console_print_ex(panel, message_log.x, y, libtcod.BKGND_NONE,
                                 libtcod.LEFT, message.text)
        y += 1

    render_bar(panel, 1, 1, bar_width, 'HP', player.fighter.hp,
               player.fighter.max_hp, libtcod.light_red, libtcod.darker_red)

    libtcod.console_print_ex(
        panel, 1, 3, libtcod.BKGND_NONE, libtcod.LEFT,
        'Dungeon level: {0}'.format(game_map.dungeon_level))

    libtcod.console_set_default_foreground(panel, libtcod.light_gray)
    libtcod.console_print_ex(panel, 1, 0, libtcod.BKGND_NONE, libtcod.LEFT,
                             get_names_under_mouse(mouse, entities, fov_map))

    libtcod.console_blit(panel, 0, 0, screen_width, panel_height, 0, 0,
                         panel_y)

    if game_state in (GameStates.SHOW_INVENTORY, GameStates.DROP_INVENTORY):
        if game_state == GameStates.SHOW_INVENTORY:
            inventory_title = 'Press the key next to an item to use it, or Esc to cancel.\n'
        else:
            inventory_title = 'Press the key next to an item to drop it, or Esc to cancel.\n'
        inventory_menu(con, inventory_title, player.inventory, 50,
                       screen_width, screen_height)

    elif game_state == GameStates.LEVEL_UP:
        level_up_menu(con, 'Level up! Choose a state to raise:', player, 40,
                      screen_width, screen_height)

    elif game_state == GameStates.CHARACTER_SCREEN:
        character_screen(player, 30, 10, screen_width, screen_height)
Ejemplo n.º 28
0
def render_all(con, panel, entities, player, game_map, fov_map, fov_recompute,
               message_log, screen_width, screen_height, bar_width,
               panel_height, panel_y, mouse, colors, game_state):
    if fov_recompute:
        # Draw all the tiles in the game map
        for y in range(game_map.height):
            for x in range(game_map.width):
                visible = libtcod.map_is_in_fov(fov_map, x, y)
                wall = game_map.tiles[x][y].block_sight

                if visible:
                    if wall:
                        libtcod.console_set_char_background(
                            con, x, y, colors.get('light_wall'),
                            libtcod.BKGND_SET)
                    else:
                        libtcod.console_set_char_background(
                            con, x, y, colors.get('light_ground'),
                            libtcod.BKGND_SET)

                    game_map.tiles[x][y].explored = True
                elif game_map.tiles[x][y].explored:
                    if wall:
                        libtcod.console_set_char_background(
                            con, x, y, colors.get('dark_wall'),
                            libtcod.BKGND_SET)
                    else:
                        libtcod.console_set_char_background(
                            con, x, y, colors.get('dark_ground'),
                            libtcod.BKGND_SET)

    entities_in_render_order = sorted(entities,
                                      key=lambda x: x.render_order.value)

    # Draw all entities in the list
    for entity in entities_in_render_order:
        draw_entity(con, entity, fov_map, game_map)

    libtcod.console_blit(con, 0, 0, screen_width, screen_height, 0, 0, 0)

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

    # Print the game messages, one line at a time
    y = 1
    for message in message_log.messages:
        libtcod.console_set_default_foreground(panel, message.color)
        libtcod.console_print_ex(panel, message_log.x, y, libtcod.BKGND_NONE,
                                 libtcod.LEFT, message.text)
        y += 1

    render_bar(panel, 1, 1, bar_width, 'HP', player.fighter.hp,
               player.fighter.max_hp, libtcod.light_red, libtcod.darker_red)
    render_bar(panel, 1, 2, bar_width, 'Mana', player.fighter.mana,
               player.fighter.max_mana, libtcod.light_blue,
               libtcod.darker_blue)
    libtcod.console_print_ex(
        panel, 1, 3, libtcod.BKGND_NONE, libtcod.LEFT,
        'Dungeon level: {0}'.format(game_map.dungeon_level))
    libtcod.console_print_ex(panel, 1, 4, libtcod.BKGND_NONE, libtcod.LEFT,
                             'Nutrition: {0}'.format(player.fighter.nutrition))
    libtcod.console_print_ex(panel, 1, 5, libtcod.BKGND_NONE, libtcod.LEFT,
                             'AC: {0}'.format(player.fighter.ac))

    libtcod.console_set_default_foreground(panel, libtcod.light_gray)
    libtcod.console_print_ex(panel, 1, 0, libtcod.BKGND_NONE, libtcod.LEFT,
                             get_names_under_mouse(mouse, entities, fov_map))

    libtcod.console_blit(panel, 0, 0, screen_width, panel_height, 0, 0,
                         panel_y)

    if game_state in (GameStates.SHOW_INVENTORY, GameStates.DROP_INVENTORY):
        if game_state == GameStates.SHOW_INVENTORY:
            inventory_title = 'Press the key next to an item to use it, or Esc to cancel.\n'
        else:
            inventory_title = 'Press the key next to an item to drop it, or Esc to cancel.\n'

        inventory_menu(con, inventory_title, player, 50, screen_width,
                       screen_height)

    elif game_state == GameStates.LEVEL_UP:
        level_up_menu(con, 'Level up! Choose a stat to raise:', player, 40,
                      screen_width, screen_height)

    elif game_state == GameStates.CHARACTER_SCREEN:
        character_screen(player, 30, 11, screen_width, screen_height)

    elif game_state == GameStates.RACE_SELECTION:
        race_select_menu(con, 'What is your race?', player, 40, screen_width,
                         screen_height)

    elif game_state == GameStates.SKILL_SELECTION:
        skill_menu(con, 'What skill would you like to use?', player, 40,
                   screen_width, screen_height)

    elif game_state == GameStates.CLASS_SELECTION:
        job_selection_menu(con, 'What class do you want to level in?', player,
                           40, screen_width, screen_height)

    elif game_state == GameStates.JOB_MENU:
        job_screen(player, 30, 10, screen_width, screen_height)
Ejemplo n.º 29
0
def render_all(con, panel, entities, player, game_map, fov_map, fov_recompute,
               message_log, screen_width, screen_height, bar_width,
               panel_height, panel_y, mouse, colors, game_state):
    '''
    Renders everything needed in game
    '''
    for y in range(game_map.height):
        for x in range(game_map.width):
            visible = libtcod.map_is_in_fov(fov_map, x, y)
            wall = game_map.tiles[x][y].block_sight

            if visible:
                if wall:
                    libtcod.console_set_char_background(
                        con, x, y, colors.get('light_wall'), libtcod.BKGND_SET)
                else:
                    libtcod.console_set_char_background(
                        con, x, y, colors.get('light_ground'),
                        libtcod.BKGND_SET)

                game_map.tiles[x][y].explored = True

            elif game_map.tiles[x][y].explored:
                if wall:
                    libtcod.console_set_char_background(
                        con, x, y, colors.get('dark_wall'), libtcod.BKGND_SET)
                else:
                    libtcod.console_set_char_background(
                        con, x, y, colors.get('dark_ground'),
                        libtcod.BKGND_SET)

    entities_in_render_order = sorted(entities,
                                      key=lambda x: x.render_order.value)
    # draw all entities in the list
    for entity in entities_in_render_order:
        draw_entity(con, entity, fov_map, game_map)

    libtcod.console_blit(con, 0, 0, screen_width, screen_height, 0, 0, 0)

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

    # print game messages, one line at a time
    y = 1
    for message in message_log.messages:
        libtcod.console_set_default_foreground(panel, message.color)
        libtcod.console_print_ex(panel, message_log.x, y, libtcod.BKGND_NONE,
                                 libtcod.LEFT, message.text)
        y += 1

    # HP bar
    render_bar(panel, 1, 1, bar_width, 'HP', player.fighter.hp,
               player.fighter.max_hp, libtcod.light_red, libtcod.darker_red)

    # bar for dungeon level
    libtcod.console_print_ex(
        panel, 1, 3, libtcod.BKGND_NONE, libtcod.LEFT,
        'Dungeon level: {0}'.format(game_map.dungeon_level))

    libtcod.console_set_default_foreground(panel, libtcod.light_gray)
    libtcod.console_print_ex(panel, 1, 0, libtcod.BKGND_NONE, libtcod.LEFT,
                             get_names_under_mouse(mouse, entities, fov_map))

    libtcod.console_blit(panel, 0, 0, screen_width, panel_height, 0, 0,
                         panel_y)

    # renders inventory menu
    if game_state in (GameStates.SHOW_INVENTORY, GameStates.DROP_INVENTORY):
        if game_state == GameStates.SHOW_INVENTORY:
            inventory_title = 'Press key next to item to use, or Esc to cancel\n'
        else:
            inventory_title = 'Press key next to item to drop, or Esc to cancel\n'

        inventory_menu(con, inventory_title, player, 50, screen_width,
                       screen_height)

    # renders level up menu
    elif game_state == GameStates.LEVEL_UP:
        level_up_menu(con, 'Level up! Choose a stat to raise:\n', player, 40,
                      screen_width, screen_height)

    # renders character screen menu
    elif game_state == GameStates.CHARACTER_SCREEN:
        character_screen(player, 30, 10, screen_width, screen_height)

    # renders shop entrance menu
    elif game_state == GameStates.ENTER_SHOP:
        enter_shop_menu(con, 'Welcome to the shop!\n', player, 40,
                        screen_width, screen_height)

    # renders buying menu for shop
    elif game_state == GameStates.BUYING:
        for entity in entities:
            if entity.shopkeep:
                entity_to_send = entity
        buy_menu(con, '', entity_to_send, 50, screen_width, screen_height)

    # renders selling menu for shop
    elif game_state == GameStates.SELLING:
        sell_menu(con, '', player, 50, screen_width, screen_height)

    # renders rules screen
    elif game_state == GameStates.RULES:
        # open background image
        rules_background = libtcod.image_load('./art/rules_background.png')
        rules_menu(player, rules_background, screen_width, screen_height)
Ejemplo n.º 30
0
def render_all(con, panel, entities, player, game_map, fov_map, fov_recompute, message_log, screen_width, screen_height,
               bar_width, panel_height, panel_y, mouse, colors, game_state):
    if fov_recompute:
        for y in range(game_map.height):
            for x in range(game_map.width):
                visible = libtcod.map_is_in_fov(fov_map, x, y)
                wall = game_map.tiles[x][y].block_sight

                if visible:
                    lighting = 'illuminated' if player.equipment and player.equipment.fov_bonus > 0 else 'shadowed'
                    if wall:
                        libtcod.console_set_char_background(con, x, y, colors.get(f'{lighting}_wall'), libtcod.BKGND_SET)
                    else:
                        libtcod.console_set_char_background(con, x, y, colors.get(f'{lighting}_ground'), libtcod.BKGND_SET)
                    game_map.tiles[x][y].explored = True
                elif game_map.tiles[x][y].explored:
                    if wall:
                        libtcod.console_set_char_background(con, x, y, colors.get('dark_wall'), libtcod.BKGND_SET)
                    else:
                        libtcod.console_set_char_background(con, x, y, colors.get('dark_ground'), libtcod.BKGND_SET)

    entities_in_render_order = sorted(entities, key=lambda x: x.render_order.value)

    # Draw all entities in the list
    for entity in entities_in_render_order:
        draw_entity(con, entity, fov_map, game_map)

    # Cast a spooky shadow under the ghost/possessed creature
    libtcod.console_set_char_background(con, player.x, player.y, colors.get('dark_ground'), libtcod.BKGND_SET)

    libtcod.console_set_default_foreground(con, libtcod.white)
    if player.fighter:
        libtcod.console_print_ex(con, 1, screen_height - 2, libtcod.BKGND_NONE, libtcod.LEFT, 'HP: {0:02}/{1:02}'.format(player.fighter.hp, player.fighter.max_hp))

    libtcod.console_blit(con, 0, 0, screen_width, screen_height, 0, 0, 0)

    if game_state in (GameStates.SHOW_INVENTORY, GameStates.DROP_INVENTORY):
        if game_state == GameStates.SHOW_INVENTORY:
            inventory_title = 'Press the key next to an item to use it, or Esc to cancel.\n'
        else:
            inventory_title = 'Press the key next to an item to drop it, or Esc to cancel.\n'

        inventory_menu(con, inventory_title, player, 50, screen_width, screen_height)

    elif game_state == GameStates.LEVEL_UP:
        level_up_menu(con, 'Level up!', player, 40, screen_width, screen_height)

    elif game_state == GameStates.CHARACTER_SCREEN:
        character_screen(player, 30, 10, screen_width, screen_height)

    elif game_state == GameStates.PLAYER_DEAD:
        death_screen(30, 10, screen_width, screen_height)

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

    # Print the game messages, one line at a time
    y = 1
    for message in message_log.messages:
        libtcod.console_set_default_foreground(panel, message.color)
        libtcod.console_print_ex(panel, message_log.x, y, libtcod.BKGND_NONE, libtcod.LEFT, message.text)
        y += 1

    if player.fighter:
        if player.possessed_entity and player.possessed_entity.name:
            centered_name = player.possessed_entity.name.center(20)
        else:
            centered_name = "???".center(20)
        libtcod.console_set_default_foreground(panel, libtcod.white)
        libtcod.console_print_ex(panel, 1, 1, libtcod.BKGND_NONE, libtcod.LEFT,
            centered_name)

        render_bar(panel, 1, 2, bar_width, 'HP', player.fighter.hp, player.fighter.max_hp,
            libtcod.light_red, libtcod.darker_red)

    libtcod.console_print_ex(panel, 1, 3, libtcod.BKGND_NONE, libtcod.LEFT,
                             'Dungeon level: {0}'.format(game_map.dungeon_level))

    libtcod.console_set_default_foreground(panel, libtcod.light_gray)
    libtcod.console_print_ex(panel, 1, 0, libtcod.BKGND_NONE, libtcod.LEFT,
                             get_names_under_mouse(mouse, entities, fov_map))

    libtcod.console_blit(panel, 0, 0, screen_width, panel_height, 0, 0, panel_y)
Ejemplo n.º 31
0
def render_all(con, panel, entities, player, game_map, fov_map, fov_recompute,
               message_log, screen_width, screen_height, bar_width,
               panel_height, panel_y, mouse, colors, game_state):
    if fov_recompute:
        # Draw all the tiles in the game map
        for y in range(game_map.height):
            for x in range(game_map.width):
                visible = libtcod.map_is_in_fov(fov_map, x, y)
                wall = game_map.tiles[x][y].block_sight

                if visible:
                    if wall:
                        libtcod.console_set_char_background(
                            con, x, y, colors.get('light_wall'),
                            libtcod.BKGND_SET)
                    else:
                        libtcod.console_set_char_background(
                            con, x, y, colors.get('light_ground'),
                            libtcod.BKGND_SET)

                    game_map.tiles[x][y].explored = True
                elif game_map.tiles[x][y].explored:
                    if wall:
                        libtcod.console_set_char_background(
                            con, x, y, colors.get('dark_wall'),
                            libtcod.BKGND_SET)
                    else:
                        libtcod.console_set_char_background(
                            con, x, y, colors.get('dark_ground'),
                            libtcod.BKGND_SET)

    entities_in_render_order = sorted(entities,
                                      key=lambda x: x.render_order.value)

    # Draw all entities in the list
    for entity in entities_in_render_order:
        draw_entity(con, entity, fov_map, game_map)

    libtcod.console_set_default_foreground(con, libtcod.white)
    libtcod.console_print_ex(
        con, 1, screen_height - 2, libtcod.BKGND_NONE, libtcod.LEFT,
        "HP: {0:02}/{1:02}".format(player.fighter.hp, player.fighter.max_hp))

    libtcod.console_blit(con, 0, 0, screen_width, screen_height, 0, 0, 0)

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

    y = 1
    for message in message_log.messages:
        libtcod.console_set_default_foreground(panel, message.color)
        libtcod.console_print_ex(panel, message_log.x, y, libtcod.BKGND_NONE,
                                 libtcod.LEFT, message.text)
        y += 1

    render_bar(panel, 1, 1, bar_width, "HP", player.fighter.hp,
               player.fighter.max_hp, libtcod.light_red, libtcod.darker_red)

    render_bar(panel, 1, 2, bar_width, "EXP", player.level.current_xp,
               player.level.experience_to_next_level, libtcod.light_blue,
               libtcod.darker_blue)

    libtcod.console_print_ex(
        panel, 1, 4, libtcod.BKGND_NONE, libtcod.LEFT,
        "Dungeon Level: {0}".format(game_map.dungeon_level))

    libtcod.console_set_default_foreground(panel, libtcod.light_gray)
    libtcod.console_print_ex(panel, 1, 0, libtcod.BKGND_NONE, libtcod.LEFT,
                             get_names_under_mouse(mouse, entities, fov_map))

    libtcod.console_blit(panel, 0, 0, screen_width, panel_height, 0, 0,
                         panel_y)

    if game_state in (GameStates.SHOW_INVENTORY, GameStates.DROP_INVENTORY):
        if game_state == GameStates.SHOW_INVENTORY:
            inventory_title = "Press the key next to an item to use it, or ESC to cancel.\n"
        else:
            inventory_title = "Press the key next to an item to drop it, or ESC to cancel.\n"

        inventory_menu(con, inventory_title, player, 50, screen_width,
                       screen_height)

    elif game_state == GameStates.SHOW_EQUIPMENT_INVENTORY:
        equipment_inventory_menu(
            con,
            "Press the key next to an item to equip it, or ESC to cancel.\n",
            player.equipment_inventory, 50, screen_width, screen_height)

    elif game_state == GameStates.LEVEL_UP:
        level_up_menu(con, "Level up! Choose a stat to raise:", player, 40,
                      screen_width, screen_height)

    elif game_state == GameStates.CHARACTER_SCREEN:
        character_screen(player, 30, 10, screen_width, screen_height)

    elif game_state == GameStates.SHOW_BAG:
        bag_title = "Press the key next to the option to open the bag.\n"

        bag_menu(con, bag_title, player, 50, screen_width, screen_height)

    elif game_state == GameStates.HELP_MENU:
        help_menu(player, 30, 10, screen_width, screen_height)