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


Python core.CollisionHandlerEvent类代码示例

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


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

示例1: getSprayTrack

    def getSprayTrack(self, origin, target, scaleUp, hold, scaleDown, horizScale = 1.0, vertScale = 1.0):
        base.localAvatar.stop(self.toonAnim)
        self.lastFrame = self.avatar.getCurrentFrame(self.toonAnim)
        track = Sequence()
        sprayProp = loader.loadModel(GagGlobals.SPRAY_MDL)
        sprayProp.setTwoSided(1)
        sprayScale = hidden.attachNewNode('spray-parent')
        sprayRot = hidden.attachNewNode('spray-rotate')
        sprayRot.setColor(GagGlobals.WATER_SPRAY_COLOR)
        sprayRot.setTransparency(1)
        collNode = CollisionNode('Collision')
        spraySphere = CollisionSphere(0, 0, 0, 1)
        spraySphere.setTangible(0)
        collNode.addSolid(spraySphere)
        collNode.setCollideMask(CIGlobals.WallBitmask)
        sprayNP = sprayRot.attachNewNode(collNode)
        sprayNP.setY(1)
        self.sprayNP = sprayNP
        event = CollisionHandlerEvent()
        event.set_in_pattern('%fn-into')
        event.set_out_pattern('%fn-out')
        base.cTrav.add_collider(sprayNP, event)
        self.avatar.acceptOnce(sprayNP.node().getName() + '-into', self.onCollision)

        def showSpray(sprayScale, sprayProp, origin, target):
            objects = [sprayRot, sprayScale, sprayProp]
            for item in objects:
                index = objects.index(item)
                if index == 0:
                    item.reparentTo(self.sprayJoint)
                    item.setPos(self.sprayJoint.getPos(render))
                    item.setHpr(self.sprayJoint.getHpr(render))
                    item.setP(0)
                else:
                    item.reparentTo(objects[index - 1])
                item.clearMat()

        track.append(Func(showSpray, sprayScale, sprayProp, origin, target))
        self.spray = sprayRot

        def calcTargetScale():
            distance = Vec3(target - origin).length()
            yScale = distance / GagGlobals.SPRAY_LEN
            targetScale = Point3(yScale * horizScale, yScale, yScale * vertScale)
            return targetScale

        track.append(Parallel(LerpScaleInterval(sprayScale, scaleUp, calcTargetScale, startScale=GagGlobals.PNT3NEAR0), sprayNP.posInterval(0.25, self.spray.getPos(render) + Point3(0, 50, 0), startPos=self.spray.getPos(render) + Point3(0, 5, 0))))
        track.append(Wait(hold))
        track.append(Func(self.handleMiss))
        track.append(LerpScaleInterval(sprayScale, 0.75, GagGlobals.PNT3NEAR0))

        def hideSpray():
            (lambda prop: prop.removeNode(), [sprayProp, sprayRot, sprayScale])

        track.append(Func(hideSpray))
        track.append(Func(self.completeSquirt))
        return track
开发者ID:coginvasion,项目名称:src,代码行数:57,代码来源:SquirtGag.py

示例2: buildCollisions

 def buildCollisions(self):
     pieSphere = CollisionSphere(0, 0, 0, 1)
     pieSensor = CollisionNode('turretGagSensor' + str(id(self)))
     pieSensor.addSolid(pieSphere)
     pieNP = self.gag.attachNewNode(pieSensor)
     pieNP.setCollideMask(BitMask32(0))
     pieNP.node().setFromCollideMask(CIGlobals.WallBitmask | CIGlobals.FloorBitmask)
     event = CollisionHandlerEvent()
     event.set_in_pattern('%fn-into')
     event.set_out_pattern('%fn-out')
     base.cTrav.addCollider(pieNP, event)
开发者ID:coginvasion,项目名称:src,代码行数:11,代码来源:TurretGag.py

示例3: __init__

 def __init__(self, model = "cube_nocol", texture = "lava", pos = (0,0,0), scale = (1,1,1), cubetype = "A"):
     super(LavaCube, self).__init__(model, texture, pos, scale)
     cn = CollisionNode('lava')
     cn.setFromCollideMask(COLLISIONMASKS['lava'])
     cn.setIntoCollideMask(BitMask32.allOff())
     np = self.node.attachNewNode(cn)
     cn.addSolid(CollisionSphere(0,0,0,1.1))
     h = CollisionHandlerEvent()
     h.addInPattern('%fn-into-%in')
     h.addOutPattern('%fn-outof-%in')
     base.cTrav.addCollider(np, h)
