當前位置: 首頁>>代碼示例>>Python>>正文


Python StateMachine.onAxisChanged方法代碼示例

本文整理匯總了Python中statemachine.StateMachine.onAxisChanged方法的典型用法代碼示例。如果您正苦於以下問題:Python StateMachine.onAxisChanged方法的具體用法?Python StateMachine.onAxisChanged怎麽用?Python StateMachine.onAxisChanged使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在statemachine.StateMachine的用法示例。


在下文中一共展示了StateMachine.onAxisChanged方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: __init__

# 需要導入模塊: from statemachine import StateMachine [as 別名]
# 或者: from statemachine.StateMachine import onAxisChanged [as 別名]

#.........這裏部分代碼省略.........
                'cButton': False,
                'dButton': False
            })
            self.controllers.append(KeyboardController(id=1))
            self.controllerOrientations.append(Orientation.South)

        self.lastFrame = time.time()

    def poll(self, dt):
        pygame.event.pump()


        if self.keyboardJoystick:
            events = pygame.event.get()

        for player in range(len(self.controllers)):
            controller = self.controllers[player]

            if self.keyboardJoystick:
                controller.set_events(events)

            previousControllerState = self.previousControllerState[player]

            xAxis = -controller.get_axis(0)
            yAxis = -controller.get_axis(1)

            previousXAxis = previousControllerState['xAxis']
            previousYAxis = previousControllerState['yAxis']
            xChanged = previousXAxis != xAxis
            yChanged = previousYAxis != yAxis

            if xChanged or yChanged:
                xAxis, yAxis = self._mapAxisToOrientation(player, xAxis, yAxis)
                self.onAxisChanged(player, xAxis, yAxis, previousXAxis, previousYAxis)

                previousControllerState['xAxis'] = xAxis
                previousControllerState['yAxis'] = yAxis

            aButton = controller.get_button(0)
            bButton = controller.get_button(1)
            cButton = controller.get_button(2)
            dButton = controller.get_button(3)
            previousAButton = previousControllerState['aButton']
            previousBButton = previousControllerState['bButton']
            previousCButton = previousControllerState['cButton']
            previousDButton = previousControllerState['dButton']
            aChanged = previousAButton != aButton
            bChanged = previousBButton != bButton
            cChanged = previousCButton != cButton
            dChanged = previousDButton != dButton

            if aChanged or bChanged:
                self.onButtonChanged(player, aButton, bButton, previousAButton, previousBButton)

                previousControllerState['aButton'] = aButton
                previousControllerState['bButton'] = bButton

            if cChanged:
                if not cButton:
                    self._onChangeOrientation(player)

                previousControllerState['cButton'] = cButton

            if dChanged:
                if not dButton:
                    self.onStartMenuTriggered(player)
開發者ID:honkomonk,項目名稱:96pxgames,代碼行數:70,代碼來源:game.py


注:本文中的statemachine.StateMachine.onAxisChanged方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。