コード例 #1
0
ファイル: testrl_0.py プロジェクト: meatloaf231/Frontier
 def draw(self):
     #set the color and then draw the object
     if (libtcod.map_is_in_fov(fov_map, self.x, self.y)
             or (self.always_visible and map[self.x][self.y].explored)):
         libtcod.console_set_foreground_color(con, self.color)
         libtcod.console_put_char(con, self.x, self.y, self.char,
                                  libtcod.BKGND_NONE)
コード例 #2
0
ファイル: Jules-Quest.py プロジェクト: okiyama/Jules-Quest
def mainMenu():
    image = libtcod.image_load("menu_background1.png")

    while not libtcod.console_is_window_closed():
        #Shows the background image
        libtcod.image_blit_2x(image, 0, 0, 0)

        #shows the game title and author
        libtcod.console_set_foreground_color(0, libtcod.light_orange)
        libtcod.console_print_center(0, SCREEN_WIDTH/2, SCREEN_HEIGHT/2-5, libtcod.BKGND_NONE, "Jules Quest")
        libtcod.console_print_center(0, SCREEN_WIDTH/2, SCREEN_HEIGHT/2-3, libtcod.BKGND_NONE, "By Julian Jocque")

        menuOptions = ["New Game", "Continue", "Quit"]
        #shows options and waits for a choice

        choice = menu("", menuOptions, MAIN_MENU_WIDTH)

        if choice == 0: #new game
            newGame()
            playGame()
        elif choice == 1: #continue
            try:
                loadGame()
                playGame()
            except:
                msgBox("\n No save file found.\n", MAIN_MENU_WIDTH)
                continue
        #elif choice == 2: #show instructions
        #    menu("\nArrow Keys to move and attack monsters.\nG to pickup an item you are standing on.\nI to open Inventory.\n" +\
        #        "D to open Drop menu.\nP to pause and unpause.\nC to open Character information screen.\n> to go down stairs.\n" +\
        #        "Mouse over a tile to see what is on it, either monsters or items.\n", [], SCREEN_WIDTH/2)
        elif choice == 2: #quit
            break
コード例 #3
0
ファイル: tut.py プロジェクト: tbadams/CaveRL
 def draw(self):
     #only show if it's visible to the player; or it's set to "always visible" and on an explored tile
     if (libtcod.map_is_in_fov(fov_map, self.x, self.y) or
         (self.always_visible and map[self.x][self.y].explored)):
         #set the color and then draw the character that represents this object at its position
         libtcod.console_set_foreground_color(con, self.color)
         libtcod.console_put_char(con, self.x, self.y, self.char, libtcod.BKGND_NONE)
コード例 #4
0
ファイル: RQA.py プロジェクト: alephic/RogueQuestAdventure
def render_all():
    libtcod.map_compute_fov(path_map, player.x, player.y, 0, True, libtcod.FOV_SHADOW)

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

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

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

    render_panel()
    render_inventory()

    blit_consoles()
コード例 #5
0
ファイル: main.py プロジェクト: dizzylee/MoonGame
def main_menu():
    img = libtcod.image_load('moon.png')

    while not libtcod.console_is_window_closed():
        libtcod.image_blit_2x(img, 0, 0, 0)

        libtcod.console_set_foreground_color(0, libtcod.light_yellow)
        libtcod.console_print_center(0, SCREEN_WIDTH / 2,
                                     (SCREEN_WIDTH / 2) - 4,
                                     libtcod.BKGND_NONE, 'Moon Game')
        libtcod.console_print_center(0, SCREEN_WIDTH / 2, SCREEN_HEIGHT - 2,
                                     libtcod.BKGND_NONE, 'James Disley')

        choice = menu('', ['Play a new game', 'Continue last game', 'Quit'],
                      24)

        if choice == 0:
            new_game()
            play_game()
        if choice == 1:
            try:
                load_game()
            except:
                msgbox('\n No saved game to load.\n', 24)
                continue
            play_game()
        elif choice == 2:
            break
コード例 #6
0
    def _printStats(self, console):
        
        c = self.coords[self._selectedX][self._selectedY]
        
        messages = [
            (1, str(tcod.sys_get_fps()) + " FPS"),
            (2, "Coord: (" + str(self._selectedX)+","+str(self._selectedY)+")"),
            (3, "X-Offset: " + str(self._offsetX)),
            (4, "Y-Offset: " + str(self._offsetY)),
            (5, "Altitude: " + str(c.altitude)),
            (6, "Temp    : " + str(c.temp)),
            (7, "Rain    : " + str(c.rainfall)),
            (8, "Salinity: " + str(c.salinity)),
            (9, "Spring  : " + str(c.hasSpring)),
            (10, "Water   : " + str(c.depth)),
            (11, "Source  : " + str(c.source)),
            (12, "Biome   : " + str(c.biome.name))]
            
        tcod.console_set_foreground_color(console, tcod.Color(255,0,127));
        tcod.console_set_background_color(console, tcod.Color(0,0,0));
        for y, msg in messages:
            tcod.console_print_right(console, self._displayWidth-1, 
                                     y, tcod.BKGND_NONE, msg)
        tcod.console_set_foreground_color(console, tcod.Color(255,255,255));
        
        
        
###/////////////////////////////////////////////////////////////////////////////////////////////////
### EOF    
コード例 #7
0
ファイル: main.py プロジェクト: dizzylee/MoonGame
def render_all():
	global fov_map, color_dark_wall, color_light_wall
	global color_dark_ground, color_light_ground
	global fov_recompute

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

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

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

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

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

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

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

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

	for object in objects:
		object.clear()
コード例 #8
0
ファイル: firstrl.py プロジェクト: nrberens/Purge
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_foreground_color(0, libtcod.black)
		libtcod.console_print_center(0, SCREEN_WIDTH/2, SCREEN_HEIGHT/2-4, libtcod.BKGND_NONE, 'P U R G A T O R I O')
		libtcod.console_set_foreground_color(0, libtcod.white)
		libtcod.console_print_center(0, SCREEN_WIDTH/2, SCREEN_HEIGHT-2, libtcod.BKGND_NONE, 'By CitizenArcane')
		
		#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()
		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
コード例 #9
0
ファイル: firstrl.py プロジェクト: nrberens/Purge
def player_card():
	#create an off-screen console that represents the card's window
	window = libtcod.console_new(30, 20)
	
	#print player stats
	libtcod.console_set_foreground_color(window, libtcod.white)
	libtcod.console_print_left(window, 1, 1, libtcod.BKGND_NONE, 'Player')
	libtcod.console_print_left(window, 1, 2, libtcod.BKGND_NONE, 'Class: ' + player.stats.plclass)
	libtcod.console_print_left(window, 1, 3, libtcod.BKGND_NONE, 'STR:' + str(player.stats.str))
	libtcod.console_print_left(window, 1, 4, libtcod.BKGND_NONE, 'DEX:' + str(player.stats.dex))
	libtcod.console_print_left(window, 1, 5, libtcod.BKGND_NONE, 'CON:' + str(player.stats.con))
	libtcod.console_print_left(window, 1, 6, libtcod.BKGND_NONE, 'INT:' + str(player.stats.int))
	libtcod.console_print_left(window, 1, 7, libtcod.BKGND_NONE, 'FTH:' + str(player.stats.fth))
	libtcod.console_print_left(window, 1, 8, libtcod.BKGND_NONE, 'PER:' + str(player.stats.per))
	
	libtcod.console_print_left(window, 1, 10, libtcod.BKGND_NONE, 'AC: ' + str(player.stats.ac))
	libtcod.console_print_left(window, 1, 11, libtcod.BKGND_NONE, 'Encumbrance: ')
	
	libtcod.console_print_left(window, 1, 13, libtcod.BKGND_NONE, 'Hit %: ' + str((20-player.stats.hitdie)*5))
	libtcod.console_print_left(window, 1, 14, libtcod.BKGND_NONE, 'Damage: ' + str(player.stats.mindmg) + ' - ' + str(player.stats.maxdmg))
	
	#blit the contents of "window" to the root console
	libtcod.console_blit(window, 0, 0, 30, 20, 0, 1, 1, 1.0, 0.7)
	
	#present the root console to the player and wait for a key-press
	libtcod.console_flush()
	key = libtcod.console_wait_for_keypress(True)
	
	if key.vk == libtcod.KEY_ENTER and key.lalt:  #(special case) Alt+Enter: toggle fullscreen
		libtcod.console_set_fullscreen(not libtcod.console_is_fullscreen())
	
	return None
コード例 #10
0
def main_menu():
    img = libtcod.image_load('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, and some credits!
        libtcod.console_set_foreground_color(0, libtcod.light_yellow)
        libtcod.console_print_center(0, SCREEN_WIDTH / 2,
                                     SCREEN_HEIGHT / 2 - 6, libtcod.BKGND_NONE,
                                     'TOMBS OF THE ANCIENT KINGS')
        libtcod.console_print_center(0, SCREEN_WIDTH / 2,
                                     SCREEN_HEIGHT / 2 - 4, libtcod.BKGND_NONE,
                                     'By Jotaf')

        # 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()
        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
コード例 #11
0
 def draw(self):
     if libtcod.map_is_in_fov(fovMap, self.x,
                              self.y) or (self.alwaysVisible
                                          and map[self.x][self.y].explored):
         libtcod.console_set_foreground_color(con, self.color)
         libtcod.console_put_char(con, self.x, self.y, self.char,
                                  libtcod.BKGND_NONE)
コード例 #12
0
ファイル: rogue.py プロジェクト: mcgillij/small_rl
def main_menu():
    img = libtcod.image_load('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, and some credits!
        libtcod.console_set_foreground_color(0, libtcod.light_yellow)
        libtcod.console_print_center(0, SCREEN_WIDTH/2, SCREEN_HEIGHT/2-4, libtcod.BKGND_NONE, 'Rogue-LIKE!')
        libtcod.console_print_center(0, SCREEN_WIDTH/2, SCREEN_HEIGHT-2, libtcod.BKGND_NONE, 'By RobBbot')
 
        #show options and wait for the player's choice
        choice = menu('', ['Play a new game', 'Continue last game', 'Controls', '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: 
            msgbox('\n "g" will pickup items\n\n "i" will bring up your inventory \n\n "d" will drop an item on the ground\n\n Arrow keys move the @ around\n\n Casting Spells requires you to click on the\n mob you want to target after selecting \n the scroll from  your inventory')
        elif choice == 3:  #quit
            break
コード例 #13
0
ファイル: testrl_0.py プロジェクト: meatloaf231/Frontier
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 game details, credits, etc
        libtcod.console_set_foreground_color(0, libtcod.light_yellow)
        libtcod.console_print_center(0, SCREEN_WIDTH / 2,
                                     SCREEN_HEIGHT / 2 - 4, libtcod.BKGND_NONE,
                                     'The Frontier')
        libtcod.console_print_center(0, SCREEN_WIDTH / 2, SCREEN_HEIGHT - 2,
                                     libtcod.BKGND_NONE,
                                     'By Winkle and Littlefoot')

        #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 save game
            try:
                load_game()
            except:
                msgbox('\n No save game to load\n', 24)
                continue
            play_game()

        elif choice == 2:  #Quit
            break
コード例 #14
0
    def _printStats(self, console):

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

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

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


###/////////////////////////////////////////////////////////////////////////////////////////////////
### EOF
コード例 #15
0
ファイル: game.py プロジェクト: scgs/tbfch
def menu(header, options, width, skip=None):
    maxoptions = 26
    if skip:
        maxoptions = 25

    if len(options) > maxoptions:
        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_height_left_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_foreground_color(window, libtcod.white)
    libtcod.console_print_left_rect(window, 0, 0, width, height, libtcod.BKGND_NONE, header)

    # print all the options
    y = header_height
    letter_index = ord("a")
    for option_text in options:
        if skip and letter_index == ord(skip):
            letter_index += 1
        text = "(" + chr(letter_index) + ") " + option_text
        libtcod.console_print_left(window, 0, y, libtcod.BKGND_NONE, text)
        y += 1
        letter_index += 1

    # 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 and wait for a key-press
    libtcod.console_flush()
    key = libtcod.console_wait_for_keypress(True)

    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")
    maxindex = len(options) - 1
    if skip and index > ord(skip) - ord("a"):
        maxindex = len(options)
    if index >= 0 and index <= maxindex:
        if skip:
            skippedindex = ord(skip) - ord("a")
            if index == skippedindex:
                return None
            if index > skippedindex:
                return index - 1
        return index
    return None
コード例 #16
0
ファイル: hud.py プロジェクト: bricks42/BrutalRL
def draw_messages(player, start_pos = 0):
	X, Y, W, H = 30, 40, 50, 10
	
	libtcod.console_set_background_color(0, libtcod.black)
	libtcod.console_rect(0, X, Y, W, H, True, libtcod.BKGND_SET)
	
	libtcod.console_set_foreground_color(0, libtcod.white)
	
	if start_pos > 0:
		offset = 1
		libtcod.console_print_left(0, X + 1, Y + 0, libtcod.BKGND_NONE, '? Too many messages; [any] to see more')
	
	else:
		offset = 0
	
	try:
		for m, message in enumerate(player.message_log[start_pos:]):
			color = message.has_seen and libtcod.grey or libtcod.white
			
			libtcod.console_set_foreground_color(0, color)
			
			wrapped = wrap_text(message.text, W - 3, subsequent_indent = ' ')
			
			for line, text in enumerate(wrapped):
				
				if line == 0:
					if message.symbol1:
						libtcod.console_put_char_ex( 0, X + ((message.symbol2 is None) and 1 or 0), Y + offset, message.symbol1[0], message.symbol1[1] * (message.has_seen and 0.5 or 1), message.symbol1[2] * (message.has_seen and 0.5 or 1))
					
					if message.symbol2:
						libtcod.console_put_char_ex( 0, X + 1, Y + offset, message.symbol2[0], message.symbol2[1] * (message.has_seen and 0.5 or 1), message.symbol2[2] * (message.has_seen and 0.5 or 1))
				
				parsed_text, parse_data = parse_colors(text)
				libtcod.console_print_left(0, X + 3, Y + offset, libtcod.BKGND_NONE, parsed_text%parse_data)
				offset += 1
				
				if offset >= H:
					if (not message.has_seen and line + 1 < len(wrapped)) or (m + 1 < len(player.message_log) and not player.message_log[start_pos+m+1].has_seen):
						raise TooManyMessages()
					
					else:
						raise LogIsFull()
				
	except LogIsFull:
		pass
	
	except TooManyMessages:
		draw_messages(player, start_pos + 1)
		return
	
	for message in player.message_log[start_pos:]:
		message.has_seen = True
	
	if start_pos > 0:
		libtcod.console_flush()
		key = libtcod.console_wait_for_keypress(True)
		draw_messages(player)
コード例 #17
0
ファイル: game.py プロジェクト: bricks42/BrutalRL
def start_menu():
    title.init_blood()
    libtcod.console_credits_reset()

    finished_libtcod_credits = False

    selection = 0
    while True:
        title.update()

        libtcod.console_clear(0)

        title.draw_blood()
        title.draw_title()

        libtcod.console_set_background_color(0, libtcod.dark_grey)
        libtcod.console_rect(0, 24, 14, 32, 7, False, libtcod.BKGND_MULTIPLY)

        libtcod.console_set_foreground_color(0, libtcod.red)
        libtcod.console_print_center(0, 40, 15, libtcod.BKGND_NONE, "Brutal RL: Slaves to Slaughter")

        libtcod.console_set_foreground_color(0, libtcod.white)
        libtcod.console_print_left(0, 35, 17, libtcod.BKGND_NONE, "New Game")
        libtcod.console_print_left(0, 35, 18, libtcod.BKGND_NONE, "Load Game")
        libtcod.console_print_left(0, 35, 19, libtcod.BKGND_NONE, "Quit")

        libtcod.console_print_left(0, 33, 17 + selection, libtcod.BKGND_NONE, ">")
        libtcod.console_print_left(0, 45, 17 + selection, libtcod.BKGND_NONE, "<")

        if not finished_libtcod_credits:
            finished_libtcod_credits = libtcod.console_credits_render(65, 43, True)

        libtcod.console_flush()

        key = libtcod.console_check_for_keypress(libtcod.KEY_PRESSED)

        if key.vk == libtcod.KEY_ESCAPE:
            if selection == 2:
                raise SetState("quit")

            else:
                selection = 2

        elif key.vk in DIRECTION_KEYS and DIRECTION_KEYS[key.vk][0] == 0:
            selection += DIRECTION_KEYS[key.vk][1]
            selection %= 3

        elif key.vk in [libtcod.KEY_ENTER, libtcod.KEY_KPENTER]:
            raise SetState([new_game, load_game, "quit"][selection])

        mouse = libtcod.mouse_get_status()
        if mouse.lbutton:
            title.set_full(mouse.cx, mouse.cy)

        elif mouse.rbutton:
            title.set_empty(mouse.cx, mouse.cy)
コード例 #18
0
ファイル: adventure.py プロジェクト: WoodSpencer/adventure
def Game():
	
	while not libtcod.console_is_window_closed():
		libtcod.console_set_foreground_color(0, libtcod.white)
		libtcod.console_print_left(0, Player.location_x, Player.location_y, libtcod.BKGND_NONE, Player.avatar)
		libtcod.console_flush()
	
		libtcod.console_print_left(0, Player.location_x, Player.location_y, libtcod.BKGND_NONE, ' ')
	
		exit = handle_keys()
		if exit:
			break
コード例 #19
0
ファイル: tcod_display.py プロジェクト: nrook/Spirit
def print_char(coords, char, color):
    """
    Print a character to the display.

    coords - an (x, y) tuple of integers representing the char's coordinates.
    char - a 1-character string representing the character printed.
    color - a 3-character (r, g, b) tuple of integers from 0 to 255.
        (0, 0, 0) is black; (255, 255, 255) is white; (255, 0, 0) is red; etc.
    """

    # tcod.console_set_background_color(None, tcod.black)
    tcod.console_set_foreground_color(None, tcod.Color(color[0], color[1], color[2]))
    tcod.console_put_char(None, coords[0], coords[1], ord(char), tcod.BKGND_SET)
コード例 #20
0
def menu(header, options, width):
    if len(options) > MAX_OPTIONS:
        raise ValueError("Cannot have a meny with more than " +
                         str(MAX_OPTIONS) + "options.")

    #calculate the height for the menu, inclues 1 tile per line of header (after wrap)
    #and 1 line per option
    if header == "":
        headerHeight = 0
    else:
        headerHeight = libtcod.console_height_left_rect(
            con, 0, 0, width, SCREEN_HEIGHT, header)
    height = len(options) + headerHeight

    #make an off-screen console that is the menu window
    window = libtcod.console_new(width, height)

    #print header, with word wrap
    libtcod.console_set_foreground_color(window, libtcod.white)
    libtcod.console_print_left_rect(window, 0, 0, width, height,
                                    libtcod.BKGND_NONE, header)

    #prints the options to the menu
    y = headerHeight
    letterIndex = ord("a")
    for optionText in options:
        text = "(" + chr(letterIndex) + ")" + optionText
        libtcod.console_print_left(window, 0, y, libtcod.BKGND_NONE, text)
        y += 1
        letterIndex += 1

    #blit the contents of the 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 player and wait for a keypress
    libtcod.console_flush()
    keyPressed = libtcod.console_wait_for_keypress(True)

    #Allows for full-screening with Alt+Enter in menus
    if keyPressed.vk == libtcod.KEY_ENTER and (keyPressed.lalt
                                               or keyPressed.ralt):
        libtcod.console_set_fullscreen(not libtcod.console_is_fullscreen)

    #after they press a key, see which it was an do the appropriate thing
    index = keyPressed.c - ord("a")
    if index >= 0 and index < len(options):
        return index
    return None
コード例 #21
0
ファイル: hud.py プロジェクト: bricks42/BrutalRL
def draw_hud(player):
	libtcod.console_set_foreground_color(0, libtcod.white)
	
	X, Y, W, H = 0, 40, 30, 10
	
	libtcod.console_set_background_color(0, libtcod.black)
	libtcod.console_rect(0, X, Y, W, H, True, libtcod.BKGND_SET)
	
	libtcod.console_put_char_ex(0, X + 1, Y + 1, player.symbol, player.color, libtcod.black)
	
	libtcod.console_print_left(0, X + 3, Y + 1, libtcod.BKGND_NONE, player.name)
	libtcod.console_print_left(0, X + 1, Y + 8, libtcod.BKGND_NONE, 'In {:s}'.format(player.map.name))
	
	for i in range(10):
		if i * player.max_health > player.health * 10:
			libtcod.console_put_char_ex(0, X + 1 + i, Y + 3, ' ', libtcod.black, libtcod.darker_red)
		
		elif (i+1) * player.max_health > player.health * 10:
			libtcod.console_put_char_ex(0, X + 1 + i, Y + 3, ' ', libtcod.black, libtcod.color_lerp(libtcod.darker_red, libtcod.red, 10.*player.health/player.max_health - i))
		
		else:
			libtcod.console_put_char_ex(0, X + 1 + i, Y + 3, ' ', libtcod.black, libtcod.red)
	
	for i in range(10):
		if player.energy > i:
			libtcod.console_put_char_ex(0, X + 1 + i, Y + 4, 'O', libtcod.blue + libtcod.white * 0.2, libtcod.black)
		
		else:
			libtcod.console_put_char_ex(0, X + 1 + i, Y + 4, 'O', libtcod.desaturated_blue * 0.5, libtcod.black)
	
	libtcod.console_print_left(0, X + 12, Y + 3, libtcod.BKGND_NONE, 'MH: - {}'.format(player.mainhand and player.mainhand.name or '-'))
	
	if player.mainhand:
		libtcod.console_put_char_ex(0, X + 16, Y + 3, player.mainhand.symbol, player.mainhand.color, libtcod.black)
	
	libtcod.console_print_left(0, X + 12, Y + 4, libtcod.BKGND_NONE, 'OH: - {}'.format(player.offhand and player.offhand.name or player.mainhand and player.mainhand.wield_twohands and player.mainhand.name or '-'))
	
	if player.offhand:
		libtcod.console_put_char_ex(0, X + 16, Y + 4, player.offhand.symbol, player.offhand.color, libtcod.black)
	
	elif player.mainhand and player.mainhand.wield_twohands:
		libtcod.console_put_char_ex(0, X + 16, Y + 4, player.mainhand.symbol, player.mainhand.color, libtcod.black)
	
	libtcod.console_print_left(0, X + 12, Y + 5, libtcod.BKGND_NONE, 'AR: - {}'.format(player.wearing  and player.wearing.name or '-'))
	
	if player.wearing:
		libtcod.console_put_char_ex(0, X + 16, Y + 5, player.wearing.symbol, player.wearing.color, libtcod.black)
	
	draw_messages(player)
コード例 #22
0
ファイル: Pythfinder.py プロジェクト: Vbitz/Pythfinder
def render_bar(x, y, total_width, name, value, maximum, bar_color, back_color):  # render a bar (HP, experience, etc).
    # first calculate the width of the bar
    bar_width = int(float(value) / maximum * total_width)
    # render the background first
    libtcod.console_set_background_color(panel, back_color)
    libtcod.console_rect(panel, x, y, total_width, 1, False)
    # now render the bar on top
    libtcod.console_set_background_color(panel, bar_color)
    if bar_width > 0:
        libtcod.console_rect(panel, x, y, bar_width, 1, False)
     # finally, some centered text with the values
    libtcod.console_set_foreground_color(panel, libtcod.white)
    libtcod.console_print_center(panel, x + total_width / 2, y, libtcod.BKGND_NONE, name + ': ' + str(value) + '/' + str(maximum))
    # show the player's stats
    libtcod.console_set_foreground_color(con, libtcod.white)
    libtcod.console_print_left(con, 1, SCREEN_HEIGHT - 2, libtcod.BKGND_NONE, 'HP: ' + str(player.fighter.hp) + '/' + str(player.fighter.max_hp) +'   ')
コード例 #23
0
ファイル: main.py プロジェクト: dizzylee/MoonGame
def render_bar(x, y, total_width, name, value, maximum, bar_color, back_color):
	float_value = float(value)
	float_max = float(maximum)
	bar_width = int((float_value/float_max)*total_width)

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

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

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

	libtcod.console_set_foreground_color(panel, libtcod.white)
	libtcod.console_print_center(panel, x + total_width/2, y, libtcod.BKGND_NONE, name + ': ' + str(value) + '/' + str(maximum))
コード例 #24
0
ファイル: testrl_0.py プロジェクト: meatloaf231/Frontier
def menu(header, options, width):

    if len(options) > 26:
        raise ValueError('Cannot have a menu with more than 26 options')
    #calculate height for the header after auto-wrap and one line per option
    header_height = libtcod.console_height_left_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 window
    window = libtcod.console_new(width, height)

    #Print the header with auto-wrap
    libtcod.console_set_foreground_color(window, libtcod.white)
    libtcod.console_print_left_rect(window, 0, 0, width, height,
                                    libtcod.BKGND_NONE, header)

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

    #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 player with the root console and wait for a key-press
    libtcod.console_flush()
    key = libtcod.console_wait_for_keypress(True)

    #Convert the ASCII code to an index, and if it corresponds an option, return it
    index = key.c - ord('a')
    if index >= 0 and index < len(options):
        return index

    #alt-enter fullscreens
    if key.vk == libtcod.KEY_ENTER and key.lalt:
        libtcod.console_set_fullscreen(not libtcod.console_is_fullscreen())

    return None
コード例 #25
0
ファイル: examplerl2.py プロジェクト: nrberens/Purge
def render_bar(x, y, total_width, name, value, maximum, bar_color, back_color):
    #render a bar (HP, experience, etc). first calculate the width of the bar
    bar_width = int(float(value) / maximum * total_width)
 
    #render the background first
    libtcod.console_set_background_color(panel, back_color)
    libtcod.console_rect(panel, x, y, total_width, 1, False)
 
    #now render the bar on top
    libtcod.console_set_background_color(panel, bar_color)
    if bar_width > 0:
        libtcod.console_rect(panel, x, y, bar_width, 1, False)
 
    #finally, some centered text with the values
    libtcod.console_set_foreground_color(panel, libtcod.black)
    libtcod.console_print_center(panel, x + total_width / 2, y, libtcod.BKGND_NONE,
        name + ': ' + str(value) + '/' + str(maximum))
コード例 #26
0
def render():
    for player in players:
        if not player.dead:
            tcod.console_put_char_ex(0, player.x, player.y,
                                     player_chars[(player.dx, player.dy)],
                                     tcod.black, player.color)
    if winner:
        tcod.console_set_foreground_color(0, winner.color)
        tcod.console_print_left(0, 0, map_size[1] - 1, tcod.BKGND_NONE,
                                'Player ' + str(players.index(winner) + 1) +
                                ' is the winner!')
    tcod.console_flush()

    # erase player arrows from their old positions
    for player in players:
        if not player.dead:
            tcod.console_put_char(0, player.x, player.y, ' ', tcod.BKGND_NONE)
コード例 #27
0
ファイル: Jules-Quest.py プロジェクト: okiyama/Jules-Quest
def menu(header, options, width):
    if len(options) > MAX_OPTIONS:
        raise ValueError("Cannot have a meny with more than " + str(MAX_OPTIONS) + "options.")

    #calculate the height for the menu, inclues 1 tile per line of header (after wrap)
    #and 1 line per option
    if header == "":
        headerHeight = 0
    else:
        headerHeight = libtcod.console_height_left_rect(con, 0, 0, width, SCREEN_HEIGHT, header)
    height = len(options) + headerHeight

    #make an off-screen console that is the menu window
    window = libtcod.console_new(width, height)

    #print header, with word wrap
    libtcod.console_set_foreground_color(window, libtcod.white)
    libtcod.console_print_left_rect(window, 0, 0, width, height, libtcod.BKGND_NONE, header)

    #prints the options to the menu
    y = headerHeight
    letterIndex = ord("a")
    for optionText in options:
        text = "(" + chr(letterIndex) + ")" + optionText
        libtcod.console_print_left(window, 0, y, libtcod.BKGND_NONE, text)
        y += 1
        letterIndex += 1

    #blit the contents of the 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 player and wait for a keypress
    libtcod.console_flush()
    keyPressed = libtcod.console_wait_for_keypress(True)

    #Allows for full-screening with Alt+Enter in menus
    if keyPressed.vk == libtcod.KEY_ENTER and (keyPressed.lalt or keyPressed.ralt):
        libtcod.console_set_fullscreen(not libtcod.console_is_fullscreen)

    #after they press a key, see which it was an do the appropriate thing
    index = keyPressed.c - ord("a")
    if index >= 0 and index < len(options):
        return index
    return None
コード例 #28
0
ファイル: Jules-Quest.py プロジェクト: okiyama/Jules-Quest
def renderBar(x, y, total_width, name, value, maximum, barColor, backColor):
    #Renders a status bar, first we calculate the width of it
    bar_width = int(float(value) / maximum * total_width)

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

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

    #text to denote what the bar is of
    libtcod.console_set_foreground_color(panel, libtcod.white)
    libtcod.console_print_center(panel, x + total_width/2, y, libtcod.BKGND_NONE,
        name + ": " + str(value) + "/" + str(maximum))
コード例 #29
0
ファイル: Pythfinder.py プロジェクト: Vbitz/Pythfinder
def render_all():
    global fov_recompute
    fov_recompute = True
    # go through all tiles, and set their background color according to the FOV
    if fov_recompute: # recompute FOV if needed (the player moved or something)
        fov_recompute = False
        libtcod.map_compute_fov(fov_map, player.x, player.y, TORCH_RADIUS, FOV_LIGHT_WALLS, FOV_ALGO)
    for y in range(MAP_HEIGHT):
        for x in range(MAP_WIDTH):
            visible = libtcod.map_is_in_fov(fov_map, x, y)
            wall = map[x][y].block_sight
            if not visible: # it's out of the player's FOV
                if map[x][y].explored:
                    libtcod.console_put_char_ex(con, x, y, *map[x][y].render_data(False))
            else: # it's visible
                libtcod.console_put_char_ex(con, x, y, *map[x][y].render_data(True))
                mouse = libtcod.mouse_get_status()
                if x == mouse.cx and y == mouse.cy:
                    libtcod.console_set_back(con, x, y, libtcod.yellow, libtcod.BKGND_SET)
                map[x][y].explored = True    
    for object in objects:
        if libtcod.map_is_in_fov(fov_map, object.x, object.y):
            object.draw()
    player.draw()
    # prepare to render the GUI panel
    libtcod.console_set_background_color(panel, libtcod.black)
    libtcod.console_clear(panel)
    # print the game messages, one line at a time
    y = 1
    for (line, color) in game_msgs:
        libtcod.console_set_foreground_color(panel, color)
        libtcod.console_print_left(panel, MSG_X, y, libtcod.BKGND_NONE, line)
        y += 1
    # show the player's stats
    render_bar(1, 1, BAR_WIDTH, 'HP', player.fighter.hp, player.fighter.max_hp,
        libtcod.dark_green, libtcod.red)

    # display names of objects under the mouse
    libtcod.console_set_foreground_color(panel, libtcod.light_gray)
    libtcod.console_print_left(panel, 1, 0, libtcod.BKGND_NONE, get_names_under_mouse())
    
    # Display on main console
    libtcod.console_blit(con, 0, 0, SCREEN_WIDTH, SCREEN_HEIGHT, 0, 0, 0)
    # blit the contents of "panel" to the root console
    libtcod.console_blit(panel, 0, 0, SCREEN_WIDTH, PANEL_HEIGHT, 0, 0, PANEL_Y)
コード例 #30
0
ファイル: testrl_0.py プロジェクト: meatloaf231/Frontier
def render_bar(x, y, total_width, name, value, maximum, bar_color, back_color):
    #render a bar for tracking something. First comes width.
    bar_width = int(float(value) / maximum * total_width)

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

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

    #And some centered text with values for clarity
    libtcod.console_set_foreground_color(panel, libtcod.white)
    libtcod.console_print_center(panel, x + total_width / 2, y,
                                 libtcod.BKGND_NONE,
                                 name + ': ' + str(value) + '/' + str(maximum))
コード例 #31
0
def renderBar(x, y, total_width, name, value, maximum, barColor, backColor):
    #Renders a status bar, first we calculate the width of it
    bar_width = int(float(value) / maximum * total_width)

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

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

    #text to denote what the bar is of
    libtcod.console_set_foreground_color(panel, libtcod.white)
    libtcod.console_print_center(panel, x + total_width / 2, y,
                                 libtcod.BKGND_NONE,
                                 name + ": " + str(value) + "/" + str(maximum))
コード例 #32
0
ファイル: main.py プロジェクト: dizzylee/MoonGame
def render_bar(x, y, total_width, name, value, maximum, bar_color, back_color):
    float_value = float(value)
    float_max = float(maximum)
    bar_width = int((float_value / float_max) * total_width)

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

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

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

    libtcod.console_set_foreground_color(panel, libtcod.white)
    libtcod.console_print_center(panel, x + total_width / 2, y,
                                 libtcod.BKGND_NONE,
                                 name + ': ' + str(value) + '/' + str(maximum))
コード例 #33
0
ファイル: main.py プロジェクト: dizzylee/MoonGame
def pop_up(text):
	width = INVENTORY_WIDTH

	header_height = libtcod.console_height_left_rect(con, 0, 0, width, SCREEN_HEIGHT, text)

	height = header_height

	window = libtcod.console_new(width, height)

	libtcod.console_set_foreground_color(window, libtcod.white)
	libtcod.console_print_left_rect(window, 0, 0, width, height, libtcod.BKGND_NONE, text)

	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)

	libtcod.console_flush()
	key = libtcod.console_wait_for_keypress(True)
コード例 #34
0
def render_bar(x, y, total_width, name, value, maximum, bar_color, back_color):
    global panel

    # render a bar (HP, experience, etc). First calculate the width of the bar
    bar_width = int(float(value) / maximum * total_width)

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

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

    # finally, some centered text with the values
    libtcod.console_set_foreground_color(panel, libtcod.white)
    libtcod.console_print_center(panel, x + total_width / 2, y,
                                 libtcod.BKGND_NONE,
                                 name + ': ' + str(value) + '/' + str(maximum))
コード例 #35
0
ファイル: RQA.py プロジェクト: alephic/RogueQuestAdventure
def render_panel():
    libtcod.console_set_background_color(panel, libtcod.black)
    libtcod.console_clear(panel)
    #bar
    libtcod.console_set_foreground_color(panel, libtcod.white)
    for x in range(SCREEN_WIDTH):
        libtcod.console_put_char(panel, x, 0, '_', libtcod.BKGND_NONE)
    for y in range(PANEL_HEIGHT - 1):
        libtcod.console_put_char(panel, STATS_WIDTH, y+1, '|', libtcod.BKGND_NONE)

    #stats
    libtcod.console_print_left(panel, 1, 2, libtcod.BKGND_NONE, 'Level '+str(player.level))
    libtcod.console_print_left(panel, 1, 3, libtcod.BKGND_NONE, 'Health: '+str(player.health)+'/'+str(player.max_health))
    draw_bar(1, 4, STATS_WIDTH-2, player.health, player.max_health, libtcod.Color(255,0,0), libtcod.Color(128,0,0))
    libtcod.console_print_left(panel, 1, 6, libtcod.BKGND_NONE, 'Exp: '+str(experience)+'/'+str(player.level*10))
    draw_bar(1, 7, STATS_WIDTH-2, experience, player.level*10, libtcod.Color(0,255,255),libtcod.Color(0,64,64))
    libtcod.console_print_left(panel, 1, 9, libtcod.BKGND_NONE, 'Strength: '+str(player.strength)+' (x'+str(player.weapon.power)+')')
    libtcod.console_print_left(panel, 1, 10, libtcod.BKGND_NONE, 'Agility: '+str(player.agility))

    render_blotter()
コード例 #36
0
ファイル: main.py プロジェクト: dizzylee/MoonGame
def pop_up(text):
    width = INVENTORY_WIDTH

    header_height = libtcod.console_height_left_rect(con, 0, 0, width,
                                                     SCREEN_HEIGHT, text)

    height = header_height

    window = libtcod.console_new(width, height)

    libtcod.console_set_foreground_color(window, libtcod.white)
    libtcod.console_print_left_rect(window, 0, 0, width, height,
                                    libtcod.BKGND_NONE, text)

    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)

    libtcod.console_flush()
    key = libtcod.console_wait_for_keypress(True)
コード例 #37
0
ファイル: main.py プロジェクト: dizzylee/MoonGame
def menu(header, options, width):
    if len(options) > 16:
        raise ValueError('Cannot have a menu with more than 26 options.')

    header_height = libtcod.console_height_left_rect(con, 0, 0, width,
                                                     SCREEN_HEIGHT, header)
    if header == '':
        header_height = 0

    height = len(options) + header_height

    window = libtcod.console_new(width, height)

    libtcod.console_set_foreground_color(window, libtcod.white)
    libtcod.console_print_left_rect(window, 0, 0, width, height,
                                    libtcod.BKGND_NONE, header)

    y = header_height
    letter_index = ord('a')
    for option_text in options:
        text = '(' + chr(letter_index) + ') ' + option_text
        libtcod.console_print_left(window, 0, y, libtcod.BKGND_NONE, text)
        y += 1
        letter_index += 1

    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)

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

    if key.vk == libtcod.KEY_ENTER and key.lalt:
        libtcod.console_set_fullscreen(not libtcod.console_is_fullscreen())

    index = key.c - ord('a')
    if index >= 0 and index < len(options): return index
    return None
コード例 #38
0
ファイル: Pythfinder.py プロジェクト: Vbitz/Pythfinder
def menu(header, options, width):
    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_height_left_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_foreground_color(window, libtcod.white)
    libtcod.console_print_left_rect(window, 0, 0, width, height, libtcod.BKGND_NONE, header)

    # print all the options
    y = header_height
    letter_index = ord('a')
    for option_text in options:
        text = '(' + chr(letter_index) + ') ' + option_text
        libtcod.console_print_left(window, 0, y, libtcod.BKGND_NONE, text)
        y += 1
        letter_index += 1

     # blit the contents of "window" to the root console
    x, y = SCREEN_WIDTH / 2 - width / 2, 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()
    key = libtcod.console_wait_for_keypress(True)

    # 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

    if key.vk == libtcod.KEY_ENTER and key.lalt:  # (special case) Alt+Enter: toggle fullscreen
        libtcod.console_set_fullscreen(not libtcod.console_is_fullscreen())
    return None
コード例 #39
0
    def doMenu(self):

        tcod.console_set_foreground_color(0, tcod.white)

        selectedLine = 1

        while True:

            tcod.console_clear(0)

            index = 1

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

            tcod.console_flush()

            # Get Input
            key = tcod.console_wait_for_keypress(True)

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

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

            if (key.vk == tcod.KEY_ENTER):
                return self._selection
コード例 #40
0
 def doMenu(self):
     
     tcod.console_set_foreground_color(0, tcod.white);
     
     selectedLine = 1
     
     while True:
         
         tcod.console_clear(0)
         
         index = 1
         
         for mode, name in self.options:
             tcod.console_print_left(
                     0, self.MENU_LEFT+2, self.MENU_TOP+index, 
                     tcod.BKGND_NONE, name)
             if (selectedLine == index):
                 self._selection = mode
                 tcod.console_put_char(0, self.MENU_LEFT+1, 
                                       self.MENU_TOP+index, '>')
             index += 1
         
         tcod.console_flush();
         
         # Get Input
         key = tcod.console_wait_for_keypress(True);
         
         if (key.vk == tcod.KEY_DOWN):
             selectedLine += 1
             if (selectedLine > len(self.options)):
                 selectedLine = 1
             
         elif (key.vk == tcod.KEY_UP):
             selectedLine -= 1
             if (selectedLine <= 0):
                 selectedLine = len(self.options)
         
         if (key.vk == tcod.KEY_ENTER):
             return self._selection
コード例 #41
0
ファイル: RQA.py プロジェクト: alephic/RogueQuestAdventure
def render_blotter():
    global blotter
    global took_turn
    
    reached_top = False
    y = PANEL_HEIGHT - 2
    for turn in range(len(blotter)):
        messages = blotter[turn]
        for message in range(len(messages)):
            (text, color) = messages[message]
            color = libtcod.color_lerp(color, libtcod.black, min(turn * 0.2, 1))
            libtcod.console_set_foreground_color(panel, color)
            y -= libtcod.console_height_left_rect(panel, STATS_WIDTH + 2, y, SCREEN_WIDTH - STATS_WIDTH - 3, 0, text)
            libtcod.console_print_left_rect(panel, STATS_WIDTH + 2, y+1, SCREEN_WIDTH - STATS_WIDTH - 3, 0, libtcod.BKGND_NONE, text)
            if y <= 1:
                reached_top = True
                break
        if reached_top:
            break

    if took_turn:
        blotter.insert(0,[])
    blotter = blotter[0:5]
コード例 #42
0
ファイル: Main.py プロジェクト: g-jackson/RogueLike
def main_menu():
    # img = libtcod.image_load('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, and some credits!
        libtcod.console_set_foreground_color(0, libtcod.light_yellow)
        libtcod.console_print_center(0, SCREEN_WIDTH/2, SCREEN_HEIGHT/2-4, libtcod.BKGND_NONE, 'Zombies!')
        libtcod.console_print_center(0, SCREEN_WIDTH/2, SCREEN_HEIGHT-2, libtcod.BKGND_NONE, 'By Glenn Jackson')
 
        #show options and wait for the player's choice
        choice = menu('', ['Play a new game'], 24)

	
        if choice == 0:  #new game
            new_game()
            play_game()
		
        else:
            new_game()
            play_game()
コード例 #43
0
def mainMenu():
    image = libtcod.image_load("menu_background1.png")

    while not libtcod.console_is_window_closed():
        #Shows the background image
        libtcod.image_blit_2x(image, 0, 0, 0)

        #shows the game title and author
        libtcod.console_set_foreground_color(0, libtcod.light_orange)
        libtcod.console_print_center(0, SCREEN_WIDTH / 2,
                                     SCREEN_HEIGHT / 2 - 5, libtcod.BKGND_NONE,
                                     "Jules Quest")
        libtcod.console_print_center(0, SCREEN_WIDTH / 2,
                                     SCREEN_HEIGHT / 2 - 3, libtcod.BKGND_NONE,
                                     "By Julian Jocque")

        menuOptions = ["New Game", "Continue", "Quit"]
        #shows options and waits for a choice

        choice = menu("", menuOptions, MAIN_MENU_WIDTH)

        if choice == 0:  #new game
            newGame()
            playGame()
        elif choice == 1:  #continue
            try:
                loadGame()
                playGame()
            except:
                msgBox("\n No save file found.\n", MAIN_MENU_WIDTH)
                continue
        #elif choice == 2: #show instructions
        #    menu("\nArrow Keys to move and attack monsters.\nG to pickup an item you are standing on.\nI to open Inventory.\n" +\
        #        "D to open Drop menu.\nP to pause and unpause.\nC to open Character information screen.\n> to go down stairs.\n" +\
        #        "Mouse over a tile to see what is on it, either monsters or items.\n", [], SCREEN_WIDTH/2)
        elif choice == 2:  #quit
            break
コード例 #44
0
ファイル: main.py プロジェクト: dizzylee/MoonGame
def menu(header, options, width):
	if len(options) > 16: raise ValueError('Cannot have a menu with more than 26 options.')

	header_height = libtcod.console_height_left_rect(con, 0, 0, width, SCREEN_HEIGHT, header)
	if header == '':
		header_height = 0

	height = len(options) + header_height

	window = libtcod.console_new(width, height)

	libtcod.console_set_foreground_color(window, libtcod.white)
	libtcod.console_print_left_rect(window, 0, 0, width, height, libtcod.BKGND_NONE, header)

	y = header_height
	letter_index = ord('a')
	for option_text in options:
		text = '(' + chr(letter_index) + ') ' + option_text
		libtcod.console_print_left(window, 0, y, libtcod.BKGND_NONE, text)
		y += 1
		letter_index += 1

	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)

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

	if key.vk == libtcod.KEY_ENTER and key.lalt:
		libtcod.console_set_fullscreen(not libtcod.console_is_fullscreen())

	index = key.c - ord('a')
	if index >= 0 and index < len(options): return index
	return None
コード例 #45
0
ファイル: main.py プロジェクト: dizzylee/MoonGame
def main_menu():
	img = libtcod.image_load('moon.png')

	while not libtcod.console_is_window_closed():
		libtcod.image_blit_2x(img, 0, 0, 0)

		libtcod.console_set_foreground_color(0, libtcod.light_yellow)
		libtcod.console_print_center(0, SCREEN_WIDTH/2, (SCREEN_WIDTH/2)-4, libtcod.BKGND_NONE, 'Moon Game')
		libtcod.console_print_center(0, SCREEN_WIDTH/2, SCREEN_HEIGHT-2, libtcod.BKGND_NONE, 'James Disley')

		choice = menu('', ['Play a new game', 'Continue last game', 'Quit'], 24)

		if choice == 0:
			new_game()
			play_game()
		if choice == 1:
			try:
				load_game()
			except:
				msgbox('\n No saved game to load.\n', 24)
				continue
			play_game()
		elif choice == 2:
			break
コード例 #46
0
ファイル: game.py プロジェクト: scgs/tbfch
def main_menu():
    while not libtcod.console_is_window_closed():
        # show the game's title, and some credits!
        libtcod.console_set_foreground_color(0, libtcod.light_yellow)
        libtcod.console_print_center(
            0, SCREEN_WIDTH / 2, SCREEN_HEIGHT / 2 - 4, libtcod.BKGND_NONE, "The Battle For Cuyler Hall"
        )
        libtcod.console_print_center(0, SCREEN_WIDTH / 2, SCREEN_HEIGHT - 2, libtcod.BKGND_NONE, "By Gilgi")

        # 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
