Exemplo n.º 1
0
    def test_moveAs2Key(self):
        pygame.init()

        screen = PygScreen()
        screen.setSize(10,10)
        ballObj = BallObj()
        ballObj.setObj("img/ball.bmp")
        ballObj.setRect()

        # Leftキーが押された時speedXが1減算
        ballObj.setSpeed( 1,1 )
        pressed_keys_cp = \
            self.makeListFromKeyTuple( pygame.key.get_pressed() )
        pressed_keys_cp[K_LEFT] = 1
        ballObj.moveAs2Key( pressed_keys_cp )
        self.assertTrue( [0,1] == ballObj.getSpeed() )

        # Rightキーが押された時speedXが1加算
        ballObj.setSpeed( 1,1 )
        pressed_keys_cp = \
            self.makeListFromKeyTuple( pygame.key.get_pressed() )
        pressed_keys_cp[K_RIGHT] = 1
        ballObj.moveAs2Key( pressed_keys_cp )
        self.assertTrue( [2,1] == ballObj.getSpeed() )

        # Upキーが押された時initSpeedが1加算
        ballObj.setInitSpeed( 5 )
        pressed_keys_cp = \
            self.makeListFromKeyTuple( pygame.key.get_pressed() )
        pressed_keys_cp[K_UP] = 1
        ballObj.moveAs2Key( pressed_keys_cp )
        self.assertTrue( 6 == ballObj.getInitSpeed() )

        # Upキーが押された時initSpeedが1加算
        ballObj.setInitSpeed( 20 )
        pressed_keys_cp = \
            self.makeListFromKeyTuple( pygame.key.get_pressed() )
        pressed_keys_cp[K_UP] = 1
        ballObj.moveAs2Key( pressed_keys_cp )
        self.assertTrue( 20 == ballObj.getInitSpeed() )

        # Downキーが押された時initSpeedが1加算
        ballObj.setInitSpeed( 1 )
        pressed_keys_cp = \
            self.makeListFromKeyTuple( pygame.key.get_pressed() )
        pressed_keys_cp[K_DOWN] = 1
        ballObj.moveAs2Key( pressed_keys_cp )
        print "test initspeed "+str(ballObj.getInitSpeed())
        self.assertTrue( 0 == ballObj.getInitSpeed() )

        # Downキーが押された時initSpeedが1加算
        # initSpeedは0以下にならない
        ballObj.setInitSpeed( 0 )
        pressed_keys_cp = \
            self.makeListFromKeyTuple( pygame.key.get_pressed() )
        pressed_keys_cp[K_DOWN] = 1
        ballObj.moveAs2Key( pressed_keys_cp )
        print "test initspeed "+str(ballObj.getInitSpeed())
        self.assertTrue( 0 == ballObj.getInitSpeed() )
Exemplo n.º 2
0
    def test_moveAs2Key(self):
        pygame.init()

        screen = PygScreen()
        screen.setSize(10, 10)
        ballObj = BallObj()
        ballObj.setObj("img/ball.bmp")
        ballObj.setRect()

        # Leftキーが押された時speedXが1減算
        ballObj.setSpeed(1, 1)
        pressed_keys_cp = \
            self.makeListFromKeyTuple( pygame.key.get_pressed() )
        pressed_keys_cp[K_LEFT] = 1
        ballObj.moveAs2Key(pressed_keys_cp)
        self.assertTrue([0, 1] == ballObj.getSpeed())

        # Rightキーが押された時speedXが1加算
        ballObj.setSpeed(1, 1)
        pressed_keys_cp = \
            self.makeListFromKeyTuple( pygame.key.get_pressed() )
        pressed_keys_cp[K_RIGHT] = 1
        ballObj.moveAs2Key(pressed_keys_cp)
        self.assertTrue([2, 1] == ballObj.getSpeed())

        # Upキーが押された時initSpeedが1加算
        ballObj.setInitSpeed(5)
        pressed_keys_cp = \
            self.makeListFromKeyTuple( pygame.key.get_pressed() )
        pressed_keys_cp[K_UP] = 1
        ballObj.moveAs2Key(pressed_keys_cp)
        self.assertTrue(6 == ballObj.getInitSpeed())

        # Upキーが押された時initSpeedが1加算
        ballObj.setInitSpeed(20)
        pressed_keys_cp = \
            self.makeListFromKeyTuple( pygame.key.get_pressed() )
        pressed_keys_cp[K_UP] = 1
        ballObj.moveAs2Key(pressed_keys_cp)
        self.assertTrue(20 == ballObj.getInitSpeed())

        # Downキーが押された時initSpeedが1加算
        ballObj.setInitSpeed(1)
        pressed_keys_cp = \
            self.makeListFromKeyTuple( pygame.key.get_pressed() )
        pressed_keys_cp[K_DOWN] = 1
        ballObj.moveAs2Key(pressed_keys_cp)
        self.assertTrue(0 == ballObj.getInitSpeed())

        # Downキーが押された時initSpeedが1加算
        # initSpeedは0以下にならない
        ballObj.setInitSpeed(0)
        pressed_keys_cp = \
            self.makeListFromKeyTuple( pygame.key.get_pressed() )
        pressed_keys_cp[K_DOWN] = 1
        ballObj.moveAs2Key(pressed_keys_cp)
        self.assertTrue(0 == ballObj.getInitSpeed())
Exemplo n.º 3
0
    def isCorrectSpeedChange(self, position, speed_before, key, speed_after):
        # init object.
        pygame.init()
        screen = PygScreen()
        screen.setSize(100, 100)
        ball = BallObj()
        ball.setObj(self.sysData.ballBmp)
        ball.setRect()

        # 判定処理
        ball.setBallrectLeft(position[0])
        ball.setBallrectBottom(position[1])
        ball.setSpeed(speed_before[0], speed_before[1])
        pressed_keys_cp = \
            self.makeListFromKeyTuple( pygame.key.get_pressed() )
        if key != None:
            pressed_keys_cp[key] = 1

        ball.decideBallPosition(pressed_keys_cp, screen.getSize())
        return speed_after == ball.getSpeed()
Exemplo n.º 4
0
    def isCorrectSpeedChange( self, position, speed_before, key, speed_after ):
        # init object.
        pygame.init()
        screen = PygScreen()
        screen.setSize(100,100)
        ball = BallObj()
        ball.setObj( self.sysData.ballBmp )
        ball.setRect()

        # 判定処理
        ball.setBallrectLeft( position[0] )
        ball.setBallrectBottom( position[1] )
        ball.setSpeed( speed_before[0], speed_before[1] )
        pressed_keys_cp = \
            self.makeListFromKeyTuple( pygame.key.get_pressed() )
        if key != None:
            pressed_keys_cp[key] = 1

        ball.decideBallPosition( pressed_keys_cp, screen.getSize() )
        return speed_after == ball.getSpeed()