开发者ID:court-jus,项目名称:Gate_OpenPortal,代码行数:11,代码来源:level.py

示例4: buildCollisions

 def buildCollisions(self):
     gagSph = CollisionSphere(0, 0, 0, 2)
     gagSensor = CollisionNode('gagSensor')
     gagSensor.addSolid(gagSph)
     sensorNP = self.gag.attachNewNode(gagSensor)
     sensorNP.setCollideMask(BitMask32(0))
     sensorNP.node().setFromCollideMask(CIGlobals.WallBitmask | CIGlobals.FloorBitmask)
     event = CollisionHandlerEvent()
     event.set_in_pattern('%fn-into')
     event.set_out_pattern('%fn-out')
     base.cTrav.addCollider(sensorNP, event)
     self.avatar.acceptOnce('gagSensor-into', self.onCollision)
开发者ID:coginvasion,项目名称:src,代码行数:12,代码来源:BigWeight.py

示例5: buildCollisions

 def buildCollisions(self, entity):
     pieSphere = CollisionSphere(0, 0, 0, 1)
     pieSensor = CollisionNode('gagSensor')
     pieSensor.addSolid(pieSphere)
     pieNP = entity.attachNewNode(pieSensor)
     pieNP.setCollideMask(BitMask32(0))
     pieNP.node().setFromCollideMask(CIGlobals.WallBitmask | CIGlobals.FloorBitmask)
     event = CollisionHandlerEvent()
     event.set_in_pattern('%fn-into')
     event.set_out_pattern('%fn-out')
     base.cTrav.add_collider(pieNP, event)
     self.avatar.acceptOnce('gagSensor-into', self.onCollision)
开发者ID:coginvasion,项目名称:src,代码行数:12,代码来源:ThrowGag.py

示例6: buildProjCollisions

 def buildProjCollisions(self):
     gagSph = CollisionSphere(0, 0, 0, 1)
     gagSph.setTangible(0)
     gagNode = CollisionNode('projSensor')
     gagNode.addSolid(gagSph)
     gagNP = self.gag.attach_new_node(gagNode)
     gagNP.setScale(0.75, 0.8, 0.75)
     gagNP.setPos(0.0, 0.1, 0.5)
     gagNP.setCollideMask(BitMask32.bit(0))
     gagNP.node().setFromCollideMask(CIGlobals.FloorBitmask)
     event = CollisionHandlerEvent()
     event.set_in_pattern('%fn-into')
     event.set_out_pattern('%fn-out')
     base.cTrav.addCollider(gagNP, event)
开发者ID:coginvasion,项目名称:src,代码行数:14,代码来源:ActivateTrapGag.py

示例7: enterPlay

 def enterPlay(self):
     self.notify.debug('enterPlay')
     self.startGameWalk()
     self.spawnUpdateSuitsTask()
     self.accept('control', self.controlKeyPressed)
     self.pieHandler = CollisionHandlerEvent()
     self.pieHandler.setInPattern('pieHit-%fn')
开发者ID:nate97,项目名称:src,代码行数:7,代码来源:DistributedCogThiefGame.py

示例8: __init__

    def __init__(self, spawn, taregt, id):

        self.projectileNode = NodePath('projectile'+str(id))
        self.projectileNode.reparentTo(render)

        self.projectileNode.setPos(spawn,0,-10, 0)
        self.projectileNode.setScale(.1)
        projectileModel = loader.loadModel("./resources/cubeShot.egg")
        projectileModel.setColorScale(200, 0, 255, 100)
        projectileModel.reparentTo(self.projectileNode)
        self.projectileNode.setHpr(spawn, 0, 0, 0)


        dir = render.getRelativeVector(spawn, Vec3(0, 1, 0))

        #speed up or slow down projectiles here
        #dir = dir*20
        self.vec = dir*-200
        
        cs = CollisionSphere(0, 0, 0, 2.5)
        cnodepath = self.projectileNode.attachNewNode(CollisionNode('projNode'))
        cnodepath.node().addSolid(cs)
        self.collHand = CollisionHandlerEvent()
        self.collHand.addInPattern('enemyProjectileinto'+str(id))
        self.collHand.addOutPattern('outof')
        base.cTrav.addCollider(cnodepath, self.collHand)
        self.acceptOnce('enemyProjectileinto'+str(id), self.hit)
        self.damage = 10
开发者ID:NicholasMarasco,项目名称:TerminalZone,代码行数:28,代码来源:projectile.py

