微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

精灵在 pygame 中走错了方向

如何解决精灵在 pygame 中走错了方向

` def move(self):
    self.rect.center = (self.rect.center[0] + self.speed * math.cos(math.radians(self.direction)),self.rect.center[1] + self.speed * math.sin(math.radians(self.direction)))

    self.image = pygame.transform.rotate(self.orig_image,-self.direction)

    if abs(self.speed) > 0: #Friction
        self.speed /= 1.001

def accelerate(self):
    self.speed += 0.04

def brake(self):
    self.speed -= 0.04

def turn_left(self):
   angle = 1
   self.direction -= angle
   print("direction =",self.direction % 360)

def turn_right(self):
    angle = 1
    self.direction += angle `
    print("direction =",self.direction % 360)

我遇到的问题是,当我不按任何键时,汽车会自行朝一个方向移动,而这会发生在我面对的某些方向上。例如,当我在方向 = 91-93 时,汽车面朝下并稍微向左移动,根本没有移动,但由于某些奇怪的原因,它开始自行向左移动,没有发生摩擦。让它停止向左移动的唯一方法是回到方向= 90,它直接朝下,汽车静止。 (请记住,这只会在我开始加速而不是完全停止时发生。)

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。