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


Python StateMachine.onClampedAxisChanged方法代碼示例

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


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

示例1: __init__

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

#.........這裏部分代碼省略.........
                previousControllerState['dButton'] = dButton

    def run(self):
        clock = pygame.time.Clock()
        while True:
            dt = clock.tick(self.framerate) / 1000.0
            #dt = time.time() - self.lastFrame

            self.update(dt)

            self.draw(self.rgb)

            self.rgb.send()

            self.lastFrame = time.time()

    def update(self, dt):
        self.poll(dt)

        self.stateMachine.update(dt)

    def draw(self, rgb):
        rgb.clear(BLACK)

        self.stateMachine.draw(rgb)

    def onAxisChanged(self, player, xAxis, yAxis, previousXAxis, previousYAxis):
        #todo rotation

        if (self._notIsZero(xAxis) and self._isZero(previousXAxis)) or \
           (self._notIsZero(yAxis) and self._isZero(previousYAxis)):

            x = 1 if xAxis > 0.1 else 0
            x = -1 if xAxis < -0.1 else x
            y = 1 if yAxis > 0.1 else 0
            y = -1 if yAxis < -0.1 else y

            if x != 0 or y != 0:
                self.onClampedAxisChanged(player, x, y)

        self.stateMachine.onAxisChanged(player, xAxis, yAxis, previousXAxis, previousYAxis)

    def onButtonChanged(self, player, aButton, bButton, previousAButton, previousBButton):
        self.stateMachine.onButtonChanged(player, aButton, bButton, previousAButton, previousBButton)

    def onClampedAxisChanged(self, player, x, y):
        self.stateMachine.onClampedAxisChanged(player, x, y)

    def playSound(self, name):
        res = self.resources[name]
        if isinstance(res, Sound):
            self.resources[name].play()
        else:
            print "tried to play non-sound resource"

    def stopSound(self, name):
        res = self.resources[name]
        if isinstance(res, Sound):
            self.resources[name].stop()
        else:
            print "tried to stop non-sound resource"

    def fadeoutSound(self, name, time):
        res = self.resources[name]
        if isinstance(res, Sound):
            self.resources[name].fadeout(time)
        else:
            print "tried to fadeout non-sound resource"

    def setState(self, name):
        self.stateMachine.setState(name)

    def onStartMenuTriggered(self, player):
        sys.exit(0)

    def _isZero(self, d):
        return abs(d) < 0.1

    def _notIsZero(self, d):
        return abs(d) > 0.1

    def _mapAxisToOrientation(self, player, xAxis, yAxis):
        orientation = self.controllerOrientations[player]

        if orientation == Orientation.North:
            xAxis = -xAxis
            yAxis = -yAxis
        elif orientation == Orientation.West:
            xTmp = xAxis
            xAxis = -yAxis
            yAxis = xTmp
        elif orientation == Orientation.East:
            xTmp = xAxis
            xAxis = yAxis
            yAxis = -xTmp

        return xAxis, yAxis

    def _onChangeOrientation(self, player):
        self.controllerOrientations[player] = (self.controllerOrientations[player] + 1) % Orientation.Count
開發者ID:honkomonk,項目名稱:96pxgames,代碼行數:104,代碼來源:game.py


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