当前位置: 首页>>代码示例>>Python>>正文


Python CollisionHandlerEvent.addAgainPattern方法代码示例

本文整理汇总了Python中panda3d.core.CollisionHandlerEvent.addAgainPattern方法的典型用法代码示例。如果您正苦于以下问题:Python CollisionHandlerEvent.addAgainPattern方法的具体用法?Python CollisionHandlerEvent.addAgainPattern怎么用?Python CollisionHandlerEvent.addAgainPattern使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在panda3d.core.CollisionHandlerEvent的用法示例。


在下文中一共展示了CollisionHandlerEvent.addAgainPattern方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: __init__

# 需要导入模块: from panda3d.core import CollisionHandlerEvent [as 别名]
# 或者: from panda3d.core.CollisionHandlerEvent import addAgainPattern [as 别名]

#.........这里部分代码省略.........
                                  "eat":"models/trex/trex-eat"})
	self.boy.reparentTo(self.render)
	self.boy.setPos(0,0,0)
	self.boy.setScale(0.5)
	self.isMoving = False
	self.myAnimControl = self.boy.getAnimControl('run')
				
	base.camera.setPos(self.boy.getX(),self.boy.getY()+10,20)
	self.floater = NodePath(PandaNode("floater"))
	self.floater.reparentTo(render)
		
	self.cBoy = self.boy.attachNewNode(CollisionNode('cBoyNode'))
	self.cBoy.node().addSolid(CollisionSphere(0, 0, 3, 8.5))
	#self.cBoy.show()
		
	#self.cPond = self.stall.attachNewNode(CollisionNode('cPond'))
	#self.cPond.node().addSolid(CollisionSphere(40, 0, 1, 70))
	#self.cPond.show()
	
 
        # Add the spinCameraTask procedure to the task manager.
        #self.taskMgr.add(self.spinCameraTask,"asdsad")
	self.keyMap = {"left":0, "right":0, "forward":0, "cam-left":0, "cam-right":0}

	cs1 = CollisionSphere(0, 0, 0, 2)
	self.cnodePath1 = render.attachNewNode(CollisionNode('cnode1'))
	self.cnodePath1.node().addSolid(cs1)
	#self.cnodePath1.setCollideMask(BitMask32(0x10))
	#self.cnodePath1.show()

	
	self.taskMgr.add(self.moveSphere1, "sfasdasf")
 

	cs2 = CollisionSphere(0, 0, 0, 1)
	self.cnodePath2 = render.attachNewNode(CollisionNode('cnode2'))
	self.cnodePath2.node().addSolid(cs2)
	#self.cnodePath2.reparentTo(self.render)
	#self.cnodePath2.node().setFromCollideMask(BitMask32.bit(0))
        #self.cnodePath2.node().setIntoCollideMask(BitMask32.allOff())
	#self.cnodePath2.show()

	self.taskMgr.add(self.moveSphere2, "sfasd")


	handler = CollisionHandlerEvent()
	handler.addInPattern('cnode1-into-cnode2')
	handler.addAgainPattern('cnode1-again-cnode2')
	handler.addOutPattern('cs1-out-cs2')


	self.accept('cnode1-into-cnode2', self.collide)
	#self.accept('cs1-out-cs2', self.collide)
	#self.accept('cnode1-again-cnode2', self.collide)


	self.traverser.addCollider(self.cnodePath1, handler)

        # Load and transform the panda actor.
        self.pandaActor = Actor("models/panda-model",
                                {"walk": "models/panda-walk4"})
        self.pandaActor.setScale(0.005, 0.005, 0.005)
        self.pandaActor.reparentTo(self.render)
        # Loop its animation.
        self.pandaActor.loop("walk")

	self.taskMgr.add(self.movePanda, "Sasdas")
	
	self.pandaActor2 = Actor("models/panda-model",{"walk": "models/panda-walk4"})
        self.pandaActor2.setScale(0.003, 0.003, 0.003)
        self.pandaActor2.reparentTo(self.render)
        # Loop its animation.
        self.pandaActor2.loop("walk")

	self.taskMgr.add(self.movePanda2, "Sak")

	self.camera.setPos(0,0,0)
	self.camera.setHpr(90,0,0)

	self.cTrav1=CollisionTraverser()
	self.collisionHandler1 = CollisionHandlerQueue()
	self.cTrav1.addCollider(self.cBoy, self.collisionHandler1)

	self.taskMgr.add(self.boyMoveTask, "BoyMoveTask")
		
	#self.accept("v",self.switchView)
	self.accept("escape", sys.exit)
	self.accept("arrow_left", self.setKey, ["left",1])
	self.accept("arrow_right", self.setKey, ["right",1])
	self.accept("arrow_up", self.setKey, ["forward",1])
	#self.accept("a", self.setKey, ["cam-left",1])
	#self.accept("s", self.setKey, ["cam-right",1])
	self.accept("arrow_left-up", self.setKey, ["left",0])
	self.accept("arrow_right-up", self.setKey, ["right",0])
	self.accept("arrow_up-up", self.setKey, ["forward",0])
	#self.accept("a-up", self.setKey, ["cam-left",0])
	#self.accept("s-up", self.setKey, ["cam-right",0])

	self.cTrav2=CollisionTraverser()
	self.collisionHandler2 = CollisionHandlerQueue()
开发者ID:DevanshiVyas,项目名称:trex,代码行数:104,代码来源:hopeworks.py

示例2: CogdoFlyingCollisions

# 需要导入模块: from panda3d.core import CollisionHandlerEvent [as 别名]
# 或者: from panda3d.core.CollisionHandlerEvent import addAgainPattern [as 别名]
class CogdoFlyingCollisions(GravityWalker):
    wantFloorSphere = 0

    def __init__(self):
        GravityWalker.__init__(self, gravity=0.0)

    def initializeCollisions(self, collisionTraverser, avatarNodePath, avatarRadius = 1.4, floorOffset = 1.0, reach = 1.0):
        self.cHeadSphereNodePath = None
        self.cFloorEventSphereNodePath = None
        self.setupHeadSphere(avatarNodePath)
        self.setupFloorEventSphere(avatarNodePath, ToontownGlobals.FloorEventBitmask, avatarRadius)
        GravityWalker.initializeCollisions(self, collisionTraverser, avatarNodePath, avatarRadius, floorOffset, reach)
        return

    def setupWallSphere(self, bitmask, avatarRadius):
        self.avatarRadius = avatarRadius
        cSphere = CollisionSphere(0.0, 0.0, self.avatarRadius + 0.75, self.avatarRadius)
        cSphereNode = CollisionNode('Flyer.cWallSphereNode')
        cSphereNode.addSolid(cSphere)
        cSphereNodePath = self.avatarNodePath.attachNewNode(cSphereNode)
        cSphereNode.setFromCollideMask(bitmask)
        cSphereNode.setIntoCollideMask(BitMask32.allOff())
        if config.GetBool('want-fluid-pusher', 0):
            self.pusher = CollisionHandlerFluidPusher()
        else:
            self.pusher = CollisionHandlerPusher()
        self.pusher.addCollider(cSphereNodePath, self.avatarNodePath)
        self.cWallSphereNodePath = cSphereNodePath

    def setupEventSphere(self, bitmask, avatarRadius):
        self.avatarRadius = avatarRadius
        cSphere = CollisionSphere(0.0, 0.0, self.avatarRadius + 0.75, self.avatarRadius * 1.04)
        cSphere.setTangible(0)
        cSphereNode = CollisionNode('Flyer.cEventSphereNode')
        cSphereNode.addSolid(cSphere)
        cSphereNodePath = self.avatarNodePath.attachNewNode(cSphereNode)
        cSphereNode.setFromCollideMask(bitmask)
        cSphereNode.setIntoCollideMask(BitMask32.allOff())
        self.event = CollisionHandlerEvent()
        self.event.addInPattern('enter%in')
        self.event.addOutPattern('exit%in')
        self.cEventSphereNodePath = cSphereNodePath

    def setupRay(self, bitmask, floorOffset, reach):
        cRay = CollisionRay(0.0, 0.0, 3.0, 0.0, 0.0, -1.0)
        cRayNode = CollisionNode('Flyer.cRayNode')
        cRayNode.addSolid(cRay)
        self.cRayNodePath = self.avatarNodePath.attachNewNode(cRayNode)
        cRayNode.setFromCollideMask(bitmask)
        cRayNode.setIntoCollideMask(BitMask32.allOff())
        self.lifter = CollisionHandlerGravity()
        self.lifter.setLegacyMode(self._legacyLifter)
        self.lifter.setGravity(self.getGravity(0))
        self.lifter.addInPattern('%fn-enter-%in')
        self.lifter.addAgainPattern('%fn-again-%in')
        self.lifter.addOutPattern('%fn-exit-%in')
        self.lifter.setOffset(floorOffset)
        self.lifter.setReach(reach)
        self.lifter.addCollider(self.cRayNodePath, self.avatarNodePath)

    def setupHeadSphere(self, avatarNodePath):
        collSphere = CollisionSphere(0, 0, 0, 1)
        collSphere.setTangible(1)
        collNode = CollisionNode('Flyer.cHeadCollSphere')
        collNode.setFromCollideMask(ToontownGlobals.CeilingBitmask)
        collNode.setIntoCollideMask(BitMask32.allOff())
        collNode.addSolid(collSphere)
        self.cHeadSphereNodePath = avatarNodePath.attachNewNode(collNode)
        self.cHeadSphereNodePath.setZ(base.localAvatar.getHeight() + 1.0)
        self.headCollisionEvent = CollisionHandlerEvent()
        self.headCollisionEvent.addInPattern('%fn-enter-%in')
        self.headCollisionEvent.addOutPattern('%fn-exit-%in')
        base.cTrav.addCollider(self.cHeadSphereNodePath, self.headCollisionEvent)

    def setupFloorEventSphere(self, avatarNodePath, bitmask, avatarRadius):
        cSphere = CollisionSphere(0.0, 0.0, 0.0, 0.75)
        cSphereNode = CollisionNode('Flyer.cFloorEventSphere')
        cSphereNode.addSolid(cSphere)
        cSphereNodePath = avatarNodePath.attachNewNode(cSphereNode)
        cSphereNode.setFromCollideMask(bitmask)
        cSphereNode.setIntoCollideMask(BitMask32.allOff())
        self.floorCollisionEvent = CollisionHandlerEvent()
        self.floorCollisionEvent.addInPattern('%fn-enter-%in')
        self.floorCollisionEvent.addAgainPattern('%fn-again-%in')
        self.floorCollisionEvent.addOutPattern('%fn-exit-%in')
        base.cTrav.addCollider(cSphereNodePath, self.floorCollisionEvent)
        self.cFloorEventSphereNodePath = cSphereNodePath

    def deleteCollisions(self):
        GravityWalker.deleteCollisions(self)
        if self.cHeadSphereNodePath != None:
            base.cTrav.removeCollider(self.cHeadSphereNodePath)
            self.cHeadSphereNodePath.detachNode()
            self.cHeadSphereNodePath = None
            self.headCollisionsEvent = None
        if self.cFloorEventSphereNodePath != None:
            base.cTrav.removeCollider(self.cFloorEventSphereNodePath)
            self.cFloorEventSphereNodePath.detachNode()
            self.cFloorEventSphereNodePath = None
            self.floorCollisionEvent = None
