Exemple #1
0
 def __createGravityZone(self):
     self.mBody = self.mWorld.CreateStaticBody(position = self.mPosition)
     shape = b2PolygonShape()
     shape.SetAsBox(self.TILE_SIZE/2, self.TILE_SIZE/2)
     fd = b2FixtureDef()
     fd.shape = shape
     fd.isSensor = True
     fd.bullet = False
     fd.userData = TileType.GRAVITYZONE
     self.mBody.CreateFixture(fd)
 def _makeWorld(self):
     self.world = b2World(gravity=(0, -10), doSleep=True)
     self.ground_body = self.world.CreateStaticBody(fixtures=b2FixtureDef(
         shape=b2EdgeShape(vertices=[(-1e5, 0), (1e5, 0)]),
         categoryBits=0x0002,
         maskBits=0x0004),
                                                    position=(0, 0),
                                                    userData='ground')
     self.helperEdge1 = self.world.CreateStaticBody(fixtures=b2FixtureDef(
         shape=b2EdgeShape(vertices=[(0, -1e5), (0, 1e5)]),
         categoryBits=0x0004,
         maskBits=0x0002),
                                                    position=(0, 0))
     self.helperEdge2 = self.world.CreateStaticBody(fixtures=b2FixtureDef(
         shape=b2EdgeShape(vertices=[(-1e5,
                                      self.MinHeight), (1e5,
                                                        self.MinHeight)]),
         categoryBits=0x0004,
         maskBits=0x0002),
                                                    position=(0, 0))
 def _create_ball(self, pos):
     """Creëren van een bal in Box2D omgeving.
     
     Args:
         pos: (tuple) x,y coördinaten van de bal.
     """
     fixture = b2FixtureDef(
         shape=b2CircleShape(
             radius=self.radius,  #create ball.
             pos=(0, 0)),
         density=1,
         friction=900000,
         restitution=0.5)
     # balpositie, vanaf nu ball.
     self.ball = self.world.CreateDynamicBody(position=pos,
                                              fixtures=fixture,
                                              linearDamping=0.5)
Exemple #4
0
 def __createTile(self):
     tl = b2Vec2(-self.TILE_SIZE/2, -self.TILE_SIZE/2)
     tr = b2Vec2(self.TILE_SIZE/2, -self.TILE_SIZE/2)
     br = b2Vec2(self.TILE_SIZE/2, self.TILE_SIZE/2)
     bl = b2Vec2(-self.TILE_SIZE/2, self.TILE_SIZE/2)
     
     shape = b2ChainShape()
     shape.vertices = (bl, br, tr, tl)
     fd = b2FixtureDef()
     fd.categoryBits = Filter.CATEGORY_WALLS
     fd.maskBits = Filter.MASK_WALLS
     fd.bullet = False
     fd.shape = shape
     
     self.mBody = self.mWorld.CreateStaticBody(position = self.mPosition)
     
     self.mBody.CreateFixture(fd)
     self.mBody.userData = self
    def LaunchBomb(self, position, velocity):
        """Een bom is een eenvoudige cirkel met de opgegeven positie en snelheid.
        Positie en snelheid moeten b2Vec2's zijn.

        Args:
            position ([type]): [description]
            velocity ([type]): [description]
        """
        if self.bomb:
            self.world.DestroyBody(self.bomb)
            self.bomb = None

        self.bomb = self.world.CreateDynamicBody(
            allowSleep=True,
            position=position,
            linearVelocity=velocity,
            fixtures=b2FixtureDef(shape=b2CircleShape(radius=0.3),
                                  density=20,
                                  restitution=0.1))
    def create_targetpoint(self, pos):
        """Creëer targetpoint (gewenste positie keeper) in de simulatie die weergegeven moet worden.
        
        Args:
            pos: (tuple) x & y coördinaten waar het targetpoint moet komen te staan.
        """

        self.fixture_tp = b2FixtureDef(
            shape=b2CircleShape(
                radius=0.3,  #create targetpoint.
                pos=(0, 0)),
            density=1,
            friction=900000,
            restitution=0.5)
        self.fixture_tp.sensor = True
        self.tp = self.world.CreateDynamicBody(position=pos,
                                               fixtures=self.fixture_tp,
                                               linearDamping=0.5)
        self.fixture_tp2 = self.tp.CreatePolygonFixture(
            shape=b2CircleShape(radius=0.3), density=100000000)
        self.fixture_tp2.sensor = True