This site requires JavaScript, please enable it in your browser!
Greenfoot back
UltimateCoder
UltimateCoder wrote ...

2013/12/24

How to make an object bounce of a Brick?

UltimateCoder UltimateCoder

2013/12/24

#
I have this game where I shoot these balls with a paddle. The obstacles are bricks which stop the bullets from going through them. However, I want the balls to bounce of the bricks at a random angle. Any help? (here is my code for the ball): public class Ball extends Animal { public void act() { move(6); moveAround(); } private void moveAround() { if (atWorldEdge()) { turn(Greenfoot.getRandomNumber (30) - 30); } } }
danpost danpost

2013/12/24

#
It would be very similar to the 'moveAround' method. Just doing the following adjustments: (1) set the proper condition for the 'if' statement (2) adjust the values of the random number and offset
UltimateCoder UltimateCoder

2013/12/27

#
thanks, but I do not know the correct 'if' statement. I am using the animal class
danpost danpost

2013/12/27

#
Use the 'canSee' method.
UltimateCoder UltimateCoder

2013/12/27

#
thanks, i used the 'isTouching' method. is that fine?
danpost danpost

2013/12/27

#
UltimateCoder wrote...
thanks, i used the 'isTouching' method. is that fine?
That should work.
You need to login to post a reply.