def initialize(): viz.phys.enable() viz.callback(viz.COLLIDE_BEGIN_EVENT, onBeginCollide) # Preload balloon model. preload = Balloon() preload.remove() time.clock() # The clock begins its count after the first call, so this ensures it starts at program start.
def newBalloon(randomY = False, recycle=None, thirdArmBalloon=False): if BCGlobals._randomScaling: newBalloonScale = random.uniform(BCGlobals.minBalloonScale, BCGlobals.maxBalloonScale) else: newBalloonScale = BCGlobals.balloonDefaultScale newBalloonRedColor = random.uniform(BCGlobals._currentColorScheme[0], BCGlobals._currentColorScheme[1]) newBalloonGreenColor = random.uniform(BCGlobals._currentColorScheme[0], BCGlobals._currentColorScheme[1]) newBalloonBlueColor = random.uniform(BCGlobals._currentColorScheme[0], BCGlobals._currentColorScheme[1]) newBalloonPosString = "" if BCGlobals.balloonPositionFile is not None: newBalloonPosString = BCGlobals.balloonPositionFile.readline() if newBalloonPosString == "": minDistOnX = random.choice([True, False]) # This variable ensures there's not a cross-shaped balloon dead-zone. if BCGlobals.minDistLocality is BCGlobals.MIN_DIST_X: minDistOnX = True if BCGlobals.minDistLocality is BCGlobals.MIN_DIST_Z: minDistOnX = False if not BCGlobals._useExponDist: newBalloonXPos = random.uniform(BCGlobals.minDistanceFromOrigin if minDistOnX else 0, BCGlobals.maxDistanceFromOrigin) else: newBalloonXPos = random.expovariate(1.0 / BCGlobals._expoMeanDist) if minDistOnX: newBalloonXPos += BCGlobals.minDistanceFromOrigin if newBalloonXPos > BCGlobals.maxDistanceFromOrigin: newBalloonXPos = BCGlobals.maxDistanceFromOrigin if random.choice([True, False]): newBalloonXPos = -newBalloonXPos if not BCGlobals._useExponDist: newBalloonZPos = random.uniform(BCGlobals.minDistanceFromOrigin if not minDistOnX else 0, BCGlobals.maxDistanceFromOrigin) else: newBalloonZPos = random.expovariate(1.0 / BCGlobals._expoMeanDist) if not minDistOnX: newBalloonZPos += BCGlobals.minDistanceFromOrigin if newBalloonZPos > BCGlobals.maxDistanceFromOrigin: newBalloonZPos = BCGlobals.maxDistanceFromOrigin if BCGlobals.balloonsAreOneSided: newBalloonZPos = -newBalloonZPos else: if random.choice([True, False]): newBalloonZPos = -newBalloonZPos newBalloonYPos = BCGlobals.lowAltitude if randomY: newBalloonYPos = random.uniform(BCGlobals.lowAltitude, BCGlobals.highAltitude - 0.1) else: newBalloonPos = eval(newBalloonPosString) newBalloonXPos = newBalloonPos[0] newBalloonYPos = newBalloonPos[1] newBalloonZPos = newBalloonPos[2] if thirdArmBalloon: newBalloonZPos -= BCGlobals.thirdArmDist # Still working on making sure balloons don't render inside other balloons. if recycle is None: recycle = Balloon(newBalloonScale, [newBalloonRedColor, newBalloonGreenColor, newBalloonBlueColor]) recycle._applyHandicap(BCGlobals._handicappedDart) else: recycle.setScale([newBalloonScale * Balloon._SCALE_NORMALIZER, newBalloonScale * Balloon._SCALE_NORMALIZER, newBalloonScale * Balloon._SCALE_NORMALIZER]) recycle.color([newBalloonRedColor, newBalloonGreenColor, newBalloonBlueColor]) recycle.ambient([newBalloonRedColor, newBalloonGreenColor, newBalloonBlueColor]) recycle.setPosition(newBalloonXPos + BCGlobals.balloonOrigin[0], newBalloonYPos, newBalloonZPos + BCGlobals.balloonOrigin[2]) if BCGlobals.noBalloonOverlap is True: intersects = viz.phys.intersectNode(recycle) if len(intersects) != 0: for object in intersects: if type(object) == Balloon: recycle = newBalloon(randomY, recycle) break return recycle