Ejemplo n.º 1
0
def render_text(x, y, name, list):
    libtcod.console_set_default_background(panel, libtcod.white)
    string = name + ": "
    for elem in list:
        string += elem + ", "
    libtcod.console_print_ex(panel, x, y, libtcod.BKGND_NONE, libtcod.CENTER,
                             string)
Ejemplo n.º 2
0
Archivo: main.py Proyecto: Makdaam/noi
def init_state():
    global state
    
#    state['seed'] = os.urandom(8)
    state['seed'] = 0
    random.seed(state['seed'])

    libtcod.console_set_custom_font('dejavu10x10_gs_tc.png', libtcod.FONT_TYPE_GREYSCALE | libtcod.FONT_LAYOUT_TCOD)
    libtcod.console_init_root(SCREEN_WIDTH, SCREEN_HEIGHT, 'python/libtcod tutorial', False)
    state['buffer']={}
    state['buffer']['map'] = libtcod.console_new(SCREEN_WIDTH, SCREEN_HEIGHT)
    con = state['buffer']['map']
    libtcod.console_set_default_foreground(con, libtcod.grey)
    libtcod.console_set_default_background(con, libtcod.black)


    state['maps'] = {}
    state['maps'][0] = make_map()
    state['maps'][1] = make_map()
    state['maps'][2] = make_map()
    state['maps'][3] = make_map()
    state['maps'][4] = make_map()

    state['entities']={}
    state['entities'][0] = list()
    state['entities'][1] = list()
    state['entities'][2] = list()
    state['entities'][3] = list()
    state['entities'][4] = list()

    generate_maps()

    state['current_level'] = 0
    state['player'] = Entity(START_X,START_Y,'@',libtcod.white)
Ejemplo n.º 3
0
def render_all(con, panel, entities, player, game_map, message_log,
               screen_width, screen_height, bar_width, panel_height, panel_y):
    for y in range(game_map.height):
        for x in range(game_map.width):
            wall = game_map.tiles[x][y].blocked
            if wall:
                libtcod.console_put_char_ex(con, x, y, '"', libtcod.white,
                                            libtcod.black)
            else:
                libtcod.console_put_char_ex(con, x, y, '_', libtcod.gray,
                                            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, 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)

    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_blit(panel, 0, 0, screen_width, panel_height, 0, 0,
                         panel_y)
Ejemplo n.º 4
0
 def render(self):
     '''         
     visible=true 보이는 상태이고
     Screen에 포함되어 있으면
     자신의 foreground color와 background color에 따라 
     Screen(의 콘솔에) char를 출력한다.
     '''
     if self.visible is True:
         if self.ownerScreen is not None:
             owner = self._ownerScreen
         
             prevBackFlag = libtcod.console_get_background_flag(owner.console)
             prevForeColor = owner.foreColor
             prevBackColor = owner.backColor
             #renderObj의 색깔로 설정
             libtcod.console_set_background_flag(owner.console, libtcod.BKGND_SET)
             libtcod.console_set_default_foreground(owner.console, self.foreColor)
             libtcod.console_set_default_background(owner.console, self.backColor)
             #출력
             libtcod.console_print(owner.console, self.x, self.y, self.char)
             #원래 owner의 색깔로 되돌리기.
             libtcod.console_set_background_flag(owner.console, prevBackFlag)
             libtcod.console_set_default_foreground(owner.console, prevForeColor)
             libtcod.console_set_default_background(owner.console, prevBackColor)
         else:
             raise NoOwnerRenderObjError()
Ejemplo n.º 5
0
def inspect_banner(x, y, banner_text, new_animation=True):

    animation_console = Render.layers['animation_console']
    # animation_console = 0

    # print "printing"

    color = libtcod.light_blue
    libtcod.console_set_default_foreground(animation_console,
                                           libtcod.lighter_blue)
    libtcod.console_set_default_background(animation_console, libtcod.green)
    libtcod.console_set_background_flag(animation_console,
                                        libtcod.BKGND_MULTIPLY)

    length = len(banner_text)

    back = libtcod.green

    Render.draw_char(animation_console, x + 1, y, libtcod.CHAR_HLINE, color,
                     back)

    Render.draw_char(animation_console, x + 2, y - 1, libtcod.CHAR_NW, color,
                     back)
    Render.draw_char(animation_console, x + 2, y, libtcod.CHAR_TEEW, color,
                     back)
    Render.draw_char(animation_console, x + 2, y + 1, libtcod.CHAR_SW, color,
                     back)

    if new_animation:
        for z in range(length):

            Render.draw_char(animation_console, x + z + 3, y - 1,
                             libtcod.CHAR_HLINE, color, back)
            Render.draw_char(animation_console, x + z + 3, y, banner_text[z],
                             color, back)
            Render.draw_char(animation_console, x + z + 3, y + 1,
                             libtcod.CHAR_HLINE, color, back)
            # Render.update_animations()
            libtcod.console_flush()
            # time.sleep(0.05)
    else:
        for z in range(length):
            Render.draw_char(animation_console, x + z + 3, y - 1,
                             libtcod.CHAR_HLINE, color, back)
            Render.draw_char(animation_console, x + z + 3, y, ' ', color, back)
            Render.draw_char(animation_console, x + z + 3, y + 1,
                             libtcod.CHAR_HLINE, color, back)

    Render.draw_char(animation_console, x + 3 + length, y - 1, libtcod.CHAR_NE,
                     color, back)
    Render.draw_char(animation_console, x + 3 + length, y, libtcod.CHAR_VLINE,
                     color, back)
    Render.draw_char(animation_console, x + 3 + length, y + 1, libtcod.CHAR_SE,
                     color, back)

    libtcod.console_set_default_foreground(animation_console,
                                           libtcod.lightest_blue)
    Render.print_line(animation_console, x + 3, y, libtcod.BKGND_NONE,
                      libtcod.LEFT, banner_text)
    libtcod.console_flush()
Ejemplo n.º 6
0
def print_lyrics(panel, lyrics, active_character):
    primary_color = tcod.sea
    primary_color_dark = tcod.darkest_sea

    tcod.console_set_default_foreground(panel, primary_color)
    tcod.console_set_default_background(panel, tcod.black)

    tcod.console_set_color_control(tcod.COLCTRL_1, primary_color_dark,
                                   tcod.black)
    tcod.console_set_color_control(tcod.COLCTRL_2, tcod.black, primary_color)

    lyrics_pre_active = '%c{}%c'.format(
        lyrics[:active_character]) % (tcod.COLCTRL_1, tcod.COLCTRL_STOP)
    lyrics_active = '%c{}%c'.format(
        lyrics[active_character]) % (tcod.COLCTRL_2, tcod.COLCTRL_STOP)
    lyrics_post_active = lyrics[active_character + 1:]
    formatted_lyrics = lyrics_pre_active + lyrics_active + lyrics_post_active

    x = int(tcod.console_get_width(panel) / 2)
    y = 1
    w = tcod.console_get_width(panel) - 8
    h = tcod.console_get_height(panel)

    tcod.console_print_rect_ex(panel, x, y, w, h, tcod.BKGND_SET, tcod.CENTER,
                               formatted_lyrics)
Ejemplo n.º 7
0
def render_bar(panel, x, y, total_width, name, value, maximum, bar_color, back_color):
    """
    Draws the health bar in the bottom panel.
    :param panel: 
    :param x: 
    :param y: 
    :param total_width: 
    :param name: 
    :param value: 
    :param maximum: 
    :param bar_color: 
    :param back_color: 
    :return: 
    """
    # Stores the width of the current HP rectangle.
    bar_width = int(float(value) / maximum * total_width)

    # The colour of the back/maximum hp rectangle.
    libtcod.console_set_default_background(panel, back_color)
    # Creates the maximum HP rectangle.
    libtcod.console_rect(panel, x, y, total_width, 1, False, libtcod.BKGND_SCREEN)

    # The colour of the HP portion of the HP bar *(probably best to set it to red).
    libtcod.console_set_default_background(panel, bar_color)
    # If the player has any hp left.
    if bar_width > 0:
        # Draws the inner HP rectangle.
        libtcod.console_rect(panel, x, y, bar_width, 1, False, libtcod.BKGND_SCREEN)

    # Prints the HP text next to the bar.
    libtcod.console_set_default_foreground(panel, libtcod.white)
    libtcod.console_print_ex(panel, int(x + total_width / 2), y, libtcod.BKGND_NONE, libtcod.CENTER,
                             "{0}: {1}/{2}".format(name, value, maximum))
Ejemplo n.º 8
0
    def renderBar(self, panel, x, y, total_width, name, value, maximum, bar_color, back_color):
        """
        Helper function to render interface bars
        """
        # render a bar (HP, experience, etc). first calculate the width of the bar
        bar_width = int(float(value) / maximum * total_width)

        # render the background first
        libtcod.console_set_default_background(panel, back_color)
        libtcod.console_rect(panel, x, y, total_width, 1, False, libtcod.BKGND_SCREEN)

        # now render the bar on top
        libtcod.console_set_default_background(panel, bar_color)
        if bar_width > 0:
            libtcod.console_rect(panel, x, y, bar_width, 1, False, libtcod.BKGND_SCREEN)

        # finally, some centered text with the values
        libtcod.console_set_default_foreground(panel, libtcod.white)
        libtcod.console_print_ex(
            panel,
            x + total_width / 2,
            y,
            libtcod.BKGND_NONE,
            libtcod.CENTER,
            name + ": " + str(value) + "/" + str(maximum),
        )
Ejemplo n.º 9
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)
Ejemplo n.º 10
0
    def build(self):

        #print 'built!'
        libtcod.console_set_default_foreground(self.console,
                                               self.get_palette().LBLUE)
        libtcod.console_set_default_background(self.console,
                                               self.get_palette().DGREY)
        libtcod.console_print_frame(self.console, 0, 0, self.width,
                                    self.height, True, libtcod.BKGND_SET,
                                    'fenetre1')

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

        libtcod.console_set_default_foreground(temp, self.get_palette().LBLUE)
        libtcod.console_set_default_background(temp, self.get_palette().DGREY)
        y = 1

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

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

            y += height
Ejemplo n.º 11
0
 def bg_colour(self, bg):
     if bg is None:
         self.bg_effect = dlib.BKGND_NONE
     else:
         if self.bg_effect == dlib.BKGND_NONE:
             self.bg_effect = dlib.BKGND_SET
         dlib.console_set_default_background(self._intern, bg.get_struct())
Ejemplo n.º 12
0
    def add_bar(self, x, y, name, value, maximum, bar_color, back_color):
        """
        Draw a bar in this panel's buffer.
        :param x: Location in X
        :param y: Location in Y
        :param name: The bar's name, displayed in the bar.
        :param value: The bar's current value.
        :param maximum: The bar's maximum value.
        :param bar_color: The color of the filled portion of the bar
        :param back_color: The color of the background of the bar.
        :return: Nothing.
        """
        total_width = (self.width - (self.margin * 4)) #Compute the maximum length of the bar.
        current_width = int(float(value) / maximum * total_width) #Compute the length of the bar.

        if current_width > total_width:
            current_width = total_width

        #Render the bar's BG
        libtcod.console_set_default_background(self.console, back_color)
        libtcod.console_rect(self.console, x, y, total_width - 1, 1, False, libtcod.BKGND_SCREEN)

        #Render the bar's colored section
        libtcod.console_set_default_background(self.console, bar_color)
        if current_width > 0:
            libtcod.console_rect(self.console, x, y, current_width, 1, False, libtcod.BKGND_SCREEN)

        #Render text on the bar
        libtcod.console_set_default_foreground(self.console, color_ui_text)
        libtcod.console_print_ex(self.console, x + total_width / 2, y, libtcod.BKGND_NONE, libtcod.CENTER, name + ": " + str(value) + "/" + str(maximum))
Ejemplo n.º 13
0
    def clear(self, back_color):

        #Set the whole panel to the default background
        libtcod.console_set_default_background(self.console, back_color)
        for y in range(self.height - 1):
            for x in range(self.width - 1):
                libtcod.console_put_char_ex(self.console, x, y, ' ', color_dark_wall, color_dark_bg)
Ejemplo n.º 14
0
def render_bar(x, y, total_width, name, value, maximum, bar_color, back_color):
    # render a bar (HP, experience, etc). first calculate the width of the bar
    bar_width = int(float(value) / maximum * total_width)

    # render the background first
    libtcod.console_set_default_background(panel, back_color)
    libtcod.console_rect(panel, x, y, total_width, 1, False,
                         libtcod.BKGND_SCREEN)

    # now render the bar on top
    libtcod.console_set_default_background(panel, bar_color)
    if bar_width > 0:
        libtcod.console_rect(panel, x, y, bar_width, 1, False,
                             libtcod.BKGND_SCREEN)

    # finally, some centered text with the values
    libtcod.console_set_default_foreground(panel, libtcod.white)
    libtcod.console_print_ex(
        panel,
        x + int(total_width / 2),
        y,
        libtcod.BKGND_NONE,
        libtcod.CENTER,
        name + ": " + str(value) + "/" + str(maximum),
    )
Ejemplo n.º 15
0
def render_bar(panel,
               x,
               y,
               total_width,
               name,
               value,
               maximum,
               bar_color,
               back_color,
               font_color=libtcod.white):
    bar_width = int(float(value) / maximum * total_width)

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

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

    libtcod.console_set_default_foreground(panel, font_color)
    libtcod.console_print_ex(panel, int(x + total_width / 2), y,
                             libtcod.BKGND_NONE, libtcod.CENTER,
                             '{0}: {1}/{2}'.format(name, value, maximum))
Ejemplo n.º 16
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.render_all()

			libtcod.console_blit(box, 0, 0, 1, 1, 0, x, y, 1.0, 0.5) #0.7 is the transparency
			libtcod.console_flush()

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

			if key.vk == libtcod.KEY_ESCAPE:
				return (None, None)

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

			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)
Ejemplo n.º 17
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.render_all()

            libtcod.console_blit(box, 0, 0, 1, 1, 0, x, y, 1.0,
                                 0.5)  #0.7 is the transparency
            libtcod.console_flush()

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

            if key.vk == libtcod.KEY_ESCAPE:
                return (None, None)

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

            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)
