当前位置: 首页>>代码示例>>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;未经允许,请勿转载。