예제 #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'
예제 #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'
예제 #3
0
파일: yelpdor.py 프로젝트: bhallen/yelpdor
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)
예제 #4
0
파일: game.py 프로젝트: jimperio/pyrl
 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'
예제 #5
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)