OtsoSilver

Untitled

Sep 18th, 2021
566
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import pygame
  2. import random
  3.  
  4. #Настройки окна
  5. WIDTH = 500
  6. HEIGHT = 500
  7. FPS = 60
  8.  
  9. # Цвета
  10. YELLOW = (255, 255, 0)
  11. SKY = (133, 193, 233)
  12. GREEN = (46, 204, 113)
  13. WHITE = (255, 255, 255)
  14.  
  15. #Инициализация
  16. pygame.init()
  17. screen = pygame.display.set_mode((WIDTH,HEIGHT))
  18. clock = pygame.time.Clock()
  19.  
  20. # Настройки персонажа
  21. bird = pygame.Rect(40, 250, 30, 23)
  22. birdImg = pygame.image.load('fpbs1.png')
  23. points = 0
  24.  
  25. # Шрифты
  26. font = pygame.font.SysFont('comic sans ms', 30)
  27. game_over_font = pygame.font.SysFont('comic sans ms', 50)
  28. game_over_text = game_over_font.render('GAME OVER', 1, WHITE)
  29.  
  30. # Падение
  31. GRAVITY = 0.3
  32. y_change = 0
  33.  
  34. # Прыжок
  35. isJump = False
  36. jumpCount = 10
  37.  
  38. GO = False
  39. running = True
  40. while running:
  41.     screen.fill(SKY)
  42.     for i in pygame.event.get():
  43.         if i.type == pygame.QUIT:
  44.             running = False
  45.         if i.type == pygame.KEYDOWN:
  46.             if i.key == pygame.K_SPACE:
  47.                 isJump = True
  48.                 hopCount = 0
  49.     if GO:
  50.         screen.blit(game_over_text, (80,120))
  51.     else:
  52.         if isJump:
  53.             hopCount += 1
  54.             bird.top -= 6
  55.             if hopCount == 5:
  56.                 y_change = 0
  57.                 isJump = False
  58.         else:
  59.             y_change += GRAVITY
  60.             bird.top += y_change
  61.         if bird.top < 0 or bird.bottom > HEIGHT:
  62.             GO = True
  63.         screen.blit(birdImg, (bird.left, bird.top))
  64.    
  65.     clock.tick(FPS)
  66.     pygame.display.update()
  67. pygame.quit()
RAW Paste Data