Nov-14-2019, 02:35 AM
I tried to recreate Flappy Bird using pygame and everything works properly except for the rotation of the Flappy Bird.
The rotated image increases the size of the rect of sprite which it makes detecting the collision of the bird with the pipes difficult.
Here is my rotation function of the bird sprite:
![[Image: ETrlk4p]](https://imgur.com/a/ETrlk4p)
![[Image: Hsh1oqY]](https://imgur.com/a/Hsh1oqY)
![[Image: oVLTK5q]](https://imgur.com/a/oVLTK5q)
I have changed the new rect with the old rect's center but still its size is getting bigger.
Here is a link to my project:
https://github.com/pranav-28/FlappyBird
The rotated image increases the size of the rect of sprite which it makes detecting the collision of the bird with the pipes difficult.
Here is my rotation function of the bird sprite:
def rotation(self, dt):
"""
Rotates the bird as per its position
:param dt: for counting frames
:return: None
"""
if self.isJump and not self.isUp:
old_center = self.rect.center
for i in range(3):
self.group_images[i] = self.rotated_group_images[i]
self.image = self.group_images[self.image_index]
self.rect = self.image.get_rect()
self.rect.center = old_center
self.isUp, self.isDown = True, False
if self.isUp and self.isJump:
self.jump_height = self.rect.y
if not self.isJump and not self.isDown:
if self.rect.y > self.jump_height:
if self.rotated >= self.max_rotation:
self.rotation_time += dt
if self.rotation_time >= self.rotation_animation_time:
self.isUp = False
old_center = self.rect.center
for i in range(3):
self.group_images[i] = pygame.transform.rotate(self.group_images[i], self.rotate)
self.image = self.group_images[self.image_index]
self.rect = self.image.get_rect()
self.rect.center = old_center
self.rotated += self.rotate
if self.rotated == self.max_rotation:
self.isDown = True
self.rotated = 0Here is what the game looks like. I have drawn the rect of the sprite to show its size:I have changed the new rect with the old rect's center but still its size is getting bigger.
Here is a link to my project:
https://github.com/pranav-28/FlappyBird
