class PhysicsEntity(GameEntity): # PLEASE NOTE: every PhysicsEntity should be listed in # game/physics.py ==> physicsEntities groups = {'all', 'updating', 'game', 'physics'} mass = 10. moment = 30. # pymunk.moment_for_poly(mass, verticies) level = None # The level that contains the physics Space # this is for the following funciton specialPolyTypes = { 2 : gl.GL_LINES, 3 : gl.GL_TRIANGLES, 4 : gl.GL_QUADS, } # creates a shape for the Entities physics body with the given verticies def createShape(self, verticies): assert len(verticies) >= 2 verticies = self.verticies = map(Vec2d, verticies) if is_clockwise(verticies): # fix it if it is clockwise average = sum(verticies) / len(verticies) verticies.sort(key=lambda v: (average-v).get_angle()) assert not is_clockwise(verticies), 'OMG, my code is wrong! the poly points are still clockwise' assert is_convex(verticies), 'Shape verticies must be convex!' if len(verticies) in self.specialPolyTypes: self.polyType = self.specialPolyTypes[len(verticies)] else: self.polyType = pg.GL_POLYGON self.shape = Poly(self.body, verticies) # note: collisionLayers and collisionType get created by physics.py self.shape.layers = self.collisionLayers self.shape.collision_type = self.collisionType self.shapes = [self.shape] bb = self.shape.cache_bb() self.size = Vec2d(bb.right-bb.left, bb.top-bb.bottom)