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


Python ClassicFSM.enterInitialState方法代码示例

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


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

示例1: ToonInterior

# 需要导入模块: from direct.fsm.ClassicFSM import ClassicFSM [as 别名]
# 或者: from direct.fsm.ClassicFSM.ClassicFSM import enterInitialState [as 别名]
class ToonInterior(Place.Place):
    notify = directNotify.newCategory('ToonInterior')

    def __init__(self, hood, parentFSM, doneEvent):
        self.parentFSM = parentFSM
        Place.Place.__init__(self, hood, doneEvent)
        self.fsm = ClassicFSM('ToonInterior', [State('start', self.enterStart, self.exitStart, ['doorOut', 'teleportIn']),
         State('walk', self.enterWalk, self.exitWalk, ['stop',
          'doorIn',
          'shtickerBook',
          'teleportOut']),
         State('shtickerBook', self.enterShtickerBook, self.exitShtickerBook, ['teleportOut', 'walk']),
         State('teleportOut', self.enterTeleportOut, self.exitTeleportOut, ['teleportIn', 'stop']),
         State('teleportIn', self.enterTeleportIn, self.exitTeleportIn, ['walk', 'stop']),
         State('tunnelOut', self.enterTunnelOut, self.exitTunnelOut, ['walk']),
         State('tunnelIn', self.enterTunnelIn, self.exitTunnelIn, ['stop']),
         State('stop', self.enterStop, self.exitStop, ['walk',
          'died',
          'teleportOut',
          'doorIn']),
         State('doorIn', self.enterDoorIn, self.exitDoorIn, ['stop']),
         State('doorOut', self.enterDoorOut, self.exitDoorOut, ['walk']),
         State('final', self.enterFinal, self.exitFinal, ['final'])], 'start', 'final')

    def enter(self, requestStatus):
        Place.Place.enter(self)
        self.fsm.enterInitialState()
        base.playMusic(self.loader.interiorMusic, volume=0.8, looping=1)
        self.fsm.request(requestStatus['how'], [requestStatus])

    def exit(self):
        self.loader.interiorMusic.stop()
        Place.Place.exit(self)

    def load(self):
        Place.Place.load(self)
        self.parentFSM.getStateNamed('toonInterior').addChild(self.fsm)

    def unload(self):
        self.parentFSM.getStateNamed('toonInterior').removeChild(self.fsm)
        del self.fsm
        del self.parentFSM
        self.ignoreAll()
        Place.Place.unload(self)
开发者ID:coginvasion,项目名称:src,代码行数:46,代码来源:ToonInterior.py

示例2: RaceGameMovement

# 需要导入模块: from direct.fsm.ClassicFSM import ClassicFSM [as 别名]
# 或者: from direct.fsm.ClassicFSM.ClassicFSM import enterInitialState [as 别名]
class RaceGameMovement(DirectObject):
    MINIMUM_POWER = 0.3
    MINIMUM_KEY_DELAY = 0.015
    POWER_FACTOR = 2.5
    defaultBoostBarColor = (0.4, 0.4, 0.7, 1.0)
    fullBoostBarColor = (0.0, 0.0, 0.7, 1.0)

    def __init__(self, avatar):
        DirectObject.__init__(self)
        self.avatar = avatar
        self.power = self.MINIMUM_POWER
        self.boost = 0.0
        self.fsm = ClassicFSM('RaceGameMovement', [State('off', self.enterOff, self.exitOff, ['run']),
         State('run', self.enterRun, self.exitRun, ['fall', 'off']),
         State('fall', self.enterFall, self.exitFall, ['run', 'off']),
         State('final', self.enterFinal, self.exitFinal)], 'off', 'final')
        self.fsm.enterInitialState()
        self.boostFSM = ClassicFSM('Boost', [State('off', self.enterBoostOff, self.exitBoostOff, ['boost']), State('boost', self.enterBoost, self.exitBoost)], 'off', 'off')
        self.boostFSM.enterInitialState()
        self.keysPressed = {'arrow_left': 0,
         'arrow_right': 0}
        self.startTime = 0.0
        self.endTime = 0.0
        self.fallTrack = None
        self.isStopped = True
        self.isBoosting = False
        return

    def setBoosting(self, value):
        self.isBoosting = value

    def getBoosting(self):
        return self.isBoosting

    def enterBoostOff(self):
        self.ignore('control')

    def exitBoostOff(self):
        pass

    def createGui(self):
        """ Create the GUI that will tell the client how much
        running power they have. """
        self.powerFrame = DirectFrame()
        self.powerBg = OnscreenImage(image=DGG.getDefaultDialogGeom(), scale=(0.5, 1.0, 0.5), pos=(1.02, 0, 0.7), parent=self.powerFrame, color=CIGlobals.DialogColor)
        self.powerBar = DirectWaitBar(barColor=(0, 0.7, 0, 1), range=20.0, value=0, parent=self.powerFrame, scale=(0.15, 0, 1.1), pos=(1.02, 0, 0.66))
        self.powerBar.setR(-90)
        self.powerTitle = DirectLabel(text='POWER', text_scale=0.08, pos=(1.02, 0, 0.85), relief=None, parent=self.powerFrame, text_fg=(1, 1, 0, 1), text_font=CIGlobals.getMickeyFont())
        self.boostFrame = DirectFrame()
        self.boostBg = OnscreenImage(image=DGG.getDefaultDialogGeom(), scale=(0.5, 1.0, 0.5), pos=(0.45, 0, 0.7), parent=self.boostFrame, color=CIGlobals.DialogColor)
        self.boostBar = DirectWaitBar(barColor=self.defaultBoostBarColor, range=10, value=0, parent=self.boostFrame, scale=(0.15, 0, 1.1), pos=(0.45, 0, 0.66))
        self.boostBar.setR(-90)
        self.boostTitle = DirectLabel(text='BOOST', text_scale=0.08, pos=(0.45, 0, 0.85), relief=None, parent=self.boostFrame, text_fg=(1, 1, 0, 1), text_font=CIGlobals.getMickeyFont())
        self.boostFullLbl = DirectLabel(text='BOOST READY', text_scale=0.065, pos=(0.45, 0, 0.3), relief=None, parent=self.boostFrame, text_fg=self.fullBoostBarColor, text_shadow=(0.4, 0.4, 0.4, 1.0), text_font=CIGlobals.getToonFont())
        self.boostFullLbl.hide()
        return

    def deleteGui(self):
        """ Delete the GUI that will tell the client how much
        running power they have. """
        self.powerFrame.destroy()
        self.powerBg.destroy()
        self.powerBar.destroy()
        self.powerTitle.destroy()
        self.boostFrame.destroy()
        self.boostBg.destroy()
        self.boostBar.destroy()
        self.boostTitle.destroy()
        self.boostFullLbl.destroy()

    def enableArrowKeys(self):
        """ Enable the arrow keys to increase movement power. """
        self.accept('arrow_left', self.keyPressed, ['arrow_left'])
        self.accept('arrow_right', self.keyPressed, ['arrow_right'])

    def disableArrowKeys(self):
        """ Disable the arrow keys to increase movement power. """
        self.ignore('arrow_left')
        self.ignore('arrow_right')

    def boostKeyPressed(self):
        self.boostFullLbl.hide()
        self.boostFSM.request('boost')

    def keyPressed(self, key):
        """ Figure out which key was pressed and increment the movement power
        if the values of both keys are 1. Also, make the avatar fall down if
        the time between key presses is too fast or the avatar pressed the same
        key more than once."""
        self.stopDelayTimer()
        if self.keysPressed[key] == 1 or self.isTooFast():
            self.resetKeys()
            self.fsm.request('fall')
            return
        self.keysPressed[key] = 1
        if self.keysPressed['arrow_left'] == 1 and self.keysPressed['arrow_right'] == 1:
            self.resetKeys()
            self.changePower()
            self.restartDelayTimer()

#.........这里部分代码省略.........
开发者ID:coginvasion,项目名称:src,代码行数:103,代码来源:RaceGameMovement.py

示例3: OptionPage

# 需要导入模块: from direct.fsm.ClassicFSM import ClassicFSM [as 别名]
# 或者: from direct.fsm.ClassicFSM.ClassicFSM import enterInitialState [as 别名]
class OptionPage(StateData):

    def __init__(self, book, parentFSM):
        self.book = book
        self.parentFSM = parentFSM
        StateData.__init__(self, 'optionPageDone')
        self.fsm = ClassicFSM('OptionPage', [State('off', self.enterOff, self.exitOff), State('basePage', self.enterBasePage, self.exitBasePage), State('displayPage', self.enterDisplayPage, self.exitDisplayPage)], 'off', 'off')
        self.fsm.enterInitialState()
        self.parentFSM.getStateNamed('optionPage').addChild(self.fsm)

    def enterOff(self):
        pass

    def exitOff(self):
        pass

    def load(self):
        StateData.load(self)

    def unload(self):
        StateData.unload(self)

    def enter(self):
        StateData.enter(self)
        self.fsm.request('basePage')

    def exit(self):
        self.fsm.request('off')
        StateData.exit(self)

    def openDisplayPage(self):
        self.fsm.request('displayPage')

    def enterDisplayPage(self):
        self.book.createPageButtons(False, False)
        self.book.setTitle('Display Options')
        dialog_gui = loader.loadModel('phase_3/models/gui/dialog_box_buttons_gui.bam')
        width, height, fs, music, sfx, tex_detail, model_detail, aa, af = SettingsManager().getSettings('settings.json')
        self.width = width
        self.height = height
        self.windowType = [fs]
        self.buttons = [DirectRadioButton(text='Windowed', variable=self.windowType, value=[False], scale=0.1, pos=(-0.45, 0.15, 0.15)), DirectRadioButton(text='Fullscreen', variable=self.windowType, value=[True], scale=0.1, pos=(-0.45, -0.15, -0.15))]
        for button in self.buttons:
            button.setOthers(self.buttons)

        self.resoLbl = DirectLabel(text='%sx%s' % (width, height), scale=0.08, relief=None, pos=(0.25, 0, 0))
        self.resSlider = DirectSlider(range=(0, 200), pageSize=50, command=self.setResoText, scale=0.3, orientation=DGG.VERTICAL, pos=(0.6, 0, 0))
        self.okBtn = DirectButton(text='OK', geom=CIGlobals.getOkayBtnGeom(), relief=None, pos=(-0.5, -0.5, -0.5), text_scale=0.05, text_pos=(0, -0.11), command=self.applyDisplaySettings)
        self.cancelBtn = DirectButton(text='Cancel', geom=CIGlobals.getCancelBtnGeom(), relief=None, pos=(-0.3, -0.5, -0.5), text_scale=0.05, text_pos=(0, -0.11), command=self.cancelDisplaySettings)
        if self.resoLbl['text'] == '640x480':
            self.resSlider['value'] = 0
        elif self.resoLbl['text'] == '800x600':
            self.resSlider['value'] = 50
        elif self.resoLbl['text'] == '1024x768':
            self.resSlider['value'] = 100
        elif self.resoLbl['text'] == '1280x1024':
            self.resSlider['value'] = 150
        elif self.resoLbl['text'] == '1600x1200':
            self.resSlider['value'] = 200
        return

    def exitDisplayPage(self):
        for button in self.buttons:
            button.destroy()
            del button

        self.resoLbl.destroy()
        del self.resoLbl
        self.resSlider.destroy()
        del self.resSlider
        self.okBtn.destroy()
        del self.okBtn
        self.cancelBtn.destroy()
        del self.cancelBtn
        del self.width
        del self.height
        del self.windowType
        del self.buttons
        self.book.clearTitle()

    def changeSetting(self, setting, value):
        if setting == 'music':
            if value:
                value = False
            elif not value:
                value = True
            base.enableMusic(value)
            self.music_btn['extraArgs'] = ['music', value]
            if value:
                valueTxt = 'On'
            else:
                valueTxt = 'Off'
            self.music_lbl['text'] = str(valueTxt).capitalize()
        elif setting == 'sfx':
            if value:
                value = False
            elif not value:
                value = True
            base.enableSoundEffects(value)
            self.sfx_btn['extraArgs'] = ['sfx', value]
#.........这里部分代码省略.........
开发者ID:coginvasion,项目名称:src,代码行数:103,代码来源:OptionPage.py

示例4: Human

# 需要导入模块: from direct.fsm.ClassicFSM import ClassicFSM [as 别名]
# 或者: from direct.fsm.ClassicFSM.ClassicFSM import enterInitialState [as 别名]
class Human(HumanBase.HumanBase, Biped.Biped):
    notify = DirectNotifyGlobal.directNotify.newCategory("Human")
    prebuiltAnimData = {}

    def __init__(self, other=None):
        Biped.Biped.__init__(self, other, HumanAnimationMixer)
        self.zombie = False
        self.crazyColorSkin = False
        self.crazyColorSkinIndex = 0
        self.flattenPending = None
        self.flattenSuperLowName = None
        self.optimizeLOD = base.config.GetBool("optimize-avatar-lod", 1)
        self.loaded = 0
        self.playingRate = None
        self.shadowFileName = "models/misc/drop_shadow"
        self.setFont(PiratesGlobals.getInterfaceFont())
        self._Human__blinkName = "blink-" + str(self.this)
        self.eyeLids = None
        self.eyeBalls = None
        self.eyeIris = None
        self.reducedAnimList = None
        self.headNode = None
        self.headEffects = NodePath("headEffects")
        self.extraNode = None
        self.scaleNode = None
        self.rootNode = None
        self.floorOffsetZ = 0.0
        self.isGhost = 0
        self.headFudgeHpr = Vec3(0, 0, 0)
        self.randGen = random.Random()
        self.randGen.seed(random.random())
        self.eyeFSM = ClassicFSM(
            "eyeFSM",
            [
                State("off", self.enterEyeFSMOff, self.exitEyeFSMOff, ["open", "closed"]),
                State("open", self.enterEyeFSMOpen, self.exitEyeFSMOpen, ["closed", "off"]),
                State("closed", self.enterEyeFSMClosed, self.exitEyeFSMClosed, ["open", "off"]),
            ],
            "off",
            "off",
        )
        self.eyeFSM.enterInitialState()
        if other != None:
            self.copyHuman(other)

    def removeCopiedNodes(self):
        self.dropShadow = self.find("**/drop_shadow*")
        if not self.dropShadow.isEmpty():
            self.deleteDropShadow()
        else:
            self.dropShadow = None
        billboardNode = self.find("**/billboardNode")
        if not billboardNode.isEmpty():
            billboardNode.removeNode()

        self.getGeomNode().getParent().removeNode()

    def flattenHuman(self):
        self.getWeaponJoints()

    def flattenSuperLow(self):
        name = "flattenSuperLow-%s" % self.this
        self.flattenSuperLowName = name
        model = self.getLOD("500")
        self.accept(name, self._Human__doneFlattenSuperLow)
        taskMgr.remove(name)
        taskMgr.add(self.flattenSuperLowTask, name, extraArgs=[model], taskChain="background")

    def flattenSuperLowTask(self, model):
        model = model.copyTo(NodePath())
        rhn = model.find("**/rightHand")
        lhn = model.find("**/leftHand")
        if lhn:
            lhn.detachNode()

        if rhn:
            rhn.detachNode()

        node = model.node()
        gr = SceneGraphReducer()
        model.node().setAttrib(TransparencyAttrib.make(0), 2000)
        gr.applyAttribs(
            node,
            SceneGraphReducer.TTApplyTextureColor
            | SceneGraphReducer.TTTexMatrix
            | SceneGraphReducer.TTOther
            | SceneGraphReducer.TTCullFace
            | SceneGraphReducer.TTTransform
            | SceneGraphReducer.TTColor
            | SceneGraphReducer.TTColorScale,
        )
        num_removed = gr.flatten(node, -1)
        gr.makeCompatibleState(node)
        gr.collectVertexData(
            node, ~(SceneGraphReducer.CVDFormat | SceneGraphReducer.CVDName | SceneGraphReducer.CVDAnimationType)
        )
        gr.unify(node, 0)
        name = self.flattenSuperLowName
        if name:
            messenger.send(name, [model], taskChain="default")
#.........这里部分代码省略.........
开发者ID:Puggyblue999,项目名称:PiratesOfTheCarribeanOnline,代码行数:103,代码来源:Human.py

示例5: DistributedBoat

# 需要导入模块: from direct.fsm.ClassicFSM import ClassicFSM [as 别名]
# 或者: from direct.fsm.ClassicFSM.ClassicFSM import enterInitialState [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
#.........这里部分代码省略.........
开发者ID:coginvasion,项目名称:src,代码行数:103,代码来源:DistributedBoat.py

示例6: Toon

# 需要导入模块: from direct.fsm.ClassicFSM import ClassicFSM [as 别名]
# 或者: from direct.fsm.ClassicFSM.ClassicFSM import enterInitialState [as 别名]
class Toon(Avatar.Avatar, ToonHead, ToonDNA.ToonDNA):

    def __init__(self, cr, mat = 0):
        self.cr = cr
        try:
            self.Toon_initialized
            return
        except:
            self.Toon_initialized = 1

        Avatar.Avatar.__init__(self, mat)
        ToonDNA.ToonDNA.__init__(self)
        ToonHead.__init__(self, cr)
        self.forwardSpeed = 0.0
        self.rotateSpeed = 0.0
        self.avatarType = CIGlobals.Toon
        self.track = None
        self.standWalkRunReverse = None
        self.playingAnim = None
        self.tag = None
        self.money = 0
        self.lookAtTrack = None
        self.portal1 = None
        self.portal2 = None
        self.gunAttached = False
        self.gun = None
        self.tokenIcon = None
        self.tokenIconIval = None
        self.backpack = None
        self.forcedTorsoAnim = None
        self.fallSfx = base.audio3d.loadSfx('phase_4/audio/sfx/MG_cannon_hit_dirt.mp3')
        base.audio3d.attachSoundToObject(self.fallSfx, self)
        self.eyes = loader.loadTexture('phase_3/maps/eyes.jpg', 'phase_3/maps/eyes_a.rgb')
        self.myTaskId = random.uniform(0, 1231231232132131231232L)
        self.closedEyes = loader.loadTexture('phase_3/maps/eyesClosed.jpg', 'phase_3/maps/eyesClosed_a.rgb')
        self.soundChatBubble = loader.loadSfx('phase_3/audio/sfx/GUI_balloon_popup.mp3')
        self.shadowCaster = None
        self.chatSoundDict = {}
        self.animFSM = ClassicFSM('Toon', [State('off', self.enterOff, self.exitOff),
         State('neutral', self.enterNeutral, self.exitNeutral),
         State('swim', self.enterSwim, self.exitSwim),
         State('walk', self.enterWalk, self.exitWalk),
         State('run', self.enterRun, self.exitRun),
         State('openBook', self.enterOpenBook, self.exitOpenBook),
         State('readBook', self.enterReadBook, self.exitReadBook),
         State('closeBook', self.enterCloseBook, self.exitCloseBook),
         State('teleportOut', self.enterTeleportOut, self.exitTeleportOut),
         State('teleportIn', self.enterTeleportIn, self.exitTeleportIn),
         State('died', self.enterDied, self.exitDied),
         State('fallFWD', self.enterFallFWD, self.exitFallFWD),
         State('fallBCK', self.enterFallBCK, self.exitFallBCK),
         State('jump', self.enterJump, self.exitJump),
         State('leap', self.enterLeap, self.exitLeap),
         State('laugh', self.enterLaugh, self.exitLaugh),
         State('happy', self.enterHappyJump, self.exitHappyJump),
         State('shrug', self.enterShrug, self.exitShrug),
         State('hdance', self.enterHDance, self.exitHDance),
         State('wave', self.enterWave, self.exitWave),
         State('scientistEmcee', self.enterScientistEmcee, self.exitScientistEmcee),
         State('scientistWork', self.enterScientistWork, self.exitScientistWork),
         State('scientistGame', self.enterScientistGame, self.exitScientistGame),
         State('scientistJealous', self.enterScientistJealous, self.exitScientistJealous),
         State('cringe', self.enterCringe, self.exitCringe),
         State('conked', self.enterConked, self.exitConked),
         State('win', self.enterWin, self.exitWin),
         State('walkBack', self.enterWalkBack, self.exitWalkBack),
         State('deadNeutral', self.enterDeadNeutral, self.exitDeadNeutral),
         State('deadWalk', self.enterDeadWalk, self.exitDeadWalk),
         State('squish', self.enterSquish, self.exitSquish),
         State('Happy', self.enterHappy, self.exitHappy),
         State('Sad', self.enterSad, self.exitSad)], 'off', 'off')
        animStateList = self.animFSM.getStates()
        self.animFSM.enterInitialState()
        if not hasattr(base, 'localAvatar') or not base.localAvatar == self:
            Avatar.Avatar.initializeBodyCollisions(self, self.avatarType, 3, 1)
        return

    def enterHappy(self, ts = 0, callback = None, extraArgs = []):
        self.playingAnim = None
        self.standWalkRunReverse = (('neutral', 1.0),
         ('walk', 1.0),
         ('run', 1.0),
         ('walk', -1.0))
        self.setSpeed(self.forwardSpeed, self.rotateSpeed)
        return

    def exitHappy(self):
        self.standWalkRunReverse = None
        self.stop()
        return

    def enterSad(self, ts = 0, callback = None, extraArgs = []):
        self.playingAnim = 'sad'
        self.standWalkRunReverse = (('dneutral', 1.0),
         ('dwalk', 1.2),
         ('dwalk', 1.2),
         ('dwalk', -1.0))
        self.setSpeed(0, 0)

    def exitSad(self):
#.........这里部分代码省略.........
开发者ID:coginvasion,项目名称:src,代码行数:103,代码来源:Toon.py

示例7: DistributedCityCart

# 需要导入模块: from direct.fsm.ClassicFSM import ClassicFSM [as 别名]
# 或者: from direct.fsm.ClassicFSM.ClassicFSM import enterInitialState [as 别名]
class DistributedCityCart(DistributedNode):
    notify = directNotify.newCategory('DistributedCityCart')

    def __init__(self, cr):
        DistributedNode.__init__(self, cr)
        self.fsm = ClassicFSM('DistributedCityCart', [State('off', self.enterOff, self.exitOff), State('pathFollow', self.enterPathFollow, self.exitPathFollow), State('collision', self.enterCollision, self.exitCollision)], 'off', 'off')
        self.fsm.enterInitialState()
        self.suitInCar = None
        self.cart = None
        self.honkSfxPath = 'phase_14/audio/sfx/cogtropolis_citycar_driveby_horn.mp3'
        self.cartModelPath = 'phase_12/models/bossbotHQ/Coggolf_cart3.bam'
        self.moPaths = ['phase_14/models/paths/ct-citycar-drivepath-1.egg',
         'phase_14/models/paths/ct-citycar-drivepath-2.egg',
         'phase_14/models/paths/ct-citycar-drivepath-3.egg',
         'phase_14/models/paths/ct-citycar-drivepath-4.egg',
         'phase_14/models/paths/ct-citycar-drivepath-5.egg',
         'phase_14/models/paths/ct-citycar-drivepath-6.egg']
        self.moPath = None
        self.soundEngineLoop = None
        self.soundDriveByHorn = None
        self.ivalTDisplace = None
        self.pathIndex = None
        self.wheelSpinTrack = None
        self.collNodePath = None
        self.soundDriveBy = None
        return

    def setIvalTDisplace(self, displace):
        self.ivalTDisplace = displace

    def setPathIndex(self, index):
        self.pathIndex = index

    def setState(self, state, timestamp):
        ts = ClockDelta.globalClockDelta.localElapsedTime(timestamp)
        self.fsm.request(state, [ts])

    def enterOff(self):
        pass

    def exitOff(self):
        pass

    def enterPathFollow(self, ts):
        duration = CityCartGlobals.index2Duration[self.pathIndex]
        self.moPath = NURBSMopath.NURBSMopath(self.moPaths[self.pathIndex], name=self.uniqueName('DCityCart_moPath'))
        startT = 0.0
        if ts > 0.0:
            startT = ts % duration * (1.0 / duration)
        self.moPath.play(self, loop=True, duration=duration, startT=startT)
        base.taskMgr.add(self.__drive, self.uniqueName('DCityCart.drive'))
        self.wheelSpinTrack = Parallel()
        for name in ['leftFrontWheel',
         'rightBackWheel',
         'rightFrontWheel',
         '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)
#.........这里部分代码省略.........
开发者ID:coginvasion,项目名称:src,代码行数:103,代码来源:DistributedCityCart.py

示例8: ToonHood

# 需要导入模块: from direct.fsm.ClassicFSM import ClassicFSM [as 别名]
# 或者: from direct.fsm.ClassicFSM.ClassicFSM import enterInitialState [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()
开发者ID:coginvasion,项目名称:src,代码行数:87,代码来源:ToonHood.py

示例9: DistributedRaceGame

# 需要导入模块: from direct.fsm.ClassicFSM import ClassicFSM [as 别名]
# 或者: from direct.fsm.ClassicFSM.ClassicFSM import enterInitialState [as 别名]
class DistributedRaceGame(DistributedMinigame.DistributedMinigame):

    def __init__(self, cr):
        try:
            self.DistributedRaceGame_initialized
            return
        except:
            self.DistributedRaceGame_initialized = 1

        DistributedMinigame.DistributedMinigame.__init__(self, cr)
        self.movement = RaceGameMovement.RaceGameMovement(base.localAvatar)
        self.skyUtil = SkyUtil()
        self.raceFSM = ClassicFSM('DistributedRaceGame', [State('race', self.enterRace, self.exitRace), State('raceTransition', self.enterRaceTransition, self.exitRaceTransition), State('off', self.enterRaceOff, self.exitRaceOff)], 'off', 'off')
        self.raceFSM.enterInitialState()
        self.cr = cr
        self.track = None
        self.sky = None
        self.countSfx = base.loadSfx('phase_5/audio/sfx/firehydrant_popup.mp3')
        self.goSfx = base.loadSfx('phase_4/audio/sfx/AA_sound_whistle.mp3')
        self.game = CIGlobals.RaceGame
        self.trackPath = 'phase_4/models/minigames/sprint_track.egg'
        self.skyPath = 'phase_3.5/models/props/TT_sky.bam'
        self.lanePos = [(-22.0, -205.0, 0.0),
         (-11.66, -205.0, 0.0),
         (0.0, -205.0, 0.0),
         (-33.66, -205.0, 0.0)]
        self.initialCamPos = {'pos': (41.1, -145.0, 25.88),
         'hpr': (135.0, 345.96, 0.0)}
        self.raceCamPos = (-24.52, -37.22, 25.0)
        self.lane = 0
        return

    def load(self):
        self.deleteWorld()
        self.track = loader.loadModel(self.trackPath)
        self.track.reparentTo(render)
        self.sky = loader.loadModel(self.skyPath)
        self.sky.reparentTo(self.track)
        self.skyUtil.startSky(self.sky)
        self.setMinigameMusic('phase_4/audio/bgm/MG_toontag.mid')
        self.setDescription('Tap the left and right arrow keys repeatedly, in turns, as fast as ' + 'you can to win the race! Every time your power bar hits the top, the boost bar starts' + ' to fill. When the boost bar is full, press CTRL to boost for a few seconds.')
        self.setWinnerPrize(20)
        self.setLoserPrize(5)
        self.d_requestToonLane()
        camera.reparentTo(render)
        camera.setPos(self.initialCamPos['pos'])
        camera.setHpr(self.initialCamPos['hpr'])
        DistributedMinigame.DistributedMinigame.load(self)

    def enterPlay(self):
        DistributedMinigame.DistributedMinigame.enterPlay(self)
        self.raceFSM.request('raceTransition')

    def exitPlay(self):
        DistributedMinigame.DistributedMinigame.exitPlay(self)
        self.raceFSM.request('off')

    def enterRace(self):
        self.startMovement()

    def exitRace(self):
        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')
#.........这里部分代码省略.........
开发者ID:coginvasion,项目名称:src,代码行数:103,代码来源:DistributedRaceGame.py

示例10: ShtickerBook

# 需要导入模块: from direct.fsm.ClassicFSM import ClassicFSM [as 别名]
# 或者: from direct.fsm.ClassicFSM.ClassicFSM import enterInitialState [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
#.........这里部分代码省略.........
开发者ID:coginvasion,项目名称:src,代码行数:103,代码来源:ShtickerBook.py

示例11: SafeZoneLoader

# 需要导入模块: from direct.fsm.ClassicFSM import ClassicFSM [as 别名]
# 或者: from direct.fsm.ClassicFSM.ClassicFSM import enterInitialState [as 别名]
class SafeZoneLoader(StateData):
    notify = directNotify.newCategory('SafeZoneLoader')

    def __init__(self, hood, parentFSMState, doneEvent):
        StateData.__init__(self, doneEvent)
        self.hood = hood
        self.parentFSMState = parentFSMState
        self.fsm = ClassicFSM('safeZoneLoader', [State('off', self.enterOff, self.exitOff),
         State('playground', self.enterPlayground, self.exitPlayground, ['quietZone']),
         State('toonInterior', self.enterToonInterior, self.exitToonInterior, ['quietZone']),
         State('quietZone', self.enterQuietZone, self.exitQuietZone, ['playground', 'toonInterior'])], 'off', 'off')
        self.placeDoneEvent = 'placeDone'
        self.place = None
        self.playground = None
        self.battleMusic = None
        self.invasionMusic = None
        self.invasionMusicFiles = None
        self.interiorMusic = None
        self.bossBattleMusic = None
        self.music = None
        self.tournamentMusic = None
        self.linkTunnels = []
        return

    def findAndMakeLinkTunnels(self):
        for tunnel in self.geom.findAllMatches('**/*linktunnel*'):
            dnaRootStr = tunnel.getName()
            link = LinkTunnel.SafeZoneLinkTunnel(tunnel, dnaRootStr)
            self.linkTunnels.append(link)

    def load(self):
        StateData.load(self)
        if self.pgMusicFilename:
            self.music = base.loadMusic(self.pgMusicFilename)
        if self.battleMusicFile:
            self.battleMusic = base.loadMusic(self.battleMusicFile)
        if self.invasionMusicFiles:
            self.invasionMusic = None
        if self.bossBattleMusicFile:
            self.bossBattleMusic = base.loadMusic(self.bossBattleMusicFile)
        if self.interiorMusicFilename:
            self.interiorMusic = base.loadMusic(self.interiorMusicFilename)
        if self.tournamentMusicFiles:
            self.tournamentMusic = None
        self.createSafeZone(self.dnaFile)
        self.parentFSMState.addChild(self.fsm)
        width, height, fs, music, sfx, tex_detail, model_detail, aa, af = SettingsManager().getSettings('settings.json')
        if af == 'on':
            self.notify.info('Anisotropic Filtering is on, applying to textures.')
            for nodepath in self.geom.findAllMatches('*'):
                try:
                    for node in nodepath.findAllMatches('**'):
                        try:
                            node.findTexture('*').setAnisotropicDegree(8)
                        except:
                            pass

                except:
                    continue

        return

    def unload(self):
        StateData.unload(self)
        self.parentFSMState.removeChild(self.fsm)
        del self.parentFSMState
        self.geom.removeNode()
        del self.geom
        del self.fsm
        del self.hood
        del self.playground
        del self.music
        del self.interiorMusic
        del self.battleMusic
        del self.bossBattleMusic
        del self.tournamentMusic
        self.ignoreAll()
        ModelPool.garbageCollect()
        TexturePool.garbageCollect()

    def enter(self, requestStatus):
        StateData.enter(self)
        if base.localAvatar.zoneId < 61000:
            self.findAndMakeLinkTunnels()
        self.fsm.enterInitialState()
        messenger.send('enterSafeZone')
        self.setState(requestStatus['where'], requestStatus)
        partyGate = self.geom.find('**/prop_party_gate_DNARoot')
        if not partyGate.isEmpty():
            partyGate.removeNode()
        del partyGate
        petShop = self.geom.find('**/prop_pet_shop_DNARoot')
        if not petShop.isEmpty():
            petShop.removeNode()
        del petShop

    def exit(self):
        StateData.exit(self)
        messenger.send('exitSafeZone')
        for link in self.linkTunnels:
#.........这里部分代码省略.........
开发者ID:coginvasion,项目名称:src,代码行数:103,代码来源:SafeZoneLoader.py

示例12: Walk

# 需要导入模块: from direct.fsm.ClassicFSM import ClassicFSM [as 别名]
# 或者: from direct.fsm.ClassicFSM.ClassicFSM import enterInitialState [as 别名]
class Walk(StateData):
    notify = directNotify.newCategory('Walk')

    def __init__(self, doneEvent):
        StateData.__init__(self, doneEvent)
        self.fsm = ClassicFSM('Walk', [State('off', self.enterOff, self.exitOff, ['walking', 'deadWalking']), State('walking', self.enterWalking, self.exitWalking), State('deadWalking', self.enterDeadWalking, self.exitDeadWalking)], 'off', 'off')
        self.fsm.enterInitialState()

    def load(self):
        pass

    def unload(self):
        del self.fsm

    def enter(self):
        base.localAvatar.startPosHprBroadcast()
        base.localAvatar.d_broadcastPositionNow()
        base.localAvatar.startBlink()
        base.localAvatar.attachCamera()
        base.localAvatar.startSmartCamera()
        base.localAvatar.collisionsOn()
        base.localAvatar.enableAvatarControls()
        base.localAvatar.enablePicking()

    def exit(self):
        base.localAvatar.lastState = None
        self.fsm.request('off')
        base.localAvatar.enablePicking()
        base.localAvatar.disableAvatarControls()
        base.localAvatar.detachCamera()
        base.localAvatar.stopSmartCamera()
        base.localAvatar.stopPosHprBroadcast()
        base.localAvatar.stopBlink()
        base.localAvatar.collisionsOff()
        base.localAvatar.controlManager.placeOnFloor()
        return

    def enterOff(self):
        pass

    def exitOff(self):
        pass

    def enterWalking(self):
        if base.localAvatar.getHealth() > 0:
            base.localAvatar.startTrackAnimToSpeed()
            base.localAvatar.setWalkSpeedNormal()
        else:
            self.fsm.request('deadWalking')

    def exitWalking(self):
        base.localAvatar.stopTrackAnimToSpeed()

    def enterDeadWalking(self):
        base.localAvatar.startTrackAnimToSpeed()
        base.localAvatar.setWalkSpeedSlow()
        base.taskMgr.add(self.__watchForPositiveHP, base.localAvatar.uniqueName('watchforPositiveHP'))

    def __watchForPositiveHP(self, task):
        if base.localAvatar.getHealth() > 0:
            self.fsm.request('walking')
            return task.done
        return task.cont

    def exitDeadWalking(self):
        base.taskMgr.remove(base.localAvatar.uniqueName('watchforPositiveHP'))
        base.localAvatar.stopTrackAnimToSpeed()
开发者ID:coginvasion,项目名称:src,代码行数:69,代码来源:Walk.py

示例13: Street

# 需要导入模块: from direct.fsm.ClassicFSM import ClassicFSM [as 别名]
# 或者: from direct.fsm.ClassicFSM.ClassicFSM import enterInitialState [as 别名]
class Street(Place):
    notify = directNotify.newCategory('Street')

    def __init__(self, loader, parentFSM, doneEvent):
        self.parentFSM = parentFSM
        Place.__init__(self, loader, doneEvent)
        self.fsm = ClassicFSM('Street', [State('start', self.enterStart, self.exitStart, ['walk',
          'doorOut',
          'teleportIn',
          'tunnelOut']),
         State('walk', self.enterWalk, self.exitWalk, ['stop',
          'tunnelIn',
          'shtickerBook',
          'teleportOut']),
         State('shtickerBook', self.enterShtickerBook, self.exitShtickerBook, ['teleportOut', 'walk']),
         State('teleportOut', self.enterTeleportOut, self.exitTeleportOut, ['teleportIn', 'stop']),
         State('tunnelOut', self.enterTunnelOut, self.exitTunnelOut, ['walk']),
         State('tunnelIn', self.enterTunnelIn, self.exitTunnelIn, ['stop']),
         State('stop', self.enterStop, self.exitStop, ['walk',
          'died',
          'teleportOut',
          'doorIn']),
         State('doorIn', self.enterDoorIn, self.exitDoorIn, ['stop']),
         State('doorOut', self.enterDoorOut, self.exitDoorOut, ['walk']),
         State('teleportIn', self.enterTeleportIn, self.exitTeleportIn, ['walk', 'stop']),
         State('final', self.enterFinal, self.exitFinal, ['final'])], 'start', 'final')

    def enter(self, requestStatus, visibilityFlag = 1):
        Place.enter(self)
        self.fsm.enterInitialState()
        base.playMusic(self.loader.music, volume=0.8, looping=1)
        self.loader.geom.reparentTo(render)
        if visibilityFlag:
            self.visibilityOn()
        self.loader.hood.startSky()
        self.enterZone(requestStatus['zoneId'])
        self.fsm.request(requestStatus['how'], [requestStatus])

    def exit(self, vis = 1):
        if vis:
            self.visibilityOff()
        self.loader.geom.reparentTo(hidden)
        self.loader.hood.stopSky()
        self.loader.music.stop()
        Place.exit(self)

    def load(self):
        Place.load(self)
        self.parentFSM.getStateNamed('street').addChild(self.fsm)

    def unload(self):
        self.parentFSM.getStateNamed('street').removeChild(self.fsm)
        del self.fsm
        del self.parentFSM
        self.enterZone(None)
        self.ignoreAll()
        Place.unload(self)
        return

    def hideAllVisibles(self):
        for i in self.loader.nodeList:
            i.stash()

    def showAllVisibles(self):
        for i in self.loader.nodeList:
            i.unstash()

    def visibilityOn(self):
        self.hideAllVisibles()
        self.accept('on-floor', self.enterZone)

    def visibilityOff(self):
        self.ignore('on-floor')
        self.showAllVisibles()

    def enterZone(self, newZone):
        if isinstance(newZone, CollisionEntry):
            try:
                newZoneId = int(newZone.getIntoNode().getName())
            except:
                self.notify.warning('Invalid floor collision node in street: %s' % newZone.getIntoNode().getName())
                return

        else:
            newZoneId = newZone
        self.doEnterZone(newZoneId)

    def doEnterZone(self, newZoneId):
        visualizeZones = 0
        if self.zoneId != None:
            for i in self.loader.nodeDict[self.zoneId]:
                if newZoneId:
                    if i not in self.loader.nodeDict[newZoneId]:
                        self.loader.fadeOutDict[i].start()
                else:
                    i.stash()

        if newZoneId != None:
            for i in self.loader.nodeDict[newZoneId]:
                if self.zoneId:
#.........这里部分代码省略.........
开发者ID:coginvasion,项目名称:src,代码行数:103,代码来源:Street.py

示例14: ToonHead

# 需要导入模块: from direct.fsm.ClassicFSM import ClassicFSM [as 别名]
# 或者: from direct.fsm.ClassicFSM.ClassicFSM import enterInitialState [as 别名]
class ToonHead(Actor.Actor):

    notify = DirectNotifyGlobal.directNotify.newCategory('ToonHead')
    EyesOpen = loader.loadTexture('phase_3/maps/eyes.jpg', 'phase_3/maps/eyes_a.rgb')
    EyesOpen.setMinfilter(Texture.FTLinear)
    EyesOpen.setMagfilter(Texture.FTLinear)
    EyesClosed = loader.loadTexture('phase_3/maps/eyesClosed.jpg', 'phase_3/maps/eyesClosed_a.rgb')
    EyesClosed.setMinfilter(Texture.FTLinear)
    EyesClosed.setMagfilter(Texture.FTLinear)
    EyesSadOpen = loader.loadTexture('phase_3/maps/eyesSad.jpg', 'phase_3/maps/eyesSad_a.rgb')
    EyesSadOpen.setMinfilter(Texture.FTLinear)
    EyesSadOpen.setMagfilter(Texture.FTLinear)
    EyesSadClosed = loader.loadTexture('phase_3/maps/eyesSadClosed.jpg', 'phase_3/maps/eyesSadClosed_a.rgb')
    EyesSadClosed.setMinfilter(Texture.FTLinear)
    EyesSadClosed.setMagfilter(Texture.FTLinear)
    EyesAngryOpen = loader.loadTexture('phase_3/maps/eyesAngry.jpg', 'phase_3/maps/eyesAngry_a.rgb')
    EyesAngryOpen.setMinfilter(Texture.FTLinear)
    EyesAngryOpen.setMagfilter(Texture.FTLinear)
    EyesAngryClosed = loader.loadTexture('phase_3/maps/eyesAngryClosed.jpg', 'phase_3/maps/eyesAngryClosed_a.rgb')
    EyesAngryClosed.setMinfilter(Texture.FTLinear)
    EyesAngryClosed.setMagfilter(Texture.FTLinear)
    EyesSurprised = loader.loadTexture('phase_3/maps/eyesSurprised.jpg', 'phase_3/maps/eyesSurprised_a.rgb')
    EyesSurprised.setMinfilter(Texture.FTLinear)
    EyesSurprised.setMagfilter(Texture.FTLinear)
    Muzzle = loader.loadTexture('phase_3/maps/muzzleShrtGeneric.jpg')
    Muzzle.setMinfilter(Texture.FTLinear)
    Muzzle.setMagfilter(Texture.FTLinear)
    MuzzleSurprised = loader.loadTexture('phase_3/maps/muzzleShortSurprised.jpg')
    MuzzleSurprised.setMinfilter(Texture.FTLinear)
    MuzzleSurprised.setMagfilter(Texture.FTLinear)
    LeftA = Point3(0.06, 0.0, 0.14)
    LeftB = Point3(-0.13, 0.0, 0.1)
    LeftC = Point3(-0.05, 0.0, 0.0)
    LeftD = Point3(0.06, 0.0, 0.0)
    RightA = Point3(0.13, 0.0, 0.1)
    RightB = Point3(-0.06, 0.0, 0.14)
    RightC = Point3(-0.06, 0.0, 0.0)
    RightD = Point3(0.05, 0.0, 0.0)
    LeftAD = Point3(LeftA[0] - LeftA[2] * (LeftD[0] - LeftA[0]) / (LeftD[2] - LeftA[2]), 0.0, 0.0)
    LeftBC = Point3(LeftB[0] - LeftB[2] * (LeftC[0] - LeftB[0]) / (LeftC[2] - LeftB[2]), 0.0, 0.0)
    RightAD = Point3(RightA[0] - RightA[2] * (RightD[0] - RightA[0]) / (RightD[2] - RightA[2]), 0.0, 0.0)
    RightBC = Point3(RightB[0] - RightB[2] * (RightC[0] - RightB[0]) / (RightC[2] - RightB[2]), 0.0, 0.0)

    def __init__(self):
        try:
            self.ToonHead_initialized
        except:
            self.ToonHead_initialized = 1
            Actor.Actor.__init__(self)
            self.toonName = 'ToonHead-' + str(self.this)
            self.__blinkName = 'blink-' + self.toonName
            self.__stareAtName = 'stareAt-' + self.toonName
            self.__lookName = 'look-' + self.toonName
            self.lookAtTrack = None
            self.__eyes = None
            self.__eyelashOpen = None
            self.__eyelashClosed = None
            self.__lod500Eyes = None
            self.__lod250Eyes = None
            self.__lpupil = None
            self.__lod500lPupil = None
            self.__lod250lPupil = None
            self.__rpupil = None
            self.__lod500rPupil = None
            self.__lod250rPupil = None
            self.__muzzle = None
            self.__eyesOpen = ToonHead.EyesOpen
            self.__eyesClosed = ToonHead.EyesClosed
            self.__height = 0.0
            self.__eyelashesHiddenByGlasses = False
            self.randGen = random.Random()
            self.randGen.seed(random.random())
            self.eyelids = ClassicFSM('eyelids', [
             State('off', self.enterEyelidsOff, self.exitEyelidsOff, ['open', 'closed', 'surprised']),
             State('open', self.enterEyelidsOpen, self.exitEyelidsOpen, ['closed', 'surprised', 'off']),
             State('surprised', self.enterEyelidsSurprised, self.exitEyelidsSurprised, ['open', 'closed', 'off']),
             State('closed', self.enterEyelidsClosed, self.exitEyelidsClosed, ['open', 'surprised', 'off'])
            ], 'off', 'off')
            self.eyelids.enterInitialState()
            self.emote = None
            self.__stareAtNode = NodePath()
            self.__defaultStarePoint = Point3(0, 0, 0)
            self.__stareAtPoint = self.__defaultStarePoint
            self.__stareAtTime = 0
            self.lookAtPositionCallbackArgs = None

    def delete(self):
        try:
            self.ToonHead_deleted
        except:
            self.ToonHead_deleted = 1
            taskMgr.remove(self.__blinkName)
            taskMgr.remove(self.__lookName)
            taskMgr.remove(self.__stareAtName)
            if self.lookAtTrack:
                self.lookAtTrack.finish()
                self.lookAtTrack = None
            del self.eyelids
            del self.__stareAtNode
            del self.__stareAtPoint
#.........这里部分代码省略.........
开发者ID:masterbate,项目名称:AIPractive,代码行数:103,代码来源:ToonHead.py

示例15: DistributedMinigame

# 需要导入模块: from direct.fsm.ClassicFSM import ClassicFSM [as 别名]
# 或者: from direct.fsm.ClassicFSM.ClassicFSM import enterInitialState [as 别名]
class DistributedMinigame(DistributedObject.DistributedObject, Timer.Timer):

    def __init__(self, cr):
        try:
            self.DistributedMinigame_initialized
            return
        except:
            self.DistributedMinigame_initialized = 1

        DistributedObject.DistributedObject.__init__(self, cr)
        Timer.Timer.__init__(self)
        self.headPanels = HeadPanels()
        self.finalScoreUI = FinalScoreGUI()
        self.fsm = ClassicFSM('DistributedMinigame', [State('start', self.enterStart, self.exitStart, ['waitForOthers']),
         State('waitForOthers', self.enterWaitForOthers, self.exitWaitForOthers, ['play']),
         State('play', self.enterPlay, self.exitPlay, ['gameOver']),
         State('gameOver', self.enterGameOver, self.exitGameOver, ['off']),
         State('off', self.enterOff, self.exitOff)], 'off', 'off')
        self.fsm.enterInitialState()
        self.cr = cr
        self.localAv = base.localAvatar
        self.localAvId = self.localAv.doId
        self.musicPath = 'phase_4/audio/bgm/trolley_song.mid'
        self.winSfx = base.loadSfx('phase_4/audio/sfx/MG_win.mp3')
        self.loseSfx = base.loadSfx('phase_4/audio/sfx/MG_lose.mp3')
        self.prizeHigh = base.loadSfx('phase_6/audio/sfx/KART_Applause_1.mp3')
        self.prizeLow = base.loadSfx('phase_6/audio/sfx/KART_Applause_4.mp3')
        self.music = None
        self.description = ''
        self.descDialog = None
        self.winnerPrize = 0
        self.loserPrize = 0
        self.winnerMsg = 'Winner!\nYou have earned: %s'
        self.loserMsg = 'Loser!\nYou have earned: %s'
        self.allWinnerMsgs = ['Nice try!\nYou have earned: %s',
         'Good job!\nYou have earned: %s',
         'Way to go!\nYou have earned: %s',
         'Awesome!\nYou have earned: %s']
        self.timer = None
        self.timeLbl = None
        return

    def enterFinalScores(self):
        self.finalScoreUI.load()
        self.finalScoreUI.showFinalScores()

    def exitFinalScores(self):
        self.finalScoreUI.hideFinalScores()
        self.finalScoreUI.unload()

    def finalScores(self, avIdList, scoreList):
        self.finalScoreUI.handleFinalScores(avIdList, scoreList)

    def generateHeadPanel(self, gender, head, headtype, color, doId, name):
        self.headPanels.generate(gender, head, headtype, color, doId, name)

    def updateHeadPanelValue(self, doId, direction):
        self.headPanels.updateValue(doId, direction)

    def setTimerTime(self, time):
        self.setTime(time)

    def createTimer(self):
        Timer.Timer.load(self)

    def deleteTimer(self):
        Timer.Timer.unload(self)

    def setDescription(self, desc):
        self.description = desc

    def getDescription(self):
        return self.description

    def enterStart(self):
        self.descDialog = GlobalDialog(style=3, message=self.getDescription(), doneEvent='gameDescAck')
        self.acceptOnce('gameDescAck', self.handleDescAck)

    def handleDescAck(self):
        self.d_ready()
        self.fsm.request('waitForOthers')

    def exitStart(self):
        self.ignore('gameDescAck')
        self.descDialog.cleanup()
        del self.descDialog

    def enterWaitForOthers(self):
        self.waitLbl = DirectLabel(text='Waiting for other players...', relief=None, text_fg=(1, 1, 1, 1), text_scale=0.08, text_shadow=(0, 0, 0, 1))
        return

    def exitWaitForOthers(self):
        self.waitLbl.destroy()
        del self.waitLbl

    def setLoserPrize(self, prize):
        self.loserPrize = prize

    def setWinnerPrize(self, prize):
        self.winnerPrize = prize
#.........这里部分代码省略.........
开发者ID:coginvasion,项目名称:src,代码行数:103,代码来源:DistributedMinigame.py


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