def createBallGeom(self, modelNode, ballBody, space): ballGeom = OdeSphereGeom(space, 1) ballGeom.setCollideBits(BitMask32(0x2)) ballGeom.setCategoryBits(BitMask32(0x1)) ballGeom.setBody(ballBody) space.setSurfaceType(ballGeom, SurfaceType.BALL) return ballGeom
def shoot(self): # TODO: add proper unit tests! angle = self.heading * math.pi / 180.0 headingX = math.cos(angle) headingY = math.sin(angle) offset = Vec3(headingX, headingY, 0) * Ship.BULLET_OFFSET shipPos = self.getPos() bulletPos = (offset[0] + shipPos[0], offset[1] + shipPos[1], offset[2]) bulletVisual = loader.loadModel("bullet.bam") bulletVisual.setPos(tupleToVec3(bulletPos)) bulletVisual.setHpr(tupleToVec3((self.heading + 90, 180))) bulletVisual.setScale(1.5) bulletVisual.reparentTo(self.bulletParent) # Create physics for bullet collisionSphere = OdeSphereGeom(1.5) collisionSphere.setCategoryBits(BitMask32(0xffffffff)) collisionSphere.setCollideBits(BitMask32(0xffffffff)) collisionSphere.setPosition(bulletPos[0], bulletPos[1], bulletPos[2]) shipVel = self.getVel() bullet = { 'vel': (headingX * Ship.BULLET_SPEED + shipVel[0] / Ship.BULLET_SHIP_SPEED_CORRELATION, headingY * Ship.BULLET_SPEED + shipVel[1] / Ship.BULLET_SHIP_SPEED_CORRELATION), 'visual': bulletVisual, 'physical': collisionSphere, 'isAlive': True, 'timeToLive': Ship.BULLET_MAX_LIFE_TIME } self.bullets.append(bullet) self.shootingSound.play()
def __init__( self, name=NAME_DEFAULT, pos=POS_DEFAULT, heading=HEADING_DEFAULT, vel=VEL_DEFAULT, acc=ACC_DEFAULT # player controlled acceleration. Can be 0.0 - 1.0 ): """@param name string""" self.name = name self.pos = pos self.vel = vel self.acc = acc self.heading = heading self.rotateLeft = False self.rotateRight = False self.visualNode = self.createVisualNode(self.pos) self.bullets = [] self.collisionHandler = colHandler self.collisions = [] self.collisionSphere = OdeSphereGeom(4) self.collisionSphere.setCategoryBits(BitMask32(0xffffffff)) self.collisionSphere.setCollideBits(BitMask32(0xffffffff)) self.collisionSphere.setPosition(pos[0], pos[1], 0) self.forces = [] self.mass = 1.0 self.health = Ship.HEALTH self.isAlive = True self.shootingSound = loader.loadSfx('anti_tank_gun_single_shot.mp3') self.destroySound = loader.loadSfx('large_explosion.mp3') self.bulletHitSound = loader.loadSfx( 'explosion_loud_internal_explosion_very_reverberant.mp3') self.collisionSound = loader.loadSfx('car_door_close.mp3') self.bulletParent = NodePath("Bullet Parent") self.bulletParent.reparentTo(render) self.bulletAmbientLight = AmbientLight('Bullet Light') self.bulletAmbientLight.setColor(Vec4(.0, .1, .2, .0)) lightnode = render.attachNewNode(self.bulletAmbientLight) self.bulletParent.setLight(lightnode)
def showGrab(self): self.nodePath.hide() self.collNodePath.hide() self.collNode.setIntoCollideMask(BitMask32(0)) if self.penalty: self.track = Parallel( SoundInterval(self.penaltyGrabSound), Sequence( Func(self.kaboom.showThrough), LerpScaleInterval(self.kaboom, duration=0.5, scale=Point3(10, 10, 10), blendType='easeOut'), Func(self.kaboom.hide))) self.track.start()
def setupToon(self): self.localAvatar.setName('Toon') self.localAvatar.setPythonTag('Avatar', self) geom = self.localAvatar.getGeomNode() geom.getChild(0).setSx(0.730000019073) geom.getChild(0).setSz(0.730000019073) base.localAvatar = self.localAvatar wallBitmask = BitMask32(1) floorBitmask = BitMask32(2) base.cTrav = CollisionTraverser() walkControls = GravityWalker(legacyLifter=True) walkControls.setWallBitMask(wallBitmask) walkControls.setFloorBitMask(floorBitmask) walkControls.setWalkSpeed(8.0, 20.0, 4.0, 20.0) walkControls.initializeCollisions(base.cTrav, self.localAvatar, floorOffset=0.025, reach=4.0) walkControls.setAirborneHeightFunc(self.getAirborneHeight) walkControls.enableAvatarControls() self.walkControls = walkControls self.localAvatar.physControls = walkControls self.localAvatar.physControls.placeOnFloor() self.setupPhysics() Hud(self) self.setupCamera() render.getPythonTag('WorldCollisions').addToonCollision()
def __init__(self, scene, dynamic=True, rate=(0.005, 0.05), texturescale=(1000, 1000), scale=(40, 40, 10), texturefile=None): Att_base.__init__(self, False, "Sky Dome 1") self.skybox = loader.loadModel("../media/models/dome2") self.skybox.setCollideMask(BitMask32().allOff()) self.skybox.setTwoSided(False) self.skybox.setScale(scale[0], scale[1], scale[2]) self.skybox.setLightOff() if texturefile == None: texturefile = "../media/textures/concrete.jpg" texture = loader.loadTexture(texturefile) self.textureStage0 = TextureStage("stage0") self.textureStage0.setMode(TextureStage.MReplace) self.skybox.setTexture(self.textureStage0, texture, 1) self.skybox.setTexScale(self.textureStage0, texturescale[0], texturescale[1]) self.skybox.reparentTo(scene)
CogStartingPositions = (VBase3(35, 18, 0), VBase3(35, 0, 0), VBase3(35, -18, 0), VBase3(-35, 18, 0), VBase3(-35, 0, 0), VBase3(-35, -18, 0), VBase3(0, 27, 0), VBase3(0, -27, 0), VBase3(35, 9, 0), VBase3(-35, 9, 0), VBase3(35, -9, 0), VBase3(-35, -9, 0)) CogReturnPositions = (VBase3(-35, 28, 0), VBase3(-14, 28, 0), VBase3(14, 28, 0), VBase3(35, 28, 0), VBase3(35, 0, 0), VBase3(35, -28, 0), VBase3(-14, -28, 0), VBase3(14, -28, 0), VBase3(-35, -28, 0), VBase3(-35, 0, 0)) StageHalfWidth = 25 StageHalfHeight = 18 NoGoal = 0 BarrelGoal = 1 ToonGoal = 2 RunAwayGoal = 3 InvalidGoalId = -1 GoalStr = { NoGoal: 'NoGoal', BarrelGoal: 'BarrelGoal', ToonGoal: 'ToonGoal', RunAwayGoal: 'RunAwayGoal', InvalidGoalId: 'InvalidGoa' } BarrelBitmask = BitMask32(512) BarrelOnGround = -1 NoBarrelCarried = -1 LyingDownDuration = 2.0 MAX_SCORE = 20 MIN_SCORE = 3 def calcScore(t): range = MAX_SCORE - MIN_SCORE score = range * (float(t) / GameTime) + MIN_SCORE return int(score + 0.5) def getMaxScore(): result = calcScore(GameTime) return result
def disable(self): self.ignore('enter' + self.getName()) self.collNode.setFromCollideMask(BitMask32(0))
def __disableCollisions(self): self.ignore('enterPartyGateSphere') self.partyGateSphere.setCollideMask(BitMask32(0))
# ToonDatabaseChannelId #'DistributedPlayerToon': ToonDatabaseChannelId, # DoodleDatabaseChannelId #'DistributedDoodle': DoodleDatabaseChannelId, } # Toontown specific camera FOVs CogHQCameraFov = 60.0 BossBattleCameraFov = 72.0 MakeAToonCameraFov = 52.0 # Things we can throw a pie at. (Pies also react to CameraBitmask and # FloorBitmask, but not WallBitmask.): # Brought in from OTPGlobals PieBitmask = BitMask32(0x100) # Pets avoid this PetBitmask = BitMask32(0x08) # For the catching minigame: CatchGameBitmask = BitMask32(0x10) # Things the magnet can pick up in the Cashbot CFO battle (same as # CatchGameBitmask): CashbotBossObjectBitmask = BitMask32(0x10) # These are used by the furniture mover: FurnitureSideBitmask = BitMask32(0x20) FurnitureTopBitmask = BitMask32(0x40) FurnitureDragBitmask = BitMask32(0x80)
#!/usr/bin/python from direct.showbase.ShowBase import ShowBase from direct.showbase.DirectObject import DirectObject from direct.actor.Actor import Actor from pandac.PandaModules import loadPrcFileData, BitMask32 loadPrcFileData('', 'win-size 960 600') loadPrcFileData('', 'interpolate-frames 1') loadPrcFileData('', 'notify-level-collide debug') FLOOR_MASK = BitMask32(1) OBSTACLE_MASK = BitMask32(2) ZONE_MASK = BitMask32(4) def clamp_deg_sign(heading): return (heading + 180) % 360 - 180 def avg_deg_sign(heading1, heading2): if heading2 - heading1 > 180: heading2 -= 360 if heading2 - heading1 < -180: heading2 += 360 return clamp_deg_sign(.85 * heading1 + .15 * heading2) class Character(DirectObject): def __init__(self, name, char_rig): from pandac.PandaModules import CollisionNode, CollisionRay, CollisionSphere self.name = name
# These can be set for debugging but should be blank for releases DEFAULT_USERNAME = "******" DEFAULT_PASSWORD = "******" # Game board settings BOARDRADIUS = 50 GRIDINTERVAL = 3 LINETHICKNESS = 1 GRIDCOLOR = (0, 1, 0, 0) MAP_PATH = './maps/' #base.appRunner.multifileRoot+'/maps/' MAP_TYPE = 'XML' # Options 'xml', 'pickle' MAP_EXT = '.map' # Deprecated # Collision bitmasks goodMask = BitMask32(0x1) badMask = BitMask32(0x2) floorMask = BitMask32(0x4) EVENTS = [ 'E_All', 'E_Mouse_1', 'E_Mouse_1_Up', 'E_Mouse_2', 'E_Mouse_2_Up', 'E_Mouse_3', 'E_Mouse_3_Up', 'E_MouseWheel_Up', 'E_MouseWheel_Down', 'E_Key_CameraUp', 'E_Key_CameraUp-up', 'E_Key_CameraDown', 'E_Key_CameraDown-up', 'E_Key_CameraLeft', 'E_Key_CameraLeft-up', 'E_Key_CameraRight', 'E_Key_CameraRight-up', 'E_Key_ZUp', 'E_Key_ZDown', 'E_Key_ZUp-up', 'E_Key_ZDown-up', 'E_Key_Move', 'E_Key_Exit', 'E_New_Entity', 'E_New_EntityRep', 'E_EntitySelect', 'E_EntityUnSelect', 'E_UpdateGUI', 'E_StartGame', 'E_EndTurn', 'E_ExitGame', 'E_ExitProgram' ]
from pandac.PandaModules import BitMask32 WallBitmask = BitMask32(1) FloorBitmask = BitMask32(2) CameraBitmask = BitMask32(4) CameraTransparentBitmask = BitMask32(8) SafetyNetBitmask = BitMask32(512) SafetyGateBitmask = BitMask32(1024) GhostBitmask = BitMask32(2048) PathFindingBitmask = BitMask32.bit(29) PickerBitmask = BitMask32(4096) CeilingBitmask = BitMask32(256) FloorEventBitmask = BitMask32(16) PieBitmask = BitMask32(256) PetBitmask = BitMask32(8) CatchGameBitmask = BitMask32(16) CashbotBossObjectBitmask = BitMask32(16) FurnitureSideBitmask = BitMask32(32) FurnitureTopBitmask = BitMask32(64) FurnitureDragBitmask = BitMask32(128) PetLookatPetBitmask = BitMask32(256) PetLookatNonPetBitmask = BitMask32(512) BanquetTableBitmask = BitMask32(1024)
class DistributedIceWorld( DistributedMinigamePhysicsWorld.DistributedMinigamePhysicsWorld): """Base class client minigame physics. Should not have any hardcoded info which is specific to a given game. """ notify = DirectNotifyGlobal.directNotify.newCategory( "DistributedMinigamePhysicsWorld") # ODE Collision bits # 0 - floor # 1 - fence # 2 # 3 # 4 # 5 # 6 # 7 # 8 - tire 0 # 9 - tire 1 # 10 - tire 2 # 11 - tire 3 floorCollideId = 1 floorMask = BitMask32(floorCollideId) wallCollideId = 1 << 1 wallMask = BitMask32(wallCollideId) obstacleCollideId = 1 << 2 obstacleMask = BitMask32(obstacleCollideId) tireCollideIds = [1 << 8, 1 << 9, 1 << 10, 1 << 11] tire0Mask = BitMask32(tireCollideIds[0]) tire1Mask = BitMask32(tireCollideIds[1]) tire2Mask = BitMask32(tireCollideIds[2]) tire3Mask = BitMask32(tireCollideIds[3]) allTiresMask = tire0Mask | tire1Mask | tire2Mask | tire3Mask tireMasks = (tire0Mask, tire1Mask, tire2Mask, tire3Mask) tireDensity = 1 # 1 kg per foot cubed tireSurfaceType = 0 iceSurfaceType = 1 fenceSurfaceType = 2 #tireCollideId = 1 << 12 def __init__(self, cr): """Create the Ice world.""" DistributedMinigamePhysicsWorld.DistributedMinigamePhysicsWorld.__init__( self, cr) def delete(self): """Remove ourself from the world.""" DistributedMinigamePhysicsWorld.DistributedMinigamePhysicsWorld.delete( self) if hasattr(self, 'floor'): # the floor seems to be destroyed automatically in ODE 0.9 # at least I see the number of constructors and destructors match up # self.floor.destroy() # we get a c++ crash now if we call this self.floor = None def setupSimulation(self): """Setup the ice game specific parameters.""" DistributedMinigamePhysicsWorld.DistributedMinigamePhysicsWorld.setupSimulation( self) # toontown uses feet, 1 meter = 3.2808399 feet # for this game lets express mass in kilograms # so gravity at 9.8 meters per seconds squared becomes self.world.setGravity(0, 0, -32.174) # ODE's default is meter, kilograms, seconds, let's change the defaults # do we need to change global ERP value, # that controls how much error correction is performed in each time step # default is 0.2 self.world.setAutoDisableFlag(1) # lets try auto disable self.world.setAutoDisableLinearThreshold(0.5 * MetersToFeet) # skipping AutoDisableAngularThreshold as that is radians per second # self.world.setAutoDisableAngularThreshold(0.01) # don't consider rotation for auto disable self.world.setAutoDisableAngularThreshold(OdeUtil.getInfinity()) self.world.setAutoDisableSteps(10) # Set and the global CFM (constraint force mixing) value. # Typical values are in the range 10-9 -- 1. # The default is 10-5 if single precision is being used self.world.setCfm(1E-5 * MetersToFeet) # Our surfaces # 0 = tire # 1 = ice # 2 = fence self.world.initSurfaceTable(3) # 3 types of surfaces # PN_uint8 pos1, PN_uint8 pos2, - surface0, surface1 # dReal mu, - 0 frictionless, 1 infinite friction # dReal bounce, # Restitution parameter 0 not bouncy, 1 max bouncy # dReal bounce_vel, #The minimum incoming velocity necessary for bounce. # Incoming velocities below this will # effectively have a bounce parameter of 0. # dReal soft_erp, # Contact normal "softness" parameter. # dReal soft_cfm, # Contact normal "softness" paramete # dReal slip, # The coefficients of force-dependent-slip (FDS) # dReal dampen) # dampening constant # the most usual collision, tire against ice self.world.setSurfaceEntry( 0, 1, 0.2, # near frictionless 0, # not bouncy 0, # bounce_vel 0, # soft_erp 0, # soft_cfm 0, # slip 0.1, # dampen ) # tire against tire self.world.setSurfaceEntry( 0, 0, 0.1, # friction 0.9, # bounciness 0.1, # bounce_vel 0, # soft_erp 0, # soft_cfm 0, # slip 0, # dampen ) # tire against fence self.world.setSurfaceEntry( 0, 2, 0.9, # friction 0.9, # bounciness 0.1, # bounce_vel 0, # soft_erp 0, # soft_cfm 0, # slip 0, # dampen ) # Create a plane geom which prevent the objects from falling forever self.floor = OdePlaneGeom(self.space, Vec4(0.0, 0.0, 1.0, -20.0)) self.floor.setCollideBits( self.allTiresMask) # we only collide against tires self.floor.setCategoryBits(self.floorMask) # normal pointing towards +x axis self.westWall = OdePlaneGeom( self.space, Vec4(1.0, 0.0, 0.0, IceGameGlobals.MinWall[0])) self.westWall.setCollideBits( self.allTiresMask) # we only collide against tires self.westWall.setCategoryBits(self.wallMask) self.space.setSurfaceType(self.westWall, self.fenceSurfaceType) self.space.setCollideId(self.westWall, self.wallCollideId) # normal pointing towards -x axis self.eastWall = OdePlaneGeom( self.space, Vec4(-1.0, 0.0, 0.0, -IceGameGlobals.MaxWall[0])) self.eastWall.setCollideBits( self.allTiresMask) # we only collide against tires self.eastWall.setCategoryBits(self.wallMask) self.space.setSurfaceType(self.eastWall, self.fenceSurfaceType) self.space.setCollideId(self.eastWall, self.wallCollideId) # normal pointing toward the +y axis self.southWall = OdePlaneGeom( self.space, Vec4(0.0, 1.0, 0.0, IceGameGlobals.MinWall[1])) self.southWall.setCollideBits( self.allTiresMask) # we only collide against tires self.southWall.setCategoryBits(self.wallMask) self.space.setSurfaceType(self.southWall, self.fenceSurfaceType) self.space.setCollideId(self.southWall, self.wallCollideId) # normal pointing toward the -y axis self.northWall = OdePlaneGeom( self.space, Vec4(0.0, -1.0, 0.0, -IceGameGlobals.MaxWall[1])) self.northWall.setCollideBits( self.allTiresMask) # we only collide against tires self.northWall.setCategoryBits(self.wallMask) self.space.setSurfaceType(self.northWall, self.fenceSurfaceType) self.space.setCollideId(self.northWall, self.wallCollideId) # a temporary floor at z=0, until we implement ice with holes self.floorTemp = OdePlaneGeom(self.space, Vec4(0.0, 0.0, 1.0, 0.0)) self.floorTemp.setCollideBits( self.allTiresMask) # we only collide against tires self.floorTemp.setCategoryBits(self.floorMask) self.space.setSurfaceType(self.floorTemp, self.iceSurfaceType) self.space.setCollideId(self.floorTemp, self.floorCollideId) self.space.setAutoCollideWorld(self.world) self.space.setAutoCollideJointGroup(self.contactgroup) self.totalPhysicsSteps = 0 def createTire(self, tireIndex): """Create one physics tire. Returns a (nodePath, OdeBody, OdeGeom) tuple""" if (tireIndex < 0) or (tireIndex >= len(self.tireMasks)): self.notify.error('invalid tireIndex %s' % tireIndex) self.notify.debug("create tireindex %s" % (tireIndex)) zOffset = 0 # for now the tires are spheres body = OdeBody(self.world) mass = OdeMass() mass.setSphere(self.tireDensity, IceGameGlobals.TireRadius) body.setMass(mass) body.setPosition(IceGameGlobals.StartingPositions[tireIndex][0], IceGameGlobals.StartingPositions[tireIndex][1], IceGameGlobals.StartingPositions[tireIndex][2]) #body.setAutoDisableFlag(1) #body.setAutoDisableLinearThreshold(1.01 * MetersToFeet) # skipping AutoDisableAngularThreshold as that is radians per second #body.setAutoDisableAngularThreshold(0.1) body.setAutoDisableDefaults() geom = OdeSphereGeom(self.space, IceGameGlobals.TireRadius) self.space.setSurfaceType(geom, self.tireSurfaceType) self.space.setCollideId(geom, self.tireCollideIds[tireIndex]) self.massList.append(mass) self.geomList.append(geom) # a tire collides against other tires, the wall and the floor geom.setCollideBits(self.allTiresMask | self.wallMask | self.floorMask | self.obstacleMask) geom.setCategoryBits(self.tireMasks[tireIndex]) geom.setBody(body) if self.notify.getDebug(): self.notify.debug('tire geom id') geom.write() self.notify.debug(' -') if self.canRender: testTire = render.attachNewNode("tire holder %d" % tireIndex) smileyModel = NodePath( ) # loader.loadModel('models/misc/smiley') # smiley! if not smileyModel.isEmpty(): smileyModel.setScale(IceGameGlobals.TireRadius) smileyModel.reparentTo(testTire) smileyModel.setAlphaScale(0.5) smileyModel.setTransparency(1) testTire.setPos(IceGameGlobals.StartingPositions[tireIndex]) #debugAxis = loader.loadModel('models/misc/xyzAxis') if 0: #not debugAxis.isEmpty(): debugAxis.reparentTo(testTire) debugAxis.setScale(IceGameGlobals.TireRadius / 10.0) debugAxis2 = loader.loadModel('models/misc/xyzAxis') debugAxis2.reparentTo(testTire) debugAxis2.setScale(-IceGameGlobals.TireRadius / 10.0) # lets create a black tire #tireModel = loader.loadModel('phase_3/models/misc/sphere') tireModel = loader.loadModel( "phase_4/models/minigames/ice_game_tire") # assuming it has a radius of 1 tireHeight = 1 #tireModel.setScale(IceGameGlobals.TireRadius, IceGameGlobals.TireRadius, 1) #tireModel.setZ( 0 - IceGameGlobals.TireRadius + (tireHeight /2.0)) #tireModel.setColor(0,0,0) tireModel.setZ(-IceGameGlobals.TireRadius + 0.01) tireModel.reparentTo(testTire) #tireModel.setAlphaScale(0.5) #tireModel.setTransparency(1) self.odePandaRelationList.append((testTire, body)) else: testTire = None self.bodyList.append((None, body)) return testTire, body, geom def placeBodies(self): """Make the nodePaths match up to the physics bodies.""" # lets see if a sphere can simulate a tire by just taking out P and R for pair in self.odePandaRelationList: pandaNodePathGeom = pair[0] odeBody = pair[1] if pandaNodePathGeom: pandaNodePathGeom.setPos(odeBody.getPosition()) # rotation = (odeBody.getRotation() * (180.0/math.pi)) pandaNodePathGeom.setQuat( Quat(odeBody.getQuaternion()[0], odeBody.getQuaternion()[1], odeBody.getQuaternion()[2], odeBody.getQuaternion()[3])) pandaNodePathGeom.setP(0) pandaNodePathGeom.setR(0) newQuat = pandaNodePathGeom.getQuat() odeBody.setQuaternion(newQuat) def postStep(self): """Called after one physics step.""" # since we change the bodie's rotation, make sure that it's called # every step so that it is deterministic and syncs correctly DistributedMinigamePhysicsWorld.DistributedMinigamePhysicsWorld.postStep( self) self.placeBodies() self.totalPhysicsSteps += 1 def createObstacle(self, pos, obstacleIndex, cubicObstacle): """Create one physics obstacle. Returns a nodePath """ if cubicObstacle: return self.createCubicObstacle(pos, obstacleIndex) else: return self.createCircularObstacle(pos, obstacleIndex) def createCircularObstacle(self, pos, obstacleIndex): """Create one physics obstacle. Returns a nodePath""" self.notify.debug("create obstacleindex %s" % (obstacleIndex)) geom = OdeSphereGeom(self.space, IceGameGlobals.TireRadius) geom.setCollideBits(self.allTiresMask) # we only collide against tires geom.setCategoryBits(self.obstacleMask) self.space.setCollideId(geom, self.obstacleCollideId) #tireModel = loader.loadModel('phase_3/models/misc/sphere') tireModel = loader.loadModel( "phase_4/models/minigames/ice_game_tirestack") # assuming it has a radius of 1 tireHeight = 1 #tireModel.setScale(IceGameGlobals.TireRadius, IceGameGlobals.TireRadius, IceGameGlobals.TireRadius) #tireModel.setZ( 0 - IceGameGlobals.TireRadius + (tireHeight /2.0)) #tireModel.setZ(IceGameGlobals.TireRadius) tireModel.setPos(pos) #tireModel.setColor(0.5,0.5,0.5) tireModel.reparentTo(render) geom.setPosition(tireModel.getPos()) # the real assets are set at Z zero tireModel.setZ(0) return tireModel def createCubicObstacle(self, pos, obstacleIndex): """Create one physics obstacle. Returns a nodePath""" self.notify.debug("create obstacleindex %s" % (obstacleIndex)) sideLength = IceGameGlobals.TireRadius * 2 geom = OdeBoxGeom(self.space, sideLength, sideLength, sideLength) geom.setCollideBits(self.allTiresMask) # we only collide against tires geom.setCategoryBits(self.obstacleMask) self.space.setCollideId(geom, self.obstacleCollideId) #tireModel = render.attachNewNode('cubicObstacle-%d'% obstacleIndex) #BuildGeometry.addBoxGeom(tireModel, sideLength, sideLength, sideLength) #tireModel.setPos(pos) #tireModel.setColor(0.5,0.5,0.5) tireModel = loader.loadModel("phase_4/models/minigames/ice_game_crate") tireModel.setPos(pos) tireModel.reparentTo(render) geom.setPosition(tireModel.getPos()) # the real assets are set at Z zero tireModel.setZ(0) return tireModel
TugOfWarTieReward = 5 TugOfWarTieThreshold = 0.75 # if the teams moved this much or less from their # start position, consider it a tie ### Party Trampoline TrampolineDuration = 60.0 # kick you off the trampoline after this long TrampolineSignOffset = Point3(-6.0, -6.0, 0.0) TrampolineLeverOffset = Point3(-5.0, -9.0, 0.0) TrampolineNumJellyBeans = 12 TrampolineJellyBeanBonus = 10 ### Party Catch # this is the duration of the tag game music... CatchActivityDuration = 55.0 # TODO-Shawn : Changing this does not end dropping CatchActivityBitmask = BitMask32(0x10) CatchLeverOffset = Point3(-3.0, -2.0, 0.0) # offset from sign's position CatchDropShadowHeight = 0.5 CatchConclusionDuration = 3.0 # this class is purely for syntactic convenience; # with it, we can reference properties of drop object types by name # 'name' == name of the drop object # 'good' == is this a good thing to catch # onscreenDurMult is how many times longer the object should take to fall, # once on-screen, than baseline objects (durationMult==1.) # For instance, an object type with an onscreenDurMult of .5 will be # on-screen half as long as a baseline object. class DropObject: def __init__(self, name, good, onscreenDurMult, modelPath):
def collides(a, b, acat, bcat): return (BitMask32(acat) & BitMask32(b)) | (BitMask32(bcat) & BitMask32(a)) != BitMask32(0)
def __disableCollisions(self): # stop listening for toons. self.ignore('enterPartyGateSphere') self.partyGateSphere.setCollideMask(BitMask32(0))
NoGoal = 0 BarrelGoal = 1 ToonGoal = 2 RunAwayGoal = 3 InvalidGoalId = -1 # since these are debugging strings, not using them in TTLocalizer GoalStr = { NoGoal: 'NoGoal', BarrelGoal: 'BarrelGoal', ToonGoal: 'ToonGoal', RunAwayGoal: 'RunAwayGoal', InvalidGoalId: 'InvalidGoa', } BarrelBitmask = BitMask32(0x200) BarrelOnGround = -1 NoBarrelCarried = -1 LyingDownDuration = 2.0 # how many seconds to keep him down MAX_SCORE = 20 MIN_SCORE = 3 def calcScore(t): """ t: time in seconds since game start """ range = MAX_SCORE - MIN_SCORE score = (range * (float(t) / GameTime) + MIN_SCORE) return int(score + .5)
class DistributedIceWorld( DistributedMinigamePhysicsWorld.DistributedMinigamePhysicsWorld): notify = DirectNotifyGlobal.directNotify.newCategory( 'DistributedMinigamePhysicsWorld') floorCollideId = 1 floorMask = BitMask32(floorCollideId) wallCollideId = 1 << 1 wallMask = BitMask32(wallCollideId) obstacleCollideId = 1 << 2 obstacleMask = BitMask32(obstacleCollideId) tireCollideIds = [1 << 8, 1 << 9, 1 << 10, 1 << 11] tire0Mask = BitMask32(tireCollideIds[0]) tire1Mask = BitMask32(tireCollideIds[1]) tire2Mask = BitMask32(tireCollideIds[2]) tire3Mask = BitMask32(tireCollideIds[3]) allTiresMask = tire0Mask | tire1Mask | tire2Mask | tire3Mask tireMasks = (tire0Mask, tire1Mask, tire2Mask, tire3Mask) tireDensity = 1 tireSurfaceType = 0 iceSurfaceType = 1 fenceSurfaceType = 2 def __init__(self, cr): DistributedMinigamePhysicsWorld.DistributedMinigamePhysicsWorld.__init__( self, cr) def delete(self): DistributedMinigamePhysicsWorld.DistributedMinigamePhysicsWorld.delete( self) if hasattr(self, 'floor'): self.floor = None return def setupSimulation(self): DistributedMinigamePhysicsWorld.DistributedMinigamePhysicsWorld.setupSimulation( self) self.world.setGravity(0, 0, -32.174) self.world.setAutoDisableFlag(1) self.world.setAutoDisableLinearThreshold(0.5 * MetersToFeet) self.world.setAutoDisableAngularThreshold(OdeUtil.getInfinity()) self.world.setAutoDisableSteps(10) self.world.setCfm(1e-05 * MetersToFeet) self.world.initSurfaceTable(3) self.world.setSurfaceEntry(0, 1, 0.2, 0, 0, 0, 0, 0, 0.1) self.world.setSurfaceEntry(0, 0, 0.1, 0.9, 0.1, 0, 0, 0, 0) self.world.setSurfaceEntry(0, 2, 0.9, 0.9, 0.1, 0, 0, 0, 0) self.floor = OdePlaneGeom(self.space, Vec4(0.0, 0.0, 1.0, -20.0)) self.floor.setCollideBits(self.allTiresMask) self.floor.setCategoryBits(self.floorMask) self.westWall = OdePlaneGeom( self.space, Vec4(1.0, 0.0, 0.0, IceGameGlobals.MinWall[0])) self.westWall.setCollideBits(self.allTiresMask) self.westWall.setCategoryBits(self.wallMask) self.space.setSurfaceType(self.westWall, self.fenceSurfaceType) self.space.setCollideId(self.westWall, self.wallCollideId) self.eastWall = OdePlaneGeom( self.space, Vec4(-1.0, 0.0, 0.0, -IceGameGlobals.MaxWall[0])) self.eastWall.setCollideBits(self.allTiresMask) self.eastWall.setCategoryBits(self.wallMask) self.space.setSurfaceType(self.eastWall, self.fenceSurfaceType) self.space.setCollideId(self.eastWall, self.wallCollideId) self.southWall = OdePlaneGeom( self.space, Vec4(0.0, 1.0, 0.0, IceGameGlobals.MinWall[1])) self.southWall.setCollideBits(self.allTiresMask) self.southWall.setCategoryBits(self.wallMask) self.space.setSurfaceType(self.southWall, self.fenceSurfaceType) self.space.setCollideId(self.southWall, self.wallCollideId) self.northWall = OdePlaneGeom( self.space, Vec4(0.0, -1.0, 0.0, -IceGameGlobals.MaxWall[1])) self.northWall.setCollideBits(self.allTiresMask) self.northWall.setCategoryBits(self.wallMask) self.space.setSurfaceType(self.northWall, self.fenceSurfaceType) self.space.setCollideId(self.northWall, self.wallCollideId) self.floorTemp = OdePlaneGeom(self.space, Vec4(0.0, 0.0, 1.0, 0.0)) self.floorTemp.setCollideBits(self.allTiresMask) self.floorTemp.setCategoryBits(self.floorMask) self.space.setSurfaceType(self.floorTemp, self.iceSurfaceType) self.space.setCollideId(self.floorTemp, self.floorCollideId) self.space.setAutoCollideWorld(self.world) self.space.setAutoCollideJointGroup(self.contactgroup) self.totalPhysicsSteps = 0 def createTire(self, tireIndex): if tireIndex < 0 or tireIndex >= len(self.tireMasks): self.notify.error('invalid tireIndex %s' % tireIndex) self.notify.debug('create tireindex %s' % tireIndex) zOffset = 0 body = OdeBody(self.world) mass = OdeMass() mass.setSphere(self.tireDensity, IceGameGlobals.TireRadius) body.setMass(mass) body.setPosition(IceGameGlobals.StartingPositions[tireIndex][0], IceGameGlobals.StartingPositions[tireIndex][1], IceGameGlobals.StartingPositions[tireIndex][2]) body.setAutoDisableDefaults() geom = OdeSphereGeom(self.space, IceGameGlobals.TireRadius) self.space.setSurfaceType(geom, self.tireSurfaceType) self.space.setCollideId(geom, self.tireCollideIds[tireIndex]) self.massList.append(mass) self.geomList.append(geom) geom.setCollideBits(self.allTiresMask | self.wallMask | self.floorMask | self.obstacleMask) geom.setCategoryBits(self.tireMasks[tireIndex]) geom.setBody(body) if self.notify.getDebug(): self.notify.debug('tire geom id') geom.write() self.notify.debug(' -') if self.canRender: testTire = render.attachNewNode('tire holder %d' % tireIndex) smileyModel = NodePath() if not smileyModel.isEmpty(): smileyModel.setScale(IceGameGlobals.TireRadius) smileyModel.reparentTo(testTire) smileyModel.setAlphaScale(0.5) smileyModel.setTransparency(1) testTire.setPos(IceGameGlobals.StartingPositions[tireIndex]) tireModel = loader.loadModel( 'phase_4/models/minigames/ice_game_tire') tireHeight = 1 tireModel.setZ(-IceGameGlobals.TireRadius + 0.01) tireModel.reparentTo(testTire) self.odePandaRelationList.append((testTire, body)) else: testTire = None self.bodyList.append((None, body)) return testTire, body, geom def placeBodies(self): for pair in self.odePandaRelationList: pandaNodePathGeom = pair[0] odeBody = pair[1] if pandaNodePathGeom: pandaNodePathGeom.setPos(odeBody.getPosition()) pandaNodePathGeom.setQuat( Quat(odeBody.getQuaternion()[0], odeBody.getQuaternion()[1], odeBody.getQuaternion()[2], odeBody.getQuaternion()[3])) pandaNodePathGeom.setP(0) pandaNodePathGeom.setR(0) newQuat = pandaNodePathGeom.getQuat() odeBody.setQuaternion(newQuat) def postStep(self): DistributedMinigamePhysicsWorld.DistributedMinigamePhysicsWorld.postStep( self) self.placeBodies() self.totalPhysicsSteps += 1 def createObstacle(self, pos, obstacleIndex, cubicObstacle): if cubicObstacle: return self.createCubicObstacle(pos, obstacleIndex) else: return self.createCircularObstacle(pos, obstacleIndex) def createCircularObstacle(self, pos, obstacleIndex): self.notify.debug('create obstacleindex %s' % obstacleIndex) geom = OdeSphereGeom(self.space, IceGameGlobals.TireRadius) geom.setCollideBits(self.allTiresMask) geom.setCategoryBits(self.obstacleMask) self.space.setCollideId(geom, self.obstacleCollideId) tireModel = loader.loadModel( 'phase_4/models/minigames/ice_game_tirestack') tireHeight = 1 tireModel.setPos(pos) tireModel.reparentTo(render) geom.setPosition(tireModel.getPos()) tireModel.setZ(0) return tireModel def createCubicObstacle(self, pos, obstacleIndex): self.notify.debug('create obstacleindex %s' % obstacleIndex) sideLength = IceGameGlobals.TireRadius * 2 geom = OdeBoxGeom(self.space, sideLength, sideLength, sideLength) geom.setCollideBits(self.allTiresMask) geom.setCategoryBits(self.obstacleMask) self.space.setCollideId(geom, self.obstacleCollideId) tireModel = loader.loadModel('phase_4/models/minigames/ice_game_crate') tireModel.setPos(pos) tireModel.reparentTo(render) geom.setPosition(tireModel.getPos()) tireModel.setZ(0) return tireModel
TugOfWarSplashZOffset = 1.0 TugOfWarHeadings = [240.0, 120.0] TugOfWarConclusionDuration = 4.0 TugOfWarFallInWinReward = 15 TugOfWarFallInLossReward = 4 TugOfWarWinReward = 12 TugOfWarLossReward = 8 TugOfWarTieReward = 5 TugOfWarTieThreshold = 0.75 TrampolineDuration = 60.0 TrampolineSignOffset = Point3(-6.0, -6.0, 0.0) TrampolineLeverOffset = Point3(-5.0, -9.0, 0.0) TrampolineNumJellyBeans = 12 TrampolineJellyBeanBonus = 10 CatchActivityDuration = 80 CatchActivityBitmask = BitMask32(16) CatchLeverOffset = Point3(-3.0, -2.0, 0.0) CatchDropShadowHeight = 0.5 CatchConclusionDuration = 3.0 class DropObject: def __init__(self, name, good, onscreenDurMult, modelPath): self.name = name self.good = good self.onscreenDurMult = onscreenDurMult self.modelPath = modelPath def isBaseline(self): return self.onscreenDurMult == 1.0
def disable(self): self.ignoreAll() self.collNode.setIntoCollideMask(BitMask32(0))
# Python bytecode 2.4 (62061) # Decompiled from: Python 2.7.15 (v2.7.15:ca079a3ea3, Apr 30 2018, 16:30:26) [MSC v.1500 64 bit (AMD64)] # Embedded file name: toontown.toonbase.ToontownGlobals import TTLocalizer from otp.otpbase.OTPGlobals import * from direct.showbase.PythonUtil import Enum, invertDict from pandac.PandaModules import BitMask32, Vec4 AccountDatabaseChannelId = 4008 ToonDatabaseChannelId = 4021 DoodleDatabaseChannelId = 4023 DefaultDatabaseChannelId = AccountDatabaseChannelId DatabaseIdFromClassName = {'Account': AccountDatabaseChannelId} CogHQCameraFov = 60.0 BossBattleCameraFov = 72.0 MakeAToonCameraFov = 35.0 PieBitmask = BitMask32(256) PetBitmask = BitMask32(8) CatchGameBitmask = BitMask32(16) CashbotBossObjectBitmask = BitMask32(16) FurnitureSideBitmask = BitMask32(32) FurnitureTopBitmask = BitMask32(64) FurnitureDragBitmask = BitMask32(128) PetLookatPetBitmask = BitMask32(256) PetLookatNonPetBitmask = BitMask32(512) FullPies = 65535 CogHQCameraFar = 900.0 CogHQCameraNear = 1.0 CashbotHQCameraFar = 2000.0 CashbotHQCameraNear = 1.0 LawbotHQCameraFar = 3000.0 LawbotHQCameraNear = 1.0
MapHotkeyOff = 'alt-up' MapHotkey = 'alt' AccountDatabaseChannelId = 4008 ToonDatabaseChannelId = 4021 DoodleDatabaseChannelId = 4023 DefaultDatabaseChannelId = AccountDatabaseChannelId DatabaseIdFromClassName = {'Account': AccountDatabaseChannelId} CogHQCameraFov = 60.0 BossBattleCameraFov = 72.0 MakeAToonCameraFov = 48.0 VPElevatorFov = 53.0 CFOElevatorFov = 43.0 CJElevatorFov = 59.0 CEOElevatorFov = 59.0 CBElevatorFov = 42.0 CeilingBitmask = BitMask32(256) FloorEventBitmask = BitMask32(16) PieBitmask = BitMask32(256) PetBitmask = BitMask32(8) CatchGameBitmask = BitMask32(16) CashbotBossObjectBitmask = BitMask32(16) FurnitureSideBitmask = BitMask32(32) FurnitureTopBitmask = BitMask32(64) FurnitureDragBitmask = BitMask32(128) PetLookatPetBitmask = BitMask32(256) PetLookatNonPetBitmask = BitMask32(512) BanquetTableBitmask = BitMask32(1024) FullPies = 65535 CogHQCameraFar = 900.0 CogHQCameraNear = 1.0 CashbotHQCameraFar = 2000.0
for i in range(15): # Setup the geometry ballNP = ball.copyTo(render) ballNP.setPos(randint(-7, 7), randint(-7, 7), 10 + random() * 5.0) ballNP.setColor(random(), random(), random(), 1) ballNP.setHpr(randint(-45, 45), randint(-45, 45), randint(-45, 45)) # Create the body and set the mass ballBody = OdeBody(world) M = OdeMass() M.setSphere(50, 1) ballBody.setMass(M) ballBody.setPosition(ballNP.getPos(render)) ballBody.setQuaternion(ballNP.getQuat(render)) # Create a ballGeom ballGeom = OdeSphereGeom(space, 1) ballGeom.setCollideBits(BitMask32(0x00000001)) ballGeom.setCategoryBits(BitMask32(0x00000001)) ballGeom.setBody(ballBody) # Create the sound ballSound = loader.loadSfx("audio/sfx/GUI_rollover.wav") balls.append((ballNP, ballGeom, ballSound)) # Add a plane to collide with cm = CardMaker("ground") cm.setFrame(-20, 20, -20, 20) cm.setUvRange((0, 1), (1, 0)) ground = render.attachNewNode(cm.generate()) ground.setPos(0, 0, 0); ground.lookAt(0, 0, -1) groundGeom = OdePlaneGeom(space, (0, 0, 1, 0)) groundGeom.setCollideBits(BitMask32(0x00000001)) groundGeom.setCategoryBits(BitMask32(0x00000001))