Example #1
0
	def __init__(self):
		global debug, font_width, font_height, con, panel, ps, fov_noise, savefiles, baseitems, prefix, suffix, tiles, monsters
		IO.load_settings()
		debug = dbg.Debug()
		debug.enable = True
		for key, value in fonts.items():
			if setting_font == key:
				libtcod.console_set_custom_font(value['file'], libtcod.FONT_TYPE_GREYSCALE | libtcod.FONT_LAYOUT_ASCII_INROW)
				font_width = value['width']
				font_height = value['height']
		self.init_root_console()
		#libtcod.console_init_root(SCREEN_WIDTH, SCREEN_HEIGHT, 'Immortal ' + VERSION, False)

		con = libtcod.console_new(MAP_WIDTH, MAP_HEIGHT)
		panel = libtcod.console_new(MESSAGE_WIDTH, MESSAGE_HEIGHT)
		ps = libtcod.console_new(PLAYER_STATS_WIDTH, PLAYER_STATS_HEIGHT)
		fov_noise = libtcod.noise_new(1, 1.0, 1.0)
		savefiles = [f for f in os.listdir('saves') if os.path.isfile(os.path.join('saves', f))]
		IO.load_high_scores()
		baseitems = BaseItemList()
		baseitems.init_parser()
		prefix = PrefixList()
		prefix.init_parser()
		suffix = SuffixList()
		suffix.init_parser()
		tiles = mapgen.TileList()
		tiles.init_parser()
		monsters = MonsterList()
		monsters.init_parser()
		self.main_menu()
Example #2
0
	def __init__(self, app_name='test app', screen_width=None, screen_height=None):
		print '__init__'
		if screen_width is None:
			screen_width, screen_height = self.SCREEN_WIDTH, self.SCREEN_HEIGHT
		libtcod.console_init_root(
			screen_width, screen_height, app_name, False
		)

		self.game_msgs = []
		global message
		message = self.message

		self.game_state = 'playing'
		self.player_action = 'didnt-take-turn'

		x,y = None,None

		self.con = libtcod.console_new(self.MAP_WIDTH, self.MAP_HEIGHT)
		self.panel = libtcod.console_new(self.SCREEN_WIDTH, self.PANEL_HEIGHT)
		self.cursor = Cursor(self.con, 'X', 0,0)

		self.key = libtcod.Key()
		self.mouse = libtcod.Mouse()

		libtcod.sys_set_fps(self.LIMIT_FPS)
Example #3
0
    def __init__(self):
        
        logg.info('Main loop initialization.')

        logg.debug('Font size set to 8')
        libtcod.console_set_custom_font('main/terminal8x8_gs_ro.png',
            libtcod.FONT_LAYOUT_ASCII_INROW | libtcod.FONT_TYPE_GRAYSCALE)

        logg.debug('Main console initialization.')
        libtcod.console_init_root(SCREEN_WIDTH, SCREEN_HEIGHT,
            WINDOW_TITLE + ' v.' + VERSION, False,
                renderer = libtcod.RENDERER_SDL)
        logg.debug('Setting the FPS limit.')
        libtcod.sys_set_fps(LIMIT_FPS)
        logg.debug('Drawing console initialization.')
        self.con = libtcod.console_new(SCREEN_WIDTH, SCREEN_HEIGHT)
        #bottom panel console
        logg.debug('Panels console initialization.')
        self.top_panel = libtcod.console_new(SCREEN_WIDTH, PANEL_HEIGHT)
        self.bottom_panel = libtcod.console_new(SCREEN_WIDTH, PANEL_HEIGHT)

        logg.debug('Gamestate variables initialization')
        self.entities=[]
        self.player = None
        self.gamestate = ""
        self.player_action = None
        self.map = None
        self.random = libtcod.random_new()
        self.score = 0
        self.gamemode = ''
Example #4
0
    def __init__(self, mouse=None, key=None):
        # initialize the console
        # set the font, and consoles
        libtcod.console_set_custom_font('arial10x10.png', libtcod.FONT_TYPE_GREYSCALE | libtcod.FONT_LAYOUT_TCOD)
        libtcod.console_init_root(self.SCREEN_WIDTH, self.SCREEN_HEIGHT, 'python/libtcod tutorial', False)
        self.con = libtcod.console_new(self.MAP_WIDTH, self.MAP_HEIGHT)
        self.panel = libtcod.console_new(self.SCREEN_WIDTH, self.PANEL_HEIGHT)
        libtcod.sys_set_fps(self.LIMIT_FPS)

        # create the tile colors
        self.color_dark_wall = libtcod.Color(0, 0, 100)
        self.color_dark_ground = libtcod.Color(50, 50, 100)
        self.color_light_wall = libtcod.Color(130, 110, 50)
        self.color_light_ground = libtcod.Color(200, 180, 50)

        # set the fov initially to None.  This will be generated properly when the map is rendered
        self.fov_map = None
        self.fov_recompute = False

        # set the mous and keyboard capture vars
        self.mouse = mouse
        self.key = key

        # set the message console
        self.game_msgs = []
Example #5
0
def init():
    global con, right_panel, bottom_panel, prev_mouse_pos
    con = tcod.console_new(MAP_WIDTH, MAP_HEIGHT)
    right_panel = tcod.console_new(RIGHT_PANEL_WIDTH,
                                   SCREEN_HEIGHT)
    bottom_panel = tcod.console_new(BOTTOM_PANEL_WIDTH,
                                    BOTTOM_PANEL_HEIGHT)
Example #6
0
def menu(header, options, width):
    #First, make sure the menu has 26 or fewer items (This is due to an alphabetical selection limitation)
    if len(options) > 26:
        raise ValueError('Cannot have a menu with more than 26 options!')

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

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

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

    #Print all the options, with a corresponding ASCII character
    y = header_height
    #Get the ASCII value of the letter 'a'
    letter_index = ord('a')
    for option_text in options:
        text = '(' + chr(letter_index) + ') ' + option_text
        libtcod.console_print_ex(window, 0, y, libtcod.BKGND_NONE, libtcod.LEFT, text)
        y += 1
        letter_index += 1

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

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

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

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

    #Convert the ASCII code to an index; if it corresponds to a valid menu item, return it
    index = key.c - ord('a')
    if index >= 0 and index < len(options): return index
    return None
Example #7
0
def new_game():
    # Initialize consoles
    lt.console_clear(0)
    lt.console_print_ex(0, SCREEN_WIDTH/2, SCREEN_HEIGHT/2, lt.BKGND_NONE, lt.CENTER, 'Loading...')
    lt.console_flush()
    global panel, log, frame
    panel = lt.console_new(PANEL_WIDTH, SCREEN_HEIGHT)
    log = lt.console_new(SCREEN_WIDTH - PANEL_WIDTH + 2, LOG_HEIGHT)
    frame = lt.console_new(MAP_WIDTH + 2, MAP_HEIGHT + 2)

    # Starting cave
    global area
    area = world.Area("cave", 50, 100)

    global game_msgs
    game_msgs = []
    message(' ')  # Ensures log is rendered.

    # Create player entity
    global player
    player = ccreate.create_player(area.area)
    player.loc = Mobile(player.loc.col, player.loc.row, player.loc.char, player.loc.f_color)
    player.ai = PlayerControl()
    player.inv = Inventory(player)

    global gamestate
    gamestate = "main"

    return True
Example #8
0
def screen():
    global con, panel
    libtcod.console_set_custom_font('arial10x10.png', libtcod.FONT_TYPE_GREYSCALE | libtcod.FONT_LAYOUT_ASCII_INROW, 16,16)
    libtcod.console_set_custom_font('menu_background1.png', libtcod.FONT_TYPE_GREYSCALE | libtcod.FONT_LAYOUT_ASCII_INROW, 16,16)
    libtcod.console_init_root(SCREEN_WIDTH, SCREEN_HEIGHT, 'Try not to Die!', False)
    libtcod.sys_set_fps(LIMIT_FPS)
    con = libtcod.console_new(MAP_WIDTH, MAP_HEIGHT)
    panel = libtcod.console_new(SCREEN_WIDTH, PANEL_HEIGHT)
    objects = []
