我正在用c++和DirectX写一个浮华的小鸟克隆。我基本上完成了,除了旋转的算法。我现在有一个(rotation = ((90 * (yVelocity+10) / 25) - 90)/2;),但它的行为方式与最初的flappy鸟不同。我正在尝试尽可能地复制最初的flappy鸟的旋转,因此任何帮助都将不胜感激。
发布于 2020-04-27 08:20:50
我会使它等于原始的yVelocity,但将其限制为2个数字。就像这样
rotation = min(topClamp, max(bottomClamp, yVelocity));你可能想玩一段时间,但这将使旋转依赖于yVelocity,但如果玩家不断向上,那么旋转将被夹在某个数字,而鸟将只是向上看,就像在原始游戏中一样。
发布于 2021-10-05 18:38:18
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)发布于 2021-10-05 18:42:51
self.temporary是当前精灵的副本。
""" 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 = 0https://stackoverflow.com/questions/61441960
复制相似问题