Pong Colision

Ok I have this code to test colision of 4 “bars” to the ball.


public void checkHBarColision1(){
		if(ballX <= hBarX+hBarW && ballX >= hBarX && ballY <= hBar1Y+hBarH){
			//if(ballDir==3 || ballDir==0)
				bounceDown();
		}	
	}
	
	public void checkHBarColision2(){
		if(ballX <= hBarX+hBarW && ballX >= hBarX && ballY+16 >= hBar2Y-hBarH){
			////if(ballDir==5 || ballDir==2)
				bounceUp();

		}	
	}

	public void checkVBarColision1(){
		if(ballY <= vBarY+vBarH && ballY >= vBarY && ballX <= vBarY+vBarW){
			//if(ballDir >= 3)
				bounceRight();

		}
	}
	
	public void checkVBarColision2(){
		if(ballY <= vBarY+vBarH && ballY >= vBarY && ballX+16 >= vBarY-vBarW){
			//if(ballDir <= 2)
				bounceRight();

		}
	}

Now what controles all four bars(2 on the top and bottom of the screen,2 on left and right.) is the mouse. mouse Y position dictates the Y position of the Verticle(sides) and the X position of the mouse dictates the x position of the horizontal bars(top and bottom). Now the ball only bounces when the mouse has touchted the ball. Any idea why the ball bounces when it touches the location of the mouse, and not the bars?

Probably because of the way variables such as vBarY and vBarH are assigned?

:o Finaly someone replys after to days >:(

Anyway, this is how I assing the X and Y positions for the bars…


	public void mouseMoved(MouseEvent m){
		if(gameState != 2 && gameState != 1){
			vBarY = m.getY();
			hBarX = m.getX();
		}
	}

It works becuase the bars move. and vBarH is the height of the bar which is 75. NEW DISCOVORY! The ball only goes wacko if the ball is within the two verticle bars. if the two verticle bars are at the opposit side of the screen, it works fine.

Have you tried putting some debug code (System.out.println) to the bounceUp/Down/Left/Right methods so that you would know which of them is being called? That that could help in locating the bug.