コード例 #47
0
ファイル: main.py プロジェクト: dizzylee/MoonGame
def render_all():
    global fov_map, color_dark_wall, color_light_wall
    global color_dark_ground, color_light_ground
    global fov_recompute

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

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

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

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

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

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

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

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

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

    for object in objects:
        object.clear()
コード例 #48
0
def renderAll():
    global fovMap, color_dark_wall, color_light_wall
    global color_dark_ground, color_light_ground
    global fovRecompute

    if fovRecompute:
        #message("Recomputing the FOV", libtcod.orange)
        fovRecompute = False
        libtcod.map_compute_fov(fovMap, player.x, player.y, TORCH_RADIUS,
                                FOV_LIGHT_WALLS, FOV_ALGO)

        for y in range(MAP_HEIGHT):
            for x in range(MAP_WIDTH):
                visible = libtcod.map_is_in_fov(fovMap, x, y)
                wall = map[x][y].block_sight
                visited = map[x][y].explored
                if not visible:
                    if visited:
                        #if a tile is not visible but it was visited, we still display it
                        if wall:
                            #message("Not visible and a wall", libtcod.orange)
                            libtcod.console_set_back(con, x, y,
                                                     color_dark_wall,
                                                     libtcod.BKGND_SET)
                        else:
                            libtcod.console_set_back(con, x, y,
                                                     color_dark_ground,
                                                     libtcod.BKGND_SET)
                else:
                    #Once we see a tile it is considered explored
                    map[x][y].explored = True

                    #currently visible to the player
                    if wall:
                        #message("Visible and a wall", libtcod.orange)
                        libtcod.console_set_back(con, x, y, color_light_wall,
                                                 libtcod.BKGND_SET)
                    else:
                        #message("Visible and ground", libtcod.orange)
                        libtcod.console_set_back(con, x, y, color_light_ground,
                                                 libtcod.BKGND_SET)

    #draw all objects in the list
    for object in objects:
        if object != player:
            object.draw()
    #draw player last so it is always on top
    player.draw()

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

    #prepares the GUI panel
    libtcod.console_set_background_color(panel, libtcod.black)
    libtcod.console_clear(panel)

    #shows the players stats
    renderBar(1, 1, BAR_WIDTH, "HP", player.fighter.hp, player.fighter.max_hp,
              libtcod.light_red, libtcod.darker_red)

    #message(the game messages, one line at a time, libtcod.orange)
    y = 1
    for (line, color) in gameMessages:
        libtcod.console_set_foreground_color(panel, color)
        libtcod.console_print_left(panel, MSG_X, y, libtcod.BKGND_NONE, line)
        y += 1

    #display names under the mouse
    libtcod.console_set_foreground_color(panel, libtcod.light_gray)
    libtcod.console_print_left(panel, 1, 0, libtcod.BKGND_NONE,
                               getNamesUnderMouse())

    #blit the panel to the root console
    libtcod.console_blit(panel, 0, 0, SCREEN_WIDTH, PANEL_HEIGHT, 0, 0,
                         PANEL_Y)
コード例 #49
0
def render_all():
    global color_light_wall, color_light_ground
    global color_dark_wall, color_dark_ground
    global fov_map, fov_recompute
    global player, map

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

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

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

    # blit off-screen console to root one
    libtcod.console_blit(con, 0, 0, MAP_WIDTH, MAP_HEIGHT, 0, 0, 0)

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

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

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

    # mouse look command
    libtcod.console_set_foreground_color(panel, libtcod.light_gray)
    libtcod.console_print_left(panel, 1, 0, libtcod.BKGND_NONE,
                               get_names_under_mouse())

    # blit the contents of "panel" to the root console
    libtcod.console_blit(panel, 0, 0, SCREEN_WIDTH, PANEL_HEIGHT, 0, 0,
                         PANEL_Y)
コード例 #50
0
ファイル: main.py プロジェクト: dizzylee/MoonGame
 def draw(self):
     if libtcod.map_is_in_fov(fov_map, self.x, self.y):
         libtcod.console_set_foreground_color(con, self.color)
         libtcod.console_put_char(con, self.x, self.y, self.char,
                                  libtcod.BKGND_NONE)
コード例 #51
0
 def draw(self):
     if libtcod.map_is_in_fov(fov_map, self.x, self.y):
         # set the color and then draw the character that represents this object at its position
         libtcod.console_set_foreground_color(con, self.color)
         libtcod.console_put_char(con, self.x, self.y, self.char,
                                  libtcod.BKGND_NONE)
