Exemple #1
0
def handle_keys():
    global playerx, playery, fov_recompute

    #console controls
    key = libtcod.console_wait_for_keypress(
        True)  # THIS LINE IS SPECIFIC FOR TURN BASED

    if key.vk == libtcod.KEY_ENTER and key.lalt:
        #ALT+ENTER toggle fullscreen
        libtcod.console_set_fullscreen(not libtcod.console_is_fullscreen())

    elif key.vk == libtcod.KEY_ESCAPE:
        return 'exit'  # exit game

    #movement keys
    #is_key_pressed is supposed to be for real-time and check_for_keypress is for TURN BASED
    #but it behaved strangely if i did not use is_key_pressed
    if game_state == 'playing':
        if libtcod.console_is_key_pressed(libtcod.KEY_UP):
            player_move_or_attack(0, -1)

        elif libtcod.console_is_key_pressed(libtcod.KEY_DOWN):
            player_move_or_attack(0, 1)

        elif libtcod.console_is_key_pressed(libtcod.KEY_LEFT):
            player_move_or_attack(-1, 0)

        elif libtcod.console_is_key_pressed(libtcod.KEY_RIGHT):
            player_move_or_attack(1, 0)

        else:
            #all other keys
            key_char = chr(key.c)
            if key_char == 'g':
                #pick up item
                for stuff in objects:
                    if stuff.x == player.x and stuff.y == player.y and stuff.item:
                        stuff.item.pick_up()
                        break
            if key_char == 'i':
                #show inventory
                chosen_item = inventory_menu(
                    'Press the key next to an item to use it, or any other to cancel. \n'
                )
                if chosen_item is not None:
                    chosen_item.use()
            if key_char == 'd':
                chosen_item = inventory_menu(
                    'Press they key next to an item to drop it, or any other to cancel. \n'
                )
                if chosen_item is not None:
                    chosen_item.drop()

            return 'didnt-take-turn'
Exemple #2
0
def handle_keys():
	global playerx, playery, fov_recompute
	
	#console controls 
	key = libtcod.console_wait_for_keypress(True) # THIS LINE IS SPECIFIC FOR TURN BASED

	if key.vk == libtcod.KEY_ENTER and key.lalt:
		#ALT+ENTER toggle fullscreen
		libtcod.console_set_fullscreen(not libtcod.console_is_fullscreen())
	
	elif key.vk == libtcod.KEY_ESCAPE:
		return  'exit' # exit game


	#movement keys
	#is_key_pressed is supposed to be for real-time and check_for_keypress is for TURN BASED 
	#but it behaved strangely if i did not use is_key_pressed
	if game_state == 'playing':
		if libtcod.console_is_key_pressed(libtcod.KEY_UP):
			player_move_or_attack(0,-1)
			

		elif libtcod.console_is_key_pressed(libtcod.KEY_DOWN):
			player_move_or_attack(0,1)
			

		elif libtcod.console_is_key_pressed(libtcod.KEY_LEFT):
			player_move_or_attack(-1,0)
			
				
		elif libtcod.console_is_key_pressed(libtcod.KEY_RIGHT):
			player_move_or_attack(1,0)
			
		else:
			#all other keys
			key_char = chr(key.c)
			if key_char == 'g':
				#pick up item
				for stuff in objects:
					if stuff.x == player.x and stuff.y == player.y and stuff.item:
						stuff.item.pick_up()
						break
			if key_char == 'i':
				#show inventory
				chosen_item = inventory_menu('Press the key next to an item to use it, or any other to cancel. \n')
				if chosen_item is not None:
					chosen_item.use()
			if key_char == 'd':
				chosen_item = inventory_menu('Press they key next to an item to drop it, or any other to cancel. \n')
				if chosen_item is not None:
						chosen_item.drop()

			return 'didnt-take-turn'
Exemple #3
0
 def handle_stroke(self, state):
     """
          key may be a libtcod.KEY_CODE or a letter.
     """
     key = libtcod.console_wait_for_keypress(True)
     if not key.pressed:
         return None         # ignore key releases
     if key.vk == libtcod.KEY_CHAR: 
         key = chr(key.c)
     else:
         key = key.vk
     if self.actionsdb[state].has_key(key):
         return self.actionsdb[state][key]
Exemple #4
0
def handle_keys():
    # key = libtcod.console_check_for_keypress()  #real-time
    key = libtcod.console_wait_for_keypress(True)  # turn-based

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

    elif key.vk == libtcod.KEY_ESCAPE:
        return True  # exit game

    # elif key.c == ord('y') or key.c == ord('Y'):
    #     # Show/hide amulet
    #     amulet.toggle()

    elif amulet.visible and amulet.is_blocking():
        if key.vk < libtcod.KEY_0 or key.vk > libtcod.KEY_KP9:
            # This is for the ReviewExperienceMenu only
            Messenger().message('You need to enter a score before continuing!')
            return
        else:
            success = amulet.keyboard_input(key.vk)
            if not success:
                return
    else:

        # movement keys
        if libtcod.console_is_key_pressed(
                libtcod.KEY_UP) and player.char != 'X':
            player.move(dungeon_map, 0, -1)

        elif libtcod.console_is_key_pressed(
                libtcod.KEY_DOWN) and player.char != 'X':
            player.move(dungeon_map, 0, 1)

        elif libtcod.console_is_key_pressed(
                libtcod.KEY_LEFT) and player.char != 'X':
            player.move(dungeon_map, -1, 0)

        elif libtcod.console_is_key_pressed(
                libtcod.KEY_RIGHT) and player.char != 'X':
            player.move(dungeon_map, 1, 0)

        # TEMPORARY: press r to review a business
        elif key.c == ord('r'):
            biz = random.choice(district.businesses)
            biz.visit(player)
        elif key.vk >= libtcod.KEY_0 and key.vk <= libtcod.KEY_KP9:
            # If amulet is displayed, redirect numeric input to amulet
            amulet.keyboard_input(key.vk)
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_get_height_rect(con, 0, 0, width,
                                                    SCREEN_HEIGHT, header)
    if header == '':
        header_height = 0
    height = len(options) + header_height

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

    # print the header, with auto-wrap
    libtcod.console_set_default_foreground(window, libtcod.white)
    libtcod.console_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 = 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)

    # (special case) Alt+Enter: toggle fullscreen
    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
