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
                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 )
            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() )
Exemplo n.º 5
0
    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)
        for event in pygame.event.get():
            if event.type == pygame.QUIT: sys.exit()

        ball.ballMove( )
        ball.decideBallPosition(pygame.key.get_pressed(), screen.getSize() )

        # ボールとバーが衝突した際の動作
        mediator.judgeConflictBallAndBar( ball, bar )
        mediator.judgeConflictBallAndWarp( ball, warp, 50 )

        screen.displayFill( white )
        screen.displayBlit( ball.getObj(), ball.getBallrect() )
        screen.displayBlit( bar.getObj(),  bar.getRect() )
        screen.displayBlit( warp.getObj(),  warp.getRect() )
        pygame.display.flip()

Exemplo n.º 6
0
    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)
        for event in pygame.event.get():
            if event.type == pygame.QUIT: sys.exit()

        ball.ballMove()
        ball.decideBallPosition(pygame.key.get_pressed(), screen.getSize())

        # ボールとバーが衝突した際の動作
        mediator.judgeConflictBallAndBar(ball, bar)
        mediator.judgeConflictBallAndWarp(ball, warp, 50)

        screen.displayFill(white)
        screen.displayBlit(ball.getObj(), ball.getBallrect())
        screen.displayBlit(bar.getObj(), bar.getRect())
        screen.displayBlit(warp.getObj(), warp.getRect())
        pygame.display.flip()