示例#1
0
def input():
    global recompute_field_of_view

    # key = libtcod.console_check_for_keypress()  #real-time
    key = tcod.console_wait_for_keypress(True)  # turn-based

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

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

    # movement keys

    if tcod.console_is_key_pressed(tcod.KEY_UP):
        engine.frogue.move(0, -1)
        render.recompute_field_of_view = True

    elif tcod.console_is_key_pressed(tcod.KEY_DOWN):
        engine.frogue.move(0, 1)
        render.recompute_field_of_view = True

    elif tcod.console_is_key_pressed(tcod.KEY_LEFT):
        engine.frogue.move(-1, 0)
        render.recompute_field_of_view = True

    elif tcod.console_is_key_pressed(tcod.KEY_RIGHT):
        engine.frogue.move(1, 0)
        render.recompute_field_of_view = True
示例#2
0
def handle_keys():
    global playerx, playery
 
    #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
 
    #movement keys
    if libtcod.console_is_key_pressed(libtcod.KEY_UP):
        playery -= 1
 
    elif libtcod.console_is_key_pressed(libtcod.KEY_DOWN):
        playery += 1
 
    elif libtcod.console_is_key_pressed(libtcod.KEY_LEFT):
        playerx -= 1
 
    elif libtcod.console_is_key_pressed(libtcod.KEY_RIGHT):
        playerx += 1
示例#3
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
示例#4
0
def handle_keys():
    game.fov_recompute = False

    key = libtcod.console_wait_for_keypress(True)

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

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

    # movement keys
    if libtcod.console_is_key_pressed(libtcod.KEY_UP):
        try_move(game.player_one, (0, -1))
        game.fov_recompute = True

    elif libtcod.console_is_key_pressed(libtcod.KEY_DOWN):
        try_move(game.player_one, (0, 1))
        game.fov_recompute = True

    elif libtcod.console_is_key_pressed(libtcod.KEY_LEFT):
        try_move(game.player_one, (-1, 0))
        game.fov_recompute = True

    elif libtcod.console_is_key_pressed(libtcod.KEY_RIGHT):
        try_move(game.player_one, (1, 0))
        game.fov_recompute = True

    else:
        return 'no-action'
示例#5
0
  def handle_keys(self):
    key = libtcod.console_wait_for_keypress(True)
    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 key.vk == libtcod.KEY_F1:
      if self.game_state == "not-playing":
        self.game_state = "playing"
        return "exit-debug-screen"
      self.game_state = "not-playing"
      return "debug-screen"

    if self.game_state != "playing":
      return

    if libtcod.console_is_key_pressed(libtcod.KEY_UP):
      self.move_player(0,-1)
    elif libtcod.console_is_key_pressed(libtcod.KEY_DOWN):
      self.move_player(0,1)
    elif libtcod.console_is_key_pressed(libtcod.KEY_LEFT):
      self.move_player(-1,0)
    elif libtcod.console_is_key_pressed(libtcod.KEY_RIGHT):
      self.move_player(1,0)
    else:
      return "didn't-move"
示例#6
0
def handle_keys(state):
  """Handles key inputs from the PLAYER.

  UP/DOWN/LEFT/RIGHT keys will move the PLAYER in their respective directions. Fullscreen mode is toggled with LAlt+ENTER; Game exit is triggered with ESCAPE.

  Accesses and modifies PLAYER, ZONE, and the FOV_RECOMPUTE flag.
  """

  # Fullscreen and Exit keys;
  # Use "True" arg for turn-based; omit for real-time
  if settings.TURN_BASED is True:
    key = libtcod.console_wait_for_keypress(True)
  else:
    key = libtcod.console_check_for_keypress()
  if key.vk == libtcod.KEY_ENTER and key.lalt:
    libtcod.console_set_fullscreen(not libtcod.console_is_fullscreen())
  elif key.vk == libtcod.KEY_ESCAPE:
    return 'exit'  # Exit game

  if state["status"] == 'playing':
    # Movement Keys
    if libtcod.console_is_key_pressed(libtcod.KEY_UP):
      player_move_or_attack(state, 0, -1)
    elif libtcod.console_is_key_pressed(libtcod.KEY_DOWN):
      player_move_or_attack(state, 0, 1)
    elif libtcod.console_is_key_pressed(libtcod.KEY_LEFT):
      player_move_or_attack(state, -1, 0)
    elif libtcod.console_is_key_pressed(libtcod.KEY_RIGHT):
      player_move_or_attack(state, 1, 0)
    else:
      print 'Hero takes no action'
      return 'no_action'
示例#7
0
def handle_keys():

  global playerx, playery

  #this is blocking, console_check_for_keypress() is nonblocking
  key = libtcod.console_wait_for_keypress(True)

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

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

  #movement keys
  # checked this way so you can just hold it down
  elif libtcod.console_is_key_pressed(libtcod.KEY_UP):
    playery -= 1
  elif libtcod.console_is_key_pressed(libtcod.KEY_DOWN):
    playery += 1
  elif libtcod.console_is_key_pressed(libtcod.KEY_LEFT):
    playerx -= 1
  elif libtcod.console_is_key_pressed(libtcod.KEY_RIGHT):
    playerx += 1
示例#8
0
def handle_keys():
  global player_x, player_y, m, turns
  #movement keys
  if libtcod.console_is_key_pressed(libtcod.KEY_UP):
    if libtcod.map_is_walkable(m, player_x, player_y - 1):
      player_y -= 1
      turns += 1
  elif libtcod.console_is_key_pressed(libtcod.KEY_DOWN):
    if libtcod.map_is_walkable(m, player_x, player_y + 1):
      player_y += 1
      turns += 1
  elif libtcod.console_is_key_pressed(libtcod.KEY_LEFT):
    if libtcod.map_is_walkable(m, player_x - 1, player_y):
      player_x -= 1
      turns += 1
  elif libtcod.console_is_key_pressed(libtcod.KEY_RIGHT):
    if libtcod.map_is_walkable(m, player_x + 1, player_y):
      player_x += 1
      turns += 1

  key = libtcod.Key()
  mouse = libtcod.Mouse()
  libtcod.sys_check_for_event(libtcod.EVENT_ANY, key, mouse)
  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_SPACE:
    end(player_x, player_y, mouse.cx, mouse.cy)
  elif key.vk == libtcod.KEY_ESCAPE:
    return True  #exit game
示例#9
0
def handle_input():
    global key, game_state

    if key.vk == libtcod.KEY_ENTER and key.lalt:

        #Alt+Enter: toggle full screen
        libtcod.console_set_fullscreen(not libtcod.console_is_fullscreen())

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

    if game_state == 'playing':
        # respond to movement keys
        if key.vk == libtcod.KEY_UP:
            return 'up'
        elif key.vk == libtcod.KEY_DOWN:
            return 'down'

        elif key.vk == libtcod.KEY_LEFT:
            window.activate_pane("-")

        elif key.vk == libtcod.KEY_RIGHT:
            window.activate_pane("+")

        elif key.vk == libtcod.KEY_SPACE:
            game_state = 'paused'
            message('Game Paused', libtcod.purple)

        else:
            return 'no action'
    elif game_state == 'paused':
        if key.vk == libtcod.KEY_SPACE:
            game_state = 'playing'
            message('Game Unpaused', libtcod.purple)
示例#10
0
def handle_keys():
  global playerx, playery

  key = libtcod.console_wait_for_keypress(True)

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

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

  #movement keys
  if libtcod.console_is_key_pressed(libtcod.KEY_UP):
    playery -= 1

  elif libtcod.console_is_key_pressed(libtcod.KEY_DOWN):
    playery += 1

  elif libtcod.console_is_key_pressed(libtcod.KEY_LEFT):
    playerx -= 1

  elif libtcod.console_is_key_pressed(libtcod.KEY_RIGHT):
    playerx += 1
示例#11
0
def handle_keys():
    global key
    global fov_recompute
    #   here we set the globals for the players position plus handle movement

    #use check for keypress for realtime


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

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

    if game_state == 'playing':

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

        elif libtcod.console_is_key_pressed(libtcod.KEY_DOWN):
            player_move_or_attack(0, 1)
            fov_recompute = True
        elif libtcod.console_is_key_pressed(libtcod.KEY_LEFT):
            player_move_or_attack(-1, 0)
            fov_recompute = True
        elif libtcod.console_is_key_pressed(libtcod.KEY_RIGHT):
            player_move_or_attack(1, 0)
            fov_recompute = True
        else:
            return 'didnt-take-turn'
示例#12
0
def player_card():
	#create an off-screen console that represents the card's window
	window = libtcod.console_new(20, 20)

	#print player stats
	libtcod.console_set_default_foreground(window, libtcod.white)
	libtcod.console_print_ex(window, 1, 1, libtcod.BKGND_NONE, libtcod.LEFT, 'STR:' + str(player.fighter.str))
	libtcod.console_print_ex(window, 1, 2, libtcod.BKGND_NONE, libtcod.LEFT, 'DEX:' + str(player.fighter.dex))
	libtcod.console_print_ex(window, 1, 3, libtcod.BKGND_NONE, libtcod.LEFT, 'CON:' + str(player.fighter.con))
	libtcod.console_print_ex(window, 1, 4, libtcod.BKGND_NONE, libtcod.LEFT, 'INT:' + str(player.fighter.int))
	libtcod.console_print_ex(window, 1, 5, libtcod.BKGND_NONE, libtcod.LEFT, 'FTH:' + str(player.fighter.fth))
	libtcod.console_print_ex(window, 1, 6, libtcod.BKGND_NONE, libtcod.LEFT, 'PER:' + str(player.fighter.per))

	libtcod.console_print_ex(window, 1, 9, libtcod.BKGND_NONE, libtcod.LEFT, 'Encumbrance: ')

	#blit the contents of "window" to the root console
	libtcod.console_blit(window, 0, 0, 20, 20, 0, 1, 7, 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
示例#13
0
def handleKeys(player):
    """
    Handles key presses from the user; including movement, exiting,
    and toggle fullscreen. It takes the player so that it can update
    the player's state.
    """
    # Our game is turnbased so we wait for a keypress every turn
    # before executing more code.
    key = libtcod.console_wait_for_keypress(True)

    if key.vk == libtcod.KEY_ENTER and key.lalt:
        # M-Return (Alt+Enter) toggles fullscreen
        libtcod.console_set_fullscreen(not
                                       libtcod.console_is_fullscreen())
        return False
    elif key.vk == libtcod.KEY_ESCAPE:
        return True # which we handle by exiting the game loop
    # Useful alias for a long fn name
    keyPressed = libtcod.console_is_key_pressed
    if keyPressed(libtcod.KEY_UP):
        player.move(0, -1)
        return False
    elif keyPressed(libtcod.KEY_DOWN):
        player.move(0, 1)
        return False
    elif keyPressed(libtcod.KEY_LEFT):
        player.move(-1, 0)
        return False
    elif keyPressed(libtcod.KEY_RIGHT):
        player.move(1, 0)
        return False
示例#14
0
文件: rl.py 项目: emersonp/roguelike
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) WITH 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)
  if key.vk == libtcod.KEY_ENTER and key.lalt:  #(special case) Alt+Enter: toggle fullscreen
    libtcod.console_set_fullscreen(not libtcod.console_is_fullscreen())
  # Convert the ASCII code to an index; if it corresponds to an option, return it.
  index = key.c - ord('a')
  if index >= 0 and index < len(options):
    return index
  return None
示例#15
0
def handle_keys():
    # global playerx,playery,fov_recompute,key

    # special keys
    if key.vk == libtcod.KEY_ENTER and key.lalt:
        # Alt+enter: FS toggler
        libtcod.console_set_fullscreen(not libtcod.console_is_fullscreen())
    elif key.vk == libtcod.KEY_ESCAPE:
        return "exit"  # GET OUT!!!!

    # Movement keys
    if game_state == "playing":
        if key.vk == libtcod.KEY_UP:
            player_move_or_attack(0, -1)
        elif key.vk == libtcod.KEY_DOWN:
            player_move_or_attack(0, 1)
        elif key.vk == libtcod.KEY_LEFT:
            player_move_or_attack(-1, 0)
        elif key.vk == libtcod.KEY_RIGHT:
            player_move_or_attack(1, 0)
        else:
            # Check for action keys
            key_char = chr(key.c)

            if key_char == "g":
                # Grab
                for object in objects:
                    if object.x == player.x and object.y == player.y and object.item:
                        object.item.pick_up()
                        break
            return "didnt-take-turn"
示例#16
0
文件: Tower.py 项目: HommeBarbu/PyRL
def handle_keys():
    global fov_recompute

    # 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

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

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

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

    elif libtcod.console_is_key_pressed(libtcod.KEY_RIGHT):
        player.move(1, 0)
        fov_recompute = True
示例#17
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
示例#18
0
def handle_keys():
    global fov_recompute, keys, mouse, msg_index, game_msgs
    
    if key.vk == libtcod.KEY_ENTER and key.lalt:
        libtcod.console_set_fullscreen(not libtcod.console_is_fullscreen())    
    elif key.vk == libtcod.KEY_ESCAPE:
        return 'exit'

    if game_state == 'playing':
        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_KP1:
            player_move_or_attack(-1,1)
        elif key.vk == libtcod.KEY_KP3:
            player_move_or_attack(1,1)
        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_KP5: # wait
            pass
示例#19
0
def handle_keys():
    global fov_recompute
 
    #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
 
    # Movement keys by arrows.
    # New for module 4: fov_recompute will force a recalculation every movement.
    if libtcod.console_is_key_pressed(libtcod.KEY_UP): #north
        player.move(0, -1)
        fov_recompute = True
  
    elif libtcod.console_is_key_pressed(libtcod.KEY_DOWN): #south
        player.move (0, 1)
        fov_recompute = True
  
    elif libtcod.console_is_key_pressed(libtcod.KEY_LEFT): #west
        player.move (-1, 0)
        fov_recompute = True
 
    elif libtcod.console_is_key_pressed(libtcod.KEY_RIGHT): #east
        player.move (1, 0)
        fov_recompute = True 
示例#20
0
def handle_keys():
    global playerx, playery, fov_recompute

    #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())
    elif key.vk == libtcod.KEY_ESCAPE:
        return "exit"

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

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

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

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

        else:
            return 'didnt-take-turn'
示例#21
0
def handle_keys():
    global keys

    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

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

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

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

        elif key.vk == libtcod.KEY_RIGHT:
            player_move_or_attack(1, 0)
        else:
            return "didnt-take-turn"
示例#22
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 'exit'  #exit game
 
    if game_state == 'playing':
        #movement keys
        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:
            return 'didnt-take-turn'
示例#23
0
    def key_input(self):
##============================================================================
        ##Menu Keyboard Input
        key = libtcod.console_check_for_keypress()  
        
        index = key.c - ord('a')
        
        if key.vk == libtcod.KEY_ENTER and key.lalt:
            libtcod.console_set_fullscreen(not libtcod.console_is_fullscreen())
            
        if key.vk == libtcod.KEY_ESCAPE:
            libtcod.console_check_for_keypress() 
            return 'close'
            
        if key:
            if index >= 0 and index < len(self.options):
                libtcod.console_check_for_keypress() 
                return index
            
        #if key.vk == libtcod.KEY_DOWN:
        #    current_pick = (current_pick +1) % len(self.options)
               
        #if key.vk == libtcod.KEY_UP:
        #    current_pick = (current_pick -1) % len(self.options)
               
        #if key.vk == libtcod.KEY_ENTER:
        #    return current_pick
        
        return -1
示例#24
0
文件: Menu.py 项目: Akhier/12Down
def Menu(header, options, width):
    if len(options) > 26:
        raise ValueError('Cannot have a menu with more than 26 options')
    header_height = libtcodpy.console_get_height_rect(0, 0, 0,
                                                      config.window_width,
                                                      config.window_height,
                                                      header)
    if header == '':
        header_height = 0
    height = len(options) + header_height
    menupanel = Panel(0, 0, width, height)
    menupanel.write_wrap_ex(0, 0, width, height, header, libtcodpy.LEFT)
    y = header_height
    letter_index = ord('a')
    for option_text in options:
        text = '(' + chr(letter_index) + ') ' + option_text
        menupanel.write(0, y, text)
        y += 1
        letter_index += 1

    x = config.window_width / 2 - width / 2
    y = config.window_height / 2 - height / 2
    menupanel.blit(xdst=x, ydst=y, bfade=0.7)

    config.gamewindow.flush
    key = libtcodpy.console_wait_for_keypress(True)

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

    index = key.c - ord('a')
    if index >= 0 and index < len(options):
        return index
    return None
示例#25
0
    def handle_keys(self):
        key = libtcod.console_wait_for_keypress(True)
        if key.vk == libtcod.KEY_ESCAPE:
            return 'exit'
        elif key.vk == libtcod.KEY_ENTER and libtcod.KEY_ALT:
            libtcod.console_set_fullscreen(not libtcod.console_is_fullscreen())
        elif key.vk == libtcod.KEY_CONTROL and ord('s'):
            libtcod.sys_save_screenshot()

        move = False
        if self.mode == 'playing':
            if libtcod.console_is_key_pressed(libtcod.KEY_UP):
                self.move_player((0, -1))
                move = True
                return 'move'
            elif libtcod.console_is_key_pressed(libtcod.KEY_DOWN):
                self.move_player((0, 1))
                move = True
                return 'move'
            elif libtcod.console_is_key_pressed(libtcod.KEY_LEFT):
                self.move_player((-1, 0))
                move = True
                return 'move'
            elif libtcod.console_is_key_pressed(libtcod.KEY_RIGHT):
                self.move_player((1, 0))
                move = True
                return 'move'
        if move:
            return 'move'
        else:
            return "didnt-take-turn"
