Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Java Development

Reply
Trusted Contributor
rrr_04
Posts: 177
Registered: ‎03-02-2010
My Device: Not Specified

How redirect ball when hit on brick?

[ Edited ]

hi,

 

how i redirect a ball when it hit on bricks on all edge (top,bottom,right left) in brick breaker game.

 

please refer some code if possible. i draw bricks and ball using XYrect and paint method.

 

i am used following code but some time it not work and ball does not redirect on right way.

            boolean movelt = brickrect.contains(ballRect.x, ballRect.y);
            boolean movert = brickrect.contains(ballRect.X2(),ballRect.y);
            boolean rightln = brickrect.contains(ballRect.x, ballRect.Y2());
            boolean leftln = brickrect.contains(ballRect.X2(), ballRect.Y2());

             if (rightln && leftln) {
                goingDown = false;
                return;}
             else if (!rightln && !leftln) {
                goingDown = true;
                return;}
             else if (movelt || rightln) {
                goingRight = true;
                return;}
             else if(movert || leftln){
                goingRight = false;
                return;}

 

 

please give me some code for this and please let me know  if i am doing wrong

 

Please use plain text.