Advertisement
OtsoSilver

Untitled

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