示例#26
0
文件: main.py 项目: flappity/Dogelike
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
示例#27
0
文件: firstrl.py 项目: nrberens/Purge
def player_card():
	#create an off-screen console that represents the card's window
	window = libtcod.console_new(30, 20)
	
	#print player stats
	libtcod.console_set_foreground_color(window, libtcod.white)
	libtcod.console_print_left(window, 1, 1, libtcod.BKGND_NONE, 'Player')
	libtcod.console_print_left(window, 1, 2, libtcod.BKGND_NONE, 'Class: ' + player.stats.plclass)
	libtcod.console_print_left(window, 1, 3, libtcod.BKGND_NONE, 'STR:' + str(player.stats.str))
	libtcod.console_print_left(window, 1, 4, libtcod.BKGND_NONE, 'DEX:' + str(player.stats.dex))
	libtcod.console_print_left(window, 1, 5, libtcod.BKGND_NONE, 'CON:' + str(player.stats.con))
	libtcod.console_print_left(window, 1, 6, libtcod.BKGND_NONE, 'INT:' + str(player.stats.int))
	libtcod.console_print_left(window, 1, 7, libtcod.BKGND_NONE, 'FTH:' + str(player.stats.fth))
	libtcod.console_print_left(window, 1, 8, libtcod.BKGND_NONE, 'PER:' + str(player.stats.per))
	
	libtcod.console_print_left(window, 1, 10, libtcod.BKGND_NONE, 'AC: ' + str(player.stats.ac))
	libtcod.console_print_left(window, 1, 11, libtcod.BKGND_NONE, 'Encumbrance: ')
	
	libtcod.console_print_left(window, 1, 13, libtcod.BKGND_NONE, 'Hit %: ' + str((20-player.stats.hitdie)*5))
	libtcod.console_print_left(window, 1, 14, libtcod.BKGND_NONE, 'Damage: ' + str(player.stats.mindmg) + ' - ' + str(player.stats.maxdmg))
	
	#blit the contents of "window" to the root console
	libtcod.console_blit(window, 0, 0, 30, 20, 0, 1, 1, 1.0, 0.7)
	
	#present the root console to the player and wait for a key-press
	libtcod.console_flush()
	key = libtcod.console_wait_for_keypress(True)
	
	if key.vk == libtcod.KEY_ENTER and key.lalt:  #(special case) Alt+Enter: toggle fullscreen
		libtcod.console_set_fullscreen(not libtcod.console_is_fullscreen())
	
	return None
示例#28
0
文件: input.py 项目: koeida/rowanrpg
def handle_keys(key,currentArea):
    shouldQuit = False
    currentArea = copy.deepcopy(currentArea)
    p = currentArea.entities[0]

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

    newX = p.x
    newY = p.y
    #movement keys
    if libtcod.console_is_key_pressed(libtcod.KEY_UP):
        newY -= 1
    elif libtcod.console_is_key_pressed(libtcod.KEY_DOWN):
        newY += 1
    elif libtcod.console_is_key_pressed(libtcod.KEY_LEFT):
        newX -= 1
    elif libtcod.console_is_key_pressed(libtcod.KEY_RIGHT):
        newX += 1
    else:
        k = chr(key.c)        

    if not bump(newX,newY,p.id,currentArea):
        currentArea.map[p.y][p.x] = currentArea.map[p.y][p.x]._replace(changed = True)
        currentArea.entities[0] = p._replace(x = newX,y = newY)

    return [shouldQuit,currentArea]
示例#29
0
def handle_keys():
	global playerx, playery
	global fov_recompute
	
	key = libtcod.console_wait_for_keypress(True)
	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 the game
		return True
	
	#movement keys
	if libtcod.console_is_key_pressed(libtcod.KEY_UP):
		player.move(0, -1)
		fov_recompute = True
		#playery -= 1
		
	elif libtcod.console_is_key_pressed(libtcod.KEY_DOWN):
		player.move(0, 1)
		fov_recompute = True
		#playery += 1
		
	elif libtcod.console_is_key_pressed(libtcod.KEY_LEFT):
		player.move(-1, 0)
		fov_recompute = True
		#playerx -= 1
		
	elif libtcod.console_is_key_pressed(libtcod.KEY_RIGHT):
		player.move(1, 0)
		fov_recompute = True
示例#30
0
def handle_keys():
    global playerx, playery
 
    #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
 
    # Movement keys by arrows.
    if libtcod.console_is_key_pressed(libtcod.KEY_UP): #north
        player.move(0, -1)
  
    elif libtcod.console_is_key_pressed(libtcod.KEY_DOWN): #south
        player.move (0, 1)
  
    elif libtcod.console_is_key_pressed(libtcod.KEY_LEFT): #west
        player.move (-1, 0)
 
    elif libtcod.console_is_key_pressed(libtcod.KEY_RIGHT): #east
        player.move (1, 0) 
示例#31
0
def main():
    screen_width = 80
    screen_height = 50

    player = Entity(int(screen_width / 2), int(screen_height / 2), '@',
                    libtcod.white)
    npc = Entity(int(screen_width / 2 - 5), 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)

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

    while not libtcod.console_is_window_closed():
        libtcod.sys_check_for_event(libtcod.EVENT_KEY_PRESS, key, mouse)

        libtcod.console_set_default_foreground(con, libtcod.white)
        libtcod.console_put_char(con, player_x, player_y, '@',
                                 libtcod.BKGND_NONE)
        libtcod.console_blit(con, 0, 0, screen_width, screen_height, 0, 0, 0)
        libtcod.console_flush()

        libtcod.console_put_char(con, player_x, player_y, ' ',
                                 libtcod.BKGND_NONE)

        action = handle_keys(key)

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

        if move:
            dx, dy = move
            player.move(dx, dy)

        if exit:
            return True

        if fullscreen:
            libtcod.console_set_fullscreen(not libtcod.console_is_fullscreen())
示例#32
0
def handle_keys():
    global game_state

    #    key = libtcod.console_check_for_keypress() # real-time
    key = libtcod.console_check_for_keypress(libtcod.KEY_PRESSED)  # 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
    if game_state == 'playing':
        if key.vk == libtcod.KEY_UP:
            player_move_or_attack(0, -1)
        elif key.vk == libtcod.KEY_DOWN:
            player_move_or_attack(0, 1)
        elif key.vk == libtcod.KEY_LEFT:
            player_move_or_attack(-1, 0)
        elif key.vk == libtcod.KEY_RIGHT:
            player_move_or_attack(1, 0)
        else:
            # test for other keys
            key_char = chr(key.c)

            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 object.item:
                        object.item.pick_up()
                        break
            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 == 'i':
                # show the 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()

            return 'didnt-take-turn'
示例#33
0
def main():
    screen_width = 80
    screen_height = 50

    player = Entity(screen_width // 2, screen_height // 2, '@', libtcod.white)
    npc = Entity(screen_width // 2 - 5, 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',
                              False)

    con = libtcod.console_new(screen_width, screen_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, screen_width, screen_height)
        libtcod.console_flush()
        clear_all(con, entities)

        action = handle_keys(key)
        move = action.get(
            'move'
        )  #returns relative coordinates as a tuple if the action was 'move'
        exit_game = action.get('exit')  #gets True if action was 'exit'
        fullscreen = action.get(
            'fullscreen')  #gets True if action was 'fullscreen'

        if move:
            dx, dy = move
            #            player_x += dx
            #            player_y += dy
            player.move(dx, dy)


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

        if fullscreen:
            libtcod.console_set_fullscreen(not libtcod.console_is_fullscreen())
示例#34
0
def handle_keys():
    global playerx, playery
    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())
    elif key.vk == libtcod.KEY_ESCAPE:
        return True
    if libtcod.console_is_key_pressed(libtcod.KEY_UP):
        playery -= 1
    elif libtcod.console_is_key_pressed(libtcod.KEY_DOWN):
        playery += 1
    elif libtcod.console_is_key_pressed(libtcod.KEY_LEFT):
        playerx -= 1
    elif libtcod.console_is_key_pressed(libtcod.KEY_RIGHT):
        playerx += 1
示例#35
0
    def run(self):
        while not libtcod.console_is_window_closed():
            self.render()
            libtcod.console_flush()

            key = libtcod.Key()
            mouse = libtcod.Mouse()
            event = libtcod.sys_wait_for_event(1, key, mouse, True)

            if key.vk == libtcod.KEY_ENTER and key.lalt:
                libtcod.console_set_fullscreen(not libtcod.console_is_fullscreen())                
            else:
                action = self.screens[-1].handle_keys(key.vk)
                if action == 'exit':
                    return action
示例#36
0
文件: vault.py 项目: brewerdave/vault
def handle_input(player):
    ui.poll()

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

    elif ui.key.vk == libtcodpy.KEY_ESCAPE:
        return 'exit'

    if player.game_state == 'playing':

        if ui.key.vk == libtcodpy.KEY_UP or chr(ui.key.c) == 'k':
            player_move_or_attack(player, 0, -1)

        elif ui.key.vk == libtcodpy.KEY_DOWN or chr(ui.key.c) == 'j':
            player_move_or_attack(player, 0, 1)

        elif ui.key.vk == libtcodpy.KEY_LEFT or chr(ui.key.c) == 'h':
            player_move_or_attack(player, -1, 0)

        elif ui.key.vk == libtcodpy.KEY_RIGHT or chr(ui.key.c) == 'l':
            player_move_or_attack(player, 1, 0)

        elif chr(ui.key.c) == 'u':
            player_move_or_attack(player, 1, -1)

        elif chr(ui.key.c) == 'y':
            player_move_or_attack(player, -1, -1)

        elif chr(ui.key.c) == 'n':
            player_move_or_attack(player, 1, 1)

        elif chr(ui.key.c) == 'b':
            player_move_or_attack(player, -1, 1)

        else:
            if chr(ui.key.c) == 'g':
                for entity in player.current_map.map_entities:
                    if entity.x_pos == player.x_pos and entity.y_pos == player.y_pos and entity.item:
                        actions.pick_up_item(player, entity)
                        break

            if chr(ui.key.c) == 'i':
                chosen_item = inventory_menu(player, 'Inventory')
                if chosen_item is not None:
                    actions.use(player, chosen_item.owner)

            return 'didnt-take-turn'
示例#37
0
文件: graph.py 项目: dongzeyuan/bbt
def handle_keys():
    global player_x, player_y
    key = tcod.console_check_for_keypress()
    if key.vk == tcod.KEY_ENTER and tcod.KEY_ALT:
        tcod.console_set_fullscreen(not tcod.console_is_fullscreen())
    elif key.vk == tcod.KEY_ESCAPE:
        return True

    if tcod.console_is_key_pressed(tcod.KEY_UP):
        player_y = player_y - 1
    elif tcod.console_is_key_pressed(tcod.KEY_DOWN):
        player_y = player_y + 1
    elif tcod.console_is_key_pressed(tcod.KEY_LEFT):
        player_x = player_x - 1
    elif tcod.console_is_key_pressed(tcod.KEY_RIGHT):
        player_x = player_x + 1
示例#38
0
def menu(header, options, width):

    if len(options) > 26:
        raise ValueError('Cannot have a menu with more than 26 options')
    #calculate height for the header after auto-wrap and one line per option
    header_height = libtcod.console_height_left_rect(con, 0, 0, width,
                                                     SCREEN_HEIGHT, header)
    if header == '':
        header_height = 0
    height = len(options) + header_height

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

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

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

    #Blit the contents of "window" to the root console
    x = SCREEN_WIDTH / 2 - width / 2
    y = SCREEN_HEIGHT / 2 - height / 2
    libtcod.console_blit(window, 0, 0, width, height, 0, x, y, 1.0, 0.7)

    #Present the player with the root console and wait for a key-press
    libtcod.console_flush()
    key = libtcod.console_wait_for_keypress(True)

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

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

    return None
示例#39
0
def handle_keys():
    global fov_recompute
    # realtime
    # key = libtcod.console_check_for_keypress()
    # turn based
    #key = libtcod.console_wait_for_keypress(True)
    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:
        return PlayerActions.EXIT  # exit game

    if game_state == GameStates.PLAYING:
        # movement keys
        if key.vk == libtcod.KEY_UP:
            player_move_or_attack(0, -1)
            fov_recompute = True

        elif key.vk == libtcod.KEY_DOWN:
            player_move_or_attack(0, 1)
            fov_recompute = True

        elif key.vk == libtcod.KEY_LEFT:
            player_move_or_attack(-1, 0)
            fov_recompute = True

        elif key.vk == libtcod.KEY_RIGHT:
            player_move_or_attack(1, 0)
            fov_recompute = True
        else:
            key_char = chr(key.c)
            if key_char == 'g':
                for gameObject in objects:
                    if gameObject.x == player.x and gameObject.y and gameObject.item:
                        gameObject.item.pick_up()
                        break
            if key_char == 'i':
                #show the 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()

            return PlayerActions.NO_MOVE
示例#40
0
def menu(header, options, width):
    if len(options) > MAX_OPTIONS:
        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,
                                                    g.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 = g.SCREEN_WIDTH / 2 - width / 2
    y = g.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()
    g.key = libtcod.console_wait_for_keypress(True)

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

    index = g.key.c - ord('a')
    if 0 <= index < len(options):
        return index
    return None
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)
    # 打印 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
    # 打印所有项目
    # 原理 : 打印一个循环,第一个选项的 Y 坐标位于页眉的正下方;我们打印该选项的文本, 并增加它。
    # 然后从字母 A 开始, 每次递增, 以在选项的文本旁边显示它。函数返回字母 A 的 ASCII 码;
    # 然后, 可以用来增加它来获取其余字母的代码。

    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)
    # 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
示例#42
0
文件: main.py 项目: dizzylee/MoonGame
def handle_keys():
    global fov_recompute

    key = libtcod.console_check_for_keypress()
    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

    if game_state == 'playing':
        #if player.wait > 0:
        #player.wait -= 1
        #else:
        #Movement keys
        if libtcod.console_is_key_pressed(libtcod.KEY_UP):
            player.move(0, -1)
            fov_recompute = True
        elif libtcod.console_is_key_pressed(libtcod.KEY_DOWN):
            player.move(0, 1)
            fov_recompute = True
        elif libtcod.console_is_key_pressed(libtcod.KEY_LEFT):
            player.move(-1, 0)
            fov_recompute = True
        elif libtcod.console_is_key_pressed(libtcod.KEY_RIGHT):
            player.move(1, 0)
            fov_recompute = True
        else:
            key_char = chr(key.c)

            if key_char == 'g':
                for object in objects:
                    if object.x == player.x and object.y == player.y and object.item:
                        object.item.pick_up()
                        break
            elif key_char == 'i':
                chosen_item = inventory_menu(
                    'Press the key next to an item to use it, or any other key to cancel\n'
                )
                if chosen_item is not None:
                    chosen_item.use()
            elif key_char == 'd':
                chosen_item = inventory_menu(
                    'Press the key next to an item to drop it, or any other key to cancel\n'
                )
                if chosen_item is not None:
                    chosen_item.drop()
示例#43
0
def session_console():
    libtcodpy.console_set_custom_font(FONT_FILE)
    console = libtcodpy.console_init_root(WIDTH, HEIGHT, TITLE, FULLSCREEN, RENDERER)

    assert libtcodpy.console_get_width(console) == WIDTH
    assert libtcodpy.console_get_height(console) == HEIGHT
    assert libtcodpy.console_is_fullscreen() == FULLSCREEN
    libtcodpy.console_set_window_title(TITLE)
    assert not libtcodpy.console_is_window_closed()

    libtcodpy.sys_get_current_resolution()
    libtcodpy.sys_get_char_size()
    libtcodpy.sys_set_renderer(RENDERER)
    libtcodpy.sys_get_renderer()

    yield console
    libtcodpy.console_delete(console)
def handle_keys():
    key = libtcod.console_check_for_keypress()

    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  #Escape: Exits the game
    # Movement keys
    if libtcod.console_is_key_pressed(libtcod.KEY_UP):
        player.move(0, -1)
    elif libtcod.console_is_key_pressed(libtcod.KEY_DOWN):
        player.move(0, 1)
    elif libtcod.console_is_key_pressed(libtcod.KEY_LEFT):
        player.move(-1, 0)
    elif libtcod.console_is_key_pressed(libtcod.KEY_RIGHT):
        player.move(1, 0)
示例#45
0
def main():
    screen_width = 80
    screen_height = 50

    player_x = int(screen_width / 2)
    player_y = int(screen_height / 2)

    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)

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

    while not libtcod.console_is_window_closed():
        libtcod.sys_check_for_event(libtcod.EVENT_KEY_PRESS, key, mouse)

        libtcod.console_set_default_foreground(con, libtcod.white)
        libtcod.console_put_char(con, player_x, player_y, '@',
                                 libtcod.BKGND_NONE)
        libtcod.console_blit(con, 0, 0, screen_width, screen_height, 0, 0, 0)
        libtcod.console_flush()

        libtcod.console_put_char(con, player_x, player_y, ' ',
                                 libtcod.BKGND_NONE)

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

        if move:
            dx, dy = move
            player_x += dx
            player_y += dy

        if exit:
            return True

        if fullscreen:
            libtcod.console_set_fullscreen(not libtcod.console_is_fullscreen())
示例#46
0
def handle_keys():
    global fov_recompute, keys

    #key = libtcod.console_check_for_keypress() # real time
    #key = libtcod.console_wait_for_keypress(True) # 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
    if game_state == 'playing':
        #movement keys
        if key.vk == libtcod.KEY_UP or key.c == ord('w'):
            #player.move(0, -1)
            player_move_or_attack(0, -1)
            #fov_recompute = True
        elif key.vk == libtcod.KEY_DOWN or key.c == ord('s'):
            player_move_or_attack(0, 1)
            #player.move(0, 1)
            #fov_recompute = True
        elif key.vk == libtcod.KEY_LEFT or key.c == ord('a'):
            player_move_or_attack(-1, 0)
            #player.move(-1, 0)
            #fov_recompute = True
        elif key.vk == libtcod.KEY_RIGHT or key.c == ord('d'):
            player_move_or_attack(1, 0)
            #player.move(1, 0)
            #fov_recompute = True
        else:
            # Test for other keys
            key_char = chr(key.c)

            if key_char == 'g':
                # Pick up an item
                for object in objects:  # Look for an item in the players tile
                    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
                chosen_item = inventory_menu(
                    "Press the key next to an item to use it, or any other key to cancel.\n"
                )
                if chosen_item is not None:
                    chosen_item.use()
            return 'didnt-take-turn'