Exemple #6
0
 def __handle_keys(self):
   key = libtcod.console_wait_for_keypress(True)
   if key.vk == libtcod.KEY_ESCAPE:
     return 'exit'
   if self.__state == 'playing':
     if libtcod.console_is_key_pressed(libtcod.KEY_UP):
       self.__player.move_or_attack(0, -1)
       self.__recompute_fov = True
     elif libtcod.console_is_key_pressed(libtcod.KEY_DOWN):
       self.__player.move_or_attack(0, 1)
       self.__recompute_fov = True
     elif libtcod.console_is_key_pressed(libtcod.KEY_LEFT):
       self.__player.move_or_attack(-1 ,0)
       self.__recompute_fov = True
     elif libtcod.console_is_key_pressed(libtcod.KEY_RIGHT):
       self.__player.move_or_attack(1, 0)
       self.__recompute_fov = True
     else:
       return 'pass'
Exemple #7
0
def menu(header, options, width):
    if len(options) > 26:
        raise ValueError('Cannot have a menu with more than 26 options.')

    #calc height of header
    header_height = libtcod.console_height_left_rect(con, 0, 0, width,
                                                     SCREEN_HEIGHT, header)
    if header == '':
        header_height = 0
    height = len(options) + header_height

    #offscreen conolse
    window = libtcod.console_new(width, height)

    #print the header
    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

    #blit the contents to the main 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)

    #wait for keypress
    libtcod.console_flush()
    key = libtcod.console_wait_for_keypress(True)

    #convert ascii to index
    index = key.c - ord('a')
    if index >= 0 and index < len(options): return index
    return None
Exemple #8
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 auto-wrap) and one line per option
    header_height = libtcod.console_height_left_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_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 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
Exemple #9
0
def handle_keys():
    global fov_recompute

    key = libtcod.console_wait_for_keypress(True)

    if key.vk == libtcod.KEY_ESCAPE:
        return True

    if libtcod.console_is_key_pressed(libtcod.KEY_UP):
        fov_recompute = True
        player.move(0, -1)

    elif libtcod.console_is_key_pressed(libtcod.KEY_DOWN):
        fov_recompute = True
        player.move(0, 1)

    elif libtcod.console_is_key_pressed(libtcod.KEY_LEFT):
        fov_recompute = True
        player.move(-1, 0)

    elif libtcod.console_is_key_pressed(libtcod.KEY_RIGHT):
        fov_recompute = True
        player.move(1, 0)
Exemple #10
0
def menu(header, options, width):
	if len(options) > 26: raise ValueError('Cannot have a menu with more than 26 options.')

	#calc height of header
	header_height = libtcod.console_height_left_rect(con, 0, 0, width, SCREEN_HEIGHT, header)
	if header == '':
		header_height = 0
	height = len(options) + header_height

	#offscreen conolse
	window = libtcod.console_new(width, height)
	
	#print the header
	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
	
	#blit the contents to the main 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)

	#wait for keypress
	libtcod.console_flush()
	key = libtcod.console_wait_for_keypress(True)

	#convert ascii to index
	index = key.c - ord('a')
	if index >= 0 and index < len(options): return index
	return None
    libtcod.line(rect.x1, rect.y1, rect.x1, rect.y2, listener)
    libtcod.line(rect.x2, rect.y1, rect.x2, rect.y2, listener)
    libtcod.line(rect.x1, rect.y2, rect.x2, rect.y2, listener)

    if tree.left is not None:
        trace_sections(tree.left)
    if tree.right is not None:
        trace_sections(tree.right)

trace_sections(tree)

libtcod.console_set_custom_font(
    'terminal12x12_gs_ro.png',
    libtcod.FONT_TYPE_GREYSCALE | libtcod.FONT_LAYOUT_ASCII_INROW)

libtcod.console_init_root(
    SCREEN_WIDTH, SCREEN_HEIGHT, 'rogue-one', False, libtcod.RENDERER_GLSL)

for x in range(SCREEN_WIDTH):
    for y in range(SCREEN_HEIGHT):
        col = libtcod.Color(60 * map[x][y], 60 * map[x][y], 60 * map[x][y])
        libtcod.console_set_char_background(0, x, y, col)
        libtcod.console_set_default_foreground(0, libtcod.dark_grey)
        libtcod.console_put_char(0, x, y, ".")

libtcod.console_flush()

libtcod.console_wait_for_keypress(True)

exit()