Advertisement
OtsoSilver

Untitled

Sep 12th, 2021
795
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.88 KB | None | 0 0
  1. #pgzero
  2.  
  3. # Игровое окно из клеток
  4. cell = Actor('border')
  5. cell1 = Actor('floor')
  6. cell2 = Actor('crack')
  7. cell3 = Actor('bones')
  8. size_w = 7 # Ширина поля в клетках
  9. size_h = 7 # Высота поля в клетках
  10. WIDTH = cell.width * size_w
  11. HEIGHT = cell.height * size_h
  12.  
  13. char = Actor('stand')
  14. char.health = 100
  15. char.attack = 5
  16. TITLE = "Подземелья" # Заголовок окна игры
  17. FPS = 30 # Количество кадров в секунду
  18. my_map = [
  19.     [0,0,0,0,0,0,0],
  20.     [0,1,2,1,3,1,0],
  21.     [0,1,1,2,1,1,0],
  22.     [0,3,2,1,1,3,0],
  23.     [0,1,1,1,3,1,0],
  24.     [0,1,3,1,1,2,0],
  25.     [0,0,0,0,0,0,0]
  26.     ]
  27. def map_draw():
  28.     for i in range(len(my_map)):
  29.         for j in range(len(my_map[0])):
  30.             if my_map[i][j] == 0:
  31.                 cell.left = cell.width*j
  32.                 cell.top = cell.height*i
  33.                 cell.draw()
  34.             elif my_map[i][j] == 1:
  35.                 cell1.left = cell1.width*j
  36.                 cell1.top = cell1.height*i
  37.                 cell1.draw()
  38.             elif my_map[i][j] == 2:
  39.                 cell2.left = cell2.width*j
  40.                 cell2.top = cell2.height*i
  41.                 cell2.draw()
  42.             elif my_map[i][j] == 3:
  43.                 cell3.left = cell3.width*j
  44.                 cell3.top = cell3.height*i
  45.                 cell3.draw()
  46.  
  47.  
  48. def on_key_down(key):
  49.     if keyboard.right:
  50.         char.x += cell.width
  51.         char.image = 'stand'
  52.     if keyboard.left:
  53.         char.x -= cell.width
  54.         char.image = 'left'    
  55.     if keyboard.up:
  56.         char.y -= cell.height
  57.     if keyboard.down:
  58.         char.y += cell.height
  59.    
  60.    
  61.    
  62. def draw():
  63.     map_draw()
  64.     char.draw()
  65.     screen.draw.text(char.health, center=(325, 10), color = 'white', fontsize = 16)
  66.     screen.draw.text(char.attack, center=(325, 25), color = 'white', fontsize = 16)
  67.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement