Exemplo n.º 1
0
Arquivo: game.py Projeto: elemel/void
 def query_draw(self):
     position = self.ship.body.GetPosition()
     aabb = box2d.b2AABB()
     aabb.lowerBound.Set(position.x - 40.0, position.y - 25.0)
     aabb.upperBound.Set(position.x + 40.0, position.y + 25.0)
     max_count = 100
     (count, shapes) = self.world.Query(aabb, max_count)
     agents = set(shape.GetBody().GetUserData() for shape in shapes)
     agents = sorted(agents, key=id)
     return agents
Exemplo n.º 2
0
Arquivo: ship.py Projeto: elemel/void
    def toggle_towline(self):
        joint_edge = self.body.GetJointList()
        if joint_edge is not None:
            self.world.DestroyJoint(joint_edge.joint)
            return

        position = self.body.GetPosition()
        aabb = box2d.b2AABB()
        aabb.lowerBound.Set(position.x - self.max_towing_range,
                            position.y - self.max_towing_range)
        aabb.upperBound.Set(position.x + self.max_towing_range,
                            position.y + self.max_towing_range)
        max_count = 100
        (count, shapes) = self.world.Query(aabb, max_count)
        targets = set(shape.GetBody().GetUserData() for shape in shapes)
        targets = list(target for target in targets if self.can_tow(target))
        if targets:
            target = random.choice(targets)
            joint_def = box2d.b2DistanceJointDef()
            joint_def.Initialize(self.body, target.body,
                                 self.body.GetPosition(),
                                 target.body.GetPosition())
            joint_def.collideConnected = True
            self.world.CreateJoint(joint_def)
Exemplo n.º 3
0
Arquivo: game.py Projeto: elemel/void
 def create_world(self):
     world_aabb = box2d.b2AABB()
     world_aabb.lowerBound.Set(-400.0, -400.0)
     world_aabb.upperBound.Set(400.0, 400.0)
     gravity = box2d.b2Vec2(0.0, 0.0)
     return box2d.b2World(world_aabb, gravity, False)