Example #9
0
def main_game_loop():
    
    global levelmap
    global levelmapobjs
    global levelmapobjs_coords
    global dungeon
    global con
    global inventory_manager

    con = libtcod.console_new(SCREEN_WIDTH, SCREEN_HEIGHT)
    panel = libtcod.console_new(SCREEN_WIDTH, PANEL_HEIGHT)

    player = character.Character(5, 5, '@', libtcod.white, "player", blocks=True)
    inventory_manager = inventorymanager.InventoryManager(SCREEN_WIDTH, SCREEN_HEIGHT, con)
    #char = character.Character(5, 5, '@', libtcod.white, "player")

    """ Right now, just demoing a dungeon. """
    #levelmap, levelmapobjs = overworldmap.generate_level_map()
    levelmap, levelmapobjs = basemap.generate_level_map(player, current_floor)
    #saveload.save_map(levelmap, levelmapobjs, "testingmapmain")
    #levelmap, levelmapobjs = saveload.load_map("testingmapmain")

    """ Initialize fog of war """
    for y in xrange(basemap.MAP_HEIGHT):
        for x in xrange(basemap.MAP_WIDTH):
            libtcod.map_set_properties(fov_map, x, y, not levelmap[x][y].block_sight, not levelmap[x][y].blocked)

    """ Coordinates for every object on the overworld map """
    for i in levelmapobjs:
        levelmapobjs_coords.append((i.x, i.y))

    dungeon.append((levelmap, levelmapobjs, levelmapobjs_coords))

    levelmapobjs.append(player)

    while not libtcod.console_is_window_closed():

        render_all(con, panel, player)
        libtcod.console_flush()
        libtcod.console_put_char(0, player.x, player.y, ' ', libtcod.BKGND_NONE)

        """ Results of the player's key actions. """        
        key_handler_status = handle_keys(player)

        move_npcs(player)

        check_endgame_conditions(player)

        if key_handler_status == "ok":
            continue

        if key_handler_status == "exit":
            break
        elif key_handler_status == "down_stairs":
            move_down_stairs(player)
Example #10
0
    def __init__(self):
        flags = libtcod.FONT_TYPE_GREYSCALE | libtcod.FONT_LAYOUT_TCOD
        libtcod.console_set_custom_font(self.font, flags)
        libtcod.console_init_root(SCREEN_WIDTH, SCREEN_HEIGHT, 'mprl', False)
        libtcod.sys_set_fps(LIMIT_FPS)

        self.con = libtcod.console_new(MAP_WIDTH, MAP_HEIGHT)
        self.panel = libtcod.console_new(SCREEN_WIDTH, PANEL_HEIGHT)
        self.inv_window = libtcod.console_new(MAP_WIDTH, MAP_HEIGHT)

        self.hp_bar = UIBar('HP', libtcod.darker_red, libtcod.light_red)
def renderer_init():
    """
    Initialize libtcod and set up our basic consoles to draw into.
    """
    global _con, _panel, _overlay, _last_frame_time
    libtcod.console_set_custom_font('arial12x12.png', libtcod.FONT_TYPE_GREYSCALE | libtcod.FONT_LAYOUT_TCOD)
    libtcod.console_init_root(config.SCREEN_WIDTH, config.SCREEN_HEIGHT, 'python/libtcod tutorial', False)
    libtcod.sys_set_fps(LIMIT_FPS)
    _con = libtcod.console_new(config.MAP_PANEL_WIDTH, config.MAP_PANEL_HEIGHT)
    _overlay = libtcod.console_new(config.MAP_PANEL_WIDTH, config.MAP_PANEL_HEIGHT)
    _panel = libtcod.console_new(config.SCREEN_WIDTH, config.PANEL_HEIGHT)
    _last_frame_time = time.time() * 1000
Example #12
0
def text_input(header):
	width = len(header)
	header_height = libtcod.console_get_height_rect(g.con, 0, 0, width, SCREEN_HEIGHT, header)
	if header == '':
		header_height = 0
	height = 1 + 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_ex(window, 0, 0, width, height, libtcod.BKGND_NONE, libtcod.LEFT, header)
 
	#blit the contents of "window" to the root console
	x = SCREEN_WIDTH/2 - width/2
	y = SCREEN_HEIGHT/6 - height/2
	libtcod.console_blit(window, 0, 0, width, height, 0, x, y, 1.0, 0.7)

	#Now, get key input repeatedly
	text = ""

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

	while key.vk != libtcod.KEY_ENTER and key.vk != libtcod.KEY_ESCAPE:
		if key.vk == libtcod.KEY_BACKSPACE:
			if len(text) > 0:
				text = text[:-1] #Cut off the last one
		elif key.c >= 32 and key.c <= 127:
			key_char = chr(key.c)
			text += key_char

		#Redraw
		#render_all()

		window = libtcod.console_new(width, height)

		#print the header, with auto-wrap
		libtcod.console_set_default_foreground(window, libtcod.white)
		libtcod.console_print_rect_ex(window, 0, 0, width, height, libtcod.BKGND_NONE, libtcod.LEFT, header)
		#libtcod.console_print_ex(window, 0, 1, libtcod.BKGND_NONE, libtcod.LEFT, 'Ravi')
		libtcod.console_print_ex(window, 0, 1, libtcod.BKGND_NONE, libtcod.LEFT, text)
		#libtcod.console_print_ex(panel, MSG_X, y, libtcod.BKGND_NONE, libtcod.LEFT,line)
	 
		#blit the contents of "window" to the root console
		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)

	return text
Example #13
0
def game_initialize():
    libtcod.console_set_custom_font('oryx_tiles3.png', libtcod.FONT_TYPE_GREYSCALE | libtcod.FONT_LAYOUT_TCOD, 32, 12)
    libtcod.console_init_root(data.SCREEN_WIDTH, data.SCREEN_HEIGHT, 'MeFightRogues!', False, libtcod.RENDERER_SDL)
    libtcod.sys_set_fps(data.LIMIT_FPS)

    libtcod.console_map_ascii_codes_to_font(256   , 32, 0, 5)  #map all characters in 1st row
    libtcod.console_map_ascii_codes_to_font(256+32, 32, 0, 6)  #map all characters in 2nd row

    Game.con = libtcod.console_new(data.MAP_WIDTH,data.MAP_HEIGHT)
    Game.panel = libtcod.console_new(data.SCREEN_WIDTH, data.PANEL_HEIGHT)

    main_menu()
Example #14
0
    def __init__(self):
        self.screen_width = 80
        self.screen_height = 50
        self.fps = 20

        self.map_width = 80
        self.map_height = 45

        self.panel = libtcod.console_new(self.screen_width, self.screen_height)
        
        self.console = libtcod.console_new(self.map_width, self.map_height)

        self.screens = []
Example #15
0
def run_game():
    """ Starts the game. """

    # Set globals.
    global player, objects, turns, depth, game_messages, fov_map, console_gui, console_message

    # Create player.
    player_alive = Alive(10, 10, 10, 10)
    player = Object(20, 10, "Player", "@", [roguelib.white, roguelib.dark_grey], True, False, alive=player_alive)

    # Create objects list.
    objects = []

    # Set global turns.
    turns = 0
    depth = 1
    game_messages = []
    create_message("Welcome to the Simple Roguelike.", roguelib.red)

    # Generate dungeon.
    make_dungeon()

    # Create FOV.
    compute_fov()

    # Create top and bottom gui consoles.
    console_gui = roguelib.console_new(SCREEN_WIDTH, CONSOLE_GUI_HEIGHT)
    console_message = roguelib.console_new(SCREEN_WIDTH, MESSAGE_CONSOLE_HEIGHT)

    # Create loop for the game to run.
    while not roguelib.console_is_window_closed():

        # Render graphics.
        render_all()

        # If player is on stairs, descend or ascend.
        if player.x == dstairs.x and player.y == dstairs.y:
            descend()

        if depth > 1:

            if player.x == astairs.x and player.y == astairs.y:
                ascend()

        # If leave_game is raised, exit game.
        leave_game = handle_input()
        if leave_game:

            break
Example #16
0
def main_init():
    global con, con_char, inf,minmap, message_bar, date, ui, game_msgs
    #libtcod.console_set_custom_font("dejavu16x16.png", libtcod.FONT_TYPE_GREYSCALE | libtcod.FONT_LAYOUT_TCOD)
    libtcod.console_set_custom_font("data\ont_big.png",libtcod.FONT_LAYOUT_ASCII_INROW)
    libtcod.console_init_root(R.SCREEN_WIDTH, R.SCREEN_HEIGHT, "Trader-RL", False)
    libtcod.sys_set_fps(R.LIMIT_FPS)
    con = R.con = libtcod.console_new(R.MAP_WIDTH, R.MAP_HEIGHT)
    con_char = R.con_char = libtcod.console_new(R.MAP_WIDTH, R.MAP_HEIGHT)
    inf = R.inf = libtcod.console_new(R.INFO_BAR_WIDTH, R.SCREEN_HEIGHT - R.PANEL_HEIGHT)
    minmap = R.minmap = libtcod.console_new(R.INFO_BAR_WIDTH, R.PANEL_HEIGHT)
    message_bar = R.message_bar = libtcod.console_new(R.PANEL_WIDTH, R.PANEL_HEIGHT)
    
    game_msgs = R.game_msgs = []
    ui = R.ui = UI.UI(con,game_msgs)
    date = R.date = [0, [DAYS[0][0], 1, 1], [MONTHS[0][0], 1, 31], 1000];
Example #17
0
def initialize(self):
	self.overview_con = libtcod.console_new(OVERVIEW_SCREEN_WIDTH, OVERVIEW_SCREEN_HEIGHT)
	self.debug_con    = libtcod.console_new(OVERVIEW_SCREEN_WIDTH, 10)
	self.region_con   = libtcod.console_new(REGION_HEIGHT,REGION_WIDTH)
	random.seed()
	height_map_seed = random.randint(-1000000,1000000)
	rain_fall_map_seed = random.randint(-1000000,1000000)
	temperature_map_seed = random.randint(-1000000,1000000)
	self.cameraX    = 0
	self.cameraY    = 0
	self.cursorX    = OVERVIEW_SCREEN_WIDTH  / 2
	self.cursorY    = OVERVIEW_SCREEN_HEIGHT / 2
	self.region_cursorX = 0
	self.region_cursorY = 0
	height_map = gen_height_map(height_map_seed, 0.004,10)
	rain_fall_map = gen_rainfall_map(rain_fall_map_seed,0.09,10)
	temperature_map = gen_temperature_map(temperature_map_seed,0.004,MAP_WIDTH,10)
	self.world = []
	for x in range(0,MAP_WIDTH):
		tilecolumn = []
		for y in range(0,MAP_HEIGHT):
			tilecolumn.append(Region(height_map,rain_fall_map,temperature_map,x,y,REGION_WIDTH,REGION_HEIGHT))
		self.world.append(tilecolumn)
		print str(x) + " of " + str(MAP_WIDTH)
	i = 0
	print "heightmap done"
	while i < RIVERLAKES:
		x = random.randint(20,MAP_WIDTH*REGION_WIDTH - 20)
		y = random.randint(20,MAP_HEIGHT*REGION_HEIGHT - 20)
		def gen_river(mapX,mapY,regX,regY,min_height):
			try:
				height = self.world[mapX][mapY].tiles[regX][regY].height
			except IndexError:
				return False
			self.world[mapX][mapY].tiles[regX][regY].height = RIVERLEVEL
			if height > min_height or height < WATER_THRESHOLD:
				return False
			for x in (-1,1):
				realx = mapX * REGION_WIDTH + regX + x
				gen_river(realx / REGION_WIDTH, mapY,realx % REGION_WIDTH, regY,height+RIVER_EROSION)
			for y in (-1,1):
				realy = mapY * REGION_HEIGHT + regY + y
				gen_river(mapX, realy / REGION_HEIGHT, regX, realy % REGION_HEIGHT, height+RIVER_EROSION)
			return True

		if gen_river(x / REGION_WIDTH, y / REGION_HEIGHT,x % REGION_WIDTH, y % REGION_HEIGHT,1):
			i += 1
			print ("river " + str(i) + " done")
Example #18
0
def equipment_menu(con, header, player, equipment_menu_width, screen_width,
                   screen_height, colors):
    """Show what items the player has equipped on the equipment slots."""
    header_height = libtcod.console_get_height_rect(con, 0, 0,
                                                    equipment_menu_width,
                                                    screen_height, header)
    height = header_height + 10

    window = libtcod.console_new(equipment_menu_width, height)

    libtcod.console_set_default_foreground(window, colors['text_default'])

    libtcod.console_set_color_control(libtcod.COLCTRL_1,
                                      colors['text_emphasize'],
                                      colors['background_default'])
    libtcod.console_set_color_control(libtcod.COLCTRL_2,
                                      colors['text_desaturate'],
                                      colors['background_default'])
    libtcod.console_set_color_control(libtcod.COLCTRL_3, colors['text_info'],
                                      colors['background_default'])
    libtcod.console_set_color_control(libtcod.COLCTRL_4,
                                      colors['text_info_alt'],
                                      colors['background_default'])

    slots = [(player.equipment.main_hand, 'Main hand'),
             (player.equipment.off_hand, 'Off hand'),
             (player.equipment.torso, 'Torso'),
             (player.equipment.head, 'Head'), (player.equipment.coat, 'Coat'),
             (player.equipment.ring_l, 'Ring (left)'),
             (player.equipment.ring_r, 'Ring (right)'),
             (player.equipment.special, 'Special')]

    libtcod.console_print_rect_ex(window, 0, 1, equipment_menu_width, height,
                                  libtcod.BKGND_NONE, libtcod.LEFT, header)

    line = header_height + 1
    letter_index = ord('a')

    for slot, slot_desc in slots:
        equippable_name = '%cEmpty.%c' % (libtcod.COLCTRL_2,
                                          libtcod.COLCTRL_STOP)
        index_prefix = f'%c({chr(letter_index)})%c' % (libtcod.COLCTRL_1,
                                                       libtcod.COLCTRL_STOP)

        if slot is not None:
            equippable_name = f'%c{slot.name} %c{slot.equippable}%c' % (
                libtcod.COLCTRL_3, libtcod.COLCTRL_4, libtcod.COLCTRL_STOP)
            equippable_stats = str(slot.equippable)

        libtcod.console_print_rect_ex(
            window, 0, line, equipment_menu_width, height, libtcod.BKGND_NONE,
            libtcod.LEFT, '{0}{1}: {2}'.format(index_prefix, slot_desc,
                                               equippable_name))
        line += 1
        letter_index += 1

    x = int(screen_width / 2 - equipment_menu_width / 2)
    y = int(screen_height / 2 - height / 2)
    libtcod.console_blit(window, 0, 0, equipment_menu_width, height, 0, x, y,
                         1.0, 0.7)
Example #19
0
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, 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 off-screen console that represeents 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_ex(window, 0, 0, width, height, libtcod.BKGND_NONE, libtcod.LEFT, header)
	#print each option
	y = header_height
	letter_index = ord('a')
	for option_text in options:
		text = '(' + chr(letter_index) + ')' + option_text
		libtcod.console_print_ex(window, 0, y, libtcod.BKGND_NONE, libtcod.LEFT, text)
		y += 1
		letter_index += 1
	#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)
	index = key.c - ord('a')
	if index >= 0 and index < len(options): return index
	return None
