Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 24 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,26 @@
Em breve, vídeo no YouTube explicando o código!

Assets tirados de: https://github.com/sourabhv/FlapPyBird
Assets tirados de: https://github.com/sourabhv/FlapPyBird


## Instruções

1. Criando ambiente virtual e inicializando;
2. Instalando dependências;
3. Executando o jogo.

### Criando ambiente virtual e inicializando
```
virtualenv -p python3 env
source env/bin/activate
```

### Instalando dependências
```
pip instal -r requirements.txt
```

### Executando o jogo
```
python ./flappy.py
```
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
34 changes: 21 additions & 13 deletions flappy.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,22 +15,28 @@

PIPE_GAP = 200

IMG_BASE = 'assets/base.png'
IMG_BACKGROUND = 'assets/background-day.png'
IMG_BIRD_MIDFLAP = 'assets/bluebird-midflap.png'
IMG_BIRD_UPFLAP = 'assets/bluebird-upflap.png'
IMG_BIRD_DOWNFLAP = 'assets/bluebird-downflap.png'
IMG_PIPE = 'assets/pipe-red.png'


class Bird(pygame.sprite.Sprite):

def __init__(self):
pygame.sprite.Sprite.__init__(self)

self.images = [pygame.image.load('bluebird-upflap.png').convert_alpha(),
pygame.image.load('bluebird-midflap.png').convert_alpha(),
pygame.image.load('bluebird-downflap.png').convert_alpha()]

self.speed = SPEED

self.images = [pygame.image.load(IMG_BIRD_UPFLAP).convert_alpha(),
pygame.image.load(IMG_BIRD_MIDFLAP).convert_alpha(),
pygame.image.load(IMG_BIRD_DOWNFLAP).convert_alpha()]
self.current_image = 0

self.image = pygame.image.load('bluebird-upflap.png').convert_alpha()
self.image = pygame.image.load(IMG_BIRD_UPFLAP).convert_alpha()
self.mask = pygame.mask.from_surface(self.image)

self.speed = SPEED
self.rect = self.image.get_rect()
self.rect[0] = SCREEN_WIDTH / 2
self.rect[1] = SCREEN_HEIGHT / 2
Expand All @@ -49,10 +55,10 @@ def bump(self):

class Pipe(pygame.sprite.Sprite):

def __init__(self, inverted, xpos, ysize):
def __init__(self, xpos, ysize, inverted=False):
pygame.sprite.Sprite.__init__(self)

self.image = pygame.image.load('pipe-red.png').convert_alpha()
self.image = pygame.image.load(IMG_PIPE).convert_alpha()
self.image = pygame.transform.scale(self.image, (PIPE_WIDTH,PIPE_HEIGHT))

self.rect = self.image.get_rect()
Expand All @@ -74,7 +80,7 @@ class Ground(pygame.sprite.Sprite):
def __init__(self, xpos):
pygame.sprite.Sprite.__init__(self)

self.image = pygame.image.load('base.png').convert_alpha()
self.image = pygame.image.load(IMG_BASE).convert_alpha()
self.image = pygame.transform.scale(self.image, (GROUND_WIDTH, GROUND_HEIGHT))

self.mask = pygame.mask.from_surface(self.image)
Expand All @@ -86,20 +92,22 @@ def __init__(self, xpos):
def update(self):
self.rect[0] -= GAME_SPEED


def is_off_screen(sprite):
return sprite.rect[0] < -(sprite.rect[2])


def get_random_pipes(xpos):
size = random.randint(100, 300)
pipe = Pipe(False, xpos, size)
pipe_inverted = Pipe(True, xpos, SCREEN_HEIGHT - size - PIPE_GAP)
pipe = Pipe(xpos, size)
pipe_inverted = Pipe(xpos, SCREEN_HEIGHT - size - PIPE_GAP, True)
return (pipe, pipe_inverted)


pygame.init()
screen = pygame.display.set_mode((SCREEN_WIDTH, SCREEN_HEIGHT))

BACKGROUND = pygame.image.load('background-day.png')
BACKGROUND = pygame.image.load(IMG_BACKGROUND)
BACKGROUND = pygame.transform.scale(BACKGROUND, (SCREEN_WIDTH, SCREEN_HEIGHT))

bird_group = pygame.sprite.Group()
Expand Down
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
pygame==2.0.1