示例9: start

 def start(self):
     self.fullyChargedSound = base.loadSfx('phase_4/audio/sfx/MG_pairing_match.mp3')
     self.rechargeSound = base.loadSfx('phase_4/audio/sfx/MG_sfx_travel_game_blue_arrow.mp3')
     self.batteryFrame = DirectFrame(parent=base.a2dBottomRight, pos=(-0.2, 0, 0.1), scale=(0.8, 0, 1))
     self.batteryBg = OnscreenImage(image='phase_4/maps/battery_charge_frame.png', parent=self.batteryFrame)
     self.batteryBg.setTransparency(1)
     self.batteryBg.setX(0.03)
     self.batteryBg.setScale(0.17, 0, 0.05)
     self.batteryBar = DirectWaitBar(value=0, range=5, barColor=(1, 1, 1, 1), relief=None, scale=(0.12, 0.0, 0.3), parent=self.batteryFrame)
     self.cameraFocus = loader.loadModel('phase_4/models/minigames/photo_game_viewfinder.bam')
     self.cameraFocus.reparentTo(base.aspect2d)
     self.focusCollHandler = CollisionHandlerEvent()
     self.focusCollHandler.setInPattern('%fn-into')
     self.focusCollHandler.setOutPattern('%fn-out')
     self.focusCollNode = CollisionNode('mouseRay')
     self.focusCollNP = base.camera.attachNewNode(self.focusCollNode)
     self.focusCollNode.setCollideMask(BitMask32(0))
     self.focusCollNode.setFromCollideMask(CIGlobals.WallBitmask)
     self.focusRay = CollisionRay()
     self.focusRay.setFromLens(base.camNode, 0.0, 0.0)
     self.focusCollNode.addSolid(self.focusRay)
     base.cTrav.addCollider(self.focusCollNP, self.focusCollHandler)
     base.localAvatar.walkControls.setWalkSpeed(CIGlobals.ToonForwardSpeed, 0.0, CIGlobals.ToonReverseSpeed, CIGlobals.ToonRotateSpeed)
     FirstPerson.start(self)
     return
开发者ID:coginvasion,项目名称:src,代码行数:25,代码来源:CameraShyFirstPerson.py

示例10: buildCollisions

 def buildCollisions(self):
     TrapGag.buildCollisions(self)
     gagSph = CollisionSphere(0, 0, 0, self.collRadius)
     gagSph.setTangible(0)
     gagNode = CollisionNode('gagSensor')
     gagNode.addSolid(gagSph)
     gagNP = self.gag.attachNewNode(gagNode)
     gagNP.setScale(0.75, 0.8, 0.75)
     gagNP.setPos(0.0, 0.1, 0.5)
     gagNP.setCollideMask(BitMask32.bit(0))
     gagNP.node().setFromCollideMask(CIGlobals.WallBitmask | CIGlobals.FloorBitmask)
     event = CollisionHandlerEvent()
     event.set_in_pattern('%fn-into')
     event.set_out_pattern('%fn-out')
     base.cTrav.addCollider(gagNP, event)
     if self.isLocal():
         self.avatar.accept('gagSensor-into', self.onCollision)
开发者ID:coginvasion,项目名称:src,代码行数:17,代码来源:ActivateTrapGag.py

示例11: createPortalCollisions

 def createPortalCollisions(self):
     # Enter the portals
     cn = CollisionNode('bluePortal')
     cn.setFromCollideMask(COLLISIONMASKS['portals'])
     cn.setIntoCollideMask(BitMask32.allOff())
     np = self.bluePortal.attachNewNode(cn)
     cn.addSolid(CollisionSphere(0,0,0,2))
     h = CollisionHandlerEvent()
     h.addInPattern('%fn-into-%in')
     h.addOutPattern('%fn-outof-%in')
     self.base.cTrav.addCollider(np, h)
     cn = CollisionNode('orangePortal')
     cn.setFromCollideMask(COLLISIONMASKS['portals'])
     cn.setIntoCollideMask(BitMask32.allOff())
     np = self.orangePortal.attachNewNode(cn)
     cn.addSolid(CollisionSphere(0,0,0,2))
     h = CollisionHandlerEvent()
     h.addInPattern('%fn-into-%in')
     h.addOutPattern('%fn-outof-%in')
     self.base.cTrav.addCollider(np, h)
开发者ID:court-jus,项目名称:Gate_OpenPortal,代码行数:20,代码来源:player.py

示例12: getFlyBallBubble

 def getFlyBallBubble(self):
     if self.__flyBallBubble == None:
         bubble = CollisionSphere(0, 0, 0, GolfGlobals.GOLF_BALL_RADIUS)
         node = CollisionNode('flyBallBubble')
         node.addSolid(bubble)
         node.setFromCollideMask(ToontownGlobals.PieBitmask | ToontownGlobals.CameraBitmask | ToontownGlobals.FloorBitmask)
         node.setIntoCollideMask(BitMask32.allOff())
         self.__flyBallBubble = NodePath(node)
         self.flyBallHandler = CollisionHandlerEvent()
         self.flyBallHandler.addInPattern('flyBallHit-%d' % self.index)
     return self.__flyBallBubble
开发者ID:nate97,项目名称:src,代码行数:11,代码来源:DistributedGolfSpot.py

示例13: Pickup

class Pickup(DirectObject):

    #Creates health pickup object
    def __init__(self, idappend, spawn):
        
        self.id = "pick"+str(idappend)
        self.deletePickup = False          
        self.projectileNode = NodePath('heal'+str(self.id))

        self.projectileNode.setScale(1)
        self.projectileModel = loader.loadModel("./resources/healthPickup.egg")
        self.projectileModel.setColorScale(200, 0, 0, 100)
        self.projectileModel.reparentTo(self.projectileNode)
        self.projectileNode.reparentTo(render)
        self.projectileNode.setPos(spawn)
        cs = CollisionSphere(0, 0, 0, .5)
        cnode = CollisionNode('heal')
        self.colNode = self.projectileModel.attachNewNode(cnode)
        self.colNode.node().addSolid(cs)
        self.collHand = CollisionHandlerEvent()
        self.collHand.addInPattern('pickupin'+str(self.id))
        self.collHand.addOutPattern('oot')
        base.cTrav.addCollider(self.colNode, self.collHand)
        self.accept('pickupin'+str(self.id), self.pickup)
   
    #Detects if the player has picked up the health
    def pickup(self, col):
        
        if col.getIntoNodePath().getName() == "cnode":

            messenger.send("pickuphealth")
            self.deletePickup = True

    #Destroys the health pickups from the scene graph
    def destroy(self):

        self.projectileNode.removeNode()
        self.projectileModel.removeNode()
        self.colNode.node().clearSolids()
        
        del self
开发者ID:NicholasMarasco,项目名称:TerminalZone,代码行数:41,代码来源:pickup.py

示例14: __init__

    def __init__(self):
        # start Panda3d
        base = ShowBase()
        # CollisionTraverser instance must be attached to base,
        # and must be called cTrav
        base.cTrav = CollisionTraverser()
        self.cHand = CollisionHandlerEvent()
        self.cHand.addInPattern('into-%in')
        
        # load smiley, which we will control
        # notice this is a little trickery. If we parent everything except smiley
        # to the camera, and the player is controlling the camera, then everything 
        # stays fixed in the same place relative to the camera, and when the camera
        # moves, the player is given the illusion that he is moving smiley, rather than 
        # the camera and the rest of the scene.
        self.smiley = base.loader.loadModel('smiley')
        self.smiley.reparentTo(render)
        self.smiley.setName('Smiley')
        
        # Setup a collision solid for this model. Our initCollisionSphere method returns
        # the cNodepath and the string representing it. We will use the cNodepath for 
        # adding to the traverser, and the string to accept it for event handling.
        #sColl = self.initCollisionSphere(self.smiley)
        sColl = self.initCollisionSphere(self.smiley, True)
        print 'smiley', sColl[0]
        print 'smiley', sColl[1]

        # Add this object to the traverser.
        base.cTrav.addCollider(sColl[0], self.cHand)

        # load frowney
        self.frowney = base.loader.loadModel('frowney')
        self.frowney.setName('Frowney')
        self.frowney.reparentTo(camera)
        
        # Setup a collision solid for this model.
        fColl = self.initCollisionSphere(self.frowney, True)
        #print 'frowney', fColl[0]
        #print 'frowney', fColl[1]
        
        # Add this object to the traverser.
        base.cTrav.addCollider(fColl[0], self.cHand)

        # Accept the events sent by the collisions.
        # smiley is the object we are 'moving', so by convention
        # it is the from object.
        # If we instead put smiley as the into object here,
        # it would work fine, but then smiley would disappear
        # when we collided them.
        self.accept('into-' + fColl[1], self.collide)        

        # set the initial positions of smiley and frowney
        self.set_initial_positions()
开发者ID:codedragon,项目名称:panda3d_unittest_example,代码行数:53,代码来源:silly.py

示例15: setupHeadSphere

 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)
开发者ID:nate97,项目名称:src,代码行数:13,代码来源:CogdoFlyingCollisions.py


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