本文整理汇总了Python中panda3d.core.CollisionHandlerEvent.setInPattern方法的典型用法代码示例。如果您正苦于以下问题:Python CollisionHandlerEvent.setInPattern方法的具体用法?Python CollisionHandlerEvent.setInPattern怎么用?Python CollisionHandlerEvent.setInPattern使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类panda3d.core.CollisionHandlerEvent
的用法示例。
在下文中一共展示了CollisionHandlerEvent.setInPattern方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: buildCollisions
# 需要导入模块: from panda3d.core import CollisionHandlerEvent [as 别名]
# 或者: from panda3d.core.CollisionHandlerEvent import setInPattern [as 别名]
def buildCollisions(self):
TrapGag.buildCollisions(self)
gagSph = CollisionSphere(0, 0, 0, 1)
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.FloorBitmask)
event = CollisionHandlerEvent()
event.setInPattern('%fn-into')
event.setOutPattern('%fn-out')
base.cTrav.addCollider(gagNP, event)
示例2: BounceCheckAttack
# 需要导入模块: from panda3d.core import CollisionHandlerEvent [as 别名]
# 或者: from panda3d.core.CollisionHandlerEvent import setInPattern [as 别名]
class BounceCheckAttack(ThrowAttack):
notify = directNotify.newCategory('BounceCheckAttack')
MaxBounces = 3
WeaponHitDistance = 0.5
def __init__(self, attacksClass, suit):
ThrowAttack.__init__(self, attacksClass, suit)
self.attack = 'bouncecheck'
self.bounceSound = None
self.numBounces = 0
return
def __pollCheckDistance(self, task):
if base.localAvatar.getDistance(self.weapon) <= self.WeaponHitDistance:
self.handleWeaponCollision(None)
return Task.done
else:
return Task.cont
return
def loadAttack(self):
self.weapon = loader.loadModel('phase_5/models/props/bounced-check.bam')
self.weapon.setScale(10)
self.weapon.setTwoSided(1)
self.bounceSound = base.audio3d.loadSfx('phase_5/audio/sfx/SA_bounce_check_bounce.mp3')
base.audio3d.attachSoundToObject(self.bounceSound, self.suit)
cSphere = CollisionSphere(0, 0, 0, 0.1)
cSphere.setTangible(0)
if hasattr(self, 'uniqueName'):
name = self.uniqueName('bounced_check_collision')
else:
name = 'bounced_check_collision'
cNode = CollisionNode(name)
cNode.addSolid(cSphere)
cNode.setFromCollideMask(CIGlobals.FloorBitmask)
cNP = self.weapon.attachNewNode(cNode)
cNP.setCollideMask(BitMask32(0))
self.event = CollisionHandlerEvent()
self.event.setInPattern('%fn-into')
self.event.setOutPattern('%fn-out')
base.cTrav.addCollider(cNP, self.event)
self.wsnp = cNP
self.wsnp.show()
def doAttack(self, ts = 0):
ThrowAttack.doAttack(self, ts)
self.loadAttack()
if hasattr(self, 'uniqueName'):
name = self.uniqueName('doBounceCheckAttack')
else:
name = 'doBounceCheckAttack'
self.suitTrack = Sequence(name=name)
self.weapon.reparentTo(self.suit.find('**/joint_Rhold'))
if self.suit.type == 'C':
self.suitTrack.append(Wait(2.3))
else:
self.suitTrack.append(Wait(3))
self.suit.play('throw-paper')
self.suitTrack.append(Func(self.throwObject))
self.suitTrack.start(ts)
def throwObject(self):
ThrowAttack.throwObject(self)
taskMgr.add(self.__pollCheckDistance, 'pollCheckDistance')
self.__doThrow(0)
def __doThrow(self, alreadyThrown):
self.weapon.setScale(1)
pathNP = NodePath('throwPath')
if not alreadyThrown:
pathNP.reparentTo(self.suit)
else:
pathNP.reparentTo(self.weapon)
pathNP.setScale(render, 1.0)
pathNP.setPos(0, 30, -100)
pathNP.setHpr(90, -90, 90)
print pathNP.getPos(base.render)
if self.throwTrajectory:
self.throwTrajectory.pause()
self.throwTrajectory = None
if alreadyThrown:
startPos = self.weapon.getPos(base.render)
gravity = 0.7
else:
gravity = 0.7
startPos = self.suit.find('**/joint_Rhold').getPos(base.render)
self.throwTrajectory = ProjectileInterval(self.weapon, startPos=startPos, endPos=pathNP.getPos(base.render), gravityMult=gravity, duration=3.0)
self.throwTrajectory.start()
self.weapon.setScale(10)
self.weapon.reparentTo(render)
self.weapon.setHpr(pathNP.getHpr(render))
self.weapon_state = 'released'
self.acceptOnce(self.wsnp.node().getName() + '-into', self.__handleHitFloor)
return
def __handleHitFloor(self, entry):
self.numBounces += 1
if self.numBounces >= self.MaxBounces:
self.cleanup()
return
#.........这里部分代码省略.........
示例3: load
# 需要导入模块: from panda3d.core import CollisionHandlerEvent [as 别名]
# 或者: from panda3d.core.CollisionHandlerEvent import setInPattern [as 别名]
def load(self):
self.notify.debug('load')
DistributedMinigame.load(self)
self.music = base.loader.loadMusic('phase_4/audio/bgm/MG_CogThief.ogg')
self.initCogInfo()
for barrelIndex in xrange(CTGG.NumBarrels):
barrel = loader.loadModel('phase_4/models/minigames/cogthief_game_gagTank')
barrel.setPos(CTGG.BarrelStartingPositions[barrelIndex])
barrel.setScale(self.BarrelScale)
barrel.reparentTo(render)
barrel.setTag('barrelIndex', str(barrelIndex))
collSphere = CollisionSphere(0, 0, 0, 4)
collSphere.setTangible(0)
name = 'BarrelSphere-%d' % barrelIndex
collSphereName = self.uniqueName(name)
collNode = CollisionNode(collSphereName)
collNode.setFromCollideMask(CTGG.BarrelBitmask)
collNode.addSolid(collSphere)
colNp = barrel.attachNewNode(collNode)
handler = CollisionHandlerEvent()
handler.setInPattern('barrelHit-%fn')
base.cTrav.addCollider(colNp, handler)
self.accept('barrelHit-' + collSphereName, self.handleEnterBarrel)
nodeToHide = '**/gagMoneyTen'
if barrelIndex % 2:
nodeToHide = '**/gagMoneyFive'
iconToHide = barrel.find(nodeToHide)
if not iconToHide.isEmpty():
iconToHide.hide()
self.barrels.append(barrel)
self.gameBoard = loader.loadModel('phase_4/models/minigames/cogthief_game')
self.gameBoard.find('**/floor_TT').hide()
self.gameBoard.find('**/floor_DD').hide()
self.gameBoard.find('**/floor_DG').hide()
self.gameBoard.find('**/floor_MM').hide()
self.gameBoard.find('**/floor_BR').hide()
self.gameBoard.find('**/floor_DL').hide()
zone = self.getSafezoneId()
if zone == ToontownGlobals.ToontownCentral:
self.gameBoard.find('**/floor_TT').show()
elif zone == ToontownGlobals.DonaldsDock:
self.gameBoard.find('**/floor_DD').show()
elif zone == ToontownGlobals.DaisyGardens:
self.gameBoard.find('**/floor_DG').show()
elif zone == ToontownGlobals.MinniesMelodyland:
self.gameBoard.find('**/floor_MM').show()
elif zone == ToontownGlobals.TheBrrrgh:
self.gameBoard.find('**/floor_BR').show()
elif zone == ToontownGlobals.DonaldsDreamland:
self.gameBoard.find('**/floor_DL').show()
else:
self.gameBoard.find('**/floor_TT').show()
self.gameBoard.setPosHpr(0, 0, 0, 0, 0, 0)
self.gameBoard.setScale(1.0)
self.toonSDs = {}
avId = self.localAvId
toonSD = CogThiefGameToonSD.CogThiefGameToonSD(avId, self)
self.toonSDs[avId] = toonSD
toonSD.load()
self.loadCogs()
self.toonHitTracks = {}
self.toonPieTracks = {}
self.sndOof = base.loader.loadSfx('phase_4/audio/sfx/MG_cannon_hit_dirt.ogg')
self.sndRewardTick = base.loader.loadSfx('phase_3.5/audio/sfx/tick_counter.ogg')
self.sndPerfect = base.loader.loadSfx('phase_4/audio/sfx/ring_perfect.ogg')
self.timer = ToontownTimer.ToontownTimer()
self.timer.posInTopRightCorner()
self.timer.hide()
purchaseModels = loader.loadModel('phase_4/models/gui/purchase_gui')
self.jarImage = purchaseModels.find('**/Jar')
self.jarImage.reparentTo(hidden)
self.rewardPanel = DirectLabel(parent=hidden, relief=None, pos=(-0.173, 0.0, -0.55), scale=0.65, text='', text_scale=0.2, text_fg=(0.95, 0.95, 0, 1), text_pos=(0, -.13), text_font=ToontownGlobals.getSignFont(), image=self.jarImage)
self.rewardPanelTitle = DirectLabel(parent=self.rewardPanel, relief=None, pos=(0, 0, 0.06), scale=0.08, text=TTLocalizer.CannonGameReward, text_fg=(0.95, 0.95, 0, 1), text_shadow=(0, 0, 0, 1))
return
示例4: DistributedCogThiefGame
# 需要导入模块: from panda3d.core import CollisionHandlerEvent [as 别名]
# 或者: from panda3d.core.CollisionHandlerEvent import setInPattern [as 别名]
class DistributedCogThiefGame(DistributedMinigame):
notify = directNotify.newCategory('DistributedCogThiefGame')
ToonSpeed = CTGG.ToonSpeed
StageHalfWidth = 200.0
StageHalfHeight = 100.0
BarrelScale = 0.25
TOON_Z = 0
UPDATE_SUITS_TASK = 'CogThiefGameUpdateSuitsTask'
REWARD_COUNTDOWN_TASK = 'cogThiefGameRewardCountdown'
ControlKeyLimitTime = 1.0
def __init__(self, cr):
DistributedMinigame.__init__(self, cr)
self.gameFSM = ClassicFSM.ClassicFSM('DistributedCogThiefGame', [State.State('off', self.enterOff, self.exitOff, ['play']), State.State('play', self.enterPlay, self.exitPlay, ['cleanup']), State.State('cleanup', self.enterCleanup, self.exitCleanup, [])], 'off', 'cleanup')
self.addChildGameFSM(self.gameFSM)
self.cameraTopView = (0, 0, 55, 0, -90.0, 0)
self.barrels = []
self.cogInfo = {}
self.lastTimeControlPressed = 0
self.stolenBarrels = []
self.useOrthoWalk = base.config.GetBool('cog-thief-ortho', 1)
self.resultIval = None
self.gameIsEnding = False
self.__textGen = TextNode('cogThiefGame')
self.__textGen.setFont(ToontownGlobals.getSignFont())
self.__textGen.setAlign(TextNode.ACenter)
return
def getTitle(self):
return TTLocalizer.CogThiefGameTitle
def getInstructions(self):
return TTLocalizer.CogThiefGameInstructions
def getMaxDuration(self):
return 0
def load(self):
self.notify.debug('load')
DistributedMinigame.load(self)
self.music = base.loader.loadMusic('phase_4/audio/bgm/MG_CogThief.ogg')
self.initCogInfo()
for barrelIndex in xrange(CTGG.NumBarrels):
barrel = loader.loadModel('phase_4/models/minigames/cogthief_game_gagTank')
barrel.setPos(CTGG.BarrelStartingPositions[barrelIndex])
barrel.setScale(self.BarrelScale)
barrel.reparentTo(render)
barrel.setTag('barrelIndex', str(barrelIndex))
collSphere = CollisionSphere(0, 0, 0, 4)
collSphere.setTangible(0)
name = 'BarrelSphere-%d' % barrelIndex
collSphereName = self.uniqueName(name)
collNode = CollisionNode(collSphereName)
collNode.setFromCollideMask(CTGG.BarrelBitmask)
collNode.addSolid(collSphere)
colNp = barrel.attachNewNode(collNode)
handler = CollisionHandlerEvent()
handler.setInPattern('barrelHit-%fn')
base.cTrav.addCollider(colNp, handler)
self.accept('barrelHit-' + collSphereName, self.handleEnterBarrel)
nodeToHide = '**/gagMoneyTen'
if barrelIndex % 2:
nodeToHide = '**/gagMoneyFive'
iconToHide = barrel.find(nodeToHide)
if not iconToHide.isEmpty():
iconToHide.hide()
self.barrels.append(barrel)
self.gameBoard = loader.loadModel('phase_4/models/minigames/cogthief_game')
self.gameBoard.find('**/floor_TT').hide()
self.gameBoard.find('**/floor_DD').hide()
self.gameBoard.find('**/floor_DG').hide()
self.gameBoard.find('**/floor_MM').hide()
self.gameBoard.find('**/floor_BR').hide()
self.gameBoard.find('**/floor_DL').hide()
zone = self.getSafezoneId()
if zone == ToontownGlobals.ToontownCentral:
self.gameBoard.find('**/floor_TT').show()
elif zone == ToontownGlobals.DonaldsDock:
self.gameBoard.find('**/floor_DD').show()
elif zone == ToontownGlobals.DaisyGardens:
self.gameBoard.find('**/floor_DG').show()
elif zone == ToontownGlobals.MinniesMelodyland:
self.gameBoard.find('**/floor_MM').show()
elif zone == ToontownGlobals.TheBrrrgh:
self.gameBoard.find('**/floor_BR').show()
elif zone == ToontownGlobals.DonaldsDreamland:
self.gameBoard.find('**/floor_DL').show()
else:
self.gameBoard.find('**/floor_TT').show()
self.gameBoard.setPosHpr(0, 0, 0, 0, 0, 0)
self.gameBoard.setScale(1.0)
self.toonSDs = {}
avId = self.localAvId
toonSD = CogThiefGameToonSD.CogThiefGameToonSD(avId, self)
self.toonSDs[avId] = toonSD
toonSD.load()
self.loadCogs()
self.toonHitTracks = {}
self.toonPieTracks = {}
#.........这里部分代码省略.........
示例5: CameraShyFirstPerson
# 需要导入模块: from panda3d.core import CollisionHandlerEvent [as 别名]
# 或者: from panda3d.core.CollisionHandlerEvent import setInPattern [as 别名]
#.........这里部分代码省略.........
return
def __handleRayInto(self, entry):
intoNP = entry.getIntoNodePath()
toonNP = intoNP.getParent()
for key in base.cr.doId2do.keys():
obj = base.cr.doId2do[key]
if obj.__class__.__name__ == 'DistributedToon':
if obj.getKey() == toonNP.getKey():
self.__handleToonInFocus(obj)
def __handleRayOut(self, entry):
intoNP = entry.getIntoNodePath()
toonNP = intoNP.getParent()
for key in base.cr.doId2do.keys():
obj = base.cr.doId2do[key]
if obj.__class__.__name__ == 'DistributedToon':
if obj.getKey() == toonNP.getKey():
self.toonToTakePicOf = None
self.hasToonInFocus = False
if self.cameraFocus.getColorScale() == self.toonInFocusColor:
self.cameraFocus.setColorScale(self.toonOutOfFocusColor)
return
def __handleToonInFocus(self, toon):
if not self.hasToonInFocus or self.toonToTakePicOf is not None or self.toonToTakePicOf.doId != toon.doId:
self.toonToTakePicOf = toon
self.hasToonInFocus = True
self.cameraFocus.setColorScale(self.toonInFocusColor)
return
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
def reallyStart(self):
self.accept('mouseRay-into', self.__handleRayInto)
self.accept('mouseRay-out', self.__handleRayOut)
self.camFSM.request('recharge')
taskMgr.add(self.movementTask, 'movementTask')
FirstPerson.reallyStart(self)
def end(self):
self.camFSM.request('off')
taskMgr.remove('movementTask')
self.ignore('mouseRay-into')
self.ignore('mouseRay-out')
FirstPerson.end(self)
def reallyEnd(self):
self.batteryBar.destroy()
self.batteryBar = None
self.batteryBg.destroy()
self.batteryBg = None
self.batteryFrame.destroy()
self.batteryFrame = None
self.cameraFocus.removeNode()
self.cameraFocus = None
self.focusCollHandler = None
self.focusCollNode = None
self.focusCollNP.removeNode()
self.focusCollNP = None
self.focusRay = None
self.hasToonInFocus = None
self.toonToTakePicOf = None
self.fullyChargedSound = None
self.rechargeSound = None
self.stopCameraFlash()
FirstPerson.reallyEnd(self)
base.localAvatar.walkControls.setWalkSpeed(CIGlobals.ToonForwardSpeed, CIGlobals.ToonJumpForce, CIGlobals.ToonReverseSpeed, CIGlobals.ToonRotateSpeed)
return
def cleanup(self):
self.camFSM.requestFinalState()
self.camFSM = None
FirstPerson.cleanup(self)
return