Ejemplo n.º 18
0
 def set_minimap(self, size):
     self.minimap_width  = size+3
     self.minimap_height = size+3
     self.minimap_buffer  = libtcod.ConsoleBuffer(self.minimap_width, self.minimap_height)
     self.minimap_console = libtcod.console_new(self.minimap_width, self.minimap_height)
     libtcod.console_set_default_foreground(self.minimap_console, libtcod.white)
     libtcod.console_set_default_background(self.minimap_console, libtcod.black)
Ejemplo n.º 19
0
    def __init__(self, tilelist, fadetime, color1, color2):
        self.tilelist = tilelist
        self.color1 = color1
        self.color2 = color2
        allx = map(lambda tile: tile.x, self.tilelist)
        ally = map(lambda tile: tile.y, self.tilelist)
        minx = min(allx)
        maxx = max(allx)
        miny = min(ally)
        maxy = max(ally)
        self.blitx = minx
        self.blity = miny
        width = maxx - minx + 1
        height = maxy - miny + 1
        EffectCon.__init__(self, width, height, fadetime)

        libtcod.console_set_key_color(self.console, libtcod.silver)
        libtcod.console_set_default_background(self.console,
                                               libtcod.silver)  #key color

        idx = [0, self.maxduration]
        col = [self.color1, self.color2]
        self.colormap = libtcod.color_gen_map(col, idx)

        newcoordlist = []
        for tile in self.tilelist:
            newcoordlist.append((tile.x - minx, tile.y - miny))
        self.con_coords = newcoordlist

        activeeffects.append(self)
Ejemplo n.º 20
0
def update():
    global DRAW_CALLS

    for call in DRAW_CALLS[:constants.MAX_DRAW_CALLS_PER_FRAME]:
        _draw_list = list(call)

        if not _draw_list:
            continue

        for draw in _draw_list:
            surface_name, x, y, c, fore_color, back_color = draw

            _set_char(surface_name,
                      x,
                      y,
                      c,
                      fore_color=fore_color,
                      back_color=back_color)

    DRAW_CALLS = DRAW_CALLS[constants.MAX_DRAW_CALLS_PER_FRAME:]

    tcod.console_set_default_background(0, tcod.dark_gray)
    tcod.console_fill_char(0, SCREEN['c'])
    tcod.console_fill_background(0, SCREEN['b'][0], SCREEN['b'][1],
                                 SCREEN['b'][2])
    tcod.console_fill_foreground(0, SCREEN['f'][0], SCREEN['f'][1],
                                 SCREEN['f'][2])

    _clear_screen()
    cleanup()
Ejemplo n.º 21
0
def character_sheet_ui(con, width, height, header):
	game.messages.box_gui(con, 0, 0, width, height)
	libtcod.console_set_default_foreground(con, libtcod.black)
	libtcod.console_set_default_background(con, libtcod.green)
	libtcod.console_print_ex(con, width / 2, 0, libtcod.BKGND_SET, libtcod.CENTER, header)
	libtcod.console_set_default_foreground(con, libtcod.white)
	libtcod.console_set_default_background(con, libtcod.black)
Ejemplo n.º 22
0
	def build(self,con):

		libtcod.console_set_default_background(con,self.bcg_color)
		libtcod.console_set_default_foreground(con,self.color)
		libtcod.console_print_ex(con,0,0,libtcod.BKGND_SET,libtcod.LEFT,self.text)
		self.width=len(self.text)
		self.height=1
Ejemplo n.º 23
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)
Ejemplo n.º 24
0
def render_bar(x, y, total_width, name, value, maximum, bar_color, back_color):
    """ Generic status bar renderer.

    Can be used for health bar, mana bar, experience bar, dungeon level, etc.

    """
    global panel

    # determine the width of the bar to render.
    bar_width = int(float(value) / maximum * total_width)

    # render the background bar.
    libtcod.console_set_default_background(panel, back_color)
    libtcod.console_rect(panel, x, y, total_width, 1, False,
                         libtcod.BKGND_SCREEN)

    # render the foreground bar.
    libtcod.console_set_default_background(panel, bar_color)
    if bar_width > 0:
        libtcod.console_rect(panel, x, y, bar_width, 1, False,
                             libtcod.BKGND_SCREEN)

    # render some centered text with the values
    msg = '{}: {}/{}'.format(name, value, maximum)
    libtcod.console_set_default_foreground(panel, libtcod.white)
    libtcod.console_print_ex(panel, x + total_width / 2, y, libtcod.BKGND_NONE,
                             libtcod.CENTER, msg)
Ejemplo n.º 25
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)
Ejemplo n.º 26
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
Ejemplo n.º 27
0
def render_bar(x, y, total_width, name, value, maximum, bar_color, back_color):
    #render a bar (HP, experience, etc). first calculate the width of the bar
    bar_width = int(float(value) / maximum * total_width)

    #render the background first
    libtcod.console_set_default_background(panel, back_color)
    libtcod.console_rect(panel, x, y, total_width, 1, False,
                         libtcod.BKGND_SCREEN)

    #now render the bar on top
    libtcod.console_set_default_background(panel, bar_color)
    if bar_width > 0:
        libtcod.console_rect(panel, x, y, bar_width, 1, False,
                             libtcod.BKGND_SCREEN)

    #finally, some centered text with the values
    libtcod.console_set_default_foreground(panel, libtcod.white)
    libtcod.console_print_ex(panel, x + total_width / 2, y, libtcod.BKGND_NONE,
                             libtcod.CENTER,
                             name + ': ' + str(value) + '/' + str(maximum))

    #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
