本文整理汇总了Python中direct.fsm.ClassicFSM.ClassicFSM.getStateNamed方法的典型用法代码示例。如果您正苦于以下问题:Python ClassicFSM.getStateNamed方法的具体用法?Python ClassicFSM.getStateNamed怎么用?Python ClassicFSM.getStateNamed使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类direct.fsm.ClassicFSM.ClassicFSM
的用法示例。
在下文中一共展示了ClassicFSM.getStateNamed方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: ToonHood
# 需要导入模块: from direct.fsm.ClassicFSM import ClassicFSM [as 别名]
# 或者: from direct.fsm.ClassicFSM.ClassicFSM import getStateNamed [as 别名]
class ToonHood(Hood.Hood):
def __init__(self, parentFSM, doneEvent, dnaStore, hoodId):
Hood.Hood.__init__(self, parentFSM, doneEvent, dnaStore, hoodId)
self.safeZoneLoader = None
self.townLoader = None
self.fsm = ClassicFSM('Hood', [State('off', self.enterOff, self.exitOff),
State('safeZoneLoader', self.enterSafeZoneLoader, self.exitSafeZoneLoader, ['quietZone', 'townLoader']),
State('townLoader', self.enterTownLoader, self.exitTownLoader, ['quietZone', 'safeZoneLoader']),
State('quietZone', self.enterQuietZone, self.exitQuietZone, ['safeZoneLoader', 'townLoader'])], 'off', 'off')
self.fsm.enterInitialState()
return
def loadLoader(self, requestStatus):
loader = requestStatus['loader']
if loader == 'safeZoneLoader':
if self.safeZoneLoader:
self.loader = self.safeZoneLoader(self, self.fsm.getStateNamed('safeZoneLoader'), self.loaderDoneEvent)
self.loader.load()
else:
self.notify.error('ToonHood.ToonHood.safeZoneLoader cannot be None!' % loader)
elif loader == 'townLoader':
if self.townLoader:
self.loader = self.townLoader(self, self.fsm.getStateNamed('townLoader'), self.loaderDoneEvent)
self.loader.load(requestStatus['zoneId'])
else:
self.notify.error('Unknown loader %s!' % loader)
def enterTownLoader(self, requestStatus):
self.acceptOnce(self.loaderDoneEvent, self.handleTownLoaderDone)
self.loader.enter(requestStatus)
self.spawnTitleText(requestStatus['zoneId'])
def exitTownLoader(self):
taskMgr.remove('titleText')
self.hideTitleText()
self.ignore(self.loaderDoneEvent)
self.loader.exit()
self.loader.unload()
del self.loader
def handleTownLoaderDone(self):
doneStatus = self.loader.getDoneStatus()
if self.isSameHood(doneStatus):
self.fsm.request('quietZone', [doneStatus])
else:
self.doneStatus = doneStatus
messenger.send(self.doneEvent)
def load(self):
Hood.Hood.load(self)
self.whiteFogColor = Vec4(0.8, 0.8, 0.8, 1)
self.underwaterFogColor = Vec4(0.0, 0.0, 0.6, 1.0)
def unload(self):
del self.safeZoneLoader
Hood.Hood.unload(self)
def enter(self, requestStatus):
self.loadLoader(requestStatus)
Hood.Hood.enter(self, requestStatus)
def exit(self):
Hood.Hood.exit(self)
def setUnderwaterFog(self):
if base.wantFog:
self.fog.setColor(self.underwaterColor)
self.fog.setLinearRange(0.1, 100.0)
render.setFog(self.fog)
self.sky.setFog(self.fog)
def setWhiteFog(self):
if base.wantFog:
self.fog.setColor(self.whiteFogColor)
self.fog.setLinearRange(0.0, 400.0)
render.clearFog()
render.setFog(self.fog)
self.sky.clearFog()
self.sky.setFog(self.fog)
def setNoFog(self):
if base.wantFog:
render.clearFog()
self.sky.clearFog()
示例2: ToonFPS
# 需要导入模块: from direct.fsm.ClassicFSM import ClassicFSM [as 别名]
# 或者: from direct.fsm.ClassicFSM.ClassicFSM import getStateNamed [as 别名]
class ToonFPS(DirectObject):
notify = directNotify.newCategory('ToonFPS')
WeaponName2DamageData = {'pistol': (36.0, 10.0, 150.0, 0.25),
'shotgun': (40.0, 15.0, 155.0, 0.5)}
def __init__(self, mg, weaponName = 'pistol'):
self.mg = mg
self.weaponName = weaponName
self.v_model_root = None
self.v_model = None
self.weapon = None
self.track = None
self.draw = None
self.shoot = None
self.reload = None
self.empty = None
self.cockBack = None
self.cockFwd = None
self.player_node = None
self.shooterTrav = None
self.shooterRay = None
self.shooterRayNode = None
self.shooterHandler = None
self.gui = ToonFPSGui(self)
self.fsm = ClassicFSM('ToonFPS', [State('off', self.enterOff, self.exitOff), State('alive', self.enterAlive, self.exitAlive), State('dead', self.enterDead, self.exitDead)], 'off', 'off')
self.aliveFSM = ClassicFSM('alive', [State('off', self.enterOff, self.exitOff),
State('draw', self.enterDraw, self.exitDraw, ['idle']),
State('idle', self.enterIdle, self.exitIdle, ['shoot', 'reload']),
State('shoot', self.enterShoot, self.exitShoot, ['idle']),
State('reload', self.enterReload, self.exitReload, ['idle'])], 'off', 'off')
self.fsm.getStateNamed('alive').addChild(self.aliveFSM)
self.fsm.enterInitialState()
self.aliveFSM.enterInitialState()
if self.weaponName == 'pistol':
self.ammo = 14
elif self.weaponName == 'shotgun':
self.ammo = 7
self.hp = 125
self.max_hp = 125
self.firstPerson = FirstPerson()
return
def movementTask(self, task):
if not inputState.isSet('jump') and not base.localAvatar.walkControls.isAirborne and inputState.isSet('forward') or inputState.isSet('reverse') or inputState.isSet('slideLeft') or inputState.isSet('slideRight'):
if base.localAvatar.getAnimState() != 'run':
base.localAvatar.setAnimState('run')
base.localAvatar.playMovementSfx('run')
self.mg.sendUpdate('runningAvatar', [base.localAvatar.doId])
elif inputState.isSet('jump') or base.localAvatar.walkControls.isAirborne:
if base.localAvatar.getAnimState() != 'jump':
base.localAvatar.setAnimState('jump')
base.localAvatar.playMovementSfx(None)
self.mg.sendUpdate('jumpingAvatar', [base.localAvatar.doId])
elif base.localAvatar.getAnimState() != 'neutral':
base.localAvatar.setAnimState('neutral')
base.localAvatar.playMovementSfx(None)
self.mg.sendUpdate('standingAvatar', [base.localAvatar.doId])
return Task.cont
def enterAlive(self):
if self.mg.fsm.getCurrentState().getName() not in ('gameOver', 'announceGameOver', 'finalScores'):
base.localAvatar.disableChatInput()
self.start()
self.resetHp()
self.resetAmmo()
if self.mg.fsm.getCurrentState().getName() == 'play':
self.reallyStart()
def exitAlive(self):
self.end()
self.v_model.reparentTo(hidden)
if self.mg.fsm.getCurrentState().getName() != 'play':
self.reallyEnd()
base.localAvatar.createChatInput()
def updatePoints(self):
self.points = self.kills - self.deaths
def enterDead(self, killer):
base.localAvatar.getGeomNode().show()
self.gui.end()
base.localAvatar.attachCamera()
self.freezeCamSfx = base.loadSfx('phase_4/audio/sfx/freeze_cam.wav')
self.freezeCamImage = None
self.freezeCamImageFile = None
base.camera.setZ(base.camera.getZ() + 2.0)
taskMgr.add(self.cameraLookAtKillerTask, 'lookAtKiller', extraArgs=[killer], appendTask=True)
taskMgr.doMethodLater(2.0, self.startZoomOnKiller, 'startFreezeCam', extraArgs=[killer], appendTask=True)
return
def startZoomOnKiller(self, killer, task):
taskMgr.add(self.__zoomOnKillerTask, 'zoomOnKiller', extraArgs=[killer], appendTask=True)
return task.done
def __zoomOnKillerTask(self, killer, task):
if base.camera.getDistance(killer) <= 10.0 and self.freezeCamSfx.status() == self.freezeCamSfx.READY:
base.playSfx(self.freezeCamSfx)
if base.camera.getDistance(killer) < 7.0:
self.doFreezeCam()
return task.done
#.........这里部分代码省略.........
示例3: ShtickerBook
# 需要导入模块: from direct.fsm.ClassicFSM import ClassicFSM [as 别名]
# 或者: from direct.fsm.ClassicFSM.ClassicFSM import getStateNamed [as 别名]
class ShtickerBook(StateData):
def __init__(self, parentFSM, doneEvent):
self.parentFSM = parentFSM
StateData.__init__(self, doneEvent)
self.fsm = ClassicFSM('ShtickerBook', [State('off', self.enterOff, self.exitOff),
State('optionPage', self.enterOptionPage, self.exitOptionPage, ['districtPage', 'off']),
State('districtPage', self.enterDistrictPage, self.exitDistrictPage, ['optionPage', 'questPage', 'off']),
State('questPage', self.enterQuestPage, self.exitQuestPage, ['inventoryPage', 'districtPage', 'off']),
State('inventoryPage', self.enterInventoryPage, self.exitInventoryPage, ['mapPage', 'questPage', 'off']),
State('mapPage', self.enterMapPage, self.exitMapPage, ['releaseNotesPage', 'inventoryPage', 'off']),
State('releaseNotesPage', self.enterReleaseNotesPage, self.exitReleaseNotesPage, ['mapPage', 'off']),
State('adminPage', self.enterAdminPage, self.exitAdminPage, ['releaseNotesPage', 'off'])], 'off', 'off')
if base.localAvatar.getAdminToken() > -1:
self.fsm.getStateNamed('releaseNotesPage').addTransition('adminPage')
self.fsm.enterInitialState()
self.entered = 0
self.parentFSM.getStateNamed('shtickerBook').addChild(self.fsm)
def enterOff(self):
pass
def exitOff(self):
pass
def load(self):
StateData.load(self)
self.book_contents = loader.loadModel('phase_3.5/models/gui/stickerbook_gui.bam')
self.book_texture = self.book_contents.find('**/big_book')
self.book_open = loader.loadSfx('phase_3.5/audio/sfx/GUI_stickerbook_open.mp3')
self.book_close = loader.loadSfx('phase_3.5/audio/sfx/GUI_stickerbook_delete.mp3')
self.book_turn = loader.loadSfx('phase_3.5/audio/sfx/GUI_stickerbook_turn.mp3')
def unload(self):
self.book_texture.removeNode()
del self.book_texture
self.book_contents.removeNode()
del self.book_contents
loader.unloadSfx(self.book_open)
del self.book_open
loader.unloadSfx(self.book_close)
del self.book_close
loader.unloadSfx(self.book_turn)
del self.book_turn
del self.fsm
del self.parentFSM
del self.entered
StateData.unload(self)
def enter(self):
if self.entered:
return
self.entered = 1
StateData.enter(self)
render.hide()
base.setBackgroundColor(0.05, 0.15, 0.4)
self.book_img = OnscreenImage(image=self.book_texture, scale=(2, 1, 1.5))
self.book_open.play()
if base.localAvatar.getAdminToken() > -1:
self.fsm.request('adminPage')
else:
self.fsm.request('mapPage')
def exit(self):
if not self.entered:
return
self.entered = 0
base.setBackgroundColor(CIGlobals.DefaultBackgroundColor)
render.show()
self.book_img.destroy()
del self.book_img
self.book_close.play()
self.fsm.request('off')
StateData.exit(self)
def enterDistrictPage(self):
self.createPageButtons('optionPage', 'questPage')
self.setTitle('Districts')
currDistrictName = base.cr.myDistrict.getDistrictName()
if not currDistrictName.isalpha():
currDistrictName = currDistrictName[:-1]
self.infoLbl = OnscreenText(text='Each District is a copy of the Cog Invasion world.\n\n\nYou are currently in the "%s" District' % currDistrictName, pos=(0.05, 0.3), align=TextNode.ALeft, wordwrap=12)
self.populationLbl = OnscreenText(text='Population: %d' % base.cr.myDistrict.getPopulation(), pos=(0.44, -0.3), align=TextNode.ACenter)
textRolloverColor = Vec4(1, 1, 0, 1)
textDownColor = Vec4(0.5, 0.9, 1, 1)
textDisabledColor = Vec4(0.4, 0.8, 0.4, 1)
self.shardButtons = []
for shard in base.cr.activeDistricts.values():
shardName = shard.getDistrictName()
shardId = shard.doId
btn = DirectButton(relief=None, text=shardName, text_scale=0.07, text_align=TextNode.ALeft, text1_bg=textDownColor, text2_bg=textRolloverColor, text3_fg=textDisabledColor, textMayChange=0, command=self.__handleShardButton, extraArgs=[shardId], text_pos=(0, 0, 0.0))
if shardId == base.localAvatar.parentId:
btn['state'] = DGG.DISABLED
else:
btn['state'] = DGG.NORMAL
self.shardButtons.append(btn)
gui = loader.loadModel('phase_3.5/models/gui/friendslist_gui.bam')
listXorigin = -0.02
listFrameSizeX = 0.625
#.........这里部分代码省略.........