Skip to content
Open
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
10 changes: 9 additions & 1 deletion ple/games/flappybird/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,13 @@ def __init__(self,

# all in terms of y
self.vel = 0
self.tilt = 0.0
self.FLAP_POWER = 9 * self.scale
self.MAX_DROP_SPEED = 10.0
self.GRAVITY = 1.0 * self.scale
self.TILT_FLAP = 30.0
self.TILT_FALLING = -70.0
self.TILT_SPEED = 120.0

self.rng = rng

Expand All @@ -50,6 +54,7 @@ def init(self, init_pos, color):
self.game_tick = 0
self.pos_x = init_pos[0]
self.pos_y = init_pos[1]
self.tilt = 0.0

def _oscillateStartPos(self):
offset = 8 * np.sin(self.rng.rand() * np.pi)
Expand All @@ -58,6 +63,7 @@ def _oscillateStartPos(self):
def flap(self):
if self.pos_y > -2.0 * self.image.get_height():
self.vel = 0.0
self.tilt = self.TILT_FLAP
self.flapped = True

def update(self, dt):
Expand All @@ -76,6 +82,7 @@ def update(self, dt):

if self.vel < self.MAX_DROP_SPEED and self.thrust_time == 0.0:
self.vel += self.GRAVITY
self.tilt = max(self.tilt - self.TILT_SPEED*dt, self.TILT_FALLING)

# the whole point is to spread this out over the same time it takes in
# 30fps.
Expand All @@ -90,7 +97,8 @@ def update(self, dt):
self.rect.center = (self.pos_x, self.pos_y)

def draw(self, screen):
screen.blit(self.image, self.rect.center)
rotated_image = pygame.transform.rotate(self.image, self.tilt)
screen.blit(rotated_image, self.rect)


class Pipe(pygame.sprite.Sprite):
Expand Down