HaxiDenti

Untitled

Mar 1st, 2021
704
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import tcod as t
  2.  
  3. screen_width = 40
  4. screen_height = 20
  5.  
  6. # Peripherals
  7. key = t.Key()
  8. mouse = t.Mouse()
  9.  
  10. # Player
  11. class Player:
  12.     x = 10
  13.     y = 5
  14.  
  15.     def move(self, x, y):
  16.         if not obstacle(x, y):
  17.             self.x = x
  18.             self.y = y
  19.  
  20. MAP = [
  21.     "           ##################### ",
  22.     "############                  ###",
  23.     "#                       T      ##",
  24.     "#    T                          #",
  25.     "#             T                 #",
  26.     "#                               #",
  27.     "#        T           T          #",
  28.     "##             T                #",
  29.     " ##                        ######",
  30.     "  ##########################     "
  31. ]
  32.  
  33. def obstacle(x, y):
  34.     if y > len(MAP) or y < 0:
  35.         return True
  36.     if x > len(MAP[0]) or x < 0:
  37.         return True
  38.     el = MAP[y][x]
  39.     if el == ' ' or el == '\t' or el == '.':
  40.         return False
  41.     else:
  42.         return True
  43.  
  44. def set_map(x, y, c):
  45.     if y > len(MAP) or y < 0:
  46.         return
  47.     if x > len(MAP[0]) or x < 0:
  48.         return
  49.     MAP[y] = MAP[y][:x] + c + MAP[y][x+1:]
  50.  
  51. def map_draw():
  52.     for y in range(len(MAP)):
  53.         for x in range(len(MAP[0])):
  54.             cchar(x, y, MAP[y][x])
  55.  
  56. # Game - My Game
  57. def game():
  58.     player = Player()
  59.  
  60.     # Console
  61.     t.console_init_root(screen_width, screen_height, "My Game")
  62.    
  63.     while not t.console_is_window_closed():
  64.         t.console_set_default_foreground(0, t.white)
  65.         t.sys_check_for_event(t.EVENT_KEY_PRESS, key, mouse)
  66.  
  67.         # Draw player
  68.         map_draw()
  69.         cchar(player.x, player.y, '@')
  70.  
  71.         t.console_flush()
  72.         cclear()
  73.  
  74.         if key.vk == t.KEY_ESCAPE:
  75.             return
  76.         if key.vk == t.KEY_UP:
  77.             player.move(player.x, player.y-1)
  78.         elif key.vk == t.KEY_DOWN:
  79.             player.move(player.x, player.y+1)
  80.         if key.vk == t.KEY_LEFT:
  81.             player.move(player.x-1, player.y)
  82.         elif key.vk == t.KEY_RIGHT:
  83.             player.move(player.x+1, player.y)
  84.         if key.vk == t.KEY_SPACE:
  85.             set_map(player.x, player.y, '.')
  86.         if key.vk == t.KEY_CONTROL:
  87.             set_map(player.x, player.y, 'o')
  88.         if key.vk == t.KEY_1:
  89.             set_map(player.x, player.y, ' ')
  90.             set_map(player.x-1, player.y, ' ')
  91.             set_map(player.x+1, player.y, ' ')
  92.             set_map(player.x, player.y-1, ' ')
  93.             set_map(player.x, player.y+1, ' ')
  94.  
  95. def cchar(x, y, c):
  96.     t.console_put_char(0, x, y, ord(c))
  97.  
  98. def cprint(x, y, txt):
  99.     t.console_print(0, x, y, txt)
  100.  
  101. def cclear():
  102.     t.console_clear(0)
  103.  
  104. if __name__ == '__main__':
  105.     game()
RAW Paste Data

Adblocker detected! Please consider disabling it...

We've detected AdBlock Plus or some other adblocking software preventing Pastebin.com from fully loading.

We don't have any obnoxious sound, or popup ads, we actively block these annoying types of ads!

Please add Pastebin.com to your ad blocker whitelist or disable your adblocking software.

×