# Paddle Brick Game- finding direction a ball hits a brick

• 05-17-2013, 12:39 AM
Stormy
Paddle Brick Game- finding direction a ball hits a brick
Hello,
I am working on a paddle brick game (this is my first 'real' attempt at making a game), I am having a bit of difficuilty getting Java to find which side of the block is hit by the ball. The idea is that the brick disappears and the ball gets reflected in the opposite direction that it came. I have used two booleans to define which direction the ball is going - these isTop and isLeft.
I have attempted to use if statements such as

public void isBrickHit(int blockLeft,int blockTop, int blockHeight, int blockWidth){
//Ball hits block from right
if(left<=blockLeft+blockWidth && left>=blockLeft && top>blockTop && top+height<=blockHeight+blockTop){
isLeft=true;
}

... and repeated for the other four sides...
}

However this doesn't very well at all as it often thinks the ball has hit the rectangle at a different square...

I think it may be possible to use an intersection method, however I am not sure how I could use this to differentiate which side is being hit!
Could someone explain how this may be possible?
Thanks for you help in advance!
Simon
• 05-18-2013, 08:08 PM
Prime624
Re: Paddle Brick Game- finding direction a ball hits a brick
I'm just learning games as well, but I was taught to do a similar game using a speed variable and a direction variable (in degrees).