예제 #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() )
예제 #2
0
    def test_BallAndBarObj( self ):
        screen = PygScreen()
        screen.setSize(10,10)
        ball = BallObj()
        ball.setObj("img/ball.bmp")
        bar = BarObj()
        bar.setObj( "img/bar.bmp" )
        mediator = Mediator()

        # 衝突した際の動作
        self.setPosition( 
                ball, 150, 120, 
               #ObjA,  X  , Y
                bar,  150, 120 )
               #ObjB,  X  , Y
        self.assertTrue( True == mediator.isBallAndBarConflict( 
            ball.getBallrect(), bar.getRect() ) )

        self.setPosition( 
                ball, 120, 10, 
                bar,  120, 40,)
        self.assertTrue( True == mediator.isBallAndBarConflict( 
            ball.getBallrect(), bar.getRect() ) )

        self.setPosition( 
                ball, 120, 70, 
                bar,  120, 40,)
        self.assertTrue( True == mediator.isBallAndBarConflict( 
            ball.getBallrect(), bar.getRect() ) )

        self.setPosition( 
                ball, 120, 80, 
                bar,  120, 40,)
        self.assertTrue( False == mediator.isBallAndBarConflict( 
            ball.getBallrect(), bar.getRect() ) )

        ball.setSpeed( 1,1 )
        self.setPosition( 
                ball, 80, 120, 
                bar,  80, 120 )
        mediator.judgeConflictBallAndBar( 
            ball, bar )
        self.assertTrue( [1, -5] == ball.getSpeed() )
예제 #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()
예제 #4
0
    def test_BallAndWarpObj( self ):
        screen = PygScreen()
        screen.setSize(10,10)
        ball = BallObj()
        ball.setObj("img/ball.bmp")
        warp = WarpObj()
        warp.setObj( "img/warp.bmp" )
        mediator = Mediator()

        self.setPosition( 
                ball, 150, 120, 
               #ObjA,  X  , Y
                warp,  150, 120 )
               #ObjB,  X  , Y
        self.assertTrue( True == mediator.isBallAndBarConflict( 
            ball.getBallrect(), warp.getRect() ) )
        ball.setSpeed( 1,1 )
        self.setPosition( 
                ball, 80, 120, 
                warp, 80, 120 )
        mediator.judgeConflictBallAndWarp( 
            ball, warp, 100 )
        self.assertTrue( (100,120) == ball.getBallrect().center)
        self.assertTrue( [0,0] == ball.getSpeed() )