示例#47
0
def handle_keys():
    #key = TCOD.console_check_for_keypress()
    key = TCOD.console_wait_for_keypress(True)

    if key.vk == TCOD.KEY_ENTER and key.lalt:
        TCOD.console_set_fullscreen(not TCOD.console_is_fullscreen())
    elif key.vk == TCOD.KEY_ESCAPE:
        return True

    if TCOD.console_is_key_pressed(TCOD.KEY_UP):
        player.move(0, -1)
    elif TCOD.console_is_key_pressed(TCOD.KEY_DOWN):
        player.move(0, 1)
    elif TCOD.console_is_key_pressed(TCOD.KEY_LEFT):
        player.move(-1, 0)
    elif TCOD.console_is_key_pressed(TCOD.KEY_RIGHT):
        player.move(1, 0)
示例#48
0
def input_controller(game_state):
    tcod.sys_check_for_event(tcod.EVENT_KEY_PRESS | tcod.EVENT_MOUSE,
                             settings.key, settings.mouse)
    if settings.key.vk == tcod.KEY_ESCAPE:
        return 'exit'
    elif settings.key.vk == tcod.KEY_ENTER and settings.key.lalt:
        tcod.console_set_fullscreen(not tcod.console_is_fullscreen())

    if game_state == 'playing':
        player_action = playing_input()
        if type(player_action) is tuple:
            player_move_or_attack(*player_action)
            end_player_turn()
    elif game_state == 'looking':
        looking_input('info', handle_direction_keys())
    elif game_state == 'running':
        run_in_direction(settings.running_direction)
示例#49
0
文件: UI.py 项目: Lemmily/py-shopRL
    def menu(self, header, options, width):
        global keys

        if len(options) > 26:
            raise ValueError("cannot have a menu with more than 26 options")
        header_height = libtcod.console_get_height_rect(
            self.con, 0, 0, width, R.SCREEN_HEIGHT, header)
        if header_height == "":
            header_height = 0
        height = len(options) + header_height

        #now creates an off screen console that represents the menu windwo.
        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)

        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 = R.SCREEN_WIDTH / 2 - width / 2
        y = R.SCREEN_HEIGHT / 2 - height / 2
        libtcod.console_blit(window, 0, 0, width, height, 0, x, y, 1.0, 0.7)

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

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

            if key.vk == libtcod.KEY_ESCAPE or key.vk == libtcod.KEY_BACKSPACE:
                return None  #exit inventory

            index = key.c - ord("a")
            if index >= 0 and index < len(options): return index
示例#50
0
def main():
    screen_width = 80
    screen_height = 50

    player_x = int(screen_width / 2)
    player_y = int(screen_height / 2)

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

    tcod.console_init_root(screen_width, screen_height,
                           'libtcod tutorial revised', False)

    con = tcod.console_new(screen_width, screen_height)

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

    while not tcod.console_is_window_closed():
        tcod.sys_check_for_event(tcod.EVENT_KEY_PRESS, key, mouse)

        tcod.console_set_default_foreground(con, tcod.white)
        tcod.console_put_char(con, player_x, player_y, '@', tcod.BKGND_NONE)
        tcod.console_blit(con, 0, 0, screen_width, screen_height, 0, 0, 0)
        tcod.console_flush()

        # Erase old @
        tcod.console_put_char(con, player_x, player_y, ' ', tcod.BKGND_NONE)

        action = handle_keys(key)

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

        if move:
            dx, dy = move
            player_x += dx
            player_y += dy

        if exit:
            return True

        if fullscreen:
            tcod.console_set_fullscreen(not tcod.console_is_fullscreen())
示例#51
0
def menu(header, options, width):
    if len(options) > 26:
        raise ValueError('Cannot have a menu with more than 26 options.')

    # Calculate total heigh 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)
    # Check for no 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)

    if key.vk == libtcod.KEY_ENTER and key.lalt:  # Special case to toggle fullscreen while a menu is up.
        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
示例#52
0
def main():
    screen_width = 80
    screen_height = 50

    player_x = int(screen_width / 2)
    player_y = int(screen_height / 2)

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

    libtcod.console_set_custom_font(
        'arial10x10.png',
        libtcod.FONT_TYPE_GREYSCALE | libtcod.FONT_LAYOUT_TCOD
    )  #Takes the font from the image file and uses it in the console
    libtcod.console_init_root(
        screen_width, screen_height, "rougelike", False
    )  #initalizes console with size and name (fullscreen set to false)
    con = libtcod.console_new(
        screen_width, screen_height)  #lets me make new consoles later on

    while not libtcod.console_is_window_closed():
        libtcod.console_set_default_foreground(con, libtcod.white)
        libtcod.console_put_char(
            con, player_x, player_y, '@', libtcod.BKGND_NONE
        )  #writes the character at the cooridinates (1, 1)
        libtcod.console_blit(con, 0, 0, screen_width, screen_height, 0, 0, 0)
        libtcod.console_flush()  #show the console
        libtcod.console_put_char(con, player_x, player_y, ' ',
                                 libtcod.BKGND_NONE)

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

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

        if move:  #moves the player
            dx, dy = move
            player_x += dx
            player_y += dy
        if exit:  #exits the game
            return True
        if fullscreen:  #fullscreen
            libtcod.console_set_fullscreen(not libtcod.console_is_fullscreen())
示例#53
0
    def menu(self, header, options, width):
        #check to see if there's more than 26 options
        if len(options) > 26: raise ValueError('Cannot have a menu with more than 26 options')

        #calculate the total height for the header (after auto-wrap) and one line per option
        if header == '':
            header_height = 0
        else:
            header_height = libtcod.console_get_height_rect(self.con, 0, 0, width, Screen.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 the 'window' to the root console
        x = Screen.SCREEN_WIDTH / 2 - width / 2
        y = Screen.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)

        #check if they user wants to go full screen
        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
