Example #1
0
    def target_tile(max_range=None):
        box = libtcod.console_new(1, 1)
        x = Game.player.x
        y = Game.player.y
        libtcod.console_set_default_background(box, libtcod.orange)
        libtcod.console_clear(box)
        key = Game.key

        while (x, y) != (0, 0):
            Game.renderer.render_all()
            Game.renderer.render_names_under_target(x, y)
            Game.renderer.render_target_tile(box, x, y)

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

            direction = Game.get_direction(key)
            if direction is not None:
                x += direction[0]
                y += direction[1]

            else:
                return (None, None)

            if direction == (0, 0):
                if Game.map.is_tile_in_fov(x, y) and (max_range is None or Game.player.distance(x, y) <= max_range):
                    return (x, y)
                else:
                    Game.message('That is out of range.', libtcod.red)
Example #2
0
    def show_menu(self, options, header, hide_options=False):
        """ Show menu with header and options in the screen. """

        #calculate total height for the header (after auto-wrap)
        header_height = libtcod.console_get_height_rect(self.inv_window, 0, 0, MAP_WIDTH,
                                                        MAP_HEIGHT, header)

        #print the header, with auto-wrap
        libtcod.console_set_default_foreground(self.inv_window, libtcod.white)
        libtcod.console_print_rect_ex(self.inv_window, 0, 0, MAP_WIDTH, MAP_HEIGHT,
                                      libtcod.BKGND_NONE, libtcod.LEFT, header)

        #print all the options
        y = header_height
        for (option_key, option_text) in options:
            if hide_options is True:
                text = option_text
            else:
                text = '(' + option_key + ') ' + option_text
            libtcod.console_print_ex(self.inv_window, 0, y,
                                     libtcod.BKGND_NONE, libtcod.LEFT, text)
            y += 1

        #blit the contents of "self.inv_window" to the root console
        x, y, _ = SCREEN_RECT.top_left.coords
        libtcod.console_blit(self.inv_window, 0, 0, MAP_WIDTH, MAP_HEIGHT, 0, x, y, 1.0, 0.7)
        libtcod.console_flush()
        libtcod.console_clear(self.inv_window)
Example #3
0
 def render(self):
     libtcod.console_set_default_background(0, libtcod.black)
     libtcod.console_set_default_background(self.panel, libtcod.black)
     libtcod.console_clear(0)
     libtcod.console_clear(self.panel)
     self.screens[-1].render()
     libtcod.console_blit(self.panel, 0, 0, self.screen_width, self.screen_height, 0, 0, 0, 1, 1)
Example #4
0
def render_all():
	# Go through all Tiles, and set their character and color.
	for y in range(MAP_HEIGHT):
		for x in range(MAP_WIDTH):
			# Draw it.
			libtcod.console_put_char_ex(con, x, y, map[x][y].char, map[x][y].color, libtcod.black)
					
	# Draw all objects in the list.
	for object in objects:
		object.draw()
		
	# Blit the contents of "con" to the root console.
	libtcod.console_blit(con, 0, 0, SCREEN_WIDTH, SCREEN_HEIGHT, 0, 0, 0)
		
	# Prepare to render the GUI panel.
	libtcod.console_set_default_background(panel, libtcod.black)
	libtcod.console_clear(panel)
	
	# Show the player's stats.
	libtcod.console_set_default_foreground(panel, libtcod.red)
	libtcod.console_print_ex(panel, 1, 1, libtcod.BKGND_NONE, libtcod.LEFT, 'Lives: ' + str(player.lives) + '/' + str(player.max_lives))
	libtcod.console_set_default_foreground(panel, libtcod.white)
	libtcod.console_print_ex(panel, 1, 3, libtcod.BKGND_NONE, libtcod.LEFT, 'Level ' + str(level_number))
		
	# Blit the contents of "panel" to the root console.
	libtcod.console_blit(panel, 0, 0, SCREEN_WIDTH, PANEL_HEIGHT, 0, 0, PANEL_Y)
Example #5
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)
Example #6
0
def play_game():
	player_action = None
	
	while not libtcod.console_is_window_closed():
		# Render the screen.
		render_all()
		
		libtcod.console_flush()
		
		# Clean the console.
		libtcod.console_clear(con)
		
		# Handle keys and exit game if needed.
		player_action = handle_keys()
		if player_action == 'exit':
			break
		
		# Let the monsters take their turn.
		if game_state == 'playing' or game_state == 'custom playing':
			for object in objects:
				if object.ai:
					if object.wait > 0:
						object.wait -= 1
					else:
						object.ai.take_turn()
						object.wait = object.speed
Example #7
0
def main_menu():
	while not libtcod.console_is_window_closed():
		libtcod.console_disable_keyboard_repeat()
		libtcod.console_set_default_background(0, libtcod.black)
		libtcod.console_set_default_foreground(0, libtcod.black)
		libtcod.console_clear(0)
	
		# Show the game's title, and some credits!
		libtcod.console_set_default_foreground(0, libtcod.light_yellow)
		libtcod.console_print_ex(0, SCREEN_WIDTH / 2, SCREEN_HEIGHT / 2 - 4, libtcod.BKGND_NONE, libtcod.CENTER, 'BALL LABYRINTH')
		libtcod.console_print_ex(0, SCREEN_WIDTH / 2, SCREEN_HEIGHT - 2, libtcod.BKGND_NONE, libtcod.CENTER, 'By Eric Williams')
		
		# Show options and wait for the player's choice.
		choice = menu('', ['Play a new game', 'Load saved game', 'Play custom level', 'Quit'], 24)
		
		if choice == 0: # New game.
			new_game()
			libtcod.console_set_keyboard_repeat(5, 5)
			play_game()
		elif choice == 1: # Load saved game.
			loaded = load_game()
			if loaded:
				libtcod.console_set_keyboard_repeat(5, 5)
				play_game()
		elif choice == 2: # Open the test arena level.
			custom = new_custom_game()
			if custom:
				libtcod.console_set_keyboard_repeat(5, 5)
				play_game()
		elif choice == 3: # Quit.
			break
Example #8
0
def panel2_display():
    str_s = 'Str:' + str(player.fighter.status.Str)
    con_s = 'Con:' + str(player.fighter.status.Con)
    dex_s = 'Dex:' + str(player.fighter.status.Dex)
    int_s = 'Int:' + str(player.fighter.status.Int)
    car_s = player.fighter.status.career
    panel2_msgs = [player.name, str_s, con_s, dex_s, int_s, ' ', 'career', car_s, ' ']
    skill_msgs = ['Skills:']
    #print skills
    s = player.fighter.total_skills
    for index in s:
        skill_msgs.append(str(index) + ')' + s[index][0] + ' [' + s[index][1] + ']')

    passive_msgs = ['','Passive:']
    #print passive
    for index in player.fighter.status.passives:
        passive_msgs.append(player.fighter.status.passives[index])
    
    panel2_msgs.extend(skill_msgs)
    panel2_msgs.extend(passive_msgs)
    
    libtcod.console_set_default_background(panel2, libtcod.black)
    libtcod.console_clear(panel2)
    
    y = 1
    for lines in panel2_msgs:
        libtcod.console_set_default_foreground(panel2, libtcod.white)
        libtcod.console_print_ex(panel2, 0, y, libtcod.BKGND_NONE, libtcod.LEFT, lines)
        y += 1
   
    libtcod.console_blit(panel2, 0 , 0, PANEL2_WIDTH, PANEL2_HEIGHT, 0 ,PANEL2_X, 0)
Example #9
0
	def draw(self):
		libtcod.console_set_alignment(0, libtcod.CENTER)
		libtcod.console_print(0, self.text_base[0], self.text_base[1], self.title_text)
		libtcod.console_print(0, self.text_base[0], self.text_base[1] + 2, "a  " + self.option_one_text)
		libtcod.console_print(0, self.text_base[0], self.text_base[1] + 4, "b  " + self.option_two_text)
		libtcod.console_flush()
		libtcod.console_clear(0)
Example #10
0
def new_game():
    global game_msgs, game_state
    
    map_number = 0
    list_of_maps = []

    #generate map, but at this point it's not drawn to the screen    
    newmap, objects_for_this_map = make_bare_surface_map() # a fresh level!

    # Append this new level to the list_of_maps, and then append all the objects to that GameMap's
    # object list.
    list_of_maps.append( GameMap(map_number, newmap, 'surface') )
    for item in objects_for_this_map:
                list_of_maps[map_number].objects.append(item)

    list_of_maps[map_number].initialize_fov()
    libtcod.console_clear(con)


    game_state = 'playing'
    # Inventory assignment used to be here ("inventory = []") but now the list gets created on the line above where we create
    # the player gamepiece. 
    
    #create the list of game messages and their colors.

    message('Welcome to Mars! This is a test of a roguelike game engine in Python and Libtcod. Push h for help.',\
            libtcod.red)

    return list_of_maps, map_number
Example #11
0
File: r3.py Project: tanadrin/ma_py
    def render_all(self):
        libtcod.console_clear(self.con)

        for y in range(self.CAMERA_HEIGHT):
            for x in range(self.CAMERA_WIDTH):
                #First, get the absolute map coordinates of whatever's in view
                (map_x, map_y) = (self.camera.x + x - self.CAMERA_WIDTH/2, self.camera.y + y - self.CAMERA_HEIGHT/2)
                #Then, get which chunk it's on, and where on that chunk it is
                chunk_count_x, chunk_count_y, local_x, local_y = self.to_chunk_and_local_coords(map_x, map_y)
                #Now, render the appropriate char based on the coords
                libtcod.console_put_char(self.con, x, y, self.map.map[chunk_count_x][chunk_count_y].chunk[local_x][local_y].char, libtcod.BKGND_NONE)
                libtcod.console_set_char_foreground(self.con, x, y, self.map.map[chunk_count_x][chunk_count_y].chunk[local_x][local_y].color)
                    
        #Draw all objects in range of the player to be active
        self.active_objects = self.get_active_objects()
        for object in self.active_objects:
            self.draw_object(object)

        if self.cursor!= None:
            self.draw_object(self.cursor)
     
        #blit the contents of "con" to the root console
        libtcod.console_blit(self.con, 0, 0, self.SCREEN_WIDTH, self.SCREEN_HEIGHT, 0, 0, 0)

        #blit the infobar to the root console
        self.refresh_infobar(self.infobar)
        libtcod.console_blit(self.infobar, 0, 0, self.SCREEN_WIDTH, self.SCREEN_HEIGHT, 0, 0, self.SCREEN_HEIGHT - 1)

        #if we're showing the right-side menu, show it
        if self.show_menu == True:
            self.refresh_menu(self.menu)
            libtcod.console_blit(self.menu, 0, 0, self.SCREEN_WIDTH, self.SCREEN_HEIGHT, 0, self.SCREEN_WIDTH - self.MENU_WIDTH, 0)
Example #12
0
def disable_panels():
	tcod.console_clear(0)
	tcod.console_clear(MESSAGE_WINDOW)
	
	SETTINGS['draw life info'] = False
	
	remove_view_from_scene_by_name('message_box')
def _draw_fov_using_terrain(player):
    """
    Overly optimized: this code inlines Map.terrain_at(), Map.is_explored(),
    and ScreenCoords.toWorldCoords() in order to get a 2.5x speedup on
    large maps.
    """
    libtcod.console_clear(_con)
    current_map = player.current_map
    pos = algebra.Location(0, 0)
    for screen_y in range(min(current_map.height, config.MAP_PANEL_HEIGHT)):
        pos.set(player.camera_position.x, player.camera_position.y + screen_y)
        for screen_x in range(min(current_map.width, config.MAP_PANEL_WIDTH)):
            # pos = ScreenCoords.toWorldCoords(player.camera_position, (screen_x, screen_y))
            visible = libtcod.map_is_in_fov(current_map.fov_map, pos.x, pos.y)
            # terrain = current_map.terrain_at(pos)
            terrain = map.terrain_types[current_map.terrain[pos.x][pos.y]]
            if not visible:
                # if current_map.is_explored(pos):
                if current_map._explored[pos.x][pos.y]:
                    libtcod.console_set_char_background(_con, screen_x, screen_y,
                                                        terrain.unseen_color, libtcod.BKGND_SET)
            else:
                libtcod.console_set_char_background(_con, screen_x, screen_y,
                                                    terrain.seen_color, libtcod.BKGND_SET)
                current_map.explore(pos)
            pos.x += 1
Example #14
0
	def draw(self):
		libtcod.console_clear(self.console)

		for y in range(len(self.entity_manager.world_tiles)):
			for x in range(len(self.entity_manager.world_tiles[y])):
				self.draw_world_tile(x, y, self.entity_manager.world_tiles[x][y]['tile'])
		#handy thing about this is it should help farther down the line when I go to implement FOV
		render_data = []
		for id, entity in self.entity_manager.entities.iteritems():
			if entity.get_attribute(AttributeTag.Visible):
				position_info = entity.get_attribute(AttributeTag.WorldPosition)
				if not position_info:
					raise LookupError('entity ' + str(entity) + ' is flagged as visible, but does not have any world position')
				draw_info = entity.get_attribute(AttributeTag.DrawInfo)			
				if not draw_info:
					raise LookupError('entity ' + str(entity) + ' is flagged as visible, but does not have any draw info')
				render_data.append({'draw_type': draw_info.data['draw_type'], 'z_level':draw_info.data['z_level'],'entity': entity})

		#z-sort the entities we're rendering so that things like world tiles can be drawn behind entities on those tiles
		render_data.sort(lambda data,other: cmp(data['z_level'], other['z_level']))


		for to_render in render_data:
			if to_render['draw_type'] in render_type_dict:
				render_type_dict[to_render['draw_type']](self, to_render['entity'])

		libtcod.console_blit(self.console, 0, 0, self.width, self.height, 0, self.world_x_start, self.world_y_start)
def draw_panel(player, pointer_location):
    """
    Refreshes the UI display and blits it to the window.
    """
    libtcod.console_set_default_background(_panel, libtcod.black)
    libtcod.console_clear(_panel)

    # Only display the (log.MSG_HEIGHT) most recent
    write_log(log.game_msgs[-log.MSG_HEIGHT:], _panel, MSG_X, 1)

    _render_bar(1, 1, config.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 ' + str(player.current_map.dungeon_level))
    # _debug_positions(player, mouse)
    # _debug_room(player)
    # _debug_danger(player)
    _debug_fps()

    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(player, pointer_location))

    # Done with "_panel", blit it to the root console.
    libtcod.console_blit(_panel, 0, 0, config.SCREEN_WIDTH, config.PANEL_HEIGHT,
                         0, 0, PANEL_Y)
Example #16
0
 def render_all(self):
     tcod.console_clear(0)
     render_conway_sim(self.conway)
     self.render_players()
     self.render_ball()
     self.render_scores()
     self.render_fps()
Example #17
0
def main_menu():
    #Set up the main menu, which is presented to the player when they first load the game
    img = libtcod.image_load('images/menu_background1.png')

    while not libtcod.console_is_window_closed():
        #Show the image at twice its usual resolution of the console
        libtcod.image_blit_2x(img, 0, SCREEN_WIDTH / 6, SCREEN_HEIGHT / 6)

        #Show the games title, and some credits
        libtcod.console_set_default_foreground(0, libtcod.light_yellow)
        libtcod.console_print_ex(0, SCREEN_WIDTH / 2, SCREEN_HEIGHT / 2 - 4, libtcod.BKGND_NONE, libtcod.CENTER,
            'DUNGEONCRAWLER')
        libtcod.console_print_ex(0, SCREEN_WIDTH / 2, SCREEN_HEIGHT - 2, libtcod.BKGND_NONE, libtcod.CENTER,
            'By Jeremy Cerise')

        #Show menu options and wait for the players choice
        choice = menu('', ['Play a new game', 'Continue last game', 'Quit'], 24)

        if choice == 0:
            #Start a new game
            #Clear the base conosle, so the menu image and options don't show up under the rest of the UI
            libtcod.console_set_default_background(0, libtcod.brass)
            libtcod.console_clear(0)
            new_game()
            play_game()
        elif choice == 1:
            try:
                libtcod.console_set_default_background(0, libtcod.brass)
                libtcod.console_clear(0)
                load_game()
            except:
                msgbox('\n No saved game to load!\n', 24)
        elif choice == 2:
            #Exit the program
            break;
Example #18
0
def render_gui():
    """ Renders just the gui. """

    # Set globals.
    global turns, game_messages

    # Clear console before drawing on it.
    roguelib.console_set_default_background(console_gui, roguelib.black)
    roguelib.console_clear(console_gui)

    # Display health and energy bars for player.
    render_bar(console_gui, 1, 1, BAR_WIDTH, "HP", player.alive.hp, player.alive.maxhp, roguelib.dark_flame,
               roguelib.dark_grey, roguelib.white)
    render_bar(console_gui, 1, 3, BAR_WIDTH, "Energy", player.alive.energy, player.alive.maxenergy, roguelib.dark_green,
               roguelib.dark_grey, roguelib.white)

    # Prints number of turns and dungeon level on screen.
    roguelib.console_set_default_foreground(console_gui, eval(SETTING_DATA[b"Text Color"][b"COLOR"]))
    roguelib.console_print(console_gui, SCREEN_WIDTH - 15, 2, "Turns:" + str(turns))
    roguelib.console_print(console_gui, SCREEN_WIDTH // 2, 2, "Depth:" + str(depth))

    # Display messages in message box.
    y = 1
    for (line, color) in game_messages:
        roguelib.console_set_default_foreground(console_message, color)
        roguelib.console_print_ex(console_message, 0, y, roguelib.BKGND_NONE, roguelib.LEFT, line)
        y += 1

    # Blit contents of consoles to screen.
    roguelib.console_blit(console_gui, 0, 0, SCREEN_WIDTH, CONSOLE_GUI_HEIGHT, 0, 0, 0)
    roguelib.console_blit(console_message, 0, 0, SCREEN_WIDTH, MESSAGE_CONSOLE_HEIGHT, 0, 0, MESSAGE_CONSOLE_Y)
Example #19
0
File: gui.py Project: jcandres/deth
def draw_main_menu(con, has_file=False):
    tcod.console_set_default_foreground(con, COL_A)
    img = tcod.image_load('small.png')
    tcod.image_set_key_color(img, tcod.red)
    tcod.image_blit(img, 0, 45, 30,  tcod.BKGND_LIGHTEN, .5, .25, 0)
    
    xx=-20
    yy=15
    
    can_cont = ""
    can_del = ''
    if has_file:
        can_cont = '-- (c)ontinue'
        can_del = '-- (D)elete'
    options=(
             """
             GAME TITLE """+chr(tcod.CHAR_BLOCK2)+chr(tcod.CHAR_BLOCK1)+chr(tcod.CHAR_BLOCK1)+"""
             |
             |
             \t-- (n)ew game
             |
             \t--\t%s
             |  |
             |  \t%s
             |
             \t-- (esc)cape
             """
             % (can_cont, can_del)
            )
    tcod.console_print_ex(con, game.GAME_WIDTH/4+xx, game.GAME_HEIGHT/3+yy,
                              tcod.BKGND_LIGHTEN, tcod.LEFT,options)
    
    tcod.console_print(con, 2, game.GAME_HEIGHT-2, 'oyyooyoyoyoyyooyoyoy')
    tcod.console_flush()
    tcod.console_clear(con)
Example #20
0
File: gui.py Project: hkwu/BOGEY
    def draw(self):
        """Draws borders around the info panel."""
        libt.console_set_default_background(self.handler.gui, data.COLOURS['gui_bg'])
        libt.console_clear(self.handler.gui)

        upper_height = config.BORDER_WIDTH / 2
        left_height = config.GUI_HEIGHT - upper_height*2

        libt.console_set_default_background(self.handler.gui, data.COLOURS['gui_border'])
        # Upper border
        libt.console_rect(self.handler.gui, 0, 0, config.GUI_WIDTH, upper_height, 
                          False, libt.BKGND_SCREEN)
        # Lower border
        libt.console_rect(self.handler.gui, 0, config.GUI_HEIGHT - config.BORDER_WIDTH/2,  
                          config.GUI_WIDTH, upper_height, False, libt.BKGND_SCREEN)
        # Left border
        libt.console_rect(self.handler.gui, 0, upper_height, config.BORDER_WIDTH / 2, 
                          left_height, False, libt.BKGND_SCREEN)
        # Right border
        libt.console_rect(self.handler.gui, config.GUI_WIDTH - config.BORDER_WIDTH/2, upper_height, 
                          config.BORDER_WIDTH / 2, left_height, False, libt.BKGND_SCREEN)
        # Middle border
        libt.console_rect(self.handler.gui, (config.GUI_WIDTH - 1)/2 - config.BORDER_WIDTH/2, upper_height, 
                          config.BORDER_WIDTH, left_height, False, libt.BKGND_SCREEN)

        # Hover details
        libt.console_set_default_foreground(self.handler.gui, data.COLOURS['text'])
        libt.console_print_ex(self.handler.gui, (config.GUI_WIDTH - 1)/2, 0,
                              libt.BKGND_NONE, libt.CENTER, self.objects_under_mouse())
Example #21
0
def stat_menu():
	""" |  Shows a menu displaying the Player's Stats and a possibility to distribute EXP Points.
		|  Derives from menu()
	"""

	libtcod.console_clear(gvar.window)
	text = 'Skills:\n\n'
	text2 = ''
	for skill in sorted(gvar.game.player.fighter.skills):
		text += ' ' + skill + '\n'
		text2 += str(gvar.game.player.fighter.skills[skill]) + '\n'
	menu_supplement(text, gvar.SCREEN_WIDTH/2, 2)
	menu_supplement(text2, gvar.SCREEN_WIDTH/2 + 15, 4)
	return menu('Character Sheet\n\nExperience: ' + str(gvar.game.player.exp) +
		'\n\nHealth Levels:' +
		'\n-0: ' + str(gvar.game.player.fighter.max_hl[0]) +
		'\n-1: ' + str(gvar.game.player.fighter.max_hl[1]) +
		'\n-2: ' + str(gvar.game.player.fighter.max_hl[2]) +
		'\n-4: ' + str(gvar.game.player.fighter.max_hl[3]) +
		'\n\nStrength:  ' + str(gvar.game.player.fighter.strength) +
		'\nDexterity: ' + str(gvar.game.player.fighter.dexterity) +
		'\nStamina:   ' + str(gvar.game.player.fighter.stamina) +
		'\n\nSoak (B/L): ' + str(gvar.game.player.fighter.bashing_soak()) + '/' + str(gvar.game.player.fighter.lethal_soak()) +
		'\nDodge DV: ' + str(gvar.game.player.fighter.dodgeDV()) +
		'\n\n\n\n\n\n\n\n\n\n\n\n', ['Distribute experience points'], gvar.SCREEN_WIDTH, libtcod.darker_grey, flush=False)
Example #22
0
def renderAll():
	global fovNeedsToBeRecomputed

	if fovNeedsToBeRecomputed:
		#If this is true, then we must recalculate the field of view and render the map.
		fovNeedsToBeRecomputed = False
		libtcod.map_compute_fov(fovMap, player.x, player.y, TORCH_RADIUS, FOV_LIGHT_WALLS, FOV_ALGO)
		
		#Iterate through the list of map tiles and set their background colors.
		for y in range(MAP_HEIGHT):
			for x in range(MAP_WIDTH):
				visible = libtcod.map_is_in_fov(fovMap, x, y)
				wall = map[x][y].blockSight
				if not visible:
					#If a tile is out of the player's field of view...
					if map[x][y].explored:
						#...it will only be drawn if the player has explored it
						if wall:
							libtcod.console_set_char_background(con, x, y, cDarkWall, libtcod.BKGND_SET)
						else:
							libtcod.console_set_char_background(con, x, y, cDarkGround, libtcod.BKGND_SET)
				else:
					#If a tile is in the player's field of view...
					if wall:
						libtcod.console_set_char_background(con, x, y, cLitWall, libtcod.BKGND_SET)
					else:
						libtcod.console_set_char_background(con, x, y, cLitGround, libtcod.BKGND_SET)
					map[x][y].explored = True
	
	#Draw all objects in the list, except the player, which needs to be drawn last.
	for object in objects:
		if object != player:
			object.draw()
	player.draw()
		
	#Blit the contents of con to the root console.
	libtcod.console_blit(con, 0, 0, MAP_WIDTH, MAP_HEIGHT, 0, 0, 0)
	
	#Prepare to render the status panel.
	libtcod.console_set_default_background(panel, libtcod.black)
	libtcod.console_clear(panel)
	
	#Print the message log, one line at a time.
	y = 1
	for (line, color) in messageLog:
		libtcod.console_set_default_foreground(panel, color)
		libtcod.console_print_ex(panel, MESSAGE_X, y, libtcod.BKGND_NONE, libtcod.LEFT, line)
		y += 1
	
	#Show the player's stats
	renderStatusBar(1, 1, BAR_WIDTH, "Health", player.fighter.cond, player.fighter.hits, libtcod.red, libtcod.darkest_red)
	
	libtcod.console_print_ex(panel, 1, 3, libtcod.BKGND_NONE, libtcod.LEFT, "Dungeon Level: " + str(dungeonLevel))
	
	#Display the names of objects 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, getNamesUnderMouse())
	
	#Blit the contents of panel to the root console.
	libtcod.console_blit(panel, 0, 0, SCREEN_WIDTH, PANEL_HEIGHT, 0, 0, PANEL_Y)
Example #23
0
 def display(self, console):
     libtcod.console_clear(console)
     self.display_string(console, 1, self.menu.current_branch.label)
     i = 3
     for item in self.menu.current_branch.children:
         i = i + 1
         self.display_string(console, i, item.label)
Example #24
0
def admin_menu():
	""" Shows an admin menu fpr debugging purposes """
	libtcod.console_clear(gvar.window)
	menu_supplement("Current Dungeon: " + str(gvar.game.player.currentmap().owner.id), 2, gvar.SCREEN_HEIGHT-2)
	choice = menu('Admin Menu', ['Toggle FOV'], gvar.SCREEN_WIDTH, libtcod.desaturated_red, flush=False)
	if choice == 0:
		gvar.admin.light_all = False if gvar.admin.light_all else True
Example #25
0
def renderAll(objects, player, con, panel, infobar):
   # draw objects without actors first
   for object in objects:
      if not object.actor:
         object.graphic.draw(con)
   for object in objects:
      if object.actor:
         object.graphic.draw(con)
   
   libtcod.console_blit(con, 0, 0, SCREEN_WIDTH, GAME_HEIGHT, 0, 0, GAME_Y)

   # do panel stuff
   libtcod.console_set_default_background(panel, PANEL_BACKGROUND_COLOUR)
   libtcod.console_clear(panel)
 
   # print the current game message
   libtcod.console_set_default_foreground(panel, getMessageColour())
   libtcod.console_print_rect(panel, 1, 1, SCREEN_WIDTH-1, PANEL_HEIGHT, getMessage())
   
   # blit the panel to the screen
   libtcod.console_blit(panel, 0, 0, SCREEN_WIDTH, PANEL_HEIGHT, 0, 0, PANEL_Y)

   # do info bar stuff
   libtcod.console_set_default_background(infobar, INFO_BAR_BACKGROUND_COLOUR)
   libtcod.console_clear(infobar)
   
   # print their current money and the time
   libtcod.console_set_default_foreground(infobar, getMoneyColour(player.actor.money))
   libtcod.console_print_rect(infobar, SCREEN_WIDTH/2 - 3, 0, SCREEN_WIDTH, INFO_BAR_HEIGHT, "$"+str(player.actor.money))
   libtcod.console_set_default_foreground(infobar, getTimeColour())
   libtcod.console_print_rect(infobar, SCREEN_WIDTH/2 + 3, 0, SCREEN_WIDTH, INFO_BAR_HEIGHT, getTimeString())
   
   libtcod.console_blit(infobar, 0, 0, SCREEN_WIDTH, INFO_BAR_HEIGHT, 0, 0, INFO_BAR_Y)
Example #26
0
def main_menu():
    img = libtcod.image_load('title.png')

    while not libtcod.console_is_window_closed():
        # show the background image, at twice the regular console resolution
        libtcod.image_blit_2x(img, 0, 0, 0)

        # show the game's title, and some credits!
        libtcod.console_set_default_foreground(0, libtcod.black)
        libtcod.console_print_ex(0, SCREEN_WIDTH / 2, int(SCREEN_HEIGHT * .75), libtcod.BKGND_NONE, libtcod.CENTER, 'WizRL')
        libtcod.console_print_ex(0, SCREEN_WIDTH / 2, int(SCREEN_HEIGHT * .75) + 2, libtcod.BKGND_NONE, libtcod.CENTER, 'By Dragyn')

        # show options and wait for the player's choice
        choice = menu('', ['Play a new game', 'Continue last game', 'Quit'], 24)

        if choice == 0:  # new game
            libtcod.console_clear(0)
            new_game()
            play_game()
        if choice == 1:  # load last game
            try:
                load_game()
            except:
                msgbox('\n No saved game to load.\n', 24)
                continue
            play_game()
        elif choice == 2:  # quit
            break
Example #27
0
def render_all():
    global fov_map, color_dark_wall, color_light_wall
    global color_dark_ground, color_light_ground
    global fov_recompute

    if fov_recompute:
        # recompute FOV if needed (the player moved or something)
        fov_recompute = False
        libtcod.map_compute_fov(fov_map, player.x, player.y, TORCH_RADIUS, FOV_LIGHT_WALLS, FOV_ALGO)

        # go through all tiles, and set their background color according to the FOV
        for y in range(MAP_HEIGHT):
            for x in range(MAP_WIDTH):
                visible = libtcod.map_is_in_fov(fov_map, x, y)
                wall = map[x][y].block_sight
                if not visible:
                    # if it's not visible right now, the player can only see it if it's explored
                    if map[x][y].explored:
                        if wall:
                            libtcod.console_set_char_background(con, x, y, color_dark_wall, libtcod.BKGND_SET)
                        else:
                            libtcod.console_set_char_background(con, x, y, color_dark_ground, libtcod.BKGND_SET)
                else:
                    # it's visible
                    if wall:
                        libtcod.console_set_char_background(con, x, y, color_light_wall, libtcod.BKGND_SET)
                    else:
                        libtcod.console_set_char_background(con, x, y, color_light_ground, libtcod.BKGND_SET)
                    # since it's visible, explore it
                    map[x][y].explored = True

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

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

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

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

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

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

    # blit GUI to screen
    libtcod.console_blit(panel, 0, 0, SCREEN_WIDTH, PANEL_HEIGHT, 0, 0, PANEL_Y)
Example #28
0
def splashScreen(console):
   libtcod.console_set_default_background(console, SPLASH_BACKGROUND_COLOUR)
   libtcod.console_clear(console)
   
   done = False
   counter = 0
   blinkOn = True
   blinkSpeed = 10

   while not done and not libtcod.console_is_window_closed():
      key = libtcod.console_check_for_keypress(True)
      if not key.vk == libtcod.KEY_NONE:
         done = True

      #print the splash messages
      libtcod.console_set_default_foreground(console, SPLASH_FOREGROUND_COLOUR1)
      libtcod.console_print_rect(console, 4, 5, SCREEN_WIDTH, SCREEN_HEIGHT, "SWORD SHOP")
      libtcod.console_set_default_foreground(console, SPLASH_FOREGROUND_COLOUR2)
      libtcod.console_print_rect(console, 4, 8, SCREEN_WIDTH, SCREEN_HEIGHT, "by luke david\n   fitzpatrick")
      if(blinkOn):
         libtcod.console_set_default_foreground(console, SPLASH_FOREGROUND_COLOUR3)
         libtcod.console_print_rect(console, 16, 13, SCREEN_WIDTH, SCREEN_HEIGHT, "press any key")

      # blit the panel to the screen
      libtcod.console_blit(console, 0, 0, SCREEN_WIDTH, SCREEN_HEIGHT-(2*6), 0, 0, 6)   
      
      libtcod.console_flush()

      counter += 1
      if counter >= blinkSpeed:
         counter = 0
         blinkOn = not blinkOn
         libtcod.console_clear(console)
Example #29
0
def render_all():
	global fov_map, color_dark_wall, color_light_wall
	global color_dark_ground, color_light_ground
	global fov_recompute

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

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

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

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

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

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

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

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

	for object in objects:
		object.clear()
Example #30
0
def main_menu():
	libtcod.console_flush()
	while not libtcod.console_is_window_closed():
		libtcod.console_clear(con)
		libtcod.console_blit(con,0,0,game.screen_width,game.screen_height,0,0,0)
		# Show the title, credits etc
		libtcod.console_set_default_foreground(0, libtcod.light_yellow)
		libtcod.console_print_ex(0,game.screen_width/2,game.screen_height/2-4, libtcod.BKGND_NONE, libtcod.CENTER,
			game.name)
		libtcod.console_print_ex(0,game.screen_width/2, game.screen_height-2,libtcod.BKGND_NONE, libtcod.CENTER,
			game.author + '2013')
		# Show options and wait for player's choice
		choice = menu('',['Play a new game', 'Continue from last game', 'Quit'], 30)

		if choice == 0: # new game
			new_game()
			play_game()
		elif choice == 1: # load game
			try:
				load_game()
			except:
				msgbox('\n No saved game to load.\n', 30)
				continue
			play_game()
		elif choice == 2: # quit
			break
Example #31
0
    def new_game():
        Game.state = 'playing'
        Game.dungeon_level = 1
        Game.game_msgs = []
        Game.mouse = libtcod.Mouse()
        Game.key = libtcod.Key()
        Game.inventory = []
        Game.panel = libtcod.console_new(Game.SCREEN_WIDTH, Game.PANEL_HEIGHT)
        Game.map = Map(Game.MAP_WIDTH, Game.MAP_HEIGHT)

        libtcod.console_clear(Game.main_console)

        _fighter_component = Components.Fighter(
            hp=100,
            dexterity=4,
            accuracy=20,
            power=4,
            xp=0,
            death_function=Components.player_death)
        Game.player = Object(Game.map.origin[0],
                             Game.map.origin[1],
                             '@',
                             'Drew',
                             libtcod.pink,
                             blocks=True,
                             fighter=_fighter_component)
        Game.player.level = 1
        Game.map.add_object(Game.player)

        _equipment_component = Equipment(slot='right hand', power_bonus=2)
        _obj = Object(0,
                      0,
                      '-',
                      'dagger',
                      libtcod.sky,
                      equipment=_equipment_component)
        Game.inventory.append(_obj)
        _equipment_component.equip()

        Game.message(
            'Welcome stranger! Prepare to perish in the Tombs of the Ancient Kings.',
            libtcod.light_green)
def enter_player_name(screen_width, screen_height):
    letters = [
        'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n',
        'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z'
    ]
    name = ''
    x = len(name) + int(screen_width / 2 - 11) + 10
    y = int(screen_height / 2) + 1
    key = libtcod.console_wait_for_keypress(True)
    while True:
        if key.vk == libtcod.KEY_BACKSPACE:
            if len(name) >= 0:
                name = name[0:len(name) - 1]
                libtcod.console_print_ex(0, x, y, libtcod.BKGND_NONE,
                                         libtcod.LEFT, ' ')
                libtcod.console_flush()
        else:
            letter = chr(key.c)
            for item in letters:
                if letter == item:
                    if len(name) <= 12:
                        name = name + letter  #add to the string
                        if len(name) == 1:
                            name = name.capitalize()
                            letter = letter.capitalize()
                        #libtcod.console_set_char(0, x,  y, letter)  #print new character at appropriate position on screen
                        libtcod.console_print_ex(0, x, y, libtcod.BKGND_NONE,
                                                 libtcod.LEFT, letter)

                        libtcod.console_set_default_foreground(
                            0, libtcod.white)  #make it white or something
                        libtcod.console_flush()
                    break
        x = len(name) + int(screen_width / 2 - 11) + 10
        key = libtcod.console_wait_for_keypress(True)

        if key.vk == libtcod.KEY_ESCAPE:
            libtcod.console_clear(0)
            libtcod.console_flush()
            return None
        elif len(name) > 0 and key.vk == libtcod.KEY_ENTER:
            return name
Example #33
0
    def get_user_input(self, x, y):
        ''' Getting user to type something in '''
        mouse = libtcod.Mouse()
        key = libtcod.Key()

        player_input = ''
        key_pressed = ''
        while not key_pressed == libtcod.KEY_ENTER:
            # Clear console, print the current iteration of string, and blit
            self.clear()

            libtcod.console_print(self.con, x, y, '>> %s_' % player_input)

            self.blit()
            libtcod.console_flush()

            #key = libtcod.console_wait_for_keypress(True)
            event = libtcod.sys_check_for_event(libtcod.EVENT_KEY_PRESS | libtcod.EVENT_MOUSE, key, mouse)

            #key_pressed = get_key(key)
            if key.vk == libtcod.KEY_CHAR: key_pressed = chr(key.c)
            else:                          key_pressed = key.vk

            #  Handle special keypresses
            if key_pressed == libtcod.KEY_SPACE:
                key_pressed = ' '

            elif key_pressed == libtcod.KEY_BACKSPACE and len(player_input) > 0:
                key_pressed = ''
                player_input = player_input[0:len(player_input) - 1]

                libtcod.console_clear(self.con)
                libtcod.console_flush()

            elif key_pressed == libtcod.KEY_ENTER:
                break

            # Try to add keypress to thing
            if isinstance(key_pressed, str):
                player_input += key_pressed

        return player_input
def inspect_item_menu(con, header, item, menu_width, menu_height, screen_width, screen_height):

	y = 0
	window = libtcod.console_new(menu_width, menu_height)

	libtcod.console_set_default_background(window, libtcod.darkest_blue)
	libtcod.console_set_default_foreground(window, libtcod.white)
	libtcod.console_clear(window)

	libtcod.console_print_rect_ex(window, 0, y, menu_width, menu_height, libtcod.BKGND_NONE,
									libtcod.LEFT, '{0}'.format(item.name))

	y += 2

	libtcod.console_print_rect_ex(window, 0, y, menu_width, menu_height, libtcod.BKGND_NONE,
									libtcod.LEFT, '{0}'.format(item.item.description))

	x = screen_width // 2 - menu_width // 2
	y = screen_height // 2 - menu_height // 2
	libtcod.console_blit(window, 0, 0, menu_width, menu_height, 0, x, y, 1.0, 1.0)
Example #35
0
 def display_status(self, state, console):
     tcod.console_clear(console.console)
     if self.status.pause:
         display_text(console.console, "*PAUSED*", 0, 0)
     display_text(console.console, str(tcod.sys_get_fps()), 10, 0)
     display_text(console.console, self.status.current_state, 15, 0)
     cash_display = 'Cash: %s' % self.status.money
     display_text(console.console, cash_display, 50, 0)
     if self.status.last_money_movement:
         color = tcod.red
         to_display = str(self.status.last_money_movement)
         if self.status.last_money_movement > 0:
             color = tcod.yellow
             to_display = '+ %s' % to_display
         display_text(console.console, to_display, 52 + len(cash_display),
                      0, color)
         self.status.delta_increment()
     for idx, f in enumerate(self.status.flags):
         display_highlighted_text(console.console, f, console.w - idx - 1,
                                  0)
Example #36
0
def play_game():
    # clear the root console (Clears the startup images)
    tcod.console_clear(0)

    settings.mouse = tcod.Mouse()
    settings.key = tcod.Key()
    settings.highlight_xy = (settings.player.x, settings.player.y)

    # MAIN LOOP
    while not tcod.console_is_window_closed():
        handle_rendering_tasks()
        check_level_up()

        settings.player_action = input_controller(settings.game_state)
        if settings.player_action == 'exit' and settings.game_state == 'playing':
            settings.save_game()
            break
        elif settings.player_action == 'exit':
            settings.game_state = 'playing'
            settings.highlight_state = 'play'
    def next_floor(self, player, message_log, constants):
        self.dungeon_level += 1
        entities = [player]

        self.tiles = self.initialize_tiles()
        self.make_map(constants['max_rooms'], constants['room_min_size'],
                      constants['room_max_size'], constants['max_maze_rooms'],
                      constants['maze_min_size'], constants['maze_max_size'],
                      constants['map_width'], constants['map_height'], player,
                      entities)
        libtcod.console_flush()
        libtcod.console_clear(constants)

        player.fighter.heal(player.fighter.max_hp // 2)

        message_log.add_message(
            Message('You take a moment to rest, and recover your strength.',
                    libtcod.light_violet))

        return entities
Example #38
0
    def draw(self):
        libtcod.console_clear(self.console)

        for y in range(len(self.entity_manager.world_tiles)):
            for x in range(len(self.entity_manager.world_tiles[y])):
                self.draw_world_tile(
                    x, y, self.entity_manager.world_tiles[x][y]['tile'])
        #handy thing about this is it should help farther down the line when I go to implement FOV
        render_data = []
        for id, entity in self.entity_manager.entities.iteritems():
            if entity.get_attribute(AttributeTag.Visible):
                position_info = entity.get_attribute(
                    AttributeTag.WorldPosition)
                if not position_info:
                    raise LookupError(
                        'entity ' + str(entity) +
                        ' is flagged as visible, but does not have any world position'
                    )
                draw_info = entity.get_attribute(AttributeTag.DrawInfo)
                if not draw_info:
                    raise LookupError(
                        'entity ' + str(entity) +
                        ' is flagged as visible, but does not have any draw info'
                    )
                render_data.append({
                    'draw_type': draw_info.data['draw_type'],
                    'z_level': draw_info.data['z_level'],
                    'entity': entity
                })

        #z-sort the entities we're rendering so that things like world tiles can be drawn behind entities on those tiles
        render_data.sort(
            lambda data, other: cmp(data['z_level'], other['z_level']))

        for to_render in render_data:
            if to_render['draw_type'] in render_type_dict:
                render_type_dict[to_render['draw_type']](self,
                                                         to_render['entity'])

        libtcod.console_blit(self.console, 0, 0, self.width, self.height, 0,
                             self.world_x_start, self.world_y_start)
def show_target(cursor, mouse, key, map_width, map_height, targeting_item):
    """Show target and impact radius (when applicable)."""
    (x, y) = (mouse.cx, mouse.cy)
    # Check if item component has a radius defined
    item_component = targeting_item.item
    radius = item_component.function_kwargs.get('radius')

    libtcod.console_clear(cursor)
    #libtcod.console_set_key_color(cursor, libtcod.black)

    if radius:
        for a in range(x - radius, x + radius + 1):
            for b in range(y - radius, y + radius + 1):
                libtcod.console_set_char_background(cursor, a, b,
                                                    targeting_item.color)
    else:
        libtcod.console_set_char_background(cursor, x, y,
                                            libtcod.lightest_grey)

    libtcod.console_blit(cursor, 0, 0, map_width, map_height, 0, 0, 0, 1.0,
                         0.5)
Example #40
0
    def render_all(self, game):
        libtcod.console_clear(self.game_area)
        libtcod.console_blit(self.game_area, 0, 0, self.game_width,
                             self.game_height, self.root_console, 0, 0)
        game.game_state.handle_video(game)

        libtcod.console_set_default_background(self.bottom_bar,
                                               libtcod.darker_grey)
        libtcod.console_clear(self.bottom_bar)

        for index, message in enumerate(
                self.message_log.on_screen_message_list):
            libtcod.console_set_default_foreground(self.bottom_bar,
                                                   message.color)
            libtcod.console_print_ex(self.bottom_bar, self.message_log.x,
                                     index + 1, libtcod.BKGND_NONE,
                                     libtcod.LEFT, message.text)
        libtcod.console_blit(self.bottom_bar, 0, 0, self.bottom_bar_width,
                             self.bottom_bar.height, self.root_console, 0,
                             self.game_height)
        libtcod.console_flush()
Example #41
0
    def render_panel(self, map_scale, mouse):
        if self.render:
            libtcod.console_set_default_background(self.con, self.backcolor)
            libtcod.console_set_default_foreground(self.con, self.frontcolor)
            libtcod.console_clear(self.con)

            self.draw_box(0, self.width-1, 0, self.height-1, self.frontcolor)

            self.render_text_func(*self.render_text_args)

            ## "General" buttons
            for button in self.gen_buttons:
                button.display(mouse)
            # Specific to worldmap ( TODO - fix.... )
            if map_scale == 'world':
                for button in self.wmap_dynamic_buttons + self.wmap_buttons:
                    button.display(mouse)

            elif map_scale == 'human':
                for button in self.bmap_dynamic_buttons + self.bmap_buttons:
                    button.display(mouse)
Example #42
0
def city_production_menu():
    width, height = R.MAP_VIEW_WIDTH - 4, R.MAP_VIEW_HEIGHT - 4
    city_select_pop = libtcod.console_new(width, height)
    selected_city = None
    limit = len(cities) - 1

    pos_x = R.MAP_VIEW_WIDTH / 2 - width / 2
    pos_y = R.MAP_VIEW_HEIGHT / 2 - height / 2
    for a in range(R.MAP_VIEW_WIDTH - 4):  #clear screen, colour dark grey, every cycle
        for b in range(R.MAP_VIEW_HEIGHT - 4):
            #libtcod.console_print_rect(window, a, b, 
            libtcod.console_print_rect_ex(city_select_pop, a, b, R.MAP_VIEW_WIDTH - 4, R.MAP_VIEW_HEIGHT - 4,
                                          libtcod.BKGND_NONE, libtcod.LEFT, " ")

    libtcod.console_blit(city_select_pop, 0, 0, width, height, 0, pos_x, pos_y, 1.0, 0.9)
    libtcod.console_flush()
    offset = 0

    while True:
        libtcod.console_clear(city_select_pop)
        libtcod.console_set_default_foreground(city_select_pop, libtcod.yellow)
        libtcod.console_set_default_foreground(city_select_pop, libtcod.light_yellow)
        #city_length = len(cities)
        for city in range(len(cities)):  # picks the smaller of the two.
            location = cities[city]
            resources = "\n"
            for resource in location.producing:
                supply_demand = location.trade_house.supply_demand[resource]
                resources += resource + " " + str(location.producing[resource][1]) + "   \t   " + str(
                    supply_demand[0]) + " " + str(supply_demand[1]) + ", " + str(supply_demand[2]) + "\n"

            libtcod.console_print_ex(city_select_pop, 1, 1 + offset, libtcod.BKGND_NONE, libtcod.LEFT,
                                     location.name + "   " + resources)
            offset += 6
        libtcod.console_blit(city_select_pop, 0, 0, width, height, 0, pos_x, pos_y, 1.0, 0.9)
        libtcod.console_flush()

        key = libtcod.console_wait_for_keypress(True)
        if key.vk == libtcod.KEY_ENTER or key.vk == libtcod.KEY_BACKSPACE or key.vk == libtcod.KEY_ESCAPE:
            break
Example #43
0
def render_panel():
    global game_msgs
    #Render the information panel on the right side of the screen

    #Clear the panel ready to render
    libtcod.console_set_default_background(panel, libtcod.black)
    libtcod.console_clear(panel)

    #Render the HP bar
    render_bar(1, 1, PANEL_WIDTH - 2, 'HP', data.player.creature.hp,
               data.player.creature.max_hp, libtcod.red, libtcod.dark_red)

    #Render the stamina bar
    render_bar(1, 3, PANEL_WIDTH - 2, 'STA', data.player.creature.stamina,
               data.player.creature.max_stamina, libtcod.blue,
               libtcod.dark_blue)

    #Show the player stats
    libtcod.console_set_default_foreground(panel, libtcod.white)
    stats = [
        'STR: ' + str(data.player.creature.strength),
        'TOU: ' + str(data.player.creature.toughness),
        'DEX: ' + str(data.player.creature.dexterity)
    ]
    y = 5
    for line in stats:
        libtcod.console_print_ex(panel, 0, y, libtcod.BKGND_NONE, libtcod.LEFT,
                                 line)
        y += 1

    #Write the game messages
    y = 0
    for line, color in game_msgs:
        libtcod.console_set_default_foreground(panel, color)
        libtcod.console_print_ex(panel, 0, PANEL_HEIGHT - MSG_HEIGHT + y,
                                 libtcod.BKGND_NONE, libtcod.LEFT, line)
        y += 1

    libtcod.console_blit(panel, 0, 0, PANEL_WIDTH, PANEL_HEIGHT, 0,
                         MAP_WINDOW_WIDTH, 0)
Example #44
0
def render_messages(Player):
    libtcod.console_set_default_foreground(var.MessagePanel, var.TextColor)
    libtcod.console_set_default_background(var.MessagePanel, libtcod.black)
    libtcod.console_clear(var.MessagePanel)

    if len(var.MessageHistory) > 10:
        s = len(var.MessageHistory) - 10
    else:
        s = 0
    y = 0

    if Player != None:
        diff = int(math.ceil(
            Player.getMoveAPCost()))  # This makes messages colored
    else:  # even if player needs more than
        diff = 1  # Otherise, use 1 turn.              # one turn to move due to burden
        # or lost limbs.
    while y <= var.PanelHeight:
        try:
            (line, color, turn) = var.MessageHistory[s]
            if turn >= (var.TurnCount -
                        diff):  # Turn count increases before redrawing
                # screen, so here we need T - 1 for color.
                libtcod.console_set_default_foreground(var.MessagePanel, color)
            else:
                libtcod.console_set_default_foreground(var.MessagePanel,
                                                       libtcod.darker_grey)

            libtcod.console_print_ex(var.MessagePanel, 1, y,
                                     libtcod.BKGND_NONE, libtcod.LEFT, line)
        except:
            break

        y += 1
        s += 1

    # Render messages:
    libtcod.console_blit(var.MessagePanel, 0, 0,
                         var.ScreenWidth - var.PanelWidth, var.PanelHeight, 0,
                         0, var.ScreenHeight - var.PanelHeight)
Example #45
0
def render_all():
    global fov_map, color_dark_wall, color_lit_wall
    global color_dark_floor, color_lit_floor
    global fov_recompute

    if fov_recompute:
        #recompute FOV is needed ( after player movement etc )
        fov_recompute = False
        libtcod.map_compute_fov(fov_map, player.x, player.y, TORCH_RADIUS,
                                FOV_LIGHT_WALLS, FOV_ALGO)

        render_map()

    #draw all objects in the list
    for object in objects:
        if object != player:
            object.draw()
    player.draw()
    #blits content of offscreen console to root console
    libtcod.console_blit(con, 0, 0, MAP_WIDTH, MAP_HEIGHT, 0, 0, 0)
    #prepare to render the gui log panel
    libtcod.console_set_default_background(log_panel, libtcod.black)
    libtcod.console_clear(log_panel)

    print_msg_log()

    #PLAYER STAT BARS
    #HP
    render_bar(1, 3, BAR_WIDTH, log_panel, "BLOOD", player.fighter.hp,
               player.fighter.max_hp, libtcod.darker_red, libtcod.darkest_red)
    #HUNGER
    render_bar(1, 5, BAR_WIDTH, log_panel, 'HNGR', player.needs.hunger,
               player.needs.max_hunger, libtcod.grey, libtcod.desaturated_red)
    #THIRST
    render_bar(1, 7, BAR_WIDTH, log_panel, 'THRST', player.needs.thirst,
               player.needs.max_thirst, libtcod.light_blue,
               libtcod.desaturated_blue)
    #blit the contents of log panel to root console
    libtcod.console_blit(log_panel, 0, 0, SCREEN_WIDTH, LOG_PANEL_HEIGHT, 0, 0,
                         LOG_PANEL_Y)
Example #46
0
def draw(first):
    global fov_px, fov_py, fov_map
    global fov_init, fov_recompute, smap

    if first:  #initialize the window and
        libtcod.console_clear(0)
        libtcod.console_set_default_foreground(0, libtcod.white)
        text = 'what?'
        libtcod.console_print_ex(0, 1, 1, libtcod.BKGND_NONE, libtcod.LEFT,
                                 text)
        libtcod.console_put_char(0, fov_px, fov_py, '@', libtcod.BKGND_NONE)

        for y in range(window_height):
            for x in range(window_width):
                if smap[y][x] == '=':
                    libtcod.console_put_char(0, x, y, libtcod.CHAR_DHLINE,
                                             libtcod.BKGND_NONE)
    if not fov_init:
        fov_init = True
        fov_map = libtcod.map_new(window_width, window_height)
        for y in range(window_height):
            for x in range(window_width):
                if smap[y][x] == ' ':
                    libtcod.map_set_properties(fov_map, x, y, True, True)
                elif smap[y][x] == '=':
                    libtcod.map_set_properties(fov_map, x, y, True, False)

    if fov_recompute:
        fov_recompute = False
        libtcod.map_compute_fov(fov_map, fov_px, fov_py, fov_radius, True)

    for y in range(window_height):  # color in the map
        for x in range(window_width):
            affect, cell = 'dark', 'ground'
            if libtcod.map_is_in_fov(fov_map, x, y): affect = 'light'
            if (smap[y][x] == '#'): cell = 'wall'
            color = fov_colors['%s %s' % (affect, cell)]
            libtcod.console_set_char_background(0, x, y, color,
                                                libtcod.BKGND_SET)
Example #47
0
def render_gui():
    """ Renders just the gui. """

    # Set globals.
    global turns, game_messages

    # Clear console before drawing on it.
    roguelib.console_set_default_background(console_gui, roguelib.black)
    roguelib.console_clear(console_gui)

    # Display health and energy bars for player.
    render_bar(console_gui, 1, 1, BAR_WIDTH, "HP", player.alive.hp,
               player.alive.maxhp, roguelib.dark_flame, roguelib.dark_grey,
               roguelib.white)
    render_bar(console_gui, 1, 3, BAR_WIDTH, "Energy", player.alive.energy,
               player.alive.maxenergy, roguelib.dark_green, roguelib.dark_grey,
               roguelib.white)

    # Prints number of turns and dungeon level on screen.
    roguelib.console_set_default_foreground(
        console_gui, eval(SETTING_DATA[b"Text Color"][b"COLOR"]))
    roguelib.console_print(console_gui, SCREEN_WIDTH - 15, 2,
                           "Turns:" + str(turns))
    roguelib.console_print(console_gui, SCREEN_WIDTH // 2, 2,
                           "Depth:" + str(depth))

    # Display messages in message box.
    y = 1
    for (line, color) in game_messages:
        roguelib.console_set_default_foreground(console_message, color)
        roguelib.console_print_ex(console_message, 0, y, roguelib.BKGND_NONE,
                                  roguelib.LEFT, line)
        y += 1

    # Blit contents of consoles to screen.
    roguelib.console_blit(console_gui, 0, 0, SCREEN_WIDTH, CONSOLE_GUI_HEIGHT,
                          0, 0, 0)
    roguelib.console_blit(console_message, 0, 0, SCREEN_WIDTH,
                          MESSAGE_CONSOLE_HEIGHT, 0, 0, MESSAGE_CONSOLE_Y)
Example #48
0
    def doMenu(self):

        tcod.console_set_foreground_color(0, tcod.white)

        selectedLine = 1

        while True:

            tcod.console_clear(0)

            index = 1

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

            tcod.console_flush()

            # Get Input
            key = tcod.console_wait_for_keypress(True)

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

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

            if (key.vk == tcod.KEY_ENTER):
                return self._selection
Example #49
0
def render_panel(msgs, panel):
    y = 1
    libtcod.console_clear(panel)
    for msg in msgs:
        libtcod.console_set_default_background(panel, libtcod.black)
        libtcod.console_set_default_foreground(panel, msg[1])
        libtcod.console_print_ex(panel, 2, y, libtcod.BKGND_NONE, libtcod.LEFT,
                                 msg[0])
        libtcod.console_blit(panel, 0, 0, SCREEN_WIDTH, PANEL_HEIGHT, 0, 0,
                             PANEL_Y)
        y = y + 1

    global move_count

    if move_count != 0:
        libtcod.console_set_default_background(panel, libtcod.black)
        libtcod.console_set_default_foreground(panel, libtcod.sky)
        libtcod.console_print_ex(panel, 70, 1, libtcod.BKGND_NONE,
                                 libtcod.LEFT,
                                 "Move count: " + str(move_count))
        libtcod.console_blit(panel, 0, 0, SCREEN_WIDTH, PANEL_HEIGHT, 0, 0,
                             PANEL_Y)
Example #50
0
def render_all(gldir, camera, panel, con):

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

    camera.camera_render()

    for obj in gldir.game_objs:
        if obj.in_camera(): obj.draw()

    gldir.player.draw()
    for obj in gldir.game_objs:
        if obj.name == 'targeter': obj.draw()

    #blits the content of the 'con' console to the root console
    libtcod.console_blit(con, 0, 0, CAMERA_WIDTH, CAMERA_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 (line, color) in gldir.game_msgs:
        libtcod.console_set_default_foreground(panel, color)
        libtcod.console_print_ex(panel, MSG_X, y, libtcod.BKGND_NONE,
                                 libtcod.LEFT, line)
        y += 1

    render_bar(1, 1, BAR_WIDTH, 'Health', gldir.player.fighter.hp,
               gldir.player.fighter.max_hp, libtcod.dark_red,
               libtcod.darkest_red, panel)  # display health
    libtcod.console_print_ex(panel, 1, 3, libtcod.BKGND_NONE, libtcod.LEFT,
                             'Dungeon level ' +
                             str(gldir.dungeon_level))  #display dungeon level

    #blits the content of the 'panel' console to the root console
    libtcod.console_blit(panel, 0, 0, SCREEN_WIDTH, PANEL_HEIGHT, 0, 0,
                         PANEL_Y)
Example #51
0
def main_menu():
    #Set up the main menu, which is presented to the player when they first load the game
    img = libtcod.image_load('images/menu_background1.png')

    while not libtcod.console_is_window_closed():
        #Show the image at twice its usual resolution of the console
        libtcod.image_blit_2x(img, 0, SCREEN_WIDTH / 6, SCREEN_HEIGHT / 6)

        #Show the games title, and some credits
        libtcod.console_set_default_foreground(0, libtcod.light_yellow)
        libtcod.console_print_ex(0, SCREEN_WIDTH / 2, SCREEN_HEIGHT / 2 - 4,
                                 libtcod.BKGND_NONE, libtcod.CENTER,
                                 'DUNGEONCRAWLER')
        libtcod.console_print_ex(0, SCREEN_WIDTH / 2, SCREEN_HEIGHT - 2,
                                 libtcod.BKGND_NONE, libtcod.CENTER,
                                 'By Jeremy Cerise')

        #Show menu options and wait for the players choice
        choice = menu('', ['Play a new game', 'Continue last game', 'Quit'],
                      24)

        if choice == 0:
            #Start a new game
            #Clear the base conosle, so the menu image and options don't show up under the rest of the UI
            libtcod.console_set_default_background(0, libtcod.brass)
            libtcod.console_clear(0)
            new_game()
            play_game()
        elif choice == 1:
            try:
                libtcod.console_set_default_background(0, libtcod.brass)
                libtcod.console_clear(0)
                load_game()
            except:
                msgbox('\n No saved game to load!\n', 24)
        elif choice == 2:
            #Exit the program
            break
Example #52
0
def update_info_bar():
    #TODO: seperate the UI updating into THIS function. the rest of the game updates in the render_all.
    # Fetch all the code into this function basically.
    #TODO: make a function for the ui to prin a message in this area. Possibly with choices whether to wipe it first or add to it.

    libtcod.console_clear(inf)
    y = 2

    if len(selected) > 0:
        for sel in selected:
            libtcod.console_print_ex(inf, 0, y, libtcod.BKGND_NONE, libtcod.LEFT, sel.name)
            libtcod.console_print_ex(inf, 0, y + 1, libtcod.BKGND_NONE, libtcod.LEFT, sel.type)
            y += 2

            try:
                if sel.component.trade_house:
                    libtcod.console_print_ex( inf, 0, y, libtcod.BKGND_NONE, libtcod.LEFT, sel.char)
                    resources = [obj + " " + str(sel.component.resources[obj][1]) for obj in sel.component.resources]

                    resources = "\n".join(resources)
                    libtcod.console_print_ex(inf, 0, y, libtcod.BKGND_NONE, libtcod.LEFT, resources)
                    y += 1
            except:
                libtcod.console_print_ex(inf, 0, y, libtcod.BKGND_NONE, libtcod.LEFT, sel.char)

        y += 4
    for (line, colour) in test_msgs:
        libtcod.console_set_default_foreground(inf, colour)
        libtcod.console_print_ex(inf, 0, y, libtcod.BKGND_NONE, libtcod.LEFT, line)
        y += 1
    #    y = 1
    #    for (line, colour) in test_msgs:
    #        libtcod.console_set_default_foreground(inf, colour)
    #        libtcod.console_print_ex(inf, 2, y, libtcod.BKGND_NONE, libtcod.LEFT, line)
    #        y += 1

    libtcod.console_blit(inf, 0, 0, R.INFO_BAR_WIDTH, R.SCREEN_HEIGHT, 0, R.MAP_VIEW_WIDTH, 0)
    libtcod.console_flush()
Example #53
0
def DrawScreen(gameState):
    libtcod.console_clear(0)

    # ---- Eventually this needs to take into account the window of view you have.
    # ---- Get the player's current location
    x, y = gameState.Player.GetLocation()

    # ---- Eventually take into account some theoretical maximum map size, but meh.

    # ---- Use the player's current location to determine the visible window.
    visibleOffsetX = (VISIBLE_MAP_WIDTH / 2) - x

    # the `- 10` makes the action take player higher to the top of the screen.
    visibleOffsetY = (VISIBLE_MAP_HEIGHT / 2) - y - 10

    drawTiles(gameState.Map, visibleOffsetX, visibleOffsetY)
    drawTrains(gameState.Trains, gameState.Player, visibleOffsetX,
               visibleOffsetY)
    drawPlayers(gameState.Player, visibleOffsetX, visibleOffsetY)

    drawUi(gameState)

    libtcod.console_flush()
Example #54
0
    def build(self):

        #print 'built!'
        libtcod.console_set_default_foreground(self.console, self.get_color())
        libtcod.console_set_default_background(self.console,
                                               self.get_bk_color())
        libtcod.console_print_frame(self.console, 0, 0, self.width,
                                    self.height, True, libtcod.BKGND_SET,
                                    self.id)

        temp = libtcod.console_new(self.width - 2, self.height - 2)
        y = 1

        if self.vertical:
            for elem in self.content:
                libtcod.console_clear(temp)
                elem.build(temp)
                height = elem.height

                libtcod.console_blit(temp, 0, 0, elem.width, elem.height,
                                     self.console, 1, y)

                y += height
Example #55
0
def show_stats(player, inventory, score):
    global game_msgs
    #prepare to render the GUI panel
    libtcod.console_set_default_background(gui_con, libtcod.black)
    libtcod.console_clear(gui_con)

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

    #print the game messages, one line at a time
    y = 1
    for (line, color) in game_msgs:
        libtcod.console_set_default_foreground(gui_con, color)
        libtcod.console_print_ex(gui_con, MSG_X, y, libtcod.BKGND_NONE,
                                 libtcod.LEFT, line)
        y += 1

    #calculate toy and candy count
    toys = 0
    candy = 0

    for thing in inventory:
        if thing.item.type == 'candy':
            candy += 1
        elif thing.item.type == 'toy':
            toys += 1

    libtcod.console_set_default_foreground(gui_con, libtcod.white)
    libtcod.console_print_ex(gui_con, 1, 3, libtcod.BKGND_NONE, libtcod.LEFT,
                             'Toys: ' + str(toys) + ' Candy: ' + str(candy))
    libtcod.console_print_ex(gui_con, 1, 4, libtcod.BKGND_NONE, libtcod.LEFT,
                             'Score: ' + str(score))

    #blit the contents of "panel" to the root console
    libtcod.console_blit(gui_con, 0, 0, SCREEN_WIDTH, PANEL_HEIGHT, 0, 0,
                         PANEL_Y)
Example #56
0
def castBanish(spell, targetList, game_msgs, context):
    messagePrinter('Left click to select your target', game_msgs)
    target = target_monster(context[0], context[1], context[2], context[3],
                            context[4], context[5], context[6])

    maxDist = BANISH_MULTIPLIER * spell.effectMultiplier

    #TODO: handle the fact that the spell might be enhanced by nouns
    #ex: "banish orc" should increase the range but affect orcs only
    #here we should re-render the map so we can see where to put them

    messagePrinter('Left click to select the location to banish them to',
                   game_msgs)
    messagePrinter(
        'The spell can banish up to a maximum of ' + str(maxDist) + ' squares',
        game_msgs)
    context[3].fighter.casting = -1  #one-shot - always stop casting
    (x, y) = target_tile(context[0], context[1], context[2], context[3],
                         context[4], context[5], context[6])

    if x is not None:
        dx = x - target.x
        dy = y - target.y

        if (target is not None) and (dx < maxDist) and (dy < maxDist):
            targetList.append(target)
            messagePrinter('Banishing: ' + target.name, game_msgs)

            if target.fighter.hp > 0:
                target.move(x - target.x, y - target.y)
                libtcod.console_clear(con)
        else:
            messagePrinter('Target location is too far!', game_msgs)
            context[3].fighter.casting = -1
            return 'No target'
    else:
        return 'No target'
def menu(con, header, background_color, options, width, screen_width, screen_height, ordered=True):
	if len(options) > 26: raise ValueError("Cannot have a menu with more than 26 options.")

	# Calculate total height for the header (after auto-wrap) and one line per option
	header_height = libtcod.console_get_height_rect(con, 0, 0, width, screen_height, header)
	height = len(options) + header_height

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

	# Print the header, with auto-wrap
	libtcod.console_set_default_background(window, background_color)
	libtcod.console_set_default_foreground(window, libtcod.white)
	libtcod.console_clear(window)
	libtcod.console_print_rect_ex(window, 0, 0, width, height, libtcod.BKGND_NONE, libtcod.LEFT, header)

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

	else:
		# Print all the options
		y = header_height
		for option_text in options:
			libtcod.console_print_ex(window, 0, y, libtcod.BKGND_NONE, libtcod.LEFT, option_text)
			y += 1

	# Blit the contents of "window" to the root console
	x = int(screen_width / 2 - width / 2)
	y = int(screen_height / 2 - height / 2)
	libtcod.console_blit(window, 0, 0, width, height, 0, x, y, 1.0, 1.0)
Example #58
0
    def draw(self):
        libtcod.console_clear(self.console)

        libtcod.console_set_default_background(self.console,
                                               libtcod.Color(255, 0, 255))
        libtcod.console_rect(self.console, 0, 0, self.width, self.height,
                             libtcod.BKGND_SET)
        libtcod.console_set_default_background(self.console, libtcod.black)

        libtcod.console_set_alignment(self.console, libtcod.LEFT)

        current_height = 0
        for line in self.console_command_history:
            libtcod.console_print(self.console, 0, current_height, line)
            current_height += 1
        if self.input_enabled:
            libtcod.console_print(
                self.console, 0, current_height,
                self.prompt_string + self.input_command + self.blinking_cursor)

        libtcod.console_vline(self.console, self.width - 1, 0, self.height)

        libtcod.console_blit(self.console, 0, 0, self.width, self.height, 0, 0,
                             self.root_console_height - self.height)
Example #59
0
def render(console):
    global entities, player, fov_recompute

    while (True):
        # Refreshes the screen
        tcod.console_set_default_background(console, tcod.black)
        tcod.console_clear(console)

        if fov_recompute:
            recompute_fov(fov_map, player.x, player.y, fov_radius,
                          fov_light_walls, fov_algorithm)

        render_all(console, entities, player, game_map, fov_map, fov_recompute,
                   SCREEN_WIDTH, SCREEN_HEIGHT, colors)

        tcod.console_set_default_background(console, tcod.black)
        renderBottomPanel(console, message_log, player)
        renderSidePanel(console, entities, fov_map)

        tcod.console_flush()

        tcod.console_blit(console, 0, 0, SCREEN_WIDTH, SCREEN_HEIGHT, 0, 0, 0)

        sleep(1 / FRAME_RATE)
Example #60
0
 def refresh_infobar(self, infobar):
     libtcod.console_clear(infobar)
     infobar_text = ""
     if self.mode == "move":
         chunk_count_x, chunk_count_y, local_x, local_y = self.to_actv_and_local_coords(
             self.player.x, self.player.y)
         infobar_text = self.active_chunks.map[chunk_count_x][
             chunk_count_y].chunk[local_x][local_y].name + " "
         for mob in self.active_objects:
             if mob.x == self.player.x and mob.y == self.player.y and hasattr(
                     mob, "name") == True:
                 if mob.name != "Player":
                     infobar_text = infobar_text + mob.name + " "
         libtcod.console_print(infobar, 0, 0, infobar_text)
     if self.mode == "look":
         chunk_count_x, chunk_count_y, local_x, local_y = self.to_actv_and_local_coords(
             self.cursor.x, self.cursor.y)
         infobar_text = self.active_chunks.map[chunk_count_x][
             chunk_count_y].chunk[local_x][local_y].name + " "
         for mob in self.active_objects:
             if mob.x == self.cursor.x and mob.y == self.cursor.y and hasattr(
                     mob, "name") == True:
                 infobar_text = infobar_text + mob.name + " "
         libtcod.console_print(infobar, 0, 0, infobar_text)