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() )
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())
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() )
# ボールの次のフレームの動作 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()
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()
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()