def __init__(self, brick, color, tileDir, thickness, density, unglueThreshold=None, shatterLimit=None, shatterThreshold=None, noSetup=False): if noSetup: return depth = thickness / 2 world = brick.world parent = brick.parent size = entrywiseMult(vecInvert(tileDir), brick.size) + (vecBasic(tileDir) * depth) pos = brick.node.getPos() + entrywiseMult(tileDir, brick.size) + (vecFromList(tileDir) * depth) self.tileDir = tileDir if unglueThreshold == None: unglueThreshold = 5 if shatterThreshold == None: shatterThreshold = 10 dir = getNeutralDir() Box.__init__(self, world, parent, color, pos, dir, size, density, unglueThreshold, shatterLimit, shatterThreshold) self.thickness = thickness self.brick = brick self.brick.addTile(self) # Glue to brick. self.glue = OdeFixedJoint(self.world.world) self.glue.attachBodies(self.body, brick.body) self.glue.set() # Adjust collision bitmasks. self.geom.setCategoryBits(GameObject.bitmaskTileGlued) self.geom.setCollideBits(GameObject.bitmaskAll & ~GameObject.bitmaskBox & ~GameObject.bitmaskTileGlued & ~GameObject.bitmaskTile)
def __init__(self, brick, color, tileDir, thickness, density, unglueThreshold=None, shatterLimit=None, shatterThreshold=None, noSetup=False): if noSetup: return depth = thickness / 2 world = brick.world parent = brick.parent size = entrywiseMult(vecInvert(tileDir), brick.size) + (vecBasic(tileDir) * depth) pos = brick.node.getPos() + entrywiseMult( tileDir, brick.size) + (vecFromList(tileDir) * depth) self.tileDir = tileDir if unglueThreshold == None: unglueThreshold = 5 if shatterThreshold == None: shatterThreshold = 10 dir = getNeutralDir() Box.__init__(self, world, parent, color, pos, dir, size, density, unglueThreshold, shatterLimit, shatterThreshold) self.thickness = thickness self.brick = brick self.brick.addTile(self) # Glue to brick. self.glue = OdeFixedJoint(self.world.world) self.glue.attachBodies(self.body, brick.body) self.glue.set() # Adjust collision bitmasks. self.geom.setCategoryBits(GameObject.bitmaskTileGlued) self.geom.setCollideBits(GameObject.bitmaskAll & ~GameObject.bitmaskBox & ~GameObject.bitmaskTileGlued & ~GameObject.bitmaskTile)
def createWall(world, parent, color, pos, size, density, quantity, shatterLimit=None, tileThickness=None, tileShatterLimit=None): boxes = [] diffBase = vecFromList(size) * 2 dir = getNeutralDir() for i in range(quantity[0]): boxes.append([]) for j in range(quantity[1]): boxes[i].append([]) for k in range(quantity[2]): diff = Vec3(diffBase[0]*i, diffBase[1]*j, diffBase[2]*k) box = Box(world, parent, color, Vec3(*pos) + diff, dir, size, density, shatterLimit=shatterLimit) boxes[i][j].append(box) if tileThickness != None: box.makeTiles( xNeg = i == 0, xPos = i == quantity[0] - 1, yNeg = j == 0, yPos = j == quantity[1] - 1, zNeg = False, zPos = k == quantity[2] - 1, thickness = tileThickness, shatterLimit = tileShatterLimit) if i > 0: Cement(boxes[i][j][k], boxes[i-1][j][k]) if j > 0: Cement(boxes[i][j][k], boxes[i][j-1][k]) if k > 0: Cement(boxes[i][j][k], boxes[i][j][k-1]) if k == 0: Cement(boxes[i][k][k], None) return boxes