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()
评论列表
文章目录