Beispiel #1
0
def main_menu():
    img = libtcod.image_load(b'img/backgrounds/menu_background.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
        libtcod.console_set_default_foreground(0, libtcod.light_yellow)
        libtcod.console_set_alignment(0, libtcod.CENTER)
        libtcod.console_print(0, int(round(SCREEN_WIDTH / 2)),
                              int(round(SCREEN_HEIGHT / 2 - 4)),
                              'THE LEGEND OF THARSA')
        libtcod.console_print(0, int(round(SCREEN_WIDTH / 2)),
                              int(round(SCREEN_HEIGHT - 2)),
                              'By Athemis')

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

        if choice == 0:  # New game
            new_game()
            play_game()
        elif 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
Beispiel #2
0
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)
 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()
Beispiel #4
0
def choice_menu(header, options, width):
    if len(options) > 26: raise ValueError(u"Cannot have a menu with more than 26 options.")

    header_hight = libtcod.console_get_height_rect(con, 0, 0, width, SCREEN_HEIGHT, header)
    height = len(options) + header_hight

    menu_console = libtcod.console_new(width, height)

    libtcod.console_set_default_foreground(menu_console, libtcod.white)
    libtcod.console_print_rect_ex(menu_console, 0, 0, width, height, libtcod.BKGND_NONE, libtcod.LEFT, header)

    # Print options.
    y = header_hight
    letter_index = ord(u"a")
    for option_text in options:
        text = "(%s) %s" % (chr(letter_index), option_text)
        libtcod.console_print(menu_console, 0, y, text)
        y += 1
        letter_index += 1

    x = SCREEN_WIDTH / 2 - width / 2
    y = SCREEN_HEIGHT / 2 - height / 2
    libtcod.console_blit(menu_console, 0, 0, width, height, 0, x, y, 1.0, 0.7)

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

    index = key.c - ord(u"a")
    if index >= 0 and index < len(options):
        return index
    return None
Beispiel #5
0
def main_menu():
	img = libtcod.image_load('menu_background1.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(0, config.SCREEN_WIDTH/2, config.SCREEN_HEIGHT/2-4, 'P U R G E')
		libtcod.console_set_default_foreground(0, libtcod.white)
		libtcod.console_print(0, config.SCREEN_WIDTH/2, config.SCREEN_HEIGHT-2, 'By Nathaniel Berens')
		
		#show options and wait for the player's choice
		choice = gfx.menu(' ', ['Play a new game', 'Continue last game', 'Quit'], 24)
		
		if choice == 0: #new game
			new_game()
			play_game()	
		elif choice == 1: #load last game
			try:
				load_game()
			except:
				gfx.msgbox('\n No saved game to load. \n', 24)
				continue
			play_game()
		elif choice == 2: #quit
			break
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)
Beispiel #7
0
 def print_string(self, x, y, s, alignment=None, bkgnd_flag=None):
     if alignment or bkgnd_flag:
         if not alignment: alignment = self.get_alignment()
         if not bkgnd_flag: bkgnd_flag = self.get_background_flag()
         libtcod.console_print_ex(self.con,x,y,bkgnd_flag,alignment,s)
     else:
         libtcod.console_print(self.con,x,y,s)
