jeudi 6 février 2020

Python says function is not defined despite being defined just two lines above

I have this class:

class Demo():

    ############################### Drawing functions

    SCREEN_OFFSETX, SCREEN_OFFSETY = SCREEN_WIDTH/16, SCREEN_HEIGHT

    def fix_vertices(vertices):
        return [(int(SCREEN_OFFSETX + v[0]), int(SCREEN_OFFSETY - v[1])) for v in vertices]

    def draw_polygon(polygon, screen, body, fixture):
        transform = body.transform
        vertices = fix_vertices([transform * v * PPM for v in polygon.vertices])
        pygame.draw.polygon(
            screen, [c / 2.0 for c in colors[body.type]], vertices, 0)
        pygame.draw.polygon(screen, colors[body.type], vertices, 1)
    polygonShape.draw = draw_polygon
    ''''
    Do other stuff...
    ''''

and I run it using these lines of code:

Car = Demo()
if __name__ == "__main__":
    Car
    print("It Works")

But when I try to run it I got an error that fix_vertices_ is not defined... how can I fix this?

Thank you very much

P.S. and another subquestion... is it the correct way of calling this class using the

if __name__ == "__main__"

syntax or is there a better way for example

if __name__ == "__main__":
    main(Demo)

Thank you very much

Aucun commentaire:

Enregistrer un commentaire