コード例 #1
0
ファイル: testBounce.py プロジェクト: kondog/python_code
    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_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())
コード例 #3
0
ファイル: testBounce.py プロジェクト: kondog/python_code
    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() )
コード例 #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()
コード例 #5
0
ファイル: testBounce.py プロジェクト: kondog/python_code
    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()
コード例 #6
0
ファイル: testBounce.py プロジェクト: kondog/python_code
    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() )
コード例 #7
0
    clock = pygame.time.Clock()
    while True:
        #clock.tick(sysData.waitTime)
        print clock.tick_busy_loop(sysData.waitTime)

        for event in pygame.event.get():
            if event.type == pygame.QUIT: sys.exit()
        
        # ボール生成部分
        # TODO: ボール生成個数とボール射出タイミングはsysDataに移動
        if len(balls) < 3:
            ballMakeTiming = ballMakeTiming + 1
            if ballMakeTiming > 25:
                ball = BallObj()
                ball.setSpeed( 0, 0 )
                ball.setObj( sysData.ballBmp )
                ball.setRect_pos( 60,-100 )
                balls.append( ball )
                ballMakeTiming = 0

        # ボールの次のフレームの動作
        for ball in balls:
            ball.ballMove()
            ball.decideBallPosition(pygame.key.get_pressed(), 
                                    screen.getSize() )
        #print balls[0].getBallrect()

        # ボールとバーが衝突した際の動作
        for ball in balls:
            mediator.judgeConflictBallAndBar( ball, barRight )
コード例 #8
0
ファイル: bounce.py プロジェクト: kondog/python_code
    def displayFlip( self ):
        self._screen = pygame.display.set_mode( self._size )

if __name__ == "__main__":
    sysData = SysData()
    white   = sysData.screenColor

    pygame.init()

    screen = PygScreen()
    screen.setSize( sysData.screenSizeX,
                    sysData.screenSizeY)
    screen.setDisplay( )

    ball = BallObj()
    ball.setSpeed( 0, -5 )
    ball.setObj( sysData.ballBmp )
    ball.setRect_pos( 50, 240 )

    bar = BarObj()
    bar.setObj( sysData.barBmp)
    bar.setRect_pos( 150, 200 )

    warp = WarpObj()
    warp.setObj( sysData.warpBmp )
    warp.setRect_pos( 230, 150 )

    mediator = Mediator()

    while True:
        time.sleep(sysData.waitTime)
コード例 #9
0
ファイル: bounce.py プロジェクト: kondog/python_code
    def displayFlip(self):
        self._screen = pygame.display.set_mode(self._size)


if __name__ == "__main__":
    sysData = SysData()
    white = sysData.screenColor

    pygame.init()

    screen = PygScreen()
    screen.setSize(sysData.screenSizeX, sysData.screenSizeY)
    screen.setDisplay()

    ball = BallObj()
    ball.setSpeed(0, -5)
    ball.setObj(sysData.ballBmp)
    ball.setRect_pos(50, 240)

    bar = BarObj()
    bar.setObj(sysData.barBmp)
    bar.setRect_pos(150, 200)

    warp = WarpObj()
    warp.setObj(sysData.warpBmp)
    warp.setRect_pos(230, 150)

    mediator = Mediator()

    while True:
        time.sleep(sysData.waitTime)