Ejemplo n.º 28
0
    def render_gui(self, player, names_under_mouse, active_level):
        # show the player's stats
        tcod.console_set_default_foreground(self._con, tcod.white)

        # prepare to render the GUI panel
        tcod.console_set_default_background(self._panel, tcod.black)
        tcod.console_clear(self._panel)

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

        #show the player's stats
        self.render_bar(1, 1, BAR_WIDTH, 'HP', player.fighter.hp,
                        player.fighter.max_hp, tcod.light_red, tcod.darker_red)
        tcod.console_print_ex(self._panel, 1, 3, tcod.BKGND_NONE, tcod.LEFT,
                              'Dungeon level ' + str(active_level))
        # display names of objects under the mouse
        tcod.console_set_default_foreground(self._panel, tcod.light_gray)
        tcod.console_print_ex(self._panel, 1, 0, tcod.BKGND_NONE, tcod.LEFT,
                              names_under_mouse)
Ejemplo n.º 29
0
def render_all():
    global color_dark_wall, color_light_wall
    global color_dark_ground, color_light_ground
    global fov_recompute

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

        for y in range(MAP_HEIGHT):
            for x in range(MAP_WIDTH):
                visible = libtcod.map_is_in_fov(fov_map, x, y)
                wall = map[x][y].block_sight
                if not visible:
                    if map[x][y].explored:
                        if wall:
                            libtcod.console_put_char_ex(con, x, y, '#', color_dark_wall, libtcod.BKGND_SET)
                            #libtcod.console_set_char_background(con, x, y, color_dark_wall, libtcod.BKGND_SET)
                        else:
                            libtcod.console_put_char_ex(con, x, y, '.', color_dark_ground, libtcod.BKGND_SET)
                            #libtcod.console_set_char_background(con, x, y, color_dark_ground, libtcod.BKGND_SET)
                else:
                    if wall:
                        libtcod.console_put_char_ex(con, x, y, '#', color_light_wall, libtcod.BKGND_SET)
                    else:
                        libtcod.console_put_char_ex(con, x, y, '.', color_light_ground, libtcod.BKGND_SET)

                    map[x][y].explored = True

    # Draw all objects in the list
    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 panel
    libtcod.console_set_default_background(panel, libtcod.black)
    libtcod.console_clear(panel)

    # Print the game messages
    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

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

    # Display names of objects under the mouse
    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 the contents of "panel" to the root console
    libtcod.console_blit(panel, 0, 0, SCREEN_WIDTH, PANEL_HEIGHT, 0, 0, PANEL_Y)
Ejemplo n.º 30
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)
			wall = map[x][y].block_sight
			if not visible:
				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
			else:
				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)
				map[x][y].explored = True

	#draw all objects, with the player last
	for object in objects:
		if object != player:
			object.draw()
		player.draw()

###################
## GUI ELEMENTS

	#preparing to render to panel
	libtcod.console_set_default_background(panel, libtcod.black)
	libtcod.console_clear(panel)

	#display the message box
	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

	#show some stats
	#render_bar(1,1,BAR_WIDTH,'HP',player.body.hp,player.body.max_hp,libtcod.light_red,libtcod.darker_red)

	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 the panel to the screen
	libtcod.console_blit(panel,0,0,SCREEN_WIDTH,PANEL_HEIGHT,0,0,PANEL_Y)


	#blit our off-screen console
	libtcod.console_blit(con,0,0,MAP_WIDTH,MAP_HEIGHT,0,0,0)
Ejemplo n.º 31
0
def render_all():

    for entity in entities:
        entity.draw()

    for y in range(MAP_HEIGHT):
        for x in range(MAP_WIDTH):
            wall = map[x][y].block_sight
            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)

    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)

    global player
    render_bar(30, 1, BAR_WIDTH, 'HP', player.stats["health"], 100,
               libtcod.light_red, libtcod.darker_red)

    global events

    render_text(10, 3, "Inventory", player.inventory)
    render_text(5, 5, "Events", events)

    libtcod.console_blit(panel, 0, 0, SCREEN_WIDTH, PANEL_HEIGHT, 0, 0,
                         PANEL_Y)
