精灵在 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 (将#修改为@)

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...