Exemplo n.º 1
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,  bar,  150, 120 ) #center
                         #ObjA,   X,   Y, ObjB,    X,   Y
        self.assertTrue( True == mediator.isBallAndBarConflict( 
            ball.getBallrect(), bar.getRect() ) )
        self.setPosition( ball, 120, 10,   bar,  120, 40,)  #left
        self.assertTrue( True == mediator.isBallAndBarConflict( 
            ball.getBallrect(), bar.getRect() ) )
        self.setPosition( ball, 120, 70,   bar,  120, 40,)  #right
        self.assertTrue( True == mediator.isBallAndBarConflict( 
            ball.getBallrect(), bar.getRect() ) )
        self.setPosition( ball, 120, 80,   bar,  120, 40,)  #none
        self.assertTrue( False == mediator.isBallAndBarConflict( 
            ball.getBallrect(), bar.getRect() ) )
        ball.setState( self.sysData.stateIdle )         #状態が変化するか idel->L2R
        self.setPosition( ball, 80, 120,   bar,  80, 120 )
        mediator.judgeConflictBallAndBar( ball, bar )
        self.assertTrue( self.sysData.stateLeft2Right == ball.getState() )
        ball.setState( self.sysData.stateLeft2Right )         #状態が変化するか L2R->R2L
        self.setPosition( ball, 80, 120,   bar,  80, 120 )
        mediator.judgeConflictBallAndBar( ball, bar )
        self.assertTrue( self.sysData.stateRight2Left == ball.getState() )
Exemplo n.º 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, bar, 150, 120)  #center
        #ObjA,   X,   Y, ObjB,    X,   Y
        self.assertTrue(True == mediator.isBallAndBarConflict(
            ball.getBallrect(), bar.getRect()))
        self.setPosition(
            ball,
            120,
            10,
            bar,
            120,
            40,
        )  #left
        self.assertTrue(True == mediator.isBallAndBarConflict(
            ball.getBallrect(), bar.getRect()))
        self.setPosition(
            ball,
            120,
            70,
            bar,
            120,
            40,
        )  #right
        self.assertTrue(True == mediator.isBallAndBarConflict(
            ball.getBallrect(), bar.getRect()))
        self.setPosition(
            ball,
            120,
            80,
            bar,
            120,
            40,
        )  #none
        self.assertTrue(False == mediator.isBallAndBarConflict(
            ball.getBallrect(), bar.getRect()))
        ball.setState(self.sysData.stateIdle)  #状態が変化するか idel->L2R
        self.setPosition(ball, 80, 120, bar, 80, 120)
        mediator.judgeConflictBallAndBar(ball, bar)
        self.assertTrue(self.sysData.stateLeft2Right == ball.getState())
        ball.setState(self.sysData.stateLeft2Right)  #状態が変化するか L2R->R2L
        self.setPosition(ball, 80, 120, bar, 80, 120)
        mediator.judgeConflictBallAndBar(ball, bar)
        self.assertTrue(self.sysData.stateRight2Left == ball.getState())
Exemplo n.º 3
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() )
Exemplo n.º 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() )
Exemplo n.º 5
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 )
            mediator.judgeConflictBallAndBar( ball, barLeft )

        # ボールの射出間隔調整
        biggest = choiceBiggestShootTiming(balls)
        if biggest != None:
            biggest.shootTimingIncliment()

        # キーが押されたときバーを移動
        barLeft.moveAs2Key( pygame.key.get_pressed())

        # 表示
        screen.displayFill( white )
        for ball in balls:
            screen.displayBlit( ball.getObj(), ball.getBallrect() )
        screen.displayBlit( barRight.getObj(), barRight.getRect() )
        screen.displayBlit( barLeft.getObj(),  barLeft.getRect() )
        pygame.display.flip()