Ejemplo n.º 32
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)
Ejemplo n.º 33
0
	def __init__(self, root_console_width, root_console_height, frame_manager):
		self.entity_manager = frame_manager.parent_menu.entity_manager

		# load xp for bg
		console_bg_xp = gzip.open('assets\\ui\\ui_frame_libraries_bg.xp')
		self.bg_data = xp_loader.load_xp_string(console_bg_xp.read())

		Frame.__init__(self, root_console_width, root_console_height, self.bg_data['width'], self.bg_data['height'], frame_manager)

		library_start_xy = xp_loader.get_position_key_xy(self.bg_data['layer_data'][1], xp_loader.poskey_color_red)

		self.library_start_xy = Vec2d(library_start_xy[0], library_start_xy[1])
		self.library_line_extent = xp_loader.get_position_key_xy(self.bg_data['layer_data'][1], xp_loader.poskey_color_green)

		#TODO put these in config somewhere
		self.line_char = chr(196)
		self.line_bg = libtcod.Color(2, 22, 12)
		self.line_fg = libtcod.Color(6, 130, 60)
		self.libname_fg = libtcod.Color(102, 255, 178)

		libtcod.console_set_default_background(self.console,self.line_bg)
		libtcod.console_set_default_foreground(self.console,self.libname_fg)
		libtcod.console_set_alignment(self.console, libtcod.LEFT)

		xp_loader.load_layer_to_console(self.console, self.bg_data['layer_data'][0])
Ejemplo n.º 34
0
def render_bar(panel,
               x,
               y,
               total_width,
               name,
               value,
               maximum,
               bar_color,
               back_color,
               fore_color=libtcod.white):
    bar_width = int(float(value) / maximum * total_width)

    # Render the background
    libtcod.console_set_default_background(panel, back_color)
    libtcod.console_rect(panel, x, y, total_width, 1, False,
                         libtcod.BKGND_SCREEN)

    # Render the filled section of the bar
    libtcod.console_set_default_background(panel, bar_color)
    if bar_width > 0:
        libtcod.console_rect(panel, x, y, bar_width, 1, False,
                             libtcod.BKGND_SCREEN)

    # Render centered text containing the actual value
    libtcod.console_set_default_foreground(panel, fore_color)
    label = consts.BAR_TEXT_TEMPLATE.format(name=name,
                                            value=value.__str__(),
                                            max=maximum.__str__())
    bar_center = x + total_width // 2
    libtcod.console_print_ex(panel, bar_center, y, libtcod.BKGND_NONE,
                             libtcod.CENTER, label)
Ejemplo n.º 35
0
    def draw(self, main_map):
        #Settings
        libtcod.console_set_default_background(self.console, libtcod.black)
        libtcod.console_set_alignment(self.console, libtcod.CENTER)

        if main_map.selected_unit:
            start = (self.width - 4)/2
            #Draw all units in the unit image
            for x in range(self.width - 4):
                for y in range(self.width - 4):
                    libtcod.image_put_pixel(self.unit_image, x, y, main_map.map_list[main_map.selected_unit.x + x - start][main_map.selected_unit.y + y - start].color)
                    for u in main_map.units:
                        if u.x == (main_map.selected_unit.x + x - start) and u.y == (main_map.selected_unit.y + y - start):
                            libtcod.console_set_char_foreground(self.console, x + 2, y + 4, u.color)
                            libtcod.console_set_char(self.console, x + 2, y + 4, u.char)

            libtcod.console_print_frame(self.console, 0, 0, self.width, self.height, False, libtcod.BKGND_NONE, main_map.selected_unit.name)
            libtcod.console_rect(self.console, 0,0, 20, 1, False)
            libtcod.image_blit_rect(self.unit_image, self.console, 2, 4, self.width - 4, self.width - 4, libtcod.BKGND_SET)

            libtcod.console_set_alignment(self.console, libtcod.LEFT)
            #Unit stats
            statx = self.width + 1
            libtcod.console_print(self.console, 2, statx, 'Speed')
            libtcod.console_print(self.console, 2, statx + 1, 'Attack')
            libtcod.console_print(self.console, 2, statx + 2, 'Armor')

            libtcod.console_set_alignment(self.console, libtcod.RIGHT)
            libtcod.console_print(self.console, self.width - 2, statx, str(main_map.selected_unit.speed))
            libtcod.console_print(self.console, self.width - 2, statx + 1, str(main_map.selected_unit.attack))
            libtcod.console_print(self.console, self.width - 2, statx + 2, str(main_map.selected_unit.armor))

            libtcod.console_blit(self.console, 0, 0, self.width, self.height, 0, 1, 60 - self.height/2, 1, 0.75)
Ejemplo n.º 36
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)
Ejemplo n.º 37
0
Archivo: gui.py Proyecto: 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())
Ejemplo n.º 38
0
def render_gui():
    #render GUI
    global game_msgs, hint
    libtcod.console_set_default_background(panel, libtcod.black)
    libtcod.console_clear(panel)
    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

    render_bar(1, 1, BAR_WIDTH, "HP", player.fighter.hp, player.fighter.max_hp,
               libtcod.light_red, libtcod.darker_red)
    #render the mouseview hint
    if hint == "":
        hint = get_names_under_mouse().capitalize()

    libtcod.console_set_default_foreground(panel, libtcod.light_gray)
    libtcod.console_print_ex(panel, 1, 0, libtcod.BKGND_NONE, libtcod.LEFT,
                             hint)

    #render turncount
    libtcod.console_print_ex(panel, 1, 3, libtcod.BKGND_NONE, libtcod.LEFT,
                             "Turn {0}".format(turncount))
    libtcod.console_blit(panel, 0, 0, SCREEN_WIDTH, PANEL_HEIGHT, 0, 0,
                         PANEL_Y)
