Как нарисовать модель PyBox2D - PullRequest
0 голосов
/ 19 сентября 2019

У меня есть этот класс Car, и я хочу нарисовать его, используя pygame (часть с импортом не показана, чтобы сделать мой код максимально коротким):

class Car:
    GRAVITY = [0, 0]
    world = world(gravity=(GRAVITY), doSleep=True)
    colors = {dynamicBody: (133, 187, 101, 0),  staticBody: (15, 0, 89, 0)}

    Chassis_Shape = [(11.5, 0.0),
        (13.0, 2.5),
        (12.25, 5.5),
        (11, 7.5),
        (10.25, 10.0),
        (9.75, 10.0),
        (9, 7.5),
        (7.75, 5.5),
        (7.0, 2.5),
        (8.5, 0.0),
        ]

    Wheel_Anchoring = [(7.0, 0.75),
        (13.0, 0.75),
        (7.0, 8.50),
        (13.0, 8.50),
        ]  

    def __init__(self,
             world = None,
             vertices = None,
             wheel_anchoring = None,
             position = (0,0),
             density = 1):

        if vertices == None:
            vertices = Car.Chassis_Shape

        if world == None:
            world = Car.world

        self.Chassis = world.CreateDynamicBody(position = position,
                                           angle=0,
                                           fixtures = b2FixtureDef(
                                                shape = b2PolygonShape(vertices=Car.Chassis_Shape),
                                                density = 2,
                                                friction = 0.3))

    def my_draw_polygon(self):
        self.vertices = [(self.Chassis.transform * v) * PPM for v in self.Chassis.fixtures.shape.vertices]
        self.vertices = [(v[0], SCREEN_HEIGHT - v[1]) for v in self.vertices]
        pygame.draw.polygon(screen, Car.colors[world.body.type], self.vertices)
    polygonShape.draw = my_draw_polygon

    for body in world.bodies:
        for fixture in body.fixtures:
            fixture.shape.draw(body, fixture)

screen = pygame.display.set_mode((SCREEN_WIDTH, SCREEN_HEIGHT))
screen.fill((255, 255, 255 ,0))
pygame.display.flip()
pygame.display.set_caption('Top Down Car')
clock = pygame.time.Clock()

MyCar = Car()
running = True
while running:  
    MyCar.my_draw_polygon()

Но когда я запускаю код, онпоказывает мне эту ошибку:

error in: self.vertices = [(self.Chassis.transform * v) * PPM for v in self.Chassis.fixtures.shape.vertices]
    list' object has no attribute 'shape'

Ошибка довольно проста, но я действительно не знаю, как ее исправить. Любая помощь более чем признательна

...