1

I am writing a flappy bird clone with c++ and DirectX. I am basically finished, except for the algorithm for the rotation. I have one now (rotation = ((90 * (yVelocity+10) / 25) - 90)/2;), but it does not act the same way as the original flappy bird. I am trying to replicate the original flappy bird's rotation as closely as possible so any help would be appreciated.

3 Answers3

1

I would make it equal to the original yVelocity but cap it at 2 numbers. Something like

rotation = min(topClamp, max(bottomClamp, yVelocity));

You might want to play around with this for a bit but this will make the rotation rely on the yVelocity but if the player is constantly going up then the rotation will be clamped at some number and the bird will just be looking up like in the original game.

Oleks G
  • 94
  • 5
0
    def fall(self):
        # bird falls with accelerated motion
        self.movement += GRAVITY
        self.rect.centery += self.movement

    def rotate(self):
        # factor is positive when falling, therefore rotation is clockwise
        # factor is negative when raising, rotation is counter-clockwise
        factor = -2
        factor *= self.movement

        self.image = pygame.transform.rotozoom(self.temporary, factor, 1)
  • I am recommending this answer for deletion. The original question was asked over a year ago. Also you provided python code for a C++ question, with completely different variables. Please pay more attention next time. – Eyal K. Oct 06 '21 at 01:46
0

self.temporary is a copy of the current sprite.

""" Bird object """
class Bird(pygame.sprite.Sprite):
    def __init__(self, color):
        super().__init__()

        # sounds
        self.flap = pygame.mixer.Sound('wing.wav')
        self.crash = pygame.mixer.Sound('crash.wav')
        
        # flapping sprites
        self.sprites = []

        for i in [1, 2, 3]:
            temp = pygame.image.load(color + str(i) + ".png").convert_alpha()
            temp = pygame.transform.scale2x(temp)
            self.sprites.append(temp)
            
        # current sprite
        self.image = self.sprites[0]

        # temporary sprite
        self.temporary = self.image

        # current rectangle
        self.rect = self.image.get_rect(center=(BIRD_X, HEIGHT/2))

        # current frame
        self.frame = 0

        # movement amount
        self.movement = 0