Ejemplo n.º 39
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)
Ejemplo n.º 40
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)
Ejemplo n.º 41
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)
Ejemplo n.º 42
0
    def __init__(self, root_console_width, root_console_height, frame_manager):
        self.entity_manager = frame_manager.parent_menu.entity_manager

        # load xp for bg
        console_bg_xp = gzip.open('assets\\ui\\ui_frame_libraries_bg.xp')
        self.bg_data = xp_loader.load_xp_string(console_bg_xp.read())

        Frame.__init__(self, root_console_width, root_console_height,
                       self.bg_data['width'], self.bg_data['height'],
                       frame_manager)

        library_start_xy = xp_loader.get_position_key_xy(
            self.bg_data['layer_data'][1], xp_loader.poskey_color_red)

        self.library_start_xy = Vec2d(library_start_xy[0], library_start_xy[1])
        self.library_line_extent = xp_loader.get_position_key_xy(
            self.bg_data['layer_data'][1], xp_loader.poskey_color_green)

        #TODO put these in config somewhere
        self.line_char = chr(196)
        self.line_bg = libtcod.Color(2, 22, 12)
        self.line_fg = libtcod.Color(6, 130, 60)
        self.libname_fg = libtcod.Color(102, 255, 178)

        libtcod.console_set_default_background(self.console, self.line_bg)
        libtcod.console_set_default_foreground(self.console, self.libname_fg)
        libtcod.console_set_alignment(self.console, libtcod.LEFT)

        xp_loader.load_layer_to_console(self.console,
                                        self.bg_data['layer_data'][0])
Ejemplo n.º 43
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)
Ejemplo n.º 44
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;
Ejemplo n.º 45
0
def main_menu():
	img = libtcod.image_load('menu_background.png')
	
	
	while not libtcod.console_is_window_closed():
		#show the menu image in a terrible way
		libtcod.image_blit_2x(img, 0, 0, 0)
		
		#fancy main menu title and crediting
		libtcod.console_set_default_foreground(0, libtcod.white)
		libtcod.console_set_default_background(0, libtcod.black)
		libtcod.console_print_ex(0, SCREEN_WIDTH/2, SCREEN_HEIGHT/2-4, libtcod.BKGND_ALPHA(0.7), libtcod.CENTER, 'JOTAF\'S COMPLETE ROGUELIKE TUTORIAL,')
		libtcod.console_print_ex(0, SCREEN_WIDTH/2, SCREEN_HEIGHT/2-3, libtcod.BKGND_ALPHA(0.7), libtcod.CENTER, 'USING PYTHON+LIBTCOD')
		#libtcod.console_print_ex(0, SCREEN_WIDTH/2, SCREEN_HEIGHT-2, libtcod.BKGND_ALPHA(0.7), libtcod.CENTER, 'Implemented By')
		
		#show main menu optionss and request selection
		choice = menu('', ['Play a new game', 'Continue last game', 'Quit'], 24)
		
		#fullscreen toggle needs to work in main menu too
		#if key.vk == libtcod.KEY_ENTER and key.lalt:
		#	libtcod.console_set_fullscreen(not libtcod.console_is_fullscreen())
		
		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', 24)
				continue
			play_game()
		elif choice == 2: #quit
			break
Ejemplo n.º 46
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):
    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_reverse_order = sorted(entities,
                                       key=lambda x: x.render_order.value)

    # Draw all entities in the list
    for entity in entities_in_reverse_order:
        draw_entity(con, entity, fov_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_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.º 47
0
def menu(header, options, width):
    #First, make sure the menu has 26 or fewer items (This is due to an alphabetical selection limitation)
    if len(options) > 26:
        raise ValueError('Cannot have a menu with more than 26 options!')

    #implicitly calculate the height of the window, based on the header height (after word wrap) and the number
    # of options
    header_height = libtcod.console_get_height_rect(con, 0, 0, width, SCREEN_HEIGHT, header)
    if header == '':
        header_height = 0
    height = len(options) + header_height

    #Create an offscreen console that represents the menus window, and a slightly larger one to nest the menu inside of
    #This will create a border effect for the inner menu, strictly asthetic
    outer_window = libtcod.console_new(width + 2, height + 2)
    window = libtcod.console_new(width, height)

    #Print the header to our offscreen console
    libtcod.console_set_default_foreground(window, libtcod.white)
    libtcod.console_set_default_background(window, libtcod.darker_sepia)
    libtcod.console_clear(window)
    libtcod.console_print_rect_ex(window, 0, 0, width, height, libtcod.BKGND_NONE, libtcod.LEFT, header)

    #Print all the options, with a corresponding ASCII character
    y = header_height
    #Get the ASCII value of the letter 'a'
    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

    #Blit the contents of the window to the main game screen, centered
    x = SCREEN_WIDTH / 2 - width / 2
    y = SCREEN_HEIGHT /2 - height / 2

    #Set up the outer window (which only acts as a border for the inner window, strictly graphical)
    libtcod.console_set_default_background(outer_window, libtcod.brass)
    libtcod.console_clear(outer_window)
    #Blit the actual message window onto the outer window, centered and one off from the borders
    libtcod.console_blit(window, 0, 0, width, height, outer_window, 1, 1)
    #Blit the outer window onto the screen, centered
    libtcod.console_blit(outer_window, 0, 0, width + 2, height + 2, 0, x, y)
    #Now that the console is presented to the player, wait for them to make a choice before doing anything else
    libtcod.console_flush()
    key = libtcod.console_wait_for_keypress(True)

    #Clear the main console, so no artifacts from the menu appear
    libtcod.console_clear(0)

    #Check for fullscreen keys
    if key.vk == libtcod.KEY_ENTER and key.lalt:
        #ALT + Enter, toggle fullscreen
        libtcod.console_set_fullscreen(not libtcod.console_is_fullscreen())

    #Convert the ASCII code to an index; if it corresponds to a valid menu item, return it
    index = key.c - ord('a')
    if index >= 0 and index < len(options): return index
    return None
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, colors):
    if fov_recompute:
        for y in range(game_map.height):
            for x in range(game_map.width):
                visible = lcod.map_is_in_fov(fov_map, x, y)
                wall = game_map.tiles[x][y].block_sight

                if visible or game_map.tiles[x][y].explored:
                    game_map.tiles[x][y].explored = True
                    if wall:
                        lcod.console_set_char_background(con, x, y, colors.get("dark_wall"), lcod.BKGND_SET)
                    else:
                        lcod.console_set_char_background(con, x, y, colors.get("dark_ground"), lcod.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)

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

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

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

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

    lcod.console_blit(panel, 0, 0, screen_width, panel_height, 0, 0, panel_y)
Ejemplo n.º 49
0
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)
Ejemplo n.º 50
0
def storyScreen(console):
   libtcod.console_set_default_background(console, STORY_BACKGROUND_COLOUR1)
   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 story message
      libtcod.console_set_default_foreground(console, STORY_FOREGROUND_COLOUR1)
      libtcod.console_print_rect(console, 1, 3, SCREEN_WIDTH, SCREEN_HEIGHT, STORY_TEXT1)
      if(blinkOn):
         libtcod.console_set_default_foreground(console, SPLASH_FOREGROUND_COLOUR3)
         libtcod.console_print_rect(console, 16, 22, SCREEN_WIDTH, SCREEN_HEIGHT, "press any key")

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

      counter += 1
      if counter >= blinkSpeed:
         counter = 0
         blinkOn = not blinkOn
         libtcod.console_clear(console)

   libtcod.console_clear(console)
Ejemplo n.º 51
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)
Ejemplo n.º 52
0
def render_all():
    global color_dark_wall
    global color_dark_ground
    global color_light_ground
    global color_light_wall
    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)
            wall = map[x][y].block_sight
            if not visible:
                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:
                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)
                map[x][y].explored = True

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

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

    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

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

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

    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)
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.º 54
0
 def create_consoles(self):
     self.background = libtcod.console_new(self.game.width,
                                           self.game.height)
     self.foreground = libtcod.console_new(self.game.width,
                                           self.game.height)
     libtcod.console_set_default_background(self.background, libtcod.blue)
     libtcod.console_set_default_background(self.foreground, libtcod.black)
     self.consoles = [self.background, self.foreground]
Ejemplo n.º 55
0
 def __init__(self, width, height):
     super(Credits, self).__init__(width, height)
     libtcod.console_set_default_background(self.console,
                                            MENU_BACKGROUND_COLOR)
     libtcod.console_set_default_foreground(self.console, MENU_TEXT_COLOR_1)
     self.text = []
     for i in range(len(self.TEXT)):
         self.text.append(self.TEXT.get(i))
Ejemplo n.º 56
0
def display_text(console, text, x=0, y=0, front=tcod.white, back=tcod.black):
    previous_back = tcod.console_get_default_background(console)
    previous_fore = tcod.console_get_default_foreground(console)
    tcod.console_set_default_background(console, back)
    tcod.console_set_default_foreground(console, front)
    tcod.console_print_ex(console, x, y, tcod.BKGND_SET, tcod.LEFT, text)
    tcod.console_set_default_background(console, previous_back)
    tcod.console_set_default_foreground(console, previous_fore)
Ejemplo n.º 57
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_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)


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