Advertisement
Josif_tepe

Untitled

Dec 7th, 2024
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.62 KB | None | 0 0
  1. import pygame as pg
  2. pg.init()
  3.  
  4. SCREEN_WIDTH = 270
  5. SCREEN_HEIGHT = 620
  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.images = []
  19.         self.index = 0
  20.         self.counter = 0
  21.         for i in range(1, 4):
  22.             img = pg.image.load(f'Assets/red_bird_{i}.png')
  23.             self.images.append(img)
  24.  
  25.         self.image = self.images[self.index]
  26.         self.rect = self.image.get_rect()
  27.         self.rect.center = [x, y]
  28.  
  29.     def update(self):
  30.         self.counter += 1
  31.         flap_cooldown = 7
  32.  
  33.         if self.counter > flap_cooldown:
  34.             self.counter = 0
  35.             self.index += 1
  36.         if self.index >= len(self.images):
  37.             self.index = 0
  38.         self.image = self.images[self.index]
  39.  
  40. bird_group = pg.sprite.Group()
  41. player = Bird(SCREEN_WIDTH / 2, SCREEN_HEIGHT / 2)
  42. bird_group.add(player)
  43.  
  44.  
  45.  
  46.  
  47. ground_scroll = 0
  48. scroll_speed = 4
  49. is_active = True
  50. while is_active:
  51.     clock.tick(FPS)
  52.  
  53.     screen.blit(bg, (0, 0))
  54.     bird_group.draw(screen)
  55.     bird_group.update()
  56.     screen.blit(ground_img, (ground_scroll, 512))
  57.     ground_scroll -= scroll_speed
  58.     if abs(ground_scroll) > 35:
  59.         ground_scroll = 0
  60.  
  61.     for event in pg.event.get():
  62.         if event.type == pg.QUIT:
  63.             is_active = False
  64.  
  65.     pg.display.update()
  66. pg.quit()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement