Advertisement
OtsoSilver

Untitled

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