我正在尝试在pygame中制作一个精灵投掷手榴弹。我想要的是它向前移动一点,然后停下来。我的问题是让手榴弹顺利前进。下面的代码所做的是让它立即移动到感兴趣的点,而不是平滑移动。
[手榴弹类]
#Grenade Class
class Explosive(pygame.sprite.Sprite):
def __init__(self, location):
pygame.sprite.Sprite.__init__(self)
self.pos = location
self.image = Nade
self.rect = self.image.get_rect()
self.rect.right = self.image.get_rect().right
self.rect.left = self.image.get_rect().left
self.rect.top = self.image.get_rect().top
self.rect.bottom = self.image.get_rect().bottom
self.rect.center = location
def move(self):
if Player.direction == 0:
self.rect.centery = self.rect.centery - 5
if Player.direction == 180:
self.rect.centery = self.rect.centery + 5
if Player.direction == 90:
self.rect.centerx = self.rect.centerx + 5
if Player.direction == 270:
self.rect.centerx = self.rect.centerx - 5
[投掷手榴弹(在主循环中)]
if event.key == pygame.K_e and grenadeNum > 0:
Grenade = Explosive([Player.rect.centerx, Player.rect.centery])
for i in range(1, 10)
Grenade.move()