Advertisement
OtsoSilver

Untitled

Sep 18th, 2021
887
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.58 KB | None | 0 0
  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. bird_img = pygame.image.load('fpbs1.png').convert()
  21. bird_rect =  bird_img.get_rect()
  22. bh = bird_rect.height
  23. bw = bird_rect.width
  24.  
  25. bird = pygame.Rect(40,40, bw, bh)
  26. points = 0
  27.  
  28. font = pygame.font.SysFont('comic sans ms', 30)
  29. game_over_font = pygame.font.SysFont('comic sans ms', 50)
  30. game_over_text = game_over_font.render('GAME OVER', 1, WHITE)
  31. grav_scale = 0.3
  32. a_speed = 0
  33. hop_count = 0
  34. is_jump = False
  35. running = True
  36. GO = False
  37. while running:
  38.     screen.fill(SKY)
  39.     for i in pygame.event.get():
  40.         if i.type == pygame.QUIT:
  41.             running = False
  42.         if i.type == pygame.KEYDOWN:
  43.             if i.key == pygame.K_SPACE:
  44.                 is_jump = True
  45.                 hop_count = 0
  46.     if GO == False:
  47.         if is_jump:
  48.             hop_count += 1
  49.             bird.y -= 6
  50.             if hop_count == 5:
  51.                 a_speed = 0
  52.                 is_jump = False
  53.         else:
  54.             a_speed += grav_scale
  55.             bird.y += a_speed
  56.         if bird.top <= 0 or bird.bottom >=HEIGHT:
  57.             GO = True
  58.         screen.fill(SKY)
  59.         screen.blit(bird_img, (bird.left, bird.top))
  60.     else:
  61.         screen.blit(game_over_text, (80,120))
  62.        
  63.     clock.tick(FPS)
  64.     pygame.display.update()
  65. pygame.quit()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement