def update(self, delta_frames=1): """Update the PipePair's position. Arguments: delta_frames: The number of frames elapsed since this method was last called. """ self.x -= ANIMATION_SPEED * frames_to_msec(delta_frames)
def update(self, delta_frames=1): """Update the bird's position. This function uses the cosine function to achieve a smooth climb: In the first and last few frames, the bird climbs very little, in the middle of the climb, it climbs a lot. One complete climb lasts CLIMB_DURATION milliseconds, during which the bird ascends with an average speed of CLIMB_SPEED px/ms. This Bird's msec_to_climb attribute will automatically be decreased accordingly if it was > 0 when this method was called. Arguments: delta_frames: The number of frames elapsed since this method was last called. """ if self.msec_to_climb > 0: frac_climb_done = 1 - self.msec_to_climb / Bird.CLIMB_DURATION self.y -= (Bird.CLIMB_SPEED * frames_to_msec(delta_frames) * (1 - math.cos(frac_climb_done * math.pi))) self.msec_to_climb -= frames_to_msec(delta_frames) else: self.y += Bird.SINK_SPEED * frames_to_msec(delta_frames)