OtsoSilver

Untitled

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