示例#54
0
    def handle_keys(self):
        turnTaken = False

        key = libtcod.console_wait_for_keypress(True)

        # Alt+Enter: toggle fullscreen
        if key.vk == libtcod.KEY_ENTER and (key.lalt or key.ralt):
            libtcod.console_set_fullscreen(not libtcod.console_is_fullscreen())
        # Exit game
        elif key.vk == libtcod.KEY_ESCAPE:
            self.exit = True  #exit game
        # Pass Turn
        elif key.vk == libtcod.KEY_SPACE:
            turnTaken = True
            self.player.move(dx=0, dy=0)
        elif key.vk == libtcod.KEY_CHAR:
            # Timeframe targeting
            if key.c == ord('q') or key.c == ord('Q'):
                self.continuum.changetargetTimeframeIndex(1)
            elif key.c == ord('e') or key.c == ord('E'):
                self.continuum.changetargetTimeframeIndex(-1)
            # MOVEMENT
            elif key.c == ord('w') or key.c == ord('W') or \
            libtcod.console_is_key_pressed(libtcod.KEY_UP):
                turnTaken = True
                self.player.move(dx=0, dy=-1)  #player y -= 1
            elif key.c == ord('s') or key.c == ord('S') or \
            libtcod.console_is_key_pressed(libtcod.KEY_DOWN):
                turnTaken = True
                self.player.move(dx=0, dy=1)  #player y += 1
            elif key.c == ord('a') or key.c == ord('A') or \
            libtcod.console_is_key_pressed(libtcod.KEY_LEFT):
                turnTaken = True
                self.player.move(dx=-1, dy=0)  #player x -= 1
            elif key.c == ord('d') or  key.c == ord('D') or \
            libtcod.console_is_key_pressed(libtcod.KEY_RIGHT):
                turnTaken = True
                self.player.move(dx=1, dy=0)  #player x += 1
            # Debug keys
            elif key.c == ord('i') or key.c == ord('I'):
                self.debug = not self.debug
            elif key.c == ord('p') or key.c == ord('P'):
                turnTaken = True
                self.player.move(dx=-100, dy=-100)
        return turnTaken
示例#55
0
def handle_keys():
    global playerx, playery

    key = libtcod.console_check_for_keypress()
    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

    if libtcod.console_is_key_pressed(libtcod.KEY_UP):
        player.move(0, -1)
    elif libtcod.console_is_key_pressed(libtcod.KEY_DOWN):
        player.move(0, 1)
    elif libtcod.console_is_key_pressed(libtcod.KEY_LEFT):
        player.move(-1, 0)
    elif libtcod.console_is_key_pressed(libtcod.KEY_RIGHT):
        player.move(1, 0)
示例#56
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

    if libtcod.console_is_key_pressed(libtcod.KEY_UP):
        world.hero.move(0, -1)
    elif libtcod.console_is_key_pressed(libtcod.KEY_DOWN):
        world.hero.move(0, 1)
    if libtcod.console_is_key_pressed(libtcod.KEY_LEFT):
        world.hero.move(-1, 0)
    elif libtcod.console_is_key_pressed(libtcod.KEY_RIGHT):
        world.hero.move(1, 0)
示例#57
0
def checkKeys():
    #key = lcod.console_check_for_keypress()
    key = lcod.console_wait_for_keypress(True)
    if key.vk == lcod.KEY_ENTER and key.lalt:
        # alt+enter to toggle fullscreen
        lcod.console_set_fullscreen(not lcod.console_is_fullscreen()) # console.is_fullscreen return true if fullscreen, false otherwise
    elif key.vk == lcod.KEY_ESCAPE:
        return True
    
    # movement keys
    if lcod.console_is_key_pressed(lcod.KEY_UP):
        player.move(0, -1)
    elif lcod.console_is_key_pressed(lcod.KEY_DOWN):
        player.move(0, 1)
    elif lcod.console_is_key_pressed(lcod.KEY_LEFT):
        player.move(-1, 0)
    elif lcod.console_is_key_pressed(lcod.KEY_RIGHT):
        player.move(1, 0)
示例#58
0
def handle_keys():
    global playerx, playery, SCREEN_WIDTH, SCREEN_HEIGHT, directionx, directiony
 
    key = libtcod.console_check_for_keypress()  #real-time
 
    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
 
    #movement keys
    if libtcod.console_is_key_pressed(libtcod.KEY_UP):
        playery -= 1
        directionx = 0
        directiony = -1
 
    elif libtcod.console_is_key_pressed(libtcod.KEY_DOWN):
        playery += 1
        directionx = 0
        directiony = 1
 
    elif libtcod.console_is_key_pressed(libtcod.KEY_LEFT):
        playerx -= 1
        directionx = -1
        directiony = 0
        
    elif libtcod.console_is_key_pressed(libtcod.KEY_RIGHT):
        playerx += 1
        directionx = 1
        directiony = 0

    if playerx > SCREEN_WIDTH - 1:
        playerx = SCREEN_WIDTH -1

    if playerx < 0:
        playerx = 0

    if playery > SCREEN_HEIGHT -1:
        playery = SCREEN_HEIGHT -1

    if playery < 0:
        playery = 0
示例#59
0
def menu(header, options, width, Game):
    if len(options) > data.MAX_NUM_ITEMS: 
        message('Cannot have a menu with more than ' + str(data.MAX_NUM_ITEMS) + ' options.', Game)

    #calculate total height of the header (after auto-wrap) and one line per option
    header_height = libtcod.console_get_height_rect(Game.con, 0, 0, width, data.SCREEN_HEIGHT, header)
    if header == '':
        header_height = 0
    height = len(options) + header_height

    #create 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 contents of window to root console
    x = data.SCREEN_WIDTH / 2 - width / 2
    y = data.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 keypress
    libtcod.console_flush()
    key = libtcod.console_wait_for_keypress(True)

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

    #convert ASCII code to an index. if it's valid, return it
    index = key.c - ord('a')
    if index >= 0 and index < len(options):
        return index
    else:
        return None
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 (after auto-wrap) and one line per option
    header_height = libtcod.console_get_height_rect(con_map, 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 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)
    libtcod.console_flush()

    key = libtcod.console_wait_for_keypress(True)
    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 an option, return it
    index = key.c - ord('a')
    if index >= 0 and index < len(options): return index
    return None