Advertisement
Josif_tepe

Untitled

Nov 29th, 2024
25
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.12 KB | None | 0 0
  1. import pygame as pg
  2. pg.init()
  3.  
  4. SCREEN_WIDTH = 256
  5. SCREEN_HEIGHT = 640
  6.  
  7. clock = pg.time.Clock()
  8. FPS = 60
  9. screen = pg.display.set_mode((SCREEN_WIDTH, SCREEN_HEIGHT))
  10. pg.display.set_caption('Flappy Bird', 'Assets/yellowbird-downflap.png')
  11.  
  12. bg = pg.image.load('Assets/background-day.png')
  13. ground_img = pg.image.load('Assets/base.png')
  14.  
  15. class Bird(pg.sprite.Sprite):
  16.     def __init__(self, x, y):
  17.         pg.sprite.Sprite.__init__(self)
  18.         self.image = pg.image.load('Assets/redbird-downflap.png')
  19.         self.rect = self.image.get_rect()
  20.         self.rect.center = [x, y]
  21.  
  22. bird_group = pg.sprite.Group()
  23. player = Bird(SCREEN_WIDTH / 2, SCREEN_HEIGHT / 2)
  24. bird_group.add(player)
  25.  
  26.  
  27.  
  28.  
  29. ground_scroll = 0
  30. scroll_speed = 4
  31. is_active = True
  32. while is_active:
  33.     clock.tick(FPS)
  34.  
  35.     screen.blit(bg, (0, 0))
  36.     bird_group.draw(screen)
  37.     screen.blit(ground_img, (ground_scroll, 512))
  38.     ground_scroll -= scroll_speed
  39.     if abs(ground_scroll) > 35:
  40.         ground_scroll = 0
  41.  
  42.     for event in pg.event.get():
  43.         if event.type == pg.QUIT:
  44.             is_active = False
  45.  
  46.     pg.display.update()
  47. pg.quit()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement