Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import pygame as pg
- pg.init()
- SCREEN_WIDTH = 270
- SCREEN_HEIGHT = 620
- clock = pg.time.Clock()
- FPS = 60
- screen = pg.display.set_mode((SCREEN_WIDTH, SCREEN_HEIGHT))
- pg.display.set_caption('Flappy Bird', 'Assets/yellowbird-downflap.png')
- bg = pg.image.load('Assets/background-day.png')
- ground_img = pg.image.load('Assets/base.png')
- class Bird(pg.sprite.Sprite):
- def __init__(self, x, y):
- pg.sprite.Sprite.__init__(self)
- self.images = []
- self.index = 0
- self.counter = 0
- for i in range(1, 4):
- img = pg.image.load(f'Assets/red_bird_{i}.png')
- self.images.append(img)
- self.image = self.images[self.index]
- self.rect = self.image.get_rect()
- self.rect.center = [x, y]
- def update(self):
- self.counter += 1
- flap_cooldown = 7
- if self.counter > flap_cooldown:
- self.counter = 0
- self.index += 1
- if self.index >= len(self.images):
- self.index = 0
- self.image = self.images[self.index]
- bird_group = pg.sprite.Group()
- player = Bird(SCREEN_WIDTH / 2, SCREEN_HEIGHT / 2)
- bird_group.add(player)
- ground_scroll = 0
- scroll_speed = 4
- is_active = True
- while is_active:
- clock.tick(FPS)
- screen.blit(bg, (0, 0))
- bird_group.draw(screen)
- bird_group.update()
- screen.blit(ground_img, (ground_scroll, 512))
- ground_scroll -= scroll_speed
- if abs(ground_scroll) > 35:
- ground_scroll = 0
- for event in pg.event.get():
- if event.type == pg.QUIT:
- is_active = False
- pg.display.update()
- pg.quit()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement