OtsoSilver

Untitled

Aug 29th, 2021
1,282
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.45 KB | None | 0 0
  1. #pgzero
  2. import random
  3.  
  4. WIDTH = 600 # Ширина окна
  5. HEIGHT = 300 # Высота окна
  6.  
  7. TITLE = "Инопланетный раннер" # Заголовок окна игры
  8. FPS = 30 # Количество кадров в секунду
  9.  
  10. # Объекты
  11. alien = Actor('alien', (50, 240))
  12. fon = Actor("fon")
  13. box = Actor('box', (550, 265))
  14. bee = Actor('bee', (550, 175))
  15. go = Actor("GO")
  16. # Переменные
  17. game_over = 0
  18. count = 0
  19. enemy = random.randint(1,2)
  20.  
  21. def boxes():
  22.     global count
  23.     global enemy
  24.     # Движение коробки
  25.     if box.x > -20:
  26.         box.x = box.x - 5
  27.         box.angle = box.angle + 5
  28.     else:
  29.         box.x = WIDTH + 20
  30.         count = count + 1
  31.         enemy = random.randint(1,2)
  32.        
  33.  
  34. def bees():
  35.     global count
  36.     global enemy
  37.     # Движение пчелы
  38.     if bee.x > -20:
  39.         bee.x = bee.x - 5
  40.     else:
  41.         bee.x = WIDTH + 20
  42.         count = count + 1
  43.         enemy = random.randint(1,2)
  44.  
  45. def draw():
  46.     fon.draw()
  47.     alien.draw()
  48.     if enemy == 1:
  49.         box.draw()
  50.     else:
  51.         bee.draw()
  52.     screen.draw.text(count, pos=(10, 10), color="white", fontsize = 24)
  53.     if game_over == 1:
  54.         go.draw()
  55.         screen.draw.text('Нажмите Enter', pos=(170, 150), color="white", fontsize = 36)
  56.  
  57.    
  58. def update(dt):
  59.     # Переменные
  60.     global count
  61.     global game_over
  62.    
  63.     # Вызов функций
  64.     if enemy == 1:
  65.         boxes()
  66.     else:
  67.         bees()
  68.    
  69.     # Управление
  70.     if keyboard.left or keyboard.a and alien.x > 20:
  71.         alien.x = alien.x - 5
  72.         # alien.image = 'left'
  73.     elif keyboard.right or keyboard.d and alien.x < 580:
  74.         alien.x = alien.x + 5
  75.         # alien.image = 'right'
  76.     elif keyboard.down or keyboard.s:
  77.         # alien.image = 'duck'
  78.         alien.y = 250
  79.     else:
  80.         # alien.image = 'alien'
  81.         if alien.y > 240:
  82.             alien.y = 240
  83.    
  84.     if game_over == 1 and keyboard.enter:
  85.         game_over = 0
  86.         count = 0
  87.         alien.pos = (50, 240)
  88.         box.pos =(550, 265)
  89.         bee.pos = (550, 175)
  90.    
  91.     # Столкновение
  92.     if alien.colliderect(box) or alien.colliderect(bee):
  93.         game_over = 1
  94.  
  95. # Прыжок        
  96. def on_key_down(key):
  97.     if keyboard.space or keyboard.up or keyboard.w:
  98.         alien.y = 100
  99.         animate(alien, tween='bounce_end', duration=2, y=240)
  100.        
Advertisement
Add Comment
Please, Sign In to add comment