Example #20
0
def menu(header, options, width):
    #generic menu function. has automatic height calculation
    if len(options) > CARRY_LIMIT:
        raise ValueError('Cannot have a menu with more than' +
                         str(CARRY_LIMIT) + 'options.')
    #calculates total height, one line per option
    header_height = libtcod.console_get_height_rect(con, 0, 0, width,
                                                    SCREEN_HEIGHT, header)
    height = len(options) + header_height
    #creates an off-screen console, menu window
    window = libtcod.console_new(width, height)
    #prints header, words wrapped
    libtcod.console_set_default_foreground(window, libtcod.white)
    libtcod.console_print_rect_ex(window, 0, 0, width, height,
                                  libtcod.BKGND_NONE, libtcod.LEFT, header)
    #prints options
    y = header_height
    letter_index = ord('a')  #gets ascii code from a character
    for option_text in options:
        text = chr(letter_index) + ') ' + option_text
        libtcod.console_print_ex(window, 0, y, libtcod.BKGND_NONE,
                                 libtcod.LEFT, text)
        y += 1
        letter_index += 1
    #blits content of window console to root console/screen
    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)
    #shows root console
    libtcod.console_flush()
    key = libtcod.console_wait_for_keypress(True)
    index = key.c - ord('a')
    if index >= 0 and index < len(options): return index
    return None
Example #21
0
def job_screen(player, character_screen_width, character_screen_height,
               screen_width, screen_height):
    window = libtcod.console_new(character_screen_width,
                                 character_screen_height)

    libtcod.console_set_default_foreground(window, libtcod.white)

    libtcod.console_print_rect_ex(
        window, 0, 2, character_screen_width, character_screen_height,
        libtcod.BKGND_NONE, libtcod.LEFT,
        'Level in Fighter: {0}'.format(player.fighter.job.fighter_level))
    libtcod.console_print_rect_ex(
        window, 0, 3, character_screen_width, character_screen_height,
        libtcod.BKGND_NONE, libtcod.LEFT,
        'Levels in Magician: {0}'.format(player.fighter.job.magician_level))
    libtcod.console_print_rect_ex(
        window, 0, 4, character_screen_width, character_screen_height,
        libtcod.BKGND_NONE, libtcod.LEFT,
        'Levels in Cleric: {0}'.format(player.fighter.job.cleric_level))
    libtcod.console_print_rect_ex(
        window, 0, 5, character_screen_width, character_screen_height,
        libtcod.BKGND_NONE, libtcod.LEFT,
        'Levels in Thief: {0}'.format(player.fighter.job.thief_level))

    x = screen_width // 2 - character_screen_width // 2
    y = screen_height // 2 - character_screen_height // 2
    libtcod.console_blit(window, 0, 0, character_screen_width,
                         character_screen_height, 0, x, y, 1.0, 0.7)
Example #22
0
def menu(header, options, width):
	if len(options) > 26: raise ValueError('Cannot have a menu with more than 26 options.') #menu cannot have 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
	#creating new window to draw menu
	window = libtcod.console_new(width, height)
	#print header
	libtcod.console_set_default_foreground(window, libtcod.white)
	libtcod.console_print_rect_ex(window, 0, 0, width, height, libtcod.BKGND_NONE, libtcod.LEFT, header)
	#print options
	y = header_height
	letter_index = ord("a")
	for option_text in options:
		text = "(" + chr(letter_index) + ") " + option_text
		libtcod.console_print_ex(window, 0, y, libtcod.BKGND_NONE, libtcod.LEFT, text)
		y += 1
		letter_index += 1
	#blit to main screen
	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) #last two parameters represent foreground and background transparency, respectively
	#flush and wait for keypress
	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())
	#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
Example #23
0
    def build(self):

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

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

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

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

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

            y += height
    def __init__(self, x, y, w, h, default, mode, insert):

        # init
        self.console = libtcod.console_new(w, h)
        self.init_time = time.time()

        self.x = x
        self.w = w
        self.y = y
        self.h = h
        self.mode = mode
        self.text = default
        self.default = default

        self.keyInput = ''

        self.redraw_cursor = True
        self.render_text = True
        self.flush = False

        self.key = key
        self.mouse = mouse

        self.cursor = Cursor()
        self.cursor.set_pos(x, y)
        self.insert_mode = insert  #replace the character under the cursor or shift it aside?

        #ignore buffer
        get_raw_input()
Example #25
0
def menu(con, header, options, width, screen_width, screen_height):
    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_ex(window, 0, 0, width, height,
                                  libtcod.BKGND_NONE, libtcod.LEFT, 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_ex(window, 0, y, libtcod.BKGND_NONE,
                                 libtcod.LEFT, text)
        y += 1
        letter_index += 1

    # blit the contents of "window" to the root console
    x = int(screen_width / 2 - width / 2)
    y = int(screen_height / 2 - height / 2)
    libtcod.console_blit(window, 0, 0, width, height, 0, x, y, 1.0, 0.7)
Example #26
0
def menu(header, options, width):
    if len(options) > 26:
        raise ValueError('More than 26 menu items not currently supported')

    header_height = libtcodpy.console_get_height_rect(_console, 0, 0, width,
                                                      config.SCREEN_HEIGHT,
                                                      header)
    height = len(options) + header_height

    window = libtcodpy.console_new(width, height)
    libtcodpy.console_set_default_foreground(window, libtcodpy.white)
    libtcodpy.console_print_rect_ex(window, 0, 0, window, height,
                                    libtcodpy.BKGND_NONE, libtcodpy.LEFT,
                                    header)

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

    x = config.SCREEN_WIDTH / 2 - width / 2
    y = config.SCREEN_HEIGHT / 2 - height / 2
    libtcodpy.console_blit(window, 0, 0, width, height, 0, x, y, 1.0, 0.7)

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

    index = key.c - ord('a')
    if 0 <= index < len(options):
        return index
    return None
Example #27
0
 def init_specialGrids(self):
     w=self.w
     h=self.h
         # init special grids
     self.grid_things =      [ [ [] for y in range(h)] for x in range(w) ]
     self.grid_lights =      [ [ [] for y in range(h)] for x in range(w) ]
     #self.grid_fluids =      [ [ [] for y in range(h)] for x in range(w) ]
         # Init root FOVmap
     self.fov_map = libtcod.map_new(w,h)
         # init lightmap which stores luminosity values for each tile
     self.lightmap_init()
         # lists of tiles of interest
     self.question_marks = []
         # init consoles for UI 
     self.con_memories = libtcod.console_new(w,h)
     self.con_map_state = libtcod.console_new(w,h)
Example #28
0
def menu(header, options, width):
    #add functionality of pages
    header_height = libtcod.console_get_height_rect(con, 0, 0, width,
                                                    SCREEN_HEIGHT, header)
    height = len(options) + header_height

    window = libtcod.console_new(width, height)

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

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

    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)
    index = key.c - ord('a')
    if index >= 0 and index < len(options): return index
    return None
Example #29
0
def menu(header, options, width):
    if len(options) > 26:
        raise ValueError('Cannot have menu with more than 26 options.')

    header_height = libtcod.console_get_height_rect(con, 0, 0, width,
                                                    SCREEN_HEIGHT, header)
    if header == '':
        header_height = 0
    height = len(options) + header_height

    window = libtcod.console_new(width, height)
    libtcod.console_set_default_foreground(window, libtcod.white)
    libtcod.console_print_rect_ex(window, 0, 0, width, height,
                                  libtcod.BKGND_NONE, libtcod.LEFT, header)
    y = header_height
    letter_index = ord('a')
    for option_text in options:
        text = '(' + chr(letter_index) + ')' + option_text
        libtcod.console_print_ex(window, 0, y, libtcod.BKGND_NONE,
                                 libtcod.LEFT, text)
        y += 1
        letter_index += 1

    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
def character_screen(player, character_screen_width, character_screen_height, screen_width, screen_height):
    window = libtcod.console_new(character_screen_width, character_screen_height)

    libtcod.console_set_default_foreground(window, libtcod.white)

    libtcod.console_print_rect_ex(window, 0, 1, character_screen_width, character_screen_height, libtcod.BKGND_NONE,
                                  libtcod.LEFT, 'Character Information')
    libtcod.console_print_rect_ex(window, 0, 2, character_screen_width, character_screen_height, libtcod.BKGND_NONE,
                                  libtcod.LEFT, 'Level: {0}'.format(player.level.current_level))
    libtcod.console_print_rect_ex(window, 0, 3, character_screen_width, character_screen_height, libtcod.BKGND_NONE,
                                  libtcod.LEFT, 'Experience: {0}'.format(player.level.current_xp))
    libtcod.console_print_rect_ex(window, 0, 4, character_screen_width, character_screen_height, libtcod.BKGND_NONE,
                                  libtcod.LEFT, 'Experience to Level: {0}'.format(player.level.experience_to_next_level))
    libtcod.console_print_rect_ex(window, 0, 6, character_screen_width, character_screen_height, libtcod.BKGND_NONE,
                                  libtcod.LEFT, 'Maximum HP: {0}'.format(player.fighter.max_hp))
    libtcod.console_print_rect_ex(window, 0, 7, character_screen_width, character_screen_height, libtcod.BKGND_NONE,
                                  libtcod.LEFT, 'Attack: {0}'.format(player.fighter.power))
    libtcod.console_print_rect_ex(window, 0, 8, character_screen_width, character_screen_height, libtcod.BKGND_NONE,
                                  libtcod.LEFT, 'Defense: {0}'.format(player.fighter.defense))
    libtcod.console_print_rect_ex(window, 0, 9, character_screen_width, character_screen_height, libtcod.BKGND_NONE,
                                  libtcod.LEFT, 'Race: {0}'.format(player.fighter.race))
    libtcod.console_print_rect_ex(window, 0, 9, character_screen_width, character_screen_height, libtcod.BKGND_NONE,
                                  libtcod.LEFT, 'Gender: {0}'.format(Gender.male))

    x = screen_width // 2 - character_screen_width // 2
    y = screen_height // 2 - character_screen_height // 2
    libtcod.console_blit(window, 0, 0, character_screen_width, character_screen_height, 0, x, y, 1.0, 0.7)
def menu(con, header, options, width, screen_width, screen_height):
    if len(options) > 26:
        raise ValueError('Cannot have a menu with more than 26 options')

    header_height = libtcod.console_get_height_rect(con, 0, 0, width,
                                                    screen_height, header)
    height = len(options) + header_height

    window = libtcod.console_new(width, height)

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

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

    x = int(screen_width / 2 - width / 2)
    y = int(screen_height / 2 - height / 2)
    libtcod.console_blit(window, 0, 0, width, height, 0, x, y, 1.0, 0.7)
Example #32
0
    def target_tile(max_range=None):
        box = libtcod.console_new(1, 1)
        x = Game.player.x
        y = Game.player.y
        libtcod.console_set_default_background(box, libtcod.orange)
        libtcod.console_clear(box)
        key = Game.key

        while (x, y) != (0, 0):
            Game.render_all()

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

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

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

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

            if direction == (0, 0):
                if Game.map.is_tile_in_fov(
                        x, y) and (max_range is None
                                   or Game.player.distance(x, y) <= max_range):
                    return (x, y)
                else:
                    Game.message('That is out of range.', libtcod.red)
Example #33
0
def menu(con, header, options, width, screenWidth, screenHeight):
    if len(options) > 28: raise ValueError('Cannot have a menu with more than 26 options.')

    # calculate height of header (post auto-wrap) and one line per option
    headerHeight = libtcod.console_get_height_rect(con,0,0,width,
        screenHeight, header)
    height = len(options) + headerHeight

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

    # print header w/ auto-wrap
    libtcod.console_set_default_foreground(window, libtcod.white)
    libtcod.console_print_rect_ex(window,0,0,width,height,
        libtcod.BKGND_NONE,libtcod.LEFT,header)

    # print options
    y = headerHeight
    letterIndex = ord('a')

    for optionText in options:
        text = '(' + chr(letterIndex) + ') ' + optionText
        libtcod.console_print_ex(window,0,y,libtcod.BKGND_NONE,
            libtcod.LEFT, text)

        y += 1
        letterIndex += 1

    # blit contents of window to root console
    x = int(screenWidth/2 - width/2)
    y = int(screenHeight/2 - height/2)

    libtcod.console_blit(window,0,0,width,height,0,x,y,1.0,0.7)
Example #34
0
def dbox(x, y, w, h, text, wrap=True, border=0, margin=0, con=0, disp='poly'):
    con_box = libtcod.console_new(w, h)

    pad = 0 if border == None else 1
    offset = margin + pad
    fulltext = textwrap.fill(text, w - 2 * (margin + pad)) if wrap else text
    boxes = word.split_stanza(
        fulltext, h - 2 * (margin + pad)) if disp == 'poly' else [fulltext]
    length = len(boxes)
    i = 0
    for box in boxes:
        i += 1
        libtcod.console_clear(con_box)
        #   print
        if border is not None: rectangle(con_box, 0, 0, w, h, border)
        libtcod.console_print(con_box, offset, offset, box)
        put_text_special_colors(con_box, box, offset)
        libtcod.console_blit(
            con_box,
            0,
            0,
            w,
            h,  # Source
            con,
            x,
            y)  # Destination
        #   wait for user input to continue...
        if i < length:
            rog.blit_to_final(con, 0, 0)
            rog.refresh()
            while True:
                reply = rog.Input(x + w - 1, y + h - 1, mode="wait")
                if (reply == ' ' or reply == ''): break
    libtcod.console_delete(con_box)
Example #35
0
def menu(header, options, width):
    if len(options) > 26: raise ValueError('Cannot have a menu with more than 26 options')
    # get geometry 
    header_height = libtcod.console_get_height_rect(con, 0, 0, width, SCREEN_HEIGHT, header)
    height = len(options) + header_height
    # create an off screen window
    window = libtcod.console_new(width, height)
    libtcod.console_set_default_foreground(window, libtcod.white)
    libtcod.console_print_rect_ex(window, 0, 0, width, height, libtcod.BKGND_NONE, libtcod.LEFT, 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_ex(window, 0, y, libtcod.BKGND_NONE, libtcod.LEFT, 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)
    index = key.c - ord('a')
    if index >= 0 and index < len(options): return index
    return None
Example #36
0
	def create_map_images(self, mode=0):
		if mode == 0:
			print 'Creating images....'
			t0 = libtcod.sys_elapsed_seconds()
		con = libtcod.console_new(game.WORLDMAP_WIDTH, game.WORLDMAP_HEIGHT)
		self.map_image_small = libtcod.image_new(game.WORLDMAP_WIDTH, game.WORLDMAP_HEIGHT)
		self.create_map_legend(con, mode)
		libtcod.image_scale(self.map_image_small, (game.SCREEN_WIDTH - 2) * 2, (game.SCREEN_HEIGHT - 2) * 2)

		if mode == 0:
			while self.player_positionx == 0:
				start = self.randomize('int', 0, (game.WORLDMAP_WIDTH * game.WORLDMAP_HEIGHT) - 1, 3)
				if int(self.hm_list[start] * 1000) in range(int(game.terrain['Forest']['elevation'] * 1000), int(game.terrain['Forest']['maxelev'] * 1000)):
					self.player_positionx = start % game.WORLDMAP_WIDTH
					self.player_positiony = start / game.WORLDMAP_WIDTH
					self.originx = self.player_positionx
					self.originy = self.player_positiony

					path = self.set_dijkstra_map()
					for y in range(game.WORLDMAP_HEIGHT):
						for x in range(game.WORLDMAP_WIDTH):
							dist = libtcod.dijkstra_get_distance(path, x, y)
							if dist > self.max_distance:
								self.max_distance = int(round(dist))
					#libtcod.image_put_pixel(self.map_image_small, self.player_positionx, self.player_positiony, libtcod.white)

		if mode == 2:
			self.map_image_big = libtcod.image_from_console(con)
			libtcod.image_save(self.map_image_big, 'maps/worldmap-' + game.player.name + '.png')
			self.map_image_big = None
		libtcod.console_delete(con)
		if mode == 0:
			t1 = libtcod.sys_elapsed_seconds()
			print '    done! (%.3f seconds)' % (t1 - t0)
Example #37
0
    def showDebugScreen(self):
        # store the current view
        behind_window = libtcod.console_new(SCREEN_WIDTH, SCREEN_HEIGHT)
        libtcod.console_blit(0, 0, 0, SCREEN_WIDTH, SCREEN_HEIGHT, behind_window, 0, 0, 1.0, 1.0)

        # show the background image, at twice the regular console resolution
        img = libtcod.image_load("./media/menu_debug.png")
        libtcod.image_blit_2x(img, 0, 0, 0)

        while not libtcod.console_is_window_closed():
            # show options and wait for the player's choice
            choice = self.showMenu(
                "Select debug option:",
                ["Run some test code!", "Show me some game stuff!", "Back"],  # Choice 0  # Choice 1  # Choice 2
                36,
            )
            # interpret choice
            if choice is None:
                continue
            if choice == 0:
                print "Running some test code!"
                self.runTestCode()
                self.showMessage("Test code complete!", "There might be some output in the console...", 36)
                continue
            elif choice == 1:
                print "Showing some game stuff!"
                self.newGame()
                self.showGameScreen()
            elif choice == 2:  # quit
                print "Back"
                break
        # Clean up (restore whatever was behind this window)
        libtcod.console_blit(behind_window, 0, 0, SCREEN_WIDTH, SCREEN_HEIGHT, 0, 0, 0, 1.0, 1.0)
        libtcod.console_flush()
Example #38
0
def menu(header, options, width):
	if len(options) > 26: raise ValueError("Cannot have a menu with more than 26 options.") #TODO: expand inventory.
	
	header_height = libtcod.console_get_height_rect(con, 0, 0, width, SCREEN_HEIGHT, header)
	height = len(options) + header_height
	
	window = libtcod.console_new(width, height)
	libtcod.console_set_default_foreground(window, libtcod.white)
	libtcod.console_print_rect_ex(window, 0, 0, width, height, libtcod.BKGND_NONE, libtcod.LEFT, header)
	
	y = header_height
	letter_index = ord("a") #can be replaced with a list i'll iterate over when i want more positions
	for option_text in options:
		text = "({0}) {1}".format(chr(letter_index), option_text)
		libtcod.console_print_ex(window, 0, y, libtcod.BKGND_NONE, libtcod.LEFT, text)
		y += 1
		letter_index += 1
	
	#center and show menu
	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)
	index = key.c - ord("a")
	if index >= 0 and index < len(options):
		return index
	else:
		return None
Example #39
0
def init():
	global SYMBOL_MAP, KEYBOARD_MAP, CON, UI, MOUSE, KEY
	w = config.SCREEN_WIDTH
	h = config.SCREEN_HEIGHT
	ltc.sys_set_fps(config.FPS)
	
	#ltc.console_set_custom_font(config.TILE_SET, ltc.FONT_LAYOUT_ASCII_INROW | ltc.FONT_TYPE_GREYSCALE, 16, 16)
	ltc.console_set_custom_font(config.TILE_SET, ltc.FONT_LAYOUT_TCOD | ltc.FONT_TYPE_GREYSCALE, 32, 8)	
	ltc.console_init_root(w, h, config.TITLE, False)
	
	KEYBOARD_MAP = dict([[v, k] for k, v in KEYBOARD_MAP.items()])
	CON = ltc.console_new(w, h)
	UI = ltc.console_new(w, h)
	ltc.console_set_key_color(UI, ltc.purple)
	MOUSE = ltc.Mouse()
	KEY = ltc.Key()
Example #40
0
    def target_tile(max_range=None):
        box = libtcod.console_new(1, 1)
        x = Game.player.x
        y = Game.player.y
        libtcod.console_set_default_background(box, libtcod.orange)
        libtcod.console_clear(box)
        key = Game.key

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

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

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

            else:
                return (None, None)

            if direction == (0, 0):
                if Game.map.is_tile_in_fov(x, y) and (max_range is None or Game.player.distance(x, y) <= max_range):
                    return (x, y)
                else:
                    Game.message('That is out of range.', libtcod.red)
Example #41
0
def menu(header, options, width):
    if len(options) > 26: raise ValueError('Cannot have a menu with more than 26 options.')
    #calculate the total height for the header 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 represent 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_ex(window, 0, 0, width, height, libtcod.BKGND_NONE, libtcod.LEFT, header)
    #print all the option
    y = header_height
    letter_index = ord('a')
    for option_text in options:
        text = '(' + chr(letter_index) + ')' + option_text
        libtcod.console_print_ex(window, 0, y, libtcod.BKGND_NONE, libtcod.LEFT, text)
        y += 1
        letter_index += 1
    #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)
    #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
Example #42
0
def menu(header, options, width):
  if len(options) > 26: raise ValueError('Cannot have a menu with more than 26 options.')
  header_height = libtcod.console_get_height_rect(con, 0, 0, width, SCREEN_HEIGHT, header)
  if header == '':
    header_height = 0
  height = len(options) + header_height
  
  window = libtcod.console_new(width, height)
  libtcod.console_set_default_foreground(window, libtcod.white)
  libtcod.console_print_rect_ex(window, 0, 0, width, height, libtcod.BKGND_NONE, libtcod.LEFT, header)
  
  y = header_height
  letter_index = ord('a')
  for option_text in options:
    text = '(' + chr(letter_index) + ') ' + option_text
    libtcod.console_print_ex(window, 0, y, libtcod.BKGND_NONE, libtcod.LEFT, text)
    y += 1
    letter_index += 1
  
  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:  #(special case) Alt+Enter: toggle fullscreen
    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
Example #43
0
def create_menu(menu=[], position=[0,0], title='Untitled', format_str='$k: $v', padding=MENU_PADDING,
                on_select=None, on_change=None, on_close=None, on_move=None, dim=True, alignment='', action=None,
                close_on_select=False):
	_menu = {'settings': {'position': list(position),'title': title,'padding': padding,'dim': dim,'format': format_str},
		'on_select': on_select,
		'on_change': on_change,
		'on_move': on_move,
		'on_close': on_close,
		'close_on_select': close_on_select,
		'alignment': alignment,
		'index': 0,
		'values':{},
		'action':action}
		
	#TODO: Does this need to be copied?
	_menu['menu'] = menu[:]
	_size = [len(title),len(_menu['menu'])+2+(_menu['settings']['padding'][1]*2)]
	
	_uid = 0
	for entry in _menu['menu']:
		entry['uid'] = _uid
		_uid+=1
		
		for value in range(len(entry['values'])):
			_line = format_entry(_menu['settings']['format'], entry, value=value)
			
			if len(_line) > _size[0]:
				_size[0] = len(_line)
	
	_menu['settings']['size'] = (_size[0]+(_menu['settings']['padding'][0]*2),_size[1])
	_menu['settings']['console'] = tcod.console_new(_menu['settings']['size'][0],_menu['settings']['size'][1])
	
	MENUS.append(_menu)
	
	return MENUS.index(_menu)
Example #44
0
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
Example #45
0
 def createPanels(self, width, height):
     self.mainconsole = libtcod.console_new(SCREEN_WIDTH, SCREEN_HEIGHT)
     self.mainconsolewidth = SCREEN_WIDTH - 11
     self.mainconsoleheight = SCREEN_HEIGHT - 15
     self.msgpanel = MessagePanel(0, height-15, width/2, 10)
     self.combatlog = MessagePanel(width/2+1, height-15, width/2, 20)
     self.typingpanel = TypingPanel(width, height-2)
Example #46
0
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 autowrap 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 another offscreen console for the menu's window
    window = libtcod.console_new(width, height)
    
    #print the header, with autowrap
    libtcod.console_set_default_foreground(window, libtcod.white)
    libtcod.console_print_rect_ex(window, 0, 0, width, height, libtcod.BKGND_NONE, libtcod.LEFT, header)
    
    y = header_height
    letter_index = ord('a') #start the list of inventory items with ordinal letter a
    for option_text in options:
        text = '(' + chr(letter_index) + ') ' + option_text #converts ordinal to a string for selection
        libtcod.console_print_ex(window, 0, y, libtcod.BKGND_NONE, libtcod.LEFT, text)
        y += 1
        letter_index += 1
        
        #blit the contents of the inventory window to the root console in the middle of the screen
        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) #last two values transparency%
        
        #present to the root console to the player and wait for key-press
        libtcod.console_flush()
        key = libtcod.console_wait_for_keypress(True)
Example #47
0
def menu(header, options, width):
    if len(options) > 26: raise ValueError('Cannot have a menu with more than 26 options')
    # Calc the header height after auto-wrap, one line per option
    header_height = libtcod.console_get_height_rect(con, 0, 0, width, opt.SCREEN_HEIGHT, header)
    if header == '':
        header_height = 0
    height = len(options) + header_height
    # Create new offscreen window
    window = libtcod.console_new(width, height)
    # Print header with auto-wrap
    libtcod.console_set_default_foreground(window, libtcod.Color(230,230,230))
    libtcod.console_print_rect_ex(window, 0, 0, width, height, libtcod.BKGND_NONE, libtcod.LEFT, header)
    # Print options
    y = header_height
    letter_index = ord('a')
    for option_text in options:
        # Print options in format a) Option
        text = chr(letter_index) + ')  ' + option_text
        libtcod.console_print_ex(window, 0, y, libtcod.BKGND_NONE, libtcod.LEFT, text)
        y += 1
        letter_index += 1
    x = opt.SCREEN_WIDTH/2 - width/2
    y = opt.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())

    # If an item was chosen, return it
    index = key.c - ord('a')
    if index >= 0 and index < len(options): return index
    return None
Example #48
0
    def __init__(self):
        #GUI and map variables
        self.SCREEN_WIDTH = 80
        self.SCREEN_HEIGHT = 50
        #MAP_X_SIZE and _Y_SIZE are the size of the map in chunks
        self.MAP_X_SIZE = 200
        self.MAP_Y_SIZE = 400
        self.CHUNK_SIZE = 128
        self.MAP_WIDTH = self.MAP_X_SIZE*self.CHUNK_SIZE
        self.MAP_HEIGHT = self.MAP_Y_SIZE*self.CHUNK_SIZE
        self.CAMERA_WIDTH = 80
        self.CAMERA_HEIGHT = 49
        self.LIMIT_FPS = 20
        self.INFOBAR_HEIGHT = 1
        self.ACTIONPANEL_WIDTH = 15
        self.MENU_WIDTH = 20
        self.GAME_FONT = 'arial10x10.png'
        #We begin in the center of this chunk
        self.PLAYER_START_X = 100
        self.PLAYER_START_Y = 200

        #Variable controlling frame interval for certain events
        self.GAMESPEED = 5

        #Minimum number of frames between player movements/actions
        self.MAX_MOVESPEED = self.GAMESPEED/2

        libtcod.console_set_custom_font(self.GAME_FONT, libtcod.FONT_TYPE_GREYSCALE | libtcod.FONT_LAYOUT_TCOD)
        libtcod.console_init_root(self.SCREEN_WIDTH, self.SCREEN_HEIGHT, 'python/libtcod tutorial', False)
        libtcod.sys_set_fps(self.LIMIT_FPS)
        self.con = libtcod.console_new(self.SCREEN_WIDTH, self.SCREEN_HEIGHT)

        #Game state and GUI control variables
        self.show_menu = False
        self.mode = "move"
        self.cursor = None
        self.time = "free"
        self.player_wait = 0

        self.npcs = []
        self.player = None
        self.camera = None
        self.objects = []
        self.map = None

        self.infobar = libtcod.console_new(self.SCREEN_WIDTH, self.INFOBAR_HEIGHT)
        self.menu = libtcod.console_new(self.MENU_WIDTH, self.SCREEN_HEIGHT)
Example #49
0
def character_screen(player, character_screen_width, character_screen_height,
                     screen_width, screen_height, colors):
    """Show character_screen with basic information."""
    window = libtcod.console_new(character_screen_width,
                                 character_screen_height)

    libtcod.console_set_default_foreground(window, colors['text_default'])
    libtcod.console_set_color_control(libtcod.COLCTRL_1,
                                      colors['text_info_alt'], libtcod.black)
    libtcod.console_set_color_control(libtcod.COLCTRL_2,
                                      colors['text_emphasize'], libtcod.black)

    heading = f'%cCharacter Information%c' % (libtcod.COLCTRL_2,
                                              libtcod.COLCTRL_STOP)
    libtcod.console_print_rect_ex(window, 0, 1, character_screen_width,
                                  character_screen_height, libtcod.BKGND_NONE,
                                  libtcod.LEFT, heading)

    player_level = f'Level: %c{player.level.current_level}%c' % (
        libtcod.COLCTRL_1, libtcod.COLCTRL_STOP)
    libtcod.console_print_rect_ex(window, 0, 2, character_screen_width,
                                  character_screen_height, libtcod.BKGND_NONE,
                                  libtcod.LEFT, player_level)

    player_experience = f'Experience: %c{player.level.current_xp}%c' % (
        libtcod.COLCTRL_1, libtcod.COLCTRL_STOP)
    libtcod.console_print_rect_ex(window, 0, 3, character_screen_width,
                                  character_screen_height, libtcod.BKGND_NONE,
                                  libtcod.LEFT, player_experience)

    player_experience_to_next_level = f'Experience to level: %c{player.level.experience_to_next_level}%c' % (
        libtcod.COLCTRL_1, libtcod.COLCTRL_STOP)
    libtcod.console_print_rect_ex(window, 0, 4, character_screen_width,
                                  character_screen_height, libtcod.BKGND_NONE,
                                  libtcod.LEFT,
                                  player_experience_to_next_level)

    player_maximum_hp = f'Maximum HP: %c{player.fighter.max_hp}%c' % (
        libtcod.COLCTRL_1, libtcod.COLCTRL_STOP)
    libtcod.console_print_rect_ex(window, 0, 6, character_screen_width,
                                  character_screen_height, libtcod.BKGND_NONE,
                                  libtcod.LEFT, player_maximum_hp)

    player_attack = f'Attack: %c{player.fighter.power}%c' % (
        libtcod.COLCTRL_1, libtcod.COLCTRL_STOP)
    libtcod.console_print_rect_ex(window, 0, 7, character_screen_width,
                                  character_screen_height, libtcod.BKGND_NONE,
                                  libtcod.LEFT, player_attack)

    player_defense = f'Defense: %c{player.fighter.defense}%c' % (
        libtcod.COLCTRL_1, libtcod.COLCTRL_STOP)
    libtcod.console_print_rect_ex(window, 0, 8, character_screen_width,
                                  character_screen_height, libtcod.BKGND_NONE,
                                  libtcod.LEFT, player_defense)

    x = int(screen_width / 2 - character_screen_width / 2)
    y = int(screen_height / 2 - character_screen_height / 2)
    libtcod.console_blit(window, 0, 0, character_screen_width,
                         character_screen_height, 0, x, y, 1.0, 0.7)
Example #50
0
def main():
    screen_width = 80
    screen_height = 80

    map_width = 80
    map_height = 70

    colors = {

        'dark_wall': libtcod.Color(45, 65, 100),
        'dark_ground': libtcod.Color(13, 23, 15)

    }


    player = Entity(int(screen_width / 2), int(screen_height / 2), '@', libtcod.white)
    entities = [player]

    libtcod.console_set_custom_font('arial10x10.png', libtcod.FONT_TYPE_GREYSCALE | libtcod.FONT_LAYOUT_TCOD)

    libtcod.console_init_root(screen_width, screen_height, 'table tosser', False)

    con = libtcod.console_new(screen_width, screen_height)

    game_map = GameMap(map_width, map_height)

    

    key = libtcod.Key()
    mouse = libtcod.Mouse()

    while not libtcod.console_is_window_closed():

        libtcod.sys_check_for_event(libtcod.EVENT_KEY_PRESS, key, mouse)


        render_all(con, entities, game_map, screen_width, screen_height, colors)


        libtcod.console_flush()
        
        clear_all(con, entities)

        action = handle_keys(key)

        move = action.get('move')
        exit = action.get('exit')
        fullscreen = action.get('fullscreen')

        if move:
            dx, dy = move
            if not game_map.is_blocked(player.x + dx, player.y +dy):
                player.move(dx, dy)

        if exit:
            return True

        if fullscreen:
            libtcod.console_set_fullscreen(not libtcod.console_is_fullscreen())