Beispiel #8
0
def main_menu():
    if (libtcod.random_get_int(0, 0, 1) == 0):
        img = libtcod.image_load('menu_background.png')
    else:
        img = libtcod.image_load('menu_background2.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.light_yellow)
        libtcod.console_set_alignment(0, libtcod.CENTER)
        libtcod.console_print(0, SCREEN_WIDTH / 2, SCREEN_HEIGHT / 2 - 4, 'Party Rogue WIP')
        libtcod.console_print(0, SCREEN_WIDTH / 2, SCREEN_HEIGHT - 2, 'By Dragynrain')
        libtcod.console_set_alignment(0, libtcod.LEFT)

        #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
            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
    def test_renderScreensInMap(self):
        #윈도우, 루트콘솔 셋팅
        defaultFont = gui.Font('font.png', libtcod.FONT_LAYOUT_ASCII_INROW, 32, 2048)
        gset.setWindow(defaultFont, gset.WINDOW_WIDTH, gset.WINDOW_HEIGHT, 'test window')
        gset.setLimitFps(gset.LIMIT_FPS)

        libtcod.console_print(self.scr1.console, 0,0, 'scr1')
        libtcod.console_print(self.scr2.console, 0,0, 'scr2')

        i = 0
        while not libtcod.console_is_window_closed():
            # ■■■버퍼 지우기■■■
            libtcod.console_clear(0) 

            #맵에 있는 스크린들 모두 그리기
            #빨리 넣은 것이 바닥에 있어야 한다.
            self.map.blitAll()

            #움직이기 렌더링 테스트
            self.map.x -= 1
            self.map.y -= 1

            # ■■■버퍼 비우기■■■
            libtcod.console_flush() 
            
            #다음 테스트로!
            i += 1
            if i == 20:
                break
Beispiel #10
0
 def render_side_panel(self, i, bar_length, bar_offset_x):
   g = self.bg.generals[i]
   libtcod.console_set_default_foreground(self.con_panels[i], libtcod.black)
   libtcod.console_put_char_ex(self.con_panels[i], bar_offset_x-1, 1, g.char, g.color, libtcod.black)
   self.render_bar(self.con_panels[i], bar_offset_x, 1, bar_length, g.hp, g.max_hp, libtcod.red, libtcod.yellow, libtcod.black)
   line = 3
   for j in range(0, len(g.skills)):
     skill = g.skills[j]
     libtcod.console_put_char_ex(self.con_panels[i], bar_offset_x-1, line, KEYMAP_SKILLS[j], libtcod.white, libtcod.black)
     self.render_bar(self.con_panels[i], bar_offset_x, line, bar_length, skill.cd, skill.max_cd,
       libtcod.dark_blue, libtcod.sky, libtcod.black)
     line += 2
   libtcod.console_set_default_foreground(self.con_panels[i], libtcod.white)
   libtcod.console_print(self.con_panels[i], 3, line+1,
                         str(self.bg.generals[i].minions_alive) + " " + self.bg.generals[i].minion.name + "s  ")
   line = self.render_tactics(i) + 1
   libtcod.console_set_default_foreground(self.con_panels[i], libtcod.black)
   swap_ready = g.swap_cd >= g.swap_max_cd
   for r in self.bg.reserves[i]:
     libtcod.console_put_char_ex(self.con_panels[i], bar_offset_x-1, line, r.char, r.color, libtcod.black)
     if swap_ready:
       self.render_bar(self.con_panels[i], bar_offset_x, line, bar_length, r.hp, r.max_hp,
                       libtcod.red, libtcod.yellow, libtcod.black)
     else:
       self.render_bar(self.con_panels[i], bar_offset_x, line, bar_length, g.swap_cd, g.swap_max_cd,
                       libtcod.dark_blue, libtcod.sky, libtcod.black)
     line += 2
Beispiel #11
0
 def display(self, console):
     if self.must_clean:
         libtcod.console_clear(console)
         self.must_clean = False
     if self.has_display_message():
         message = self.consume_message()
         libtcod.console_clear(console)
         libtcod.console_print(console, 0,0,message.complement())
Beispiel #12
0
 def draw(self):
     x = self.pos.x
     if self.centred:
         x -= len(self.text)//2
     if self.colour is None:
         libtcod.console_print(0, x, self.pos.y, self.text) #, libtcod.white, libtcod.BKGND_NONE)
     else:
         libtcod.console_print(0, x, self.pos.y, "%c%s%c"%(self.colour,self.text,self.COLCTRL_STOP))
Beispiel #13
0
	def set_time(self):
		libtcod.console_print(0, game.MAP_X, 1, 'Set time: ')
		libtcod.console_flush()
		choice = game.messages.input('', 0, game.MAP_X + 10, 1)
		split = choice.split(':')
		game.fov_recompute = True
		game.draw_map = True
		return int(split[0]), int(split[1])
Beispiel #14
0
def draw_visible(con):
    tcod.console_set_default_foreground(con, COL_B)
    ls = []
    for object in game.actors:
        if map.is_fov(object.x, object.y):
            ls.append(object.char)  
    line = ', '.join(ls)
    tcod.console_print(con, 1, game.GAME_HEIGHT - 4, chr(254)+' '+line)
Beispiel #15
0
 def refresh_infobar(self, infobar):
     libtcod.console_clear(infobar)
     infobar_text = ""
     if self.mode == "look":
         for actor in self.level.actors:
             if actor.x == self.cursor.x and actor.y == self.cursor.y and hasattr(actor, "name") == True:
                 infobar_text = infobar_text + actor.name + " "
         libtcod.console_print(infobar, 0, 0, infobar_text)
Beispiel #16
0
def drawUiNormalCar(player):
    if (player.OnCar.Engine is None): return

    message = "Brakes are off"
    if (player.OnCar.Engine.brakesOn == True):
        message = "Brakes are *on*"
    libtcod.console_print(0, 52, 6, message)
    libtcod.console_print(0, 52, 7, "(a) Toggle Brakes")
Beispiel #17
0
def get_filename(append=None):
	libtcod.console_disable_keyboard_repeat()

	height = 3
	width = 50
	
	filename = ''
	window = libtcod.console_new(width, height)
	
	while True: # Don't leave the menu until a valid filename has been written.
		# Print a nice border around the menu.
		libtcod.console_clear(window)
		frame = '#' * width * height
		back = ' ' * (width - 1) * (height - 1)
		libtcod.console_set_default_foreground(window, libtcod.white)
		libtcod.console_print_rect_ex(window, 0, 0, width, height, libtcod.BKGND_NONE, libtcod.LEFT, frame)		
		libtcod.console_print_rect_ex(window, 1, 1, width - 2, height - 2, libtcod.BKGND_NONE, libtcod.LEFT, back)
		
		
		# Print the filename.
		libtcod.console_set_default_foreground(window, libtcod.white)
		if append:
			libtcod.console_print(window, 1, 1, filename + append)
		else:
			libtcod.console_print(window, 1, 1, filename)
		
		# Blit the contents of "window" to the root console.
		x = SCREEN_WIDTH / 2 - width / 2
		y = SCREEN_HEIGHT / 2 - height / 2
		libtcod.console_blit(window, 0, 0, width, height, 0, x, y, 1.0, 0.7)
		
		# Present the root console to the player.
		libtcod.console_flush()
		
		# Wait for a keypress.
		key = libtcod.console_check_for_keypress(libtcod.KEY_PRESSED)
		
		key_char = chr(key.c)
		key_letter_index = key.c - ord('a')
		key_number_index = key.c - ord('0')
		
		# Handle keys.
		if key.vk == libtcod.KEY_ENTER and key.lalt: # Special case: Alt + Enter toggles fullscreen.
			libtcod.console_set_fullscreen(not libtcod.console_is_fullscreen())
		
		if (key_letter_index >= 0 and key_letter_index < 27) or (key_number_index >= 0 and key_number_index < 10):
			filename += key_char
			
		elif key.vk == libtcod.KEY_BACKSPACE or key.vk == libtcod.KEY_DELETE:
			filename = filename[:len(filename)-1]
				
		elif key.vk == libtcod.KEY_ENTER:
			if append:
				filename += append
			return filename
		
		elif key.vk == libtcod.KEY_ESCAPE:
			return None
Beispiel #18
0
    def draw_panel(self):
        # TODO: Change background color back to black after testing
        libtcod.console_set_default_background(self.console_panel, libtcod.dark_gray)
        libtcod.console_clear(self.console_panel)

        for index in range(len(self.message_panel.messages)):
            libtcod.console_print(self.console_panel, 0, index, self.message_panel.messages[index])

        libtcod.console_blit(self.console_panel, 0, 0, self.message_panel.width, self.message_panel.height, 0, self.message_panel.x, self.message_panel.y)
Beispiel #19
0
    def draw(self):
        libtcod.console_clear(self.console)
        libtcod.console_hline(self.console, 0, 0, self.width)

        libtcod.console_set_alignment(self.console, libtcod.LEFT)
        libtcod.console_print(self.console, 0, 0, "COMMANDS")

        libtcod.console_hline(self.console, 0, self.height - 1, self.width)
        libtcod.console_blit(self.console, 0, 0, self.width, self.height, 0, self.start_x, 0)
Beispiel #20
0
def render_message_panel():
	y = 0
	libtcod.console_clear(game.panel)
	for i in range(max(0, len(game.message.log) - game.MESSAGE_HEIGHT - game.old_msg), len(game.message.log) - game.old_msg):
		libtcod.console_set_default_foreground(game.panel, game.message.log[i][1])
		libtcod.console_print(game.panel, 0, y, game.message.log[i][0])
		y += 1
	scrollbar(game.panel, game.MESSAGE_WIDTH - 1, 0, game.old_msg, game.MESSAGE_HEIGHT, len(game.message.log), True)
	libtcod.console_blit(game.panel, 0, 0, game.MESSAGE_WIDTH, game.MESSAGE_HEIGHT, 0, game.MESSAGE_X, game.MESSAGE_Y)
Beispiel #21
0
 def render_tactics(self, i):
   bar_offset_x = 3
   line = 7 + len(self.bg.generals[i].skills)*2
   for s in range(0, len(self.bg.generals[i].tactics)):
     libtcod.console_set_default_foreground(self.con_panels[i],
       libtcod.red if self.bg.generals[i].tactics[s] == self.bg.generals[i].selected_tactic else libtcod.white)
     libtcod.console_print(self.con_panels[i], bar_offset_x, line, KEYMAP_TACTICS[s] + ": " + self.bg.generals[i].tactic_quotes[s])
     line += 2
   return line
Beispiel #22
0
def menu(header, options, width, options_params=None):
    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_foreground(window, libtcod.white)
    libtcod.console_print_rect(window, 0, 0, width, height, header)

    # print all the options
    y = header_height
    letter_index = ord('a')

    longest_text = 0

    for option_text in options:
        text = '(' + chr(letter_index) + ') ' + option_text
        libtcod.console_print(window, 0, y, text)
        y += 1
        letter_index += 1

        if len(text) > longest_text:
            longest_text = len(text)

    # draw a line between the letter and the option
    libtcod.console_vline(window, 3, header_height,
                          height, libtcod.BKGND_LIGHTEN)

    if options_params:
        y = header_height
        last_char_x = longest_text
        # draw a line between the letter and the option
        libtcod.console_vline(window, last_char_x, header_height,
                              height, libtcod.BKGND_LIGHTEN)
        for param in options_params:
            libtcod.console_print(window, last_char_x+1, y, str(param))
            y += 1
            if len(str(param)) > longest_text:
                longest_text = len(str(param))

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

    # present the root console to the player
    libtcod.console_flush()
Beispiel #23
0
def draw_log(con, n_lines):
    tcod.console_set_default_foreground(con, COL_A)
    log_y = game.GAME_HEIGHT - n_lines - 1
    while len(game.game_log) < n_lines: #dummy lines at game start
        game.game_log.append('\b')

    for i in range(n_lines):
        c = (i-(i*30)-50)
        tcod.console_set_default_foreground(con, tcod.Color(c, c, c))
        tcod.console_print(con, 1, log_y - i, game.game_log[len(game.game_log)-1-i])
Beispiel #24
0
def save_game():
	util.render_map()
	libtcod.console_print(0, game.MAP_X, game.MAP_Y, 'Do you want to save (and quit) the game? (y/n)')
	libtcod.console_flush()
	key = libtcod.Key()

	libtcod.sys_wait_for_event(libtcod.EVENT_KEY_PRESS, key, libtcod.Mouse(), True)
	if chr(key.c) == 'y' or chr(key.c) == 'Y':
		return True
	return False
Beispiel #25
0
def draw_inventory(con, inventory, title):
    INVENTORY_HEIGHT = len(inventory)+2
    xx = game.GAME_WIDTH/2 - INVENTORY_WIDTH/2
    yy = game.GAME_HEIGHT/2 - INVENTORY_HEIGHT/2
    tcod.console_set_default_foreground(con, COL_A)
    tcod.console_print_frame(con, xx, yy, INVENTORY_WIDTH, INVENTORY_HEIGHT, fmt=title)
    for i in range(len(inventory)):
        line =' %s - %s'  % (chr(ord('a')+i), inventory[i].name)
        if inventory[i].equipment and inventory[i].equipment.is_equipped:
            line += ' '+ chr(tcod.CHAR_BULLET_SQUARE)
        tcod.console_print(con, xx+2, yy+1+i, line)
    tcod.console_flush()
Beispiel #26
0
def print_messages(con, x, y):
    global screen_messages
    lbt.console_print(con,
                      x, 
                      y,
                      "Messages: ")
    for i in xrange(len(screen_messages)):
        lbt.console_print(con,
                          x,
                          i+y+1,
                          screen_messages[i])
    screen_messages = []
Beispiel #27
0
    def draw(self, console):
        #The Map draws all of the tiles.
        libtcod.console_set_default_foreground(console, libtcod.white)

        for y in range(self.height):
            row = ''
            for x in range(self.width):
                char = self.tiles[x][y].sprite.char
                color = self.tiles[x][y].sprite.color
                rgb = (color.r, color.g, color.b)
                row += ('%c%c%c%c%c%c%c%c%c%c' % ((libtcod.COLCTRL_FORE_RGB, ) + rgb + (libtcod.COLCTRL_BACK_RGB, ) + (1,1,1) + (char, libtcod.COLCTRL_STOP)))
            libtcod.console_print(console, 0, y, row)
Beispiel #28
0
def menu(header, options, width):
    global key
    global mouse

    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)
    if header == '':
        header_height = 0
    height = len(options) + header_height

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

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

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

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

    # Present the root console to the player and wait for a key-press
    libtcod.console_flush()

    libtcod.sys_wait_for_event(libtcod.EVENT_KEY_PRESS, key, mouse, False)

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

    # Convert the ASCII code to an index; if it corresponds to an
    # option, return it
    index = key.c - ord('a')
    if index >= 0 and index < len(options):
        return index
    return None