#.........这里部分代码省略.........
开发者ID:nate97,项目名称:src,代码行数:103,代码来源:CogdoFlyingCollisions.py

示例3: MyApp

# 需要导入模块: from panda3d.core import CollisionHandlerEvent [as 别名]
# 或者: from panda3d.core.CollisionHandlerEvent import addAgainPattern [as 别名]

#.........这里部分代码省略.........
        self.camera.lookAt(self.pandaActor)
        self.taskMgr.add(self.spinCameraTask, "zombieTask_SpinCameraTask")
        self.taskMgr.doMethodLater(0.01,self.movePandaTask,"zombieTask_movePandaTask")
        
        
        #Collision Handling
        self.cTrav = CollisionTraverser()
        self.collisionHandler = CollisionHandlerEvent()
        
        #Add collider for terrain
        self.groundCollider = self.environ.find("**/terrain")
        
        #Add walker for panda
        self.collision_sphere = CollisionSphere(0,0,1,1)
        self.collNode = CollisionNode('pandaWalker')
        self.cnodePath = self.pandaActor.attachNewNode(self.collNode)
        self.cnodePath.node().addSolid(self.collision_sphere)
        
        #AddZombieDetector for panda
        self.zombie_sphere = CollisionSphere(0,0,3,1)
        self.zomb_detector_node = CollisionNode('zombieDetector')
        self.zomb_detector_NP = self.pandaActor.attachNewNode(self.zomb_detector_node)
        self.zomb_detector_NP.node().addSolid(self.zombie_sphere)
        #self.zomb_detector_NP.show()
        
        #Add pusher against gravity
        self.pusher = PhysicsCollisionHandler()
        self.pusher.addCollider(self.cnodePath, self.pandaActorPhysicsP)
        self.pusher.addCollider(self.zomb_detector_NP,self.pandaActorPhysicsP)
        self.cTrav.addCollider(self.cnodePath,self.pusher)
        self.cTrav.addCollider(self.zomb_detector_NP,self.pusher)
        
        self.pusher.addInPattern('%fn-into-%in')
        self.pusher.addAgainPattern('%fn-again-%in')
        
        #Add collision handler patterns
        self.collisionHandler.addInPattern('%fn-into-%in')
        self.collisionHandler.addAgainPattern('%fn-again-%in')
        
        self.abientLight = AmbientLight("ambientLight")
        self.abientLight.setColor(Vec4(0.1, 0.1, 0.1, 1))
        self.directionalLight = DirectionalLight("directionalLight")
        self.directionalLight.setDirection(Vec3(-5, -5, -5))
        self.directionalLight.setColor(Vec4((229.0/255), (204.0/255), (255.0/255), 0.7))
        self.directionalLight.setSpecularColor(Vec4(0.4, 0.4, 0.4, 0.1))
        self.directionalLight.setShadowCaster(True,512,512)
        self.render.setLight(self.render.attachNewNode(self.abientLight))
        self.render.setLight(self.render.attachNewNode(self.directionalLight))
        self.render.setShaderAuto()
        
        #create zombie land
        self.zombieland = zombie.Zombies(self)
        self.taskMgr.doMethodLater(0.01,self.zombieland.moveZombie, "zombieTask_ZombieMover")
        layer2d.incBar(self.health)
        self.taskMgr.add(self.game_monitor,"zombieTask_gameMonitor")
        self.taskMgr.doMethodLater(2.7,self.music_play, "zombieTask_music")
        
        #Add random useless things:
        self.randomthings_.add_random_things()
    def music_play(self,task):
        self.music.play()
        return Task.done
    #def get_color(self):
     #   return self.color[min(len(self.color)-1,self.level)]
    
    #GameMonitor
开发者ID:ss250294,项目名称:Python-Game1,代码行数:70,代码来源:main.py


注:本文中的panda3d.core.CollisionHandlerEvent.addAgainPattern方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。