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
Posts: 177
Registered: ‎03-02-2010
My Device: Not Specified

Brick breaker game help how redirect ball when hit o brick.............?

hi,

 

how i redirect a ball when it hit on bricks on brick?.

 

please refer some code if possible. i draw bricks and ball using XYrect and continue calling 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

Developer
Posts: 562
Registered: ‎09-30-2009
My Device: Not Specified

Re: Brick breaker game help how redirect ball when hit o brick.............?

Do you know what the physical relationship is between a flat mirror and a beam of light pointed at it is? It is the same as a particle hitting a flat surface. Model this in your code and it should behave correctly.

 

This is not a Blackberry specific issue. This is a general instance of collision detection in computer graphics and how to handle it appropriately.