Beispiel #29
0
def showmessages(color=libtcod.white):
    global msghist
    
    libtcod.console_clear(message.con)
    
    for i in range(1, MSG_HEIGHT):
        
        msgindex = len(msghist) - i
        value = -1 * (i * 0.05)
        
        if msgindex > 0:
            libtcod.console_set_default_foreground(message.con, applyval(color,value))
            libtcod.console_print(message.con, 0, MSG_HEIGHT-i, msghist[msgindex])
Beispiel #30
0
def render(self):
	libtcod.console_clear(self.con)
	i = 0
	while i < len(self.current_menu):
		if type(self.current_menu[i]) is list:
			to_print = self.current_menu[i][0]
		else:
			to_print = self.current_menu[i]
		libtcod.console_print(self.con, 5, 10 + i, to_print)
		i += 1
	libtcod.console_print(self.con, 3, 10 + self.menu_choice, "*")
	libtcod.console_blit(self.con, 0, 0, 0, 0, 0, 1, 1)
	libtcod.console_flush()
Beispiel #31
0
    def render(self, entity):
        """Renders an entity's inventory in the given window.
        
        Arguments:
        entity - the entity whose inventory you want to render
        
        """
        # Background
        libtcod.console_set_default_background(0, libtcod.black)
        libtcod.console_set_default_foreground(0, libtcod.black)
        libtcod.console_rect(0, self.x_offset, self.y_offset, self.width,
                             self.height, True, libtcod.BKGND_SET)

        libtcod.console_set_default_foreground(0, libtcod.white)
        libtcod.console_print(0, self.x_offset + 1, self.y_offset + 1,
                              entity.name)

        if entity.inventory is None:
            libtcod.console_print(
                0, self.x_offset + 1, self.y_offset + 3,
                "This entity has no inventory.  %s" % DEBUG_MSG)
        else:
            char_list = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"

            # Draw actions text - highlight the selected one
            libtcod.console_set_color_control(libtcod.COLCTRL_1, libtcod.blue,
                                              libtcod.black)
            libtcod.console_set_color_control(libtcod.COLCTRL_2, libtcod.blue,
                                              libtcod.white)
            libtcod.console_set_color_control(libtcod.COLCTRL_3, libtcod.black,
                                              libtcod.white)

            action_text = "%cU%cse%c   %cD%crop%c   %cT%chrow%c   %cC%consume%c   %cE%cquip%c   %cW%cear%c"
            action_text_format = [
                libtcod.COLCTRL_1, libtcod.COLCTRL_STOP, libtcod.COLCTRL_STOP
            ] * 6
            if self.action_filter is not None:
                index = ["use", "drop", "throw", "consume", "equip",
                         "wear"].index(self.action_filter)
                action_text_format[index * 3 + 0] = libtcod.COLCTRL_2
                action_text_format[index * 3 + 1] = libtcod.COLCTRL_3

            action_text = action_text % tuple(action_text_format)
            libtcod.console_print(0, self.x_offset + 1, self.y_offset + 3,
                                  action_text)

            # Set up screen offsets for rendering
            lcol = self.x_offset + 1
            rcol = self.x_offset + 25
            lrow = rrow = self.y_offset + 5

            # In the case of no items, render_types will return 0, but still render a line (none) - so we need to
            # take this line into account when adjusting offsets.
            char_index = 0
            num_weapons = self.render_types(entity.inventory, lcol, lrow,
                                            EntityType.WEAPON, "WEAPONS",
                                            char_list[char_index:])
            lrow += max(1, num_weapons) + 3
            char_index += num_weapons
            num_clothing = self.render_types(entity.inventory, rcol, rrow,
                                             EntityType.CLOTHING, "CLOTHING",
                                             char_list[char_index:])
            rrow += max(1, num_clothing) + 3
            char_index += num_clothing
            num_comestibles = self.render_types(entity.inventory, lcol, lrow,
                                                EntityType.COMESTIBLE,
                                                "COMESTIBLES",
                                                char_list[char_index:])
            lrow += max(1, num_comestibles) + 3
            char_index += num_comestibles
            num_medecine = self.render_types(entity.inventory, rcol, rrow,
                                             EntityType.MEDECINE, "MEDECINE",
                                             char_list[char_index:])
            rrow += max(1, num_medecine) + 3
            char_index += num_medecine
            num_other = self.render_types(entity.inventory, lcol, lrow,
                                          EntityType.OTHER, "OTHER",
                                          char_list[char_index:])
Beispiel #32
0
def render(self):
	libtcod.console_clear(self.overview_con)
	libtcod.console_clear(self.debug_con)
	libtcod.console_clear(self.region_con)
	
	#draw overview map
	for x in range(0, OVERVIEW_SCREEN_WIDTH):
		for y in range(0, OVERVIEW_SCREEN_HEIGHT):
			#height = self.world[self.cameraX + x][self.cameraY + y].average_height
			draw_region(x,y,self.world[self.cameraX+x][self.cameraY+y].average_height,self.world[self.cameraX+x][self.cameraY+y].biome,self.overview_con)
			#if height < WATER_THRESHOLD:
			#	libtcod.console_put_char_ex(self.overview_con, x,y, '~', libtcod.lighter_blue * (height * 1.5 + 1), libtcod.blue * (height *1.5 + 1))
			#elif height >= WATER_THRESHOLD and height < TREELINE:
			#	libtcod.console_put_char_ex(self.overview_con,x,y, chr(33),libtcod.green * (height *-1.5 +1), libtcod.dark_green * (height * -1.5 + 1))
			#elif height >= TREELINE:
			#	libtcod.console_put_char_ex(self.overview_con, x,y, '^', libtcod.light_grey, libtcod.dark_grey)
			if self.cursorX - self.cameraX == x and self.cursorY- self.cameraY == y:
				libtcod.console_put_char_ex(self.overview_con,x,y,'X',libtcod.white,libtcod.black)
	
	#draw region map
	for x in range(0,REGION_WIDTH):
		for y in range(0,REGION_HEIGHT):
			draw_tile(x,y,self.world[self.cursorX][self.cursorY].tiles[x][y].height,self.world[self.cursorX][self.cursorY].biome,self.region_con)

	#debug text
	libtcod.console_print(self.debug_con,0,0,"cursorX: " + str(self.cursorX))
	libtcod.console_print(self.debug_con,0,1,"cursorY: " + str(self.cursorY))
	libtcod.console_print(self.debug_con,0,2,"cameraX: " + str(self.cameraX))
	libtcod.console_print(self.debug_con,0,3,"cameraY: " + str(self.cameraY))
	libtcod.console_print(self.debug_con,0,4,"temperature: " + str(self.world[self.cursorX][self.cursorY].temperature))
	libtcod.console_print(self.debug_con,0,5,"rainfall:    " + str(self.world[self.cursorX][self.cursorY].rainfall))
	libtcod.console_print(self.debug_con,0,6,"biome: " + self.world[self.cursorX][self.cursorY].biome)
	libtcod.console_print(self.debug_con,0,7,"avg.height: " + str(self.world[self.cursorX][self.cursorY].average_height))


	libtcod.console_blit(self.debug_con,0, 0, 0, 0, 0, 0, OVERVIEW_SCREEN_HEIGHT + 1)
	libtcod.console_blit(self.region_con,0, 0, 0, 0, 0, OVERVIEW_SCREEN_WIDTH +1,0)
	libtcod.console_blit(self.overview_con, 0, 0, 0, 0, 0, 0, 0)
	libtcod.console_flush()