Example #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'
Example #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'
Example #3
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)
Example #4
0
def handle_input():
    key = libtcod.console_check_for_keypress(libtcod.KEY_PRESSED)
    mouse = libtcod.mouse_get_status()
    (x, y) = (mouse.cx, mouse.cy)

    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

    elif chr(key.c) == 'r':
        reset()

    if game_state == 'playing':
        #movement keys
        if key.vk == libtcod.KEY_KP8 or key.vk == libtcod.KEY_UP:
            player_move_or_attack(0, -1)
 
        elif key.vk == libtcod.KEY_KP2 or key.vk == libtcod.KEY_DOWN:
            player_move_or_attack(0, 1)
 
        elif key.vk == libtcod.KEY_KP4 or key.vk == libtcod.KEY_LEFT:
            player_move_or_attack(-1, 0)
 
        elif key.vk == libtcod.KEY_KP6 or key.vk == libtcod.KEY_RIGHT:
            player_move_or_attack(1, 0)

        elif key.vk == libtcod.KEY_KP7:
            player_move_or_attack(-1, -1)

        elif key.vk == libtcod.KEY_KP9:
            player_move_or_attack(1, -1)

        elif key.vk == libtcod.KEY_KP1:
            player_move_or_attack(-1, 1)

        elif key.vk == libtcod.KEY_KP3:
            player_move_or_attack(1, 1)

        #if nearest player neighbor is clicked
        elif mouse.lbutton:
            angle = math.atan2(player.y-y, player.x-x)/math.pi*180
            if angle > 157.5:
                player_move_or_attack(1, 0)
            elif 157.5 > angle > 112.5:
                player_move_or_attack(1, -1)
            elif 112.5 > angle > 67.5:
                player_move_or_attack(0, -1)
            elif 67.5 > angle > 22.5:
                player_move_or_attack(-1, -1)
            elif 22.5 > angle > -22.5:
                player_move_or_attack(-1, 0)
            elif -22.5 > angle > -67.5:
                player_move_or_attack(-1, 1)
            elif -67.5 > angle > -112.5:
                player_move_or_attack(0, 1)
            elif -112.5 > angle > -157.5:
                player_move_or_attack(1, 1)
            elif -157.5 > angle:
                player_move_or_attack(1, 0)
        else:
            #test for other keys
            key_char = chr(key.c)

            if key_char == 'n':
                for object in objects:  #look for an item in the player's tile
                    if object.x == player.x and object.y == player.y and isinstance(object, Object):
                        if object.name == 'hole':
                            next_level()
                            break
                        else:
                            no_hole = True
                if no_hole == True:
                    message('There is no hole down there.')

            if key_char == 'g':
                #pick up an item
                for object in objects:  #look for an item in the player's tile
                    if object.x == player.x and object.y == player.y and isinstance(object, Item):
                        object.pick_up()
                        break
 
            if key_char == 'i':
                #show the inventory; if an item is selected, use it
                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':
                #show the inventory; if an item is selected, drop it
                chosen_item = inventory_menu('Press the 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'
def handle_keys():
    global key

    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:
        # exit game
        return 'exit'

    if game_state == 'playing':
        # movement keys
        if key.vk == libtcod.KEY_UP or key.vk == libtcod.KEY_KP8:
            player_move_or_attack(0, -1)
        elif key.vk == libtcod.KEY_DOWN or key.vk == libtcod.KEY_KP2:
            player_move_or_attack(0, 1)
        elif key.vk == libtcod.KEY_LEFT or key.vk == libtcod.KEY_KP4:
            player_move_or_attack(-1, 0)
        elif key.vk == libtcod.KEY_RIGHT or key.vk == libtcod.KEY_KP6:
            player_move_or_attack(1, 0)
        elif key.vk == libtcod.KEY_HOME or key.vk == libtcod.KEY_KP7:
            player_move_or_attack(-1, -1)
        elif key.vk == libtcod.KEY_PAGEUP or key.vk == libtcod.KEY_KP9:
            player_move_or_attack(1, -1)
        elif key.vk == libtcod.KEY_END or key.vk == libtcod.KEY_KP1:
            player_move_or_attack(-1, 1)
        elif key.vk == libtcod.KEY_PAGEDOWN or key.vk == libtcod.KEY_KP3:
            player_move_or_attack(1, 1)
        elif key.vk == libtcod.KEY_KP5:
            # do nothing ie wait for the monster to come to you
            pass
        else:
            # test for other keys
            key_char = chr(key.c)

            if key_char == 'g':
                # pick up an item, after looking for an item in the
                # player's tile
                for object in objects:
                    if object.x == player.x and object.y == player.y and \
                            object.item:
                        object.item.pick_up()
                        break

            if key_char == 'i':
                # show the inventory; if an item is selected, use it
                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':
                # show the inventory; if an item is selected, drop it
                chosen_item = inventory_menu(
                    'Press the key next to an item to drop it, or any other'
                    ' to cancel.\n')
                if chosen_item is not None:
                    chosen_item.drop()

            if key_char == 'c':
                # show character information
                level_up_xp = LEVEL_UP_BASE + player.level * LEVEL_UP_FACTOR
                msgbox('Character Information\n\nLevel: ' +
                       str(player.level) + '\nExperience: ' +
                       str(player.fighter.xp) + '\nExperience to level up: ' +
                       str(level_up_xp) + '\n\nMaximum HP: ' +
                       str(player.fighter.max_hp) + '\nAttack: ' +
                       str(player.fighter.power) + '\nDefense: ' +
                       str(player.fighter.defense), CHARACTER_SCREEN_WIDTH)

            if key_char == '<':
                # go down stairs, if the player is on them
                if stairs.x == player.x and stairs.y == player.y:
                    next_level()

            return 'didnt-take-turn'
Example #6
0
def handle_input():
    key = libtcod.console_check_for_keypress(libtcod.KEY_PRESSED)
    mouse = libtcod.mouse_get_status()
    (x, y) = (mouse.cx, mouse.cy)

    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

    elif chr(key.c) == 'r':
        reset()

    if game_state == 'playing':
        #movement keys
        if key.vk == libtcod.KEY_KP8 or key.vk == libtcod.KEY_UP:
            player_move_or_attack(0, -1)

        elif key.vk == libtcod.KEY_KP2 or key.vk == libtcod.KEY_DOWN:
            player_move_or_attack(0, 1)

        elif key.vk == libtcod.KEY_KP4 or key.vk == libtcod.KEY_LEFT:
            player_move_or_attack(-1, 0)

        elif key.vk == libtcod.KEY_KP6 or key.vk == libtcod.KEY_RIGHT:
            player_move_or_attack(1, 0)

        elif key.vk == libtcod.KEY_KP7:
            player_move_or_attack(-1, -1)

        elif key.vk == libtcod.KEY_KP9:
            player_move_or_attack(1, -1)

        elif key.vk == libtcod.KEY_KP1:
            player_move_or_attack(-1, 1)

        elif key.vk == libtcod.KEY_KP3:
            player_move_or_attack(1, 1)

        #if nearest player neighbor is clicked
        elif mouse.lbutton:
            angle = math.atan2(player.y - y, player.x - x) / math.pi * 180
            if angle > 157.5:
                player_move_or_attack(1, 0)
            elif 157.5 > angle > 112.5:
                player_move_or_attack(1, -1)
            elif 112.5 > angle > 67.5:
                player_move_or_attack(0, -1)
            elif 67.5 > angle > 22.5:
                player_move_or_attack(-1, -1)
            elif 22.5 > angle > -22.5:
                player_move_or_attack(-1, 0)
            elif -22.5 > angle > -67.5:
                player_move_or_attack(-1, 1)
            elif -67.5 > angle > -112.5:
                player_move_or_attack(0, 1)
            elif -112.5 > angle > -157.5:
                player_move_or_attack(1, 1)
            elif -157.5 > angle:
                player_move_or_attack(1, 0)
        else:
            #test for other keys
            key_char = chr(key.c)

            if key_char == 'n':
                for object in objects:  #look for an item in the player's tile
                    if object.x == player.x and object.y == player.y and isinstance(
                            object, Object):
                        if object.name == 'hole':
                            next_level()
                            break
                        else:
                            no_hole = True
                if no_hole == True:
                    message('There is no hole down there.')

            if key_char == 'g':
                #pick up an item
                for object in objects:  #look for an item in the player's tile
                    if object.x == player.x and object.y == player.y and isinstance(
                            object, Item):
                        object.pick_up()
                        break

            if key_char == 'i':
                #show the inventory; if an item is selected, use it
                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':
                #show the inventory; if an item is selected, drop it
                chosen_item = inventory_menu(
                    'Press the 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'
Example #7
0
 def toggleFullScreen(self):
     libtcod.console_set_fullscreen(not libtcod.console_is_fullscreen())