Advertisement
OtsoSilver

Untitled

Nov 12th, 2021
685
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.96 KB | None | 0 0
  1. #pgzero
  2. import random
  3. WIDTH = 400 # Ширина окна
  4. HEIGHT = 400 # Высота окна
  5.  
  6. TITLE = "Летающая тарелка" # Заголовок окна игры
  7. FPS = 30 # Количество кадров в секунду
  8.  
  9. # Объекты
  10. tarelka= Actor('tarelka', (50, 385))
  11. background= Actor("background")
  12. top = Actor('top', (200, 50))
  13. bottom = Actor("bottom", (450, 350))
  14. game_over = 0
  15. count = 0
  16.  
  17. x=random.randint(1,2)
  18.  
  19. def draw():
  20.     background.draw()
  21.     tarelka.draw()
  22.     if x ==1:
  23.         top.draw()
  24.     else:
  25.         bottom.draw()
  26.        
  27.     screen.draw.text(count, pos=(10, 10), color="white", fontsize = 24)    
  28.     if game_over == 1:
  29.         # game_over.draw()
  30.         screen.draw.text('Нажмите Enter', pos=(170, 150), color="white", fontsize = 36)        
  31.    
  32.  
  33.        
  34. #функции
  35. def topa():
  36.     global count
  37.     # Движение стен
  38.     if top.x > -20:
  39.         top.x = top.x - 5
  40.     else:
  41.         top.x = WIDTH + 20
  42.         count = count + 1
  43.  
  44. #функция коробки
  45. def bot():
  46.     global count
  47.         # Движение коробки
  48.     if bottom.x > -20:
  49.         bottom.x = bottom.x - 5
  50.         bottom.angle = bottom.angle + 5
  51.     else:
  52.         bottom.x = WIDTH + 20
  53.         count = count + 1
  54.        
  55. def update(dt):
  56.     global game_over
  57.     global count
  58.    
  59.     if x==1:
  60.         topa()
  61.     else:
  62.         bot()
  63.        
  64. def on_key_down(key):        
  65.     # Прыжок
  66.     global game_over
  67.     if keyboard.space or keyboard.up or keyboard.w:
  68.         tarelka.y -= 50
  69.         animate(tarelka, tween='bounce_end', duration=2, y=382)        
  70.        
  71.    
  72.     if game_over == 1 and keyboard.enter:
  73.         game_over = 0
  74.         count = 0
  75.         tarelka.pos = (50, 385)
  76.         top.pos =(200, 50)
  77.         bottom.pos = (450, 350)
  78.    
  79.     # Столкновение
  80.     if tarelka.colliderect(top) or tarelka.colliderect(bottom):
  81.         game_over = 1
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement