daily pastebin goal
41%
SHARE
TWEET

Untitled

a guest Jun 13th, 2018 61 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import libtcodpy as libtcod
  2.  
  3. ####################
  4. #  Normal values   #
  5. ####################
  6.  
  7. SCREEN_WIDTH = 80
  8. SCREEN_HEIGHT = 50
  9. LIMIT_FPS = 20
  10.  
  11. libtcod.console_set_custom_font('arial10x10.png', libtcod.FONT_TYPE_GREYSCALE | libtcod.FONT_LAYOUT_TCOD)
  12.  
  13. libtcod.console_init_root(SCREEN_WIDTH, SCREEN_HEIGHT, 'python/libtcod tutorial', False)
  14.  
  15. while not libtcod.console_is_window_closed():
  16.  
  17.     libtcod.console_set_foreground_color(0, libtcod.white)
  18.    
  19.     libtcod.console_print_left(0, 1, 1, libtcod.BKGND_NONE, '@'
  20.    
  21.     libtcod.console_flush()
  22.  
  23. playerx = SCREEN_WIDTH/2
  24. playery = SCREEN_HEIGHT/2
  25.  
  26. def handle_keys():
  27.     global playerx, playery
  28.    
  29.    
  30.     if libtcod.console_is_key_pressed(libtcod.KEY_UP):
  31.         playery -= 1
  32.    
  33.     elif libtcod.console_is_key_pressed(libtcod.KEY_DOWN):
  34.         playery+= 1
  35.    
  36.     elif libtcod.console_is_key_pressed(libtcod.KEY_LEFT):
  37.         playerx -= 1
  38.    
  39.     elif libtcod.console_is_key_pressed(libtcod.KEY_RIGHT):
  40.         playerx += 1
  41.    
  42.     key = libtcod.console_check_for_keypress()
  43.     if key.vk == libtcod.KEY_ENTER and key.lalt:
  44.     libtcod.console_set_fullscreen (not libtcod.console_is_fullscree())
  45.    
  46.     elif key.vk == libtcod.KEY_ESCAPE:
  47.         return True
  48.    
  49.     key = libtcod.console_wait_for_keypress(True)
  50.    
  51.     libtcod.console_set_foreground_color(0, libtcod.white)
  52.     libtcod.console_print_left(0,, playerx, playery, libtcod.BKGND_NONE, '@')
  53.    
  54.     libtcod.console_flush()
  55.    
  56.     exit = handle_keys()
  57.     if exit:
  58.         break
  59.    
  60.     libtcod.console_print_left(0, playerx, playery, libtcod.BKGND_NONE, ' ')
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top