Advertisement
OtsoSilver

Untitled

Sep 25th, 2021
1,242
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 3.24 KB | None | 0 0
  1. #pgzero
  2.  
  3. import random
  4.  
  5. # Игровое окно
  6. cell = Actor('border')
  7. cell1 = Actor('floor')
  8. cell2 = Actor("crack")
  9. cell3 = Actor("bones")
  10. size_w = 9 # Ширина поля в клетках
  11. size_h = 10 # Высота поля в клетках
  12. WIDTH = cell.width * size_w
  13. HEIGHT = cell.height * size_h
  14.  
  15. TITLE = "Подземелья" # Заголовок окна игры
  16. FPS = 30 # Количество кадров в секунду
  17. my_map = [[0, 0, 0, 0, 0, 0, 0, 0, 0],
  18.           [0, 1, 1, 1, 1, 1, 1, 1, 0],
  19.           [0, 1, 1, 2, 1, 3, 1, 1, 0],
  20.           [0, 1, 1, 1, 2, 1, 1, 1, 0],
  21.           [0, 1, 3, 2, 1, 1, 3, 1, 0],
  22.           [0, 1, 1, 1, 1, 3, 1, 1, 0],
  23.           [0, 1, 1, 3, 1, 1, 2, 1, 0],
  24.           [0, 1, 1, 1, 1, 1, 1, 1, 0],
  25.           [0, 0, 0, 0, 0, 0, 0, 0, 0],
  26.           [-1, -1, -1, -1, -1, -1, -1, -1, -1]] # Строка с атакой и здоровьем
  27.  
  28. # Главный герой
  29. char = Actor('stand')
  30. char.top = cell.height
  31. char.left = cell.width
  32. char.health = 100
  33. char.attack = 5
  34. enemies = []
  35. for i in range(5):
  36.     x = random.randint(1,7) * cell.width
  37.     y = random.randint(1,7) * cell.height
  38.     enemy = Actor('enemy', topleft = (x,y))
  39.     enemy.health = random.randint(10,20)
  40.     enemy.attack = random.randint(5,10)
  41.     enemies.append(enemy)
  42.  
  43. def map_draw():
  44.     for i in range(len(my_map)):
  45.         for j in range(len(my_map[0])):
  46.             if my_map[i][j] == 0:
  47.                 cell.left = cell.width*j
  48.                 cell.top = cell.height*i
  49.                 cell.draw()
  50.             elif my_map[i][j] == 1:
  51.                 cell1.left = cell.width*j
  52.                 cell1.top = cell.height*i
  53.                 cell1.draw()
  54.             elif my_map[i][j] == 2:
  55.                 cell2.left = cell.width*j
  56.                 cell2.top = cell.height*i
  57.                 cell2.draw()  
  58.             elif my_map[i][j] == 3:
  59.                 cell3.left = cell.width*j
  60.                 cell3.top = cell.height*i
  61.                 cell3.draw()
  62.  
  63. def draw():
  64.     screen.fill("#2f3542")
  65.     map_draw()
  66.     char.draw()
  67.     screen.draw.text("HP:", center=(25, 475), color = 'white', fontsize = 20)
  68.     screen.draw.text(char.health, center=(75, 475), color = 'white', fontsize = 20)
  69.     screen.draw.text("AP:", center=(375, 475), color = 'white', fontsize = 20)
  70.     screen.draw.text(char.attack, center=(425, 475), color = 'white', fontsize = 20)
  71.     for i in enemies:
  72.         i.draw()
  73.  
  74. def on_key_down(key):
  75.     if keyboard.right and char.x + cell.width < WIDTH - cell.width:
  76.         char.x += cell.width
  77.         char.image = 'stand'
  78.     elif keyboard.left and char.x - cell.width > cell.width:
  79.         char.x -= cell.width
  80.         char.image = 'left'
  81.     elif keyboard.down and char.y + cell.height < HEIGHT - cell.height*2:
  82.         char.y += cell.height
  83.     elif keyboard.up and char.y - cell.height > cell.height:
  84.         char.y -= cell.height
  85.    
  86.     enemy_index = char.collidelist(enemies)
  87.     if enemy_index != -1:
  88.         enemy = enemies[enemy_index]
  89.         char.health -= enemy.attack
  90.         enemy.health -= char.attack
  91.         if enemy.health <= 0:
  92.             enemies.remove(enemy)
  93.    
  94.    
  95.    
  96.    
  97.    
  98.    
  99.    
  100.    
  101.    
  102.    
  103.    
  104.    
  105.    
  106.    
  107.    
  108.    
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement