carmunk.py 文件源码

python
阅读 23 收藏 0 点赞 0 评论 0

项目:ml_capstone 作者: drscott173 项目源码 文件源码
def __init__(self, game):
        # Global-ish.
        self.game = game
        self.crashed = False

        # Physics stuff.
        self.space = pymunk.Space()
        self.space.gravity = pymunk.Vec2d(0., 0.)

        # Create the car.
        self.create_car(100, 100, 0.5)

        # Record steps.
        self.num_steps = 0

        # Create walls.
        height = self.game.height
        width = self.game.width
        thick = 1

        static = [
            pymunk.Segment(
                self.space.static_body,
                (0, thick), (0, height), thick),
            pymunk.Segment(
                self.space.static_body,
                (thick, height), (width, height), thick),
            pymunk.Segment(
                self.space.static_body,
                (width-thick, height), (width-thick, thick), thick),
            pymunk.Segment(
                self.space.static_body,
                (thick, thick), (width, thick), thick)
        ]
        for s in static:
            s.friction = 1.
            s.group = 1
            s.collision_type = 1
            s.color = THECOLORS['red']
        self.space.add(static)

        # Create some obstacles, semi-randomly.
        # We'll create three and they'll move around to prevent over-fitting.
        self.obstacles = []
        self.obstacles.append(self.create_obstacle(200, 350, 100))
        self.obstacles.append(self.create_obstacle(700, 200, 125))
        self.obstacles.append(self.create_obstacle(600, 600, 35))

        # Create a cat and food and hud
        self.create_cat()
        self.hud = "HUD"
        self.show_hud()
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号