コード例 #52
0
libtcod.console_set_custom_font(
    'arial10x10.png', libtcod.FONT_TYPE_GREYSCALE | libtcod.FONT_LAYOUT_TCOD)
libtcod.console_init_root(SCREEN_WIDTH, SCREEN_HEIGHT, 'wait a tic')
con = libtcod.console_new(SCREEN_WIDTH, SCREEN_HEIGHT)

#Creating the player
player = Object(SCREEN_WIDTH / 2, SCREEN_HEIGHT / 2, '@', libtcod.white)

#Creating an NPC
npc_0 = Object(SCREEN_WIDTH / 2 - 5, SCREEN_HEIGHT / 2 + 2, '@',
               libtcod.yellow)

#Adding both to the list
objects = [npc_0, player]

#Generate the map
make_map()

while not libtcod.console_is_window_closed():
    libtcod.console_set_foreground_color(con, libtcod.white)

    render_all()

    libtcod.console_flush()

    clear_all()

    exit = handle_keys()
    if exit:
        break
コード例 #53
0
ファイル: testrl_0.py プロジェクト: meatloaf231/Frontier
def render_all():
    global color_dark_wall, color_light_wall
    global color_dark_ground, color_light_ground
    global fov_recompute

    if fov_recompute:
        #recompute FOV if needed (such as player movement or spellcasting or light or something)
        fov_recompute = True
        libtcod.map_compute_fov(fov_map, player.x, player.y, TORCH_RADIUS,
                                FOV_LIGHT_WALLS, FOV_ALGO)

        #Go through tiles, set BG color
        for y in range(MAP_HEIGHT):
            for x in range(MAP_WIDTH):
                visible = libtcod.map_is_in_fov(fov_map, x, y)
                wall = map[x][y].block_sight
                if not visible:
                    #Even if it isn't visible it should be "remembered"
                    if map[x][y].explored:
                        #out of player FOV
                        if wall:
                            libtcod.console_set_back(con, x, y,
                                                     color_dark_wall,
                                                     libtcod.BKGND_SET)
                        else:
                            libtcod.console_set_back(con, x, y,
                                                     color_dark_ground,
                                                     libtcod.BKGND_SET)
                else:
                    #it is visible
                    if wall:
                        libtcod.console_set_back(con, x, y, color_light_wall,
                                                 libtcod.BKGND_SET)
                    else:
                        libtcod.console_set_back(con, x, y, color_light_ground,
                                                 libtcod.BKGND_SET)
                    map[x][y].explored = True

        #Draw all objects in the object list
        for object in objects:
            if object != player:
                object.draw()
        player.draw()

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

        #prepare to render GUI panels
        libtcod.console_set_background_color(panel, libtcod.black)
        libtcod.console_clear(panel)

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

        #show player's stats
        render_bar(1, 1, BAR_WIDTH, 'HP', player.combat.hp,
                   player.combat.max_hp, libtcod.light_red, libtcod.darker_red)
        libtcod.console_print_left(panel, 1, 3, libtcod.BKGND_NONE,
                                   'Dungeon level ' + str(dungeon_level))

        #Display names of things under mouse
        libtcod.console_set_foreground_color(panel, libtcod.light_gray)
        libtcod.console_print_left(panel, 1, 0, libtcod.BKGND_NONE,
                                   get_names_under_mouse())

        #blit the contents of the 'panel' to the root console
        libtcod.console_blit(panel, 0, 0, SCREEN_WIDTH, PANEL_HEIGHT, 0, 0,
                             PANEL_Y)
コード例 #54
0
 def draw(self):
     #set the color and then draw the object
     libtcod.console_set_foreground_color(con, self.color)
     libtcod.console_put_char(con, self.x, self.y, self.char,
                              libtcod.BKGND_NONE)