本文整理汇总了Python中direct.fsm.ClassicFSM.ClassicFSM.requestFinalState方法的典型用法代码示例。如果您正苦于以下问题:Python ClassicFSM.requestFinalState方法的具体用法?Python ClassicFSM.requestFinalState怎么用?Python ClassicFSM.requestFinalState使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类direct.fsm.ClassicFSM.ClassicFSM
的用法示例。
在下文中一共展示了ClassicFSM.requestFinalState方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: TownLoader
# 需要导入模块: from direct.fsm.ClassicFSM import ClassicFSM [as 别名]
# 或者: from direct.fsm.ClassicFSM.ClassicFSM import requestFinalState [as 别名]
class TownLoader(StateData):
notify = directNotify.newCategory('TownLoader')
def __init__(self, hood, parentFSMState, doneEvent):
self.hood = hood
self.parentFSMState = parentFSMState
StateData.__init__(self, doneEvent)
self.fsm = ClassicFSM('TownLoader', [State('start', self.enterStart, self.exitStart, ['quietZone', 'street']),
State('street', self.enterStreet, self.exitStreet, ['quietZone']),
State('toonInterior', self.enterToonInterior, self.exitToonInterior, ['quietZone']),
State('quietZone', self.enterQuietZone, self.exitQuietZone, ['street', 'toonInterior']),
State('final', self.enterFinal, self.exitFinal, ['start'])], 'start', 'final')
self.branchZone = None
self.canonicalBranchZone = None
self.placeDoneEvent = 'placeDone'
self.linkTunnels = []
return
def findAndMakeLinkTunnels(self, requestStatus):
for tunnel in self.geom.findAllMatches('**/*linktunnel*'):
dnaRootStr = tunnel.getName()
zone = LinkTunnel.getZoneFromDNARootStr(dnaRootStr)
zone = LinkTunnel.maybeFixZone(zone)
tunnelClass = LinkTunnel.getRecommendedTunnelClassFromZone(zone)
link = tunnelClass(tunnel, dnaRootStr)
self.linkTunnels.append(link)
def load(self, zoneId):
StateData.load(self)
self.zoneId = zoneId
self.branchZone = ZoneUtil.getBranchZone(zoneId)
self.canonicalBranchZone = ZoneUtil.getCanonicalBranchZone(zoneId)
self.music = base.loadMusic(self.musicFile)
self.interiorMusic = base.loadMusic(self.interiorMusicFile)
def unload(self):
self.parentFSMState.removeChild(self.fsm)
del self.parentFSMState
del self.fsm
del self.streetClass
self.landmarkBlocks.removeNode()
del self.landmarkBlocks
self.hood.dnaStore.resetSuitPoints()
self.hood.dnaStore.resetBattleCells()
del self.hood
del self.nodeDict
del self.zoneDict
del self.fadeInDict
del self.fadeOutDict
del self.nodeList
self.geom.removeNode()
del self.geom
del self.music
del self.interiorMusic
ModelPool.garbageCollect()
TexturePool.garbageCollect()
StateData.unload(self)
def enter(self, requestStatus):
StateData.enter(self)
self.findAndMakeLinkTunnels(requestStatus)
self.fsm.enterInitialState()
self.setState(requestStatus['where'], requestStatus)
def exit(self):
self.fsm.requestFinalState()
self.ignoreAll()
ModelPool.garbageCollect()
TexturePool.garbageCollect()
StateData.exit(self)
def setState(self, state, requestStatus):
self.fsm.request(state, [requestStatus])
def enterStart(self):
pass
def exitStart(self):
pass
def enterStreet(self, requestStatus):
self.acceptOnce(self.placeDoneEvent, self.streetDone)
self.place = self.streetClass(self, self.fsm, self.placeDoneEvent)
self.place.load()
def exitStreet(self):
self.ignore(self.placeDoneEvent)
self.place.exit()
self.place.unload()
self.place = None
base.cr.playGame.setPlace(self.place)
return
def streetDone(self):
self.requestStatus = self.place.doneStatus
status = self.place.doneStatus
if status['loader'] == 'townLoader' and ZoneUtil.getBranchZone(status['zoneId']) == self.branchZone and status['shardId'] == None or status['how'] == 'doorOut':
self.fsm.request('quietZone', [status])
else:
self.doneStatus = status
#.........这里部分代码省略.........
示例2: AdminPage
# 需要导入模块: from direct.fsm.ClassicFSM import ClassicFSM [as 别名]
# 或者: from direct.fsm.ClassicFSM.ClassicFSM import requestFinalState [as 别名]
class AdminPage(StateData):
notify = directNotify.newCategory('AdminPage')
def __init__(self, book, parentFSM):
self.book = book
self.parentFSM = parentFSM
StateData.__init__(self, 'adminPageDone')
self.fsm = ClassicFSM('AdminPage', [State('off', self.enterOff, self.exitOff),
State('basePage', self.enterBasePage, self.exitBasePage),
State('kickSection', self.enterKickSection, self.exitKickSection),
State('sysMsgSection', self.enterSysMsgSection, self.exitSysMsgSection)], 'off', 'off')
self.fsm.enterInitialState()
self.parentFSM.getStateNamed('adminPage').addChild(self.fsm)
def enterOff(self):
pass
def exitOff(self):
pass
def enter(self):
StateData.enter(self)
self.fsm.request('basePage')
def exit(self):
self.fsm.requestFinalState()
StateData.exit(self)
def unload(self):
del self.book
del self.parentFSM
del self.fsm
StateData.unload(self)
def enterSysMsgSection(self):
self.book.createPageButtons(None, None)
self.book.setTitle('System Message')
geom = CIGlobals.getDefaultBtnGeom()
self.infoLbl = OnscreenText(text='Inform all online players about something.', pos=(0, 0.45))
self.msgEntry = DirectEntry(initialText='System Message...', scale=0.055, width=15, numLines=4, command=self.sendSystemMessageCommand, focusInCommand=base.localAvatar.chatInput.disableKeyboardShortcuts, focusOutCommand=base.localAvatar.chatInput.enableKeyboardShortcuts, pos=(-0.4, 0, 0))
self.sendBtn = DirectButton(geom=geom, text_scale=0.04, relief=None, scale=1.0, text='Send', pos=(0, 0, -0.35), text_pos=(0, -0.01), command=self.sendSystemMessageCommand)
self.cancelBtn = DirectButton(geom=geom, text_scale=0.04, relief=None, scale=1.0, text='Cancel', pos=(-0.45, 0.15, -0.55), text_pos=(0, -0.01), command=self.fsm.request, extraArgs=['basePage'])
return
def sendSystemMessageCommand(self, foo = None):
msg = self.msgEntry.get()
base.cr.myDistrict.sendUpdate('systemMessageCommand', [base.localAvatar.getAdminToken(), msg])
self.fsm.request('basePage')
def exitSysMsgSection(self):
self.infoLbl.destroy()
del self.infoLbl
self.msgEntry.destroy()
del self.msgEntry
self.sendBtn.destroy()
del self.sendBtn
self.cancelBtn.destroy()
del self.cancelBtn
self.book.clearTitle()
self.book.deletePageButtons(False, False)
def enterKickSection(self):
self.book.createPageButtons(None, None)
self.book.setTitle('Kick Player')
geom = CIGlobals.getDefaultBtnGeom()
self.infoLbl = OnscreenText(text='Type the ID of the player you want to boot out.', pos=(0, 0.45))
self.idEntry = DirectEntry(width=10, scale=0.12, pos=(-0.59, 0, 0.15), command=self.sendKickMessage, focusInCommand=base.localAvatar.chatInput.disableKeyboardShortcuts, focusOutCommand=base.localAvatar.chatInput.enableKeyboardShortcuts)
self.kickBtn = DirectButton(geom=geom, text_scale=0.04, relief=None, scale=1.0, text='Kick', pos=(0, 0, -0.15), text_pos=(0, -0.01), command=self.sendKickMessage)
self.banBtn = DirectButton(geom=geom, text_scale=0.04, relief=None, scale=1.0, text='Ban', pos=(0, 0, -0.25), text_pos=(0, -0.01), command=self.sendKickMessage, extraArgs=[None, 1])
self.cancelBtn = DirectButton(geom=geom, text_scale=0.04, relief=None, scale=1.0, text='Cancel', pos=(-0.45, 0.15, -0.45), text_pos=(0, -0.01), command=self.fsm.request, extraArgs=['basePage'])
return
def sendKickMessage(self, foo = None, andBan = 0):
if self.idEntry.get().isspace() or len(self.idEntry.get()) == 0:
return
print 'Sending out kick request for avatar id: ' + str(self.idEntry.get())
base.localAvatar.sendUpdate('requestEject', [int(self.idEntry.get()), andBan])
self.fsm.request('basePage')
def exitKickSection(self):
self.banBtn.destroy()
del self.banBtn
self.infoLbl.destroy()
del self.infoLbl
self.cancelBtn.destroy()
del self.cancelBtn
self.idEntry.destroy()
del self.idEntry
self.kickBtn.destroy()
del self.kickBtn
self.book.deletePageButtons(False, False)
self.book.clearTitle()
def enterBasePage(self):
self.book.createPageButtons('releaseNotesPage', None)
self.book.setTitle('Admin Stuff')
geom = CIGlobals.getDefaultBtnGeom()
self.suitSpawnerBtn = DirectButton(geom=geom, text_scale=0.04, relief=None, scale=1.0, text='', pos=(-0.45, 0.15, 0.5), text_pos=(0, -0.01), command=self.sendSuitCommand, extraArgs=['suitSpawner'])
self.killCogsBtn = DirectButton(geom=geom, text_scale=0.04, relief=None, scale=1.0, text='Kill All Cogs', pos=(-0.45, 0.15, 0.4), text_pos=(0, -0.01), command=self.sendSuitCommand, extraArgs=['killCogs'])
self.makeTournamentBtn = DirectButton(geom=geom, text_scale=0.04, relief=None, scale=1.0, text='Make Cog Tournament', pos=(-0.45, 0.15, 0.3), text_pos=(0, -0.01), command=self.sendSuitCommand, extraArgs=['tournament'])
#.........这里部分代码省略.........
示例3: DistributedBoat
# 需要导入模块: from direct.fsm.ClassicFSM import ClassicFSM [as 别名]
# 或者: from direct.fsm.ClassicFSM.ClassicFSM import requestFinalState [as 别名]
class DistributedBoat(DistributedObject):
notify = directNotify.newCategory('DistributedBoat')
def __init__(self, cr):
DistributedObject.__init__(self, cr)
self.fsm = ClassicFSM('DistributedBoat', [State('off', self.enterOff, self.exitOff), State('eastToWest', self.enterEastToWest, self.exitEastToWest), State('westToEast', self.enterWestToEast, self.exitWestToEast)], 'off', 'off')
self.boat = None
self.eastPier = None
self.eastPierPath = 'east_pier'
self.westPier = None
self.westPierPath = 'west_pier'
self.pierUpP = 0.0
self.pierDownP = -45.0
self.fogHorn = 'phase_5/audio/sfx/SZ_DD_foghorn.mp3'
self.shipBell = 'phase_6/audio/sfx/SZ_DD_shipbell.mp3'
self.waterLap = 'phase_6/audio/sfx/SZ_DD_waterlap.mp3'
self.dockCreak = 'phase_6/audio/sfx/SZ_DD_dockcreak.mp3'
self.eastWest = 'phase_6/paths/dd-e-w.bam'
self.westEast = 'phase_6/paths/dd-w-e.bam'
self.boatPath = '*donalds_boat*'
self.track = None
self.state = None
return
def __handleOnBoat(self, entry):
base.localAvatar.b_setParent(CIGlobals.SPDonaldsBoat)
base.playSfx(self.soundWaterLap, looping=1)
def __handleOffBoat(self, entry):
base.localAvatar.b_setParent(CIGlobals.SPRender)
self.soundWaterLap.stop()
def __pollBoat(self, task):
try:
self.boat = self.cr.playGame.hood.loader.geom.find('**/' + self.boatPath)
except:
return task.cont
self.generated()
return task.done
def generate(self):
DistributedObject.generate(self)
self.soundFogHorn = base.loadSfx(self.fogHorn)
self.soundShipBell = base.loadSfx(self.shipBell)
self.soundWaterLap = base.loadSfx(self.waterLap)
self.soundDockCreak = base.loadSfx(self.dockCreak)
self.boat = self.cr.playGame.hood.loader.geom.find('**/' + self.boatPath)
self.generated()
def generated(self):
self.eastPier = self.cr.playGame.hood.loader.geom.find('**/' + self.eastPierPath)
self.westPier = self.cr.playGame.hood.loader.geom.find('**/' + self.westPierPath)
base.cr.parentMgr.registerParent(CIGlobals.SPDonaldsBoat, self.boat)
self.accept('enterdonalds_boat_floor', self.__handleOnBoat)
self.accept('exitdonalds_boat_floor', self.__handleOffBoat)
self.d_requestCurrentStateAndTimestamp()
self.fsm.enterInitialState()
def disable(self):
base.taskMgr.remove(self.uniqueName('__pollBoat'))
base.cr.parentMgr.unregisterParent(CIGlobals.SPDonaldsBoat)
self.ignore('enterdonalds_boat_floor')
self.ignore('exitdonalds_boat_floor')
self.fsm.requestFinalState()
del self.fsm
del self.soundFogHorn
del self.soundShipBell
del self.soundWaterLap
del self.soundDockCreak
self.fogHorn = None
self.shipBell = None
self.waterLap = None
self.dockCreak = None
self.boat = None
self.track = None
self.pierDownP = None
self.pierUpP = None
self.eastPier = None
self.eastPierPath = None
self.westPier = None
self.westPierPath = None
self.boatPath = None
self.westEast = None
self.eastWest = None
DistributedObject.disable(self)
return
def currentStateAndTimestamp(self, state, timestamp):
self.setState(state, timestamp)
def d_requestCurrentStateAndTimestamp(self):
self.sendUpdate('requestCurrentStateAndTimestamp', [])
def setState(self, state, timestamp = None):
if timestamp == None:
ts = 0.0
else:
ts = globalClockDelta.localElapsedTime(timestamp)
self.state = state
#.........这里部分代码省略.........
示例4: AvChooser
# 需要导入模块: from direct.fsm.ClassicFSM import ClassicFSM [as 别名]
# 或者: from direct.fsm.ClassicFSM.ClassicFSM import requestFinalState [as 别名]
class AvChooser(StateData):
notify = directNotify.newCategory('AvChooser')
def __init__(self, parentFSM):
StateData.__init__(self, 'avChooseDone')
self.avChooseFSM = ClassicFSM('avChoose', [State('getToonData', self.enterGetToonData, self.exitGetToonData),
State('avChoose', self.enterAvChoose, self.exitAvChoose),
State('waitForToonDelResponse', self.enterWaitForToonDelResponse, self.exitWaitForToonDelResponse),
State('off', self.enterOff, self.exitOff)], 'off', 'off')
self.avChooseFSM.enterInitialState()
self.parentFSM = parentFSM
self.parentFSM.getStateNamed('avChoose').addChild(self.avChooseFSM)
self.pickAToon = None
self.setAvatarsNone()
return
def enter(self):
StateData.enter(self)
base.transitions.noTransitions()
self.avChooseFSM.request('getToonData')
def exit(self):
StateData.exit(self)
self.setAvatarsNone()
self.avChooseFSM.requestFinalState()
def setAvatarsNone(self):
self.avChoices = []
def enterOff(self):
pass
def exitOff(self):
pass
def enterGetToonData(self):
self.acceptOnce(base.cr.csm.getSetAvatarsEvent(), self.handleToonData)
base.cr.csm.d_requestAvatars()
def handleToonData(self, avatarList):
for av in avatarList:
avId = av[0]
dna = av[1]
name = av[2]
slot = av[3]
choice = AvChoice(dna, name, slot, avId)
self.avChoices.append(choice)
self.avChooseFSM.request('avChoose')
def exitGetToonData(self):
self.ignore(base.cr.csm.getSetAvatarsEvent())
def enterAvChoose(self):
self.pickAToon = CharSelection(self)
self.pickAToon.load()
def enterWaitForToonDelResponse(self, avId):
self.acceptOnce(base.cr.csm.getToonDeletedEvent(), self.handleDeleteToonResp)
base.cr.csm.sendDeleteToon(avId)
def exitWaitForToonDelResponse(self):
self.ignore(base.cr.csm.getToonDeletedEvent())
def hasToonInSlot(self, slot):
if self.getAvChoiceBySlot(slot) != None:
return True
else:
return False
return
def getNameInSlot(self, slot):
return self.getAvChoiceBySlot(slot).getName()
def getAvChoiceBySlot(self, slot):
for avChoice in self.avChoices:
if avChoice.getSlot() == slot:
return avChoice
return None
def getHeadInfo(self, slot):
dna = self.getAvChoiceBySlot(slot).getDNA()
self.pickAToon.dna.setDNAStrand(dna)
return [self.pickAToon.dna.getGender(),
self.pickAToon.dna.getAnimal(),
self.pickAToon.dna.getHead(),
self.pickAToon.dna.getHeadColor()]
def handleDeleteToonResp(self):
base.cr.loginFSM.request('avChoose')
def exitAvChoose(self):
self.pickAToon.unload()
self.pickAToon = None
return
示例5: DistributedCityCart
# 需要导入模块: from direct.fsm.ClassicFSM import ClassicFSM [as 别名]
# 或者: from direct.fsm.ClassicFSM.ClassicFSM import requestFinalState [as 别名]
#.........这里部分代码省略.........
'leftBackWheel']:
wheel = self.find('**/' + name)
self.wheelSpinTrack.append(LerpHprInterval(wheel, duration=0.1, hpr=(0, 360, 0), startHpr=(0, 0, 0)))
self.wheelSpinTrack.loop()
self.accept('enter' + self.collNodePath.node().getName(), self.__handleRanOver)
def __handleRanOver(self, entry):
self.suitInCar.setChat(CityCartGlobals.SuitRanOverTaunt)
self.sendUpdate('hitByCar')
self.cr.playGame.getPlace().fsm.request('stop')
base.localAvatar.b_setAnimState('squish', callback=self.cr.playGame.getPlace().fsm.request, extraArgs=['walk'])
def __drive(self, task):
if base.localAvatar.getDistance(self) < 10.0:
if self.soundDriveByHorn.status() == self.soundDriveByHorn.READY:
wantsToHonk = random.randint(0, 3)
if wantsToHonk == 3:
base.playSfx(self.soundDriveByHorn)
return task.cont
elif base.localAvatar.getDistance(self) < 20.0:
if self.soundDriveBy.status() == self.soundDriveBy.READY:
base.playSfx(self.soundDriveBy)
return task.cont
return task.cont
def exitPathFollow(self):
self.ignore('enter' + self.collNodePath.node().getName())
if self.wheelSpinTrack:
self.wheelSpinTrack.finish()
self.wheelSpinTrack = None
if self.moPath:
self.moPath.stop()
self.moPath = None
return
def enterCollision(self, ts):
pass
def exitCollision(self):
pass
def generate(self):
DistributedNode.generate(self)
self.cart = loader.loadModel(self.cartModelPath)
self.cart.reparentTo(self)
self.cart.setH(180)
heads = []
for head in CIGlobals.SuitBodyData.keys():
if CIGlobals.SuitBodyData[head][0] != 'B':
heads.append(head)
head = random.choice(heads)
suitType = CIGlobals.SuitBodyData[head][0]
suitDept = CIGlobals.SuitBodyData[head][1]
self.suitInCar = Suit()
self.suitInCar.generateSuit(suitType, head, suitDept, 137, 0, False)
self.suitInCar.loop('sit')
self.suitInCar.disableRay()
self.suitInCar.setScale(0.7)
self.suitInCar.setH(180)
self.suitInCar.setPos(0, -1, -1.5)
self.suitInCar.reparentTo(self.cart.find('**/seat1'))
self.soundEngineLoop = base.audio3d.loadSfx('phase_6/audio/sfx/KART_Engine_loop_0.wav')
base.audio3d.attachSoundToObject(self.soundEngineLoop, self)
base.playSfx(self.soundEngineLoop, looping=1)
self.soundDriveByHorn = base.audio3d.loadSfx(self.honkSfxPath)
base.audio3d.attachSoundToObject(self.soundDriveByHorn, self)
self.soundDriveBy = base.audio3d.loadSfx('phase_14/audio/sfx/cogtropolis_citycar_driveby.mp3')
base.audio3d.attachSoundToObject(self.soundDriveBy, self)
sphere = CollisionSphere(0, 0, 0, 2.5)
sphere.setTangible(0)
node = CollisionNode(self.uniqueName('cartSphere'))
node.setCollideMask(CIGlobals.WallBitmask)
node.addSolid(sphere)
self.collNodePath = self.attachNewNode(node)
self.collNodePath.setZ(1.5)
self.collNodePath.setSy(2.0)
self.collNodePath.setSx(1.75)
def disable(self):
self.fsm.requestFinalState()
if self.moPath:
self.moPath.stop()
self.moPath = None
self.moPaths = None
self.honkSfxPath = None
self.cartModelPath = None
self.soundEngineLoop = None
self.soundDriveBy = None
if self.suitInCar:
self.suitInCar.disable()
self.suitInCar.delete()
self.suitInCar = None
if self.cart:
self.cart.removeNode()
self.cart = None
del self.fsm
DistributedNode.disable(self)
return
示例6: __init__
# 需要导入模块: from direct.fsm.ClassicFSM import ClassicFSM [as 别名]
# 或者: from direct.fsm.ClassicFSM.ClassicFSM import requestFinalState [as 别名]
#.........这里部分代码省略.........
self.iceCube.removeNode()
del self.iceCube
def enterFreezeUp(self):
length = 1.0
base.playSfx(self.freezeUpSfx)
self.fucsIval = Sequence(LerpColorScaleInterval(base.localAvatar.getGeomNode(), duration=length, colorScale=VBase4(0.5, 0.5, 1.0, 1.0), startColorScale=base.localAvatar.getGeomNode().getColorScale(), blendType='easeOut'), Func(self.fsm.request, 'frozen'))
self.fucsIval.start()
self.playground.startWaterWatch(0)
def exitFreezeUp(self):
self.fucsIval.pause()
del self.fucsIval
self.playground.stopWaterWatch()
def enterFrozen(self):
self.loadIceCube()
base.cr.playGame.getPlace().fsm.request('stop', [0])
base.localAvatar.stop()
base.playSfx(choice(self.frozenSfxArray))
self.iccsIval = LerpColorScaleInterval(self.iceCube, duration=0.5, colorScale=VBase4(0.76, 0.76, 1.0, 1.0), startColorScale=self.iceCube.getColorScale(), blendType='easeInOut')
self.iccsIval.start()
props = WindowProperties()
props.setCursorHidden(True)
base.win.requestProperties(props)
self.frame = DirectFrame(pos=(0, 0, 0.7))
self.powerBar = DirectWaitBar(frameColor=(1, 1, 1, 1), range=100, value=0, scale=(0.4, 0.5, 0.25), parent=self.frame, barColor=(0.55, 0.7, 1.0, 1.0))
self.label = OnscreenText(text='SHAKE MOUSE', shadow=(0, 0, 0, 1), fg=(0.55, 0.7, 1.0, 1.0), pos=(0, -0.1, 0), parent=self.frame)
taskMgr.add(self.__watchMouseMovement, 'BRWater-watchMouseMovement')
taskMgr.add(self.__lowerPowerBar, 'BRWater-lowerPowerBar')
mw = base.mouseWatcherNode
if mw.hasMouse():
self.lastMouseX = mw.getMouseX()
def __lowerPowerBar(self, task):
if self.powerBar['value'] <= 0:
self.powerBar.update(0)
decrement = 1
self.powerBar.update(self.powerBar['value'] - decrement)
task.delayTime = 0.1
return task.again
def __watchMouseMovement(self, task):
if self.powerBar['value'] >= self.powerBar['range']:
self.fsm.request('coolDown', [1])
return task.done
mw = base.mouseWatcherNode
if mw.hasMouse():
if not self.lastMouseX or self.lastMouseX != mw.getMouseX():
value = 3 * self.lastMouseX - mw.getMouseX()
self.lastMouseX = mw.getMouseX()
self.powerBar.update(self.powerBar['value'] + abs(value))
return task.cont
def exitFrozen(self):
props = WindowProperties()
props.setCursorHidden(False)
base.win.requestProperties(props)
self.iccsIval.pause()
del self.iccsIval
self.unloadIceCube()
taskMgr.remove('BRWater-lowerPowerBar')
taskMgr.remove('BRWater-watchMouseMovement')
self.label.destroy()
del self.label
self.powerBar.destroy()
del self.powerBar
self.frame.destroy()
del self.frame
del self.lastMouseX
base.cr.playGame.getPlace().fsm.request('walk')
base.localAvatar.b_setAnimState('neutral')
def enterCoolDown(self, fromFrozen = 0):
if fromFrozen:
self.loadIceCube()
self.iceCube.setColorScale(0.76, 0.76, 1.0, 1.0)
self.iccdIval = LerpColorScaleInterval(self.iceCube, duration=0.5, colorScale=VBase4(0.76, 0.76, 1.0, 0.0), startColorScale=self.iceCube.getColorScale(), blendType='easeInOut')
self.iccdIval.start()
length = 1.0
base.playSfx(choice(self.coolSfxArray))
self.cdcsIval = Sequence(LerpColorScaleInterval(base.localAvatar.getGeomNode(), duration=length, colorScale=VBase4(1.0, 1.0, 1.0, 1.0), startColorScale=base.localAvatar.getGeomNode().getColorScale(), blendType='easeOut'), Func(self.fsm.request, 'off'))
self.cdcsIval.start()
def exitCoolDown(self):
if hasattr(self, 'iccdIval'):
self.iccdIval.pause()
del self.iccdIval
self.unloadIceCube()
self.cdcsIval.pause()
del self.cdcsIval
def cleanup(self):
self.fsm.requestFinalState()
self.playground.stopWaterWatch()
del self.fsm
del self.freezeUpSfx
del self.frozenSfxArray
del self.coolSfxArray
del self.playground
示例7: DistributedRaceGame
# 需要导入模块: from direct.fsm.ClassicFSM import ClassicFSM [as 别名]
# 或者: from direct.fsm.ClassicFSM.ClassicFSM import requestFinalState [as 别名]
#.........这里部分代码省略.........
self.stopMovement()
def enterRaceOff(self):
pass
def exitRaceOff(self):
pass
def enterRaceTransition(self):
self.raceTrans = Sequence(Wait(0.5), Func(self.moveCameraToToon), Wait(4.5), Func(self.moveCameraToTop), Wait(4.5), Func(self.startCountdown))
self.raceTrans.start()
def exitRaceTransition(self):
self.raceTrans.pause()
del self.raceTrans
def startMovement(self):
self.movement.createGui()
self.movement.fsm.request('run')
def enterGameOver(self, winner = 0, winnerDoId = 0, allPrize = 0):
self.raceFSM.request('off')
DistributedMinigame.DistributedMinigame.enterGameOver(self, winner, winnerDoId, allPrize)
def stopMovement(self):
self.movement.cleanup()
self.movement.deleteGui()
def startCountdown(self):
""" Start the countdown to the start of the race. """
self.countdownLbl = DirectLabel(text='', text_scale=0.3, text_font=CIGlobals.getMickeyFont(), text_fg=(1, 1, 0, 1), pos=(0, 0, 0.5))
Sequence(Func(self.setCountdownText, '3'), Wait(1.0), Func(self.setCountdownText, '2'), Wait(1.0), Func(self.setCountdownText, '1'), Wait(1.0), Func(self.setCountdownText, 'GO!'), Wait(1.5), Func(self.deleteCountdownLabel)).start()
def setCountdownText(self, number):
self.countdownLbl['text'] = number
if number == 'GO!':
self.countdownLbl['text_fg'] = (0, 1, 0, 1)
self.goSfx.play()
self.raceFSM.request('race')
else:
self.countSfx.play()
def deleteCountdownLabel(self):
self.countdownLbl.destroy()
del self.countdownLbl
def moveCameraToToon(self):
camPInt = LerpPosInterval(camera, duration=3.0, pos=self.localAv.getPos(render) + (0, 15, 3), startPos=camera.getPos(render), blendType='easeInOut')
camQInt = camera.quatInterval(3.0, hpr=Vec3(180, 0, 0), blendType='easeInOut')
camPInt.start()
camQInt.start()
def moveCameraToTop(self):
camera.setPos(camera.getPos(self.localAv))
camera.reparentTo(self.localAv)
oldPos = camera.getPos()
camera.setPos(self.raceCamPos)
oldHpr = camera.getHpr()
camera.lookAt(self.localAv.getPart('head'))
newHpr = camera.getHpr()
camera.setHpr(oldHpr)
camera.setPos(oldPos)
camPInt = LerpPosInterval(camera, duration=3.0, pos=self.raceCamPos, startPos=oldPos, blendType='easeInOut')
camQInt = camera.quatInterval(3.0, hpr=newHpr, blendType='easeInOut')
camPInt.start()
camQInt.start()
def deleteWorld(self):
if self.track:
self.track.removeNode()
self.track = None
if self.sky:
self.skyUtil.stopSky()
self.sky.removeNode()
self.sky = None
return
def setToonLane(self, lane):
self.lane = lane
base.localAvatar.setPos(self.lanePos[lane])
base.localAvatar.setHpr(0, 0, 0)
def getToonLane(self):
return self.lane
def d_requestToonLane(self):
self.sendUpdate('requestToonLane', [])
def announceGenerate(self):
DistributedMinigame.DistributedMinigame.announceGenerate(self)
self.load()
def disable(self):
DistributedMinigame.DistributedMinigame.disable(self)
self.deleteWorld()
self.raceFSM.requestFinalState()
del self.raceFSM
self.countSfx = None
self.goSfx = None
return
示例8: DistributedMinigame
# 需要导入模块: from direct.fsm.ClassicFSM import ClassicFSM [as 别名]
# 或者: from direct.fsm.ClassicFSM.ClassicFSM import requestFinalState [as 别名]
#.........这里部分代码省略.........
Sequence(Wait(3.5), Func(self.displayGameOver, 'winner')).start()
def showPrize(self, amt):
self.winSfx.play()
self.localAv.b_setAnimState('happy')
Sequence(Wait(3.5), Func(self.displayGameOver, 'showPrize', amt)).start()
def loser(self):
self.loseSfx.play()
self.localAv.b_setAnimState('neutral')
Sequence(Wait(3.5), Func(self.displayGameOver, 'loser')).start()
def displayGameOver(self, scenario, amt = None):
if scenario == 'winner':
msg = self.winnerMsg % self.winnerPrize
self.prizeHigh.play()
elif scenario == 'loser':
msg = self.loserMsg % self.loserPrize
self.prizeLow.play()
elif scenario == 'showPrize':
msg = random.choice(self.allWinnerMsgs) % amt
self.prizeHigh.play()
self.gameOverDialog = GlobalDialog(message=msg, style=3, doneEvent='gameOverAck')
self.acceptOnce('gameOverAck', self.__handleGameOverAck)
self.gameOverDialog.show()
def deleteGameOverDialog(self):
self.ignore('gameOverAck')
if hasattr(self, 'gameOverDialog'):
self.gameOverDialog.cleanup()
del self.gameOverDialog
def __handleGameOverAck(self):
self.fsm.requestFinalState()
Sequence(Func(base.transitions.irisOut, 1.0), Wait(1.2), Func(self.d_leaving), Func(self.headBackToMinigameArea)).start()
def headBackToMinigameArea(self):
whereName = ZoneUtil.getWhereName(CIGlobals.MinigameAreaId)
loaderName = ZoneUtil.getLoaderName(CIGlobals.MinigameAreaId)
requestStatus = {'zoneId': CIGlobals.MinigameAreaId,
'hoodId': CIGlobals.MinigameArea,
'where': whereName,
'how': 'teleportIn',
'avId': base.localAvatar.doId,
'shardId': None,
'loader': loaderName}
self.cr.playGame.hood.fsm.request('quietZone', [requestStatus])
return
def abort(self):
self.headBackToMinigameArea()
def load(self):
self.fsm.request('start')
base.transitions.irisIn()
def d_leaving(self):
""" Tell the AI that we are leaving. """
self.sendUpdate('leaving', [])
def allPlayersReady(self):
self.fsm.request('play')
def enterPlay(self):
self.playMinigameMusic()
示例9: RaceGameMovement
# 需要导入模块: from direct.fsm.ClassicFSM import ClassicFSM [as 别名]
# 或者: from direct.fsm.ClassicFSM.ClassicFSM import requestFinalState [as 别名]
#.........这里部分代码省略.........
return
def isTooFast(self):
""" Determine if the delay between key presses in seconds is too low. """
return self.getDelayTime() < self.MINIMUM_KEY_DELAY
def resetKeys(self):
""" Reset the value of the keys. """
for key in self.keysPressed:
self.keysPressed[key] = 0
def changePower(self):
""" Increase the avatar's movement power. """
self.power = self.POWER_FACTOR / self.getDelayTime()
if self.boostBar['barColor'] != self.fullBoostBarColor:
if self.power >= self.powerBar['range']:
self.boostBar['value'] += 0.8
if self.boostBar['value'] >= self.boostBar['range']:
self.boostBar['barColor'] = self.fullBoostBarColor
self.boostFullLbl.show()
self.acceptOnce('control', self.boostKeyPressed)
print self.power
self.powerBar.update(self.power)
def startDelayTimer(self):
self.startTime = globalClock.getFrameTime()
def stopDelayTimer(self):
self.endTime = globalClock.getFrameTime()
def resetDelayTimer(self):
self.startTime = 0.0
self.endTime = 0.0
def restartDelayTimer(self):
self.stopDelayTimer()
self.resetDelayTimer()
self.startDelayTimer()
def getDelayTime(self):
return self.endTime - self.startTime
def enterRun(self):
""" Start moving the avatar, make the avatar run, and
start tracking the delay between key presses. """
taskMgr.add(self.move, 'move')
if self.boostBar['barColor'] == self.fullBoostBarColor:
self.boostFullLbl.show()
self.acceptOnce('control', self.boostKeyPressed)
self.startDelayTimer()
self.enableArrowKeys()
self.avatar.b_setAnimState('run')
self.isStopped = False
def exitRun(self):
""" Stop moving the avatar, make the avatar stand, and stop
tracking the delay between key presses. """
taskMgr.remove('move')
self.boostFSM.request('off')
if self.boostBar['barColor'] == self.fullBoostBarColor:
self.boostFullLbl.hide()
self.ignore('control')
self.stopDelayTimer()
self.resetDelayTimer()
self.disableArrowKeys()
self.avatar.b_setAnimState('neutral')
self.isStopped = True
self.power = self.MINIMUM_POWER
self.powerBar.update(0)
def enterOff(self):
pass
def exitOff(self):
pass
def enterFinal(self):
pass
def exitFinal(self):
pass
def decreasePower(self, task):
""" Decrease power so the avatar does not keep the same amount
of power while not tapping the arrow keys. """
if self.power > self.MINIMUM_POWER:
self.power -= self.POWER_FACTOR / 0.01
if self.power < self.MINIMUM_POWER:
self.power = self.MINIMUM_POWER
task.delayTime = 0.5
return Task.again
def move(self, task):
""" Move the avatar forward on the Y axis with the current amount of power. """
dt = globalClock.getDt()
self.avatar.setY(self.avatar.getY() + self.power * dt)
return Task.cont
def cleanup(self):
self.fsm.requestFinalState()
示例10: CameraShyFirstPerson
# 需要导入模块: from direct.fsm.ClassicFSM import ClassicFSM [as 别名]
# 或者: from direct.fsm.ClassicFSM.ClassicFSM import requestFinalState [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