Example #51
0
def offscreen(console):
    """Return an off-screen console with the same size as the root console."""
    offscreen = libtcodpy.console_new(
        libtcodpy.console_get_width(console),
        libtcodpy.console_get_height(console),
        )
    yield offscreen
    libtcodpy.console_delete(offscreen)
Example #52
0
 def setup_ingame_ui(self):
     self.game_view = GameView(self.max_camera_width,
                               self.max_camera_height)
     self.infobar = Infobar(self.max_camera_width, self.infobar_height)
     self.sidemenu = SideMenu(self.sidemenu_width, self.max_camera_height)
     self.gui_background = libtcod.console_new(self.screen_width,
                                               self.screen_height)
     self.current_menu = None
Example #53
0
    def initDisplay(self, displayWidth, displayHeight):
        self._displayWidth = displayWidth
        self._displayHeight = displayHeight

        #libtcod consoles to draw to
        self._displayCon = tcod.console_new(displayWidth, displayHeight)
        self._overlay = tcod.console_new(displayWidth, displayHeight)

        #position of the "crosshair" within the console
        self._hudX = self._displayWidth / 2
        self._hudY = self._displayHeight / 2

        #the map coord where the "Crosshair" is currently located
        self._selectedX = self._offsetX + self._hudX
        self._selectedY = self._offsetY + self._hudY

        self.showCrosshair = True
Example #54
0
 def __init__(self):
     self.width = constants.WINDOW_WIDTH
     self.height = constants.WINDOW_HEIGHT
     self.console = libtcod.console_new(self.width, self.height)
     libtcod.console_set_custom_font(b'arial10x10.png',
                                     libtcod.FONT_TYPE_GREYSCALE |
                                     libtcod.FONT_LAYOUT_TCOD)
     libtcod.console_init_root(self.width, self.height, b'Pyrogue', False)
Example #55
0
 def render(self):
     con = libtcod.console_new(self.width, self.height)
     y = 1
     for (line, color) in self.lines:
         libtcod.console_set_default_foreground(con, color)
         libtcod.console_print_ex(con, 0, y, libtcod.BKGND_NONE,
                                  libtcod.LEFT, line)
         y += 1
     return con
Example #56
0
 def __init__(self, width=20, height=10, console_id=None):
     if console_id is None:
         self.console_id = libtcod.console_new(width, height)
         self.width = width
         self.height = height
     else:
         self.console_id = console_id
         self.width = libtcod.console_get_width(console_id)
         self.height = libtcod.console_get_height(console_id)
Example #57
0
 def __init__(self, x: int, y: int, width: int, height: int, fore_fade: float, back_fade: float, parent=None):
     self.con_id: int = libtcod.console_new(width, height)
     self.parent: GameConsole = parent  # If None, it prints to root
     self.x: int = x  # The console's starting top left coordinates on it's parent interface
     self.y: int = y
     self.width: int = width
     self.height: int = height
     self.fore_fade: float = fore_fade
     self.back_fade: float = back_fade
Example #58
0
def main():
    screen_width = 80
    screen_height = 50
    map_width = 80
    map_height = 45

    colors = {
        "dark_wall": libtcod.Color(0, 0, 100),
        "dark_ground": libtcod.Color(50, 50, 150)
    }

    player = Entity(int(screen_width / 2), int(screen_height / 2), "@",
                    libtcod.fuchsia)
    npc = Entity(int(screen_width / 2 - 5), int(screen_height / 2), "@",
                 libtcod.yellow)
    entities = [npc, player]

    # http://roguecentral.org/doryen/data/libtcod/doc/1.5.1/html2/console_set_custom_font.html?c=false&cpp=false&cs=false&py=true&lua=false
    libtcod.console_set_custom_font(
        "arial10x10.png",
        libtcod.FONT_TYPE_GREYSCALE | libtcod.FONT_LAYOUT_TCOD)
    # Creates the window, title, and fullscreen
    libtcod.console_init_root(screen_width, screen_height, "B@rd", False)

    # Draw a new console
    con = libtcod.console_new(screen_width, screen_height)

    game_map = GameMap(map_width, map_height)

    # Holds keyboard and mouse input
    key = libtcod.Key()
    mouse = libtcod.Mouse()

    # Game loop (until screen is closed)
    while not libtcod.console_is_window_closed():
        libtcod.sys_check_for_event(libtcod.EVENT_KEY_PRESS, key, mouse)

        render_all(con, entities, game_map, screen_width, screen_height,
                   colors)
        libtcod.console_flush()
        clear_all(con, entities)

        action = handle_keys(key)
        move = action.get("move")
        exit = action.get("exit")
        fullscreen = action.get("fullscreen")

        if move:
            dx, dy = move
            if not game_map.is_blocked(player.x + dx, player.y + dy):
                player.move(dx, dy)

        if exit:
            return True

        if fullscreen:
            libtcod.console_set_fullscreen(not libtcod.console_is_fullscreen())
Example #59
0
def init():
    global SYMBOL_MAP, KEYBOARD_MAP, CON, UI, MOUSE, KEY
    w = config.SCREEN_WIDTH
    h = config.SCREEN_HEIGHT
    ltc.sys_set_fps(config.FPS)

    #ltc.console_set_custom_font(config.TILE_SET, ltc.FONT_LAYOUT_ASCII_INROW | ltc.FONT_TYPE_GREYSCALE, 16, 16)
    ltc.console_set_custom_font(config.TILE_SET,
                                ltc.FONT_LAYOUT_TCOD | ltc.FONT_TYPE_GREYSCALE,
                                32, 8)
    ltc.console_init_root(w, h, config.TITLE, False)

    KEYBOARD_MAP = dict([[v, k] for k, v in KEYBOARD_MAP.items()])
    CON = ltc.console_new(w, h)
    UI = ltc.console_new(w, h)
    ltc.console_set_key_color(UI, ltc.purple)
    MOUSE = ltc.Mouse()
    KEY = ltc.Key()
Example #60
0
def main():
	screen_width = 80
	screen_height = 50
	map_width = 80
	map_height = 45
	
	room_max_size = 10
	room_min_size = 6
	max_rooms = 30
	
	colors = {
		'dark_wall': libtcod.Color(0, 0, 100),
		'dark_ground': libtcod.Color(50, 50, 150)
	}
	
	player = Entity(int(screen_width / 2), int(screen_height / 2), '@', libtcod.white)
	npc = Entity(int(screen_width / 2), int(screen_height / 2), '@', libtcod.yellow)
	entities = [npc, player]
	
	libtcod.console_set_custom_font('arial10x10.png', libtcod.FONT_TYPE_GREYSCALE | libtcod.FONT_LAYOUT_TCOD)
	
	libtcod.console_init_root(screen_width, screen_height, 'libtcod tutorial revised', False)
	
	con = libtcod.console_new(screen_width, screen_height)
	
	game_map = GameMap(map_width, map_height)
	game_map.make_map(max_rooms, room_min_size, room_max_size, map_width, map_height, player)
	
	key = libtcod.Key()
	mouse = libtcod.Mouse()
	
	while not libtcod.console_is_window_closed():
		libtcod.sys_check_for_event(libtcod.EVENT_KEY_PRESS, key, mouse)
	
		render_all(con, entities, game_map, screen_width, screen_height, colors)
		
		libtcod.console_flush()
		
		clear_all(con, entities)
		
		action = handle_keys(key)
		
		move = action.get('move')
		exit = action.get('exit')
		fullscreen = action.get('fullscreen')
		
		if move:
			dx, dy = move
			if not game_map.is_blocked(player.x + dx, player.y + dy):
				player.move(dx, dy)
		
		if exit:
			return True
			
		if fullscreen:
			libtcod.console_set_fullscreen(not libtcod.console_is_fullscreen())